Commit e84ec36a authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Move the thread get/set information functions to the Unix library.

parent 44a23093
......@@ -3629,8 +3629,6 @@ void WINAPI LdrShutdownThread(void)
RtlAcquirePebLock();
RemoveEntryList( &NtCurrentTeb()->TlsLinks );
RtlReleasePebLock();
if ((pointers = NtCurrentTeb()->ThreadLocalStoragePointer))
{
for (i = 0; i < tls_module_count; i++) RtlFreeHeap( GetProcessHeap(), 0, pointers[i] );
......@@ -3638,6 +3636,9 @@ void WINAPI LdrShutdownThread(void)
}
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots );
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots );
NtCurrentTeb()->TlsExpansionSlots = NULL;
RtlReleasePebLock();
RtlLeaveCriticalSection( &loader_section );
}
......
......@@ -55,7 +55,6 @@ struct drive_info
};
extern NTSTATUS close_handle( HANDLE ) DECLSPEC_HIDDEN;
extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
/* exceptions */
extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) DECLSPEC_HIDDEN;
......
......@@ -85,13 +85,6 @@ HANDLE CDECL __wine_make_process_system(void)
return ret;
}
ULONG_PTR get_system_affinity_mask(void)
{
ULONG num_cpus = NtCurrentTeb()->Peb->NumberOfProcessors;
if (num_cpus >= sizeof(ULONG_PTR) * 8) return ~(ULONG_PTR)0;
return ((ULONG_PTR)1 << num_cpus) - 1;
}
/******************************************************************************
* NtQueryInformationProcess [NTDLL.@]
* ZwQueryInformationProcess [NTDLL.@]
......
......@@ -868,6 +868,7 @@ static struct unix_funcs unix_funcs =
NtFreeVirtualMemory,
NtFsControlFile,
NtGetContextThread,
NtGetCurrentProcessorNumber,
NtGetWriteWatch,
NtIsProcessInJob,
NtLockVirtualMemory,
......@@ -892,6 +893,7 @@ static struct unix_funcs unix_funcs =
NtQueryInformationFile,
NtQueryInformationJobObject,
NtQueryInformationProcess,
NtQueryInformationThread,
NtQueryIoCompletion,
NtQueryMutant,
NtQueryPerformanceCounter,
......@@ -919,6 +921,7 @@ static struct unix_funcs unix_funcs =
NtSetInformationFile,
NtSetInformationJobObject,
NtSetInformationProcess,
NtSetInformationThread,
NtSetIoCompletion,
NtSetLdtEntries,
NtSetSystemTime,
......@@ -975,7 +978,6 @@ static struct unix_funcs unix_funcs =
init_threading,
exit_thread,
exit_process,
get_thread_ldt_entry,
exec_process,
wine_server_call,
server_send_fd,
......
......@@ -781,7 +781,7 @@ static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext )
/**********************************************************************
* get_thread_ldt_entry
*/
NTSTATUS CDECL get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
{
return STATUS_NOT_IMPLEMENTED;
}
......
......@@ -695,7 +695,7 @@ static void usr2_handler( int signal, siginfo_t *siginfo, void *sigcontext )
/**********************************************************************
* get_thread_ldt_entry
*/
NTSTATUS CDECL get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
{
return STATUS_NOT_IMPLEMENTED;
}
......
......@@ -2039,7 +2039,7 @@ static void ldt_set_fs( WORD sel, TEB *teb )
/**********************************************************************
* get_thread_ldt_entry
*/
NTSTATUS CDECL get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
{
THREAD_DESCRIPTOR_INFORMATION *info = data;
NTSTATUS status = STATUS_SUCCESS;
......
......@@ -1245,7 +1245,7 @@ static void usr1_handler( int signal, siginfo_t *siginfo, void *ucontext )
/**********************************************************************
* get_thread_ldt_entry
*/
NTSTATUS CDECL get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
{
return STATUS_NOT_IMPLEMENTED;
}
......
......@@ -22,6 +22,7 @@
#define __NTDLL_UNIX_PRIVATE_H
#include "unixlib.h"
#include "wine/list.h"
#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
#define InterlockedCompareExchange64(dest,xchg,cmp) RtlInterlockedCompareExchange64(dest,xchg,cmp)
......@@ -45,6 +46,7 @@ struct ntdll_thread_data
int wait_fd[2]; /* fd for sleeping server requests */
BOOL wow64_redir; /* Wow64 filesystem redirection flag */
pthread_t pthread_id; /* pthread thread id */
struct list entry; /* entry in TEB list */
};
C_ASSERT( sizeof(struct ntdll_thread_data) <= sizeof(((TEB *)0)->GdiTebBatch) );
......@@ -113,7 +115,6 @@ extern TEB * CDECL init_threading( int *nb_threads_ptr, struct ldt_copy **ldt_co
timeout_t *start_time ) DECLSPEC_HIDDEN;
extern void CDECL DECLSPEC_NORETURN exit_thread( int status ) DECLSPEC_HIDDEN;
extern void CDECL DECLSPEC_NORETURN exit_process( int status ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
......@@ -173,6 +174,7 @@ extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
extern TEB *virtual_alloc_first_teb(void) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_alloc_teb( TEB **ret_teb ) DECLSPEC_HIDDEN;
extern void virtual_free_teb( TEB *teb ) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_clear_tls_index( ULONG index ) DECLSPEC_HIDDEN;
extern void virtual_map_user_shared_data(void) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err, BOOL on_signal_stack ) DECLSPEC_HIDDEN;
extern unsigned int virtual_locked_server_call( void *req_ptr ) DECLSPEC_HIDDEN;
......@@ -188,6 +190,7 @@ extern void virtual_set_force_exec( BOOL enable ) DECLSPEC_HIDDEN;
extern void virtual_fill_image_information( const pe_image_info_t *pe_info,
SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
extern NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) DECLSPEC_HIDDEN;
extern void signal_init_threading(void) DECLSPEC_HIDDEN;
extern NTSTATUS signal_alloc_thread( TEB *teb ) DECLSPEC_HIDDEN;
extern void signal_free_thread( TEB *teb ) DECLSPEC_HIDDEN;
......
......@@ -170,6 +170,7 @@ static SIZE_T signal_stack_align;
static TEB *teb_block;
static TEB *next_free_teb;
static int teb_block_pos;
static struct list teb_list = LIST_INIT( teb_list );
#define ROUND_ADDR(addr,mask) ((void *)((UINT_PTR)(addr) & ~(UINT_PTR)(mask)))
#define ROUND_SIZE(addr,size) (((SIZE_T)(size) + ((UINT_PTR)(addr) & page_mask) + page_mask) & ~page_mask)
......@@ -2537,6 +2538,25 @@ NTSTATUS CDECL virtual_create_builtin_view( void *module )
}
/* set some initial values in a new TEB */
static void init_teb( TEB *teb, PEB *peb )
{
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)&teb->GdiTebBatch;
teb->Peb = peb;
teb->Tib.Self = &teb->Tib;
teb->Tib.ExceptionList = (void *)~0ul;
teb->Tib.StackBase = (void *)~0ul;
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
thread_data->request_fd = -1;
thread_data->reply_fd = -1;
thread_data->wait_fd[0] = -1;
thread_data->wait_fd[1] = -1;
list_add_head( &teb_list, &thread_data->entry );
}
/***********************************************************************
* virtual_alloc_first_teb
*/
......@@ -2566,13 +2586,7 @@ TEB *virtual_alloc_first_teb(void)
peb = (PEB *)((char *)teb_block + 32 * teb_size - peb_size);
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&teb, 0, &teb_size, MEM_COMMIT, PAGE_READWRITE );
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&peb, 0, &peb_size, MEM_COMMIT, PAGE_READWRITE );
teb->Peb = peb;
teb->Tib.Self = &teb->Tib;
teb->Tib.ExceptionList = (void *)~0ul;
teb->Tib.StackBase = (void *)~0ul;
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
init_teb( teb, peb );
use_locks = TRUE;
return teb;
}
......@@ -2615,14 +2629,10 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb )
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&teb, 0, &teb_size,
MEM_COMMIT, PAGE_READWRITE );
}
init_teb( teb, NtCurrentTeb()->Peb );
*ret_teb = teb;
server_leave_uninterrupted_section( &csVirtual, &sigset );
*ret_teb = teb;
teb->Peb = NtCurrentTeb()->Peb;
teb->Tib.Self = &teb->Tib;
teb->Tib.ExceptionList = (void *)~0UL;
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
if ((status = signal_alloc_thread( teb )))
{
server_enter_uninterrupted_section( &csVirtual, &sigset );
......@@ -2656,6 +2666,7 @@ void virtual_free_teb( TEB *teb )
}
server_enter_uninterrupted_section( &csVirtual, &sigset );
list_remove( &thread_data->entry );
*(TEB **)teb = next_free_teb;
next_free_teb = teb;
server_leave_uninterrupted_section( &csVirtual, &sigset );
......@@ -2663,6 +2674,42 @@ void virtual_free_teb( TEB *teb )
/***********************************************************************
* virtual_clear_tls_index
*/
NTSTATUS virtual_clear_tls_index( ULONG index )
{
struct ntdll_thread_data *thread_data;
sigset_t sigset;
if (index < TLS_MINIMUM_AVAILABLE)
{
server_enter_uninterrupted_section( &csVirtual, &sigset );
LIST_FOR_EACH_ENTRY( thread_data, &teb_list, struct ntdll_thread_data, entry )
{
TEB *teb = CONTAINING_RECORD( thread_data, TEB, GdiTebBatch );
teb->TlsSlots[index] = 0;
}
server_leave_uninterrupted_section( &csVirtual, &sigset );
}
else
{
index -= TLS_MINIMUM_AVAILABLE;
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
return STATUS_INVALID_PARAMETER;
server_enter_uninterrupted_section( &csVirtual, &sigset );
LIST_FOR_EACH_ENTRY( thread_data, &teb_list, struct ntdll_thread_data, entry )
{
TEB *teb = CONTAINING_RECORD( thread_data, TEB, GdiTebBatch );
if (teb->TlsExpansionSlots) teb->TlsExpansionSlots[index] = 0;
}
server_leave_uninterrupted_section( &csVirtual, &sigset );
}
return STATUS_SUCCESS;
}
/***********************************************************************
* virtual_alloc_thread_stack
*/
NTSTATUS CDECL virtual_alloc_thread_stack( INITIAL_TEB *stack, SIZE_T reserve_size, SIZE_T commit_size, SIZE_T *pthread_size )
......
......@@ -28,7 +28,7 @@ struct ldt_copy;
struct msghdr;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 53
#define NTDLL_UNIXLIB_VERSION 54
struct unix_funcs
{
......@@ -105,6 +105,7 @@ struct unix_funcs
void *in_buffer, ULONG in_size,
void *out_buffer, ULONG out_size );
NTSTATUS (WINAPI *NtGetContextThread)( HANDLE handle, CONTEXT *context );
ULONG (WINAPI *NtGetCurrentProcessorNumber)(void);
NTSTATUS (WINAPI *NtGetWriteWatch)( HANDLE process, ULONG flags, PVOID base, SIZE_T size,
PVOID *addresses, ULONG_PTR *count, ULONG *granularity );
NTSTATUS (WINAPI *NtIsProcessInJob)( HANDLE process, HANDLE job );
......@@ -154,6 +155,8 @@ struct unix_funcs
void *info, ULONG len, ULONG *ret_len );
NTSTATUS (WINAPI *NtQueryInformationProcess)( HANDLE handle, PROCESSINFOCLASS class, void *info,
ULONG size, ULONG *ret_len );
NTSTATUS (WINAPI *NtQueryInformationThread)( HANDLE handle, THREADINFOCLASS class,
void *data, ULONG length, ULONG *ret_len );
NTSTATUS (WINAPI *NtQueryIoCompletion)( HANDLE handle, IO_COMPLETION_INFORMATION_CLASS class,
void *buffer, ULONG len, ULONG *ret_len );
NTSTATUS (WINAPI *NtQueryMutant)( HANDLE handle, MUTANT_INFORMATION_CLASS class,
......@@ -202,6 +205,8 @@ struct unix_funcs
void *info, ULONG len );
NTSTATUS (WINAPI *NtSetInformationProcess)( HANDLE handle, PROCESSINFOCLASS class,
void *info, ULONG size );
NTSTATUS (WINAPI *NtSetInformationThread)( HANDLE handle, THREADINFOCLASS class,
const void *data, ULONG length );
NTSTATUS (WINAPI *NtSetIoCompletion)( HANDLE handle, ULONG_PTR key, ULONG_PTR value,
NTSTATUS status, SIZE_T count );
NTSTATUS (WINAPI *NtSetLdtEntries)( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_ENTRY entry2 );
......@@ -291,7 +296,6 @@ struct unix_funcs
BOOL *suspend, unsigned int *cpus, BOOL *wow64, timeout_t *start_time );
void (CDECL *exit_thread)( int status );
void (CDECL *exit_process)( int status );
NTSTATUS (CDECL *get_thread_ldt_entry)( HANDLE handle, void *data, ULONG len, ULONG *ret_len );
NTSTATUS (CDECL *exec_process)( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status );
/* server functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment