Changeset 97907 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Dec 29, 2022 6:33:45 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 154997
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/alloc-win.cpp
r96407 r97907 56 56 57 57 58 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF59 {60 RT_NOREF_PV(pszTag);61 62 /*63 * Allocate first.64 */65 AssertMsg(cb, ("Allocating ZERO bytes is really not a good idea! Good luck with the next assertion!\n"));66 #ifdef USE_VIRTUAL_ALLOC67 cb = RT_ALIGN_Z(cb, PAGE_SIZE);68 void *pv = VirtualAlloc(NULL, cb, MEM_COMMIT, PAGE_EXECUTE_READWRITE);69 AssertMsg(pv, ("VirtualAlloc(%zx) failed!!!\n", cb));70 #else71 cb = RT_ALIGN_Z(cb, 32);72 void *pv = malloc(cb);73 AssertMsg(pv, ("malloc(%d) failed!!!\n", cb));74 if (pv)75 {76 memset(pv, 0xcc, cb);77 void *pvProt = (void *)((uintptr_t)pv & ~(uintptr_t)PAGE_OFFSET_MASK);78 size_t cbProt = ((uintptr_t)pv & PAGE_OFFSET_MASK) + cb;79 cbProt = RT_ALIGN_Z(cbProt, PAGE_SIZE);80 DWORD fFlags = 0;81 if (!VirtualProtect(pvProt, cbProt, PAGE_EXECUTE_READWRITE, &fFlags))82 {83 AssertMsgFailed(("VirtualProtect(%p, %#x,,) -> lasterr=%d\n", pvProt, cbProt, GetLastError()));84 free(pv);85 pv = NULL;86 }87 }88 #endif89 return pv;90 }91 92 93 RTDECL(void) RTMemExecFree(void *pv, size_t cb) RT_NO_THROW_DEF94 {95 RT_NOREF_PV(cb);96 97 if (pv)98 #ifdef USE_VIRTUAL_ALLOC99 if (!VirtualFree(pv, 0, MEM_RELEASE))100 AssertMsgFailed(("pv=%p lasterr=%d\n", pv, GetLastError()));101 #else102 free(pv);103 #endif104 }105 106 107 58 RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF 108 59 {
Note:
See TracChangeset
for help on using the changeset viewer.