64 bit compiler runtime problem

Discussion in 'Windows Vista Drivers' started by siddu, Jun 30, 2009.

  1. siddu

    siddu Guest

    I am porting my 32bit windows driver to 64 bit windows driver,this driver is
    using some dynamic initializer which works good in 32 bit windows but not in
    64 bit.

    the section of code wriiten in c++ as follows

    #ifdef __cplusplus
    extern "C" {
    #endif

    // Declare types used in the run-time sources

    typedef void (__cdecl *_PVFV)(void);

    // Declare initialization segment

    #pragma data_seg(".CRT$XIA")
    _PVFV __xi_a[] = { 0 };

    #pragma data_seg(".CRT$XIZ")
    _PVFV __xi_z[] = { 0 };

    #pragma data_seg(".CRT$XCA")
    _PVFV __xc_a[] = { 0 };

    #pragma data_seg(".CRT$XCZ")
    _PVFV __xc_z[] = { 0 };

    #pragma data_seg(".CRT$XPA")
    _PVFV __xp_a[] = { 0 };

    #pragma data_seg(".CRT$XPZ")
    _PVFV __xp_z[] = { 0 };

    #pragma data_seg(".CRT$XTA")
    _PVFV __xt_a[] = { 0 };

    #pragma data_seg(".CRT$XTZ")
    _PVFV __xt_z[] = { 0 };

    #pragma data_seg() /* reset */

    #pragma comment(linker, "/merge:.CRT=.DATA")

    // Declare deinitializer functions pointer table
    //
    static _PVFV _pvfv[32];
    static int _npvfv = 0;

    ////////////////////////////////////////////////////////////////////////////////
    // C/C++ initialization/termination implementation

    int _cdecl atexit(_PVFV func)
    {
    // Check if still have enough room
    if (_npvfv >= (sizeof(_pvfv)/sizeof(_pvfv[0])) && !func)
    return -1;

    _pvfv[_npvfv++] = func;
    return 0;
    }


    void _cdecl _initterm(_PVFV * pfbegin,_PVFV * pfend)
    {
    // Walk the table of function pointers from the bottom up, until
    // the end is encountered. Do not skip the first entry. The initial
    // value of pfbegin points to the first valid entry. Do not try to
    // execute what pfend points to. Only entries before pfend are valid.
    KdPrint(("IN _initterm pfbegin=%x,pfend=%x", pfbegin,pfend));
    while (pfbegin < pfend)
    {
    // If current table entry is non-NULL, call thru it.
    KdPrint(("pfbegin= %x",pfbegin));
    if (*pfbegin != 0)
    { KdPrint(("inside if pfbegin = %x",pfbegin));
    (**pfbegin)();
    }
    ++pfbegin;
    }
    }

    #ifdef __cplusplus
    }
    #endif

    ////////////////////////////////////////////////////////////////////////////////
    // Public functions that has to be called on driver entrance/exit

    int _cdecl DfxRtlInitialize()
    {
    int nIdx;

    // Clear terminator function count and table
    _npvfv = 0;
    for (nIdx = 0; nIdx < (sizeof(_pvfv)/sizeof(_pvfv[0])); nIdx++ )
    {
    _pvfv[nIdx] = 0;
    KdPrint(("DfxRtlInitialize = %x,%x",sizeof(_pvfv),sizeof(_pvfv[0]) ));
    }

    // Call initializers
    _initterm(__xt_a, __xt_z);

    // Call C++ initializers
    _initterm(__xc_a, __xc_z);

    return 0;
    }


    int _cdecl DfxRtlTerminate()
    {
    _PVFV func;

    // Call deinitializers in the LIFO order
    for (--_npvfv; _npvfv >= 0; --_npvfv)
    {
    func = _pvfv[_npvfv];
    (*func)();
    }

    return 0;
    }


    Problem found that,In _initterm function must call the X() function which
    creates the object.
    the trace shows that if (*pfbegin != 0) is false which means there is a
    linkage problem in
    #pragma comment(linker, "/merge:.CRT=.DATA")

    can any one help me how to solve this?

    thanks and regards,
    siddu
     
    siddu, Jun 30, 2009
    #1
    1. Advertisements

  2. Please look at an old thread titled
    `Has anyone used M Roddys C++ kernel runtime in a 64-bit driver`.
    It should give you the background to find yourself an answer.
    Then, you should get the hint on other things to look for.

    --
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of any included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm


     
    Ivan Brugiolo [MSFT], Jul 7, 2009
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.