- Timestamp:
- Jul 15, 2002, 4:28:53 PM (23 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/heapcode.cpp
r5075 r8877 1 /* $Id: heapcode.cpp,v 1. 3 2001-02-09 18:31:05sandervl Exp $ */1 /* $Id: heapcode.cpp,v 1.4 2002-07-15 14:28:51 sandervl Exp $ */ 2 2 /* 3 3 * Code heap functions for OS/2 4 4 * 5 5 * Initially commit 4 kb, add more when required 6 * 7 * NOTE: If high memory is ever used for this heap, then you must use VirtualAlloc! 6 8 * 7 9 * TODO: Not process/thread safe (initializing/destroying heap) … … 22 24 #include "dbglocal.h" 23 25 24 Heap_t codeHeap = 0;25 static PVOID pCodeMem = NULL;26 Heap_t codeHeap = 0; 27 static PVOID pCodeMem = NULL; 26 28 27 29 void * _LNK_CONV getmoreCodeMem(Heap_t pHeap, size_t *size, int *clean); 28 void _LNK_CONV releaseCodeMem(Heap_t pHeap, void *block, size_t size);30 void _LNK_CONV releaseCodeMem(Heap_t pHeap, void *block, size_t size); 29 31 30 32 //****************************************************************************** … … 32 34 BOOL InitializeCodeHeap() 33 35 { 34 APIRET rc;36 APIRET rc; 35 37 36 dprintf(("KERNEL32: InitializeCodeHeap")); 37 rc = DosAllocMem(&pCodeMem, PAGE_SIZE, PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE); 38 if(rc != 0) { 39 dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc)); 40 return FALSE; 41 } 42 codeHeap = _ucreate(pCodeMem, PAGE_SIZE, _BLOCK_CLEAN, 43 _HEAP_REGULAR, getmoreCodeMem, releaseCodeMem); 44 if(codeHeap == NULL) { 45 DosFreeMem(pCodeMem); 38 dprintf(("KERNEL32: InitializeCodeHeap")); 39 40 //NOTE: MUST use 64kb here or else we are at risk of running out of virtual 41 // memory space. (when allocating 4kb we actually get 4kb + 60k uncommited) 42 rc = DosAllocMem(&pCodeMem, 64*1024, PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE); 43 if(rc != 0) { 44 dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc)); 45 return FALSE; 46 } 47 codeHeap = _ucreate(pCodeMem, PAGE_SIZE, _BLOCK_CLEAN, _HEAP_REGULAR, getmoreCodeMem, releaseCodeMem); 48 if(codeHeap == NULL) { 49 DosFreeMem(pCodeMem); 46 50 pCodeMem = NULL; 47 dprintf(("InitializeSharedHeap: _ucreate failed!"));48 return FALSE;49 }50 return TRUE;51 dprintf(("InitializeSharedHeap: _ucreate failed!")); 52 return FALSE; 53 } 54 return TRUE; 51 55 } 52 56 //****************************************************************************** … … 54 58 void DestroyCodeHeap() 55 59 { 56 dprintf(("KERNEL32: DestroyCodeHeap"));57 if(codeHeap) {58 _uclose(codeHeap);59 _udestroy(codeHeap, _FORCE);60 codeHeap = NULL;61 }62 if(pCodeMem) {63 DosFreeMem(pCodeMem);64 pCodeMem = NULL;65 }60 dprintf(("KERNEL32: DestroyCodeHeap")); 61 if(codeHeap) { 62 _uclose(codeHeap); 63 _udestroy(codeHeap, _FORCE); 64 codeHeap = NULL; 65 } 66 if(pCodeMem) { 67 DosFreeMem(pCodeMem); 68 pCodeMem = NULL; 69 } 66 70 } 67 71 //****************************************************************************** … … 69 73 void * _LNK_CONV getmoreCodeMem(Heap_t pHeap, size_t *size, int *clean) 70 74 { 71 APIRET rc;72 PVOID newblock;75 APIRET rc; 76 PVOID newblock; 73 77 74 dprintf(("KERNEL32: getmoreCodeMem(%08xh, %08xh, %08xh)\n", 75 pHeap, 76 *size, 77 *clean)); 78 dprintf(("KERNEL32: getmoreCodeMem(%08xh, %08xh, %08xh)\n", pHeap, *size, *clean)); 78 79 79 /* round the size up to a multiple of 4K */ 80 *size = (*size / 4096) * 4096 + 4096; 80 /* round the size up to a multiple of 64K */ 81 //NOTE: MUST use 64kb here or else we are at risk of running out of virtual 82 // memory space. (when allocating 4kb we actually get 4kb + 60k uncommited) 83 *size = ( (*size / 65536) + 1) * 65536; 81 84 82 rc = DosAllocMem(&newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE);83 if(rc != 0) {84 dprintf(("getmoreCodeMem: DosAllocMem failed with %d", rc));85 return FALSE;86 }87 *clean = _BLOCK_CLEAN;88 dprintf(("KERNEL32: getmoreCodeMem %x %d", newblock, *size));89 return newblock;85 rc = DosAllocMem(&newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE); 86 if(rc != 0) { 87 dprintf(("getmoreCodeMem: DosAllocMem failed with %d", rc)); 88 return FALSE; 89 } 90 *clean = _BLOCK_CLEAN; 91 dprintf(("KERNEL32: getmoreCodeMem %x %d", newblock, *size)); 92 return newblock; 90 93 } 91 94 //****************************************************************************** … … 93 96 void _LNK_CONV releaseCodeMem(Heap_t pHeap, void *block, size_t size) 94 97 { 95 dprintf(("KERNEL32: releaseCodeMem %x %d", block, size));96 DosFreeMem(block);98 dprintf(("KERNEL32: releaseCodeMem %x %d", block, size)); 99 DosFreeMem(block); 97 100 } 98 101 //****************************************************************************** -
trunk/src/kernel32/heapshared.cpp
r5564 r8877 1 /* $Id: heapshared.cpp,v 1. 8 2001-04-22 09:00:19sandervl Exp $ */1 /* $Id: heapshared.cpp,v 1.9 2002-07-15 14:28:51 sandervl Exp $ */ 2 2 /* 3 3 * Shared heap functions for OS/2 … … 39 39 BOOL InitializeSharedHeap() 40 40 { 41 APIRET rc;41 APIRET rc; 42 42 43 if(pSharedMem == NULL) { 44 rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE); 45 if(rc != 0) { 46 dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc)); 47 return FALSE; 48 } 49 rc = DosSetMem(pSharedMem, INCR_HEAPSIZE, PAG_READ|PAG_WRITE|PAG_COMMIT); 50 if(rc != 0) { 51 DosFreeMem(pSharedMem); 52 dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc)); 53 return FALSE; 54 } 55 sharedHeap = _ucreate(pSharedMem, INCR_HEAPSIZE, _BLOCK_CLEAN, 56 _HEAP_REGULAR|_HEAP_SHARED, 57 getmoreShared, releaseShared); 43 if(pSharedMem == NULL) { 44 rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE); 45 if(rc != 0) { 46 dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc)); 47 return FALSE; 48 } 49 rc = DosSetMem(pSharedMem, INCR_HEAPSIZE, PAG_READ|PAG_WRITE|PAG_COMMIT); 50 if(rc != 0) { 51 DosFreeMem(pSharedMem); 52 dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc)); 53 return FALSE; 54 } 55 sharedHeap = _ucreate(pSharedMem, INCR_HEAPSIZE, _BLOCK_CLEAN, _HEAP_REGULAR|_HEAP_SHARED, 56 getmoreShared, releaseShared); 58 57 59 if(sharedHeap == NULL) {60 DosFreeMem(pSharedMem);61 dprintf(("InitializeSharedHeap: _ucreate failed!"));62 return FALSE;63 }64 dprintf(("KERNEL32: First InitializeSharedHeap %x %x", pSharedMem, sharedHeap));65 for(int i=0;i<INCR_HEAPSIZE/PAGE_SIZE;i++) {66 pageBitmap[i] = 1; //mark as committed67 }68 }69 else {70 if(DosGetSharedMem(pSharedMem, PAG_READ|PAG_WRITE) != 0) {71 dprintf(("InitializeSharedHeap: DosGetSharedMem failed!"));72 return FALSE;73 }74 dprintf(("KERNEL32: InitializeSharedHeap %x %x refcount %d", pSharedMem, sharedHeap, refCount));75 if(_uopen(sharedHeap) != 0) {76 dprintf(("InitializeSharedHeap: unable to open shared heap!"));77 return FALSE;78 }79 }80 refCount++;81 return TRUE;58 if(sharedHeap == NULL) { 59 DosFreeMem(pSharedMem); 60 dprintf(("InitializeSharedHeap: _ucreate failed!")); 61 return FALSE; 62 } 63 dprintf(("KERNEL32: First InitializeSharedHeap %x %x", pSharedMem, sharedHeap)); 64 for(int i=0;i<INCR_HEAPSIZE/PAGE_SIZE;i++) { 65 pageBitmap[i] = 1; //mark as committed 66 } 67 } 68 else { 69 if(DosGetSharedMem(pSharedMem, PAG_READ|PAG_WRITE) != 0) { 70 dprintf(("InitializeSharedHeap: DosGetSharedMem failed!")); 71 return FALSE; 72 } 73 dprintf(("KERNEL32: InitializeSharedHeap %x %x refcount %d", pSharedMem, sharedHeap, refCount)); 74 if(_uopen(sharedHeap) != 0) { 75 dprintf(("InitializeSharedHeap: unable to open shared heap!")); 76 return FALSE; 77 } 78 } 79 refCount++; 80 return TRUE; 82 81 } 83 82 //****************************************************************************** … … 85 84 void DestroySharedHeap() 86 85 { 87 dprintf(("KERNEL32: DestroySharedHeap %d", refCount));88 if(--refCount == 0) {89 if(sharedHeap) {90 _uclose(sharedHeap);91 _udestroy(sharedHeap, _FORCE);92 sharedHeap = NULL;93 }94 if(pSharedMem) {95 DosFreeMem(pSharedMem);96 pSharedMem = NULL;97 }98 }99 else {100 _uclose(sharedHeap);101 }86 dprintf(("KERNEL32: DestroySharedHeap %d", refCount)); 87 if(--refCount == 0) { 88 if(sharedHeap) { 89 _uclose(sharedHeap); 90 _udestroy(sharedHeap, _FORCE); 91 sharedHeap = NULL; 92 } 93 if(pSharedMem) { 94 DosFreeMem(pSharedMem); 95 pSharedMem = NULL; 96 } 97 } 98 else { 99 _uclose(sharedHeap); 100 } 102 101 } 103 102 //****************************************************************************** … … 105 104 ULONG GetPageRangeFree(ULONG pageoffset) 106 105 { 107 dprintf(("KERNEL32: GetPageRangeFree(%08xh)\n", 108 pageoffset)); 106 dprintf(("KERNEL32: GetPageRangeFree(%08xh)", pageoffset)); 109 107 110 for(int i=pageoffset;i<MAX_HEAPPAGES;i++) {111 112 break;113 }114 }115 return i-pageoffset;108 for(int i=pageoffset;i<MAX_HEAPPAGES;i++) { 109 if(pageBitmap[i] == 1) { 110 break; 111 } 112 } 113 return i-pageoffset; 116 114 } 117 115 //****************************************************************************** … … 119 117 void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean) 120 118 { 121 APIRET rc;122 ULONG newsize;123 PVOID newblock;119 APIRET rc; 120 ULONG newsize; 121 PVOID newblock; 124 122 125 dprintf(("KERNEL32: getmoreShared(%08xh, %08xh, %08xh)\n", 126 pHeap, 127 *size, 128 *clean)); 123 dprintf(("KERNEL32: getmoreShared(%08xh, %08xh, %08xh)\n", pHeap, *size, *clean)); 129 124 130 /* round the size up to a multiple of 4K */131 // *size = (*size / 4096) * 4096 + 4096;132 // @@@PH speed improvement133 *size = (*size + 4096) & 0xFFFFF000;134 *size = max(*size, INCR_HEAPSIZE);125 /* round the size up to a multiple of 4K */ 126 // *size = (*size / 4096) * 4096 + 4096; 127 // @@@PH speed improvement 128 *size = (*size + 4096) & 0xFFFFF000; 129 *size = max(*size, INCR_HEAPSIZE); 135 130 136 for(int i=0;i<MAX_HEAPPAGES;i++)137 {138 int nrpagesfree = GetPageRangeFree(i);139 if(nrpagesfree >= *size/PAGE_SIZE) {140 newblock = (PVOID)((ULONG)pSharedMem + i*PAGE_SIZE);141 rc = DosSetMem(newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT);142 if(rc != 0) {143 dprintf(("getmoreShared: DosSetMem failed with %d", rc));144 return NULL;145 }146 for(int j=0;j < *size/PAGE_SIZE; j++)147 148 pageBitmap[i+j] = 1; //mark as committed149 }131 for(int i=0;i<MAX_HEAPPAGES;i++) 132 { 133 int nrpagesfree = GetPageRangeFree(i); 134 if(nrpagesfree >= *size/PAGE_SIZE) { 135 newblock = (PVOID)((ULONG)pSharedMem + i*PAGE_SIZE); 136 rc = DosSetMem(newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT); 137 if(rc != 0) { 138 dprintf(("getmoreShared: DosSetMem failed with %d", rc)); 139 return NULL; 140 } 141 for(int j=0;j < *size/PAGE_SIZE; j++) 142 { 143 pageBitmap[i+j] = 1; //mark as committed 144 } 150 145 151 *clean = _BLOCK_CLEAN;152 dprintf(("KERNEL32: getmoreShared %x %d", newblock, *size));153 return newblock;154 }155 if(nrpagesfree)156 i += nrpagesfree-1;157 }158 dprintf(("KERNEL32: getmoreShared NOTHING LEFT (%d)", *size));159 return NULL;146 *clean = _BLOCK_CLEAN; 147 dprintf(("KERNEL32: getmoreShared %x %d", newblock, *size)); 148 return newblock; 149 } 150 if(nrpagesfree) 151 i += nrpagesfree-1; 152 } 153 dprintf(("KERNEL32: getmoreShared NOTHING LEFT (%d)", *size)); 154 return NULL; 160 155 } 161 156 //****************************************************************************** … … 163 158 void _LNK_CONV releaseShared(Heap_t pHeap, void *block, size_t size) 164 159 { 165 ULONG pagenr;160 ULONG pagenr; 166 161 167 dprintf(("KERNEL32: releaseShared %x %d", block, size));168 DosSetMem(block, size, PAG_READ|PAG_WRITE|PAG_DECOMMIT);162 dprintf(("KERNEL32: releaseShared %x %d", block, size)); 163 DosSetMem(block, size, PAG_READ|PAG_WRITE|PAG_DECOMMIT); 169 164 170 pagenr = (ULONG)block - (ULONG)pSharedMem;171 pagenr /= PAGE_SIZE;172 for(int i=pagenr;i<pagenr+size/PAGE_SIZE;i++) {173 pageBitmap[i] = 0; //mark as decommitted174 }165 pagenr = (ULONG)block - (ULONG)pSharedMem; 166 pagenr /= PAGE_SIZE; 167 for(int i=pagenr;i<pagenr+size/PAGE_SIZE;i++) { 168 pageBitmap[i] = 0; //mark as decommitted 169 } 175 170 } 176 171 //****************************************************************************** … … 178 173 DWORD HeapGetSharedMemBase() 179 174 { 180 dprintf(("KERNEL32: HeapGetSharedMemBase()\n"));181 return (DWORD) pSharedMem;175 dprintf(("KERNEL32: HeapGetSharedMemBase()\n")); 176 return (DWORD) pSharedMem; 182 177 } 183 178 //****************************************************************************** -
trunk/src/kernel32/hmthread.cpp
r8648 r8877 1 /* $Id: hmthread.cpp,v 1.1 3 2002-06-11 16:36:53sandervl Exp $ */1 /* $Id: hmthread.cpp,v 1.14 2002-07-15 14:28:51 sandervl Exp $ */ 2 2 3 3 /* … … 13 13 * WaitForSingle/MultipleObjects needs to be rewritten! (not using 14 14 * Open32) 15 * 16 ************************************************************************************ 17 * NOTE: If we ever decide to allocate our own stack, then we MUST use VirtualAlloc!!!! 18 * (alignment reasons) 19 ************************************************************************************ 15 20 * 16 21 * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl) … … 77 82 cbStack = 1048576; // per default 1MB stack per thread 78 83 84 //************************************************************************************ 85 //NOTE: If we ever decide to allocate our own stack, then we MUST use VirtualAlloc!!!! 86 // (alignment reasons) 87 //************************************************************************************ 79 88 pHMHandleData->hHMHandle = O32_CreateThread(lpsa, cbStack, winthread->GetOS2Callback(), 80 89 (LPVOID)winthread, fdwCreate, lpIDThread); -
trunk/src/kernel32/mmap.cpp
r8659 r8877 1 /* $Id: mmap.cpp,v 1.5 7 2002-06-13 14:11:39sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.58 2002-07-15 14:28:51 sandervl Exp $ */ 2 2 3 3 /* … … 33 33 #include "mmap.h" 34 34 #include "oslibdos.h" 35 #include "oslibmem.h" 35 36 #include <winimagepeldr.h> 36 37 #include <custombuild.h> … … 610 611 Win32MemMapView *tmpview = mapviews; 611 612 612 errorState = 0;613 mParentMap = map;614 mSize = size;615 mOffset = offset;616 mProcessId = GetCurrentProcessId();617 pShareViewAddr = NULL;613 errorState = 0; 614 mParentMap = map; 615 mSize = size; 616 mOffset = offset; 617 mProcessId = GetCurrentProcessId(); 618 pShareViewAddr = NULL; 618 619 619 620 switch(fdwAccess) { 620 621 case FILE_MAP_READ: 621 accessAttr = PAG_READ;622 mfAccess = MEMMAP_ACCESS_READ;622 accessAttr = PAG_READ; 623 mfAccess = MEMMAP_ACCESS_READ; 623 624 break; 624 625 case FILE_MAP_ALL_ACCESS: … … 626 627 case FILE_MAP_WRITE|FILE_MAP_READ: 627 628 case FILE_MAP_COPY: 628 accessAttr = (PAG_READ|PAG_WRITE);629 mfAccess = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE;629 accessAttr = (PAG_READ|PAG_WRITE); 630 mfAccess = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE; 630 631 break; 631 632 } -
trunk/src/kernel32/os2heap.cpp
r7728 r8877 1 /* $Id: os2heap.cpp,v 1.3 2 2002-01-06 16:48:47sandervl Exp $ */1 /* $Id: os2heap.cpp,v 1.33 2002-07-15 14:28:51 sandervl Exp $ */ 2 2 3 3 /* … … 7 7 * 8 8 * 9 * NOTE: Do NOT use high memory here. Risky with 16 bits tcpip stack 10 * If this is ever changed, then you must use VirtualAlloc! 11 * 9 12 * NOTE: ReAlloc allocates memory using Alloc if memory pointer == NULL 10 13 * WINE controls depend on this, even though it apparently … … 64 67 OS2Heap::OS2Heap(DWORD flOptions, DWORD dwInitialSize, DWORD dwMaximumSize) 65 68 { 66 OS2Heap *curheap = OS2Heap::heap;69 OS2Heap *curheap = OS2Heap::heap; 67 70 68 71 #ifdef DEBUG 69 totalAlloc = 0; 70 #endif 71 fInitialized = 0; 72 nrHeaps = 0; 73 heapelem = NULL; 74 75 dwInitialSize = (dwInitialSize >= 0x4000) ? dwInitialSize : 0x4000; 76 77 this->dwMaximumSize = dwMaximumSize; 78 this->dwInitialSize = dwInitialSize; 79 this->flOptions = flOptions; 80 81 heaplistmutex.enter(); 82 if(curheap != NULL) { 72 totalAlloc = 0; 73 #endif 74 fInitialized = 0; 75 nrHeaps = 0; 76 heapelem = NULL; 77 78 /* round the size up to a multiple of 64K */ 79 //NOTE: MUST use 64kb here or else we are at risk of running out of virtual 80 // memory space. (when allocating 4kb we actually get 4kb + 60k uncommited) 81 dwInitialSize = ( (dwInitialSize / 65536) + 1) * 65536; 82 83 this->dwMaximumSize = dwMaximumSize; 84 this->dwInitialSize = dwInitialSize; 85 this->flOptions = flOptions; 86 87 heaplistmutex.enter(); 88 if(curheap != NULL) { 83 89 while(curheap->next != NULL) { 84 90 curheap = curheap->next; 85 91 } 86 92 curheap->next = this; 87 }88 else heap = this;89 next = NULL;90 91 heaplistmutex.leave();92 93 APIRET rc;94 95 rc = DosAllocMem((PPVOID)&pInitialHeapMem, dwInitialSize, PAG_READ|PAG_WRITE|PAG_COMMIT);96 if(rc != 0) {97 dprintf(("OS2Heap::OS2Heap: DosAllocSharedMem failed with %d", rc));93 } 94 else heap = this; 95 next = NULL; 96 97 heaplistmutex.leave(); 98 99 APIRET rc; 100 101 rc = DosAllocMem((PPVOID)&pInitialHeapMem, dwInitialSize, PAG_READ|PAG_WRITE|PAG_COMMIT); 102 if(rc != 0) { 103 dprintf(("OS2Heap::OS2Heap: DosAllocSharedMem failed with %d", rc)); 98 104 DebugInt3(); 99 }100 uheap = _ucreate(pInitialHeapMem, dwInitialSize, _BLOCK_CLEAN,101 _HEAP_REGULAR, getmoreHeapMem, releaseHeapMem);102 if(uheap == NULL) {103 DosFreeMem(pInitialHeapMem);105 } 106 uheap = _ucreate(pInitialHeapMem, dwInitialSize, _BLOCK_CLEAN, 107 _HEAP_REGULAR, getmoreHeapMem, releaseHeapMem); 108 if(uheap == NULL) { 109 DosFreeMem(pInitialHeapMem); 104 110 pInitialHeapMem = NULL; 105 dprintf(("OS2Heap::OS2Heap: _ucreate failed!"));111 dprintf(("OS2Heap::OS2Heap: _ucreate failed!")); 106 112 DebugInt3(); 107 }108 hPrimaryHeap = (HANDLE)uheap;109 dprintf(("KERNEL32: HeapCreate: initial size %d, max size %d (flags %X) returned %X\n", dwInitialSize, dwMaximumSize, flOptions, hPrimaryHeap));113 } 114 hPrimaryHeap = (HANDLE)uheap; 115 dprintf(("KERNEL32: HeapCreate: initial size %d, max size %d (flags %X) returned %X\n", dwInitialSize, dwMaximumSize, flOptions, hPrimaryHeap)); 110 116 } 111 117 //****************************************************************************** … … 113 119 OS2Heap::~OS2Heap() 114 120 { 115 OS2Heap *curheap = OS2Heap::heap; 116 int i; 117 118 // invalidate handle cache 119 fhhm_lastHandle = 0; 120 fhhm_lastHeap = NULL; 121 122 123 dprintf(("dtr OS2Heap, hPrimaryHeap = %X\n", hPrimaryHeap)); 124 125 heaplistmutex.enter(); 126 if(heap == this) { 121 OS2Heap *curheap = OS2Heap::heap; 122 int i; 123 124 // invalidate handle cache 125 fhhm_lastHandle = 0; 126 fhhm_lastHeap = NULL; 127 128 dprintf(("dtr OS2Heap, hPrimaryHeap = %X\n", hPrimaryHeap)); 129 130 heaplistmutex.enter(); 131 if(heap == this) { 127 132 heap = next; 128 }129 else {133 } 134 else { 130 135 while(curheap->next != NULL) { 131 136 if(curheap->next == this) { … … 135 140 curheap = curheap->next; 136 141 } 137 }138 heaplistmutex.leave();139 140 if(uheap) {141 _uclose(uheap);142 _udestroy(uheap, _FORCE);143 uheap = NULL;144 }145 if(pInitialHeapMem) {146 DosFreeMem(pInitialHeapMem);147 pInitialHeapMem = NULL;148 }149 150 dprintf(("dtr OS2Heap, hPrimaryHeap = %X done\n", hPrimaryHeap));142 } 143 heaplistmutex.leave(); 144 145 if(uheap) { 146 _uclose(uheap); 147 _udestroy(uheap, _FORCE); 148 uheap = NULL; 149 } 150 if(pInitialHeapMem) { 151 DosFreeMem(pInitialHeapMem); 152 pInitialHeapMem = NULL; 153 } 154 155 dprintf(("dtr OS2Heap, hPrimaryHeap = %X done\n", hPrimaryHeap)); 151 156 } 152 157 //****************************************************************************** … … 154 159 LPVOID OS2Heap::Alloc(DWORD dwFlags, DWORD dwBytes) 155 160 { 156 HEAPELEM *lpHeapObj;157 LPVOID lpMem;158 DWORD dwAllocBytes;161 HEAPELEM *lpHeapObj; 162 LPVOID lpMem; 163 DWORD dwAllocBytes; 159 164 160 165 // dprintf(("OS2Heap::Alloc\n")); 161 166 162 //size must be multiple of 8 bytes163 dwAllocBytes = HEAP_ALIGN(dwBytes);164 165 lpMem = _umalloc(uheap, dwAllocBytes + HEAP_OVERHEAD);166 if(lpMem == NULL) {167 dprintf(("OS2Heap::Alloc, lpMem == NULL"));168 return(NULL);169 }170 if(dwFlags & HEAP_ZERO_MEMORY) {171 memset(lpMem, 0, dwAllocBytes+HEAP_OVERHEAD);172 }167 //size must be multiple of 8 bytes 168 dwAllocBytes = HEAP_ALIGN(dwBytes); 169 170 lpMem = _umalloc(uheap, dwAllocBytes + HEAP_OVERHEAD); 171 if(lpMem == NULL) { 172 dprintf(("OS2Heap::Alloc, lpMem == NULL")); 173 return(NULL); 174 } 175 if(dwFlags & HEAP_ZERO_MEMORY) { 176 memset(lpMem, 0, dwAllocBytes+HEAP_OVERHEAD); 177 } 173 178 174 179 #ifdef DEBUG 175 totalAlloc += dwAllocBytes;176 #endif 177 178 //align at 8 byte boundary179 lpHeapObj = (HEAPELEM *)HEAP_ALIGN(lpMem);180 lpHeapObj->lpMem = lpMem;181 lpHeapObj->magic = MAGIC_NR_HEAP;182 lpHeapObj->orgsize = dwBytes; //original size183 lpHeapObj->cursize = dwBytes; //original size180 totalAlloc += dwAllocBytes; 181 #endif 182 183 //align at 8 byte boundary 184 lpHeapObj = (HEAPELEM *)HEAP_ALIGN(lpMem); 185 lpHeapObj->lpMem = lpMem; 186 lpHeapObj->magic = MAGIC_NR_HEAP; 187 lpHeapObj->orgsize = dwBytes; //original size 188 lpHeapObj->cursize = dwBytes; //original size 184 189 185 return(LPVOID)(lpHeapObj+1);190 return(LPVOID)(lpHeapObj+1); 186 191 } 187 192 //****************************************************************************** … … 189 194 DWORD OS2Heap::Size(DWORD dwFlags, PVOID lpMem) 190 195 { 191 HEAPELEM *helem = GET_HEAPOBJ(lpMem);192 193 if(lpMem == NULL) {196 HEAPELEM *helem = GET_HEAPOBJ(lpMem); 197 198 if(lpMem == NULL) { 194 199 dprintf(("OS2Heap::Size lpMem == NULL\n")); 195 200 return -1; 196 } 197 /* verify lpMem address */ 198 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000) 199 { 201 } 202 /* verify lpMem address */ 203 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000) 204 { 205 dprintf(("OS2Heap::Size ERROR BAD HEAP POINTER:%X\n", lpMem)); 206 return -1; 207 } 208 209 if(helem->magic != MAGIC_NR_HEAP) 210 { 200 211 dprintf(("OS2Heap::Size ERROR BAD HEAP POINTER:%X\n", lpMem)); 201 212 return -1; 202 } 203 204 if(helem->magic != MAGIC_NR_HEAP) 205 { 206 dprintf(("OS2Heap::Size ERROR BAD HEAP POINTER:%X\n", lpMem)); 207 return -1; 208 } 209 return helem->cursize; //return current size of memory block 213 } 214 return helem->cursize; //return current size of memory block 210 215 } 211 216 //****************************************************************************** … … 213 218 LPVOID OS2Heap::ReAlloc(DWORD dwFlags, LPVOID lpMem, DWORD dwBytes) 214 219 { 215 HEAPELEM *helem = GET_HEAPOBJ(lpMem);216 LPVOID lpNewMem;217 int i, maxSize;218 219 if (dwBytes == 0) return NULL; // intercept stupid parameters220 221 //NOTE: Allocate memory using Alloc -> WINE controls depend on this, even222 // though it apparently doesn't work in Windows.223 if (lpMem == 0) return Alloc(dwFlags, dwBytes);220 HEAPELEM *helem = GET_HEAPOBJ(lpMem); 221 LPVOID lpNewMem; 222 int i, maxSize; 223 224 if (dwBytes == 0) return NULL; // intercept stupid parameters 225 226 //NOTE: Allocate memory using Alloc -> WINE controls depend on this, even 227 // though it apparently doesn't work in Windows. 228 if (lpMem == 0) return Alloc(dwFlags, dwBytes); 224 229 // if (lpMem == 0) return NULL; 225 230 226 if (helem->magic != MAGIC_NR_HEAP)227 {228 dprintf(("OS2Heap::ReAlloc ERROR BAD HEAP POINTER:%X\n", lpMem));229 return lpMem;230 }231 232 maxSize = HEAP_ALIGN(helem->orgsize);233 if (dwBytes <= maxSize) {234 dprintf(("ReAlloc with smaller size than original (%d); return old pointer", maxSize));235 //update current size so HeapSize will return the right value236 helem->cursize = dwBytes;237 return lpMem; // if reallocation with same size don't do anything238 }239 lpNewMem = Alloc(dwFlags, dwBytes);240 memcpy(lpNewMem, lpMem, dwBytes < maxSize ? dwBytes : maxSize);241 Free(0, lpMem);242 243 if(lpNewMem == NULL)244 {245 dprintf(("OS2Heap::ReAlloc, no more memory left\n"));246 }247 248 return(lpNewMem);231 if (helem->magic != MAGIC_NR_HEAP) 232 { 233 dprintf(("OS2Heap::ReAlloc ERROR BAD HEAP POINTER:%X\n", lpMem)); 234 return lpMem; 235 } 236 237 maxSize = HEAP_ALIGN(helem->orgsize); 238 if (dwBytes <= maxSize) { 239 dprintf(("ReAlloc with smaller size than original (%d); return old pointer", maxSize)); 240 //update current size so HeapSize will return the right value 241 helem->cursize = dwBytes; 242 return lpMem; // if reallocation with same size don't do anything 243 } 244 lpNewMem = Alloc(dwFlags, dwBytes); 245 memcpy(lpNewMem, lpMem, dwBytes < maxSize ? dwBytes : maxSize); 246 Free(0, lpMem); 247 248 if(lpNewMem == NULL) 249 { 250 dprintf(("OS2Heap::ReAlloc, no more memory left\n")); 251 } 252 253 return(lpNewMem); 249 254 } 250 255 //****************************************************************************** … … 252 257 BOOL OS2Heap::Free(DWORD dwFlags, LPVOID lpMem) 253 258 { 254 HEAPELEM *helem = GET_HEAPOBJ(lpMem);255 256 /* verify lpMem address */257 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000)258 {259 HEAPELEM *helem = GET_HEAPOBJ(lpMem); 260 261 /* verify lpMem address */ 262 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000) 263 { 259 264 dprintf(("OS2Heap::Free ERROR BAD HEAP POINTER:%X\n", lpMem)); 260 265 return FALSE; 261 }262 263 if(helem->magic != MAGIC_NR_HEAP)264 {266 } 267 268 if(helem->magic != MAGIC_NR_HEAP) 269 { 265 270 dprintf(("OS2Heap::Free ERROR BAD HEAP POINTER:%X\n", lpMem)); 266 271 return FALSE; 267 }272 } 268 273 269 274 #ifdef DEBUG1 270 int size = Size(0, lpMem);271 dprintf(("OS2Heap::Free lpMem = %X, size %d\n", lpMem, size));275 int size = Size(0, lpMem); 276 dprintf(("OS2Heap::Free lpMem = %X, size %d\n", lpMem, size)); 272 277 #ifdef DEBUG 273 totalAlloc -= size;274 #endif 275 #endif 276 277 free(helem->lpMem);278 return(TRUE);278 totalAlloc -= size; 279 #endif 280 #endif 281 282 free(helem->lpMem); 283 return(TRUE); 279 284 } 280 285 //****************************************************************************** … … 282 287 DWORD OS2Heap::Compact(DWORD dwFlags) 283 288 { 284 dprintf(("OS2Heap::Compact, %X- stub\n", dwFlags));285 return(0);289 dprintf(("OS2Heap::Compact, %X- stub\n", dwFlags)); 290 return(0); 286 291 } 287 292 //****************************************************************************** … … 289 294 BOOL OS2Heap::Validate(DWORD dwFlags, LPCVOID lpMem) 290 295 { 291 HEAPELEM *helem = GET_HEAPOBJ(lpMem);292 293 dprintf(("OS2Heap::Validate, %X %X", dwFlags, lpMem));294 295 /* verify lpMem address */296 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000)297 {296 HEAPELEM *helem = GET_HEAPOBJ(lpMem); 297 298 dprintf(("OS2Heap::Validate, %X %X", dwFlags, lpMem)); 299 300 /* verify lpMem address */ 301 if (lpMem >= (LPVOID)ulMaxAddr || lpMem < (LPVOID)0x10000) 302 { 298 303 dprintf(("OS2Heap::Validate BAD HEAP POINTER:%X\n", lpMem)); 299 304 return FALSE; 300 }301 302 if(helem->magic != MAGIC_NR_HEAP)303 {305 } 306 307 if(helem->magic != MAGIC_NR_HEAP) 308 { 304 309 dprintf(("OS2Heap::Validate BAD HEAP POINTER:%X\n", lpMem)); 305 310 return FALSE; 306 }307 return(TRUE);311 } 312 return(TRUE); 308 313 } 309 314 //****************************************************************************** … … 311 316 BOOL OS2Heap::Walk(void *lpEntry) 312 317 { 313 dprintf(("OS2Heap::Walk, %X - stub? (TRUE)\n", lpEntry));314 return(TRUE);318 dprintf(("OS2Heap::Walk, %X - stub? (TRUE)\n", lpEntry)); 319 return(TRUE); 315 320 } 316 321 //****************************************************************************** … … 363 368 void * _LNK_CONV getmoreHeapMem(Heap_t pHeap, size_t *size, int *clean) 364 369 { 365 APIRET rc; 366 PVOID newblock; 367 368 dprintf(("KERNEL32: getmoreHeapMem(%08xh, %08xh, %08xh)", pHeap, *size, *clean)); 369 370 /* round the size up to a multiple of 64K */ 371 //NOTE: MUST use 64kb here or else we are at risk of running out of virtual 372 // memory space. (when allocating 4kb we actually get 4kb + 60k uncommited) 373 *size = ( (*size / 65536) + 1) * 65536; 374 375 rc = DosAllocMem(&newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE); 376 //// rc = DosAllocMem(&newblock, *size, flAllocMem|PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE); 377 if(rc != 0) { 378 dprintf(("getmoreHeapMem: DosAllocMem failed with %d", rc)); 379 return FALSE; 380 } 381 *clean = _BLOCK_CLEAN; 382 dprintf(("KERNEL32: getmoreHeapMem %x %d", newblock, *size)); 383 return newblock; 370 APIRET rc; 371 PVOID newblock; 372 373 dprintf(("KERNEL32: getmoreHeapMem(%08xh, %08xh, %08xh)", pHeap, *size, *clean)); 374 375 /* round the size up to a multiple of 64K */ 376 //NOTE: MUST use 64kb here or else we are at risk of running out of virtual 377 // memory space. (when allocating 4kb we actually get 4kb + 60k uncommited) 378 *size = ( (*size / 65536) + 1) * 65536; 379 380 rc = DosAllocMem(&newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT|PAG_EXECUTE); 381 if(rc != 0) { 382 dprintf(("getmoreHeapMem: DosAllocMem failed with %d", rc)); 383 return FALSE; 384 } 385 *clean = _BLOCK_CLEAN; 386 dprintf(("KERNEL32: getmoreHeapMem %x %d", newblock, *size)); 387 return newblock; 384 388 } 385 389 //****************************************************************************** … … 387 391 void _LNK_CONV releaseHeapMem(Heap_t pHeap, void *block, size_t size) 388 392 { 389 dprintf(("KERNEL32: releaseHeapMem %x %x %d", pHeap, block, size));390 DosFreeMem(block);391 } 392 //****************************************************************************** 393 //****************************************************************************** 393 dprintf(("KERNEL32: releaseHeapMem %x %x %d", pHeap, block, size)); 394 DosFreeMem(block); 395 } 396 //****************************************************************************** 397 //****************************************************************************** -
trunk/src/kernel32/oslibdos.h
r8600 r8877 1 /* $Id: oslibdos.h,v 1.4 6 2002-06-08 11:40:15sandervl Exp $ */1 /* $Id: oslibdos.h,v 1.47 2002-07-15 14:28:52 sandervl Exp $ */ 2 2 3 3 /* … … 22 22 void OSLibInitWSeBFileIO(); 23 23 24 DWORD OSLibDosAliasMem(LPVOID pb, ULONG cb, LPVOID *ppbAlias, ULONG fl);25 DWORD OSLibDosAllocMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags);26 DWORD OSLibDosFreeMem(LPVOID lpMemAddr);27 DWORD OSLibDosQueryMem(LPVOID lpMemAddr, DWORD *lpRangeSize, DWORD *lpAttr);28 DWORD OSLibDosSetMem(LPVOID lpMemAddr, DWORD size, DWORD flags);29 DWORD OSLibDosAllocSharedMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags, LPSTR name);30 DWORD OSLibDosGetNamedSharedMem(LPVOID *lplpMemAddr, LPSTR name);31 24 DWORD OSLibDosChangeMaxFileHandles(); 32 25 … … 41 34 #define OSLIB_ERROR_ACCESS_DENIED 2 42 35 #define OSLIB_ERROR_INVALID_PARAMETER 3 43 44 #ifndef __OS2_H__45 46 /* Access protection */47 #define PAG_READ 0x00000001U /* read access */48 #define PAG_WRITE 0x00000002U /* write access */49 #define PAG_EXECUTE 0x00000004U /* execute access */50 #define PAG_GUARD 0x00000008U /* guard protection */51 #define PAG_DEFAULT 0x00000400U /* default (initial) access */52 53 /* Commit */54 #define PAG_COMMIT 0x00000010U /* commit storage */55 #define PAG_DECOMMIT 0x00000020U /* decommit storage */56 57 /* Allocation attributes */58 #define OBJ_TILE 0x00000040U /* tile object */59 #define OBJ_PROTECTED 0x00000080U /* protect object */60 #define OBJ_GETTABLE 0x00000100U /* gettable by other processes */61 #define OBJ_GIVEABLE 0x00000200U /* giveable to other processes */62 63 /* Allocation type (returned from DosQueryMem) */64 #define PAG_SHARED 0x00002000U /* shared object */65 #define PAG_FREE 0x00004000U /* pages are free */66 #define PAG_BASE 0x00010000U /* first page in object */67 68 #endif69 36 70 37 #define OSLIB_ACCESS_READONLY 1 … … 144 111 DWORD OSLibDosDupHandle(DWORD hFile, DWORD *hNew); 145 112 DWORD OSLibDosSetFilePtr2(DWORD hFile, DWORD offset, DWORD method); 146 147 #ifndef PAGE_SIZE148 #define PAGE_SIZE 4096149 #endif150 113 151 114 BOOL OSLibDosQueryProcTimes(DWORD procid, ULONG *kerneltime, ULONG *usertime); -
trunk/src/kernel32/oslibmem.cpp
r8866 r8877 1 /* $Id: oslibmem.cpp,v 1. 2 2002-07-13 16:30:40sandervl Exp $ */1 /* $Id: oslibmem.cpp,v 1.3 2002-07-15 14:28:52 sandervl Exp $ */ 2 2 /* 3 3 * Wrappers for OS/2 Dos* API … … 35 35 #include "initterm.h" 36 36 #include "oslibdos.h" 37 #include "oslibmem.h" 37 38 #include "dosqss.h" 38 39 #include "win32k.h" … … 56 57 rc = DosQueryMem(pb, &size, &attr); 57 58 if(rc) { 58 dprintf((" OSLibDosAliasMem: DosQueryMem %x %x return %d", pb, size, rc));59 dprintf(("!ERROR!: OSLibDosAliasMem: DosQueryMem %x %x return %d", pb, size, rc)); 59 60 return rc; 60 61 } … … 62 63 size+= PAGE_SIZE; 63 64 if(size != cb) { 64 dprintf((" ERROR: OSLibDosAliasMem: size != cb (%x!=%x)!!!!!!!!", size, cb));65 dprintf(("!WARNING!: OSLibDosAliasMem: size != cb (%x!=%x)!!!!!!!!", size, cb)); 65 66 //ignore this and continue return 5; 66 67 attr = fl; //just use original protection flags (NOT CORRECT) … … 70 71 rc = DosSetMem(pb, size, fl); 71 72 if(rc) { 72 dprintf((" OSLibDosAliasMem: DosSetMem %x %x return %d", pb, size, rc));73 dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem %x %x return %d", pb, size, rc)); 73 74 attr = fl; 74 75 //just continue for now … … 78 79 rc = DosAliasMem(pb, cb, ppbAlias, 2); 79 80 if(rc) { 80 dprintf((" OSLibDosAliasMem: DosAliasMem %x %x returned %d", pb, cb, rc));81 dprintf(("!ERROR!: OSLibDosAliasMem: DosAliasMem %x %x returned %d", pb, cb, rc)); 81 82 return rc; 82 83 } … … 84 85 rc = DosSetMem(pb, size, attr); 85 86 if(rc) { 86 dprintf((" OSLibDosAliasMem: DosSetMem (2) %x %x return %d", pb, size, rc));87 dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem (2) %x %x return %d", pb, size, rc)); 87 88 return rc; 88 89 } … … 91 92 } 92 93 //****************************************************************************** 94 //Allocate memory aligned at 64kb boundary 93 95 //****************************************************************************** 94 96 DWORD OSLibDosAllocMem(LPVOID *lplpMemAddr, DWORD cbSize, DWORD flFlags) … … 114 116 rc = DosAllocMem(&pvMemAddr, cbSize, flFlags | flAllocMem); 115 117 if(rc) { 116 dprintf((" DosAllocMem failed with rc %d", rc));118 dprintf(("!ERROR!: DosAllocMem failed with rc %d", rc)); 117 119 return rc; 118 120 } 119 //TODO!!!!!!!!!!!!120 #if 0121 121 // already 64k aligned ? 122 if(( DWORD) pvMemAddr & 0xFFFF)122 if((ULONG) pvMemAddr & 0xFFFF) 123 123 { 124 DWORD addr64kb; 124 ULONG addr64kb; 125 126 //free misaligned allocated memory 127 DosFreeMem(pvMemAddr); 125 128 126 129 //Allocate 64kb more so we can round the address to a 64kb aligned value 127 rc = DosAllocMem((PPVOID)&addr64kb, cbSize + 64*1024, PAG_READ| flAllocMem);130 rc = DosAllocMem((PPVOID)&addr64kb, cbSize + 64*1024, (flFlags & ~PAG_COMMIT) | flAllocMem); 128 131 if(rc) { 129 dprintf((" DosAllocMem failed with rc %d", rc));132 dprintf(("!ERROR!: DosAllocMem failed with rc %d", rc)); 130 133 return rc; 131 134 } 135 dprintf(("Allocate aligned memory %x -> %x", addr64kb, (addr64kb + 0xFFFF) & ~0xFFFF)); 136 132 137 if(addr64kb & 0xFFFF) { 133 addr64kb = (addr64kb + 0xFFFF) &0xFFFF;138 addr64kb = (addr64kb + 0xFFFF) & ~0xFFFF; 134 139 } 135 140 pvMemAddr = (PVOID)addr64kb; 136 141 137 142 //and set the correct page flags for the request range 138 rc = DosSetMem(pvMemAddr, cbSize, flFlags | flAllocMem); 139 } 140 #endif 143 if((flFlags & ~PAG_COMMIT) != flFlags) { 144 rc = DosSetMem(pvMemAddr, cbSize, flFlags); 145 if(rc) { 146 dprintf(("!ERROR!: DosSetMem failed with rc %d", rc)); 147 return rc; 148 } 149 } 150 } 151 141 152 if(!rc) 142 153 *lplpMemAddr = pvMemAddr; … … 145 156 } 146 157 //****************************************************************************** 158 //Locate the base page of a memory allocation (the page with the PAG_BASE attribute) 159 //****************************************************************************** 160 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr) 161 { 162 ULONG ulAttr, ulSize, ulAddr; 163 APIRET rc; 164 165 rc = DosQueryMem(lpMemAddr, &ulSize, &ulAttr); 166 if(rc != NO_ERROR) { 167 dprintf(("!ERROR!: OSLibDosFindMemBase: DosQueryMem %x failed with rc %d", lpMemAddr, rc)); 168 return lpMemAddr; 169 } 170 if(!(ulAttr & PAG_BASE)) { 171 //Not the base of the initial allocation (can happen due to alignment) or app 172 //passing address inside memory allocation range 173 ulAddr = (DWORD)lpMemAddr & ~0xFFF; 174 ulAddr -= PAGE_SIZE; 175 176 while(ulAddr > 0) 177 { 178 rc = DosQueryMem((PVOID)ulAddr, &ulSize, &ulAttr); 179 if(rc) { 180 dprintf(("!ERROR!: OSLibDosFindMemBase: DosQueryMem %x failed with rc %d", lpMemAddr, rc)); 181 DebugInt3(); 182 return NULL; 183 } 184 if(ulAttr & PAG_BASE) { 185 //Memory below the 512 MB boundary is always aligned at 64kb and VirtualAlloc only 186 //returns high memory (if OS/2 version supports it) 187 //If it is above the 512 MB boundary, then we must make sure the right base address 188 //is returned. VirtualAlloc allocates extra memory to make sure it can return addresses 189 //aligned at 64kb. If extra pages are needed, then the allocation base is inside 190 //the filler region. In that case we must return the next 64kb address as base. 191 if(ulAddr > MEM_TILED_CEILING) { 192 ulAddr = (ulAddr + 0xFFFF) & ~0xFFFF; 193 } 194 lpMemAddr = (PVOID)ulAddr; 195 break; 196 } 197 ulAddr -= PAGE_SIZE; 198 } 199 } 200 return lpMemAddr; 201 } 202 //****************************************************************************** 147 203 //****************************************************************************** 148 204 DWORD OSLibDosFreeMem(LPVOID lpMemAddr) 149 205 { 206 ULONG ulAttr, ulSize, ulAddr; 207 APIRET rc; 208 209 ulAddr = (DWORD)lpMemAddr & ~0xFFF; 210 211 //Find base within previous 64kb (alignment can add filler pages) 212 for(int i=0;i<16;i++) { 213 rc = DosQueryMem((PVOID)ulAddr, &ulSize, &ulAttr); 214 if(rc != NO_ERROR) { 215 dprintf(("!ERROR!: OSLibDosFreeMem: DosQueryMem %x failed with rc %d", lpMemAddr, rc)); 216 i = 16; //fail 217 break; 218 } 219 if(ulAttr & PAG_BASE) { 220 break; 221 } 222 ulAddr -= PAGE_SIZE; 223 } 224 if(i == 16) { 225 //oh, oh. didn't find base; shouldn't happen!! 226 dprintf(("!ERROR!: OSLibDosFreeMem: Unable to find base of %x", lpMemAddr)); 227 DebugInt3(); 228 } 229 else { 230 lpMemAddr = (PVOID)ulAddr; 231 } 150 232 return DosFreeMem(lpMemAddr); 151 233 } -
trunk/src/kernel32/virtual.cpp
r8866 r8877 1 /* $Id: virtual.cpp,v 1.4 7 2002-07-13 16:30:40sandervl Exp $ */1 /* $Id: virtual.cpp,v 1.48 2002-07-15 14:28:52 sandervl Exp $ */ 2 2 3 3 /* … … 28 28 #include "mmap.h" 29 29 #include "oslibdos.h" 30 #include "oslibmem.h" 30 31 31 32 #define DBG_LOCALLOG DBG_virtual … … 270 271 DWORD fdwProtect) 271 272 { 272 PVOID Address = lpvAddress;273 ULONG flag = 0, base;274 DWORD rc;275 276 SetLastError(ERROR_SUCCESS);277 278 if (cbSize > 0x7fc00000) /* 2Gb - 4Mb */279 {280 dprintf(("VirtualAlloc: size too large"));273 PVOID Address = lpvAddress; 274 ULONG flag = 0, base; 275 DWORD rc; 276 277 SetLastError(ERROR_SUCCESS); 278 279 if (cbSize > 0x7fc00000) /* 2Gb - 4Mb */ 280 { 281 dprintf(("VirtualAlloc: size too large")); 281 282 SetLastError( ERROR_OUTOFMEMORY ); 282 283 return NULL; 283 }284 285 if (!(fdwAllocationType & (MEM_COMMIT | MEM_RESERVE)) ||284 } 285 286 if (!(fdwAllocationType & (MEM_COMMIT | MEM_RESERVE)) || 286 287 (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE))) 287 {288 { 288 289 dprintf(("VirtualAlloc: Invalid parameter")); 289 290 SetLastError( ERROR_INVALID_PARAMETER ); 290 291 return NULL; 291 }292 293 if(fdwAllocationType & MEM_COMMIT)294 {292 } 293 294 if(fdwAllocationType & MEM_COMMIT) 295 { 295 296 dprintf(("VirtualAlloc: commit\n")); 296 297 flag = PAG_COMMIT; 297 }298 299 if(fdwAllocationType & MEM_RESERVE) {300 //SvL: DosRead crashes if memory is initially reserved with write298 } 299 300 if(fdwAllocationType & MEM_RESERVE) { 301 //SvL: DosRead crashes if memory is initially reserved with write 301 302 // access disabled (OS/2 bug) even if the commit sets the page 302 303 // flags to read/write: 303 // DosSetMem does not alter the 16 bit selectors so if you change memory304 // attributes and then access the memory with a 16 bit API (such as DosRead),305 // it will have the old (alloc time) attributes306 flag |= PAG_READ|PAG_WRITE;307 }308 if(fdwProtect & PAGE_READONLY) flag |= PAG_READ;309 if(fdwProtect & PAGE_NOACCESS) flag |= PAG_READ; //can't do this in OS/2310 if(fdwProtect & PAGE_READWRITE) flag |= (PAG_READ | PAG_WRITE);311 if(fdwProtect & PAGE_WRITECOPY) flag |= (PAG_READ | PAG_WRITE);312 313 if(fdwProtect & PAGE_EXECUTE_READWRITE) flag |= (PAG_EXECUTE | PAG_WRITE | PAG_READ);314 if(fdwProtect & PAGE_EXECUTE_READ) flag |= (PAG_EXECUTE | PAG_READ);315 if(fdwProtect & PAGE_EXECUTE) flag |= PAG_EXECUTE;316 317 if(fdwProtect & PAGE_GUARD) {304 // DosSetMem does not alter the 16 bit selectors so if you change memory 305 // attributes and then access the memory with a 16 bit API (such as DosRead), 306 // it will have the old (alloc time) attributes 307 flag |= PAG_READ|PAG_WRITE; 308 } 309 if(fdwProtect & PAGE_READONLY) flag |= PAG_READ; 310 if(fdwProtect & PAGE_NOACCESS) flag |= PAG_READ; //can't do this in OS/2 311 if(fdwProtect & PAGE_READWRITE) flag |= (PAG_READ | PAG_WRITE); 312 if(fdwProtect & PAGE_WRITECOPY) flag |= (PAG_READ | PAG_WRITE); 313 314 if(fdwProtect & PAGE_EXECUTE_READWRITE) flag |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 315 if(fdwProtect & PAGE_EXECUTE_READ) flag |= (PAG_EXECUTE | PAG_READ); 316 if(fdwProtect & PAGE_EXECUTE) flag |= PAG_EXECUTE; 317 318 if(fdwProtect & PAGE_GUARD) { 318 319 dprintf(("ERROR: PAGE_GUARD bit set for VirtualAlloc -> we don't support this right now!")); 319 320 flag |= PAG_GUARD; 320 } 321 322 //just do this if other options are used 323 if(!(flag & (PAG_READ | PAG_WRITE | PAG_EXECUTE)) || flag == 0) 324 { 325 dprintf(("VirtualAlloc: Unknown protection flags, default to read/write")); 326 flag |= PAG_READ | PAG_WRITE; 327 } 328 329 if(lpvAddress) 330 { 331 Win32MemMap *map; 332 ULONG offset, nrpages, accessflags = 0; 321 } 333 322 334 nrpages = cbSize >> PAGE_SHIFT; 335 if(cbSize & 0xFFF) 336 nrpages++; 337 338 if(flag & PAG_READ) { 339 accessflags |= MEMMAP_ACCESS_READ; 340 } 341 if(flag & PAG_WRITE) { 342 accessflags |= MEMMAP_ACCESS_WRITE; 343 } 344 if(flag & PAG_EXECUTE) { 345 accessflags |= MEMMAP_ACCESS_EXECUTE; 346 } 347 map = Win32MemMapView::findMapByView((ULONG)lpvAddress, &offset, accessflags); 348 if(map) { 349 //TODO: We don't allow protection flag changes for mmaped files now 350 map->commitPage(offset, FALSE, nrpages); 351 return lpvAddress; 352 } 353 } 354 355 // commit memory 356 if(fdwAllocationType & MEM_COMMIT) 357 { 358 Address = lpvAddress; 359 360 rc = OSLibDosSetMem(lpvAddress, cbSize, flag); 361 362 //might try to commit larger part with same base address 363 if(rc == OSLIB_ERROR_ACCESS_DENIED && cbSize > 4096 ) 364 { //knut: AND more than one page 365 char *newbase = (char *)lpvAddress + ((cbSize-1) & 0xFFFFF000); //knut: lets not start after the last page! 366 ULONG size, os2flags; 367 368 while(newbase >= (char *)lpvAddress) 369 { //knut: should check first page to!! 370 size = 4096; 371 os2flags = 0; 372 rc = OSLibDosQueryMem(newbase, &size, &os2flags); 373 if(rc) 374 break; 375 376 if(os2flags & PAG_COMMIT) 323 //just do this if other options are used 324 if(!(flag & (PAG_READ | PAG_WRITE | PAG_EXECUTE)) || flag == 0) 325 { 326 dprintf(("VirtualAlloc: Unknown protection flags, default to read/write")); 327 flag |= PAG_READ | PAG_WRITE; 328 } 329 330 if(lpvAddress) 331 { 332 Win32MemMap *map; 333 ULONG offset, nrpages, accessflags = 0; 334 335 nrpages = cbSize >> PAGE_SHIFT; 336 if(cbSize & 0xFFF) 337 nrpages++; 338 339 if(flag & PAG_READ) { 340 accessflags |= MEMMAP_ACCESS_READ; 341 } 342 if(flag & PAG_WRITE) { 343 accessflags |= MEMMAP_ACCESS_WRITE; 344 } 345 if(flag & PAG_EXECUTE) { 346 accessflags |= MEMMAP_ACCESS_EXECUTE; 347 } 348 map = Win32MemMapView::findMapByView((ULONG)lpvAddress, &offset, accessflags); 349 if(map) { 350 //TODO: We don't allow protection flag changes for mmaped files now 351 map->commitPage(offset, FALSE, nrpages); 352 return lpvAddress; 353 } 354 } 355 356 // commit memory 357 if(fdwAllocationType & MEM_COMMIT) 358 { 359 Address = lpvAddress; 360 361 rc = OSLibDosSetMem(lpvAddress, cbSize, flag); 362 363 //might try to commit larger part with same base address 364 if(rc == OSLIB_ERROR_ACCESS_DENIED && cbSize > 4096 ) 365 { //knut: AND more than one page 366 char *newbase = (char *)lpvAddress + ((cbSize-1) & 0xFFFFF000); //knut: lets not start after the last page! 367 ULONG size, os2flags; 368 369 while(newbase >= (char *)lpvAddress) 370 { //knut: should check first page to!! 371 size = 4096; 372 os2flags = 0; 373 rc = OSLibDosQueryMem(newbase, &size, &os2flags); 374 if(rc) 375 break; 376 377 if(os2flags & PAG_COMMIT) 378 { 379 newbase += 4096; 380 break; 381 } 382 newbase -= 4096; 383 } 384 385 if(rc == 0) 377 386 { 378 newbase += 4096; 379 break; 387 //In case it wants to commit bytes that fall into the last 388 //page of the previous commit command 389 if(cbSize > ((int)newbase - (int)lpvAddress)) 390 rc = OSLibDosSetMem(newbase, cbSize - ((int)newbase - (int)lpvAddress), flag); 380 391 } 381 newbase -= 4096; 382 } 383 384 if(rc == 0) 392 else return(NULL); 393 } 394 else 385 395 { 386 //In case it wants to commit bytes that fall into the last 387 //page of the previous commit command 388 if(cbSize > ((int)newbase - (int)lpvAddress)) 389 rc = OSLibDosSetMem(newbase, cbSize - ((int)newbase - (int)lpvAddress), flag); 390 } 391 else return(NULL); 392 393 } 394 else 395 { 396 if(rc == OSLIB_ERROR_INVALID_ADDRESS) { 397 rc = OSLibDosAllocMem(&Address, cbSize, flag ); 398 } 399 else { 400 if(rc) { 401 //check if the app tries to commit an already commited part of memory or change the protection flags 402 ULONG size = cbSize, os2flags, newrc; 403 newrc = OSLibDosQueryMem(lpvAddress, &size, &os2flags); 404 if(newrc == 0) { 405 if(size >= cbSize && (os2flags & PAG_COMMIT)) { 406 dprintf(("VirtualAlloc: commit on committed memory")); 407 if((flag & (PAG_READ|PAG_WRITE|PAG_EXECUTE)) != (os2flags & (PAG_READ|PAG_WRITE|PAG_EXECUTE))) 408 { //change protection flags 409 DWORD tmp; 410 if(VirtualProtect(lpvAddress, cbSize, fdwProtect, &tmp) == TRUE) { 411 return lpvAddress; 396 if(rc == OSLIB_ERROR_INVALID_ADDRESS) { 397 rc = OSLibDosAllocMem(&Address, cbSize, flag ); 398 } 399 else { 400 if(rc) { 401 //check if the app tries to commit an already commited part of memory or change the protection flags 402 ULONG size = cbSize, os2flags, newrc; 403 newrc = OSLibDosQueryMem(lpvAddress, &size, &os2flags); 404 if(newrc == 0) { 405 if(size >= cbSize && (os2flags & PAG_COMMIT)) { 406 dprintf(("VirtualAlloc: commit on committed memory")); 407 if((flag & (PAG_READ|PAG_WRITE|PAG_EXECUTE)) != (os2flags & (PAG_READ|PAG_WRITE|PAG_EXECUTE))) 408 { //change protection flags 409 DWORD tmp; 410 if(VirtualProtect(lpvAddress, cbSize, fdwProtect, &tmp) == TRUE) { 411 return lpvAddress; 412 } 413 dprintf(("ERROR: VirtualAlloc: commit on committed memory -> VirtualProtect failed!!")); 414 return NULL; 412 415 } 413 dprintf(("ERROR: VirtualAlloc: commit on committed memory -> VirtualProtect failed!!")); 414 return NULL; 415 } 416 //else everything ok 417 return lpvAddress; 416 //else everything ok 417 return lpvAddress; 418 } 419 else dprintf(("Unexpected DosSetMem error %x", rc)); 418 420 } 419 else dprintf(("Unexpected DosSetMem error %x", rc)); 420 } 421 else { 422 dprintf(("Unexpected DosQueryMem error %x", newrc)); 421 else { 422 dprintf(("Unexpected DosQueryMem error %x", newrc)); 423 } 423 424 } 424 425 } 425 426 } 426 427 } 427 } 428 else 429 { 430 rc = OSLibDosAllocMem(&Address, cbSize, flag); 431 } 432 433 if(rc) 434 { 435 dprintf(("DosSetMem returned %d\n", rc)); 436 SetLastError( ERROR_OUTOFMEMORY ); 437 return(NULL); 438 } 439 440 dprintf(("VirtualAlloc returned %X\n", Address)); 441 return(Address); 428 else 429 { 430 rc = OSLibDosAllocMem(&Address, cbSize, flag); 431 } 432 433 if(rc) 434 { 435 dprintf(("DosSetMem returned %d\n", rc)); 436 SetLastError( ERROR_OUTOFMEMORY ); 437 return(NULL); 438 } 439 440 dprintf(("VirtualAlloc returned %X\n", Address)); 441 return(Address); 442 442 } 443 443 //****************************************************************************** … … 665 665 // flags used in the initial call to VirtualAlloc 666 666 pmbiBuffer->AllocationProtect = pmbiBuffer->Protect; 667 if(dAttr & PAG_BASE) { 668 pmbiBuffer->AllocationBase = lpBase; 669 } 670 else 671 { 672 pmbiBuffer->AllocationBase = 0; 673 while(lpBase > 0) 674 { 675 rc = OSLibDosQueryMem(lpBase, &cbRangeSize, &dAttr); 676 if(rc) { 677 dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d\n", 678 lpBase, cbLength, rc)); 679 break; 680 } 681 if(dAttr & PAG_BASE) { 682 pmbiBuffer->AllocationBase = lpBase; 683 break; 684 } 685 lpBase = (LPVOID)((ULONG)lpBase - PAGE_SIZE); 686 } 687 } 688 #if 0 689 //TODO!!!!!!!!!!!! 690 //NOTE: !!!!!!!!!!!!!!!!!!!!!!! 691 //Allocation base is always aligned at 64kb 692 //the page with the PAG_BASE attribute might not be the real allocation base 693 //(due to extra alloc + rounding (see oslibmem.cpp) 694 //Only exception to this rule is the stack 695 TEB *teb = GetThreadTEB(); 696 if(teb) { 697 if(pmbiBuffer->AllocationBase >= teb->stack_low && pmbiBuffer->AllocationBase < teb->stack_top) { 698 pmbiBuffer->AllocationBase = pmbiBuffer->AllocationBase; 699 } 700 else pmbiBuffer->AllocationBase = (LPVOID)(((DWORD)pmbiBuffer->AllocationBase + 0xFFFF) & 0xFFFF); 701 } 702 else pmbiBuffer->AllocationBase = (LPVOID)(((DWORD)pmbiBuffer->AllocationBase + 0xFFFF) & 0xFFFF); 703 //END NOTE: !!!!!!!!!!!!!!!!!!! 704 #endif 667 pmbiBuffer->AllocationBase = OSLibDosFindMemBase(lpBase); 705 668 706 669 dprintf(("Memory region alloc base 0x%08x", pmbiBuffer->AllocationBase)); -
trunk/src/kernel32/winexedummy.cpp
r7797 r8877 1 /* $Id: winexedummy.cpp,v 1. 1 2002-02-03 13:16:22sandervl Exp $ */1 /* $Id: winexedummy.cpp,v 1.2 2002-07-15 14:28:53 sandervl Exp $ */ 2 2 3 3 /* … … 25 25 #include <win32api.h> 26 26 #include <wprocess.h> 27 #include "initterm.h" 27 28 28 29 //****************************************************************************** … … 31 32 BOOL WIN32API RegisterDummyExe(LPSTR pszExeName) 32 33 { 33 if(WinExe != NULL) //should never happen34 if(WinExe != NULL) //should never happen 34 35 delete(WinExe); 35 36 36 Win32DummyExe *winexe;37 Win32DummyExe *winexe; 37 38 38 winexe = new Win32DummyExe(pszExeName);39 winexe = new Win32DummyExe(pszExeName); 39 40 40 if(winexe) {41 if(winexe) { 41 42 InitCommandLine(FALSE); 42 winexe->start();43 }44 else {43 winexe->start(); 44 } 45 else { 45 46 eprintf(("Win32DummyExe creation failed!\n")); 46 47 DebugInt3(); 47 return FALSE;48 }49 return TRUE;48 return FALSE; 49 } 50 return TRUE; 50 51 } 51 52 //****************************************************************************** … … 55 56 Win32ExeBase(-1), header(0) 56 57 { 57 dprintf(("Win32DummyExe ctor: %s", pszExeName));58 hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI);59 strcpy(szModule, pszExeName);60 strcpy(szFileName, pszExeName);61 setFullPath(pszExeName);58 dprintf(("Win32DummyExe ctor: %s", pszExeName)); 59 hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI); 60 strcpy(szModule, pszExeName); 61 strcpy(szFileName, pszExeName); 62 setFullPath(pszExeName); 62 63 } 63 64 //****************************************************************************** … … 65 66 Win32DummyExe::~Win32DummyExe() 66 67 { 67 if(header) {68 DosFreeMem(header);69 }68 if(header) { 69 DosFreeMem(header); 70 } 70 71 } 71 72 //****************************************************************************** … … 92 93 DWORD Subsystem) 93 94 { 94 APIRET rc;95 IMAGE_DOS_HEADER *pdosheader;96 PIMAGE_OPTIONAL_HEADER poh;97 PIMAGE_FILE_HEADER pfh;98 DWORD *ntsig;95 APIRET rc; 96 IMAGE_DOS_HEADER *pdosheader; 97 PIMAGE_OPTIONAL_HEADER poh; 98 PIMAGE_FILE_HEADER pfh; 99 DWORD *ntsig; 99 100 100 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT);101 if(rc) {102 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));101 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT | flAllocMem); 102 if(rc) { 103 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc)); 103 104 DebugInt3(); 104 return NULL;105 }106 memcpy(header, dosHeader, sizeof(dosHeader));107 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader));108 *ntsig = IMAGE_NT_SIGNATURE;109 pfh = (PIMAGE_FILE_HEADER)(ntsig+1);110 pfh->Machine = IMAGE_FILE_MACHINE_I386;111 pfh->NumberOfSections = 0;112 pfh->TimeDateStamp = 0x3794f60f;113 pfh->PointerToSymbolTable = 0;114 pfh->NumberOfSymbols = 0;115 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);116 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |117 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |118 IMAGE_FILE_RELOCS_STRIPPED;119 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1);120 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;121 poh->MajorLinkerVersion = 0x3;122 poh->MinorLinkerVersion = 0xA;123 poh->SizeOfCode = 0;124 poh->SizeOfInitializedData = 0;125 poh->SizeOfUninitializedData = 0;126 poh->AddressOfEntryPoint = 0;127 poh->BaseOfCode = 0;128 poh->BaseOfData = 0;129 poh->ImageBase = 0;130 poh->SectionAlignment = 4096;131 poh->FileAlignment = 512;132 poh->MajorOperatingSystemVersion = MajorImageVersion;133 poh->MinorOperatingSystemVersion = MinorImageVersion;134 poh->MajorImageVersion = MajorImageVersion;135 poh->MinorImageVersion = MinorImageVersion;136 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION;137 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION;138 poh->Reserved1 = 0;139 poh->SizeOfImage = 0;140 poh->SizeOfHeaders = 1024;141 poh->CheckSum = 0;142 poh->Subsystem = Subsystem;143 poh->DllCharacteristics = 0;144 poh->SizeOfStackReserve = 1*1024*1024;145 poh->SizeOfStackCommit = 4096;146 poh->SizeOfHeapReserve = 1*1024*1024;147 poh->SizeOfHeapCommit = 4096;148 poh->LoaderFlags = 0;149 poh->NumberOfRvaAndSizes = 0;105 return NULL; 106 } 107 memcpy(header, dosHeader, sizeof(dosHeader)); 108 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader)); 109 *ntsig = IMAGE_NT_SIGNATURE; 110 pfh = (PIMAGE_FILE_HEADER)(ntsig+1); 111 pfh->Machine = IMAGE_FILE_MACHINE_I386; 112 pfh->NumberOfSections = 0; 113 pfh->TimeDateStamp = 0x3794f60f; 114 pfh->PointerToSymbolTable = 0; 115 pfh->NumberOfSymbols = 0; 116 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER); 117 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE | 118 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | 119 IMAGE_FILE_RELOCS_STRIPPED; 120 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1); 121 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC; 122 poh->MajorLinkerVersion = 0x3; 123 poh->MinorLinkerVersion = 0xA; 124 poh->SizeOfCode = 0; 125 poh->SizeOfInitializedData = 0; 126 poh->SizeOfUninitializedData = 0; 127 poh->AddressOfEntryPoint = 0; 128 poh->BaseOfCode = 0; 129 poh->BaseOfData = 0; 130 poh->ImageBase = 0; 131 poh->SectionAlignment = 4096; 132 poh->FileAlignment = 512; 133 poh->MajorOperatingSystemVersion = MajorImageVersion; 134 poh->MinorOperatingSystemVersion = MinorImageVersion; 135 poh->MajorImageVersion = MajorImageVersion; 136 poh->MinorImageVersion = MinorImageVersion; 137 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION; 138 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION; 139 poh->Reserved1 = 0; 140 poh->SizeOfImage = 0; 141 poh->SizeOfHeaders = 1024; 142 poh->CheckSum = 0; 143 poh->Subsystem = Subsystem; 144 poh->DllCharacteristics = 0; 145 poh->SizeOfStackReserve = 1*1024*1024; 146 poh->SizeOfStackCommit = 4096; 147 poh->SizeOfHeapReserve = 1*1024*1024; 148 poh->SizeOfHeapCommit = 4096; 149 poh->LoaderFlags = 0; 150 poh->NumberOfRvaAndSizes = 0; 150 151 // poh->DataDirectory[0] 151 152 152 return header;153 return header; 153 154 } 154 155 //****************************************************************************** -
trunk/src/kernel32/winimagelx.cpp
r7797 r8877 1 /* $Id: winimagelx.cpp,v 1.1 4 2002-02-03 13:16:22sandervl Exp $ */1 /* $Id: winimagelx.cpp,v 1.15 2002-07-15 14:28:53 sandervl Exp $ */ 2 2 3 3 /* … … 66 66 : Win32ImageBase(hInstance), header(0) 67 67 { 68 APIRET rc;69 char *name;68 APIRET rc; 69 char *name; 70 70 71 szFileName[0] = 0;71 szFileName[0] = 0; 72 72 73 if(lpszCustomDllName) {73 if(lpszCustomDllName) { 74 74 name = lpszCustomDllName; 75 75 this->dwOrdinalBase = ::dwOrdinalBase; 76 }77 else {76 } 77 else { 78 78 name = OSLibGetDllName(hinstance); 79 79 this->dwOrdinalBase = 0; 80 }80 } 81 81 82 strcpy(szFileName, name);83 strupr(szFileName);82 strcpy(szFileName, name); 83 strupr(szFileName); 84 84 85 setFullPath(szFileName);85 setFullPath(szFileName); 86 86 87 //Pointer to PE resource tree generates by wrc (or NULL for system dlls)88 pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;87 //Pointer to PE resource tree generates by wrc (or NULL for system dlls) 88 pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)pResData; 89 89 90 //ulRVAResourceSection contains the virtual address of the imagebase in the PE header91 //for the resource section (images loaded by the pe.exe)92 //For LX images, this is 0 as OffsetToData contains a relative offset93 ulRVAResourceSection = 0;90 //ulRVAResourceSection contains the virtual address of the imagebase in the PE header 91 //for the resource section (images loaded by the pe.exe) 92 //For LX images, this is 0 as OffsetToData contains a relative offset 93 ulRVAResourceSection = 0; 94 94 } 95 95 //****************************************************************************** … … 97 97 Win32LxImage::~Win32LxImage() 98 98 { 99 if(header) {100 DosFreeMem(header);101 }99 if(header) { 100 DosFreeMem(header); 101 } 102 102 } 103 103 //****************************************************************************** … … 105 105 ULONG Win32LxImage::getApi(char *name) 106 106 { 107 APIRET rc;108 ULONG apiaddr;107 APIRET rc; 108 ULONG apiaddr; 109 109 110 rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr);111 if(rc)112 {113 dprintf(("Win32LxImage::getApi %x %s -> rc = %d", hinstanceOS2, name, rc));114 return(0);115 }116 return(apiaddr);110 rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr); 111 if(rc) 112 { 113 dprintf(("Win32LxImage::getApi %x %s -> rc = %d", hinstanceOS2, name, rc)); 114 return(0); 115 } 116 return(apiaddr); 117 117 } 118 118 //****************************************************************************** … … 120 120 ULONG Win32LxImage::getApi(int ordinal) 121 121 { 122 APIRET rc;123 ULONG apiaddr;122 APIRET rc; 123 ULONG apiaddr; 124 124 125 rc = DosQueryProcAddr(hinstanceOS2, dwOrdinalBase+ordinal, NULL, (PFN *)&apiaddr);126 if(rc) {127 dprintf(("Win32LxImage::getApi %x %d -> rc = %d", hinstanceOS2, ordinal, rc));128 return(0);129 }130 return(apiaddr);125 rc = DosQueryProcAddr(hinstanceOS2, dwOrdinalBase+ordinal, NULL, (PFN *)&apiaddr); 126 if(rc) { 127 dprintf(("Win32LxImage::getApi %x %d -> rc = %d", hinstanceOS2, ordinal, rc)); 128 return(0); 129 } 130 return(apiaddr); 131 131 } 132 132 //****************************************************************************** … … 135 135 DWORD Subsystem) 136 136 { 137 APIRET rc;138 IMAGE_DOS_HEADER *pdosheader;139 PIMAGE_OPTIONAL_HEADER poh;140 PIMAGE_FILE_HEADER pfh;141 DWORD *ntsig;137 APIRET rc; 138 IMAGE_DOS_HEADER *pdosheader; 139 PIMAGE_OPTIONAL_HEADER poh; 140 PIMAGE_FILE_HEADER pfh; 141 DWORD *ntsig; 142 142 143 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT);144 if(rc) {145 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));143 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT | flAllocMem); 144 if(rc) { 145 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc)); 146 146 DebugInt3(); 147 return NULL;148 }149 memcpy(header, dosHeader, sizeof(dosHeader));150 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader));151 *ntsig = IMAGE_NT_SIGNATURE;152 pfh = (PIMAGE_FILE_HEADER)(ntsig+1);153 pfh->Machine = IMAGE_FILE_MACHINE_I386;154 pfh->NumberOfSections = 0;155 pfh->TimeDateStamp = 0x3794f60f;156 pfh->PointerToSymbolTable = 0;157 pfh->NumberOfSymbols = 0;158 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);159 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |160 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |161 IMAGE_FILE_RELOCS_STRIPPED;162 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1);163 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;164 poh->MajorLinkerVersion = 0x3;165 poh->MinorLinkerVersion = 0xA;166 poh->SizeOfCode = 0;167 poh->SizeOfInitializedData = 0;168 poh->SizeOfUninitializedData = 0;169 poh->AddressOfEntryPoint = 0;170 poh->BaseOfCode = 0;171 poh->BaseOfData = 0;172 poh->ImageBase = 0;173 poh->SectionAlignment = 4096;174 poh->FileAlignment = 512;175 poh->MajorOperatingSystemVersion = MajorImageVersion;176 poh->MinorOperatingSystemVersion = MinorImageVersion;177 poh->MajorImageVersion = MajorImageVersion;178 poh->MinorImageVersion = MinorImageVersion;179 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION;180 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION;181 poh->Reserved1 = 0;182 poh->SizeOfImage = 0;183 poh->SizeOfHeaders = 1024;184 poh->CheckSum = 0;185 poh->Subsystem = Subsystem;186 poh->DllCharacteristics = 0;187 poh->SizeOfStackReserve = 1*1024*1024;188 poh->SizeOfStackCommit = 4096;189 poh->SizeOfHeapReserve = 1*1024*1024;190 poh->SizeOfHeapCommit = 4096;191 poh->LoaderFlags = 0;192 poh->NumberOfRvaAndSizes = 0;147 return NULL; 148 } 149 memcpy(header, dosHeader, sizeof(dosHeader)); 150 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader)); 151 *ntsig = IMAGE_NT_SIGNATURE; 152 pfh = (PIMAGE_FILE_HEADER)(ntsig+1); 153 pfh->Machine = IMAGE_FILE_MACHINE_I386; 154 pfh->NumberOfSections = 0; 155 pfh->TimeDateStamp = 0x3794f60f; 156 pfh->PointerToSymbolTable = 0; 157 pfh->NumberOfSymbols = 0; 158 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER); 159 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE | 160 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | 161 IMAGE_FILE_RELOCS_STRIPPED; 162 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1); 163 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC; 164 poh->MajorLinkerVersion = 0x3; 165 poh->MinorLinkerVersion = 0xA; 166 poh->SizeOfCode = 0; 167 poh->SizeOfInitializedData = 0; 168 poh->SizeOfUninitializedData = 0; 169 poh->AddressOfEntryPoint = 0; 170 poh->BaseOfCode = 0; 171 poh->BaseOfData = 0; 172 poh->ImageBase = 0; 173 poh->SectionAlignment = 4096; 174 poh->FileAlignment = 512; 175 poh->MajorOperatingSystemVersion = MajorImageVersion; 176 poh->MinorOperatingSystemVersion = MinorImageVersion; 177 poh->MajorImageVersion = MajorImageVersion; 178 poh->MinorImageVersion = MinorImageVersion; 179 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION; 180 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION; 181 poh->Reserved1 = 0; 182 poh->SizeOfImage = 0; 183 poh->SizeOfHeaders = 1024; 184 poh->CheckSum = 0; 185 poh->Subsystem = Subsystem; 186 poh->DllCharacteristics = 0; 187 poh->SizeOfStackReserve = 1*1024*1024; 188 poh->SizeOfStackCommit = 4096; 189 poh->SizeOfHeapReserve = 1*1024*1024; 190 poh->SizeOfHeapCommit = 4096; 191 poh->LoaderFlags = 0; 192 poh->NumberOfRvaAndSizes = 0; 193 193 // poh->DataDirectory[0] 194 194 195 return header;195 return header; 196 196 } 197 197 //****************************************************************************** -
trunk/src/kernel32/winimagepeldr.cpp
r7811 r8877 1 /* $Id: winimagepeldr.cpp,v 1.9 5 2002-02-06 16:33:39sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.96 2002-07-15 14:28:53 sandervl Exp $ */ 2 2 3 3 /* … … 53 53 #include <win\virtual.h> 54 54 #include "oslibdos.h" 55 #include "oslibmem.h" 55 56 #include "mmap.h" 56 57 #include <wprocess.h> … … 159 160 160 161 if(realBaseAddress) 161 DosFreeMem((PVOID)realBaseAddress);162 OSLibDosFreeMem((PVOID)realBaseAddress); 162 163 163 164 if(nameexports) … … 924 925 return allocFixedMem(reservedMem); 925 926 } 926 rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ | PAG_WRITE | flAllocMem);927 rc = OSLibDosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ | PAG_WRITE); 927 928 if(rc) { 928 929 dprintf((LOG, "Win32PeLdrImage::allocSections, DosAllocMem returned %d", rc)); … … 1011 1012 } 1012 1013 while(TRUE) { 1013 rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ | allocFlags);1014 rc = OSLibDosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ | allocFlags); 1014 1015 if(rc) break; 1015 1016 … … 1017 1018 if(address + FALLOC_SIZE >= oh.ImageBase) { 1018 1019 if(address > oh.ImageBase) {//we've passed it! 1019 DosFreeMem((PVOID)address);1020 OSLibDosFreeMem((PVOID)address); 1020 1021 break; 1021 1022 } 1022 1023 //found the right address 1023 DosFreeMem((PVOID)address);1024 OSLibDosFreeMem((PVOID)address); 1024 1025 1025 1026 diff = oh.ImageBase - address; 1026 1027 if(diff) { 1027 rc = DosAllocMem((PPVOID)&address, diff, PAG_READ | allocFlags);1028 rc = OSLibDosAllocMem((PPVOID)&address, diff, PAG_READ | allocFlags); 1028 1029 if(rc) break; 1029 1030 } 1030 rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ | PAG_WRITE | allocFlags);1031 rc = OSLibDosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ | PAG_WRITE | allocFlags); 1031 1032 if(rc) break; 1032 1033 1033 if(diff) DosFreeMem((PVOID)address);1034 if(diff) OSLibDosFreeMem((PVOID)address); 1034 1035 1035 1036 realBaseAddress = baseAddress; … … 1039 1040 } 1040 1041 for(i=0;i<alloccnt;i++) { 1041 DosFreeMem((PVOID)memallocs[i]);1042 OSLibDosFreeMem((PVOID)memallocs[i]); 1042 1043 } 1043 1044 free(memallocs);
Note:
See TracChangeset
for help on using the changeset viewer.