• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (c) 2016 mingw-w64 project
3 
4     Contributing authors: Hugo Beauzée-Luyssen
5 
6     Permission is hereby granted, free of charge, to any person obtaining a
7     copy of this software and associated documentation files (the "Software"),
8     to deal in the Software without restriction, including without limitation
9     the rights to use, copy, modify, merge, publish, distribute, sublicense,
10     and/or sell copies of the Software, and to permit persons to whom the
11     Software is furnished to do so, subject to the following conditions:
12 
13     The above copyright notice and this permission notice shall be included in
14     all copies or substantial portions of the Software.
15 
16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22     DEALINGS IN THE SOFTWARE.
23 */
24 
25 #define _WIN32_WINNT 0x501
26 
27 #define _beginthreadex ___beginthreadex
28 #define _endthreadex ___endthreadex
29 #include <windef.h>
30 #include <winbase.h>
31 #include <processthreadsapi.h>
32 #undef _endthreadex
33 #undef _beginthreadex
34 
_beginthreadex(void * _Security,unsigned _StackSize,unsigned (__stdcall * _StartAddress)(void *),void * _ArgList,unsigned _InitFlag,unsigned * _ThrdAddr)35 uintptr_t __cdecl _beginthreadex(void *_Security, unsigned _StackSize,
36                                          unsigned (__stdcall *_StartAddress) (void *),
37                                          void *_ArgList,unsigned _InitFlag,unsigned *_ThrdAddr)
38 {
39     return (uintptr_t)CreateThread(_Security, _StackSize, (LPTHREAD_START_ROUTINE)_StartAddress,
40                         _ArgList, _InitFlag, (LPDWORD)_ThrdAddr);
41 }
42 
_endthreadex(unsigned _Retval)43 void __cdecl _endthreadex(unsigned _Retval)
44 {
45     ExitThread(_Retval);
46 }
47 
48 #ifdef _X86_
49 uintptr_t (__cdecl *__MINGW_IMP_SYMBOL(_beginthreadex))(void*, unsigned, unsigned (__stdcall *)(void *), void *,unsigned, unsigned*) asm("__imp___beginthreadex") = _beginthreadex;
50 void (__cdecl *__MINGW_IMP_SYMBOL(_endthreadex))(unsigned) asm("__imp___endthreadex") = _endthreadex;
51 #else
52 void (__cdecl *__MINGW_IMP_SYMBOL(_beginthreadex))(void*, unsigned, unsigned (__stdcall *)(void *), void *,unsigned, unsigned*) asm("__imp__beginthreadex") = _beginthreadex;
53 void (__cdecl *__MINGW_IMP_SYMBOL(_endthreadex))(unsigned) asm("__imp__endthreadex") = _endthreadex;
54 #endif
55