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
;
20 /* FIXME: X libs compiled w/o -D_REENTRANT should be detected by autoconf. */
21 #define NO_REENTRANT_X11
23 #ifdef NO_REENTRANT_X11
24 /* Xlib critical section (FIXME: does not belong here) */
25 CRITICAL_SECTION X11DRV_CritSection
= { 0, };
33 # define CLONE_VM 0x00000100
34 # define CLONE_FS 0x00000200
35 # define CLONE_FILES 0x00000400
36 # define CLONE_SIGHAND 0x00000800
37 # define CLONE_PID 0x00001000
38 /* If we didn't get the flags, we probably didn't get the prototype either */
39 extern int clone( int (*fn
)(void *arg
), void *stack
, int flags
, void *arg
);
40 # endif /* CLONE_VM */
41 #endif /* __linux__ */
45 /***********************************************************************
48 * Get the per-thread errno location.
50 int *__errno_location()
52 THDB
*thdb
= THREAD_Current();
53 if (!thdb
) return perrno
;
54 #ifdef NO_REENTRANT_X11
55 /* Use static libc errno while running in Xlib. */
56 if (X11DRV_CritSection
.OwningThread
== THDB_TO_THREAD_ID(thdb
))
59 return &thdb
->thread_errno
;
62 /***********************************************************************
65 * Get the per-thread h_errno location.
67 int *__h_errno_location()
69 THDB
*thdb
= THREAD_Current();
70 if (!thdb
) return ph_errno
;
71 #ifdef NO_REENTRANT_X11
72 /* Use static libc h_errno while running in Xlib. */
73 if (X11DRV_CritSection
.OwningThread
== THDB_TO_THREAD_ID(thdb
))
76 return &thdb
->thread_h_errno
;
79 /***********************************************************************
82 * Startup routine for a new thread.
84 static void SYSDEPS_StartThread( THDB
*thdb
)
86 LPTHREAD_START_ROUTINE func
= (LPTHREAD_START_ROUTINE
)thdb
->entry_point
;
87 thdb
->unix_pid
= getpid();
88 SET_FS( thdb
->teb_sel
);
89 ExitThread( func( thdb
->entry_arg
) );
91 #endif /* __linux__ */
94 /***********************************************************************
97 * Start running a new thread.
98 * Return -1 on error, 0 if OK.
100 int SYSDEPS_SpawnThread( THDB
*thread
)
103 if (clone( (int (*)(void *))SYSDEPS_StartThread
, thread
->teb
.stack_top
,
104 CLONE_VM
| CLONE_FS
| CLONE_FILES
| SIGCHLD
, thread
) < 0)
107 fprintf( stderr
, "CreateThread: stub\n" );
108 #endif /* __linux__ */
113 /***********************************************************************
116 * Exit a running thread; must not return.
118 void SYSDEPS_ExitThread(void)
124 /**********************************************************************
125 * NtCurrentTeb (NTDLL.89)
127 TEB
* WINAPI
NtCurrentTeb(void)
133 /* Check if we have a current thread */
135 if (!fs
) return NULL
;
137 if (fs
== ds
) return NULL
; /* FIXME: should be an assert */
138 /* Get the TEB self-pointer */
139 __asm__( ".byte 0x64\n\tmovl (%1),%0"
140 : "=r" (teb
) : "r" (&((TEB
*)0)->self
) );
143 if (!pCurrentThread
) return NULL
;
144 return &pCurrentThread
->teb
;
145 #endif /* __i386__ */