ntdll: Store the current PEB in a global variable.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-06-15 12:40:01 +02:00
parent 09bb5d949f
commit 588d91aecf
8 changed files with 25 additions and 31 deletions

View File

@ -299,7 +299,7 @@ void dbg_init(void)
if (nb_debug_options == -1) init_options();
options = (struct __wine_debug_channel *)((char *)NtCurrentTeb()->Peb + (is_win64 ? 2 : 1) * page_size);
options = (struct __wine_debug_channel *)((char *)peb + (is_win64 ? 2 : 1) * page_size);
memcpy( options, debug_options, nb_debug_options * sizeof(*options) );
free( debug_options );
debug_options = options;

View File

@ -62,6 +62,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(environ);
PEB *peb = NULL;
USHORT *uctable = NULL, *lctable = NULL;
SIZE_T startup_info_size = 0;
BOOL is_prefix_bootstrap = FALSE;
@ -1996,8 +1997,6 @@ static void *build_wow64_parameters( const RTL_USER_PROCESS_PARAMETERS *params )
*/
static void init_peb( RTL_USER_PROCESS_PARAMETERS *params, void *module )
{
PEB *peb = NtCurrentTeb()->Peb;
peb->ImageBaseAddress = module;
peb->ProcessParameters = params;
peb->OSMajorVersion = 6;

View File

@ -1772,7 +1772,7 @@ static void load_ntdll(void)
/***********************************************************************
* get_image_address
*/
ULONG_PTR get_image_address(void)
static ULONG_PTR get_image_address(void)
{
#ifdef HAVE_GETAUXVAL
ULONG_PTR size, num, phdr_addr = getauxval( AT_PHDR );
@ -1877,6 +1877,7 @@ static void start_main_thread(void)
if (p___wine_main_argc) *p___wine_main_argc = main_argc;
if (p___wine_main_argv) *p___wine_main_argv = main_argv;
if (p___wine_main_wargv) *p___wine_main_wargv = main_wargv;
*(ULONG_PTR *)&peb->CloudFileFlags = get_image_address();
set_load_order_app_name( main_wargv[0] );
init_thread_stack( teb, is_win64 ? 0x7fffffff : 0, 0, 0 );
NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 );

View File

@ -1558,7 +1558,6 @@ size_t server_init_process(void)
*/
void server_init_process_done(void)
{
PEB *peb = NtCurrentTeb()->Peb;
void *entry, *teb;
NTSTATUS status;
int suspend, needs_close, unixdir;
@ -1738,7 +1737,7 @@ NTSTATUS WINAPI NtClose( HANDLE handle )
if (fd != -1) close( fd );
if (ret != STATUS_INVALID_HANDLE || !handle) return ret;
if (!NtCurrentTeb()->Peb->BeingDebugged) return ret;
if (!peb->BeingDebugged) return ret;
if (!NtQueryInformationProcess( NtCurrentProcess(), ProcessDebugPort, &port, sizeof(port), NULL) && port)
{
NtCurrentTeb()->ExceptionCode = ret;

View File

@ -485,7 +485,7 @@ void init_cpu_info(void)
num = 1;
FIXME("Detecting the number of processors is not supported.\n");
#endif
NtCurrentTeb()->Peb->NumberOfProcessors = num;
peb->NumberOfProcessors = num;
get_cpuinfo( &cpu_info );
TRACE( "<- CPU arch %d, level %d, rev %d, features 0x%x\n",
cpu_info.ProcessorArchitecture, cpu_info.ProcessorLevel, cpu_info.ProcessorRevision,
@ -1033,7 +1033,7 @@ static NTSTATUS create_logical_proc_info( SYSTEM_LOGICAL_PROCESSOR_INFORMATION *
if (relation != RelationAll)
FIXME("Relationship filtering not implemented: 0x%x\n", relation);
lcpu_no = NtCurrentTeb()->Peb->NumberOfProcessors;
lcpu_no = peb->NumberOfProcessors;
size = sizeof(pkgs_no);
if (sysctlbyname("hw.packages", &pkgs_no, &size, NULL, 0))
@ -1180,7 +1180,7 @@ static NTSTATUS create_cpuset_info(SYSTEM_CPU_SET_INFORMATION *info)
ULONG64 cpu_mask;
NTSTATUS status;
count = NtCurrentTeb()->Peb->NumberOfProcessors;
count = peb->NumberOfProcessors;
cpu_info_size = 3 * sizeof(*proc_info);
if (!(proc_info_buffer = malloc(cpu_info_size)))
@ -2411,7 +2411,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
{
static int i = 1;
unsigned int n;
cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
cpus = min(peb->NumberOfProcessors, out_cpus);
FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
/* many programs expect these values to change so fake change */
for (n = 0; n < cpus; n++)
@ -2537,7 +2537,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
case SystemInterruptInformation: /* 23 */
{
len = NtCurrentTeb()->Peb->NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
len = peb->NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
if (size >= len)
{
if (!info) ret = STATUS_ACCESS_VIOLATION;
@ -2716,7 +2716,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
/* Each logical processor may use up to 7 entries in returned table:
* core, numa node, package, L1i, L1d, L2, L3 */
len = 7 * NtCurrentTeb()->Peb->NumberOfProcessors;
len = 7 * peb->NumberOfProcessors;
buf = malloc( len * sizeof(*buf) );
if (!buf)
{
@ -2904,7 +2904,7 @@ NTSTATUS WINAPI NtQuerySystemInformationEx( SYSTEM_INFORMATION_CLASS class,
case SystemCpuSetInformation:
{
unsigned int cpu_count = NtCurrentTeb()->Peb->NumberOfProcessors;
unsigned int cpu_count = peb->NumberOfProcessors;
PROCESS_BASIC_INFORMATION pbi;
HANDLE process;
@ -3261,7 +3261,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input,
int i, out_cpus;
if ((output == NULL) || (out_size == 0)) return STATUS_INVALID_PARAMETER;
out_cpus = NtCurrentTeb()->Peb->NumberOfProcessors;
out_cpus = peb->NumberOfProcessors;
if ((out_size / sizeof(PROCESSOR_POWER_INFORMATION)) < out_cpus) return STATUS_BUFFER_TOO_SMALL;
#if defined(linux)
{

View File

@ -1096,7 +1096,7 @@ NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_c
select_op_t select_op;
sigset_t old_set;
if (!NtCurrentTeb()->Peb->BeingDebugged) return 0; /* no debugger present */
if (!peb->BeingDebugged) return 0; /* no debugger present */
pthread_sigmask( SIG_BLOCK, &server_block_set, &old_set );
@ -1906,21 +1906,21 @@ ULONG WINAPI NtGetCurrentProcessorNumber(void)
if (res != -1) return processor;
#endif
if (NtCurrentTeb()->Peb->NumberOfProcessors > 1)
if (peb->NumberOfProcessors > 1)
{
ULONG_PTR thread_mask, processor_mask;
if (!NtQueryInformationThread( GetCurrentThread(), ThreadAffinityMask,
&thread_mask, sizeof(thread_mask), NULL ))
{
for (processor = 0; processor < NtCurrentTeb()->Peb->NumberOfProcessors; processor++)
for (processor = 0; processor < peb->NumberOfProcessors; processor++)
{
processor_mask = (1 << processor);
if (thread_mask & processor_mask)
{
if (thread_mask != processor_mask)
FIXME( "need multicore support (%d processors)\n",
NtCurrentTeb()->Peb->NumberOfProcessors );
peb->NumberOfProcessors );
return processor;
}
}

View File

@ -127,6 +127,7 @@ extern const char *build_dir DECLSPEC_HIDDEN;
extern const char *config_dir DECLSPEC_HIDDEN;
extern const char *user_name DECLSPEC_HIDDEN;
extern const char **dll_paths DECLSPEC_HIDDEN;
extern PEB *peb DECLSPEC_HIDDEN;
extern USHORT *uctable DECLSPEC_HIDDEN;
extern USHORT *lctable DECLSPEC_HIDDEN;
extern SIZE_T startup_info_size DECLSPEC_HIDDEN;
@ -167,7 +168,6 @@ extern NTSTATUS load_main_exe( const WCHAR *name, const char *unix_name, const W
void **module ) DECLSPEC_HIDDEN;
extern NTSTATUS load_start_exe( WCHAR **image, void **module ) DECLSPEC_HIDDEN;
extern void start_server( BOOL debug ) DECLSPEC_HIDDEN;
extern ULONG_PTR get_image_address(void) DECLSPEC_HIDDEN;
extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
extern void server_enter_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;

View File

@ -2688,7 +2688,7 @@ void virtual_init(void)
*/
ULONG_PTR get_system_affinity_mask(void)
{
ULONG num_cpus = NtCurrentTeb()->Peb->NumberOfProcessors;
ULONG num_cpus = peb->NumberOfProcessors;
if (num_cpus >= sizeof(ULONG_PTR) * 8) return ~(ULONG_PTR)0;
return ((ULONG_PTR)1 << num_cpus) - 1;
}
@ -2723,7 +2723,7 @@ void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info )
info->LowestUserAddress = (void *)0x10000;
info->HighestUserAddress = (char *)user_space_limit - 1;
info->ActiveProcessorsAffinityMask = get_system_affinity_mask();
info->NumberOfProcessors = NtCurrentTeb()->Peb->NumberOfProcessors;
info->NumberOfProcessors = peb->NumberOfProcessors;
}
@ -2840,7 +2840,7 @@ NTSTATUS virtual_create_builtin_view( void *module, const UNICODE_STRING *nt_nam
/* set some initial values in a new TEB */
static TEB *init_teb( void *ptr, PEB *peb, BOOL is_wow )
static TEB *init_teb( void *ptr, BOOL is_wow )
{
struct ntdll_thread_data *thread_data;
TEB *teb;
@ -2902,8 +2902,6 @@ static TEB *init_teb( void *ptr, PEB *peb, BOOL is_wow )
*/
TEB *virtual_alloc_first_teb(void)
{
TEB *teb;
PEB *peb;
void *ptr;
NTSTATUS status;
SIZE_T data_size = page_size;
@ -2926,9 +2924,7 @@ TEB *virtual_alloc_first_teb(void)
data_size = 2 * block_size;
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&ptr, 0, &data_size, MEM_COMMIT, PAGE_READWRITE );
peb = (PEB *)((char *)teb_block + 31 * block_size + (is_win64 ? 0 : page_size));
teb = init_teb( ptr, peb, FALSE );
*(ULONG_PTR *)&peb->CloudFileFlags = get_image_address();
return teb;
return init_teb( ptr, FALSE );
}
@ -2969,7 +2965,7 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb )
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&ptr, 0, &block_size,
MEM_COMMIT, PAGE_READWRITE );
}
*ret_teb = teb = init_teb( ptr, NtCurrentTeb()->Peb, !!NtCurrentTeb()->WowTebOffset );
*ret_teb = teb = init_teb( ptr, !!NtCurrentTeb()->WowTebOffset );
server_leave_uninterrupted_section( &virtual_mutex, &sigset );
if ((status = signal_alloc_thread( teb )))
@ -3050,8 +3046,7 @@ NTSTATUS virtual_clear_tls_index( ULONG index )
else
{
index -= TLS_MINIMUM_AVAILABLE;
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
return STATUS_INVALID_PARAMETER;
if (index >= 8 * sizeof(peb->TlsExpansionBitmapBits)) return STATUS_INVALID_PARAMETER;
server_enter_uninterrupted_section( &virtual_mutex, &sigset );
LIST_FOR_EACH_ENTRY( thread_data, &teb_list, struct ntdll_thread_data, entry )
@ -3655,7 +3650,7 @@ void CDECL virtual_release_address_space(void)
void virtual_set_large_address_space(void)
{
/* no large address space on win9x */
if (NtCurrentTeb()->Peb->OSPlatformId != VER_PLATFORM_WIN32_NT) return;
if (peb->OSPlatformId != VER_PLATFORM_WIN32_NT) return;
user_space_limit = working_set_limit = address_space_limit;
}