2 * Wine server communication
4 * Copyright (C) 1998 Alexandre Julliard
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
34 #ifdef HAVE_PTHREAD_NP_H
35 # include <pthread_np.h>
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
45 #ifdef HAVE_SYS_WAIT_H
51 #ifdef HAVE_SYS_MMAN_H
54 #ifdef HAVE_SYS_PRCTL_H
55 # include <sys/prctl.h>
57 #ifdef HAVE_SYS_STAT_H
58 # include <sys/stat.h>
60 #ifdef HAVE_SYS_SYSCALL_H
61 # include <sys/syscall.h>
66 #ifdef HAVE_SYS_UCONTEXT_H
67 # include <sys/ucontext.h>
77 #define WIN32_NO_STATUS
80 #include "wine/library.h"
81 #include "wine/server.h"
82 #include "wine/debug.h"
83 #include "ntdll_misc.h"
85 WINE_DEFAULT_DEBUG_CHANNEL(server
);
87 /* Some versions of glibc don't define this */
92 #ifndef MSG_CMSG_CLOEXEC
93 #define MSG_CMSG_CLOEXEC 0
96 #define SOCKETNAME "socket" /* name of the socket file */
97 #define LOCKNAME "lock" /* name of the lock file */
100 static const enum cpu_type client_cpu
= CPU_x86
;
101 #elif defined(__x86_64__)
102 static const enum cpu_type client_cpu
= CPU_x86_64
;
103 #elif defined(__powerpc__)
104 static const enum cpu_type client_cpu
= CPU_POWERPC
;
105 #elif defined(__arm__)
106 static const enum cpu_type client_cpu
= CPU_ARM
;
107 #elif defined(__aarch64__)
108 static const enum cpu_type client_cpu
= CPU_ARM64
;
110 #error Unsupported CPU
113 unsigned int server_cpus
= 0;
114 BOOL is_wow64
= FALSE
;
116 timeout_t server_start_time
= 0; /* time of server startup */
118 sigset_t server_block_set
; /* signals to block during server calls */
119 static int fd_socket
= -1; /* socket to exchange file descriptors with the server */
120 static pid_t server_pid
;
122 static RTL_CRITICAL_SECTION fd_cache_section
;
123 static RTL_CRITICAL_SECTION_DEBUG critsect_debug
=
125 0, 0, &fd_cache_section
,
126 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
127 0, 0, { (DWORD_PTR
)(__FILE__
": fd_cache_section") }
129 static RTL_CRITICAL_SECTION fd_cache_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
131 /* atomically exchange a 64-bit value */
132 static inline LONG64
interlocked_xchg64( LONG64
*dest
, LONG64 val
)
135 return (LONG64
)interlocked_xchg_ptr( (void **)dest
, (void *)val
);
138 while (interlocked_cmpxchg64( dest
, val
, tmp
) != tmp
) tmp
= *dest
;
144 static void fatal_error( const char *err
, ... ) __attribute__((noreturn
, format(printf
,1,2)));
145 static void fatal_perror( const char *err
, ... ) __attribute__((noreturn
, format(printf
,1,2)));
146 static void server_connect_error( const char *serverdir
) __attribute__((noreturn
));
149 /* die on a fatal error; use only during initialization */
150 static void fatal_error( const char *err
, ... )
154 va_start( args
, err
);
155 fprintf( stderr
, "wine: " );
156 vfprintf( stderr
, err
, args
);
161 /* die on a fatal error; use only during initialization */
162 static void fatal_perror( const char *err
, ... )
166 va_start( args
, err
);
167 fprintf( stderr
, "wine: " );
168 vfprintf( stderr
, err
, args
);
175 /***********************************************************************
176 * server_protocol_error
178 static DECLSPEC_NORETURN
void server_protocol_error( const char *err
, ... )
182 va_start( args
, err
);
183 fprintf( stderr
, "wine client error:%x: ", GetCurrentThreadId() );
184 vfprintf( stderr
, err
, args
);
190 /***********************************************************************
191 * server_protocol_perror
193 static DECLSPEC_NORETURN
void server_protocol_perror( const char *err
)
195 fprintf( stderr
, "wine client error:%x: ", GetCurrentThreadId() );
201 /***********************************************************************
204 * Send a request to the server.
206 static unsigned int send_request( const struct __server_request_info
*req
)
211 if (!req
->u
.req
.request_header
.request_size
)
213 if ((ret
= write( ntdll_get_thread_data()->request_fd
, &req
->u
.req
,
214 sizeof(req
->u
.req
) )) == sizeof(req
->u
.req
)) return STATUS_SUCCESS
;
219 struct iovec vec
[__SERVER_MAX_DATA
+1];
221 vec
[0].iov_base
= (void *)&req
->u
.req
;
222 vec
[0].iov_len
= sizeof(req
->u
.req
);
223 for (i
= 0; i
< req
->data_count
; i
++)
225 vec
[i
+1].iov_base
= (void *)req
->data
[i
].ptr
;
226 vec
[i
+1].iov_len
= req
->data
[i
].size
;
228 if ((ret
= writev( ntdll_get_thread_data()->request_fd
, vec
, i
+1 )) ==
229 req
->u
.req
.request_header
.request_size
+ sizeof(req
->u
.req
)) return STATUS_SUCCESS
;
232 if (ret
>= 0) server_protocol_error( "partial write %d\n", ret
);
233 if (errno
== EPIPE
) abort_thread(0);
234 if (errno
== EFAULT
) return STATUS_ACCESS_VIOLATION
;
235 server_protocol_perror( "write" );
239 /***********************************************************************
242 * Read data from the reply buffer; helper for wait_reply.
244 static void read_reply_data( void *buffer
, size_t size
)
250 if ((ret
= read( ntdll_get_thread_data()->reply_fd
, buffer
, size
)) > 0)
252 if (!(size
-= ret
)) return;
253 buffer
= (char *)buffer
+ ret
;
257 if (errno
== EINTR
) continue;
258 if (errno
== EPIPE
) break;
259 server_protocol_perror("read");
261 /* the server closed the connection; time to die... */
266 /***********************************************************************
269 * Wait for a reply from the server.
271 static inline unsigned int wait_reply( struct __server_request_info
*req
)
273 read_reply_data( &req
->u
.reply
, sizeof(req
->u
.reply
) );
274 if (req
->u
.reply
.reply_header
.reply_size
)
275 read_reply_data( req
->reply_data
, req
->u
.reply
.reply_header
.reply_size
);
276 return req
->u
.reply
.reply_header
.error
;
280 /***********************************************************************
281 * wine_server_call (NTDLL.@)
283 * Perform a server call.
286 * req_ptr [I/O] Function dependent data
289 * Depends on server function being called, but usually an NTSTATUS code.
292 * Use the SERVER_START_REQ and SERVER_END_REQ to help you fill out the
293 * server request structure for the particular call. E.g:
294 *| SERVER_START_REQ( event_op )
296 *| req->handle = handle;
297 *| req->op = SET_EVENT;
298 *| ret = wine_server_call( req );
302 unsigned int wine_server_call( void *req_ptr
)
304 struct __server_request_info
* const req
= req_ptr
;
308 pthread_sigmask( SIG_BLOCK
, &server_block_set
, &old_set
);
309 ret
= send_request( req
);
310 if (!ret
) ret
= wait_reply( req
);
311 pthread_sigmask( SIG_SETMASK
, &old_set
, NULL
);
316 /***********************************************************************
317 * server_enter_uninterrupted_section
319 void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION
*cs
, sigset_t
*sigset
)
321 pthread_sigmask( SIG_BLOCK
, &server_block_set
, sigset
);
322 RtlEnterCriticalSection( cs
);
326 /***********************************************************************
327 * server_leave_uninterrupted_section
329 void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION
*cs
, sigset_t
*sigset
)
331 RtlLeaveCriticalSection( cs
);
332 pthread_sigmask( SIG_SETMASK
, sigset
, NULL
);
336 /***********************************************************************
339 * Wait for a reply on the waiting pipe of the current thread.
341 static int wait_select_reply( void *cookie
)
344 struct wake_up_reply reply
;
348 ret
= read( ntdll_get_thread_data()->wait_fd
[0], &reply
, sizeof(reply
) );
349 if (ret
== sizeof(reply
))
351 if (!reply
.cookie
) abort_thread( reply
.signaled
); /* thread got killed */
352 if (wine_server_get_ptr(reply
.cookie
) == cookie
) return reply
.signaled
;
353 /* we stole another reply, wait for the real one */
354 signaled
= wait_select_reply( cookie
);
355 /* and now put the wrong one back in the pipe */
358 ret
= write( ntdll_get_thread_data()->wait_fd
[1], &reply
, sizeof(reply
) );
359 if (ret
== sizeof(reply
)) break;
360 if (ret
>= 0) server_protocol_error( "partial wakeup write %d\n", ret
);
361 if (errno
== EINTR
) continue;
362 server_protocol_perror("wakeup write");
366 if (ret
>= 0) server_protocol_error( "partial wakeup read %d\n", ret
);
367 if (errno
== EINTR
) continue;
368 server_protocol_perror("wakeup read");
373 /***********************************************************************
376 * Invoke a single APC. Return TRUE if a user APC has been run.
378 static BOOL
invoke_apc( const apc_call_t
*call
, apc_result_t
*result
)
380 BOOL user_apc
= FALSE
;
384 memset( result
, 0, sizeof(*result
) );
392 void (WINAPI
*func
)(ULONG_PTR
,ULONG_PTR
,ULONG_PTR
) = wine_server_get_ptr( call
->user
.func
);
393 func( call
->user
.args
[0], call
->user
.args
[1], call
->user
.args
[2] );
399 void (WINAPI
*func
)(void*, unsigned int, unsigned int) = wine_server_get_ptr( call
->timer
.func
);
400 func( wine_server_get_ptr( call
->timer
.arg
),
401 (DWORD
)call
->timer
.time
, (DWORD
)(call
->timer
.time
>> 32) );
407 IO_STATUS_BLOCK
*iosb
= wine_server_get_ptr( call
->async_io
.sb
);
408 NTSTATUS (**user
)(void *, IO_STATUS_BLOCK
*, NTSTATUS
) = wine_server_get_ptr( call
->async_io
.user
);
409 result
->type
= call
->type
;
410 result
->async_io
.status
= (*user
)( user
, iosb
, call
->async_io
.status
);
411 if (result
->async_io
.status
!= STATUS_PENDING
)
412 result
->async_io
.total
= iosb
->Information
;
415 case APC_VIRTUAL_ALLOC
:
416 result
->type
= call
->type
;
417 addr
= wine_server_get_ptr( call
->virtual_alloc
.addr
);
418 size
= call
->virtual_alloc
.size
;
419 if ((ULONG_PTR
)addr
== call
->virtual_alloc
.addr
&& size
== call
->virtual_alloc
.size
)
421 result
->virtual_alloc
.status
= NtAllocateVirtualMemory( NtCurrentProcess(), &addr
,
422 call
->virtual_alloc
.zero_bits
, &size
,
423 call
->virtual_alloc
.op_type
,
424 call
->virtual_alloc
.prot
);
425 result
->virtual_alloc
.addr
= wine_server_client_ptr( addr
);
426 result
->virtual_alloc
.size
= size
;
428 else result
->virtual_alloc
.status
= STATUS_WORKING_SET_LIMIT_RANGE
;
430 case APC_VIRTUAL_FREE
:
431 result
->type
= call
->type
;
432 addr
= wine_server_get_ptr( call
->virtual_free
.addr
);
433 size
= call
->virtual_free
.size
;
434 if ((ULONG_PTR
)addr
== call
->virtual_free
.addr
&& size
== call
->virtual_free
.size
)
436 result
->virtual_free
.status
= NtFreeVirtualMemory( NtCurrentProcess(), &addr
, &size
,
437 call
->virtual_free
.op_type
);
438 result
->virtual_free
.addr
= wine_server_client_ptr( addr
);
439 result
->virtual_free
.size
= size
;
441 else result
->virtual_free
.status
= STATUS_INVALID_PARAMETER
;
443 case APC_VIRTUAL_QUERY
:
445 MEMORY_BASIC_INFORMATION info
;
446 result
->type
= call
->type
;
447 addr
= wine_server_get_ptr( call
->virtual_query
.addr
);
448 if ((ULONG_PTR
)addr
== call
->virtual_query
.addr
)
449 result
->virtual_query
.status
= NtQueryVirtualMemory( NtCurrentProcess(),
450 addr
, MemoryBasicInformation
, &info
,
451 sizeof(info
), NULL
);
453 result
->virtual_query
.status
= STATUS_WORKING_SET_LIMIT_RANGE
;
455 if (result
->virtual_query
.status
== STATUS_SUCCESS
)
457 result
->virtual_query
.base
= wine_server_client_ptr( info
.BaseAddress
);
458 result
->virtual_query
.alloc_base
= wine_server_client_ptr( info
.AllocationBase
);
459 result
->virtual_query
.size
= info
.RegionSize
;
460 result
->virtual_query
.prot
= info
.Protect
;
461 result
->virtual_query
.alloc_prot
= info
.AllocationProtect
;
462 result
->virtual_query
.state
= info
.State
>> 12;
463 result
->virtual_query
.alloc_type
= info
.Type
>> 16;
467 case APC_VIRTUAL_PROTECT
:
468 result
->type
= call
->type
;
469 addr
= wine_server_get_ptr( call
->virtual_protect
.addr
);
470 size
= call
->virtual_protect
.size
;
471 if ((ULONG_PTR
)addr
== call
->virtual_protect
.addr
&& size
== call
->virtual_protect
.size
)
473 result
->virtual_protect
.status
= NtProtectVirtualMemory( NtCurrentProcess(), &addr
, &size
,
474 call
->virtual_protect
.prot
,
475 &result
->virtual_protect
.prot
);
476 result
->virtual_protect
.addr
= wine_server_client_ptr( addr
);
477 result
->virtual_protect
.size
= size
;
479 else result
->virtual_protect
.status
= STATUS_INVALID_PARAMETER
;
481 case APC_VIRTUAL_FLUSH
:
482 result
->type
= call
->type
;
483 addr
= wine_server_get_ptr( call
->virtual_flush
.addr
);
484 size
= call
->virtual_flush
.size
;
485 if ((ULONG_PTR
)addr
== call
->virtual_flush
.addr
&& size
== call
->virtual_flush
.size
)
487 result
->virtual_flush
.status
= NtFlushVirtualMemory( NtCurrentProcess(),
488 (const void **)&addr
, &size
, 0 );
489 result
->virtual_flush
.addr
= wine_server_client_ptr( addr
);
490 result
->virtual_flush
.size
= size
;
492 else result
->virtual_flush
.status
= STATUS_INVALID_PARAMETER
;
494 case APC_VIRTUAL_LOCK
:
495 result
->type
= call
->type
;
496 addr
= wine_server_get_ptr( call
->virtual_lock
.addr
);
497 size
= call
->virtual_lock
.size
;
498 if ((ULONG_PTR
)addr
== call
->virtual_lock
.addr
&& size
== call
->virtual_lock
.size
)
500 result
->virtual_lock
.status
= NtLockVirtualMemory( NtCurrentProcess(), &addr
, &size
, 0 );
501 result
->virtual_lock
.addr
= wine_server_client_ptr( addr
);
502 result
->virtual_lock
.size
= size
;
504 else result
->virtual_lock
.status
= STATUS_INVALID_PARAMETER
;
506 case APC_VIRTUAL_UNLOCK
:
507 result
->type
= call
->type
;
508 addr
= wine_server_get_ptr( call
->virtual_unlock
.addr
);
509 size
= call
->virtual_unlock
.size
;
510 if ((ULONG_PTR
)addr
== call
->virtual_unlock
.addr
&& size
== call
->virtual_unlock
.size
)
512 result
->virtual_unlock
.status
= NtUnlockVirtualMemory( NtCurrentProcess(), &addr
, &size
, 0 );
513 result
->virtual_unlock
.addr
= wine_server_client_ptr( addr
);
514 result
->virtual_unlock
.size
= size
;
516 else result
->virtual_unlock
.status
= STATUS_INVALID_PARAMETER
;
519 result
->type
= call
->type
;
520 addr
= wine_server_get_ptr( call
->map_view
.addr
);
521 size
= call
->map_view
.size
;
522 if ((ULONG_PTR
)addr
== call
->map_view
.addr
&& size
== call
->map_view
.size
)
524 LARGE_INTEGER offset
;
525 offset
.QuadPart
= call
->map_view
.offset
;
526 result
->map_view
.status
= NtMapViewOfSection( wine_server_ptr_handle(call
->map_view
.handle
),
527 NtCurrentProcess(), &addr
,
528 call
->map_view
.zero_bits
, 0,
529 &offset
, &size
, ViewShare
,
530 call
->map_view
.alloc_type
, call
->map_view
.prot
);
531 result
->map_view
.addr
= wine_server_client_ptr( addr
);
532 result
->map_view
.size
= size
;
534 else result
->map_view
.status
= STATUS_INVALID_PARAMETER
;
535 NtClose( wine_server_ptr_handle(call
->map_view
.handle
) );
538 result
->type
= call
->type
;
539 addr
= wine_server_get_ptr( call
->unmap_view
.addr
);
540 if ((ULONG_PTR
)addr
== call
->unmap_view
.addr
)
541 result
->unmap_view
.status
= NtUnmapViewOfSection( NtCurrentProcess(), addr
);
543 result
->unmap_view
.status
= STATUS_INVALID_PARAMETER
;
545 case APC_CREATE_THREAD
:
549 SIZE_T reserve
= call
->create_thread
.reserve
;
550 SIZE_T commit
= call
->create_thread
.commit
;
551 void *func
= wine_server_get_ptr( call
->create_thread
.func
);
552 void *arg
= wine_server_get_ptr( call
->create_thread
.arg
);
554 result
->type
= call
->type
;
555 if (reserve
== call
->create_thread
.reserve
&& commit
== call
->create_thread
.commit
&&
556 (ULONG_PTR
)func
== call
->create_thread
.func
&& (ULONG_PTR
)arg
== call
->create_thread
.arg
)
558 result
->create_thread
.status
= RtlCreateUserThread( NtCurrentProcess(), NULL
,
559 call
->create_thread
.suspend
, NULL
,
560 reserve
, commit
, func
, arg
, &handle
, &id
);
561 result
->create_thread
.handle
= wine_server_obj_handle( handle
);
562 result
->create_thread
.tid
= HandleToULong(id
.UniqueThread
);
564 else result
->create_thread
.status
= STATUS_INVALID_PARAMETER
;
568 server_protocol_error( "get_apc_request: bad type %d\n", call
->type
);
575 /***********************************************************************
578 unsigned int server_select( const select_op_t
*select_op
, data_size_t size
, UINT flags
,
579 const LARGE_INTEGER
*timeout
)
583 BOOL user_apc
= FALSE
;
584 obj_handle_t apc_handle
= 0;
587 timeout_t abs_timeout
= timeout
? timeout
->QuadPart
: TIMEOUT_INFINITE
;
589 memset( &result
, 0, sizeof(result
) );
593 SERVER_START_REQ( select
)
596 req
->cookie
= wine_server_client_ptr( &cookie
);
597 req
->prev_apc
= apc_handle
;
598 req
->timeout
= abs_timeout
;
599 wine_server_add_data( req
, &result
, sizeof(result
) );
600 wine_server_add_data( req
, select_op
, size
);
601 ret
= wine_server_call( req
);
602 abs_timeout
= reply
->timeout
;
603 apc_handle
= reply
->apc_handle
;
607 if (ret
== STATUS_PENDING
) ret
= wait_select_reply( &cookie
);
608 if (ret
!= STATUS_USER_APC
) break;
609 if (invoke_apc( &call
, &result
))
611 /* if we ran a user apc we have to check once more if additional apcs are queued,
612 * but we don't want to wait */
618 /* don't signal multiple times */
619 if (size
>= sizeof(select_op
->signal_and_wait
) && select_op
->op
== SELECT_SIGNAL_AND_WAIT
)
620 size
= offsetof( select_op_t
, signal_and_wait
.signal
);
623 if (ret
== STATUS_TIMEOUT
&& user_apc
) ret
= STATUS_USER_APC
;
625 /* A test on Windows 2000 shows that Windows always yields during
626 a wait, but a wait that is hit by an event gets a priority
627 boost as well. This seems to model that behavior the closest. */
628 if (ret
== STATUS_TIMEOUT
) NtYieldExecution();
634 /***********************************************************************
635 * server_queue_process_apc
637 unsigned int server_queue_process_apc( HANDLE process
, const apc_call_t
*call
, apc_result_t
*result
)
645 SERVER_START_REQ( queue_apc
)
647 req
->handle
= wine_server_obj_handle( process
);
649 if (!(ret
= wine_server_call( req
)))
651 handle
= wine_server_ptr_handle( reply
->handle
);
656 if (ret
!= STATUS_SUCCESS
) return ret
;
660 invoke_apc( call
, result
);
664 NtWaitForSingleObject( handle
, FALSE
, NULL
);
666 SERVER_START_REQ( get_apc_result
)
668 req
->handle
= wine_server_obj_handle( handle
);
669 if (!(ret
= wine_server_call( req
))) *result
= reply
->result
;
673 if (!ret
&& result
->type
== APC_NONE
) continue; /* APC didn't run, try again */
680 /***********************************************************************
681 * wine_server_send_fd (NTDLL.@)
683 * Send a file descriptor to the server.
686 * fd [I] file descriptor to send
691 void CDECL
wine_server_send_fd( int fd
)
694 struct msghdr msghdr
;
698 #ifdef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
699 msghdr
.msg_accrights
= (void *)&fd
;
700 msghdr
.msg_accrightslen
= sizeof(fd
);
701 #else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
702 char cmsg_buffer
[256];
703 struct cmsghdr
*cmsg
;
704 msghdr
.msg_control
= cmsg_buffer
;
705 msghdr
.msg_controllen
= sizeof(cmsg_buffer
);
706 msghdr
.msg_flags
= 0;
707 cmsg
= CMSG_FIRSTHDR( &msghdr
);
708 cmsg
->cmsg_len
= CMSG_LEN( sizeof(fd
) );
709 cmsg
->cmsg_level
= SOL_SOCKET
;
710 cmsg
->cmsg_type
= SCM_RIGHTS
;
711 *(int *)CMSG_DATA(cmsg
) = fd
;
712 msghdr
.msg_controllen
= cmsg
->cmsg_len
;
713 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
715 msghdr
.msg_name
= NULL
;
716 msghdr
.msg_namelen
= 0;
717 msghdr
.msg_iov
= &vec
;
718 msghdr
.msg_iovlen
= 1;
720 vec
.iov_base
= (void *)&data
;
721 vec
.iov_len
= sizeof(data
);
723 data
.tid
= GetCurrentThreadId();
728 if ((ret
= sendmsg( fd_socket
, &msghdr
, 0 )) == sizeof(data
)) return;
729 if (ret
>= 0) server_protocol_error( "partial write %d\n", ret
);
730 if (errno
== EINTR
) continue;
731 if (errno
== EPIPE
) abort_thread(0);
732 server_protocol_perror( "sendmsg" );
737 /***********************************************************************
740 * Receive a file descriptor passed from the server.
742 static int receive_fd( obj_handle_t
*handle
)
745 struct msghdr msghdr
;
748 #ifdef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
749 msghdr
.msg_accrights
= (void *)&fd
;
750 msghdr
.msg_accrightslen
= sizeof(fd
);
751 #else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
752 char cmsg_buffer
[256];
753 msghdr
.msg_control
= cmsg_buffer
;
754 msghdr
.msg_controllen
= sizeof(cmsg_buffer
);
755 msghdr
.msg_flags
= 0;
756 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
758 msghdr
.msg_name
= NULL
;
759 msghdr
.msg_namelen
= 0;
760 msghdr
.msg_iov
= &vec
;
761 msghdr
.msg_iovlen
= 1;
762 vec
.iov_base
= (void *)handle
;
763 vec
.iov_len
= sizeof(*handle
);
767 if ((ret
= recvmsg( fd_socket
, &msghdr
, MSG_CMSG_CLOEXEC
)) > 0)
769 #ifndef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
770 struct cmsghdr
*cmsg
;
771 for (cmsg
= CMSG_FIRSTHDR( &msghdr
); cmsg
; cmsg
= CMSG_NXTHDR( &msghdr
, cmsg
))
773 if (cmsg
->cmsg_level
!= SOL_SOCKET
) continue;
774 if (cmsg
->cmsg_type
== SCM_RIGHTS
) fd
= *(int *)CMSG_DATA(cmsg
);
775 #ifdef SCM_CREDENTIALS
776 else if (cmsg
->cmsg_type
== SCM_CREDENTIALS
)
778 struct ucred
*ucred
= (struct ucred
*)CMSG_DATA(cmsg
);
779 server_pid
= ucred
->pid
;
783 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
784 if (fd
!= -1) fcntl( fd
, F_SETFD
, FD_CLOEXEC
); /* in case MSG_CMSG_CLOEXEC is not supported */
788 if (errno
== EINTR
) continue;
789 if (errno
== EPIPE
) break;
790 server_protocol_perror("recvmsg");
792 /* the server closed the connection; time to die... */
797 /***********************************************************************/
798 /* fd cache support */
800 #include "pshpack1.h"
807 enum server_fd_type type
: 5;
808 unsigned int access
: 3;
809 unsigned int options
: 24;
814 C_ASSERT( sizeof(union fd_cache_entry
) == sizeof(LONG64
) );
816 #define FD_CACHE_BLOCK_SIZE (65536 / sizeof(union fd_cache_entry))
817 #define FD_CACHE_ENTRIES 128
819 static union fd_cache_entry
*fd_cache
[FD_CACHE_ENTRIES
];
820 static union fd_cache_entry fd_cache_initial_block
[FD_CACHE_BLOCK_SIZE
];
822 static inline unsigned int handle_to_index( HANDLE handle
, unsigned int *entry
)
824 unsigned int idx
= (wine_server_obj_handle(handle
) >> 2) - 1;
825 *entry
= idx
/ FD_CACHE_BLOCK_SIZE
;
826 return idx
% FD_CACHE_BLOCK_SIZE
;
830 /***********************************************************************
833 * Caller must hold fd_cache_section.
835 static BOOL
add_fd_to_cache( HANDLE handle
, int fd
, enum server_fd_type type
,
836 unsigned int access
, unsigned int options
)
838 unsigned int entry
, idx
= handle_to_index( handle
, &entry
);
839 union fd_cache_entry cache
;
841 if (entry
>= FD_CACHE_ENTRIES
)
843 FIXME( "too many allocated handles, not caching %p\n", handle
);
847 if (!fd_cache
[entry
]) /* do we need to allocate a new block of entries? */
849 if (!entry
) fd_cache
[0] = fd_cache_initial_block
;
852 void *ptr
= wine_anon_mmap( NULL
, FD_CACHE_BLOCK_SIZE
* sizeof(union fd_cache_entry
),
853 PROT_READ
| PROT_WRITE
, 0 );
854 if (ptr
== MAP_FAILED
) return FALSE
;
855 fd_cache
[entry
] = ptr
;
859 /* store fd+1 so that 0 can be used as the unset value */
862 cache
.s
.access
= access
;
863 cache
.s
.options
= options
;
864 cache
.data
= interlocked_xchg64( &fd_cache
[entry
][idx
].data
, cache
.data
);
865 assert( !cache
.s
.fd
);
870 /***********************************************************************
873 static inline NTSTATUS
get_cached_fd( HANDLE handle
, int *fd
, enum server_fd_type
*type
,
874 unsigned int *access
, unsigned int *options
)
876 unsigned int entry
, idx
= handle_to_index( handle
, &entry
);
877 union fd_cache_entry cache
;
879 if (entry
>= FD_CACHE_ENTRIES
|| !fd_cache
[entry
]) return STATUS_INVALID_HANDLE
;
881 cache
.data
= interlocked_cmpxchg64( &fd_cache
[entry
][idx
].data
, 0, 0 );
882 if (!cache
.data
) return STATUS_INVALID_HANDLE
;
884 /* if fd type is invalid, fd stores an error value */
885 if (cache
.s
.type
== FD_TYPE_INVALID
) return cache
.s
.fd
- 1;
887 *fd
= cache
.s
.fd
- 1;
888 if (type
) *type
= cache
.s
.type
;
889 if (access
) *access
= cache
.s
.access
;
890 if (options
) *options
= cache
.s
.options
;
891 return STATUS_SUCCESS
;
895 /***********************************************************************
896 * server_remove_fd_from_cache
898 int server_remove_fd_from_cache( HANDLE handle
)
900 unsigned int entry
, idx
= handle_to_index( handle
, &entry
);
903 if (entry
< FD_CACHE_ENTRIES
&& fd_cache
[entry
])
905 union fd_cache_entry cache
;
906 cache
.data
= interlocked_xchg64( &fd_cache
[entry
][idx
].data
, 0 );
907 if (cache
.s
.type
!= FD_TYPE_INVALID
) fd
= cache
.s
.fd
- 1;
914 /***********************************************************************
917 * The returned unix_fd should be closed iff needs_close is non-zero.
919 int server_get_unix_fd( HANDLE handle
, unsigned int wanted_access
, int *unix_fd
,
920 int *needs_close
, enum server_fd_type
*type
, unsigned int *options
)
923 obj_handle_t fd_handle
;
925 unsigned int access
= 0;
929 wanted_access
&= FILE_READ_DATA
| FILE_WRITE_DATA
| FILE_APPEND_DATA
;
931 ret
= get_cached_fd( handle
, &fd
, type
, &access
, options
);
932 if (ret
!= STATUS_INVALID_HANDLE
) goto done
;
934 server_enter_uninterrupted_section( &fd_cache_section
, &sigset
);
935 ret
= get_cached_fd( handle
, &fd
, type
, &access
, options
);
936 if (ret
== STATUS_INVALID_HANDLE
)
938 SERVER_START_REQ( get_handle_fd
)
940 req
->handle
= wine_server_obj_handle( handle
);
941 if (!(ret
= wine_server_call( req
)))
943 if (type
) *type
= reply
->type
;
944 if (options
) *options
= reply
->options
;
945 access
= reply
->access
;
946 if ((fd
= receive_fd( &fd_handle
)) != -1)
948 assert( wine_server_ptr_handle(fd_handle
) == handle
);
949 *needs_close
= (!reply
->cacheable
||
950 !add_fd_to_cache( handle
, fd
, reply
->type
,
951 reply
->access
, reply
->options
));
953 else ret
= STATUS_TOO_MANY_OPENED_FILES
;
955 else if (reply
->cacheable
)
957 add_fd_to_cache( handle
, ret
, FD_TYPE_INVALID
, 0, 0 );
962 server_leave_uninterrupted_section( &fd_cache_section
, &sigset
);
965 if (!ret
&& ((access
& wanted_access
) != wanted_access
))
967 ret
= STATUS_ACCESS_DENIED
;
968 if (*needs_close
) close( fd
);
970 if (!ret
) *unix_fd
= fd
;
975 /***********************************************************************
976 * wine_server_fd_to_handle (NTDLL.@)
978 * Allocate a file handle for a Unix file descriptor.
981 * fd [I] Unix file descriptor.
982 * access [I] Win32 access flags.
983 * attributes [I] Object attributes.
984 * handle [O] Address where Wine file handle will be stored.
989 int CDECL
wine_server_fd_to_handle( int fd
, unsigned int access
, unsigned int attributes
, HANDLE
*handle
)
994 wine_server_send_fd( fd
);
996 SERVER_START_REQ( alloc_file_handle
)
998 req
->access
= access
;
999 req
->attributes
= attributes
;
1001 if (!(ret
= wine_server_call( req
))) *handle
= wine_server_ptr_handle( reply
->handle
);
1008 /***********************************************************************
1009 * wine_server_handle_to_fd (NTDLL.@)
1011 * Retrieve the file descriptor corresponding to a file handle.
1014 * handle [I] Wine file handle.
1015 * access [I] Win32 file access rights requested.
1016 * unix_fd [O] Address where Unix file descriptor will be stored.
1017 * options [O] Address where the file open options will be stored. Optional.
1022 int CDECL
wine_server_handle_to_fd( HANDLE handle
, unsigned int access
, int *unix_fd
,
1023 unsigned int *options
)
1025 int needs_close
, ret
= server_get_unix_fd( handle
, access
, unix_fd
, &needs_close
, NULL
, options
);
1027 if (!ret
&& !needs_close
)
1029 if ((*unix_fd
= dup(*unix_fd
)) == -1) ret
= FILE_GetNtStatus();
1035 /***********************************************************************
1036 * wine_server_release_fd (NTDLL.@)
1038 * Release the Unix file descriptor returned by wine_server_handle_to_fd.
1041 * handle [I] Wine file handle.
1042 * unix_fd [I] Unix file descriptor to release.
1047 void CDECL
wine_server_release_fd( HANDLE handle
, int unix_fd
)
1053 /***********************************************************************
1056 * Create a pipe for communicating with the server.
1058 int server_pipe( int fd
[2] )
1062 static BOOL have_pipe2
= TRUE
;
1066 if (!(ret
= pipe2( fd
, O_CLOEXEC
))) return ret
;
1067 if (errno
== ENOSYS
|| errno
== EINVAL
) have_pipe2
= FALSE
; /* don't try again */
1070 if (!(ret
= pipe( fd
)))
1072 fcntl( fd
[0], F_SETFD
, FD_CLOEXEC
);
1073 fcntl( fd
[1], F_SETFD
, FD_CLOEXEC
);
1079 /***********************************************************************
1082 * Start a new wine server.
1084 static void start_server(void)
1086 static BOOL started
; /* we only try once */
1088 static char wineserver
[] = "server/wineserver";
1089 static char debug
[] = "-d";
1095 if (pid
== -1) fatal_perror( "fork" );
1098 argv
[0] = wineserver
;
1099 argv
[1] = TRACE_ON(server
) ? debug
: NULL
;
1101 wine_exec_wine_binary( argv
[0], argv
, getenv("WINESERVER") );
1102 fatal_error( "could not exec wineserver\n" );
1104 waitpid( pid
, &status
, 0 );
1105 status
= WIFEXITED(status
) ? WEXITSTATUS(status
) : 1;
1106 if (status
== 2) return; /* server lock held by someone else, will retry later */
1107 if (status
) exit(status
); /* server failed */
1113 /***********************************************************************
1116 * Setup the wine configuration dir.
1118 static void setup_config_dir(void)
1120 const char *p
, *config_dir
= wine_get_config_dir();
1122 if (chdir( config_dir
) == -1)
1124 if (errno
!= ENOENT
) fatal_perror( "chdir to %s\n", config_dir
);
1126 if ((p
= strrchr( config_dir
, '/' )) && p
!= config_dir
)
1131 if (!(tmp_dir
= malloc( p
+ 1 - config_dir
))) fatal_error( "out of memory\n" );
1132 memcpy( tmp_dir
, config_dir
, p
- config_dir
);
1133 tmp_dir
[p
- config_dir
] = 0;
1134 if (!stat( tmp_dir
, &st
) && st
.st_uid
!= getuid())
1135 fatal_error( "'%s' is not owned by you, refusing to create a configuration directory there\n",
1140 mkdir( config_dir
, 0777 );
1141 if (chdir( config_dir
) == -1) fatal_perror( "chdir to %s\n", config_dir
);
1143 MESSAGE( "wine: created the configuration directory '%s'\n", config_dir
);
1146 if (mkdir( "dosdevices", 0777 ) == -1)
1148 if (errno
== EEXIST
) return;
1149 fatal_perror( "cannot create %s/dosdevices\n", config_dir
);
1152 /* create the drive symlinks */
1154 mkdir( "drive_c", 0777 );
1155 symlink( "../drive_c", "dosdevices/c:" );
1156 symlink( "/", "dosdevices/z:" );
1160 /***********************************************************************
1161 * server_connect_error
1163 * Try to display a meaningful explanation of why we couldn't connect
1166 static void server_connect_error( const char *serverdir
)
1171 if ((fd
= open( LOCKNAME
, O_WRONLY
)) == -1)
1172 fatal_error( "for some mysterious reason, the wine server never started.\n" );
1174 fl
.l_type
= F_WRLCK
;
1175 fl
.l_whence
= SEEK_SET
;
1178 if (fcntl( fd
, F_GETLK
, &fl
) != -1)
1180 if (fl
.l_type
== F_WRLCK
) /* the file is locked */
1181 fatal_error( "a wine server seems to be running, but I cannot connect to it.\n"
1182 " You probably need to kill that process (it might be pid %d).\n",
1184 fatal_error( "for some mysterious reason, the wine server failed to run.\n" );
1186 fatal_error( "the file system of '%s' doesn't support locks,\n"
1187 " and there is a 'socket' file in that directory that prevents wine from starting.\n"
1188 " You should make sure no wine server is running, remove that file and try again.\n",
1193 /***********************************************************************
1196 * Attempt to connect to an existing server socket.
1197 * We need to be in the server directory already.
1199 static int server_connect(void)
1201 const char *serverdir
;
1202 struct sockaddr_un addr
;
1204 int s
, slen
, retry
, fd_cwd
;
1206 /* retrieve the current directory */
1207 fd_cwd
= open( ".", O_RDONLY
);
1208 if (fd_cwd
!= -1) fcntl( fd_cwd
, F_SETFD
, FD_CLOEXEC
);
1211 serverdir
= wine_get_server_dir();
1213 /* chdir to the server directory */
1214 if (chdir( serverdir
) == -1)
1216 if (errno
!= ENOENT
) fatal_perror( "chdir to %s", serverdir
);
1218 if (chdir( serverdir
) == -1) fatal_perror( "chdir to %s", serverdir
);
1221 /* make sure we are at the right place */
1222 if (stat( ".", &st
) == -1) fatal_perror( "stat %s", serverdir
);
1223 if (st
.st_uid
!= getuid()) fatal_error( "'%s' is not owned by you\n", serverdir
);
1224 if (st
.st_mode
& 077) fatal_error( "'%s' must not be accessible by other users\n", serverdir
);
1226 for (retry
= 0; retry
< 6; retry
++)
1228 /* if not the first try, wait a bit to leave the previous server time to exit */
1231 usleep( 100000 * retry
* retry
);
1233 if (lstat( SOCKETNAME
, &st
) == -1) continue; /* still no socket, wait a bit more */
1235 else if (lstat( SOCKETNAME
, &st
) == -1) /* check for an already existing socket */
1237 if (errno
!= ENOENT
) fatal_perror( "lstat %s/%s", serverdir
, SOCKETNAME
);
1239 if (lstat( SOCKETNAME
, &st
) == -1) continue; /* still no socket, wait a bit more */
1242 /* make sure the socket is sane (ISFIFO needed for Solaris) */
1243 if (!S_ISSOCK(st
.st_mode
) && !S_ISFIFO(st
.st_mode
))
1244 fatal_error( "'%s/%s' is not a socket\n", serverdir
, SOCKETNAME
);
1245 if (st
.st_uid
!= getuid())
1246 fatal_error( "'%s/%s' is not owned by you\n", serverdir
, SOCKETNAME
);
1248 /* try to connect to it */
1249 addr
.sun_family
= AF_UNIX
;
1250 strcpy( addr
.sun_path
, SOCKETNAME
);
1251 slen
= sizeof(addr
) - sizeof(addr
.sun_path
) + strlen(addr
.sun_path
) + 1;
1252 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
1253 addr
.sun_len
= slen
;
1255 if ((s
= socket( AF_UNIX
, SOCK_STREAM
, 0 )) == -1) fatal_perror( "socket" );
1260 setsockopt( s
, SOL_SOCKET
, SO_PASSCRED
, &enable
, sizeof(enable
) );
1263 if (connect( s
, (struct sockaddr
*)&addr
, slen
) != -1)
1265 /* switch back to the starting directory */
1271 fcntl( s
, F_SETFD
, FD_CLOEXEC
);
1276 server_connect_error( serverdir
);
1281 #include <mach/mach.h>
1282 #include <mach/mach_error.h>
1283 #include <servers/bootstrap.h>
1285 /* send our task port to the server */
1286 static void send_server_task_port(void)
1288 mach_port_t bootstrap_port
, wineserver_port
;
1292 mach_msg_header_t header
;
1293 mach_msg_body_t body
;
1294 mach_msg_port_descriptor_t task_port
;
1297 if (task_get_bootstrap_port(mach_task_self(), &bootstrap_port
) != KERN_SUCCESS
) return;
1299 kret
= bootstrap_look_up(bootstrap_port
, (char*)wine_get_server_dir(), &wineserver_port
);
1300 if (kret
!= KERN_SUCCESS
)
1301 fatal_error( "cannot find the server port: 0x%08x\n", kret
);
1303 mach_port_deallocate(mach_task_self(), bootstrap_port
);
1305 msg
.header
.msgh_bits
= MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND
, 0) | MACH_MSGH_BITS_COMPLEX
;
1306 msg
.header
.msgh_size
= sizeof(msg
);
1307 msg
.header
.msgh_remote_port
= wineserver_port
;
1308 msg
.header
.msgh_local_port
= MACH_PORT_NULL
;
1310 msg
.body
.msgh_descriptor_count
= 1;
1311 msg
.task_port
.name
= mach_task_self();
1312 msg
.task_port
.disposition
= MACH_MSG_TYPE_COPY_SEND
;
1313 msg
.task_port
.type
= MACH_MSG_PORT_DESCRIPTOR
;
1315 kret
= mach_msg_send(&msg
.header
);
1316 if (kret
!= KERN_SUCCESS
)
1317 server_protocol_error( "mach_msg_send failed: 0x%08x\n", kret
);
1319 mach_port_deallocate(mach_task_self(), wineserver_port
);
1321 #endif /* __APPLE__ */
1324 /***********************************************************************
1327 * Retrieve the Unix tid to use on the server side for the current thread.
1329 static int get_unix_tid(void)
1332 #ifdef HAVE_PTHREAD_GETTHREADID_NP
1333 ret
= pthread_getthreadid_np();
1334 #elif defined(linux)
1335 ret
= syscall( __NR_gettid
);
1336 #elif defined(__sun)
1337 ret
= pthread_self();
1338 #elif defined(__APPLE__)
1339 ret
= mach_thread_self();
1340 mach_port_deallocate(mach_task_self(), ret
);
1341 #elif defined(__NetBSD__)
1343 #elif defined(__FreeBSD__)
1347 #elif defined(__DragonFly__)
1354 /***********************************************************************
1355 * server_init_process
1357 * Start the server and create the initial socket pair.
1359 void server_init_process(void)
1361 obj_handle_t version
;
1362 const char *env_socket
= getenv( "WINESERVERSOCKET" );
1367 fd_socket
= atoi( env_socket
);
1368 if (fcntl( fd_socket
, F_SETFD
, FD_CLOEXEC
) == -1)
1369 fatal_perror( "Bad server socket %d", fd_socket
);
1370 unsetenv( "WINESERVERSOCKET" );
1374 const char *arch
= getenv( "WINEARCH" );
1376 if (arch
&& strcmp( arch
, "win32" ) && strcmp( arch
, "win64" ))
1377 fatal_error( "WINEARCH set to invalid value '%s', it must be either win32 or win64.\n", arch
);
1379 fd_socket
= server_connect();
1382 /* setup the signal mask */
1383 sigemptyset( &server_block_set
);
1384 sigaddset( &server_block_set
, SIGALRM
);
1385 sigaddset( &server_block_set
, SIGIO
);
1386 sigaddset( &server_block_set
, SIGINT
);
1387 sigaddset( &server_block_set
, SIGHUP
);
1388 sigaddset( &server_block_set
, SIGUSR1
);
1389 sigaddset( &server_block_set
, SIGUSR2
);
1390 sigaddset( &server_block_set
, SIGCHLD
);
1391 pthread_sigmask( SIG_BLOCK
, &server_block_set
, NULL
);
1393 /* receive the first thread request fd on the main socket */
1394 ntdll_get_thread_data()->request_fd
= receive_fd( &version
);
1397 /* now that we hopefully received the server_pid, disable SO_PASSCRED */
1400 setsockopt( fd_socket
, SOL_SOCKET
, SO_PASSCRED
, &enable
, sizeof(enable
) );
1404 if (version
!= SERVER_PROTOCOL_VERSION
)
1405 server_protocol_error( "version mismatch %d/%d.\n"
1406 "Your %s binary was not upgraded correctly,\n"
1407 "or you have an older one somewhere in your PATH.\n"
1408 "Or maybe the wrong wineserver is still running?\n",
1409 version
, SERVER_PROTOCOL_VERSION
,
1410 (version
> SERVER_PROTOCOL_VERSION
) ? "wine" : "wineserver" );
1412 send_server_task_port();
1414 #if defined(__linux__) && defined(HAVE_PRCTL)
1415 /* work around Ubuntu's ptrace breakage */
1416 if (server_pid
!= -1) prctl( 0x59616d61 /* PR_SET_PTRACER */, server_pid
);
1421 /***********************************************************************
1422 * server_init_process_done
1424 NTSTATUS
server_init_process_done(void)
1426 PEB
*peb
= NtCurrentTeb()->Peb
;
1427 IMAGE_NT_HEADERS
*nt
= RtlImageNtHeader( peb
->ImageBaseAddress
);
1430 /* Install signal handlers; this cannot be done earlier, since we cannot
1431 * send exceptions to the debugger before the create process event that
1432 * is sent by REQ_INIT_PROCESS_DONE.
1433 * We do need the handlers in place by the time the request is over, so
1434 * we set them up here. If we segfault between here and the server call
1435 * something is very wrong... */
1436 signal_init_process();
1438 /* Signal the parent process to continue */
1439 SERVER_START_REQ( init_process_done
)
1441 req
->module
= wine_server_client_ptr( peb
->ImageBaseAddress
);
1443 req
->ldt_copy
= wine_server_client_ptr( &wine_ldt_copy
);
1445 req
->entry
= wine_server_client_ptr( (char *)peb
->ImageBaseAddress
+ nt
->OptionalHeader
.AddressOfEntryPoint
);
1446 req
->gui
= (nt
->OptionalHeader
.Subsystem
!= IMAGE_SUBSYSTEM_WINDOWS_CUI
);
1447 status
= wine_server_call( req
);
1455 /***********************************************************************
1456 * server_init_thread
1458 * Send an init thread request. Return 0 if OK.
1460 size_t server_init_thread( void *entry_point
)
1462 static const char *cpu_names
[] = { "x86", "x86_64", "PowerPC", "ARM", "ARM64" };
1463 static const BOOL is_win64
= (sizeof(void *) > sizeof(int));
1464 const char *arch
= getenv( "WINEARCH" );
1467 struct sigaction sig_act
;
1470 sig_act
.sa_handler
= SIG_IGN
;
1471 sig_act
.sa_flags
= 0;
1472 sigemptyset( &sig_act
.sa_mask
);
1474 /* ignore SIGPIPE so that we get an EPIPE error instead */
1475 sigaction( SIGPIPE
, &sig_act
, NULL
);
1477 /* create the server->client communication pipes */
1478 if (server_pipe( reply_pipe
) == -1) server_protocol_perror( "pipe" );
1479 if (server_pipe( ntdll_get_thread_data()->wait_fd
) == -1) server_protocol_perror( "pipe" );
1480 wine_server_send_fd( reply_pipe
[1] );
1481 wine_server_send_fd( ntdll_get_thread_data()->wait_fd
[1] );
1482 ntdll_get_thread_data()->reply_fd
= reply_pipe
[0];
1483 close( reply_pipe
[1] );
1485 SERVER_START_REQ( init_thread
)
1487 req
->unix_pid
= getpid();
1488 req
->unix_tid
= get_unix_tid();
1489 req
->teb
= wine_server_client_ptr( NtCurrentTeb() );
1490 req
->entry
= wine_server_client_ptr( entry_point
);
1491 req
->reply_fd
= reply_pipe
[1];
1492 req
->wait_fd
= ntdll_get_thread_data()->wait_fd
[1];
1493 req
->debug_level
= (TRACE_ON(server
) != 0);
1494 req
->cpu
= client_cpu
;
1495 ret
= wine_server_call( req
);
1496 NtCurrentTeb()->ClientId
.UniqueProcess
= ULongToHandle(reply
->pid
);
1497 NtCurrentTeb()->ClientId
.UniqueThread
= ULongToHandle(reply
->tid
);
1498 info_size
= reply
->info_size
;
1499 server_start_time
= reply
->server_start
;
1500 server_cpus
= reply
->all_cpus
;
1504 is_wow64
= !is_win64
&& (server_cpus
& ((1 << CPU_x86_64
) | (1 << CPU_ARM64
))) != 0;
1505 ntdll_get_thread_data()->wow64_redir
= is_wow64
;
1509 case STATUS_SUCCESS
:
1512 if (!strcmp( arch
, "win32" ) && (is_win64
|| is_wow64
))
1513 fatal_error( "WINEARCH set to win32 but '%s' is a 64-bit installation.\n",
1514 wine_get_config_dir() );
1515 if (!strcmp( arch
, "win64" ) && !is_win64
&& !is_wow64
)
1516 fatal_error( "WINEARCH set to win64 but '%s' is a 32-bit installation.\n",
1517 wine_get_config_dir() );
1520 case STATUS_INVALID_IMAGE_WIN_64
:
1521 fatal_error( "'%s' is a 32-bit installation, it cannot support 64-bit applications.\n",
1522 wine_get_config_dir() );
1523 case STATUS_NOT_SUPPORTED
:
1524 fatal_error( "'%s' is a 64-bit installation, it cannot be used with a 32-bit wineserver.\n",
1525 wine_get_config_dir() );
1526 case STATUS_INVALID_IMAGE_FORMAT
:
1527 fatal_error( "wineserver doesn't support the %s architecture\n", cpu_names
[client_cpu
] );
1529 server_protocol_error( "init_thread failed with status %x\n", ret
);