简体   繁体   中英

allocate global pool in kernel mode

Hope i get an answer even if this question might sound silly. I've read about allocating Memory with ExAllocatePoolWithTag now but i still do not know where i can iplement it and where i am not allowed to do it.

In my case i have to allocate a global buffer. This is the way i tried:

POOL.H

#ifndef _POOL_H_
#define _POOL_H_

typedef struct _POOL_LIST {
   CHAR list_data[500] ;
   struct _POOL_LIST* next;
}
    POOL_LIST, * PPOOL_LIST;


#ifdef __cplusplus
extern "C" {
#endif

extern ULONG pcount;
extern PPOOL_LIST PoolData;

void poolinitialize();
void poolterminate();

#ifdef __cplusplus
};
#endif

#endif // _POOL_H_

POOL.C

#include "precomp.h"
#pragma hdrstop

ULONG pcount = 0;


void poolinitialize()
{
    PoolData = (PPOOL_LIST*) ExAllocatePoolWithTag(NonPagedPool, GLOBALBUFFERMAX, 'tag1');
}

void poolterminate()
{
    ExFreePoolWithTag(PoolData, 'tag1');
}

here i get a Linker Error in the WinXP x86 Checked Build Environment:

error LNK2001: unresolved external symbol _PoolData
error LNK1120: 1 unresolved externals

If i do not declare it extern, just PPOOL_LIST PoolData; i get another error

error LNK2005: _PoolData already defined in filter.obj

But i can declare pcount, why not PoolData ?

The extern keyword is used to say that the variable is located somewhere else - eg it exists somewhere. So complation works. The linker is actually looking for an instance of PoolData and it failed to find it.

In your C file declare:

PPOOL_LIST PoolData; //without extern .

or

static PPOOL_LIST PoolData; // only accessible from this C file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM