Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 threads |
| 3 | * |
| 4 | * Copyright 1996 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
François Gouget | 1425941 | 2001-11-06 20:57:11 +0000 | [diff] [blame] | 21 | #include "config.h" |
Francois Gouget | 386cf6e | 2001-10-14 16:25:47 +0000 | [diff] [blame] | 22 | #include "wine/port.h" |
Patrik Stridvall | 478eee1 | 1999-07-31 13:13:23 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 24 | #include <assert.h> |
Alexandre Julliard | f016752 | 1999-03-21 19:26:25 +0000 | [diff] [blame] | 25 | #include <fcntl.h> |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 26 | #include <sys/types.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 27 | #ifdef HAVE_SYS_MMAN_H |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 28 | #include <sys/mman.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 29 | #endif |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 30 | #ifdef HAVE_UNISTD_H |
| 31 | # include <unistd.h> |
| 32 | #endif |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 33 | #include "wine/winbase16.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 34 | #include "thread.h" |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 35 | #include "task.h" |
| 36 | #include "module.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 37 | #include "winerror.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 38 | #include "selectors.h" |
| 39 | #include "winnt.h" |
Alexandre Julliard | 37e9503 | 2001-07-19 00:39:09 +0000 | [diff] [blame] | 40 | #include "wine/server.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 41 | #include "stackframe.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 42 | #include "wine/debug.h" |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 43 | #include "winnls.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 44 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 45 | WINE_DEFAULT_DEBUG_CHANNEL(thread); |
| 46 | WINE_DECLARE_DEBUG_CHANNEL(relay); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 47 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 48 | /* TEB of the initial thread */ |
| 49 | static TEB initial_teb; |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 50 | |
Alexandre Julliard | becb9a3 | 2000-12-11 03:48:15 +0000 | [diff] [blame] | 51 | extern struct _PDB current_process; |
| 52 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 53 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 54 | * THREAD_IdToTEB |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 55 | * |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 56 | * Convert a thread id to a TEB, making sure it is valid. |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 57 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 58 | TEB *THREAD_IdToTEB( DWORD id ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 59 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 60 | TEB *ret = NULL; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 61 | |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 62 | if (!id || id == GetCurrentThreadId()) return NtCurrentTeb(); |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 63 | |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 64 | SERVER_START_REQ( get_thread_info ) |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 65 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 66 | req->handle = 0; |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 67 | req->tid_in = id; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 68 | if (!wine_server_call( req )) ret = reply->teb; |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 69 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 70 | SERVER_END_REQ; |
| 71 | |
| 72 | if (!ret) |
| 73 | { |
| 74 | /* Allow task handles to be used; convert to main thread */ |
| 75 | if ( IsTask16( id ) ) |
| 76 | { |
Alexandre Julliard | 2ec34e4 | 2001-04-04 00:21:05 +0000 | [diff] [blame] | 77 | TDB *pTask = TASK_GetPtr( id ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 78 | if (pTask) return pTask->teb; |
| 79 | } |
| 80 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 81 | } |
| 82 | return ret; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 86 | /*********************************************************************** |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 87 | * THREAD_InitTEB |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 88 | * |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 89 | * Initialization of a newly created TEB. |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 90 | */ |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 91 | static BOOL THREAD_InitTEB( TEB *teb ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 92 | { |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 93 | teb->except = (void *)~0UL; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 94 | teb->self = teb; |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 95 | teb->tibflags = TEBF_WIN32; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 96 | teb->tls_ptr = teb->tls_array; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 97 | teb->exit_code = STILL_ACTIVE; |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 98 | teb->request_fd = -1; |
| 99 | teb->reply_fd = -1; |
Alexandre Julliard | e5dedb1 | 2001-03-08 01:16:41 +0000 | [diff] [blame] | 100 | teb->wait_fd[0] = -1; |
| 101 | teb->wait_fd[1] = -1; |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 102 | teb->stack_top = (void *)~0UL; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 103 | teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer); |
| 104 | teb->StaticUnicodeString.Buffer = (PWSTR)teb->StaticUnicodeBuffer; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 105 | teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, WINE_LDT_FLAGS_DATA|WINE_LDT_FLAGS_32BIT ); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 106 | return (teb->teb_sel != 0); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /*********************************************************************** |
| 111 | * THREAD_FreeTEB |
| 112 | * |
| 113 | * Free data structures associated with a thread. |
| 114 | * Must be called from the context of another thread. |
| 115 | */ |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 116 | static void THREAD_FreeTEB( TEB *teb ) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 117 | { |
| 118 | TRACE("(%p) called\n", teb ); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 119 | /* Free the associated memory */ |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 120 | FreeSelector16( teb->stack_sel ); |
Alexandre Julliard | 8c540c6 | 2000-11-13 04:16:05 +0000 | [diff] [blame] | 121 | FreeSelector16( teb->teb_sel ); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 122 | VirtualFree( teb->stack_base, 0, MEM_RELEASE ); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /*********************************************************************** |
| 127 | * THREAD_InitStack |
| 128 | * |
| 129 | * Allocate the stack of a thread. |
| 130 | */ |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 131 | TEB *THREAD_InitStack( TEB *teb, DWORD stack_size ) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 132 | { |
| 133 | DWORD old_prot, total_size; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 134 | DWORD page_size = getpagesize(); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 135 | void *base; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 136 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 137 | /* Allocate the stack */ |
| 138 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 139 | if (stack_size >= 16*1024*1024) |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 140 | WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 141 | |
Alexandre Julliard | ce68603 | 2000-05-03 17:45:14 +0000 | [diff] [blame] | 142 | /* if size is smaller than default, get stack size from parent */ |
| 143 | if (stack_size < 1024 * 1024) |
| 144 | { |
| 145 | if (teb) |
| 146 | stack_size = 1024 * 1024; /* no parent */ |
| 147 | else |
| 148 | stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->stack_base |
| 149 | - SIGNAL_STACK_SIZE - 3 * page_size); |
| 150 | } |
| 151 | |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 152 | /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */ |
| 153 | stack_size += 64 * 1024; |
| 154 | |
| 155 | /* Memory layout in allocated block: |
| 156 | * |
| 157 | * size contents |
| 158 | * 1 page NOACCESS guard page |
| 159 | * SIGNAL_STACK_SIZE signal stack |
| 160 | * 1 page NOACCESS guard page |
| 161 | * 1 page PAGE_GUARD guard page |
| 162 | * stack_size normal stack |
| 163 | * 64Kb 16-bit stack (optional) |
| 164 | * 1 page TEB (except for initial thread) |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 165 | * 1 page debug info (except for initial thread) |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 166 | */ |
| 167 | |
| 168 | stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1); |
| 169 | total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size; |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 170 | total_size += 0x10000; /* 16-bit stack */ |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 171 | if (!teb) total_size += 2 * page_size; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 172 | |
| 173 | if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE ))) |
| 174 | return NULL; |
| 175 | |
| 176 | if (!teb) |
| 177 | { |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 178 | teb = (TEB *)((char *)base + total_size - 2 * page_size); |
| 179 | if (!THREAD_InitTEB( teb )) goto error; |
| 180 | teb->debug_info = (char *)teb + page_size; |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 197 | teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, WINE_LDT_FLAGS_DATA ); |
| 198 | if (!teb->stack_sel) goto error; |
| 199 | teb->cur_stack = MAKESEGPTR( teb->stack_sel, 0x10000 - sizeof(STACK16FRAME) ); |
| 200 | |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 201 | return teb; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 202 | |
| 203 | error: |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 204 | FreeSelector16( teb->teb_sel ); |
| 205 | VirtualFree( base, 0, MEM_RELEASE ); |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 206 | return NULL; |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
| 210 | /*********************************************************************** |
Alexandre Julliard | 598412e | 2001-01-17 20:22:22 +0000 | [diff] [blame] | 211 | * thread_errno_location |
| 212 | * |
| 213 | * Get the per-thread errno location. |
| 214 | */ |
| 215 | static int *thread_errno_location(void) |
| 216 | { |
| 217 | return &NtCurrentTeb()->thread_errno; |
| 218 | } |
| 219 | |
| 220 | /*********************************************************************** |
| 221 | * thread_h_errno_location |
| 222 | * |
| 223 | * Get the per-thread h_errno location. |
| 224 | */ |
| 225 | static int *thread_h_errno_location(void) |
| 226 | { |
| 227 | return &NtCurrentTeb()->thread_h_errno; |
| 228 | } |
| 229 | |
| 230 | /*********************************************************************** |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 231 | * THREAD_Init |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 232 | * |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 233 | * Setup the initial thread. |
Alexandre Julliard | 3ef9322 | 2000-04-13 17:03:22 +0000 | [diff] [blame] | 234 | * |
| 235 | * NOTES: The first allocated TEB on NT is at 0x7ffde000. |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 236 | */ |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 237 | void THREAD_Init(void) |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 238 | { |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 239 | if (!initial_teb.self) /* do it only once */ |
| 240 | { |
| 241 | THREAD_InitTEB( &initial_teb ); |
| 242 | assert( initial_teb.teb_sel ); |
Alexandre Julliard | 52900c8 | 2000-08-09 22:33:42 +0000 | [diff] [blame] | 243 | initial_teb.process = ¤t_process; |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 244 | SYSDEPS_SetCurThread( &initial_teb ); |
Alexandre Julliard | 598412e | 2001-01-17 20:22:22 +0000 | [diff] [blame] | 245 | wine_errno_location = thread_errno_location; |
| 246 | wine_h_errno_location = thread_h_errno_location; |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 247 | } |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Alexandre Julliard | 8c21dfc | 2000-05-01 21:21:31 +0000 | [diff] [blame] | 250 | DECL_GLOBAL_CONSTRUCTOR(thread_init) { THREAD_Init(); } |
Alexandre Julliard | 13e5519 | 1999-02-21 18:34:18 +0000 | [diff] [blame] | 251 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 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 | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 260 | LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point; |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 261 | |
Francois Gouget | e17d1a3 | 2001-05-08 00:13:38 +0000 | [diff] [blame] | 262 | if (TRACE_ON(relay)) |
| 263 | DPRINTF("%08lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func ); |
Dmitry Timoshkov | 4ea3c26 | 2001-04-09 18:47:10 +0000 | [diff] [blame] | 264 | |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 265 | PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 266 | MODULE_DllThreadAttach( NULL ); |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 267 | ExitThread( func( NtCurrentTeb()->entry_arg ) ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
| 271 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 272 | * CreateThread (KERNEL32.@) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 273 | */ |
Dmitry Timoshkov | 472d016 | 2002-09-21 01:21:00 +0000 | [diff] [blame] | 274 | HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, SIZE_T stack, |
Ulrich Weigand | 4526f2e | 1999-03-16 16:28:59 +0000 | [diff] [blame] | 275 | LPTHREAD_START_ROUTINE start, LPVOID param, |
| 276 | DWORD flags, LPDWORD id ) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 277 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 278 | HANDLE handle = 0; |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 279 | TEB *teb; |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 280 | DWORD tid = 0; |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 281 | int request_pipe[2]; |
| 282 | |
| 283 | if (pipe( request_pipe ) == -1) |
| 284 | { |
| 285 | SetLastError( ERROR_TOO_MANY_OPEN_FILES ); |
| 286 | return 0; |
| 287 | } |
| 288 | fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */ |
| 289 | wine_server_send_fd( request_pipe[0] ); |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 290 | |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 291 | SERVER_START_REQ( new_thread ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 292 | { |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 293 | req->suspend = ((flags & CREATE_SUSPENDED) != 0); |
| 294 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 295 | req->request_fd = request_pipe[0]; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 296 | if (!wine_server_call_err( req )) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 297 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 298 | handle = reply->handle; |
| 299 | tid = reply->tid; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 300 | } |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 301 | close( request_pipe[0] ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 302 | } |
| 303 | SERVER_END_REQ; |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 304 | |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 305 | if (!handle || !(teb = THREAD_InitStack( NULL, stack ))) |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 306 | { |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 307 | close( request_pipe[1] ); |
Alexandre Julliard | 9a0e28f | 2000-03-25 19:14:37 +0000 | [diff] [blame] | 308 | return 0; |
| 309 | } |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 310 | |
| 311 | teb->process = NtCurrentTeb()->process; |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 312 | teb->tid = tid; |
| 313 | teb->request_fd = request_pipe[1]; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 314 | teb->entry_point = start; |
| 315 | teb->entry_arg = param; |
| 316 | teb->startup = THREAD_Start; |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 317 | teb->htask16 = GetCurrentTask(); |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 318 | |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 319 | if (id) *id = tid; |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 320 | if (SYSDEPS_SpawnThread( teb ) == -1) |
Alexandre Julliard | 96c08d8 | 1999-02-28 13:27:56 +0000 | [diff] [blame] | 321 | { |
| 322 | CloseHandle( handle ); |
Alexandre Julliard | c77c4df | 2002-01-07 18:03:14 +0000 | [diff] [blame] | 323 | close( request_pipe[1] ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 324 | THREAD_FreeTEB( teb ); |
Alexandre Julliard | 617955d | 1999-06-26 18:40:24 +0000 | [diff] [blame] | 325 | return 0; |
Alexandre Julliard | 96c08d8 | 1999-02-28 13:27:56 +0000 | [diff] [blame] | 326 | } |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 327 | return handle; |
| 328 | } |
| 329 | |
Ulrich Weigand | f0a1c2f | 1999-09-20 18:45:28 +0000 | [diff] [blame] | 330 | /*********************************************************************** |
| 331 | * CreateThread16 (KERNEL.441) |
| 332 | */ |
| 333 | static DWORD CALLBACK THREAD_StartThread16( LPVOID threadArgs ) |
| 334 | { |
| 335 | FARPROC16 start = ((FARPROC16 *)threadArgs)[0]; |
| 336 | DWORD param = ((DWORD *)threadArgs)[1]; |
| 337 | HeapFree( GetProcessHeap(), 0, threadArgs ); |
| 338 | |
| 339 | ((LPDWORD)CURRENT_STACK16)[-1] = param; |
Alexandre Julliard | 7aee907 | 2002-10-18 00:29:32 +0000 | [diff] [blame] | 340 | return wine_call_to_16( start, sizeof(DWORD) ); |
Ulrich Weigand | f0a1c2f | 1999-09-20 18:45:28 +0000 | [diff] [blame] | 341 | } |
| 342 | HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack, |
| 343 | FARPROC16 start, SEGPTR param, |
| 344 | DWORD flags, LPDWORD id ) |
| 345 | { |
| 346 | DWORD *threadArgs = HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD) ); |
| 347 | if (!threadArgs) return INVALID_HANDLE_VALUE; |
| 348 | threadArgs[0] = (DWORD)start; |
| 349 | threadArgs[1] = (DWORD)param; |
| 350 | |
| 351 | return CreateThread( sa, stack, THREAD_StartThread16, threadArgs, flags, id ); |
| 352 | } |
| 353 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 354 | |
| 355 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 356 | * ExitThread [KERNEL32.@] Ends a thread |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 357 | * |
| 358 | * RETURNS |
| 359 | * None |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 360 | */ |
Alexandre Julliard | 301f2c6 | 1999-03-14 19:48:04 +0000 | [diff] [blame] | 361 | void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */ |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 362 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 363 | BOOL last; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 364 | SERVER_START_REQ( terminate_thread ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 365 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 366 | /* send the exit code to the server */ |
| 367 | req->handle = GetCurrentThread(); |
| 368 | req->exit_code = code; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 369 | wine_server_call( req ); |
| 370 | last = reply->last; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 371 | } |
| 372 | SERVER_END_REQ; |
| 373 | |
| 374 | if (last) |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 375 | { |
| 376 | MODULE_DllProcessDetach( TRUE, (LPVOID)1 ); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 377 | exit( code ); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | MODULE_DllThreadDetach( NULL ); |
Alexandre Julliard | 4e951ea | 2000-11-08 22:47:53 +0000 | [diff] [blame] | 382 | if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask(); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 383 | SYSDEPS_ExitThread( code ); |
| 384 | } |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Chris Morgan | 417296c | 2002-04-02 00:49:05 +0000 | [diff] [blame] | 387 | /*********************************************************************** |
| 388 | * OpenThread Retrieves a handle to a thread from its thread id |
| 389 | * |
| 390 | * RETURNS |
| 391 | * None |
| 392 | */ |
| 393 | HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId ) |
| 394 | { |
| 395 | HANDLE ret = 0; |
| 396 | SERVER_START_REQ( open_thread ) |
| 397 | { |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 398 | req->tid = dwThreadId; |
Chris Morgan | 417296c | 2002-04-02 00:49:05 +0000 | [diff] [blame] | 399 | req->access = dwDesiredAccess; |
| 400 | req->inherit = bInheritHandle; |
| 401 | if (!wine_server_call_err( req )) ret = reply->handle; |
| 402 | } |
| 403 | SERVER_END_REQ; |
| 404 | return ret; |
| 405 | } |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 406 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 407 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 408 | * SetThreadContext [KERNEL32.@] Sets context of thread. |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 409 | * |
| 410 | * RETURNS |
| 411 | * Success: TRUE |
| 412 | * Failure: FALSE |
| 413 | */ |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 414 | BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ |
| 415 | const CONTEXT *context ) /* [in] Address of context structure */ |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 416 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 417 | BOOL ret; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 418 | SERVER_START_REQ( set_thread_context ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 419 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 420 | req->handle = handle; |
| 421 | req->flags = context->ContextFlags; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 422 | wine_server_add_data( req, context, sizeof(*context) ); |
| 423 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 424 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 425 | SERVER_END_REQ; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 426 | return ret; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 429 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 430 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 431 | * GetThreadContext [KERNEL32.@] Retrieves context of thread. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 432 | * |
| 433 | * RETURNS |
| 434 | * Success: TRUE |
| 435 | * Failure: FALSE |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 436 | */ |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 437 | BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ |
| 438 | CONTEXT *context ) /* [out] Address of context structure */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 439 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 440 | BOOL ret; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 441 | SERVER_START_REQ( get_thread_context ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 442 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 443 | req->handle = handle; |
| 444 | req->flags = context->ContextFlags; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 445 | wine_server_add_data( req, context, sizeof(*context) ); |
| 446 | wine_server_set_reply( req, context, sizeof(*context) ); |
| 447 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 448 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 449 | SERVER_END_REQ; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 450 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
| 454 | /********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 455 | * GetThreadPriority [KERNEL32.@] Returns priority for thread. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 456 | * |
| 457 | * RETURNS |
| 458 | * Success: Thread's priority level. |
| 459 | * Failure: THREAD_PRIORITY_ERROR_RETURN |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 460 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 461 | INT WINAPI GetThreadPriority( |
| 462 | HANDLE hthread) /* [in] Handle to thread */ |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 463 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 464 | INT ret = THREAD_PRIORITY_ERROR_RETURN; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 465 | SERVER_START_REQ( get_thread_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 466 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 467 | req->handle = hthread; |
| 468 | req->tid_in = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 469 | if (!wine_server_call_err( req )) ret = reply->priority; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 470 | } |
| 471 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 472 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 475 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 476 | /********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 477 | * SetThreadPriority [KERNEL32.@] Sets priority for thread. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 478 | * |
| 479 | * RETURNS |
| 480 | * Success: TRUE |
| 481 | * Failure: FALSE |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 482 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 483 | BOOL WINAPI SetThreadPriority( |
| 484 | HANDLE hthread, /* [in] Handle to thread */ |
| 485 | INT priority) /* [in] Thread priority level */ |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 486 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 487 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 488 | SERVER_START_REQ( set_thread_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 489 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 490 | req->handle = hthread; |
| 491 | req->priority = priority; |
| 492 | req->mask = SET_THREAD_INFO_PRIORITY; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 493 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 494 | } |
| 495 | SERVER_END_REQ; |
| 496 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | |
| 500 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 501 | * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread. |
Slava Monich | fb8934d | 2000-07-08 12:47:30 +0000 | [diff] [blame] | 502 | * |
| 503 | * Always reports that priority boost is disabled. |
| 504 | * |
| 505 | * RETURNS |
| 506 | * Success: TRUE. |
| 507 | * Failure: FALSE |
| 508 | */ |
| 509 | BOOL WINAPI GetThreadPriorityBoost( |
| 510 | HANDLE hthread, /* [in] Handle to thread */ |
| 511 | PBOOL pstate) /* [out] pointer to var that receives the boost state */ |
| 512 | { |
| 513 | if (pstate) *pstate = FALSE; |
| 514 | return NO_ERROR; |
| 515 | } |
| 516 | |
| 517 | |
| 518 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 519 | * SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread. |
Slava Monich | fb8934d | 2000-07-08 12:47:30 +0000 | [diff] [blame] | 520 | * |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 521 | * Priority boost is not implemented. Thsi function always returns |
Slava Monich | fb8934d | 2000-07-08 12:47:30 +0000 | [diff] [blame] | 522 | * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED |
| 523 | * |
| 524 | * RETURNS |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 525 | * Always returns FALSE to indicate a failure |
Slava Monich | fb8934d | 2000-07-08 12:47:30 +0000 | [diff] [blame] | 526 | */ |
| 527 | BOOL WINAPI SetThreadPriorityBoost( |
| 528 | HANDLE hthread, /* [in] Handle to thread */ |
| 529 | BOOL disable) /* [in] TRUE to disable priority boost */ |
| 530 | { |
| 531 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 532 | return FALSE; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 537 | * SetThreadAffinityMask (KERNEL32.@) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 538 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 539 | DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 540 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 541 | DWORD ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 542 | SERVER_START_REQ( set_thread_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 543 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 544 | req->handle = hThread; |
| 545 | req->affinity = dwThreadAffinityMask; |
| 546 | req->mask = SET_THREAD_INFO_AFFINITY; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 547 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 548 | /* FIXME: should return previous value */ |
| 549 | } |
| 550 | SERVER_END_REQ; |
| 551 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 552 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 553 | |
Geoffrey Hausheer | 03f4e22 | 2002-04-02 19:37:15 +0000 | [diff] [blame] | 554 | /********************************************************************** |
| 555 | * SetThreadIdealProcessor [KERNEL32.@] Obtains timing information. |
| 556 | * |
| 557 | * RETURNS |
| 558 | * Success: Value of last call to SetThreadIdealProcessor |
| 559 | * Failure: -1 |
| 560 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 561 | DWORD WINAPI SetThreadIdealProcessor( |
Geoffrey Hausheer | 03f4e22 | 2002-04-02 19:37:15 +0000 | [diff] [blame] | 562 | HANDLE hThread, /* [in] Specifies the thread of interest */ |
| 563 | DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */ |
| 564 | { |
Andrew John Hughes | ed800c6 | 2002-11-21 03:45:01 +0000 | [diff] [blame^] | 565 | FIXME("(0x%p): stub\n",hThread); |
Geoffrey Hausheer | 03f4e22 | 2002-04-02 19:37:15 +0000 | [diff] [blame] | 566 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 567 | return -1L; |
| 568 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 569 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 570 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 571 | * TerminateThread [KERNEL32.@] Terminates a thread |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 572 | * |
| 573 | * RETURNS |
| 574 | * Success: TRUE |
| 575 | * Failure: FALSE |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 576 | */ |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 577 | BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */ |
| 578 | DWORD exit_code) /* [in] Exit code for thread */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 579 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 580 | NTSTATUS status = NtTerminateThread( handle, exit_code ); |
| 581 | if (status) SetLastError( RtlNtStatusToDosError(status) ); |
| 582 | return !status; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 583 | } |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 584 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 585 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 586 | /********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 587 | * GetExitCodeThread (KERNEL32.@) |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 588 | * |
| 589 | * Gets termination status of thread. |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 590 | * |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 591 | * RETURNS |
| 592 | * Success: TRUE |
| 593 | * Failure: FALSE |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 594 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 595 | BOOL WINAPI GetExitCodeThread( |
| 596 | HANDLE hthread, /* [in] Handle to thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 597 | LPDWORD exitcode) /* [out] Address to receive termination status */ |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 598 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 599 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 600 | SERVER_START_REQ( get_thread_info ) |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 601 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 602 | req->handle = hthread; |
| 603 | req->tid_in = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 604 | ret = !wine_server_call_err( req ); |
| 605 | if (ret && exitcode) *exitcode = reply->exit_code; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 606 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 607 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 608 | return ret; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 611 | |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 612 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 613 | * ResumeThread [KERNEL32.@] Resumes a thread. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 614 | * |
| 615 | * Decrements a thread's suspend count. When count is zero, the |
| 616 | * execution of the thread is resumed. |
| 617 | * |
| 618 | * RETURNS |
| 619 | * Success: Previous suspend count |
| 620 | * Failure: 0xFFFFFFFF |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 621 | * Already running: 0 |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 622 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 623 | DWORD WINAPI ResumeThread( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 624 | HANDLE hthread) /* [in] Identifies thread to restart */ |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 625 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 626 | DWORD ret = 0xffffffff; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 627 | SERVER_START_REQ( resume_thread ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 628 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 629 | req->handle = hthread; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 630 | if (!wine_server_call_err( req )) ret = reply->count; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 631 | } |
| 632 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 633 | return ret; |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 634 | } |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 635 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 636 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 637 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 638 | * SuspendThread [KERNEL32.@] Suspends a thread. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 639 | * |
| 640 | * RETURNS |
| 641 | * Success: Previous suspend count |
| 642 | * Failure: 0xFFFFFFFF |
| 643 | */ |
| 644 | DWORD WINAPI SuspendThread( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 645 | HANDLE hthread) /* [in] Handle to the thread */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 646 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 647 | DWORD ret = 0xffffffff; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 648 | SERVER_START_REQ( suspend_thread ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 649 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 650 | req->handle = hthread; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 651 | if (!wine_server_call_err( req )) ret = reply->count; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 652 | } |
| 653 | SERVER_END_REQ; |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 654 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 655 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 656 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 657 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 658 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 659 | * QueueUserAPC (KERNEL32.@) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 660 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 661 | DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 662 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 663 | DWORD ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 664 | SERVER_START_REQ( queue_apc ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 665 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 666 | req->handle = hthread; |
Alexandre Julliard | 2362380 | 2001-01-06 01:48:51 +0000 | [diff] [blame] | 667 | req->user = 1; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 668 | req->func = func; |
| 669 | req->param = (void *)data; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 670 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 671 | } |
| 672 | SERVER_END_REQ; |
| 673 | return ret; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | |
| 677 | /********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 678 | * GetThreadTimes [KERNEL32.@] Obtains timing information. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 679 | * |
| 680 | * NOTES |
| 681 | * What are the fields where these values are stored? |
| 682 | * |
| 683 | * RETURNS |
| 684 | * Success: TRUE |
| 685 | * Failure: FALSE |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 686 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 687 | BOOL WINAPI GetThreadTimes( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 688 | HANDLE thread, /* [in] Specifies the thread of interest */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 689 | LPFILETIME creationtime, /* [out] When the thread was created */ |
| 690 | LPFILETIME exittime, /* [out] When the thread was destroyed */ |
| 691 | LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */ |
| 692 | LPFILETIME usertime) /* [out] Time thread spent in user mode */ |
| 693 | { |
Andrew John Hughes | ed800c6 | 2002-11-21 03:45:01 +0000 | [diff] [blame^] | 694 | FIXME("(0x%p): stub\n",thread); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 695 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 696 | return FALSE; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 697 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 698 | |
| 699 | |
| 700 | /********************************************************************** |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 701 | * VWin32_BoostThreadGroup [KERNEL.535] |
| 702 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 703 | VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 704 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 705 | FIXME("(0x%08lx,%d): stub\n", threadId, boost); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /********************************************************************** |
| 709 | * VWin32_BoostThreadStatic [KERNEL.536] |
| 710 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 711 | VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 712 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 713 | FIXME("(0x%08lx,%d): stub\n", threadId, boost); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Juergen Schmied | 79d850f | 2000-06-12 21:56:02 +0000 | [diff] [blame] | 716 | |
| 717 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 718 | * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 719 | * |
| 720 | * RETURNS |
| 721 | * Pseudohandle for the current thread |
| 722 | */ |
| 723 | #undef GetCurrentThread |
| 724 | HANDLE WINAPI GetCurrentThread(void) |
| 725 | { |
Alexandre Julliard | 7375597 | 2002-07-31 19:26:03 +0000 | [diff] [blame] | 726 | return (HANDLE)0xfffffffe; |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 730 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 731 | * ProcessIdToSessionId (KERNEL32.@) |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 732 | * This function is available on Terminal Server 4SP4 and Windows 2000 |
| 733 | */ |
| 734 | BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr ) |
| 735 | { |
| 736 | /* According to MSDN, if the calling process is not in a terminal |
| 737 | * services environment, then the sessionid returned is zero. |
| 738 | */ |
| 739 | *sessionid_ptr = 0; |
| 740 | return TRUE; |
| 741 | } |
| 742 | |
James Juran | 7313b78 | 2001-03-13 23:33:26 +0000 | [diff] [blame] | 743 | /*********************************************************************** |
| 744 | * SetThreadExecutionState (KERNEL32.@) |
| 745 | * |
| 746 | * Informs the system that activity is taking place for |
| 747 | * power management purposes. |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 748 | */ |
James Juran | 7313b78 | 2001-03-13 23:33:26 +0000 | [diff] [blame] | 749 | EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags) |
| 750 | { |
Andreas Mohr | b2059fa | 2001-10-03 18:39:23 +0000 | [diff] [blame] | 751 | static EXECUTION_STATE current = |
| 752 | ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED|ES_USER_PRESENT; |
| 753 | EXECUTION_STATE old = current; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 754 | |
Andreas Mohr | b2059fa | 2001-10-03 18:39:23 +0000 | [diff] [blame] | 755 | if (!(current & ES_CONTINUOUS) || (flags & ES_CONTINUOUS)) |
| 756 | current = flags; |
| 757 | FIXME("(0x%lx): stub, harmless (power management).\n", flags); |
| 758 | return old; |
James Juran | 7313b78 | 2001-03-13 23:33:26 +0000 | [diff] [blame] | 759 | } |
| 760 | |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 761 | |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 762 | #ifdef __i386__ |
| 763 | |
Patrik Stridvall | db92305 | 2001-07-24 00:58:52 +0000 | [diff] [blame] | 764 | /*********************************************************************** |
| 765 | * SetLastError (KERNEL.147) |
| 766 | * SetLastError (KERNEL32.@) |
| 767 | */ |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 768 | /* void WINAPI SetLastError( DWORD error ); */ |
| 769 | __ASM_GLOBAL_FUNC( SetLastError, |
| 770 | "movl 4(%esp),%eax\n\t" |
| 771 | ".byte 0x64\n\t" |
| 772 | "movl %eax,0x60\n\t" |
| 773 | "ret $4" ); |
| 774 | |
Patrik Stridvall | db92305 | 2001-07-24 00:58:52 +0000 | [diff] [blame] | 775 | /*********************************************************************** |
| 776 | * GetLastError (KERNEL.148) |
| 777 | * GetLastError (KERNEL32.@) |
| 778 | */ |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 779 | /* DWORD WINAPI GetLastError(void); */ |
| 780 | __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" ); |
| 781 | |
Patrik Stridvall | db92305 | 2001-07-24 00:58:52 +0000 | [diff] [blame] | 782 | /*********************************************************************** |
| 783 | * GetCurrentProcessId (KERNEL.471) |
| 784 | * GetCurrentProcessId (KERNEL32.@) |
| 785 | */ |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 786 | /* DWORD WINAPI GetCurrentProcessId(void) */ |
| 787 | __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 788 | |
Patrik Stridvall | db92305 | 2001-07-24 00:58:52 +0000 | [diff] [blame] | 789 | /*********************************************************************** |
| 790 | * GetCurrentThreadId (KERNEL.462) |
| 791 | * GetCurrentThreadId (KERNEL32.@) |
| 792 | */ |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 793 | /* DWORD WINAPI GetCurrentThreadId(void) */ |
| 794 | __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 795 | |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 796 | #else /* __i386__ */ |
| 797 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 798 | /********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 799 | * SetLastError (KERNEL.147) |
| 800 | * SetLastError (KERNEL32.@) |
| 801 | * |
| 802 | * Sets the last-error code. |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 803 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 804 | void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */ |
| 805 | { |
| 806 | NtCurrentTeb()->last_error = error; |
| 807 | } |
| 808 | |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 809 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 810 | * GetLastError (KERNEL.148) |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 811 | * GetLastError (KERNEL32.@) |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 812 | * |
| 813 | * Returns last-error code. |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 814 | */ |
| 815 | DWORD WINAPI GetLastError(void) |
| 816 | { |
| 817 | return NtCurrentTeb()->last_error; |
| 818 | } |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 819 | |
| 820 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 821 | * GetCurrentProcessId (KERNEL.471) |
| 822 | * GetCurrentProcessId (KERNEL32.@) |
| 823 | * |
| 824 | * Returns process identifier. |
Alexandre Julliard | 114830e | 2000-04-11 20:01:59 +0000 | [diff] [blame] | 825 | */ |
| 826 | DWORD WINAPI GetCurrentProcessId(void) |
| 827 | { |
| 828 | return (DWORD)NtCurrentTeb()->pid; |
| 829 | } |
| 830 | |
| 831 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 832 | * GetCurrentThreadId (KERNEL.462) |
| 833 | * GetCurrentThreadId (KERNEL32.@) |
| 834 | * |
| 835 | * Returns thread identifier. |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 836 | */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 837 | DWORD WINAPI GetCurrentThreadId(void) |
| 838 | { |
| 839 | return (DWORD)NtCurrentTeb()->tid; |
| 840 | } |
Alexandre Julliard | ca3c9ba | 2000-03-07 13:14:27 +0000 | [diff] [blame] | 841 | |
| 842 | #endif /* __i386__ */ |