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