Added wine_pthread_create_thread and wine_pthread_exit_thread to the
[wine/multimedia.git] / dlls / ntdll / sysdeps.c
blob4bb0830e544efb01d4e244cfc1104a25294803b9
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <signal.h>
25 #include <stdio.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
31 #endif
32 #ifdef HAVE_SYS_SYSCALL_H
33 # include <sys/syscall.h>
34 #endif
35 #ifdef HAVE_SYS_LWP_H
36 # include <sys/lwp.h>
37 #endif
38 #ifdef HAVE_UCONTEXT_H
39 # include <ucontext.h>
40 #endif
41 #ifdef HAVE_SYS_MMAN_H
42 #include <sys/mman.h>
43 #endif
44 #ifdef HAVE_SCHED_H
45 #include <sched.h>
46 #endif
48 #include "ntstatus.h"
49 #include "thread.h"
50 #include "wine/pthread.h"
51 #include "wine/server.h"
52 #include "winbase.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 )
66 #if defined(__i386__)
67 /* On the i386, the current thread is in the %fs register */
68 LDT_ENTRY fs_entry;
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 */
76 # ifdef __APPLE__
77 __asm__ __volatile__("mr r13, %0" : : "r" (teb));
78 # else
79 __asm__ __volatile__("mr 2, %0" : : "r" (teb));
80 # endif
81 #elif defined(HAVE__LWP_CREATE)
82 /* On non-i386 Solaris, we use the LWP private pointer */
83 _lwp_setprivate( teb );
84 #endif
85 wine_pthread_init_thread();
89 /***********************************************************************
90 * SYSDEPS_AbortThread
92 * Same as SYSDEPS_ExitThread, but must not do anything that requires a server call.
94 void SYSDEPS_AbortThread( int status )
96 SIGNAL_Block();
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 /***********************************************************************
105 * SYSDEPS_GetUnixTid
107 * Get the Unix tid of the current thread.
109 int SYSDEPS_GetUnixTid(void)
111 #ifdef HAVE__LWP_SELF
112 return _lwp_self();
113 #elif defined(__linux__) && defined(__i386__)
114 int ret;
115 __asm__("int $0x80" : "=a" (ret) : "0" (224) /* SYS_gettid */);
116 if (ret < 0) ret = -1;
117 return ret;
118 #else
119 return -1;
120 #endif
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__)
142 # ifdef __APPLE__
143 __ASM_GLOBAL_FUNC( NtCurrentTeb, "\n\tmr r3,r13\n\tblr" );
144 # else
145 __ASM_GLOBAL_FUNC( NtCurrentTeb, "\n\tmr 3,2\n\tblr" );
146 # endif
147 #else
148 # error NtCurrentTeb not defined for this architecture
149 #endif /* __i386__ */