Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 threads |
| 3 | * |
| 4 | * Copyright 1996 Alexandre Julliard |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 8 | #include <fcntl.h> |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 9 | #include <sys/types.h> |
| 10 | #include <sys/socket.h> |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 11 | #include <sys/mman.h> |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 12 | #include <unistd.h> |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 13 | #include "wine/winbase16.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 14 | #include "thread.h" |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 15 | #include "process.h" |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 16 | #include "task.h" |
| 17 | #include "module.h" |
| 18 | #include "user.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 19 | #include "winerror.h" |
| 20 | #include "heap.h" |
| 21 | #include "selectors.h" |
| 22 | #include "winnt.h" |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 23 | #include "server.h" |
Ulrich Weigand | 36a1a25 | 1999-05-08 10:48:03 +0000 | [diff] [blame] | 24 | #include "services.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 25 | #include "stackframe.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 26 | #include "debugtools.h" |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 27 | #include "queue.h" |
| 28 | #include "hook.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 29 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 30 | DEFAULT_DEBUG_CHANNEL(thread) |
| 31 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 32 | /* TEB of the initial thread */ |
| 33 | static TEB initial_teb; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 35 | /* Global thread list (FIXME: not thread-safe) */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 36 | TEB *THREAD_First = &initial_teb; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 37 | |
| 38 | /*********************************************************************** |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 39 | * THREAD_IsWin16 |
| 40 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 41 | BOOL THREAD_IsWin16( TEB *teb ) |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 42 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 43 | return !teb || !(teb->flags & TEBF_WIN32); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 46 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 47 | * THREAD_IdToTEB |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 48 | * |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 49 | * Convert a thread id to a TEB, making sure it is valid. |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 50 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 51 | TEB *THREAD_IdToTEB( DWORD id ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 52 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 53 | TEB *teb = THREAD_First; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 54 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 55 | if (!id) return NtCurrentTeb(); |
| 56 | while (teb) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 57 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 58 | if ((DWORD)teb->tid == id) return teb; |
| 59 | teb = teb->next; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 60 | } |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 61 | /* Allow task handles to be used; convert to main thread */ |
| 62 | if ( IsTask16( id ) ) |
| 63 | { |
| 64 | TDB *pTask = (TDB *)GlobalLock16( id ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 65 | if (pTask) return pTask->teb; |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 66 | } |
| 67 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 68 | return NULL; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 72 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 73 | * THREAD_InitTEB |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 74 | * |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 75 | * Initialization of a newly created TEB. |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 76 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 77 | static BOOL THREAD_InitTEB( TEB *teb, DWORD stack_size, BOOL alloc_stack16, |
| 78 | LPSECURITY_ATTRIBUTES sa ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 79 | { |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 80 | DWORD old_prot; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 81 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 82 | /* Allocate the stack */ |
| 83 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 84 | /* FIXME: |
| 85 | * If stacksize smaller than 1 MB, allocate 1MB |
| 86 | * (one program wanted only 10 kB, which is recommendable, but some WINE |
| 87 | * functions, noteably in the files subdir, push HUGE structures and |
| 88 | * arrays on the stack. They probably shouldn't.) |
| 89 | * If stacksize larger than 16 MB, warn the user. (We could shrink the stack |
| 90 | * but this could give more or less unexplainable crashes.) |
| 91 | */ |
| 92 | if (stack_size<1024*1024) |
| 93 | stack_size = 1024 * 1024; |
| 94 | if (stack_size >= 16*1024*1024) |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 95 | WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 96 | teb->stack_base = VirtualAlloc(NULL, stack_size + SIGNAL_STACK_SIZE + |
| 97 | (alloc_stack16 ? 0x10000 : 0), |
| 98 | MEM_COMMIT, PAGE_EXECUTE_READWRITE ); |
| 99 | if (!teb->stack_base) goto error; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 100 | /* Set a guard page at the bottom of the stack */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 101 | VirtualProtect( teb->stack_base, 1, PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot ); |
| 102 | teb->stack_top = (char *)teb->stack_base + stack_size; |
| 103 | teb->stack_low = teb->stack_base; |
| 104 | teb->signal_stack = teb->stack_top; /* start of signal stack */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 105 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 106 | /* Allocate the 16-bit stack selector */ |
| 107 | |
| 108 | if (alloc_stack16) |
| 109 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 110 | teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, SEGMENT_DATA, |
| 111 | FALSE, FALSE ); |
| 112 | if (!teb->stack_sel) goto error; |
| 113 | teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( teb->stack_sel, |
| 114 | 0x10000 - sizeof(STACK16FRAME) ); |
| 115 | teb->signal_stack = (char *)teb->signal_stack + 0x10000; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Alexandre Julliard | dbf2bf0 | 1999-01-01 17:05:53 +0000 | [diff] [blame] | 118 | /* Create the thread event */ |
| 119 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 120 | if (!(teb->event = CreateEventA( NULL, FALSE, FALSE, NULL ))) goto error; |
| 121 | teb->event = ConvertToGlobalHandle( teb->event ); |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 122 | return TRUE; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 123 | |
| 124 | error: |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 125 | if (teb->event) CloseHandle( teb->event ); |
| 126 | if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 ); |
| 127 | if (teb->stack_base) VirtualFree( teb->stack_base, 0, MEM_RELEASE ); |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 128 | return FALSE; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 133 | * THREAD_FreeTEB |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 134 | * |
| 135 | * Free data structures associated with a thread. |
| 136 | * Must be called from the context of another thread. |
| 137 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 138 | void CALLBACK THREAD_FreeTEB( ULONG_PTR arg ) |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 139 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 140 | TEB *teb = (TEB *)arg; |
| 141 | TEB **pptr = &THREAD_First; |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 142 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 143 | TRACE("(%p) called\n", teb ); |
| 144 | SERVICE_Delete( teb->cleanup ); |
Ulrich Weigand | 36a1a25 | 1999-05-08 10:48:03 +0000 | [diff] [blame] | 145 | |
Alexandre Julliard | bda3969 | 1999-05-24 15:01:05 +0000 | [diff] [blame] | 146 | PROCESS_CallUserSignalProc( USIG_THREAD_EXIT, 0 ); |
Ulrich Weigand | 8139c30 | 1999-04-01 11:43:05 +0000 | [diff] [blame] | 147 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 148 | CloseHandle( teb->event ); |
| 149 | while (*pptr && (*pptr != teb)) pptr = &(*pptr)->next; |
| 150 | if (*pptr) *pptr = teb->next; |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 151 | |
| 152 | /* Free the associated memory */ |
| 153 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 154 | if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 ); |
| 155 | SELECTOR_FreeBlock( teb->teb_sel, 1 ); |
| 156 | close( teb->socket ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 157 | if (teb->buffer) munmap( teb->buffer, teb->buffer_size ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 158 | VirtualFree( teb->stack_base, 0, MEM_RELEASE ); |
| 159 | HeapFree( SystemHeap, 0, teb ); |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | /*********************************************************************** |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 164 | * THREAD_CreateInitialThread |
| 165 | * |
| 166 | * Create the initial thread. |
| 167 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 168 | TEB *THREAD_CreateInitialThread( PDB *pdb, int server_fd ) |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 169 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 170 | initial_teb.except = (void *)-1; |
| 171 | initial_teb.self = &initial_teb; |
| 172 | initial_teb.flags = /* TEBF_WIN32 */ 0; |
| 173 | initial_teb.tls_ptr = initial_teb.tls_array; |
| 174 | initial_teb.process = pdb; |
| 175 | initial_teb.exit_code = 0x103; /* STILL_ACTIVE */ |
| 176 | initial_teb.socket = server_fd; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 177 | |
| 178 | /* Allocate the TEB selector (%fs register) */ |
| 179 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 180 | if (!(initial_teb.teb_sel = SELECTOR_AllocBlock( &initial_teb, 0x1000, |
| 181 | SEGMENT_DATA, TRUE, FALSE ))) |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 182 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 183 | MESSAGE("Could not allocate fs register for initial thread\n" ); |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 184 | return NULL; |
| 185 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 186 | SYSDEPS_SetCurThread( &initial_teb ); |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 187 | |
| 188 | /* Now proceed with normal initialization */ |
| 189 | |
Alexandre Julliard | 875c4b3 | 1999-03-23 14:09:41 +0000 | [diff] [blame] | 190 | if (CLIENT_InitThread()) return NULL; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 191 | if (!THREAD_InitTEB( &initial_teb, 0, TRUE, NULL )) return NULL; |
| 192 | return &initial_teb; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | /*********************************************************************** |
| 197 | * THREAD_Create |
| 198 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 199 | TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16, |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 200 | LPSECURITY_ATTRIBUTES sa, int *server_handle ) |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 201 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 202 | struct new_thread_request *req = get_req_buffer(); |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 203 | int fd[2]; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 204 | HANDLE cleanup_object; |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 205 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 206 | TEB *teb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(TEB) ); |
| 207 | if (!teb) return NULL; |
| 208 | teb->except = (void *)-1; |
| 209 | teb->htask16 = pdb->task; |
| 210 | teb->self = teb; |
| 211 | teb->flags = (pdb->flags & PDB32_WIN16_PROC)? 0 : TEBF_WIN32; |
| 212 | teb->tls_ptr = teb->tls_array; |
| 213 | teb->process = pdb; |
| 214 | teb->exit_code = 0x103; /* STILL_ACTIVE */ |
| 215 | teb->socket = -1; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 216 | |
| 217 | /* Allocate the TEB selector (%fs register) */ |
| 218 | |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 219 | *server_handle = -1; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 220 | teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, SEGMENT_DATA, TRUE, FALSE ); |
| 221 | if (!teb->teb_sel) goto error; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 222 | |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 223 | /* Create the socket pair for server communication */ |
| 224 | |
| 225 | if (socketpair( AF_UNIX, SOCK_STREAM, 0, fd ) == -1) |
| 226 | { |
| 227 | SetLastError( ERROR_TOO_MANY_OPEN_FILES ); /* FIXME */ |
| 228 | goto error; |
| 229 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 230 | teb->socket = fd[0]; |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 231 | fcntl( fd[0], F_SETFD, 1 ); /* set close on exec flag */ |
| 232 | |
| 233 | /* Create the thread on the server side */ |
| 234 | |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 235 | req->pid = teb->process->server_pid; |
| 236 | req->suspend = ((flags & CREATE_SUSPENDED) != 0); |
| 237 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 238 | if (server_call_fd( REQ_NEW_THREAD, fd[1], NULL )) goto error; |
| 239 | teb->tid = req->tid; |
| 240 | *server_handle = req->handle; |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 241 | |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 242 | /* Do the rest of the initialization */ |
| 243 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 244 | if (!THREAD_InitTEB( teb, stack_size, alloc_stack16, sa )) goto error; |
| 245 | teb->next = THREAD_First; |
| 246 | THREAD_First = teb; |
Ulrich Weigand | 36a1a25 | 1999-05-08 10:48:03 +0000 | [diff] [blame] | 247 | |
| 248 | /* Install cleanup handler */ |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 249 | if ( !DuplicateHandle( GetCurrentProcess(), *server_handle, |
| 250 | GetCurrentProcess(), &cleanup_object, |
| 251 | 0, FALSE, DUPLICATE_SAME_ACCESS ) ) goto error; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 252 | teb->cleanup = SERVICE_AddObject( cleanup_object, THREAD_FreeTEB, (ULONG_PTR)teb ); |
Ulrich Weigand | 36a1a25 | 1999-05-08 10:48:03 +0000 | [diff] [blame] | 253 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 254 | return teb; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 255 | |
| 256 | error: |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 257 | if (*server_handle != -1) CloseHandle( *server_handle ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 258 | if (teb->teb_sel) SELECTOR_FreeBlock( teb->teb_sel, 1 ); |
| 259 | if (teb->socket != -1) close( teb->socket ); |
| 260 | HeapFree( SystemHeap, 0, teb ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 261 | return NULL; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | /*********************************************************************** |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 266 | * THREAD_Start |
| 267 | * |
| 268 | * Start execution of a newly created thread. Does not return. |
| 269 | */ |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 270 | static void THREAD_Start(void) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 271 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 272 | LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point; |
Alexandre Julliard | bda3969 | 1999-05-24 15:01:05 +0000 | [diff] [blame] | 273 | PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 ); |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 274 | PE_InitTls(); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 275 | MODULE_DllThreadAttach( NULL ); |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 276 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 277 | if (NtCurrentTeb()->process->flags & PDB32_DEBUGGED) DEBUG_SendCreateThreadEvent( func ); |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 278 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 279 | ExitThread( func( NtCurrentTeb()->entry_arg ) ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
| 283 | /*********************************************************************** |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 284 | * CreateThread (KERNEL32.63) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 285 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 286 | HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack, |
Ulrich Weigand | 4526f2e | 1999-03-16 16:28:59 +0000 | [diff] [blame] | 287 | LPTHREAD_START_ROUTINE start, LPVOID param, |
| 288 | DWORD flags, LPDWORD id ) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 289 | { |
Alexandre Julliard | 96c08d8 | 1999-02-28 13:27:56 +0000 | [diff] [blame] | 290 | int handle = -1; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 291 | TEB *teb = THREAD_Create( PROCESS_Current(), flags, stack, TRUE, sa, &handle ); |
| 292 | if (!teb) return INVALID_HANDLE_VALUE; |
| 293 | teb->flags |= TEBF_WIN32; |
| 294 | teb->entry_point = start; |
| 295 | teb->entry_arg = param; |
| 296 | teb->startup = THREAD_Start; |
| 297 | if (SYSDEPS_SpawnThread( teb ) == -1) |
Alexandre Julliard | 96c08d8 | 1999-02-28 13:27:56 +0000 | [diff] [blame] | 298 | { |
| 299 | CloseHandle( handle ); |
| 300 | return INVALID_HANDLE_VALUE; |
| 301 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 302 | if (id) *id = (DWORD)teb->tid; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 303 | return handle; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 308 | * ExitThread [KERNEL32.215] Ends a thread |
| 309 | * |
| 310 | * RETURNS |
| 311 | * None |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 312 | */ |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 313 | void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */ |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 314 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 315 | MODULE_DllThreadDetach( NULL ); |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 316 | TerminateThread( GetCurrentThread(), code ); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | |
| 320 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 321 | * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread |
| 322 | * |
| 323 | * RETURNS |
| 324 | * Pseudohandle for the current thread |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 325 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 326 | HANDLE WINAPI GetCurrentThread(void) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 327 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 328 | return CURRENT_THREAD_PSEUDOHANDLE; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 332 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 333 | * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code. |
| 334 | * |
| 335 | * RETURNS |
| 336 | * Calling thread's last error code value. |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 337 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 338 | DWORD WINAPI GetLastError(void) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 339 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 340 | return NtCurrentTeb()->last_error; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | |
| 344 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 345 | * SetLastErrorEx [USER32.485] Sets the last-error code. |
| 346 | * |
| 347 | * RETURNS |
| 348 | * None. |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 349 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 350 | void WINAPI SetLastErrorEx( |
| 351 | DWORD error, /* [in] Per-thread error code */ |
| 352 | DWORD type) /* [in] Error type */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 353 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 354 | TRACE("(0x%08lx, 0x%08lx)\n", error,type); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 355 | switch(type) { |
| 356 | case 0: |
| 357 | break; |
| 358 | case SLE_ERROR: |
| 359 | case SLE_MINORERROR: |
| 360 | case SLE_WARNING: |
| 361 | /* Fall through for now */ |
| 362 | default: |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 363 | FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error,type); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 364 | break; |
| 365 | } |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 366 | SetLastError( error ); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | /********************************************************************** |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 371 | * TlsAlloc [KERNEL32.530] Allocates a TLS index. |
| 372 | * |
| 373 | * Allocates a thread local storage index |
| 374 | * |
| 375 | * RETURNS |
| 376 | * Success: TLS Index |
| 377 | * Failure: 0xFFFFFFFF |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 378 | */ |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 379 | DWORD WINAPI TlsAlloc( void ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 380 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 381 | PDB *process = PROCESS_Current(); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 382 | DWORD i, mask, ret = 0; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 383 | DWORD *bits = process->tls_bits; |
| 384 | EnterCriticalSection( &process->crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 385 | if (*bits == 0xffffffff) |
| 386 | { |
| 387 | bits++; |
| 388 | ret = 32; |
| 389 | if (*bits == 0xffffffff) |
| 390 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 391 | LeaveCriticalSection( &process->crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 392 | SetLastError( ERROR_NO_MORE_ITEMS ); |
| 393 | return 0xffffffff; |
| 394 | } |
| 395 | } |
| 396 | for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break; |
| 397 | *bits |= mask; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 398 | LeaveCriticalSection( &process->crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 399 | return ret + i; |
| 400 | } |
| 401 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 402 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 403 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 404 | * TlsFree [KERNEL32.531] Releases a TLS index. |
| 405 | * |
| 406 | * Releases a thread local storage index, making it available for reuse |
| 407 | * |
| 408 | * RETURNS |
| 409 | * Success: TRUE |
| 410 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 411 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 412 | BOOL WINAPI TlsFree( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 413 | DWORD index) /* [in] TLS Index to free */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 414 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 415 | PDB *process = PROCESS_Current(); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 416 | DWORD mask; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 417 | DWORD *bits = process->tls_bits; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 418 | if (index >= 64) |
| 419 | { |
| 420 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 421 | return FALSE; |
| 422 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 423 | EnterCriticalSection( &process->crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 424 | if (index >= 32) bits++; |
| 425 | mask = (1 << (index & 31)); |
| 426 | if (!(*bits & mask)) /* already free? */ |
| 427 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 428 | LeaveCriticalSection( &process->crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 429 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 430 | return FALSE; |
| 431 | } |
| 432 | *bits &= ~mask; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 433 | NtCurrentTeb()->tls_array[index] = 0; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 434 | /* FIXME: should zero all other thread values */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 435 | LeaveCriticalSection( &process->crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 436 | return TRUE; |
| 437 | } |
| 438 | |
| 439 | |
| 440 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 441 | * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot |
| 442 | * |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 443 | * RETURNS |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 444 | * Success: Value stored in calling thread's TLS slot for index |
| 445 | * Failure: 0 and GetLastError returns NO_ERROR |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 446 | */ |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 447 | LPVOID WINAPI TlsGetValue( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 448 | DWORD index) /* [in] TLS index to retrieve value for */ |
| 449 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 450 | if (index >= 64) |
| 451 | { |
| 452 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 453 | return NULL; |
| 454 | } |
| 455 | SetLastError( ERROR_SUCCESS ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 456 | return NtCurrentTeb()->tls_array[index]; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | |
| 460 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 461 | * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot. |
| 462 | * |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 463 | * RETURNS |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 464 | * Success: TRUE |
| 465 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 466 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 467 | BOOL WINAPI TlsSetValue( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 468 | DWORD index, /* [in] TLS index to set value for */ |
| 469 | LPVOID value) /* [in] Value to be stored */ |
| 470 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 471 | if (index >= 64) |
| 472 | { |
| 473 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 474 | return FALSE; |
| 475 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 476 | NtCurrentTeb()->tls_array[index] = value; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 477 | return TRUE; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | /*********************************************************************** |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 482 | * SetThreadContext [KERNEL32.670] Sets context of thread. |
| 483 | * |
| 484 | * RETURNS |
| 485 | * Success: TRUE |
| 486 | * Failure: FALSE |
| 487 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 488 | BOOL WINAPI SetThreadContext( |
| 489 | HANDLE handle, /* [in] Handle to thread with context */ |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 490 | CONTEXT *context) /* [out] Address of context structure */ |
| 491 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 492 | FIXME("not implemented\n" ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 493 | return TRUE; |
| 494 | } |
| 495 | |
| 496 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 497 | * GetThreadContext [KERNEL32.294] Retrieves context of thread. |
| 498 | * |
| 499 | * RETURNS |
| 500 | * Success: TRUE |
| 501 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 502 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 503 | BOOL WINAPI GetThreadContext( |
| 504 | HANDLE handle, /* [in] Handle to thread with context */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 505 | CONTEXT *context) /* [out] Address of context structure */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 506 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 507 | WORD cs, ds; |
| 508 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 509 | FIXME("returning dummy info\n" ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 510 | |
| 511 | /* make up some plausible values for segment registers */ |
| 512 | GET_CS(cs); |
| 513 | GET_DS(ds); |
| 514 | context->SegCs = cs; |
| 515 | context->SegDs = ds; |
| 516 | context->SegEs = ds; |
| 517 | context->SegGs = ds; |
| 518 | context->SegSs = ds; |
| 519 | context->SegFs = ds; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 520 | return TRUE; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | |
| 524 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 525 | * GetThreadPriority [KERNEL32.296] Returns priority for thread. |
| 526 | * |
| 527 | * RETURNS |
| 528 | * Success: Thread's priority level. |
| 529 | * Failure: THREAD_PRIORITY_ERROR_RETURN |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 530 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 531 | INT WINAPI GetThreadPriority( |
| 532 | HANDLE hthread) /* [in] Handle to thread */ |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 533 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 534 | INT ret = THREAD_PRIORITY_ERROR_RETURN; |
| 535 | struct get_thread_info_request *req = get_req_buffer(); |
| 536 | req->handle = hthread; |
| 537 | if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority; |
| 538 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 541 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 542 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 543 | * SetThreadPriority [KERNEL32.514] Sets priority for thread. |
| 544 | * |
| 545 | * RETURNS |
| 546 | * Success: TRUE |
| 547 | * Failure: FALSE |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 548 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 549 | BOOL WINAPI SetThreadPriority( |
| 550 | HANDLE hthread, /* [in] Handle to thread */ |
| 551 | INT priority) /* [in] Thread priority level */ |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 552 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 553 | struct set_thread_info_request *req = get_req_buffer(); |
| 554 | req->handle = hthread; |
| 555 | req->priority = priority; |
| 556 | req->mask = SET_THREAD_INFO_PRIORITY; |
| 557 | return !server_call( REQ_SET_THREAD_INFO ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
| 561 | /********************************************************************** |
| 562 | * SetThreadAffinityMask (KERNEL32.669) |
| 563 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 564 | DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 565 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 566 | struct set_thread_info_request *req = get_req_buffer(); |
| 567 | req->handle = hThread; |
| 568 | req->affinity = dwThreadAffinityMask; |
| 569 | req->mask = SET_THREAD_INFO_AFFINITY; |
| 570 | if (server_call( REQ_SET_THREAD_INFO )) return 0; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 571 | return 1; /* FIXME: should return previous value */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 572 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 573 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 574 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 575 | /********************************************************************** |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 576 | * TerminateThread [KERNEL32.685] Terminates a thread |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 577 | * |
| 578 | * RETURNS |
| 579 | * Success: TRUE |
| 580 | * Failure: FALSE |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 581 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 582 | BOOL WINAPI TerminateThread( |
| 583 | HANDLE handle, /* [in] Handle to thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 584 | DWORD exitcode) /* [in] Exit code for thread */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 585 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 586 | struct terminate_thread_request *req = get_req_buffer(); |
| 587 | req->handle = handle; |
| 588 | req->exit_code = exitcode; |
| 589 | return !server_call( REQ_TERMINATE_THREAD ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 590 | } |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 591 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 592 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 593 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 594 | * GetExitCodeThread [KERNEL32.???] Gets termination status of thread. |
| 595 | * |
| 596 | * RETURNS |
| 597 | * Success: TRUE |
| 598 | * Failure: FALSE |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 599 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 600 | BOOL WINAPI GetExitCodeThread( |
| 601 | HANDLE hthread, /* [in] Handle to thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 602 | LPDWORD exitcode) /* [out] Address to receive termination status */ |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 603 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 604 | BOOL ret = FALSE; |
| 605 | struct get_thread_info_request *req = get_req_buffer(); |
| 606 | req->handle = hthread; |
| 607 | if (!server_call( REQ_GET_THREAD_INFO )) |
| 608 | { |
| 609 | if (exitcode) *exitcode = req->exit_code; |
| 610 | ret = TRUE; |
| 611 | } |
| 612 | return ret; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 615 | |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 616 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 617 | * ResumeThread [KERNEL32.587] Resumes a thread. |
| 618 | * |
| 619 | * Decrements a thread's suspend count. When count is zero, the |
| 620 | * execution of the thread is resumed. |
| 621 | * |
| 622 | * RETURNS |
| 623 | * Success: Previous suspend count |
| 624 | * Failure: 0xFFFFFFFF |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 625 | * Already running: 0 |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 626 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 627 | DWORD WINAPI ResumeThread( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 628 | HANDLE hthread) /* [in] Identifies thread to restart */ |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 629 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 630 | DWORD ret = 0xffffffff; |
| 631 | struct resume_thread_request *req = get_req_buffer(); |
| 632 | req->handle = hthread; |
| 633 | if (!server_call( REQ_RESUME_THREAD )) ret = req->count; |
| 634 | return ret; |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 635 | } |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 636 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 637 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 638 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 639 | * SuspendThread [KERNEL32.681] Suspends a thread. |
| 640 | * |
| 641 | * RETURNS |
| 642 | * Success: Previous suspend count |
| 643 | * Failure: 0xFFFFFFFF |
| 644 | */ |
| 645 | DWORD WINAPI SuspendThread( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 646 | HANDLE hthread) /* [in] Handle to the thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 647 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 648 | DWORD ret = 0xffffffff; |
| 649 | struct suspend_thread_request *req = get_req_buffer(); |
| 650 | req->handle = hthread; |
| 651 | if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count; |
| 652 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 653 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 654 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 655 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 656 | /*********************************************************************** |
| 657 | * QueueUserAPC (KERNEL32.566) |
| 658 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 659 | DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 660 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame^] | 661 | struct queue_apc_request *req = get_req_buffer(); |
| 662 | req->handle = hthread; |
| 663 | req->func = func; |
| 664 | req->param = (void *)data; |
| 665 | return !server_call( REQ_QUEUE_APC ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
| 669 | /********************************************************************** |
| 670 | * GetThreadTimes [KERNEL32.???] Obtains timing information. |
| 671 | * |
| 672 | * NOTES |
| 673 | * What are the fields where these values are stored? |
| 674 | * |
| 675 | * RETURNS |
| 676 | * Success: TRUE |
| 677 | * Failure: FALSE |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 678 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 679 | BOOL WINAPI GetThreadTimes( |
| 680 | HANDLE thread, /* [in] Specifies the thread of interest */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 681 | LPFILETIME creationtime, /* [out] When the thread was created */ |
| 682 | LPFILETIME exittime, /* [out] When the thread was destroyed */ |
| 683 | LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */ |
| 684 | LPFILETIME usertime) /* [out] Time thread spent in user mode */ |
| 685 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 686 | FIXME("(0x%08x): stub\n",thread); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 687 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 688 | return FALSE; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 689 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 690 | |
| 691 | |
| 692 | /********************************************************************** |
| 693 | * AttachThreadInput [KERNEL32.8] Attaches input of 1 thread to other |
| 694 | * |
| 695 | * Attaches the input processing mechanism of one thread to that of |
| 696 | * another thread. |
| 697 | * |
| 698 | * RETURNS |
| 699 | * Success: TRUE |
| 700 | * Failure: FALSE |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 701 | * |
| 702 | * TODO: |
| 703 | * 1. Reset the Key State (currenly per thread key state is not maintained) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 704 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 705 | BOOL WINAPI AttachThreadInput( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 706 | DWORD idAttach, /* [in] Thread to attach */ |
| 707 | DWORD idAttachTo, /* [in] Thread to attach to */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 708 | BOOL fAttach) /* [in] Attach or detach */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 709 | { |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 710 | MESSAGEQUEUE *pSrcMsgQ = 0, *pTgtMsgQ = 0; |
| 711 | BOOL16 bRet = 0; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 712 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 713 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 714 | |
| 715 | /* A thread cannot attach to itself */ |
| 716 | if ( idAttach == idAttachTo ) |
| 717 | goto CLEANUP; |
| 718 | |
| 719 | /* According to the docs this method should fail if a |
| 720 | * "Journal record" hook is installed. (attaches all input queues together) |
| 721 | */ |
| 722 | if ( HOOK_IsHooked( WH_JOURNALRECORD ) ) |
| 723 | goto CLEANUP; |
| 724 | |
| 725 | /* Retrieve message queues corresponding to the thread id's */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 726 | pTgtMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetThreadQueue16( idAttach ) ); |
| 727 | pSrcMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetThreadQueue16( idAttachTo ) ); |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 728 | |
| 729 | /* Ensure we have message queues and that Src and Tgt threads |
| 730 | * are not system threads. |
| 731 | */ |
| 732 | if ( !pSrcMsgQ || !pTgtMsgQ || !pSrcMsgQ->pQData || !pTgtMsgQ->pQData ) |
| 733 | goto CLEANUP; |
| 734 | |
| 735 | if (fAttach) /* Attach threads */ |
| 736 | { |
| 737 | /* Only attach if currently detached */ |
| 738 | if ( pTgtMsgQ->pQData != pSrcMsgQ->pQData ) |
| 739 | { |
| 740 | /* First release the target threads perQData */ |
| 741 | PERQDATA_Release( pTgtMsgQ->pQData ); |
| 742 | |
| 743 | /* Share a reference to the source threads perQDATA */ |
| 744 | PERQDATA_Addref( pSrcMsgQ->pQData ); |
| 745 | pTgtMsgQ->pQData = pSrcMsgQ->pQData; |
| 746 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 747 | } |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 748 | else /* Detach threads */ |
| 749 | { |
| 750 | /* Only detach if currently attached */ |
| 751 | if ( pTgtMsgQ->pQData == pSrcMsgQ->pQData ) |
| 752 | { |
| 753 | /* First release the target threads perQData */ |
| 754 | PERQDATA_Release( pTgtMsgQ->pQData ); |
| 755 | |
| 756 | /* Give the target thread its own private perQDATA once more */ |
| 757 | pTgtMsgQ->pQData = PERQDATA_CreateInstance(); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | /* TODO: Reset the Key State */ |
| 762 | |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 763 | bRet = 1; /* Success */ |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 764 | |
| 765 | CLEANUP: |
| 766 | |
| 767 | /* Unlock the queues before returning */ |
| 768 | if ( pSrcMsgQ ) |
| 769 | QUEUE_Unlock( pSrcMsgQ ); |
| 770 | if ( pTgtMsgQ ) |
| 771 | QUEUE_Unlock( pTgtMsgQ ); |
| 772 | |
| 773 | return bRet; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 776 | /********************************************************************** |
| 777 | * VWin32_BoostThreadGroup [KERNEL.535] |
| 778 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 779 | VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 780 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 781 | FIXME("(0x%08lx,%d): stub\n", threadId, boost); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /********************************************************************** |
| 785 | * VWin32_BoostThreadStatic [KERNEL.536] |
| 786 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 787 | VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 788 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 789 | FIXME("(0x%08lx,%d): stub\n", threadId, boost); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Guy Albertelli | c66f5d5 | 1999-01-24 09:59:14 +0000 | [diff] [blame] | 792 | /********************************************************************** |
| 793 | * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale. |
| 794 | * |
| 795 | * RETURNS |
| 796 | * Success: TRUE |
| 797 | * Failure: FALSE |
| 798 | * |
| 799 | * NOTES |
| 800 | * Implemented in NT only (3.1 and above according to MS |
| 801 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 802 | BOOL WINAPI SetThreadLocale( |
Guy Albertelli | c66f5d5 | 1999-01-24 09:59:14 +0000 | [diff] [blame] | 803 | LCID lcid) /* [in] Locale identifier */ |
| 804 | { |
| 805 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 806 | return FALSE; |
| 807 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 808 | |
| 809 | |
| 810 | /********************************************************************** |
| 811 | * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code. |
| 812 | * |
| 813 | * RETURNS |
| 814 | * None. |
| 815 | */ |
| 816 | #undef SetLastError |
| 817 | void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */ |
| 818 | { |
| 819 | NtCurrentTeb()->last_error = error; |
| 820 | } |
| 821 | |
| 822 | |
| 823 | /*********************************************************************** |
| 824 | * GetCurrentThreadId [KERNEL32.201] Returns thread identifier. |
| 825 | * |
| 826 | * RETURNS |
| 827 | * Thread identifier of calling thread |
| 828 | */ |
| 829 | #undef GetCurrentThreadId |
| 830 | DWORD WINAPI GetCurrentThreadId(void) |
| 831 | { |
| 832 | return (DWORD)NtCurrentTeb()->tid; |
| 833 | } |