Added support for building certain dlls with -DSTRICT.
[wine] / scheduler / client.c
1 /*
2  * Client part of the client/server communication
3  *
4  * Copyright (C) 1998 Alexandre Julliard
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <ctype.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <signal.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <sys/types.h>
32 #ifdef HAVE_SYS_SOCKET_H
33 # include <sys/socket.h>
34 #endif
35 #ifdef HAVE_SYS_WAIT_H
36 #include <sys/wait.h>
37 #endif
38 #include <sys/un.h>
39 #ifdef HAVE_SYS_MMAN_H
40 #include <sys/mman.h>
41 #endif
42 #include <sys/stat.h>
43 #include <sys/uio.h>
44 #ifdef HAVE_UNISTD_H
45 # include <unistd.h>
46 #endif
47 #include <stdarg.h>
48
49 #include "thread.h"
50 #include "wine/library.h"
51 #include "wine/server.h"
52 #include "winerror.h"
53 #include "options.h"
54
55 /* Some versions of glibc don't define this */
56 #ifndef SCM_RIGHTS
57 #define SCM_RIGHTS 1
58 #endif
59
60 #define SOCKETNAME "socket"        /* name of the socket file */
61 #define LOCKNAME   "lock"          /* name of the lock file */
62
63 #ifndef HAVE_MSGHDR_ACCRIGHTS
64 /* data structure used to pass an fd with sendmsg/recvmsg */
65 struct cmsg_fd
66 {
67     int len;   /* sizeof structure */
68     int level; /* SOL_SOCKET */
69     int type;  /* SCM_RIGHTS */
70     int fd;    /* fd to pass */
71 };
72 #endif  /* HAVE_MSGHDR_ACCRIGHTS */
73
74 static DWORD boot_thread_id;
75 static sigset_t block_set;  /* signals to block during server calls */
76 static int fd_socket;  /* socket to exchange file descriptors with the server */
77
78 #ifdef __GNUC__
79 static void fatal_error( const char *err, ... ) __attribute__((noreturn, format(printf,1,2)));
80 static void fatal_perror( const char *err, ... ) __attribute__((noreturn, format(printf,1,2)));
81 static void server_connect_error( const char *serverdir ) __attribute__((noreturn));
82 #endif
83
84 /* die on a fatal error; use only during initialization */
85 static void fatal_error( const char *err, ... )
86 {
87     va_list args;
88
89     va_start( args, err );
90     fprintf( stderr, "wine: " );
91     vfprintf( stderr, err, args );
92     va_end( args );
93     exit(1);
94 }
95
96 /* die on a fatal error; use only during initialization */
97 static void fatal_perror( const char *err, ... )
98 {
99     va_list args;
100
101     va_start( args, err );
102     fprintf( stderr, "wine: " );
103     vfprintf( stderr, err, args );
104     perror( " " );
105     va_end( args );
106     exit(1);
107 }
108
109 /***********************************************************************
110  *           server_protocol_error
111  */
112 void server_protocol_error( const char *err, ... )
113 {
114     va_list args;
115
116     va_start( args, err );
117     fprintf( stderr, "wine client error:%lx: ", NtCurrentTeb()->tid );
118     vfprintf( stderr, err, args );
119     va_end( args );
120     SYSDEPS_AbortThread(1);
121 }
122
123
124 /***********************************************************************
125  *           server_protocol_perror
126  */
127 void server_protocol_perror( const char *err )
128 {
129     fprintf( stderr, "wine client error:%lx: ", NtCurrentTeb()->tid );
130     perror( err );
131     SYSDEPS_AbortThread(1);
132 }
133
134
135 /***********************************************************************
136  *           send_request
137  *
138  * Send a request to the server.
139  */
140 static void send_request( const struct __server_request_info *req )
141 {
142     int i, ret;
143
144     if (!req->u.req.request_header.request_size)
145     {
146         if ((ret = write( NtCurrentTeb()->request_fd, &req->u.req,
147                           sizeof(req->u.req) )) == sizeof(req->u.req)) return;
148
149     }
150     else
151     {
152         struct iovec vec[__SERVER_MAX_DATA+1];
153
154         vec[0].iov_base = (void *)&req->u.req;
155         vec[0].iov_len = sizeof(req->u.req);
156         for (i = 0; i < req->data_count; i++)
157         {
158             vec[i+1].iov_base = (void *)req->data[i].ptr;
159             vec[i+1].iov_len = req->data[i].size;
160         }
161         if ((ret = writev( NtCurrentTeb()->request_fd, vec, i+1 )) ==
162             req->u.req.request_header.request_size + sizeof(req->u.req)) return;
163     }
164
165     if (ret >= 0) server_protocol_error( "partial write %d\n", ret );
166     if (errno == EPIPE) SYSDEPS_AbortThread(0);
167     server_protocol_perror( "sendmsg" );
168 }
169
170
171 /***********************************************************************
172  *           read_reply_data
173  *
174  * Read data from the reply buffer; helper for wait_reply.
175  */
176 static void read_reply_data( void *buffer, size_t size )
177 {
178     int ret;
179
180     for (;;)
181     {
182         if ((ret = read( NtCurrentTeb()->reply_fd, buffer, size )) > 0)
183         {
184             if (!(size -= ret)) return;
185             buffer = (char *)buffer + ret;
186             continue;
187         }
188         if (!ret) break;
189         if (errno == EINTR) continue;
190         if (errno == EPIPE) break;
191         server_protocol_perror("read");
192     }
193     /* the server closed the connection; time to die... */
194     SYSDEPS_AbortThread(0);
195 }
196
197
198 /***********************************************************************
199  *           wait_reply
200  *
201  * Wait for a reply from the server.
202  */
203 inline static void wait_reply( struct __server_request_info *req )
204 {
205     read_reply_data( &req->u.reply, sizeof(req->u.reply) );
206     if (req->u.reply.reply_header.reply_size)
207         read_reply_data( req->reply_data, req->u.reply.reply_header.reply_size );
208 }
209
210
211 /***********************************************************************
212  *           wine_server_call (NTDLL.@)
213  *
214  * Perform a server call.
215  */
216 unsigned int wine_server_call( void *req_ptr )
217 {
218     struct __server_request_info * const req = req_ptr;
219     sigset_t old_set;
220
221     memset( (char *)&req->u.req + req->size, 0, sizeof(req->u.req) - req->size );
222     sigprocmask( SIG_BLOCK, &block_set, &old_set );
223     send_request( req );
224     wait_reply( req );
225     sigprocmask( SIG_SETMASK, &old_set, NULL );
226     return req->u.reply.reply_header.error;
227 }
228
229
230 /***********************************************************************
231  *           wine_server_send_fd
232  *
233  * Send a file descriptor to the server.
234  */
235 void wine_server_send_fd( int fd )
236 {
237 #ifndef HAVE_MSGHDR_ACCRIGHTS
238     struct cmsg_fd cmsg;
239 #endif
240     struct send_fd data;
241     struct msghdr msghdr;
242     struct iovec vec;
243     int ret;
244
245     vec.iov_base = (void *)&data;
246     vec.iov_len  = sizeof(data);
247
248     msghdr.msg_name    = NULL;
249     msghdr.msg_namelen = 0;
250     msghdr.msg_iov     = &vec;
251     msghdr.msg_iovlen  = 1;
252
253 #ifdef HAVE_MSGHDR_ACCRIGHTS
254     msghdr.msg_accrights    = (void *)&fd;
255     msghdr.msg_accrightslen = sizeof(fd);
256 #else  /* HAVE_MSGHDR_ACCRIGHTS */
257     cmsg.len   = sizeof(cmsg);
258     cmsg.level = SOL_SOCKET;
259     cmsg.type  = SCM_RIGHTS;
260     cmsg.fd    = fd;
261     msghdr.msg_control    = &cmsg;
262     msghdr.msg_controllen = sizeof(cmsg);
263     msghdr.msg_flags      = 0;
264 #endif  /* HAVE_MSGHDR_ACCRIGHTS */
265
266     data.tid = GetCurrentThreadId();
267     data.fd  = fd;
268
269     for (;;)
270     {
271         if ((ret = sendmsg( fd_socket, &msghdr, 0 )) == sizeof(data)) return;
272         if (ret >= 0) server_protocol_error( "partial write %d\n", ret );
273         if (errno == EINTR) continue;
274         if (errno == EPIPE) SYSDEPS_AbortThread(0);
275         server_protocol_perror( "sendmsg" );
276     }
277 }
278
279
280 /***********************************************************************
281  *           receive_fd
282  *
283  * Receive a file descriptor passed from the server.
284  */
285 static int receive_fd( obj_handle_t *handle )
286 {
287     struct iovec vec;
288     int ret, fd;
289
290 #ifdef HAVE_MSGHDR_ACCRIGHTS
291     struct msghdr msghdr;
292
293     fd = -1;
294     msghdr.msg_accrights    = (void *)&fd;
295     msghdr.msg_accrightslen = sizeof(fd);
296 #else  /* HAVE_MSGHDR_ACCRIGHTS */
297     struct msghdr msghdr;
298     struct cmsg_fd cmsg;
299
300     cmsg.len   = sizeof(cmsg);
301     cmsg.level = SOL_SOCKET;
302     cmsg.type  = SCM_RIGHTS;
303     cmsg.fd    = -1;
304     msghdr.msg_control    = &cmsg;
305     msghdr.msg_controllen = sizeof(cmsg);
306     msghdr.msg_flags      = 0;
307 #endif  /* HAVE_MSGHDR_ACCRIGHTS */
308
309     msghdr.msg_name    = NULL;
310     msghdr.msg_namelen = 0;
311     msghdr.msg_iov     = &vec;
312     msghdr.msg_iovlen  = 1;
313     vec.iov_base = (void *)handle;
314     vec.iov_len  = sizeof(*handle);
315
316     for (;;)
317     {
318         if ((ret = recvmsg( fd_socket, &msghdr, 0 )) > 0)
319         {
320 #ifndef HAVE_MSGHDR_ACCRIGHTS
321             fd = cmsg.fd;
322 #endif
323             if (fd == -1) server_protocol_error( "no fd received for handle %d\n", *handle );
324             fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */
325             return fd;
326         }
327         if (!ret) break;
328         if (errno == EINTR) continue;
329         if (errno == EPIPE) break;
330         server_protocol_perror("recvmsg");
331     }
332     /* the server closed the connection; time to die... */
333     SYSDEPS_AbortThread(0);
334 }
335
336
337 /***********************************************************************
338  *           store_cached_fd
339  *
340  * Store the cached fd value for a given handle back into the server.
341  * Returns the new fd, which can be different if there was already an
342  * fd in the cache for that handle.
343  */
344 inline static int store_cached_fd( int fd, obj_handle_t handle )
345 {
346     SERVER_START_REQ( set_handle_info )
347     {
348         req->handle = handle;
349         req->flags  = 0;
350         req->mask   = 0;
351         req->fd     = fd;
352         if (!wine_server_call( req ))
353         {
354             if (reply->cur_fd != fd)
355             {
356                 /* someone was here before us */
357                 close( fd );
358                 fd = reply->cur_fd;
359             }
360         }
361         else
362         {
363             close( fd );
364             fd = -1;
365         }
366     }
367     SERVER_END_REQ;
368     return fd;
369 }
370
371
372 /***********************************************************************
373  *           wine_server_fd_to_handle   (NTDLL.@)
374  *
375  * Allocate a file handle for a Unix fd.
376  */
377 int wine_server_fd_to_handle( int fd, unsigned int access, int inherit, obj_handle_t *handle )
378 {
379     int ret;
380
381     *handle = 0;
382     wine_server_send_fd( fd );
383
384     SERVER_START_REQ( alloc_file_handle )
385     {
386         req->access  = access;
387         req->inherit = inherit;
388         req->fd      = fd;
389         if (!(ret = wine_server_call( req ))) *handle = reply->handle;
390     }
391     SERVER_END_REQ;
392     return ret;
393 }
394
395
396 /***********************************************************************
397  *           wine_server_handle_to_fd   (NTDLL.@)
398  *
399  * Retrieve the Unix fd corresponding to a file handle.
400  */
401 int wine_server_handle_to_fd( obj_handle_t handle, unsigned int access, int *unix_fd,
402                               enum fd_type *type, int *flags )
403 {
404     obj_handle_t fd_handle;
405     int ret, fd = -1;
406
407     *unix_fd = -1;
408     for (;;)
409     {
410         SERVER_START_REQ( get_handle_fd )
411         {
412             req->handle = handle;
413             req->access = access;
414             if (!(ret = wine_server_call( req ))) fd = reply->fd;
415             if (type) *type = reply->type;
416             if (flags) *flags = reply->flags;
417         }
418         SERVER_END_REQ;
419         if (ret) return ret;
420
421         if (fd != -1) break;
422
423         /* it wasn't in the cache, get it from the server */
424         fd = receive_fd( &fd_handle );
425         /* and store it back into the cache */
426         fd = store_cached_fd( fd, fd_handle );
427
428         if (fd_handle == handle) break;
429         /* if we received a different handle this means there was
430          * a race with another thread; we restart everything from
431          * scratch in this case.
432          */
433     }
434
435     if ((fd != -1) && ((fd = dup(fd)) == -1)) return STATUS_TOO_MANY_OPENED_FILES;
436     *unix_fd = fd;
437     return STATUS_SUCCESS;
438 }
439
440
441 /***********************************************************************
442  *           start_server
443  *
444  * Start a new wine server.
445  */
446 static void start_server( const char *oldcwd )
447 {
448     static int started;  /* we only try once */
449     char *path, *p;
450     if (!started)
451     {
452         int status;
453         int pid = fork();
454         if (pid == -1) fatal_perror( "fork" );
455         if (!pid)
456         {
457             /* if server is explicitly specified, use this */
458             if ((p = getenv("WINESERVER")))
459             {
460                 if (p[0] != '/' && oldcwd[0] == '/')  /* make it an absolute path */
461                 {
462                     if (!(path = malloc( strlen(oldcwd) + strlen(p) + 1 )))
463                         fatal_error( "out of memory\n" );
464                     sprintf( path, "%s/%s", oldcwd, p );
465                     p = path;
466                 }
467                 execl( p, p, NULL );
468                 fatal_perror( "could not exec the server '%s'\n"
469                               "    specified in the WINESERVER environment variable", p );
470             }
471
472             /* first try the installation dir */
473             execl( BINDIR "/wineserver", "wineserver", NULL );
474
475             /* now try the dir we were launched from */
476             if (full_argv0)
477             {
478                 if (!(path = malloc( strlen(full_argv0) + 20 )))
479                     fatal_error( "out of memory\n" );
480                 if ((p = strrchr( strcpy( path, full_argv0 ), '/' )))
481                 {
482                     strcpy( p, "/wineserver" );
483                     execl( path, path, NULL );
484                 }
485                 free(path);
486             }
487
488             /* finally try the path */
489             execlp( "wineserver", "wineserver", NULL );
490             fatal_error( "could not exec wineserver\n" );
491         }
492         waitpid( pid, &status, 0 );
493         status = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
494         if (status == 2) return;  /* server lock held by someone else, will retry later */
495         if (status) exit(status);  /* server failed */
496         started = 1;
497     }
498 }
499
500
501 /***********************************************************************
502  *           server_connect_error
503  *
504  * Try to display a meaningful explanation of why we couldn't connect
505  * to the server.
506  */
507 static void server_connect_error( const char *serverdir )
508 {
509     int fd;
510     struct flock fl;
511
512     if ((fd = open( LOCKNAME, O_WRONLY )) == -1)
513         fatal_error( "for some mysterious reason, the wine server never started.\n" );
514
515     fl.l_type   = F_WRLCK;
516     fl.l_whence = SEEK_SET;
517     fl.l_start  = 0;
518     fl.l_len    = 1;
519     if (fcntl( fd, F_GETLK, &fl ) != -1)
520     {
521         if (fl.l_type == F_WRLCK)  /* the file is locked */
522             fatal_error( "a wine server seems to be running, but I cannot connect to it.\n"
523                          "   You probably need to kill that process (it might be pid %d).\n",
524                          (int)fl.l_pid );
525         fatal_error( "for some mysterious reason, the wine server failed to run.\n" );
526     }
527     fatal_error( "the file system of '%s' doesn't support locks,\n"
528           "   and there is a 'socket' file in that directory that prevents wine from starting.\n"
529           "   You should make sure no wine server is running, remove that file and try again.\n",
530                  serverdir );
531 }
532
533
534 /***********************************************************************
535  *           server_connect
536  *
537  * Attempt to connect to an existing server socket.
538  * We need to be in the server directory already.
539  */
540 static int server_connect( const char *oldcwd, const char *serverdir )
541 {
542     struct sockaddr_un addr;
543     struct stat st;
544     int s, slen, retry;
545
546     /* chdir to the server directory */
547     if (chdir( serverdir ) == -1)
548     {
549         if (errno != ENOENT) fatal_perror( "chdir to %s", serverdir );
550         start_server( "." );
551         if (chdir( serverdir ) == -1) fatal_perror( "chdir to %s", serverdir );
552     }
553
554     /* make sure we are at the right place */
555     if (stat( ".", &st ) == -1) fatal_perror( "stat %s", serverdir );
556     if (st.st_uid != getuid()) fatal_error( "'%s' is not owned by you\n", serverdir );
557     if (st.st_mode & 077) fatal_error( "'%s' must not be accessible by other users\n", serverdir );
558
559     for (retry = 0; retry < 6; retry++)
560     {
561         /* if not the first try, wait a bit to leave the previous server time to exit */
562         if (retry)
563         {
564             usleep( 100000 * retry * retry );
565             start_server( oldcwd );
566             if (lstat( SOCKETNAME, &st ) == -1) continue;  /* still no socket, wait a bit more */
567         }
568         else if (lstat( SOCKETNAME, &st ) == -1) /* check for an already existing socket */
569         {
570             if (errno != ENOENT) fatal_perror( "lstat %s/%s", serverdir, SOCKETNAME );
571             start_server( oldcwd );
572             if (lstat( SOCKETNAME, &st ) == -1) continue;  /* still no socket, wait a bit more */
573         }
574
575         /* make sure the socket is sane (ISFIFO needed for Solaris) */
576         if (!S_ISSOCK(st.st_mode) && !S_ISFIFO(st.st_mode))
577             fatal_error( "'%s/%s' is not a socket\n", serverdir, SOCKETNAME );
578         if (st.st_uid != getuid())
579             fatal_error( "'%s/%s' is not owned by you\n", serverdir, SOCKETNAME );
580
581         /* try to connect to it */
582         addr.sun_family = AF_UNIX;
583         strcpy( addr.sun_path, SOCKETNAME );
584         slen = sizeof(addr) - sizeof(addr.sun_path) + strlen(addr.sun_path) + 1;
585 #ifdef HAVE_SOCKADDR_SUN_LEN
586         addr.sun_len = slen;
587 #endif
588         if ((s = socket( AF_UNIX, SOCK_STREAM, 0 )) == -1) fatal_perror( "socket" );
589         if (connect( s, (struct sockaddr *)&addr, slen ) != -1)
590         {
591             fcntl( s, F_SETFD, 1 ); /* set close on exec flag */
592             return s;
593         }
594         close( s );
595     }
596     server_connect_error( serverdir );
597 }
598
599
600 /***********************************************************************
601  *           CLIENT_InitServer
602  *
603  * Start the server and create the initial socket pair.
604  */
605 void CLIENT_InitServer(void)
606 {
607     int size;
608     char *oldcwd;
609     obj_handle_t dummy_handle;
610
611     /* retrieve the current directory */
612     for (size = 512; ; size *= 2)
613     {
614         if (!(oldcwd = malloc( size ))) break;
615         if (getcwd( oldcwd, size )) break;
616         free( oldcwd );
617         if (errno == ERANGE) continue;
618         oldcwd = NULL;
619         break;
620     }
621
622     /* if argv[0] is a relative path, make it absolute */
623     full_argv0 = argv0;
624     if (oldcwd && argv0[0] != '/' && strchr( argv0, '/' ))
625     {
626         char *new_argv0 = malloc( strlen(oldcwd) + strlen(argv0) + 2 );
627         if (new_argv0)
628         {
629             strcpy( new_argv0, oldcwd );
630             strcat( new_argv0, "/" );
631             strcat( new_argv0, argv0 );
632             full_argv0 = new_argv0;
633         }
634     }
635
636     /* connect to the server */
637     fd_socket = server_connect( oldcwd, wine_get_server_dir() );
638
639     /* switch back to the starting directory */
640     if (oldcwd)
641     {
642         chdir( oldcwd );
643         free( oldcwd );
644     }
645
646     /* setup the signal mask */
647     sigemptyset( &block_set );
648     sigaddset( &block_set, SIGALRM );
649     sigaddset( &block_set, SIGIO );
650     sigaddset( &block_set, SIGINT );
651     sigaddset( &block_set, SIGHUP );
652
653     /* receive the first thread request fd on the main socket */
654     NtCurrentTeb()->request_fd = receive_fd( &dummy_handle );
655
656     CLIENT_InitThread();
657 }
658
659
660 /***********************************************************************
661  *           CLIENT_InitThread
662  *
663  * Send an init thread request. Return 0 if OK.
664  */
665 void CLIENT_InitThread(void)
666 {
667     TEB *teb = NtCurrentTeb();
668     int version, ret;
669     int reply_pipe[2];
670
671     /* ignore SIGPIPE so that we get a EPIPE error instead  */
672     signal( SIGPIPE, SIG_IGN );
673     /* automatic child reaping to avoid zombies */
674     signal( SIGCHLD, SIG_IGN );
675
676     /* create the server->client communication pipes */
677     if (pipe( reply_pipe ) == -1) server_protocol_perror( "pipe" );
678     if (pipe( teb->wait_fd ) == -1) server_protocol_perror( "pipe" );
679     wine_server_send_fd( reply_pipe[1] );
680     wine_server_send_fd( teb->wait_fd[1] );
681     teb->reply_fd = reply_pipe[0];
682     close( reply_pipe[1] );
683
684     /* set close on exec flag */
685     fcntl( teb->reply_fd, F_SETFD, 1 );
686     fcntl( teb->wait_fd[0], F_SETFD, 1 );
687     fcntl( teb->wait_fd[1], F_SETFD, 1 );
688
689     SERVER_START_REQ( init_thread )
690     {
691         req->unix_pid    = getpid();
692         req->teb         = teb;
693         req->entry       = teb->entry_point;
694         req->reply_fd    = reply_pipe[1];
695         req->wait_fd     = teb->wait_fd[1];
696         ret = wine_server_call( req );
697         teb->pid = reply->pid;
698         teb->tid = reply->tid;
699         version  = reply->version;
700         if (reply->boot) boot_thread_id = teb->tid;
701         else if (boot_thread_id == teb->tid) boot_thread_id = 0;
702     }
703     SERVER_END_REQ;
704
705     if (ret) server_protocol_error( "init_thread failed with status %x\n", ret );
706     if (version != SERVER_PROTOCOL_VERSION)
707         server_protocol_error( "version mismatch %d/%d.\n"
708                                "Your %s binary was not upgraded correctly,\n"
709                                "or you have an older one somewhere in your PATH.\n"
710                                "Or maybe the wrong wineserver is still running?\n",
711                                version, SERVER_PROTOCOL_VERSION,
712                                (version > SERVER_PROTOCOL_VERSION) ? "wine" : "wineserver" );
713 }
714
715
716 /***********************************************************************
717  *           CLIENT_BootDone
718  *
719  * Signal that we have finished booting, and set debug level.
720  */
721 void CLIENT_BootDone( int debug_level )
722 {
723     SERVER_START_REQ( boot_done )
724     {
725         req->debug_level = debug_level;
726         wine_server_call( req );
727     }
728     SERVER_END_REQ;
729 }
730
731
732 /***********************************************************************
733  *           CLIENT_IsBootThread
734  *
735  * Return TRUE if current thread is the boot thread.
736  */
737 int CLIENT_IsBootThread(void)
738 {
739     return (GetCurrentThreadId() == (DWORD)boot_thread_id);
740 }