2 * System-dependent scheduler support
4 * Copyright 1998 Alexandre Julliard
7 /* Get pointers to the static errno and h_errno variables used by Xlib. This
8 must be done before including <errno.h> makes the variables invisible. */
10 static int *perrno
= &errno
;
12 static int *ph_errno
= &h_errno
;
22 /* Xlib critical section (FIXME: does not belong here) */
23 CRITICAL_SECTION X11DRV_CritSection
= { 0, };
25 #ifdef HAVE_CLONE_SYSCALL
30 # define CLONE_VM 0x00000100
31 # define CLONE_FS 0x00000200
32 # define CLONE_FILES 0x00000400
33 # define CLONE_SIGHAND 0x00000800
34 # define CLONE_PID 0x00001000
35 /* If we didn't get the flags, we probably didn't get the prototype either */
36 extern int clone( int (*fn
)(void *arg
), void *stack
, int flags
, void *arg
);
37 # endif /* CLONE_VM */
38 #endif /* HAVE_CLONE_SYSCALL */
42 /***********************************************************************
45 * Get the per-thread errno location.
47 int *__errno_location()
49 THDB
*thdb
= THREAD_Current();
50 if (!thdb
) return perrno
;
51 #ifdef NO_REENTRANT_X11
52 /* Use static libc errno while running in Xlib. */
53 if (X11DRV_CritSection
.OwningThread
== (HANDLE
)thdb
->server_tid
)
56 return &thdb
->thread_errno
;
59 /***********************************************************************
62 * Get the per-thread h_errno location.
64 int *__h_errno_location()
66 THDB
*thdb
= THREAD_Current();
67 if (!thdb
) return ph_errno
;
68 #ifdef NO_REENTRANT_X11
69 /* Use static libc h_errno while running in Xlib. */
70 if (X11DRV_CritSection
.OwningThread
== (HANDLE
)thdb
->server_tid
)
73 return &thdb
->thread_h_errno
;
76 /***********************************************************************
79 * Startup routine for a new thread.
81 static void SYSDEPS_StartThread( THDB
*thdb
)
83 SET_CUR_THREAD( thdb
);
86 _exit(0); /* should never get here */
88 #endif /* USE_THREADS */
91 /***********************************************************************
94 * Start running a new thread.
95 * Return -1 on error, 0 if OK.
97 int SYSDEPS_SpawnThread( THDB
*thread
)
101 #ifdef HAVE_CLONE_SYSCALL
102 if (clone( (int (*)(void *))SYSDEPS_StartThread
, thread
->teb
.stack_top
,
103 CLONE_VM
| CLONE_FS
| CLONE_FILES
| SIGCHLD
, thread
) < 0)
105 /* FIXME: close the child socket in the parent process */
106 /* close( thread->socket );*/
110 FIXME(thread
, "Threads using rfork() not implemented\n" );
113 #else /* !USE_THREADS */
114 FIXME(thread
, "CreateThread: stub\n" );
115 #endif /* USE_THREADS */
120 /***********************************************************************
123 * Exit a running thread; must not return.
124 * Must not make any reference to the thread structures (THDB etc.) as
125 * they have already been deleted.
127 void SYSDEPS_ExitThread(void)
133 /**********************************************************************
134 * NtCurrentTeb (NTDLL.89)
136 * This will crash and burn if called before threading is initialized
138 TEB
* WINAPI
NtCurrentTeb(void)
143 /* Get the TEB self-pointer */
144 __asm__( ".byte 0x64\n\tmovl (%1),%0"
145 : "=r" (teb
) : "r" (&((TEB
*)0)->self
) );
148 return &pCurrentThread
->teb
;
149 #endif /* __i386__ */