diff --git a/libcpu/sim/win32/cpu_port.c b/libcpu/sim/win32/cpu_port.c index 0b13cc8a1e..5969d2e8d1 100644 --- a/libcpu/sim/win32/cpu_port.c +++ b/libcpu/sim/win32/cpu_port.c @@ -39,6 +39,18 @@ typedef struct DWORD ThreadID; }win_thread_t; +const DWORD MS_VC_EXCEPTION=0x406D1388; + +#pragma pack(push,8) +typedef struct tagTHREADNAME_INFO +{ + DWORD dwType; // Must be 0x1000. + LPCSTR szName; // Pointer to name (in user addr space). + DWORD dwThreadID; // Thread ID (-1=caller thread). + DWORD dwFlags; // Reserved for future use, must be zero. +} THREADNAME_INFO; +#pragma pack(pop) + /* ********************************************************************************************************* * LOCAL DEFINES @@ -97,6 +109,23 @@ rt_uint32_t SysTickInterruptHandle(void); static DWORD WINAPI ThreadforSysTickTimer(LPVOID lpParam); static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam); +static void SetThreadName(DWORD dwThreadID, char* threadName) +{ + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = threadName; + info.dwThreadID = dwThreadID; + info.dwFlags = 0; + + __try + { + RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + } +} + /* ********************************************************************************************************* * rt_hw_stack_init() @@ -110,10 +139,13 @@ static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam); static DWORD WINAPI thread_run( LPVOID lpThreadParameter ) { + rt_thread_t tid = rt_thread_self(); win_thread_t *pWinThread = (win_thread_t *)lpThreadParameter; + + SetThreadName(GetCurrentThreadId(), tid->name); + pWinThread->Entry(pWinThread->Param); - printf("thread %x exit\n", pWinThread->ThreadID); pWinThread->Exit(); return 0; } @@ -154,9 +186,6 @@ rt_uint8_t* rt_hw_stack_init(void *pEntry,void *pParam,rt_uint8_t *pStackAddr,vo return (rt_uint8_t*)pWinThread; } /*** rt_hw_stack_init ***/ - - - /* ********************************************************************************************************* * rt_hw_interrupt_disable() @@ -222,7 +251,7 @@ void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_interrupt_to_thread = *((rt_uint32_t *)(to)); - //trigger YIELD exception(cause contex switch) + //trigger YIELD exception(cause context switch) TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD); } /*** rt_hw_context_switch_interrupt ***/