Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#267 winddk.h: pack 1 for structures

closed-fixed
Earnie Boyd
2003-05-05
2003-01-21
Marcel Telka
No

Some structures in winddk.h requires "#pragma
pack(push,1)" and "#pragma pack(pop)" around
declarations. This is true at least for "struct _IRP"
(lines 975 - 1029 in winddk.h).

Discussion

  • Numa Tortolero
    Numa Tortolero
    2003-04-06

    Logged In: YES
    user_id=751046

    Sorry, but I did not find a category for this bug.

    In the line 130 of winddk.h (from Win32api-2.2.tar.gz),
    there is the following declaration:

    typedef ULONG KIRQL, *PKIRQL;

    This is not correct, and causes errors when you use
    the IRP structure. So, when you use macros as:

    IoGetCurrentIrpStackLocation(Irp)

    you will get a bad pointer to the stack location, because
    KIRQL is really CHAR type.

    The correct declaration is:

    typedef UCHAR KIRQL;
    typedef KIRQL *PKIRQL

    greetings
    numit_or
    numit_or@cantv.net

     
  • Danny Smith
    Danny Smith
    2003-05-02

    Logged In: YES
    user_id=11494

    Marcel

    Are you still sure about _IRP? I think the change of
    KIRQL to UCHAR may have fixed the allignmnent
    problem in _IRP. If not can you point out where offsets
    differ?

    Danny

     
  • Numa Tortolero
    Numa Tortolero
    2003-05-05

    Logged In: YES
    user_id=751046

    All right Danny. I was writting a demo kmd for win2k. And I
    had
    problems in this line:

    irpStack = IoGetCurrentIrpStackLocation(Irp);

    IoGetCurrentIrpStackLocation() is a macro that returns the
    current IRP stack
    location, where you find the IRPs.

    In IRP structure, CurrentIrpStackLocation member is after of
    CancelIrql member,
    that is KIRQL type.

    When I used the original definition in Win32api-2.2.tar.gz
    winddk.h (lines
    125-133):

    /*
    ** Simple structures
    */

    typedef LONG KPRIORITY;
    typedef ULONG KIRQL, *PKIRQL;
    ...

    I got this result:

    _DriverDispatch@8:
    # declare local variables:
    pushl %ebp
    movl %esp, %ebp
    subl $24, %esp

    \# NTSTATUS status =
    

    STATUS_NOT_IMPLEMENTED;
    movl $-1073741822, -4(%ebp)

    \# irpStack = IoGetCurrentIrpStackLocation\(Irp\);
    movl    12\(%ebp\), %eax    \# IRP pointer in
    

    EAX
    movl 104(%eax), %eax #
    IRP.CurrentStackLocation in EAX <-

    movl    %eax, -8\(%ebp\)
    

    I revised the definition in win2k ddk ntdef.h (lines 1302-09)

    //
    // Interrupt Request Level (IRQL)
    //

    typedef UCHAR KIRQL;

    typedef KIRQL *PKIRQL;

    And I did these changes in win2k ddk winnt.h, like ntdef.h:

    /*
    ** Simple structures
    */

    typedef LONG KPRIORITY;
    //
    // Interrupt Request Level (IRQL)
    //
    typedef UCHAR KIRQL;
    typedef KIRQL *PKIRQL;
    //typedef ULONG KIRQL, *PKIRQL;

    I got these results:

    _DriverDispatch@8:
    # declare local variables:
    pushl %ebp
    movl %esp, %ebp
    subl $24, %esp

    \# NTSTATUS status =
    

    STATUS_NOT_IMPLEMENTED;
    movl $-1073741822, -4(%ebp)

    \# irpStack = IoGetCurrentIrpStackLocation\(Irp\);
    movl    12\(%ebp\), %eax    \# IRP pointer in
    

    EAX
    movl 96(%eax), %eax #
    IRP.CurrentStackLocation in EAX <-
    movl %eax, -8(%ebp)

    movl    -8\(%ebp\), %eax
    

    Now, if you see the line signaled with the arrow "<-", you will
    see
    the difference:

    FIRST \(the bad\):
    movl    104\(%eax\), %eax \#
    

    IRP.CurrentStackLocation in EAX <-

    SECOND \(the correct\):
    movl    96\(%eax\), %eax    \#
    

    IRP.CurrentStackLocation in EAX <-

    And now the code generated bt MSVC++:

    001036F loc_1036F:

    0001036F push esi
    ; irpStack = IoGetCurrentIrpStackLocation(Irp);
    00010370 mov esi, [esp+0Ch] ; IRP pointer in
    ESI
    00010374 xor ecx, ecx
    00010376 push edi
    00010377 mov eax, [esi+60h] ;
    IRP.CurrentStackLocation in EAX <-

    remember that hexadecimal 60 = decimal 96.

    As you can see, the line:

    typedef ULONG KIRQL, *PKIRQL;

    seems not be correct.

    greetings
    nmt

     
  • Marcel Telka
    Marcel Telka
    2003-05-05

    Logged In: YES
    user_id=395402

    Danny,

    the problem still persist. Simple testcase:

    #include <ddk/ntddk.h>

    int
    main( void )
    {
    IRP irp;
    printf( "%d\n", (char *)
    &IoGetCurrentIrpStackLocation( &irp ) - (char *) &irp );
    }

    Valid output should be 96. But with w32api-2.3-1 (a part of
    the cygwin) the output is 104.

    Please see line 74 in file
    http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/openwince/tools/ioperm/driver/ioperm.c?annotate=1.4
    for this bug workaround example.

    Thanks.

    --
    Marcel Telka

     
  • Danny Smith
    Danny Smith
    2003-05-05

    Logged In: YES
    user_id=11494

    Thanks for the testcase. With current cvs (KIRQL
    typedefed as UCHAR), the offset is 96. #pragma
    pack(push,1) is not necessary.

    Danny

     
  • Danny Smith
    Danny Smith
    2003-05-05

    • status: open --> closed-fixed