64 bit compiler runtime problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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

.



Relevant Pages

  • Re: 64 bit compiler runtime problem
    ... `Has anyone used M Roddys C++ kernel runtime in a 64-bit driver`. ... #pragma data_seg ... int _cdecl atexit ... // value of pfbegin points to the first valid entry. ...
    (microsoft.public.development.device.drivers)
  • Re: Creating virtual midi loopback driver
    ... a software midi driver to connect to my application. ... // install DMusUART miniport. ... #pragma code_seg ... If I search google for 'dmusuart' theres no links to software midi drivers ...
    (microsoft.public.development.device.drivers)
  • Re: reading a C++ structure from a binary file using C#
    ... because it pragma pack was used several different values would be possible. ... The int is the first field of the struct, the second is a char array which has no alignment restriction, so, whatever the packing, the length written on disk will be 74. ... Padding is included in sizeof, because sizeof is the separation between adjacent array elements which must both be properly aligned. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: gcc 3 versions wont compile hello.cpp
    ... changed in gcc3, how can one use gcc3 for non-vertical ... Given a pragma to change the default to _System, ... int foo(int a, int b) ... Both use the stack right to left and both prepend an underscore. ...
    (comp.os.os2.programmer.tools)
  • Re: newbie questions about pageable code
    ... >I have a few questions about makeing code pageable in a kernal mode driver. ... > #pragma alloc_text ... Don Burn (MVP, Windows DDK) ...
    (microsoft.public.win32.programmer.kernel)