Changeset 95818 in vbox for trunk/src/VBox
- Timestamp:
- Jul 25, 2022 2:48:00 PM (2 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r95815 r95818 2274 2274 r3/win/nocrt-RTLogWriteStdOut-win.cpp 2275 2275 RuntimeGuestR3_SOURCES.x86 += \ 2276 r3/win/nocrt-atexit.asm \ 2277 r3/win/nocrt-mainCRTStartup.asm \ 2278 r3/win/nocrt-stack.asm \ 2276 2279 common/string/memcpy.asm \ 2277 2280 common/string/memchr.asm \ … … 2285 2288 common/string/strcpy.asm 2286 2289 RuntimeGuestR3_SOURCES.amd64 += \ 2290 r3/win/nocrt-atexit.asm \ 2291 r3/win/nocrt-mainCRTStartup.asm \ 2292 r3/win/nocrt-stack.asm \ 2287 2293 common/string/memcpy.asm \ 2288 2294 common/string/memchr.asm \ -
trunk/src/VBox/Runtime/r3/alloc-ef.cpp
r93115 r95818 36 36 #include <VBox/sup.h> 37 37 #include <iprt/errcore.h> 38 #include <errno.h> 39 #include <stdio.h> 40 #include <stdlib.h> 38 #ifndef IPRT_NO_CRT 39 # include <errno.h> 40 # include <stdio.h> 41 # include <stdlib.h> 42 #endif 41 43 42 44 #include <iprt/alloc.h> -
trunk/src/VBox/Runtime/r3/init.cpp
r95806 r95818 89 89 static bool volatile g_fInitializing = false; 90 90 91 #if !defined(IPRT_NO_CRT) || !defined(RT_OS_WINDOWS) 91 92 /** The process path. 92 93 * This is used by RTPathExecDir and RTProcGetExecutablePath and set by rtProcInitName. */ … … 94 95 /** The length of g_szrtProcExePath. */ 95 96 DECL_HIDDEN_DATA(size_t) g_cchrtProcExePath; 97 /** The offset of the process name into g_szrtProcExePath. */ 98 DECL_HIDDEN_DATA(size_t) g_offrtProcName; 99 #endif 96 100 /** The length of directory path component of g_szrtProcExePath. */ 97 101 DECL_HIDDEN_DATA(size_t) g_cchrtProcDir; 98 /** The offset of the process name into g_szrtProcExePath. */99 DECL_HIDDEN_DATA(size_t) g_offrtProcName;100 102 101 103 /** The IPRT init flags. */ -
trunk/src/VBox/Runtime/r3/win/nocrt-alloc-win.cpp
r95802 r95818 104 104 } 105 105 106 107 #undef RTMemReallocZTag108 RTDECL(void *) RTMemReallocZTag(void *pvOld, size_t cbOld, size_t cbNew, const char *pszTag)109 {110 RT_NOREF(pszTag, cbOld);111 if (pvOld)112 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pvOld, cbNew);113 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNew);114 }115 -
trunk/src/VBox/Runtime/r3/win/nocrt-startup-exe-win.cpp
r93115 r95818 41 41 #include <iprt/utf16.h> 42 42 43 #ifdef IPRT_NO_CRT 44 # include <iprt/asm.h> 45 # include <iprt/nocrt/stdlib.h> 46 #endif 47 48 49 /********************************************************************************************************************************* 50 * Structures and Typedefs * 51 *********************************************************************************************************************************/ 52 #ifdef IPRT_NO_CRT 53 typedef struct RTNOCRTATEXITCHUNK 54 { 55 PFNRTNOCRTATEXITCALLBACK apfnCallbacks[256]; 56 } RTNOCRTATEXITCHUNK; 57 #endif 58 43 59 44 60 /********************************************************************************************************************************* … … 52 68 RT_C_DECLS_END 53 69 70 #ifdef IPRT_NO_CRT 71 /** The first atexit() registration chunk. */ 72 static RTNOCRTATEXITCHUNK g_aAtExitPrealloc; 73 /** Array of atexit() callback chunk pointers. */ 74 static RTNOCRTATEXITCHUNK *g_apAtExit[8192 / 256] = { &g_aAtExitPrealloc, }; 75 /** Chunk and callback index in one. */ 76 static volatile uint32_t g_idxNextAtExit = 0; 77 #endif 78 54 79 55 80 /********************************************************************************************************************************* … … 60 85 extern int main(int argc, char **argv, char **envp); /* in program */ 61 86 87 88 #ifdef IPRT_NO_CRT 89 extern "C" 90 int rtnocrt_atexit(PFNRTNOCRTATEXITCALLBACK pfnCallback) RT_NOEXCEPT 91 { 92 AssertPtr(pfnCallback); 93 94 /* 95 * Allocate a table index. 96 */ 97 uint32_t idx = ASMAtomicIncU32(&g_idxNextAtExit) - 1; 98 AssertReturnStmt(idx < RT_ELEMENTS(g_apAtExit) * RT_ELEMENTS(g_apAtExit[0]->apfnCallbacks), 99 ASMAtomicDecU32(&g_idxNextAtExit), -1); 100 101 /* 102 * Make sure the table chunk is there. 103 */ 104 uint32_t idxChunk = idx / RT_ELEMENTS(g_apAtExit[0]->apfnCallbacks); 105 RTNOCRTATEXITCHUNK *pChunk = ASMAtomicReadPtrT(&g_apAtExit[idxChunk], RTNOCRTATEXITCHUNK *); 106 if (!pChunk) 107 { 108 pChunk = (RTNOCRTATEXITCHUNK *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pChunk)); 109 AssertReturn(pChunk, -1); /* don't try decrement, someone could be racing us... */ 110 111 if (!ASMAtomicCmpXchgPtr(&g_apAtExit[idxChunk], pChunk, NULL)) 112 { 113 HeapFree(GetProcessHeap(), 0, pChunk); 114 115 pChunk = ASMAtomicReadPtrT(&g_apAtExit[idxChunk], RTNOCRTATEXITCHUNK *); 116 Assert(pChunk); 117 } 118 } 119 120 /* 121 * Add our callback. 122 */ 123 pChunk->apfnCallbacks[idxChunk % RT_ELEMENTS(pChunk->apfnCallbacks)] = pfnCallback; 124 return 0; 125 } 126 #endif 127 128 129 static int rtTerminateProcess(int32_t rcExit, bool fDoAtExit) 130 { 131 #ifdef IPRT_NO_CRT 132 /* 133 * Run atexit callback in reverse order. 134 */ 135 if (fDoAtExit) 136 { 137 uint32_t idxAtExit = ASMAtomicReadU32(&g_idxNextAtExit); 138 if (idxAtExit-- > 0) 139 { 140 uint32_t idxChunk = idxAtExit / RT_ELEMENTS(g_apAtExit[0]->apfnCallbacks); 141 uint32_t idxCallback = idxAtExit % RT_ELEMENTS(g_apAtExit[0]->apfnCallbacks); 142 for (;;) 143 { 144 RTNOCRTATEXITCHUNK *pChunk = ASMAtomicReadPtrT(&g_apAtExit[idxChunk], RTNOCRTATEXITCHUNK *); 145 if (pChunk) 146 { 147 do 148 { 149 PFNRTNOCRTATEXITCALLBACK pfnCallback = pChunk->apfnCallbacks[idxCallback]; 150 if (pfnCallback) /* Can be NULL see registration code */ 151 pfnCallback(); 152 } while (idxCallback-- > 0); 153 } 154 if (idxChunk == 0) 155 break; 156 idxChunk--; 157 idxCallback = RT_ELEMENTS(g_apAtExit[0]->apfnCallbacks) - 1; 158 } 159 } 160 } 161 #else 162 RT_NOREF(fDoAtExit); 163 #endif 164 165 /* 166 * Terminate. 167 */ 168 for (;;) 169 NtTerminateProcess(NtCurrentProcess(), rcExit); 170 } 62 171 63 172 … … 79 188 } 80 189 else 81 RTMsgError ExitFailure("initProcExecPath: RTUtf16ToUtf8Ex failed: %Rrc\n", rc);190 RTMsgError("initProcExecPath: RTUtf16ToUtf8Ex failed: %Rrc\n", rc); 82 191 } 83 192 else 84 RTMsgError ExitFailure("initProcExecPath: GetModuleFileNameW failed: %Rhrc\n", GetLastError());85 } 86 87 88 voidCustomMainEntrypoint(PPEB pPeb)193 RTMsgError("initProcExecPath: GetModuleFileNameW failed: %Rhrc\n", GetLastError()); 194 } 195 196 197 DECLASM(void) CustomMainEntrypoint(PPEB pPeb) 89 198 { 90 199 /* … … 114 223 * Call the main function. 115 224 */ 225 AssertCompile(sizeof(rcExit) == sizeof(int)); 116 226 rcExit = (RTEXITCODE)main(cArgs, papszArgv, NULL /*envp*/); 117 227 } … … 125 235 rcExit = RTMsgErrorExitFailure("No command line\n"); 126 236 127 for (;;) 128 NtTerminateProcess(NtCurrentProcess(), rcExit); 129 } 130 237 rtTerminateProcess(rcExit, true /*fDoAtExit*/); 238 } 239
Note:
See TracChangeset
for help on using the changeset viewer.