Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 threads |
| 3 | * |
| 4 | * Copyright 1996 Alexandre Julliard |
| 5 | */ |
| 6 | |
Patrik Stridvall | 478eee1 | 1999-07-31 13:13:23 +0000 | [diff] [blame] | 7 | #include "config.h" |
| 8 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 9 | #include <assert.h> |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 10 | #include <fcntl.h> |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 11 | #include <sys/types.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 12 | #ifdef HAVE_SYS_MMAN_H |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 13 | #include <sys/mman.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 14 | #endif |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 15 | #include <unistd.h> |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 16 | #include "wine/winbase16.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 17 | #include "thread.h" |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 18 | #include "process.h" |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 19 | #include "task.h" |
| 20 | #include "module.h" |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 21 | #include "global.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 22 | #include "winerror.h" |
| 23 | #include "heap.h" |
| 24 | #include "selectors.h" |
| 25 | #include "winnt.h" |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 26 | #include "server.h" |
Ulrich Weigand | 36a1a25 | 1999-05-08 10:48:03 +0000 | [diff] [blame] | 27 | #include "services.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 28 | #include "stackframe.h" |
Ulrich Weigand | f0a1c2f | 1999-09-20 18:45:28 +0000 | [diff] [blame] | 29 | #include "builtin16.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 30 | #include "debugtools.h" |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 31 | #include "winnls.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 33 | DEFAULT_DEBUG_CHANNEL(thread); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 35 | /* TEB of the initial thread */ |
| 36 | static TEB initial_teb; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 37 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 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 | { |
Ulrich Weigand | f3bfa3a | 2000-01-30 21:16:06 +0000 | [diff] [blame] | 43 | return !teb || !(teb->tibflags & 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 | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 53 | TEB *ret = NULL; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 54 | |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 55 | if (!id || id == GetCurrentThreadId()) return NtCurrentTeb(); |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 56 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 57 | SERVER_START_REQ |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 58 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 59 | struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 60 | req->handle = -1; |
| 61 | req->tid_in = (void *)id; |
| 62 | if (!server_call_noerr( REQ_GET_THREAD_INFO )) ret = req->teb; |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 63 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 64 | SERVER_END_REQ; |
| 65 | |
| 66 | if (!ret) |
| 67 | { |
| 68 | /* Allow task handles to be used; convert to main thread */ |
| 69 | if ( IsTask16( id ) ) |
| 70 | { |
| 71 | TDB *pTask = (TDB *)GlobalLock16( id ); |
| 72 | if (pTask) return pTask->teb; |
| 73 | } |
| 74 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 75 | } |
| 76 | return ret; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 80 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 81 | * THREAD_InitTEB |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 82 | * |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 83 | * Initialization of a newly created TEB. |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 84 | */ |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 85 | static BOOL THREAD_InitTEB( TEB *teb ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 86 | { |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 87 | teb->except = (void *)~0UL; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 88 | teb->self = teb; |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 89 | teb->tibflags = TEBF_WIN32; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 90 | teb->tls_ptr = teb->tls_array; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 91 | teb->exit_code = STILL_ACTIVE; |
| 92 | teb->socket = -1; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 93 | teb->stack_top = (void *)~0UL; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 94 | teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer); |
| 95 | teb->StaticUnicodeString.Buffer = (PWSTR)teb->StaticUnicodeBuffer; |
| 96 | teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, SEGMENT_DATA, TRUE, FALSE ); |
| 97 | return (teb->teb_sel != 0); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /*********************************************************************** |
| 102 | * THREAD_FreeTEB |
| 103 | * |
| 104 | * Free data structures associated with a thread. |
| 105 | * Must be called from the context of another thread. |
| 106 | */ |
| 107 | static void CALLBACK THREAD_FreeTEB( TEB *teb ) |
| 108 | { |
| 109 | TRACE("(%p) called\n", teb ); |
| 110 | if (teb->cleanup) SERVICE_Delete( teb->cleanup ); |
| 111 | |
| 112 | /* Free the associated memory */ |
| 113 | |
| 114 | if (teb->socket != -1) close( teb->socket ); |
| 115 | if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 ); |
| 116 | SELECTOR_FreeBlock( teb->teb_sel, 1 ); |
Alexandre Julliard | 8611353 | 2000-08-29 03:54:30 +0000 | [diff] [blame] | 117 | if (teb->buffer) munmap( (void *)teb->buffer, |
| 118 | (char *)(teb->buffer_info+1) - (char *)teb->buffer ); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 119 | if (teb->debug_info) HeapFree( GetProcessHeap(), 0, teb->debug_info ); |
| 120 | VirtualFree( teb->stack_base, 0, MEM_RELEASE ); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /*********************************************************************** |
| 125 | * THREAD_InitStack |
| 126 | * |
| 127 | * Allocate the stack of a thread. |
| 128 | */ |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 129 | TEB *THREAD_InitStack( TEB *teb, DWORD stack_size, BOOL alloc_stack16 ) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 130 | { |
| 131 | DWORD old_prot, total_size; |
| 132 | DWORD page_size = VIRTUAL_GetPageSize(); |
| 133 | void *base; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 134 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 135 | /* Allocate the stack */ |
| 136 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 137 | if (stack_size >= 16*1024*1024) |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 138 | WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 139 | |
Alexandre Julliard | ce68603 | 2000-05-03 17:45:14 +0000 | [diff] [blame] | 140 | /* if size is smaller than default, get stack size from parent */ |
| 141 | if (stack_size < 1024 * 1024) |
| 142 | { |
| 143 | if (teb) |
| 144 | stack_size = 1024 * 1024; /* no parent */ |
| 145 | else |
| 146 | stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->stack_base |
| 147 | - SIGNAL_STACK_SIZE - 3 * page_size); |
| 148 | } |
| 149 | |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 150 | /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */ |
| 151 | stack_size += 64 * 1024; |
| 152 | |
| 153 | /* Memory layout in allocated block: |
| 154 | * |
| 155 | * size contents |
| 156 | * 1 page NOACCESS guard page |
| 157 | * SIGNAL_STACK_SIZE signal stack |
| 158 | * 1 page NOACCESS guard page |
| 159 | * 1 page PAGE_GUARD guard page |
| 160 | * stack_size normal stack |
| 161 | * 64Kb 16-bit stack (optional) |
| 162 | * 1 page TEB (except for initial thread) |
| 163 | */ |
| 164 | |
| 165 | stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1); |
| 166 | total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size; |
| 167 | if (alloc_stack16) total_size += 0x10000; |
| 168 | if (!teb) total_size += page_size; |
| 169 | |
| 170 | if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE ))) |
| 171 | return NULL; |
| 172 | |
| 173 | if (!teb) |
| 174 | { |
| 175 | teb = (TEB *)((char *)base + total_size - page_size); |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 176 | if (!THREAD_InitTEB( teb )) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 177 | { |
| 178 | VirtualFree( base, 0, MEM_RELEASE ); |
| 179 | return NULL; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | teb->stack_low = base; |
| 184 | teb->stack_base = base; |
| 185 | teb->signal_stack = (char *)base + page_size; |
| 186 | teb->stack_top = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size; |
| 187 | |
| 188 | /* Setup guard pages */ |
| 189 | |
| 190 | VirtualProtect( base, 1, PAGE_NOACCESS, &old_prot ); |
| 191 | VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot ); |
| 192 | VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1, |
| 193 | PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 194 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 195 | /* Allocate the 16-bit stack selector */ |
| 196 | |
| 197 | if (alloc_stack16) |
| 198 | { |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 199 | teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, SEGMENT_DATA, |
| 200 | FALSE, FALSE ); |
| 201 | if (!teb->stack_sel) goto error; |
| 202 | teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( teb->stack_sel, |
| 203 | 0x10000 - sizeof(STACK16FRAME) ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 204 | } |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 205 | return teb; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 206 | |
| 207 | error: |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 208 | THREAD_FreeTEB( teb ); |
| 209 | return NULL; |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | |
| 213 | /*********************************************************************** |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 214 | * THREAD_Init |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 215 | * |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 216 | * Setup the initial thread. |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 217 | * |
| 218 | * NOTES: The first allocated TEB on NT is at 0x7ffde000. |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 219 | */ |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 220 | void THREAD_Init(void) |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 221 | { |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 222 | if (!initial_teb.self) /* do it only once */ |
| 223 | { |
| 224 | THREAD_InitTEB( &initial_teb ); |
| 225 | assert( initial_teb.teb_sel ); |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 226 | initial_teb.process = ¤t_process; |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 227 | SYSDEPS_SetCurThread( &initial_teb ); |
| 228 | } |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 231 | DECL_GLOBAL_CONSTRUCTOR(thread_init) { THREAD_Init(); } |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 232 | |
| 233 | /*********************************************************************** |
| 234 | * THREAD_Create |
Juergen Schmied | 71e69dd | 1999-12-25 22:49:33 +0000 | [diff] [blame] | 235 | * |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 236 | */ |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 237 | TEB *THREAD_Create( int fd, DWORD stack_size, BOOL alloc_stack16 ) |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 238 | { |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 239 | TEB *teb; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 240 | |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 241 | if ((teb = THREAD_InitStack( NULL, stack_size, alloc_stack16 ))) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 242 | { |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 243 | teb->tibflags = (current_process.flags & PDB32_WIN16_PROC) ? 0 : TEBF_WIN32; |
| 244 | teb->process = ¤t_process; |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 245 | teb->socket = fd; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 246 | fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */ |
| 247 | TRACE("(%p) succeeded\n", teb); |
| 248 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 249 | return teb; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | |
| 253 | /*********************************************************************** |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 254 | * THREAD_Start |
| 255 | * |
| 256 | * Start execution of a newly created thread. Does not return. |
| 257 | */ |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 258 | static void THREAD_Start(void) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 259 | { |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 260 | HANDLE cleanup_object; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 261 | LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point; |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 262 | |
| 263 | /* install cleanup handler */ |
| 264 | if (DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), |
| 265 | GetCurrentProcess(), &cleanup_object, |
| 266 | 0, FALSE, DUPLICATE_SAME_ACCESS )) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 267 | NtCurrentTeb()->cleanup = SERVICE_AddObject( cleanup_object, (PAPCFUNC)THREAD_FreeTEB, |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 268 | (ULONG_PTR)NtCurrentTeb() ); |
| 269 | |
| 270 | PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 ); |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 271 | PE_InitTls(); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 272 | MODULE_DllThreadAttach( NULL ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 273 | ExitThread( func( NtCurrentTeb()->entry_arg ) ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | |
| 277 | /*********************************************************************** |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 278 | * CreateThread (KERNEL32.63) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 279 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 280 | HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack, |
Ulrich Weigand | 4526f2e | 1999-03-16 16:28:59 +0000 | [diff] [blame] | 281 | LPTHREAD_START_ROUTINE start, LPVOID param, |
| 282 | DWORD flags, LPDWORD id ) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 283 | { |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 284 | int socket, handle = -1; |
| 285 | TEB *teb; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 286 | void *tid = 0; |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 287 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 288 | SERVER_START_REQ |
| 289 | { |
| 290 | struct new_thread_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 291 | |
| 292 | req->suspend = ((flags & CREATE_SUSPENDED) != 0); |
| 293 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 294 | if (!server_call_fd( REQ_NEW_THREAD, -1, &socket )) |
| 295 | { |
| 296 | handle = req->handle; |
| 297 | tid = req->tid; |
| 298 | } |
| 299 | } |
| 300 | SERVER_END_REQ; |
| 301 | if (handle == -1) return 0; |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 302 | |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 303 | if (!(teb = THREAD_Create( socket, stack, TRUE ))) |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 304 | { |
| 305 | close( socket ); |
| 306 | return 0; |
| 307 | } |
Ulrich Weigand | f3bfa3a | 2000-01-30 21:16:06 +0000 | [diff] [blame] | 308 | teb->tibflags |= TEBF_WIN32; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 309 | teb->entry_point = start; |
| 310 | teb->entry_arg = param; |
| 311 | teb->startup = THREAD_Start; |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 312 | teb->htask16 = GetCurrentTask(); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 313 | if (id) *id = (DWORD)tid; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 314 | if (SYSDEPS_SpawnThread( teb ) == -1) |
Alexandre Julliard | 96c08d8 | 1999-02-28 13:27:56 +0000 | [diff] [blame] | 315 | { |
| 316 | CloseHandle( handle ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 317 | THREAD_FreeTEB( teb ); |
Alexandre Julliard | 617955d | 1999-06-26 18:40:24 +0000 | [diff] [blame] | 318 | return 0; |
Alexandre Julliard | 96c08d8 | 1999-02-28 13:27:56 +0000 | [diff] [blame] | 319 | } |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 320 | return handle; |
| 321 | } |
| 322 | |
Ulrich Weigand | f0a1c2f | 1999-09-20 18:45:28 +0000 | [diff] [blame] | 323 | /*********************************************************************** |
| 324 | * CreateThread16 (KERNEL.441) |
| 325 | */ |
| 326 | static DWORD CALLBACK THREAD_StartThread16( LPVOID threadArgs ) |
| 327 | { |
| 328 | FARPROC16 start = ((FARPROC16 *)threadArgs)[0]; |
| 329 | DWORD param = ((DWORD *)threadArgs)[1]; |
| 330 | HeapFree( GetProcessHeap(), 0, threadArgs ); |
| 331 | |
| 332 | ((LPDWORD)CURRENT_STACK16)[-1] = param; |
| 333 | return CallTo16Long( start, sizeof(DWORD) ); |
| 334 | } |
| 335 | HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack, |
| 336 | FARPROC16 start, SEGPTR param, |
| 337 | DWORD flags, LPDWORD id ) |
| 338 | { |
| 339 | DWORD *threadArgs = HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD) ); |
| 340 | if (!threadArgs) return INVALID_HANDLE_VALUE; |
| 341 | threadArgs[0] = (DWORD)start; |
| 342 | threadArgs[1] = (DWORD)param; |
| 343 | |
| 344 | return CreateThread( sa, stack, THREAD_StartThread16, threadArgs, flags, id ); |
| 345 | } |
| 346 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 347 | |
| 348 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 349 | * ExitThread [KERNEL32.215] Ends a thread |
| 350 | * |
| 351 | * RETURNS |
| 352 | * None |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 353 | */ |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 354 | void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */ |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 355 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 356 | BOOL last; |
| 357 | SERVER_START_REQ |
| 358 | { |
| 359 | struct terminate_thread_request *req = server_alloc_req( sizeof(*req), 0 ); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 360 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 361 | /* send the exit code to the server */ |
| 362 | req->handle = GetCurrentThread(); |
| 363 | req->exit_code = code; |
| 364 | server_call( REQ_TERMINATE_THREAD ); |
| 365 | last = req->last; |
| 366 | } |
| 367 | SERVER_END_REQ; |
| 368 | |
| 369 | if (last) |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 370 | { |
| 371 | MODULE_DllProcessDetach( TRUE, (LPVOID)1 ); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 372 | exit( code ); |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | MODULE_DllThreadDetach( NULL ); |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 377 | if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_KillTask( 0 ); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 378 | SYSDEPS_ExitThread( code ); |
| 379 | } |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 383 | /********************************************************************** |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 384 | * TlsAlloc [KERNEL32.530] Allocates a TLS index. |
| 385 | * |
| 386 | * Allocates a thread local storage index |
| 387 | * |
| 388 | * RETURNS |
| 389 | * Success: TLS Index |
| 390 | * Failure: 0xFFFFFFFF |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 391 | */ |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 392 | DWORD WINAPI TlsAlloc( void ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 393 | { |
| 394 | DWORD i, mask, ret = 0; |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 395 | DWORD *bits = current_process.tls_bits; |
| 396 | EnterCriticalSection( ¤t_process.crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 397 | if (*bits == 0xffffffff) |
| 398 | { |
| 399 | bits++; |
| 400 | ret = 32; |
| 401 | if (*bits == 0xffffffff) |
| 402 | { |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 403 | LeaveCriticalSection( ¤t_process.crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 404 | SetLastError( ERROR_NO_MORE_ITEMS ); |
| 405 | return 0xffffffff; |
| 406 | } |
| 407 | } |
| 408 | for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break; |
| 409 | *bits |= mask; |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 410 | LeaveCriticalSection( ¤t_process.crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 411 | return ret + i; |
| 412 | } |
| 413 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 414 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 415 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 416 | * TlsFree [KERNEL32.531] Releases a TLS index. |
| 417 | * |
| 418 | * Releases a thread local storage index, making it available for reuse |
| 419 | * |
| 420 | * RETURNS |
| 421 | * Success: TRUE |
| 422 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 423 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 424 | BOOL WINAPI TlsFree( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 425 | DWORD index) /* [in] TLS Index to free */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 426 | { |
| 427 | DWORD mask; |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 428 | DWORD *bits = current_process.tls_bits; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 429 | if (index >= 64) |
| 430 | { |
| 431 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 432 | return FALSE; |
| 433 | } |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 434 | EnterCriticalSection( ¤t_process.crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 435 | if (index >= 32) bits++; |
| 436 | mask = (1 << (index & 31)); |
| 437 | if (!(*bits & mask)) /* already free? */ |
| 438 | { |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 439 | LeaveCriticalSection( ¤t_process.crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 440 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 441 | return FALSE; |
| 442 | } |
| 443 | *bits &= ~mask; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 444 | NtCurrentTeb()->tls_array[index] = 0; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 445 | /* FIXME: should zero all other thread values */ |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 446 | LeaveCriticalSection( ¤t_process.crit_section ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 447 | return TRUE; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 452 | * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot |
| 453 | * |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 454 | * RETURNS |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 455 | * Success: Value stored in calling thread's TLS slot for index |
| 456 | * Failure: 0 and GetLastError returns NO_ERROR |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 457 | */ |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 458 | LPVOID WINAPI TlsGetValue( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 459 | DWORD index) /* [in] TLS index to retrieve value for */ |
| 460 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 461 | if (index >= 64) |
| 462 | { |
| 463 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 464 | return NULL; |
| 465 | } |
| 466 | SetLastError( ERROR_SUCCESS ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 467 | return NtCurrentTeb()->tls_array[index]; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | |
| 471 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 472 | * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot. |
| 473 | * |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 474 | * RETURNS |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 475 | * Success: TRUE |
| 476 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 477 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 478 | BOOL WINAPI TlsSetValue( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 479 | DWORD index, /* [in] TLS index to set value for */ |
| 480 | LPVOID value) /* [in] Value to be stored */ |
| 481 | { |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 482 | if (index >= 64) |
| 483 | { |
| 484 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 485 | return FALSE; |
| 486 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 487 | NtCurrentTeb()->tls_array[index] = value; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 488 | return TRUE; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | /*********************************************************************** |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 493 | * SetThreadContext [KERNEL32.670] Sets context of thread. |
| 494 | * |
| 495 | * RETURNS |
| 496 | * Success: TRUE |
| 497 | * Failure: FALSE |
| 498 | */ |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 499 | BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ |
| 500 | const CONTEXT *context ) /* [in] Address of context structure */ |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 501 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 502 | BOOL ret; |
| 503 | SERVER_START_REQ |
| 504 | { |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 505 | struct set_thread_context_request *req = server_alloc_req( sizeof(*req), |
| 506 | sizeof(*context) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 507 | req->handle = handle; |
| 508 | req->flags = context->ContextFlags; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 509 | memcpy( server_data_ptr(req), context, sizeof(*context) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 510 | ret = !server_call( REQ_SET_THREAD_CONTEXT ); |
| 511 | } |
| 512 | SERVER_END_REQ; |
| 513 | return ret; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 516 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 517 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 518 | * GetThreadContext [KERNEL32.294] Retrieves context of thread. |
| 519 | * |
| 520 | * RETURNS |
| 521 | * Success: TRUE |
| 522 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 523 | */ |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 524 | BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ |
| 525 | CONTEXT *context ) /* [out] Address of context structure */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 526 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 527 | BOOL ret; |
| 528 | SERVER_START_REQ |
| 529 | { |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 530 | struct get_thread_context_request *req = server_alloc_req( sizeof(*req), |
| 531 | sizeof(*context) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 532 | req->handle = handle; |
| 533 | req->flags = context->ContextFlags; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 534 | memcpy( server_data_ptr(req), context, sizeof(*context) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 535 | if ((ret = !server_call( REQ_GET_THREAD_CONTEXT ))) |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 536 | memcpy( context, server_data_ptr(req), sizeof(*context) ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 537 | } |
| 538 | SERVER_END_REQ; |
| 539 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | |
| 543 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 544 | * GetThreadPriority [KERNEL32.296] Returns priority for thread. |
| 545 | * |
| 546 | * RETURNS |
| 547 | * Success: Thread's priority level. |
| 548 | * Failure: THREAD_PRIORITY_ERROR_RETURN |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 549 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 550 | INT WINAPI GetThreadPriority( |
| 551 | HANDLE hthread) /* [in] Handle to thread */ |
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 | INT ret = THREAD_PRIORITY_ERROR_RETURN; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 554 | SERVER_START_REQ |
| 555 | { |
| 556 | struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 557 | req->handle = hthread; |
| 558 | req->tid_in = 0; |
| 559 | if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority; |
| 560 | } |
| 561 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 562 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 565 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 566 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 567 | * SetThreadPriority [KERNEL32.514] Sets priority for thread. |
| 568 | * |
| 569 | * RETURNS |
| 570 | * Success: TRUE |
| 571 | * Failure: FALSE |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 572 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 573 | BOOL WINAPI SetThreadPriority( |
| 574 | HANDLE hthread, /* [in] Handle to thread */ |
| 575 | INT priority) /* [in] Thread priority level */ |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 576 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 577 | BOOL ret; |
| 578 | SERVER_START_REQ |
| 579 | { |
| 580 | struct set_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 581 | req->handle = hthread; |
| 582 | req->priority = priority; |
| 583 | req->mask = SET_THREAD_INFO_PRIORITY; |
| 584 | ret = !server_call( REQ_SET_THREAD_INFO ); |
| 585 | } |
| 586 | SERVER_END_REQ; |
| 587 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
| 591 | /********************************************************************** |
Slava Monich | fb8934d | 2000-07-08 12:47:30 +0000 | [diff] [blame] | 592 | * GetThreadPriorityBoost [KERNEL32.877] Returns priority boost for thread. |
| 593 | * |
| 594 | * Always reports that priority boost is disabled. |
| 595 | * |
| 596 | * RETURNS |
| 597 | * Success: TRUE. |
| 598 | * Failure: FALSE |
| 599 | */ |
| 600 | BOOL WINAPI GetThreadPriorityBoost( |
| 601 | HANDLE hthread, /* [in] Handle to thread */ |
| 602 | PBOOL pstate) /* [out] pointer to var that receives the boost state */ |
| 603 | { |
| 604 | if (pstate) *pstate = FALSE; |
| 605 | return NO_ERROR; |
| 606 | } |
| 607 | |
| 608 | |
| 609 | /********************************************************************** |
| 610 | * SetThreadPriorityBoost [KERNEL32.893] Sets priority boost for thread. |
| 611 | * |
| 612 | * Priority boost is not implemented. Thsi function always returns |
| 613 | * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED |
| 614 | * |
| 615 | * RETURNS |
| 616 | * Always returns FALSE to indicate a failure |
| 617 | */ |
| 618 | BOOL WINAPI SetThreadPriorityBoost( |
| 619 | HANDLE hthread, /* [in] Handle to thread */ |
| 620 | BOOL disable) /* [in] TRUE to disable priority boost */ |
| 621 | { |
| 622 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 623 | return FALSE; |
| 624 | } |
| 625 | |
| 626 | |
| 627 | /********************************************************************** |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 628 | * SetThreadAffinityMask (KERNEL32.669) |
| 629 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 630 | DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 631 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 632 | DWORD ret; |
| 633 | SERVER_START_REQ |
| 634 | { |
| 635 | struct set_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 636 | req->handle = hThread; |
| 637 | req->affinity = dwThreadAffinityMask; |
| 638 | req->mask = SET_THREAD_INFO_AFFINITY; |
| 639 | ret = !server_call( REQ_SET_THREAD_INFO ); |
| 640 | /* FIXME: should return previous value */ |
| 641 | } |
| 642 | SERVER_END_REQ; |
| 643 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 644 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 645 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 646 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 647 | /********************************************************************** |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 648 | * TerminateThread [KERNEL32.685] Terminates a thread |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 649 | * |
| 650 | * RETURNS |
| 651 | * Success: TRUE |
| 652 | * Failure: FALSE |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 653 | */ |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 654 | BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */ |
| 655 | DWORD exit_code) /* [in] Exit code for thread */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 656 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 657 | NTSTATUS status = NtTerminateThread( handle, exit_code ); |
| 658 | if (status) SetLastError( RtlNtStatusToDosError(status) ); |
| 659 | return !status; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 660 | } |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 661 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 662 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 663 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 664 | * GetExitCodeThread [KERNEL32.???] Gets termination status of thread. |
| 665 | * |
| 666 | * RETURNS |
| 667 | * Success: TRUE |
| 668 | * Failure: FALSE |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 669 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 670 | BOOL WINAPI GetExitCodeThread( |
| 671 | HANDLE hthread, /* [in] Handle to thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 672 | LPDWORD exitcode) /* [out] Address to receive termination status */ |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 673 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 674 | BOOL ret; |
| 675 | SERVER_START_REQ |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 676 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 677 | struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 678 | req->handle = hthread; |
| 679 | req->tid_in = 0; |
| 680 | ret = !server_call( REQ_GET_THREAD_INFO ); |
| 681 | if (ret && exitcode) *exitcode = req->exit_code; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 682 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 683 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 684 | return ret; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 687 | |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 688 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 689 | * ResumeThread [KERNEL32.587] Resumes a thread. |
| 690 | * |
| 691 | * Decrements a thread's suspend count. When count is zero, the |
| 692 | * execution of the thread is resumed. |
| 693 | * |
| 694 | * RETURNS |
| 695 | * Success: Previous suspend count |
| 696 | * Failure: 0xFFFFFFFF |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 697 | * Already running: 0 |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 698 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 699 | DWORD WINAPI ResumeThread( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 700 | HANDLE hthread) /* [in] Identifies thread to restart */ |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 701 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 702 | DWORD ret = 0xffffffff; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 703 | SERVER_START_REQ |
| 704 | { |
| 705 | struct resume_thread_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 706 | req->handle = hthread; |
| 707 | if (!server_call( REQ_RESUME_THREAD )) ret = req->count; |
| 708 | } |
| 709 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 710 | return ret; |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 711 | } |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 712 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 713 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 714 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 715 | * SuspendThread [KERNEL32.681] Suspends a thread. |
| 716 | * |
| 717 | * RETURNS |
| 718 | * Success: Previous suspend count |
| 719 | * Failure: 0xFFFFFFFF |
| 720 | */ |
| 721 | DWORD WINAPI SuspendThread( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 722 | HANDLE hthread) /* [in] Handle to the thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 723 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 724 | DWORD ret = 0xffffffff; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 725 | SERVER_START_REQ |
| 726 | { |
| 727 | struct suspend_thread_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 728 | req->handle = hthread; |
| 729 | if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count; |
| 730 | } |
| 731 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 732 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 733 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 734 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 735 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 736 | /*********************************************************************** |
| 737 | * QueueUserAPC (KERNEL32.566) |
| 738 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 739 | DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 740 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 741 | DWORD ret; |
| 742 | SERVER_START_REQ |
| 743 | { |
| 744 | struct queue_apc_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 745 | req->handle = hthread; |
| 746 | req->func = func; |
| 747 | req->param = (void *)data; |
| 748 | ret = !server_call( REQ_QUEUE_APC ); |
| 749 | } |
| 750 | SERVER_END_REQ; |
| 751 | return ret; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | |
| 755 | /********************************************************************** |
| 756 | * GetThreadTimes [KERNEL32.???] Obtains timing information. |
| 757 | * |
| 758 | * NOTES |
| 759 | * What are the fields where these values are stored? |
| 760 | * |
| 761 | * RETURNS |
| 762 | * Success: TRUE |
| 763 | * Failure: FALSE |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 764 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 765 | BOOL WINAPI GetThreadTimes( |
| 766 | HANDLE thread, /* [in] Specifies the thread of interest */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 767 | LPFILETIME creationtime, /* [out] When the thread was created */ |
| 768 | LPFILETIME exittime, /* [out] When the thread was destroyed */ |
| 769 | LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */ |
| 770 | LPFILETIME usertime) /* [out] Time thread spent in user mode */ |
| 771 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 772 | FIXME("(0x%08x): stub\n",thread); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 773 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 774 | return FALSE; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 775 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 776 | |
| 777 | |
| 778 | /********************************************************************** |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 779 | * VWin32_BoostThreadGroup [KERNEL.535] |
| 780 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 781 | VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 782 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 783 | FIXME("(0x%08lx,%d): stub\n", threadId, boost); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /********************************************************************** |
| 787 | * VWin32_BoostThreadStatic [KERNEL.536] |
| 788 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 789 | VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 790 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 791 | FIXME("(0x%08lx,%d): stub\n", threadId, boost); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 794 | |
| 795 | /*********************************************************************** |
| 796 | * GetThreadLocale (KERNEL32.295) |
| 797 | */ |
| 798 | LCID WINAPI GetThreadLocale(void) |
| 799 | { |
Alexandre Julliard | bec3244 | 2000-07-10 15:23:04 +0000 | [diff] [blame] | 800 | LCID ret = NtCurrentTeb()->CurrentLocale; |
| 801 | if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID(); |
| 802 | return ret; |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | |
Guy Albertelli | c66f5d5 | 1999-01-24 09:59:14 +0000 | [diff] [blame] | 806 | /********************************************************************** |
| 807 | * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale. |
| 808 | * |
| 809 | * RETURNS |
| 810 | * Success: TRUE |
| 811 | * Failure: FALSE |
| 812 | * |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 813 | * FIXME |
| 814 | * check if lcid is a valid cp |
Guy Albertelli | c66f5d5 | 1999-01-24 09:59:14 +0000 | [diff] [blame] | 815 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 816 | BOOL WINAPI SetThreadLocale( |
Guy Albertelli | c66f5d5 | 1999-01-24 09:59:14 +0000 | [diff] [blame] | 817 | LCID lcid) /* [in] Locale identifier */ |
| 818 | { |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 819 | switch (lcid) |
| 820 | { |
| 821 | case LOCALE_SYSTEM_DEFAULT: |
| 822 | lcid = GetSystemDefaultLCID(); |
| 823 | break; |
| 824 | case LOCALE_USER_DEFAULT: |
| 825 | case LOCALE_NEUTRAL: |
| 826 | lcid = GetUserDefaultLCID(); |
| 827 | break; |
| 828 | } |
| 829 | NtCurrentTeb()->CurrentLocale = lcid; |
| 830 | return TRUE; |
Guy Albertelli | c66f5d5 | 1999-01-24 09:59:14 +0000 | [diff] [blame] | 831 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 832 | |
| 833 | |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 834 | /*********************************************************************** |
| 835 | * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread |
| 836 | * |
| 837 | * RETURNS |
| 838 | * Pseudohandle for the current thread |
| 839 | */ |
| 840 | #undef GetCurrentThread |
| 841 | HANDLE WINAPI GetCurrentThread(void) |
| 842 | { |
| 843 | return 0xfffffffe; |
| 844 | } |
| 845 | |
| 846 | |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame^] | 847 | /*********************************************************************** |
| 848 | * ProcessIdToSessionId (KERNEL32) |
| 849 | * This function is available on Terminal Server 4SP4 and Windows 2000 |
| 850 | */ |
| 851 | BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr ) |
| 852 | { |
| 853 | /* According to MSDN, if the calling process is not in a terminal |
| 854 | * services environment, then the sessionid returned is zero. |
| 855 | */ |
| 856 | *sessionid_ptr = 0; |
| 857 | return TRUE; |
| 858 | } |
| 859 | |
| 860 | |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 861 | #ifdef __i386__ |
| 862 | |
| 863 | /* void WINAPI SetLastError( DWORD error ); */ |
| 864 | __ASM_GLOBAL_FUNC( SetLastError, |
| 865 | "movl 4(%esp),%eax\n\t" |
| 866 | ".byte 0x64\n\t" |
| 867 | "movl %eax,0x60\n\t" |
| 868 | "ret $4" ); |
| 869 | |
| 870 | /* DWORD WINAPI GetLastError(void); */ |
| 871 | __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" ); |
| 872 | |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 873 | /* DWORD WINAPI GetCurrentProcessId(void) */ |
| 874 | __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" ); |
| 875 | |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 876 | /* DWORD WINAPI GetCurrentThreadId(void) */ |
| 877 | __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" ); |
| 878 | |
| 879 | #else /* __i386__ */ |
| 880 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 881 | /********************************************************************** |
| 882 | * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code. |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 883 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 884 | void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */ |
| 885 | { |
| 886 | NtCurrentTeb()->last_error = error; |
| 887 | } |
| 888 | |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 889 | /********************************************************************** |
| 890 | * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code. |
| 891 | */ |
| 892 | DWORD WINAPI GetLastError(void) |
| 893 | { |
| 894 | return NtCurrentTeb()->last_error; |
| 895 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 896 | |
| 897 | /*********************************************************************** |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 898 | * GetCurrentProcessId [KERNEL32.199] Returns process identifier. |
| 899 | */ |
| 900 | DWORD WINAPI GetCurrentProcessId(void) |
| 901 | { |
| 902 | return (DWORD)NtCurrentTeb()->pid; |
| 903 | } |
| 904 | |
| 905 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 906 | * GetCurrentThreadId [KERNEL32.201] Returns thread identifier. |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 907 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 908 | DWORD WINAPI GetCurrentThreadId(void) |
| 909 | { |
| 910 | return (DWORD)NtCurrentTeb()->tid; |
| 911 | } |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 912 | |
| 913 | #endif /* __i386__ */ |