Due to some reason, I have to provide my own malloc/free/calloc
functions so that other parts of the driver are happy. These functions
are simply a wrapper around ExAllocatePool. However, when I compile it,
the linker complains: "warning LNK4217: locally defined symbol _free
imported in function xxxx".

This is the free() function:
void __cdecl free(void *p)
{
ExFreePool(p);
}

How can I get rid of this message? Thanks

Re: problem of providing my own version of malloc/free by Skywing

Skywing
Mon Oct 10 17:58:23 CDT 2005

You (or the header you are including) is using __declspec(dllimport) in the
prototype for free - remove that decoration and link.exe will be happy.

<ronghuazhang@gmail.com> wrote in message
news:1128984516.455378.309090@g44g2000cwa.googlegroups.com...
> Due to some reason, I have to provide my own malloc/free/calloc
> functions so that other parts of the driver are happy. These functions
> are simply a wrapper around ExAllocatePool. However, when I compile it,
> the linker complains: "warning LNK4217: locally defined symbol _free
> imported in function xxxx".
>
> This is the free() function:
> void __cdecl free(void *p)
> {
> ExFreePool(p);
> }
>
> How can I get rid of this message? Thanks
>



RE: problem of providing my own version of malloc/free by Demetrius

Demetrius
Tue Oct 11 03:45:02 CDT 2005

Try
void __cdecl operator free

"ronghuazhang@gmail.com" wrote:

> Due to some reason, I have to provide my own malloc/free/calloc
> functions so that other parts of the driver are happy. These functions
> are simply a wrapper around ExAllocatePool. However, when I compile it,
> the linker complains: "warning LNK4217: locally defined symbol _free
> imported in function xxxx".
>
> This is the free() function:
> void __cdecl free(void *p)
> {
> ExFreePool(p);
> }
>
> How can I get rid of this message? Thanks
>
>

Re: problem of providing my own version of malloc/free by ronghuazhang

ronghuazhang
Tue Oct 11 17:31:56 CDT 2005

Thanks for the reply. My case is a little complicated.

The driver is compiled with another .c file, which includes stdlib.h
and calls malloc/free. This .c file is shared by other parts of my
project. It's also used by some user level applications. So changing it
to remove the 'stdlib.h' inclusion is not an option (according to your
reply, I think this header file is the cause for the warning). Is there
other ways to get around this issue? Thanks again


Re: problem of providing my own version of malloc/free by Skywing

Skywing
Tue Oct 11 17:46:10 CDT 2005

How about making it conditional based on some compiler option?

#if _NT_KERNEL_BUILD

/* do one thing */

#else

/* do another thing*/

#endif

the -D_NT_KERNEL_BUILD=0 or -D_NT_KERNEL_BUILD=1

You might consider just renaming your malloc/free calls entirely based on
that conditional. For instance have a "my_malloc" and "my_free", which
would be #define'd to malloc/free or something else in kmode, to avoid the
linkage warning.

<ronghuazhang@gmail.com> wrote in message
news:1129069916.464716.199570@g14g2000cwa.googlegroups.com...
> Thanks for the reply. My case is a little complicated.
>
> The driver is compiled with another .c file, which includes stdlib.h
> and calls malloc/free. This .c file is shared by other parts of my
> project. It's also used by some user level applications. So changing it
> to remove the 'stdlib.h' inclusion is not an option (according to your
> reply, I think this header file is the cause for the warning). Is there
> other ways to get around this issue? Thanks again
>



Re: problem of providing my own version of malloc/free by James

James
Tue Oct 11 18:59:25 CDT 2005

If a person needs to build 2 different ways, one approach is to split the
builds into 2 pieces, with a sources file for each, and each sources file
with appropriate include paths and other directives. This approach works
even when the builds are for a single driver: Build one piece as a .lib file
(eg, TARGETTYPE=DRIVER_LIBRARY) and have the other piece include that file
when the second piece is built.

--
James Antognini
Windows DDK and WDK Support


This posting is provided "AS IS" with no warranties, and confers no rights.



<ronghuazhang@gmail.com> wrote in message
news:1129069916.464716.199570@g14g2000cwa.googlegroups.com...
> Thanks for the reply. My case is a little complicated.
>
> The driver is compiled with another .c file, which includes stdlib.h
> and calls malloc/free. This .c file is shared by other parts of my
> project. It's also used by some user level applications. So changing it
> to remove the 'stdlib.h' inclusion is not an option (according to your
> reply, I think this header file is the cause for the warning). Is there
> other ways to get around this issue? Thanks again
>