]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc_r/uthread/uthread_init.c
This commit was generated by cvs2svn to compensate for changes in r133665,
[FreeBSD/FreeBSD.git] / lib / libc_r / uthread / uthread_init.c
1 /*
2  * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by John Birrell.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  */
34
35 /* Allocate space for global thread variables here: */
36 #define GLOBAL_PTHREAD_PRIVATE
37
38 #include "namespace.h"
39 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <machine/reg.h>
42
43 #include <sys/ioctl.h>
44 #include <sys/mount.h>
45 #include <sys/uio.h>
46 #include <sys/socket.h>
47 #include <sys/event.h>
48 #include <sys/stat.h>
49 #include <sys/sysctl.h>
50 #include <sys/time.h>
51 #include <sys/ttycom.h>
52 #include <sys/user.h>
53 #include <sys/wait.h>
54 #include <sys/mman.h>
55 #include <dirent.h>
56 #include <errno.h>
57 #include <fcntl.h>
58 #include <paths.h>
59 #include <poll.h>
60 #include <pthread.h>
61 #include <pthread_np.h>
62 #include <signal.h>
63 #include <stdio.h>
64 #include <stdlib.h>
65 #include <string.h>
66 #include <unistd.h>
67 #include "un-namespace.h"
68
69 #include "libc_private.h"
70 #include "pthread_private.h"
71
72 int     __pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
73 int     __pthread_mutex_lock(pthread_mutex_t *);
74 int     __pthread_mutex_trylock(pthread_mutex_t *);
75
76 /*
77  * All weak references used within libc should be in this table.
78  * This allows static libraries to work.
79  */
80 static void *references[] = {
81         &_accept,
82         &_bind,
83         &_close,
84         &_connect,
85         &_dup,
86         &_dup2,
87         &_execve,
88         &_fcntl,
89         &_flock,
90         &_flockfile,
91         &_fstat,
92         &_fstatfs,
93         &_fsync,
94         &_funlockfile,
95         &_getdirentries,
96         &_getlogin,
97         &_getpeername,
98         &_getsockname,
99         &_getsockopt,
100         &_ioctl,
101         &_kevent,
102         &_listen,
103         &_nanosleep,
104         &_open,
105         &_pthread_cond_destroy,
106         &_pthread_cond_init,
107         &_pthread_cond_signal,
108         &_pthread_cond_wait,
109         &_pthread_getspecific,
110         &_pthread_key_create,
111         &_pthread_key_delete,
112         &_pthread_mutex_destroy,
113         &_pthread_mutex_init,
114         &_pthread_mutex_lock,
115         &_pthread_mutex_trylock,
116         &_pthread_mutex_unlock,
117         &_pthread_mutexattr_init,
118         &_pthread_mutexattr_destroy,
119         &_pthread_mutexattr_settype,
120         &_pthread_once,
121         &_pthread_setspecific,
122         &_read,
123         &_readv,
124         &_recvfrom,
125         &_recvmsg,
126         &_select,
127         &_sendmsg,
128         &_sendto,
129         &_setsockopt,
130         &_sigaction,
131         &_sigprocmask,
132         &_sigsuspend,
133         &_socket,
134         &_socketpair,
135         &_wait4,
136         &_write,
137         &_writev
138 };
139
140 /*
141  * These are needed when linking statically.  All references within
142  * libgcc (and libc) to these routines are weak, but if they are not
143  * (strongly) referenced by the application or other libraries, then
144  * the actual functions will not be loaded.
145  */
146 static void *libgcc_references[] = {
147         &_pthread_once,
148         &_pthread_key_create,
149         &_pthread_key_delete,
150         &_pthread_getspecific,
151         &_pthread_setspecific,
152         &_pthread_mutex_init,
153         &_pthread_mutex_destroy,
154         &_pthread_mutex_lock,
155         &_pthread_mutex_trylock,
156         &_pthread_mutex_unlock
157 };
158
159 #define DUAL_ENTRY(entry)       \
160         (pthread_func_t)entry, (pthread_func_t)entry
161
162 static pthread_func_t jmp_table[][2] = {
163         {DUAL_ENTRY(_pthread_cond_broadcast)},  /* PJT_COND_BROADCAST */
164         {DUAL_ENTRY(_pthread_cond_destroy)},    /* PJT_COND_DESTROY */
165         {DUAL_ENTRY(_pthread_cond_init)},       /* PJT_COND_INIT */
166         {DUAL_ENTRY(_pthread_cond_signal)},     /* PJT_COND_SIGNAL */
167         {(pthread_func_t)__pthread_cond_wait,
168          (pthread_func_t)_pthread_cond_wait},   /* PJT_COND_WAIT */
169         {DUAL_ENTRY(_pthread_getspecific)},     /* PJT_GETSPECIFIC */
170         {DUAL_ENTRY(_pthread_key_create)},      /* PJT_KEY_CREATE */
171         {DUAL_ENTRY(_pthread_key_delete)},      /* PJT_KEY_DELETE*/
172         {DUAL_ENTRY(_pthread_main_np)},         /* PJT_MAIN_NP */
173         {DUAL_ENTRY(_pthread_mutex_destroy)},   /* PJT_MUTEX_DESTROY */
174         {DUAL_ENTRY(_pthread_mutex_init)},      /* PJT_MUTEX_INIT */
175         {(pthread_func_t)__pthread_mutex_lock,
176          (pthread_func_t)_pthread_mutex_lock},  /* PJT_MUTEX_LOCK */
177         {(pthread_func_t)__pthread_mutex_trylock,
178          (pthread_func_t)_pthread_mutex_trylock},/* PJT_MUTEX_TRYLOCK */
179         {DUAL_ENTRY(_pthread_mutex_unlock)},    /* PJT_MUTEX_UNLOCK */
180         {DUAL_ENTRY(_pthread_mutexattr_destroy)}, /* PJT_MUTEXATTR_DESTROY */
181         {DUAL_ENTRY(_pthread_mutexattr_init)},  /* PJT_MUTEXATTR_INIT */
182         {DUAL_ENTRY(_pthread_mutexattr_settype)}, /* PJT_MUTEXATTR_SETTYPE */
183         {DUAL_ENTRY(_pthread_once)},            /* PJT_ONCE */
184         {DUAL_ENTRY(_pthread_rwlock_destroy)},  /* PJT_RWLOCK_DESTROY */
185         {DUAL_ENTRY(_pthread_rwlock_init)},     /* PJT_RWLOCK_INIT */
186         {DUAL_ENTRY(_pthread_rwlock_rdlock)},   /* PJT_RWLOCK_RDLOCK */
187         {DUAL_ENTRY(_pthread_rwlock_tryrdlock)},/* PJT_RWLOCK_TRYRDLOCK */
188         {DUAL_ENTRY(_pthread_rwlock_trywrlock)},/* PJT_RWLOCK_TRYWRLOCK */
189         {DUAL_ENTRY(_pthread_rwlock_unlock)},   /* PJT_RWLOCK_UNLOCK */
190         {DUAL_ENTRY(_pthread_rwlock_wrlock)},   /* PJT_RWLOCK_WRLOCK */
191         {DUAL_ENTRY(_pthread_self)},            /* PJT_SELF */
192         {DUAL_ENTRY(_pthread_setspecific)},     /* PJT_SETSPECIFIC */
193         {DUAL_ENTRY(_pthread_sigmask)}          /* PJT_SIGMASK */
194 };
195
196 int _pthread_guard_default;
197 int _pthread_page_size;
198
199 /*
200  * Threaded process initialization
201  */
202 void
203 _thread_init(void)
204 {
205         int             fd;
206         int             flags;
207         int             i;
208         size_t          len;
209         int             mib[2];
210         int             sched_stack_size;       /* Size of scheduler stack. */
211 #if !defined(__ia64__)
212         u_long          stackp;
213 #endif
214
215         struct clockinfo clockinfo;
216         struct sigaction act;
217
218
219         /* Check if this function has already been called: */
220         if (_thread_initial)
221                 /* Only initialise the threaded application once. */
222                 return;
223
224         _pthread_page_size = getpagesize();;
225         _pthread_guard_default = _pthread_page_size;
226         sched_stack_size = 4 * _pthread_page_size;
227
228         _pthread_attr_default.guardsize_attr = _pthread_guard_default;
229
230         /*
231          * Make gcc quiescent about {,libgcc_}references not being
232          * referenced:
233          */
234         if ((references[0] == NULL) || (libgcc_references[0] == NULL))
235                 PANIC("Failed loading mandatory references in _thread_init");
236
237         /*
238          * Check the size of the jump table to make sure it is preset
239          * with the correct number of entries.
240          */
241         if (sizeof(jmp_table) != (sizeof(pthread_func_t) * PJT_MAX * 2))
242                 PANIC("Thread jump table not properly initialized");
243         memcpy(__thr_jtable, jmp_table, sizeof(jmp_table));
244
245         /*
246          * Check for the special case of this process running as
247          * or in place of init as pid = 1:
248          */
249         if (getpid() == 1) {
250                 /*
251                  * Setup a new session for this process which is
252                  * assumed to be running as root.
253                  */
254                 if (setsid() == -1)
255                         PANIC("Can't set session ID");
256                 if (revoke(_PATH_CONSOLE) != 0)
257                         PANIC("Can't revoke console");
258                 if ((fd = __sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
259                         PANIC("Can't open console");
260                 if (setlogin("root") == -1)
261                         PANIC("Can't set login to root");
262                 if (__sys_ioctl(fd, TIOCSCTTY, (char *) NULL) == -1)
263                         PANIC("Can't set controlling terminal");
264                 if (__sys_dup2(fd, 0) == -1 ||
265                     __sys_dup2(fd, 1) == -1 ||
266                     __sys_dup2(fd, 2) == -1)
267                         PANIC("Can't dup2");
268         }
269
270         /* Get the standard I/O flags before messing with them : */
271         for (i = 0; i < 3; i++) {
272                 if (((_pthread_stdio_flags[i] =
273                     __sys_fcntl(i, F_GETFL, NULL)) == -1) &&
274                     (errno != EBADF))
275                         PANIC("Cannot get stdio flags");
276         }
277
278         /*
279          * Create a pipe that is written to by the signal handler to prevent
280          * signals being missed in calls to _select:
281          */
282         if (__sys_pipe(_thread_kern_pipe) != 0) {
283                 /* Cannot create pipe, so abort: */
284                 PANIC("Cannot create kernel pipe");
285         }
286
287         /*
288          * Make sure the pipe does not get in the way of stdio:
289          */
290         for (i = 0; i < 2; i++) {
291                 if (_thread_kern_pipe[i] < 3) {
292                         fd = __sys_fcntl(_thread_kern_pipe[i], F_DUPFD, 3);
293                         if (fd == -1)
294                             PANIC("Cannot create kernel pipe");
295                         __sys_close(_thread_kern_pipe[i]);
296                         _thread_kern_pipe[i] = fd;
297                 }
298         }
299         /* Get the flags for the read pipe: */
300         if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
301                 /* Abort this application: */
302                 PANIC("Cannot get kernel read pipe flags");
303         }
304         /* Make the read pipe non-blocking: */
305         else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
306                 /* Abort this application: */
307                 PANIC("Cannot make kernel read pipe non-blocking");
308         }
309         /* Get the flags for the write pipe: */
310         else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
311                 /* Abort this application: */
312                 PANIC("Cannot get kernel write pipe flags");
313         }
314         /* Make the write pipe non-blocking: */
315         else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
316                 /* Abort this application: */
317                 PANIC("Cannot get kernel write pipe flags");
318         }
319         /* Allocate and initialize the ready queue: */
320         else if (_pq_alloc(&_readyq, PTHREAD_MIN_PRIORITY, PTHREAD_LAST_PRIORITY) != 0) {
321                 /* Abort this application: */
322                 PANIC("Cannot allocate priority ready queue.");
323         }
324         /* Allocate memory for the thread structure of the initial thread: */
325         else if ((_thread_initial = (pthread_t) malloc(sizeof(struct pthread))) == NULL) {
326                 /*
327                  * Insufficient memory to initialise this application, so
328                  * abort:
329                  */
330                 PANIC("Cannot allocate memory for initial thread");
331         }
332         /* Allocate memory for the scheduler stack: */
333         else if ((_thread_kern_sched_stack = malloc(sched_stack_size)) == NULL)
334                 PANIC("Failed to allocate stack for scheduler");
335         else {
336                 /* Zero the global kernel thread structure: */
337                 memset(&_thread_kern_thread, 0, sizeof(struct pthread));
338                 _thread_kern_thread.flags = PTHREAD_FLAGS_PRIVATE;
339                 memset(_thread_initial, 0, sizeof(struct pthread));
340
341                 /* Initialize the waiting and work queues: */
342                 TAILQ_INIT(&_waitingq);
343                 TAILQ_INIT(&_workq);
344
345                 /* Initialize the scheduling switch hook routine: */
346                 _sched_switch_hook = NULL;
347
348                 /* Give this thread default attributes: */
349                 memcpy((void *) &_thread_initial->attr, &_pthread_attr_default,
350                     sizeof(struct pthread_attr));
351
352                 /* Find the stack top */
353                 mib[0] = CTL_KERN;
354                 mib[1] = KERN_USRSTACK;
355                 len = sizeof (_usrstack);
356                 if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
357                         _usrstack = (void *)USRSTACK;
358                 /*
359                  * Create a red zone below the main stack.  All other stacks are
360                  * constrained to a maximum size by the paramters passed to
361                  * mmap(), but this stack is only limited by resource limits, so
362                  * this stack needs an explicitly mapped red zone to protect the
363                  * thread stack that is just beyond.
364                  */
365                 if (mmap(_usrstack - PTHREAD_STACK_INITIAL -
366                     _pthread_guard_default, _pthread_guard_default, 0,
367                     MAP_ANON, -1, 0) == MAP_FAILED)
368                         PANIC("Cannot allocate red zone for initial thread");
369
370                 /* Set the main thread stack pointer. */
371                 _thread_initial->stack = _usrstack - PTHREAD_STACK_INITIAL;
372
373                 /* Set the stack attributes: */
374                 _thread_initial->attr.stackaddr_attr = _thread_initial->stack;
375                 _thread_initial->attr.stacksize_attr = PTHREAD_STACK_INITIAL;
376
377                 /* Setup the context for the scheduler: */
378                 _setjmp(_thread_kern_sched_jb);
379 #if !defined(__ia64__)
380                 stackp = (long)_thread_kern_sched_stack + sched_stack_size - sizeof(double);
381 #if defined(__amd64__)
382                 stackp &= ~0xFUL;
383 #endif
384                 SET_STACK_JB(_thread_kern_sched_jb, stackp);
385 #else
386                 SET_STACK_JB(_thread_kern_sched_jb, _thread_kern_sched_stack,
387                     sched_stack_size);
388 #endif
389                 SET_RETURN_ADDR_JB(_thread_kern_sched_jb, _thread_kern_scheduler);
390
391                 /*
392                  * Write a magic value to the thread structure
393                  * to help identify valid ones:
394                  */
395                 _thread_initial->magic = PTHREAD_MAGIC;
396
397                 /* Set the initial cancel state */
398                 _thread_initial->cancelflags = PTHREAD_CANCEL_ENABLE |
399                     PTHREAD_CANCEL_DEFERRED;
400
401                 /* Default the priority of the initial thread: */
402                 _thread_initial->base_priority = PTHREAD_DEFAULT_PRIORITY;
403                 _thread_initial->active_priority = PTHREAD_DEFAULT_PRIORITY;
404                 _thread_initial->inherited_priority = 0;
405
406                 /* Initialise the state of the initial thread: */
407                 _thread_initial->state = PS_RUNNING;
408
409                 /* Set the name of the thread: */
410                 _thread_initial->name = strdup("_thread_initial");
411
412                 /* Initialize joiner to NULL (no joiner): */
413                 _thread_initial->joiner = NULL;
414
415                 /* Initialize the owned mutex queue and count: */
416                 TAILQ_INIT(&(_thread_initial->mutexq));
417                 _thread_initial->priority_mutex_count = 0;
418
419                 /* Initialize the global scheduling time: */
420                 _sched_ticks = 0;
421                 gettimeofday((struct timeval *) &_sched_tod, NULL);
422
423                 /* Initialize last active: */
424                 _thread_initial->last_active = (long) _sched_ticks;
425
426                 /* Initialize the initial context: */
427                 _thread_initial->curframe = NULL;
428
429                 /* Initialise the rest of the fields: */
430                 _thread_initial->poll_data.nfds = 0;
431                 _thread_initial->poll_data.fds = NULL;
432                 _thread_initial->sig_defer_count = 0;
433                 _thread_initial->yield_on_sig_undefer = 0;
434                 _thread_initial->specific = NULL;
435                 _thread_initial->cleanup = NULL;
436                 _thread_initial->flags = 0;
437                 _thread_initial->error = 0;
438                 TAILQ_INIT(&_thread_list);
439                 TAILQ_INSERT_HEAD(&_thread_list, _thread_initial, tle);
440                 _set_curthread(_thread_initial);
441
442                 /* Initialise the global signal action structure: */
443                 sigfillset(&act.sa_mask);
444                 act.sa_handler = (void (*) ()) _thread_sig_handler;
445                 act.sa_flags = SA_SIGINFO | SA_RESTART;
446
447                 /* Clear pending signals for the process: */
448                 sigemptyset(&_process_sigpending);
449
450                 /* Clear the signal queue: */
451                 memset(_thread_sigq, 0, sizeof(_thread_sigq));
452
453                 /* Enter a loop to get the existing signal status: */
454                 for (i = 1; i < NSIG; i++) {
455                         /* Check for signals which cannot be trapped: */
456                         if (i == SIGKILL || i == SIGSTOP) {
457                         }
458
459                         /* Get the signal handler details: */
460                         else if (__sys_sigaction(i, NULL,
461                             &_thread_sigact[i - 1]) != 0) {
462                                 /*
463                                  * Abort this process if signal
464                                  * initialisation fails:
465                                  */
466                                 PANIC("Cannot read signal handler info");
467                         }
468
469                         /* Initialize the SIG_DFL dummy handler count. */
470                         _thread_dfl_count[i] = 0;
471                 }
472
473                 /*
474                  * Install the signal handler for the most important
475                  * signals that the user-thread kernel needs. Actually
476                  * SIGINFO isn't really needed, but it is nice to have.
477                  */
478                 if (__sys_sigaction(_SCHED_SIGNAL, &act, NULL) != 0 ||
479                     __sys_sigaction(SIGINFO,       &act, NULL) != 0 ||
480                     __sys_sigaction(SIGCHLD,       &act, NULL) != 0) {
481                         /*
482                          * Abort this process if signal initialisation fails:
483                          */
484                         PANIC("Cannot initialise signal handler");
485                 }
486                 _thread_sigact[_SCHED_SIGNAL - 1].sa_flags = SA_SIGINFO;
487                 _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO;
488                 _thread_sigact[SIGCHLD - 1].sa_flags = SA_SIGINFO;
489
490                 /* Get the process signal mask: */
491                 __sys_sigprocmask(SIG_SETMASK, NULL, &_process_sigmask);
492
493                 /* Get the kernel clockrate: */
494                 mib[0] = CTL_KERN;
495                 mib[1] = KERN_CLOCKRATE;
496                 len = sizeof (struct clockinfo);
497                 if (sysctl(mib, 2, &clockinfo, &len, NULL, 0) == 0)
498                         _clock_res_usec = clockinfo.tick > CLOCK_RES_USEC_MIN ?
499                             clockinfo.tick : CLOCK_RES_USEC_MIN;
500
501                 /* Get the table size: */
502                 if ((_thread_dtablesize = getdtablesize()) < 0) {
503                         /*
504                          * Cannot get the system defined table size, so abort
505                          * this process.
506                          */
507                         PANIC("Cannot get dtablesize");
508                 }
509                 /* Allocate memory for the file descriptor table: */
510                 if ((_thread_fd_table = (struct fd_table_entry **) malloc(sizeof(struct fd_table_entry *) * _thread_dtablesize)) == NULL) {
511                         /* Avoid accesses to file descriptor table on exit: */
512                         _thread_dtablesize = 0;
513
514                         /*
515                          * Cannot allocate memory for the file descriptor
516                          * table, so abort this process.
517                          */
518                         PANIC("Cannot allocate memory for file descriptor table");
519                 }
520                 /* Allocate memory for the pollfd table: */
521                 if ((_thread_pfd_table = (struct pollfd *) malloc(sizeof(struct pollfd) * _thread_dtablesize)) == NULL) {
522                         /*
523                          * Cannot allocate memory for the file descriptor
524                          * table, so abort this process.
525                          */
526                         PANIC("Cannot allocate memory for pollfd table");
527                 } else {
528                         /*
529                          * Enter a loop to initialise the file descriptor
530                          * table:
531                          */
532                         for (i = 0; i < _thread_dtablesize; i++) {
533                                 /* Initialise the file descriptor table: */
534                                 _thread_fd_table[i] = NULL;
535                         }
536
537                         /* Initialize stdio file descriptor table entries: */
538                         for (i = 0; i < 3; i++) {
539                                 if ((_thread_fd_table_init(i) != 0) &&
540                                     (errno != EBADF))
541                                         PANIC("Cannot initialize stdio file "
542                                             "descriptor table entry");
543                         }
544                 }
545         }
546
547         /* Initialise the garbage collector mutex and condition variable. */
548         if (_pthread_mutex_init(&_gc_mutex,NULL) != 0 ||
549             _pthread_cond_init(&_gc_cond,NULL) != 0)
550                 PANIC("Failed to initialise garbage collector mutex or condvar");
551 }
552
553
554 /*
555  * Special start up code for NetBSD/Alpha
556  */
557 #if     defined(__NetBSD__) && defined(__alpha__)
558 int
559 main(int argc, char *argv[], char *env);
560
561 int
562 _thread_main(int argc, char *argv[], char *env)
563 {
564         _thread_init();
565         return (main(argc, argv, env));
566 }
567 #endif