[英]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. 我已经读过关于使用
ExAllocatePoolWithTag
分配内存的信息,但是我仍然不知道我可以在哪里实现它,以及在哪里不可以实现它。
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: 在WinXP x86 Checked构建环境中,我在这里收到链接器错误:
error LNK2001: unresolved external symbol _PoolData
error LNK1120: 1 unresolved externals
If i do not declare it extern, just PPOOL_LIST PoolData;
如果我不声明它为extern,则只是
PPOOL_LIST PoolData;
i get another error 我得到另一个错误
error LNK2005: _PoolData already defined in filter.obj
But i can declare pcount, why not PoolData ? 但是我可以声明pcount,为什么不声明PoolData呢?
The extern
keyword is used to say that the variable is located somewhere else - eg it exists somewhere. extern
关键字用于表示变量位于其他位置,例如,它存在于某个位置。 So complation works. 因此,合并有效。 The linker is actually looking for an instance of PoolData and it failed to find it.
链接器实际上正在寻找PoolData的实例,但找不到它。
In your C file declare: 在您的C文件中声明:
PPOOL_LIST PoolData;
//without extern
. //没有
extern
。
or 要么
static PPOOL_LIST PoolData;
// only accessible from this C file //仅可从此C文件访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.