7 #ifdef MY_USE_INTERNAL_MEMMANAGER 19 #else // NO X86 optimization , use generic C/C++ 31 #ifdef MEM_LOCK_BY_SPINLOCK 34 #define LockMemoryManager() KeAcquireSpinLock(&FrameLock, &oldIrql) 35 #define UnlockMemoryManager() KeReleaseSpinLock(&FrameLock, oldIrql) 38 InitLockMemoryManager() {
42 #define DeinitLockMemoryManager() {NOTHING;} 43 #else //MEM_LOCK_BY_SPINLOCK 45 #define LockMemoryManager() ExAcquireResourceExclusiveLite(&FrameLock, TRUE) 46 #define UnlockMemoryManager() ExReleaseResourceForThreadLite(&FrameLock, ExGetCurrentResourceThread()) 47 #define InitLockMemoryManager() ExInitializeResourceLite(&FrameLock) 48 #define DeinitLockMemoryManager() ExDeleteResourceLite(&FrameLock) 49 #endif //MEM_LOCK_BY_SPINLOCK 54 #define MyAllocIsFrameFree(FrameList, i) \ 55 (!(FrameList[i].LastUsed || FrameList[i].FirstFree)) 71 #ifdef MY_HEAP_TRACK_OWNERS 74 #ifdef MY_HEAP_TRACK_REF 82 #define DUMP_MEM_FRAMES 84 #ifdef DUMP_MEM_FRAMES 86 #endif //DUMP_MEM_FRAMES 88 #define DUMP_MEM_FRAMES2 98 Allocs = FrameList[Frame].
Frame;
101 #ifdef DUMP_MEM_FRAMES 103 #endif //DUMP_MEM_FRAMES 106 UDFPrint((
"Dumping frame %x\n",Frame));
107 UDFPrint((
"FirstFree %x LastUsed %x ", FrameList[Frame].FirstFree, FrameList[Frame].LastUsed));
113 #ifdef MY_HEAP_TRACK_OWNERS 114 UDFPrint((
"src %x \t line %d \t", Allocs[
i].Src, Allocs[
i].
Line));
116 #ifdef MY_HEAP_TRACK_REF 120 if(!(Allocs[
i].
Len) && !(Allocs[
i].Addr)) {
138 if(FrameList[
i].Frame) {
146 if(FrameList[
i].Frame) {
147 UDFPrint((
"Addr %x ", FrameList[
i].Frame));
161 Allocs = FrameList[Frame].
Frame;
167 if(
len != (Allocs[
i+1].Addr -
addr) ) {
168 if(Allocs[
i+1].Addr) {
169 UDFPrint((
"ERROR! Memory block aliasing\n"));
170 UDFPrint((
"block %x, frame %x\n",
i, Frame));
171 UDFPrint((
"block descriptor %x\n", &(Allocs[
i]) ));
173 MyAllocDumpFrame(Frame);
176 #ifdef MY_HEAP_CHECK_BOUNDS 178 MyAllocDumpDescr(Allocs,
i);
180 #endif //MY_HEAP_CHECK_BOUNDS 187 #define MyAllocDumpFrame(a) {} 188 #define MyAllocCheck(a) {} 189 #define MyAllocDumpFrames() {} 194 #ifndef MY_HEAP_TRACK_OWNERS 197 MyAllocatePoolInFrame(
200 #ifdef MY_HEAP_TRACK_OWNERS
204 #ifdef MY_HEAP_TRACK_REF
215 ULONG LastUsed, FirstFree;
218 #ifdef CHECK_ALLOC_FRAMES 223 #ifdef MY_HEAP_CHECK_BOUNDS 224 size+=MY_HEAP_CHECK_BOUNDS_BSZ;
231 Allocs0 = FrameList[Frame].
Frame;
232 if(!Allocs0)
return NULL;
235 LastUsed = FrameList[Frame].
LastUsed;
241 for(
i=FirstFree, Allocs = &(Allocs0[
i]);
i<=LastUsed;
i++, Allocs++) {
246 if(
l < min_len || !min_len) {
257 Allocs = Allocs0+best_i;
278 if(FirstFree == best_i) {
283 Allocs = Allocs0+best_i;
286 #ifdef MY_HEAP_TRACK_OWNERS 290 #ifdef MY_HEAP_TRACK_REF 292 #endif //MY_HEAP_TRACK_REF 297 #ifdef MY_HEAP_CHECK_BOUNDS 298 for(
i=0;
i<MY_HEAP_CHECK_BOUNDS_SZ;
i++) {
301 #endif //MY_HEAP_CHECK_BOUNDS 321 Allocs = FrameList[Frame].
Frame;
327 if(!
right && FrameList[Frame].FirstFree)
342 if(Allocs[
i].Addr && (Allocs[
i].Addr < (
ULONG)
addr)) {
363 Allocs = FrameList[Frame].
Frame;
365 i = MyFindMemDescByAddr(Frame,
addr);
367 UDFPrint((
"Mem: <<<*** WARNING ***>>> Double deallocation at %x !!! ;( \n",
addr));
368 MyAllocDumpFrame(Frame);
375 #ifdef MY_HEAP_CHECK_BOUNDS 376 for(
j=0;
j<MY_HEAP_CHECK_BOUNDS_SZ;
j++) {
379 MyAllocDumpDescr(Allocs,
i);
382 #endif //MY_HEAP_CHECK_BOUNDS 423 if(FrameList[Frame].FirstFree > (
ULONG)
i)
426 if(FrameList[Frame].LastUsed < pc) {
440 #ifdef MY_HEAP_TRACK_REF
451 Allocs = FrameList[Frame].
Frame;
452 i = MyFindMemDescByAddr(Frame,
addr);
454 UDFPrint((
"Mem: <<<*** WARNING ***>>> Double deallocation at %x !!! ;( \n",
addr));
455 MyAllocDumpFrame(Frame);
462 #ifdef MY_HEAP_TRACK_REF 463 *
Tag = Allocs[
i].Tag;
464 #endif //MY_HEAP_TRACK_REF 468 #ifdef MY_HEAP_CHECK_BOUNDS 469 new_len += MY_HEAP_CHECK_BOUNDS_BSZ;
470 for(
j=0;
j<MY_HEAP_CHECK_BOUNDS_SZ;
j++) {
473 MyAllocDumpDescr(Allocs,
i);
476 #endif //MY_HEAP_CHECK_BOUNDS 483 Allocs[
i].
Len += (len2 = (new_len -
len));
484 Allocs[
i+1].
Len -= len2;
485 Allocs[
i+1].
Addr += len2;
487 #ifdef MY_HEAP_CHECK_BOUNDS 488 for(
j=0;
j<MY_HEAP_CHECK_BOUNDS_SZ;
j++) {
489 *((
PULONG)(
addr+new_len+(
j*
sizeof(
ULONG))-MY_HEAP_CHECK_BOUNDS_BSZ)) = 0xBAADF00D;
491 #endif //MY_HEAP_CHECK_BOUNDS 493 if(!Allocs[
i+1].
Len) {
497 if((
ULONG)
i<FrameList[Frame].LastUsed)
499 if(FrameList[Frame].FirstFree == (
ULONG)
i) {
512 len2 =
len - new_len;
513 if(!len2)
return TRUE;
515 #ifdef MY_HEAP_CHECK_BOUNDS 516 for(
j=0;
j<MY_HEAP_CHECK_BOUNDS_SZ;
j++) {
517 *((
PULONG)(
addr+new_len+(
j*
sizeof(
ULONG))-MY_HEAP_CHECK_BOUNDS_BSZ)) = 0xBAADF00D;
519 #endif //MY_HEAP_CHECK_BOUNDS 521 Allocs[
i].
Len -= len2;
526 Allocs[
i].
Len = len2;
529 if(FrameList[Frame].FirstFree > (
ULONG)
i)
534 Allocs[
i+1].
Len += len2;
535 Allocs[
i+1].
Addr -= len2;
556 UDFPrint((
"Insufficient resources to allocate frame descriptor\n"));
565 if(!Allocs[0].Addr) {
566 UDFPrint((
"Insufficient resources to allocate frame\n"));
575 FrameList[Frame].
Frame = Allocs;
580 if(LastFrame < Frame)
591 if(!FrameList[Frame].Frame) {
599 if(LastFrame == Frame) {
601 for(
i=LastFrame;
i>0;
i--) {
602 if(FrameList[
i].Frame)
610 #ifndef MY_HEAP_TRACK_OWNERS 616 #ifdef MY_HEAP_TRACK_OWNERS
620 #ifdef MY_HEAP_TRACK_REF
632 #ifdef DUMP_MEM_FRAMES2 639 if( FrameList[
i].Frame &&
642 #ifdef MY_HEAP_TRACK_OWNERS
645 #ifdef MY_HEAP_TRACK_REF
660 UnlockMemoryManager();
665 #ifdef DUMP_MEM_FRAMES2 671 if(!(FrameList[
i].Frame)) {
672 MyAllocInitFrame(
type,
i);
673 if(FrameList[
i].Frame &&
675 #ifdef MY_HEAP_TRACK_OWNERS
678 #ifdef MY_HEAP_TRACK_REF
695 #ifdef DUMP_MEM_FRAMES2 701 UnlockMemoryManager();
715 for(
i=0;
i<=LastFrame;
i++) {
716 if( (Allocs = FrameList[
i].Frame) &&
736 i = MyFindFrameByAddr(
addr);
738 UnlockMemoryManager();
739 UDFPrint((
"Mem: <<<*** WARNING ***>>> Double deallocation at %x !!! ;( \n",
addr));
755 MyFreePoolInFrame(
i,
addr);
761 if(MyAllocIsFrameFree(FrameList,
i)) {
764 UnlockMemoryManager();
769 #ifndef MY_HEAP_TRACK_OWNERS 777 #ifdef MY_HEAP_TRACK_OWNERS
785 #ifdef MY_HEAP_TRACK_REF 791 if(OldLength ==
NewLength)
return OldLength;
799 i = MyFindFrameByAddr(
addr);
801 UnlockMemoryManager();
802 UDFPrint((
"Mem: <<<*** WARNING ***>>> Double deallocation at %x !!! ;( \n",
addr));
808 #ifdef MY_HEAP_TRACK_REF
812 #ifdef CHECK_ALLOC_FRAMES 818 UnlockMemoryManager();
823 #ifdef MY_HEAP_TRACK_OWNERS
826 #ifdef MY_HEAP_TRACK_REF
831 UnlockMemoryManager();
838 MyFreePoolInFrame(
i,
addr);
840 if(MyAllocIsFrameFree(FrameList,
i)) {
843 UnlockMemoryManager();
846 (*NewBuff) = new_buff;
853 MyFindMemDescByRangeInFrame(
865 Allocs = FrameList[Frame].
Frame;
871 if(!
right && FrameList[Frame].FirstFree)
875 curaddr = Allocs[
i].
Addr;
876 curlen = Allocs[
i].
Len;
890 if(Allocs[
i].Addr && (Allocs[
i].Addr < (
ULONG)
addr)) {
907 Frame = MyFindFrameByAddr(
addr);
909 UnlockMemoryManager();
910 UDFPrint((
"Mem: <<<*** WARNING ***>>> Unknown base for %x !!! ;( \n",
addr));
914 i = MyFindMemDescByRangeInFrame(Frame,
addr);
916 UnlockMemoryManager();
930 return (MyMemInitialized =
TRUE);
939 if(!MyMemInitialized)
943 if(Allocs = FrameList[
i].Frame) {
948 UnlockMemoryManager();
949 DeinitLockMemoryManager();
950 MyMemInitialized =
FALSE;
953 #endif //MY_USE_INTERNAL_MEMMANAGER
#define RtlMoveMemory(Destination, Source, Length)
static USHORT USHORT * NewLength
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
GLenum const GLvoid * addr
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define RtlZeroMemory(Destination, Length)
#define RtlCopyMemory(Destination, Source, Length)
GLuint GLuint GLsizei GLenum type
GLboolean GLboolean GLboolean GLboolean a