Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 process handles |
| 3 | * |
| 4 | * Copyright 1998 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 | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 23 | #include <assert.h> |
| 24 | #include <stdio.h> |
Patrik Stridvall | 9aab47e | 2002-08-28 23:42:34 +0000 | [diff] [blame] | 25 | #ifdef HAVE_IO_H |
| 26 | # include <io.h> |
| 27 | #endif |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 28 | #ifdef HAVE_UNISTD_H |
| 29 | # include <unistd.h> |
| 30 | #endif |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 31 | #include "winbase.h" |
Alexandre Julliard | 37e9503 | 2001-07-19 00:39:09 +0000 | [diff] [blame] | 32 | #include "wine/server.h" |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 33 | #include "winerror.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 34 | #include "wine/debug.h" |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 35 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 36 | WINE_DEFAULT_DEBUG_CHANNEL(win32); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 37 | |
| 38 | /********************************************************************* |
Patrik Stridvall | 044855c | 2001-07-11 18:56:41 +0000 | [diff] [blame] | 39 | * CloseW32Handle (KERNEL.474) |
| 40 | * CloseHandle (KERNEL32.@) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 41 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 42 | BOOL WINAPI CloseHandle( HANDLE handle ) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 43 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 44 | NTSTATUS status; |
| 45 | |
Alexandre Julliard | a67d716 | 1999-11-04 02:49:06 +0000 | [diff] [blame] | 46 | /* stdio handles need special treatment */ |
Alexandre Julliard | 267ca68 | 2002-07-31 17:20:00 +0000 | [diff] [blame] | 47 | if ((handle == (HANDLE)STD_INPUT_HANDLE) || |
| 48 | (handle == (HANDLE)STD_OUTPUT_HANDLE) || |
| 49 | (handle == (HANDLE)STD_ERROR_HANDLE)) |
| 50 | handle = GetStdHandle( (DWORD)handle ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 51 | |
| 52 | status = NtClose( handle ); |
| 53 | if (status) SetLastError( RtlNtStatusToDosError(status) ); |
| 54 | return !status; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
| 58 | /********************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 59 | * GetHandleInformation (KERNEL32.@) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 60 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 61 | BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags ) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 62 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 63 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 64 | SERVER_START_REQ( set_handle_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 65 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 66 | req->handle = handle; |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 67 | req->flags = 0; |
| 68 | req->mask = 0; |
| 69 | req->fd = -1; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 70 | ret = !wine_server_call_err( req ); |
| 71 | if (ret && flags) *flags = reply->old_flags; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 72 | } |
| 73 | SERVER_END_REQ; |
| 74 | return ret; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | /********************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 79 | * SetHandleInformation (KERNEL32.@) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 80 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 81 | BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags ) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 82 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 83 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 84 | SERVER_START_REQ( set_handle_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 85 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 86 | req->handle = handle; |
| 87 | req->flags = flags; |
| 88 | req->mask = mask; |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 89 | req->fd = -1; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 90 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 91 | } |
| 92 | SERVER_END_REQ; |
| 93 | return ret; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 94 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | /********************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 98 | * DuplicateHandle (KERNEL32.@) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 99 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 100 | BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source, |
Alexandre Julliard | ac7b9d3 | 2002-09-16 19:32:50 +0000 | [diff] [blame] | 101 | HANDLE dest_process, HANDLE *dest, |
| 102 | DWORD access, BOOL inherit, DWORD options ) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 103 | { |
Alexandre Julliard | ac7b9d3 | 2002-09-16 19:32:50 +0000 | [diff] [blame] | 104 | NTSTATUS status = NtDuplicateObject( source_process, source, dest_process, dest, |
| 105 | access, inherit ? OBJ_INHERIT : 0, options ); |
| 106 | if (status) SetLastError( RtlNtStatusToDosError(status) ); |
| 107 | return !status; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 108 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 109 | |
| 110 | |
| 111 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 112 | * ConvertToGlobalHandle (KERNEL.476) |
| 113 | * ConvertToGlobalHandle (KERNEL32.@) |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 114 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 115 | HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc) |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 116 | { |
François Gouget | 55146db | 2000-12-24 20:33:01 +0000 | [diff] [blame] | 117 | HANDLE ret = INVALID_HANDLE_VALUE; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 118 | DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE, |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 119 | DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE ); |
| 120 | return ret; |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 121 | } |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 122 | |
| 123 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 124 | * SetHandleContext (KERNEL32.@) |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 125 | */ |
| 126 | BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) { |
Andreas Mohr | 913ce1f | 2000-07-15 21:29:34 +0000 | [diff] [blame] | 127 | FIXME("(%d,%ld), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context); |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 128 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 129 | return FALSE; |
| 130 | } |
| 131 | |
| 132 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 133 | * GetHandleContext (KERNEL32.@) |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 134 | */ |
| 135 | DWORD WINAPI GetHandleContext(HANDLE hnd) { |
Andreas Mohr | 913ce1f | 2000-07-15 21:29:34 +0000 | [diff] [blame] | 136 | FIXME("(%d), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd); |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 137 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 142 | * CreateSocketHandle (KERNEL32.@) |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 143 | */ |
| 144 | HANDLE WINAPI CreateSocketHandle(void) { |
Andreas Mohr | 913ce1f | 2000-07-15 21:29:34 +0000 | [diff] [blame] | 145 | FIXME("(), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n"); |
Marcus Meissner | 450f96a | 1999-04-22 14:55:06 +0000 | [diff] [blame] | 146 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 147 | return INVALID_HANDLE_VALUE; |
| 148 | } |