- Timestamp:
- Jul 1, 2011 3:41:37 PM (13 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/vboxmouse/undefined_15
r33338 r37733 49 49 lseek64 50 50 malloc 51 nanosleep 51 52 memalign 52 53 memchr -
trunk/src/VBox/Additions/x11/vboxmouse/undefined_70
r33338 r37733 60 60 lseek64 61 61 malloc 62 nanosleep 62 63 memalign 63 64 memchr -
trunk/src/VBox/Additions/x11/vboxmouse/undefined_71
r33338 r37733 63 63 lseek64 64 64 malloc 65 nanosleep 65 66 memalign 66 67 memchr -
trunk/src/VBox/Additions/x11/vboxvideo/undefined
r35949 r37733 68 68 lseek64 69 69 malloc 70 nanosleep 70 71 memalign 71 72 memchr -
trunk/src/VBox/Runtime/Makefile.kmk
r37560 r37733 568 568 r3/win/rtFileNativeSetAttributes-win.cpp \ 569 569 r3/win/thread-win.cpp \ 570 r3/win/thread2-win.cpp \ 570 571 r3/win/time-win.cpp \ 571 572 r3/win/timer-win.cpp \ … … 635 636 r3/posix/symlink-posix.cpp \ 636 637 r3/posix/thread-posix.cpp \ 638 r3/posix/thread2-posix.cpp \ 637 639 r3/posix/timelocal-posix.cpp \ 638 640 r3/posix/timer-posix.cpp \ … … 786 788 r3/posix/symlink-posix.cpp \ 787 789 r3/posix/thread-posix.cpp \ 790 r3/posix/thread2-posix.cpp \ 788 791 r3/posix/timelocal-posix.cpp \ 789 792 r3/posix/tls-posix.cpp \ … … 849 852 r3/posix/symlink-posix.cpp \ 850 853 r3/posix/thread-posix.cpp \ 854 r3/posix/thread2-posix.cpp \ 851 855 r3/posix/time-posix.cpp \ 852 856 r3/posix/timelocal-posix.cpp \ … … 906 910 r3/posix/symlink-posix.cpp \ 907 911 r3/posix/thread-posix.cpp \ 912 r3/posix/thread2-posix.cpp \ 908 913 r3/posix/time-posix.cpp \ 909 914 r3/posix/timelocal-posix.cpp \ … … 1076 1081 RuntimeGuestR3Mini_DEFS := \ 1077 1082 $(filter-out RTCRITSECT_STRICT RT_NO_GIP RT_WITH_ICONV_CACHE, $(RuntimeR3_DEFS)) \ 1078 RT_MINI IN_RT_STATIC 1083 RT_MINI IN_RT_STATIC RTMEM_NO_WRAP_TO_EF_APIS 1079 1084 RuntimeGuestR3Mini_DEFS.$(KBUILD_TARGET) := $(RuntimeR3_DEFS.$(KBUILD_TARGET)) 1080 1085 RuntimeGuestR3Mini_DEFS.$(KBUILD_HOST) := $(RuntimeR3_DEFS.$(KBUILD_HOST)) … … 1159 1164 r3/posix/path2-posix.cpp \ 1160 1165 r3/posix/utf8-posix.cpp \ 1166 r3/posix/thread2-posix.cpp \ 1161 1167 common/err/errmsgxpcom.cpp 1162 1168 RuntimeGuestR3Mini_SOURCES.linux = \ … … 1170 1176 r3/posix/path2-posix.cpp \ 1171 1177 r3/posix/utf8-posix.cpp \ 1178 r3/posix/thread2-posix.cpp \ 1172 1179 common/err/errmsgxpcom.cpp 1173 1180 RuntimeGuestR3Mini_SOURCES.solaris = \ … … 1181 1188 r3/posix/path2-posix.cpp \ 1182 1189 r3/posix/utf8-posix.cpp \ 1190 r3/posix/thread2-posix.cpp \ 1183 1191 common/err/errmsgxpcom.cpp 1184 1192 RuntimeGuestR3Mini_SOURCES.win = \ … … 1187 1195 r3/win/path-win.cpp \ 1188 1196 r3/win/utf8-win.cpp \ 1197 r3/win/thread2-win.cpp \ 1189 1198 win/errmsgwin.cpp \ 1190 1199 win/RTErrConvertFromWin32.cpp -
trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp
r37154 r37733 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 53 53 #include <iprt/assert.h> 54 54 #include <iprt/asm.h> 55 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)56 # include <iprt/asm-amd64-x86.h>57 #endif58 55 #include <iprt/err.h> 59 56 #include <iprt/string.h> … … 315 312 316 313 317 RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)318 {319 return (RTNATIVETHREAD)pthread_self();320 }321 322 323 RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)324 {325 LogFlow(("RTThreadSleep: cMillies=%d\n", cMillies));326 if (!cMillies)327 {328 /* pthread_yield() isn't part of SuS, thus this fun. */329 #ifdef RT_OS_DARWIN330 pthread_yield_np();331 #elif defined(RT_OS_FREEBSD) /* void pthread_yield */332 pthread_yield();333 #elif defined(RT_OS_SOLARIS)334 sched_yield();335 #else336 if (!pthread_yield())337 #endif338 {339 LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));340 return VINF_SUCCESS;341 }342 }343 else344 {345 struct timespec ts;346 struct timespec tsrem = {0,0};347 348 ts.tv_nsec = (cMillies % 1000) * 1000000;349 ts.tv_sec = cMillies / 1000;350 if (!nanosleep(&ts, &tsrem))351 {352 LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));353 return VINF_SUCCESS;354 }355 }356 357 int rc = RTErrConvertFromErrno(errno);358 LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", rc, cMillies));359 return rc;360 }361 362 363 RTDECL(bool) RTThreadYield(void)364 {365 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)366 uint64_t u64TS = ASMReadTSC();367 #endif368 #ifdef RT_OS_DARWIN369 pthread_yield_np();370 #elif defined(RT_OS_SOLARIS)371 sched_yield();372 #else373 pthread_yield();374 #endif375 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)376 u64TS = ASMReadTSC() - u64TS;377 bool fRc = u64TS > 1500;378 LogFlow(("RTThreadYield: returning %d (%llu ticks)\n", fRc, u64TS));379 #else380 bool fRc = true; /* PORTME: Add heuristics for determining whether the cpus was yielded. */381 #endif382 return fRc;383 }384 385 386 314 #ifdef RTTHREAD_POSIX_WITH_POKE 387 315 RTDECL(int) RTThreadPoke(RTTHREAD hThread) -
trunk/src/VBox/Runtime/r3/posix/thread2-posix.cpp
r37729 r37733 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Threads , POSIX.3 * IPRT - Threads part 2, POSIX. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #include <errno.h> 33 33 #include <pthread.h> 34 #include <signal.h> 35 #if defined(RT_OS_LINUX) 36 # include <unistd.h> 37 # include <sys/syscall.h> 38 #endif 34 #include <unistd.h> 39 35 #if defined(RT_OS_SOLARIS) 40 36 # include <sched.h> 41 # include <sys/resource.h>42 #endif43 #if defined(RT_OS_DARWIN)44 # include <mach/thread_act.h>45 # include <mach/thread_info.h>46 # include <mach/host_info.h>47 # include <mach/mach_init.h>48 # include <mach/mach_host.h>49 37 #endif 50 38 51 39 #include <iprt/thread.h> 52 40 #include <iprt/log.h> 53 #include <iprt/assert.h>54 41 #include <iprt/asm.h> 55 42 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) … … 57 44 #endif 58 45 #include <iprt/err.h> 59 #include <iprt/string.h>60 46 #include "internal/thread.h" 61 62 63 /*******************************************************************************64 * Defined Constants And Macros *65 *******************************************************************************/66 #ifndef IN_GUEST67 /** Includes RTThreadPoke. */68 # define RTTHREAD_POSIX_WITH_POKE69 #endif70 71 72 /*******************************************************************************73 * Global Variables *74 *******************************************************************************/75 /** The pthread key in which we store the pointer to our own PRTTHREAD structure. */76 static pthread_key_t g_SelfKey;77 #ifdef RTTHREAD_POSIX_WITH_POKE78 /** The signal we use for poking threads.79 * This is set to -1 if no available signal was found. */80 static int g_iSigPokeThread = -1;81 #endif82 83 84 /*******************************************************************************85 * Internal Functions *86 *******************************************************************************/87 static void *rtThreadNativeMain(void *pvArgs);88 static void rtThreadKeyDestruct(void *pvValue);89 static void rtThreadPosixPokeSignal(int iSignal);90 91 92 DECLHIDDEN(int) rtThreadNativeInit(void)93 {94 /*95 * Allocate the TLS (key in posix terms) where we store the pointer to96 * a threads RTTHREADINT structure.97 */98 int rc = pthread_key_create(&g_SelfKey, rtThreadKeyDestruct);99 if (rc)100 return VERR_NO_TLS_FOR_SELF;101 102 #ifdef RTTHREAD_POSIX_WITH_POKE103 /*104 * Try register the dummy signal handler for RTThreadPoke.105 * Avoid SIGRTMIN thru SIGRTMIN+2 because of LinuxThreads.106 */107 static const int s_aiSigCandidates[] =108 {109 # ifdef SIGRTMAX110 SIGRTMAX-3,111 SIGRTMAX-2,112 SIGRTMAX-1,113 # endif114 # ifndef RT_OS_SOLARIS115 SIGUSR2,116 # endif117 SIGWINCH118 };119 120 g_iSigPokeThread = -1;121 for (unsigned iSig = 0; iSig < RT_ELEMENTS(s_aiSigCandidates); iSig++)122 {123 struct sigaction SigActOld;124 if (!sigaction(s_aiSigCandidates[iSig], NULL, &SigActOld))125 {126 if ( SigActOld.sa_handler == SIG_DFL127 || SigActOld.sa_handler == rtThreadPosixPokeSignal)128 {129 struct sigaction SigAct;130 RT_ZERO(SigAct);131 SigAct.sa_handler = rtThreadPosixPokeSignal;132 SigAct.sa_flags = 0;133 sigfillset(&SigAct.sa_mask);134 135 /* ASSUMES no sigaction race... (lazy bird) */136 if (!sigaction(s_aiSigCandidates[iSig], &SigAct, NULL))137 {138 g_iSigPokeThread = s_aiSigCandidates[iSig];139 break;140 }141 AssertMsgFailed(("rc=%Rrc errno=%d\n", RTErrConvertFromErrno(errno), errno));142 }143 }144 else145 AssertMsgFailed(("rc=%Rrc errno=%d\n", RTErrConvertFromErrno(errno), errno));146 }147 #endif /* RTTHREAD_POSIX_WITH_POKE */148 return rc;149 }150 151 152 /**153 * Destructor called when a thread terminates.154 * @param pvValue The key value. PRTTHREAD in our case.155 */156 static void rtThreadKeyDestruct(void *pvValue)157 {158 /*159 * Deal with alien threads.160 */161 PRTTHREADINT pThread = (PRTTHREADINT)pvValue;162 if (pThread->fIntFlags & RTTHREADINT_FLAGS_ALIEN)163 {164 pthread_setspecific(g_SelfKey, pThread);165 rtThreadTerminate(pThread, 0);166 pthread_setspecific(g_SelfKey, NULL);167 }168 }169 170 171 #ifdef RTTHREAD_POSIX_WITH_POKE172 /**173 * Dummy signal handler for the poke signal.174 *175 * @param iSignal The signal number.176 */177 static void rtThreadPosixPokeSignal(int iSignal)178 {179 Assert(iSignal == g_iSigPokeThread);180 NOREF(iSignal);181 }182 #endif183 184 185 /**186 * Adopts a thread, this is called immediately after allocating the187 * thread structure.188 *189 * @param pThread Pointer to the thread structure.190 */191 DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)192 {193 /*194 * Block SIGALRM - required for timer-posix.cpp.195 * This is done to limit harm done by OSes which doesn't do special SIGALRM scheduling.196 * It will not help much if someone creates threads directly using pthread_create. :/197 */198 sigset_t SigSet;199 sigemptyset(&SigSet);200 sigaddset(&SigSet, SIGALRM);201 sigprocmask(SIG_BLOCK, &SigSet, NULL);202 #ifdef RTTHREAD_POSIX_WITH_POKE203 if (g_iSigPokeThread != -1)204 siginterrupt(g_iSigPokeThread, 1);205 #endif206 207 int rc = pthread_setspecific(g_SelfKey, pThread);208 if (!rc)209 return VINF_SUCCESS;210 return VERR_FAILED_TO_SET_SELF_TLS;211 }212 213 214 DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)215 {216 if (pThread == (PRTTHREADINT)pthread_getspecific(g_SelfKey))217 pthread_setspecific(g_SelfKey, NULL);218 }219 220 221 /**222 * Wrapper which unpacks the params and calls thread function.223 */224 static void *rtThreadNativeMain(void *pvArgs)225 {226 PRTTHREADINT pThread = (PRTTHREADINT)pvArgs;227 228 #if defined(RT_OS_LINUX)229 /*230 * Set the TID.231 */232 pThread->tid = syscall(__NR_gettid);233 ASMMemoryFence();234 #endif235 236 /*237 * Block SIGALRM - required for timer-posix.cpp.238 * This is done to limit harm done by OSes which doesn't do special SIGALRM scheduling.239 * It will not help much if someone creates threads directly using pthread_create. :/240 */241 sigset_t SigSet;242 sigemptyset(&SigSet);243 sigaddset(&SigSet, SIGALRM);244 sigprocmask(SIG_BLOCK, &SigSet, NULL);245 #ifdef RTTHREAD_POSIX_WITH_POKE246 if (g_iSigPokeThread != -1)247 siginterrupt(g_iSigPokeThread, 1);248 #endif249 250 int rc = pthread_setspecific(g_SelfKey, pThread);251 AssertReleaseMsg(!rc, ("failed to set self TLS. rc=%d thread '%s'\n", rc, pThread->szName));252 253 /*254 * Call common main.255 */256 pthread_t Self = pthread_self();257 Assert((uintptr_t)Self == (RTNATIVETHREAD)Self && (uintptr_t)Self != NIL_RTNATIVETHREAD);258 rc = rtThreadMain(pThread, (uintptr_t)Self, &pThread->szName[0]);259 260 pthread_setspecific(g_SelfKey, NULL);261 pthread_exit((void *)(intptr_t)rc);262 return (void *)(intptr_t)rc;263 }264 265 266 DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThread, PRTNATIVETHREAD pNativeThread)267 {268 /*269 * Set the default stack size.270 */271 if (!pThread->cbStack)272 pThread->cbStack = 512*1024;273 274 #ifdef RT_OS_LINUX275 pThread->tid = -1;276 #endif277 278 /*279 * Setup thread attributes.280 */281 pthread_attr_t ThreadAttr;282 int rc = pthread_attr_init(&ThreadAttr);283 if (!rc)284 {285 rc = pthread_attr_setdetachstate(&ThreadAttr, PTHREAD_CREATE_DETACHED);286 if (!rc)287 {288 rc = pthread_attr_setstacksize(&ThreadAttr, pThread->cbStack);289 if (!rc)290 {291 /*292 * Create the thread.293 */294 pthread_t ThreadId;295 rc = pthread_create(&ThreadId, &ThreadAttr, rtThreadNativeMain, pThread);296 if (!rc)297 {298 *pNativeThread = (uintptr_t)ThreadId;299 return VINF_SUCCESS;300 }301 }302 }303 pthread_attr_destroy(&ThreadAttr);304 }305 return RTErrConvertFromErrno(rc);306 }307 308 309 RTDECL(RTTHREAD) RTThreadSelf(void)310 {311 PRTTHREADINT pThread = (PRTTHREADINT)pthread_getspecific(g_SelfKey);312 /** @todo import alien threads? */313 return pThread;314 }315 47 316 48 … … 383 115 } 384 116 385 386 #ifdef RTTHREAD_POSIX_WITH_POKE387 RTDECL(int) RTThreadPoke(RTTHREAD hThread)388 {389 AssertReturn(hThread != RTThreadSelf(), VERR_INVALID_PARAMETER);390 PRTTHREADINT pThread = rtThreadGet(hThread);391 AssertReturn(pThread, VERR_INVALID_HANDLE);392 393 int rc;394 if (g_iSigPokeThread != -1)395 {396 rc = pthread_kill((pthread_t)(uintptr_t)pThread->Core.Key, g_iSigPokeThread);397 rc = RTErrConvertFromErrno(rc);398 }399 else400 rc = VERR_NOT_SUPPORTED;401 402 rtThreadRelease(pThread);403 return rc;404 }405 #endif406 407 /** @todo move this into platform specific files. */408 RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pKernelTime, uint64_t *pUserTime)409 {410 #if defined(RT_OS_SOLARIS)411 struct rusage ts;412 int rc = getrusage(RUSAGE_LWP, &ts);413 if (rc)414 return RTErrConvertFromErrno(rc);415 416 *pKernelTime = ts.ru_stime.tv_sec * 1000 + ts.ru_stime.tv_usec / 1000;417 *pUserTime = ts.ru_utime.tv_sec * 1000 + ts.ru_utime.tv_usec / 1000;418 return VINF_SUCCESS;419 420 #elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)421 /* on Linux, getrusage(RUSAGE_THREAD, ...) is available since 2.6.26 */422 struct timespec ts;423 int rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);424 if (rc)425 return RTErrConvertFromErrno(rc);426 427 *pKernelTime = 0;428 *pUserTime = (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;429 return VINF_SUCCESS;430 431 #elif defined(RT_OS_DARWIN)432 thread_basic_info ThreadInfo;433 mach_msg_type_number_t Count = THREAD_BASIC_INFO_COUNT;434 kern_return_t krc = thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)&ThreadInfo, &Count);435 AssertReturn(krc == KERN_SUCCESS, RTErrConvertFromDarwinKern(krc));436 437 *pKernelTime = ThreadInfo.system_time.seconds * 1000 + ThreadInfo.system_time.microseconds / 1000;438 *pUserTime = ThreadInfo.user_time.seconds * 1000 + ThreadInfo.user_time.microseconds / 1000;439 440 return VINF_SUCCESS;441 #else442 return VERR_NOT_IMPLEMENTED;443 #endif444 }445 -
trunk/src/VBox/Runtime/r3/win/thread-win.cpp
r37310 r37733 240 240 241 241 242 RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)243 {244 return (RTNATIVETHREAD)GetCurrentThreadId();245 }246 247 248 RTR3DECL(int) RTThreadSleep(RTMSINTERVAL cMillies)249 {250 LogFlow(("RTThreadSleep: cMillies=%d\n", cMillies));251 Sleep(cMillies);252 LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));253 return VINF_SUCCESS;254 }255 256 257 RTR3DECL(bool) RTThreadYield(void)258 {259 uint64_t u64TS = ASMReadTSC();260 Sleep(0);261 u64TS = ASMReadTSC() - u64TS;262 bool fRc = u64TS > 1500;263 LogFlow(("RTThreadYield: returning %d (%llu ticks)\n", fRc, u64TS));264 return fRc;265 }266 267 268 242 #if 0 /* noone is using this ... */ 269 243 /** -
trunk/src/VBox/Runtime/r3/win/thread2-win.cpp
r37729 r37733 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Threads , Windows.3 * IPRT - Threads part 2, Windows. 4 4 */ 5 5 … … 32 32 #include <Windows.h> 33 33 34 #include <errno.h>35 #include <process.h>36 37 34 #include <iprt/thread.h> 38 35 #include "internal/iprt.h" 39 36 40 37 #include <iprt/asm-amd64-x86.h> 41 #include <iprt/assert.h>42 #include <iprt/cpuset.h>43 38 #include <iprt/err.h> 44 39 #include <iprt/log.h> 45 #include <iprt/mem.h>46 40 #include "internal/thread.h" 47 48 49 /*******************************************************************************50 * Defined Constants And Macros *51 *******************************************************************************/52 /** The TLS index allocated for storing the RTTHREADINT pointer. */53 static DWORD g_dwSelfTLS = TLS_OUT_OF_INDEXES;54 55 56 /*******************************************************************************57 * Internal Functions *58 *******************************************************************************/59 static unsigned __stdcall rtThreadNativeMain(void *pvArgs);60 61 62 DECLHIDDEN(int) rtThreadNativeInit(void)63 {64 g_dwSelfTLS = TlsAlloc();65 if (g_dwSelfTLS == TLS_OUT_OF_INDEXES)66 return VERR_NO_TLS_FOR_SELF;67 return VINF_SUCCESS;68 }69 70 71 DECLHIDDEN(void) rtThreadNativeDetach(void)72 {73 /*74 * Deal with alien threads.75 */76 PRTTHREADINT pThread = (PRTTHREADINT)TlsGetValue(g_dwSelfTLS);77 if ( pThread78 && (pThread->fIntFlags & RTTHREADINT_FLAGS_ALIEN))79 {80 rtThreadTerminate(pThread, 0);81 TlsSetValue(g_dwSelfTLS, NULL);82 }83 }84 85 86 DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)87 {88 if (pThread == (PRTTHREADINT)TlsGetValue(g_dwSelfTLS))89 TlsSetValue(g_dwSelfTLS, NULL);90 91 if ((HANDLE)pThread->hThread != INVALID_HANDLE_VALUE)92 {93 CloseHandle((HANDLE)pThread->hThread);94 pThread->hThread = (uintptr_t)INVALID_HANDLE_VALUE;95 }96 }97 98 99 DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)100 {101 if (!TlsSetValue(g_dwSelfTLS, pThread))102 return VERR_FAILED_TO_SET_SELF_TLS;103 return VINF_SUCCESS;104 }105 106 107 /**108 * Bitch about dangling COM and OLE references, dispose of them109 * afterwards so we don't end up deadlocked somewhere below110 * OLE32!DllMain.111 */112 static void rtThreadNativeUninitComAndOle(void)113 {114 #if 1 /* experimental code */115 /*116 * Read the counters.117 */118 struct MySOleTlsData119 {120 void *apvReserved0[2]; /**< x86=0x00 W7/64=0x00 */121 DWORD adwReserved0[3]; /**< x86=0x08 W7/64=0x10 */122 void *apvReserved1[1]; /**< x86=0x14 W7/64=0x20 */123 DWORD cComInits; /**< x86=0x18 W7/64=0x28 */124 DWORD cOleInits; /**< x86=0x1c W7/64=0x2c */125 DWORD dwReserved1; /**< x86=0x20 W7/64=0x30 */126 void *apvReserved2[4]; /**< x86=0x24 W7/64=0x38 */127 DWORD adwReserved2[1]; /**< x86=0x34 W7/64=0x58 */128 void *pvCurrentCtx; /**< x86=0x38 W7/64=0x60 */129 IUnknown *pCallState; /**< x86=0x3c W7/64=0x68 */130 } *pOleTlsData = NULL; /* outside the try/except for debugging */131 DWORD cComInits = 0;132 DWORD cOleInits = 0;133 __try134 {135 void *pvTeb = NtCurrentTeb();136 # ifdef RT_ARCH_AMD64137 pOleTlsData = *(struct MySOleTlsData **)((uintptr_t)pvTeb + 0x1758); /*TEB.ReservedForOle*/138 # elif RT_ARCH_X86139 pOleTlsData = *(struct MySOleTlsData **)((uintptr_t)pvTeb + 0x0f80); /*TEB.ReservedForOle*/140 # else141 # error "Port me!"142 # endif143 if (pOleTlsData)144 {145 cComInits = pOleTlsData->cComInits;146 cOleInits = pOleTlsData->cOleInits;147 }148 }149 __except(EXCEPTION_EXECUTE_HANDLER)150 {151 AssertFailedReturnVoid();152 }153 154 /*155 * Assert sanity. If any of these breaks, the structure layout above is156 * probably not correct any longer.157 */158 AssertMsgReturnVoid(cComInits < 1000, ("%u (%#x)\n", cComInits, cComInits));159 AssertMsgReturnVoid(cOleInits < 1000, ("%u (%#x)\n", cOleInits, cOleInits));160 AssertMsgReturnVoid(cComInits >= cOleInits, ("cComInits=%#x cOleInits=%#x\n", cComInits, cOleInits));161 162 /*163 * Do the uninitializing.164 */165 if (cComInits)166 {167 AssertMsgFailed(("cComInits=%u (%#x) cOleInits=%u (%#x) - dangling COM/OLE inits!\n",168 cComInits, cComInits, cOleInits, cOleInits));169 170 HMODULE hOle32 = GetModuleHandle("OLE32");171 AssertReturnVoid(hOle32 != NULL);172 173 typedef void (WINAPI *PFNOLEUNINITIALIZE)(void);174 PFNOLEUNINITIALIZE pfnOleUninitialize = (PFNOLEUNINITIALIZE)GetProcAddress(hOle32, "OleUninitialize");175 AssertReturnVoid(pfnOleUninitialize);176 177 typedef void (WINAPI *PFNCOUNINITIALIZE)(void);178 PFNCOUNINITIALIZE pfnCoUninitialize = (PFNCOUNINITIALIZE)GetProcAddress(hOle32, "CoUninitialize");179 AssertReturnVoid(pfnCoUninitialize);180 181 while (cOleInits-- > 0)182 {183 pfnOleUninitialize();184 cComInits--;185 }186 187 while (cComInits-- > 0)188 pfnCoUninitialize();189 }190 #endif191 }192 193 194 /**195 * Wrapper which unpacks the param stuff and calls thread function.196 */197 static unsigned __stdcall rtThreadNativeMain(void *pvArgs)198 {199 DWORD dwThreadId = GetCurrentThreadId();200 PRTTHREADINT pThread = (PRTTHREADINT)pvArgs;201 202 if (!TlsSetValue(g_dwSelfTLS, pThread))203 AssertReleaseMsgFailed(("failed to set self TLS. lasterr=%d thread '%s'\n", GetLastError(), pThread->szName));204 205 int rc = rtThreadMain(pThread, dwThreadId, &pThread->szName[0]);206 207 TlsSetValue(g_dwSelfTLS, NULL);208 rtThreadNativeUninitComAndOle();209 _endthreadex(rc);210 return rc;211 }212 213 214 DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThread, PRTNATIVETHREAD pNativeThread)215 {216 AssertReturn(pThread->cbStack < ~(unsigned)0, VERR_INVALID_PARAMETER);217 218 /*219 * Create the thread.220 */221 pThread->hThread = (uintptr_t)INVALID_HANDLE_VALUE;222 unsigned uThreadId = 0;223 uintptr_t hThread = _beginthreadex(NULL, (unsigned)pThread->cbStack, rtThreadNativeMain, pThread, 0, &uThreadId);224 if (hThread != 0 && hThread != ~0U)225 {226 pThread->hThread = hThread;227 *pNativeThread = uThreadId;228 return VINF_SUCCESS;229 }230 return RTErrConvertFromErrno(errno);231 }232 233 234 RTDECL(RTTHREAD) RTThreadSelf(void)235 {236 PRTTHREADINT pThread = (PRTTHREADINT)TlsGetValue(g_dwSelfTLS);237 /** @todo import alien threads ? */238 return pThread;239 }240 41 241 42 … … 266 67 267 68 268 #if 0 /* noone is using this ... */269 /**270 * Returns the processor number the current thread was running on during this call271 *272 * @returns processor nr273 */274 static int rtThreadGetCurrentProcessorNumber(void)275 {276 static bool fInitialized = false;277 static DWORD (WINAPI *pfnGetCurrentProcessorNumber)(void) = NULL;278 if (!fInitialized)279 {280 HMODULE hmodKernel32 = GetModuleHandle("KERNEL32.DLL");281 if (hmodKernel32)282 pfnGetCurrentProcessorNumber = (DWORD (WINAPI*)(void))GetProcAddress(hmodKernel32, "GetCurrentProcessorNumber");283 fInitialized = true;284 }285 if (pfnGetCurrentProcessorNumber)286 return pfnGetCurrentProcessorNumber();287 return -1;288 }289 #endif290 291 292 RTR3DECL(int) RTThreadSetAffinity(PCRTCPUSET pCpuSet)293 {294 DWORD_PTR fNewMask = pCpuSet ? RTCpuSetToU64(pCpuSet) : ~(DWORD_PTR)0;295 DWORD_PTR dwRet = SetThreadAffinityMask(GetCurrentThread(), fNewMask);296 if (dwRet)297 return VINF_SUCCESS;298 299 int iLastError = GetLastError();300 AssertMsgFailed(("SetThreadAffinityMask failed, LastError=%d\n", iLastError));301 return RTErrConvertFromWin32(iLastError);302 }303 304 305 RTR3DECL(int) RTThreadGetAffinity(PRTCPUSET pCpuSet)306 {307 /*308 * Haven't found no query api, but the set api returns the old mask, so let's use that.309 */310 DWORD_PTR dwIgnored;311 DWORD_PTR dwProcAff = 0;312 if (GetProcessAffinityMask(GetCurrentProcess(), &dwProcAff, &dwIgnored))313 {314 HANDLE hThread = GetCurrentThread();315 DWORD_PTR dwRet = SetThreadAffinityMask(hThread, dwProcAff);316 if (dwRet)317 {318 DWORD_PTR dwSet = SetThreadAffinityMask(hThread, dwRet);319 Assert(dwSet == dwProcAff); NOREF(dwRet);320 321 RTCpuSetFromU64(pCpuSet, (uint64_t)dwSet);322 return VINF_SUCCESS;323 }324 }325 326 int iLastError = GetLastError();327 AssertMsgFailed(("SetThreadAffinityMask or GetProcessAffinityMask failed, LastError=%d\n", iLastError));328 return RTErrConvertFromWin32(iLastError);329 }330 331 332 RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pKernelTime, uint64_t *pUserTime)333 {334 uint64_t u64CreationTime, u64ExitTime, u64KernelTime, u64UserTime;335 336 if (GetThreadTimes(GetCurrentThread(), (LPFILETIME)&u64CreationTime, (LPFILETIME)&u64ExitTime, (LPFILETIME)&u64KernelTime, (LPFILETIME)&u64UserTime))337 {338 *pKernelTime = u64KernelTime / 10000; /* GetThreadTimes returns time in 100 ns units */339 *pUserTime = u64UserTime / 10000; /* GetThreadTimes returns time in 100 ns units */340 return VINF_SUCCESS;341 }342 343 int iLastError = GetLastError();344 AssertMsgFailed(("GetThreadTimes failed, LastError=%d\n", iLastError));345 return RTErrConvertFromWin32(iLastError);346 }347
Note:
See TracChangeset
for help on using the changeset viewer.