2 * System-dependent scheduler support
4 * Copyright 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
32 #ifdef HAVE_SYS_SYSCALL_H
33 # include <sys/syscall.h>
38 #ifdef HAVE_UCONTEXT_H
39 # include <ucontext.h>
41 #ifdef HAVE_SYS_MMAN_H
50 #include "wine/pthread.h"
51 #include "wine/server.h"
53 #include "wine/library.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(thread
);
59 /***********************************************************************
60 * SYSDEPS_SetCurThread
62 * Make 'thread' the current thread.
64 void SYSDEPS_SetCurThread( TEB
*teb
)
67 /* On the i386, the current thread is in the %fs register */
70 wine_ldt_set_base( &fs_entry
, teb
);
71 wine_ldt_set_limit( &fs_entry
, 0xfff );
72 wine_ldt_set_flags( &fs_entry
, WINE_LDT_FLAGS_DATA
|WINE_LDT_FLAGS_32BIT
);
73 wine_ldt_init_fs( teb
->teb_sel
, &fs_entry
);
74 #elif defined(__powerpc__)
75 /* On PowerPC, the current TEB is in the gpr13 register */
77 __asm__
__volatile__("mr r13, %0" : : "r" (teb
));
79 __asm__
__volatile__("mr 2, %0" : : "r" (teb
));
81 #elif defined(HAVE__LWP_CREATE)
82 /* On non-i386 Solaris, we use the LWP private pointer */
83 _lwp_setprivate( teb
);
85 wine_pthread_init_thread();
89 /***********************************************************************
92 * Same as SYSDEPS_ExitThread, but must not do anything that requires a server call.
94 void SYSDEPS_AbortThread( int status
)
97 close( NtCurrentTeb()->wait_fd
[0] );
98 close( NtCurrentTeb()->wait_fd
[1] );
99 close( NtCurrentTeb()->reply_fd
);
100 close( NtCurrentTeb()->request_fd
);
101 wine_pthread_abort_thread( status
);
104 /***********************************************************************
107 * Get the Unix tid of the current thread.
109 int SYSDEPS_GetUnixTid(void)
111 #ifdef HAVE__LWP_SELF
113 #elif defined(__linux__) && defined(__i386__)
115 __asm__("int $0x80" : "=a" (ret
) : "0" (224) /* SYS_gettid */);
116 if (ret
< 0) ret
= -1;
123 /**********************************************************************
124 * NtCurrentTeb (NTDLL.@)
126 * This will crash and burn if called before threading is initialized
128 #if defined(__i386__) && defined(__GNUC__)
129 __ASM_GLOBAL_FUNC( NtCurrentTeb
, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" );
130 #elif defined(__i386__) && defined(_MSC_VER)
131 /* Nothing needs to be done. MS C "magically" exports the inline version from winnt.h */
132 #elif defined(HAVE__LWP_CREATE)
133 /***********************************************************************
134 * NtCurrentTeb (NTDLL.@)
136 struct _TEB
* WINAPI
NtCurrentTeb(void)
138 extern void *_lwp_getprivate(void);
139 return (struct _TEB
*)_lwp_getprivate();
141 #elif defined(__powerpc__)
143 __ASM_GLOBAL_FUNC( NtCurrentTeb
, "\n\tmr r3,r13\n\tblr" );
145 __ASM_GLOBAL_FUNC( NtCurrentTeb
, "\n\tmr 3,2\n\tblr" );
148 # error NtCurrentTeb not defined for this architecture
149 #endif /* __i386__ */