blob: 1155da9c0d895425630f6590210719e868417ab0 [file] [log] [blame]
Alexandre Julliard03468f71998-02-15 19:40:49 +00001/*
2 * Win32 process handles
3 *
4 * Copyright 1998 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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 Julliard03468f71998-02-15 19:40:49 +000019 */
20
Patrik Stridvalld016f812002-08-17 00:43:16 +000021#include "config.h"
22
Alexandre Julliard03468f71998-02-15 19:40:49 +000023#include <assert.h>
24#include <stdio.h>
Patrik Stridvall9aab47e2002-08-28 23:42:34 +000025#ifdef HAVE_IO_H
26# include <io.h>
27#endif
Patrik Stridvalld016f812002-08-17 00:43:16 +000028#ifdef HAVE_UNISTD_H
29# include <unistd.h>
30#endif
Alexandre Julliard03468f71998-02-15 19:40:49 +000031#include "winbase.h"
Alexandre Julliard37e95032001-07-19 00:39:09 +000032#include "wine/server.h"
Marcus Meissner450f96a1999-04-22 14:55:06 +000033#include "winerror.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000034#include "wine/debug.h"
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000035
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000036WINE_DEFAULT_DEBUG_CHANNEL(win32);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000037
38/*********************************************************************
Patrik Stridvall044855c2001-07-11 18:56:41 +000039 * CloseW32Handle (KERNEL.474)
40 * CloseHandle (KERNEL32.@)
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000041 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000042BOOL WINAPI CloseHandle( HANDLE handle )
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000043{
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000044 NTSTATUS status;
45
Alexandre Julliarda67d7161999-11-04 02:49:06 +000046 /* stdio handles need special treatment */
Alexandre Julliard267ca682002-07-31 17:20:00 +000047 if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
48 (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
49 (handle == (HANDLE)STD_ERROR_HANDLE))
50 handle = GetStdHandle( (DWORD)handle );
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000051
52 status = NtClose( handle );
53 if (status) SetLastError( RtlNtStatusToDosError(status) );
54 return !status;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000055}
56
57
58/*********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +000059 * GetHandleInformation (KERNEL32.@)
Alexandre Julliard03468f71998-02-15 19:40:49 +000060 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000061BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
Alexandre Julliard03468f71998-02-15 19:40:49 +000062{
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000063 BOOL ret;
Alexandre Julliard67a74992001-02-27 02:09:16 +000064 SERVER_START_REQ( set_handle_info )
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000065 {
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000066 req->handle = handle;
Alexandre Julliardd549f692000-12-22 02:04:15 +000067 req->flags = 0;
68 req->mask = 0;
69 req->fd = -1;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +000070 ret = !wine_server_call_err( req );
71 if (ret && flags) *flags = reply->old_flags;
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000072 }
73 SERVER_END_REQ;
74 return ret;
Alexandre Julliard03468f71998-02-15 19:40:49 +000075}
76
77
78/*********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +000079 * SetHandleInformation (KERNEL32.@)
Alexandre Julliard03468f71998-02-15 19:40:49 +000080 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000081BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
Alexandre Julliard03468f71998-02-15 19:40:49 +000082{
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000083 BOOL ret;
Alexandre Julliard67a74992001-02-27 02:09:16 +000084 SERVER_START_REQ( set_handle_info )
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000085 {
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000086 req->handle = handle;
87 req->flags = flags;
88 req->mask = mask;
Alexandre Julliardd549f692000-12-22 02:04:15 +000089 req->fd = -1;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +000090 ret = !wine_server_call_err( req );
Alexandre Julliard9c2370b2000-08-30 00:00:48 +000091 }
92 SERVER_END_REQ;
93 return ret;
Alexandre Julliard03468f71998-02-15 19:40:49 +000094}
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000095
96
97/*********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +000098 * DuplicateHandle (KERNEL32.@)
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000099 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000100BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
Alexandre Julliardac7b9d32002-09-16 19:32:50 +0000101 HANDLE dest_process, HANDLE *dest,
102 DWORD access, BOOL inherit, DWORD options )
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000103{
Alexandre Julliardac7b9d32002-09-16 19:32:50 +0000104 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 Julliardc7c217b1998-04-13 12:21:30 +0000108}
Alexandre Julliard55443871998-12-31 15:52:06 +0000109
110
111/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000112 * ConvertToGlobalHandle (KERNEL.476)
113 * ConvertToGlobalHandle (KERNEL32.@)
Alexandre Julliard55443871998-12-31 15:52:06 +0000114 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000115HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
Alexandre Julliard55443871998-12-31 15:52:06 +0000116{
François Gouget55146db2000-12-24 20:33:01 +0000117 HANDLE ret = INVALID_HANDLE_VALUE;
Alexandre Julliard8081e5a2001-01-05 04:08:07 +0000118 DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000119 DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
120 return ret;
Alexandre Julliard55443871998-12-31 15:52:06 +0000121}
Marcus Meissner450f96a1999-04-22 14:55:06 +0000122
123/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000124 * SetHandleContext (KERNEL32.@)
Marcus Meissner450f96a1999-04-22 14:55:06 +0000125 */
126BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) {
Andreas Mohr913ce1f2000-07-15 21:29:34 +0000127 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 Meissner450f96a1999-04-22 14:55:06 +0000128 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
129 return FALSE;
130}
131
132/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000133 * GetHandleContext (KERNEL32.@)
Marcus Meissner450f96a1999-04-22 14:55:06 +0000134 */
135DWORD WINAPI GetHandleContext(HANDLE hnd) {
Andreas Mohr913ce1f2000-07-15 21:29:34 +0000136 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 Meissner450f96a1999-04-22 14:55:06 +0000137 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
138 return 0;
139}
140
141/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000142 * CreateSocketHandle (KERNEL32.@)
Marcus Meissner450f96a1999-04-22 14:55:06 +0000143 */
144HANDLE WINAPI CreateSocketHandle(void) {
Andreas Mohr913ce1f2000-07-15 21:29:34 +0000145 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 Meissner450f96a1999-04-22 14:55:06 +0000146 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
147 return INVALID_HANDLE_VALUE;
148}