Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:19:10+00:00 2026-06-05T15:19:10+00:00

I am looking at the File System Filter driver example in the WDK called

  • 0

I am looking at the File System Filter driver example in the WDK called minispy… specially how they are passing data between userspace and the kernel using the FilterSendMessage and related functions:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff541513%28v=vs.85%29.aspx

The code I am looking at and will be referring to should be located here if you install the WDK:

WinDDK Root Dir\version\src\filesys\miniFilter\minispy

So basically the first thing I am looking at is the shared header file in inc\minispy.h:

#pragma warning(push)
#pragma warning(disable:4200) // disable warnings for structures with zero length arrays.

typedef struct _LOG_RECORD {


ULONG Length;           // Length of log record.  This Does not include
ULONG SequenceNumber;   // space used by other members of RECORD_LIST

ULONG RecordType;       // The type of log record this is.
ULONG Reserved;         // For alignment on IA64

RECORD_DATA Data;
WCHAR Name[];           //  This is a null terminated string

} LOG_RECORD, *PLOG_RECORD;

Here we have Name which is not given an explicit size and it looks like they are using some options to disable warnings for this.

Now I am looking at where this is filled in, filter\mspyLib.c:

(I only copied lines I thought were relevant…)

VOID SpySetRecordName (__inout PLOG_RECORD LogRecord, __in PUNICODE_STRING Name)

    ULONG nameCopyLength;
    PCHAR copyPointer = (PCHAR)LogRecord->Name;
    ...
    // A bunch of code for getting nameCopyLength from UNICODE_STRING -- I understand this.
    ...

    // comment about adding sizeof(PVOID) for IA64 alignment -- I understand this.
    LogRecord->Length = ROUND_TO_SIZE( (LogRecord->Length + nameCopyLength + sizeof( UNICODE_NULL )), sizeof( PVOID ) );

    RtlCopyMemory( copyPointer, Name->Buffer, nameCopyLength );

    copyPointer += nameCopyLength;

    *((PWCHAR) copyPointer) = UNICODE_NULL;

So my question is basically is this the best method for passing strings inside of a struct for user-kernel communication using FilterSendMessage? I’m having trouble picturing the layout of these structs and what happens if the name string turns out to be too big. Also, allocation for the struct happens in the userspace component on it’s stack but the resize happens in kernel space component acting on a passed pointer to the struct. I think this is more a problem of me not understanding zero length arrays but how does the userspace component know how much space to reserve for the Name field before its resized?

This essentially seems to be a form of dynamically sized arrays which is discussed in several threads such as:

C: Recommended style for dynamically sized structs

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:19:11+00:00Added an answer on June 5, 2026 at 3:19 pm

    First of all, yes, it appears to be a form of dynamically sized array. Basically, the Name string is placed right after the end of structure. When passing data between user- and kernel-mode it is very often used trick. There are several advantages of this approach:

    • It does not require several memory allocations.
    • When passing data from user mode to kernel mode (and vice versa) you often need to copy memory from one buffer to another (I believe FilterSendMessage does that). If we use pointer to a different memory location for storing string we will need several calls to copy (or lock) memory. When dealing with user-supplied messages it is impossible to OS to know the layout of your data structure. The key to solving this problem is to use plain structure as the one described above.

    It is very useful approach. I personally use such trick to avoid multiples calls to memory functions (allocate, copy, move etc.) even in simple applications. When developing Windows drivers I see such structures everywhere (i.e. ZwQueryInformationFile, ZwQueryDirectoryFile etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for optimal approach to use file system based data storage in
I'm looking to create a driver I guess for a custom file system on
I have been looking into libraries for a file system that will allow path
I have been looking for a C# tree control for displaying a file system
I'm looking for a way to search a file system that contains approximately 1TB
I'm looking for a C# class that represents a file system path . I
I've been looking over the Doom 3 SDK code, specifically their File System implementation.
I'm looking for some code to check if a file in the file system
I'm looking for some code to check if a file in the file system
Looking for suggestions on file system management tools. We have several terabytes of images,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.