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