Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
7a7ef6a6
Commit
7a7ef6a6
authored
Mar 26, 2008
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32: Moved the allocation of the process stack to ntdll.
parent
c9f0bea9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
58 deletions
+71
-58
process.c
dlls/kernel32/process.c
+2
-45
loader.c
dlls/ntdll/loader.c
+69
-13
No files found.
dlls/kernel32/process.c
View file @
7a7ef6a6
...
...
@@ -52,10 +52,6 @@
#include "wine/unicode.h"
#include "wine/debug.h"
#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
WINE_DEFAULT_DEBUG_CHANNEL
(
process
);
WINE_DECLARE_DEBUG_CHANNEL
(
file
);
WINE_DECLARE_DEBUG_CHANNEL
(
relay
);
...
...
@@ -818,44 +814,6 @@ static HANDLE start_wineboot(void)
/***********************************************************************
* init_stack
*
* Allocate the stack of new process.
*/
static
void
*
init_stack
(
void
)
{
void
*
base
;
SIZE_T
stack_size
,
page_size
=
getpagesize
();
IMAGE_NT_HEADERS
*
nt
=
RtlImageNtHeader
(
NtCurrentTeb
()
->
Peb
->
ImageBaseAddress
);
stack_size
=
max
(
nt
->
OptionalHeader
.
SizeOfStackReserve
,
nt
->
OptionalHeader
.
SizeOfStackCommit
);
stack_size
+=
page_size
;
/* for the guard page */
stack_size
=
(
stack_size
+
0xffff
)
&
~
0xffff
;
/* round to 64K boundary */
if
(
stack_size
<
1024
*
1024
)
stack_size
=
1024
*
1024
;
/* Xlib needs a large stack */
if
(
!
(
base
=
VirtualAlloc
(
NULL
,
stack_size
,
MEM_COMMIT
,
PAGE_READWRITE
)))
{
ERR
(
"failed to allocate main process stack
\n
"
);
ExitProcess
(
1
);
}
/* note: limit is lower than base since the stack grows down */
NtCurrentTeb
()
->
DeallocationStack
=
base
;
NtCurrentTeb
()
->
Tib
.
StackBase
=
(
char
*
)
base
+
stack_size
;
NtCurrentTeb
()
->
Tib
.
StackLimit
=
(
char
*
)
base
+
page_size
;
#ifdef VALGRIND_STACK_REGISTER
/* no need to de-register the stack as it's the one of the main thread */
VALGRIND_STACK_REGISTER
(
NtCurrentTeb
()
->
Tib
.
StackLimit
,
NtCurrentTeb
()
->
Tib
.
StackBase
);
#endif
/* setup guard page */
VirtualProtect
(
base
,
page_size
,
PAGE_NOACCESS
,
NULL
);
return
NtCurrentTeb
()
->
Tib
.
StackBase
;
}
/***********************************************************************
* start_process
*
* Startup routine of a new process. Runs on the new process stack.
...
...
@@ -868,8 +826,6 @@ static void start_process( void *arg )
IMAGE_NT_HEADERS
*
nt
;
LPTHREAD_START_ROUTINE
entry
;
LdrInitializeThunk
(
0
,
0
,
0
,
0
);
nt
=
RtlImageNtHeader
(
peb
->
ImageBaseAddress
);
entry
=
(
LPTHREAD_START_ROUTINE
)((
char
*
)
peb
->
ImageBaseAddress
+
nt
->
OptionalHeader
.
AddressOfEntryPoint
);
...
...
@@ -1000,8 +956,9 @@ void __wine_kernel_init(void)
CloseHandle
(
boot_event
);
}
LdrInitializeThunk
(
0
,
0
,
0
,
0
);
/* switch to the new stack */
wine_switch_to_stack
(
start_process
,
NULL
,
init_stack
()
);
wine_switch_to_stack
(
start_process
,
NULL
,
NtCurrentTeb
()
->
Tib
.
StackBase
);
error:
ExitProcess
(
GetLastError
()
);
...
...
dlls/ntdll/loader.c
View file @
7a7ef6a6
...
...
@@ -24,6 +24,12 @@
#include <assert.h>
#include <stdarg.h>
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#ifdef HAVE_VALGRIND_MEMCHECK_H
# include <valgrind/memcheck.h>
#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
...
...
@@ -2313,6 +2319,65 @@ PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule)
}
/***********************************************************************
* alloc_process_stack
*
* Allocate the stack of new process.
*/
static
NTSTATUS
alloc_process_stack
(
IMAGE_NT_HEADERS
*
nt
)
{
NTSTATUS
status
;
void
*
base
=
NULL
;
SIZE_T
stack_size
,
page_size
=
getpagesize
();
stack_size
=
max
(
nt
->
OptionalHeader
.
SizeOfStackReserve
,
nt
->
OptionalHeader
.
SizeOfStackCommit
);
stack_size
+=
page_size
;
/* for the guard page */
stack_size
=
(
stack_size
+
0xffff
)
&
~
0xffff
;
/* round to 64K boundary */
if
(
stack_size
<
1024
*
1024
)
stack_size
=
1024
*
1024
;
/* Xlib needs a large stack */
if
((
status
=
NtAllocateVirtualMemory
(
GetCurrentProcess
(),
&
base
,
16
,
&
stack_size
,
MEM_COMMIT
,
PAGE_READWRITE
)))
return
status
;
/* note: limit is lower than base since the stack grows down */
NtCurrentTeb
()
->
DeallocationStack
=
base
;
NtCurrentTeb
()
->
Tib
.
StackBase
=
(
char
*
)
base
+
stack_size
;
NtCurrentTeb
()
->
Tib
.
StackLimit
=
(
char
*
)
base
+
page_size
;
#ifdef VALGRIND_STACK_REGISTER
/* no need to de-register the stack as it's the one of the main thread */
VALGRIND_STACK_REGISTER
(
NtCurrentTeb
()
->
Tib
.
StackLimit
,
NtCurrentTeb
()
->
Tib
.
StackBase
);
#endif
/* setup guard page */
NtProtectVirtualMemory
(
GetCurrentProcess
(),
&
base
,
&
page_size
,
PAGE_NOACCESS
,
NULL
);
return
STATUS_SUCCESS
;
}
/***********************************************************************
* attach_process_dlls
*
* Initial attach to all the dlls loaded by the process.
*/
static
NTSTATUS
attach_process_dlls
(
void
*
wm
)
{
NTSTATUS
status
;
RtlEnterCriticalSection
(
&
loader_section
);
if
((
status
=
process_attach
(
wm
,
(
LPVOID
)
1
))
!=
STATUS_SUCCESS
)
{
if
(
last_failed_modref
)
ERR
(
"%s failed to initialize, aborting
\n
"
,
debugstr_w
(
last_failed_modref
->
ldr
.
BaseDllName
.
Buffer
)
+
1
);
return
status
;
}
attach_implicitly_loaded_dlls
(
(
LPVOID
)
1
);
RtlLeaveCriticalSection
(
&
loader_section
);
return
status
;
}
/******************************************************************
* LdrInitializeThunk (NTDLL.@)
*
...
...
@@ -2344,8 +2409,8 @@ void WINAPI LdrInitializeThunk( ULONG unknown1, ULONG unknown2, ULONG unknown3,
RemoveEntryList
(
&
wm
->
ldr
.
InLoadOrderModuleList
);
InsertHeadList
(
&
peb
->
LdrData
->
InLoadOrderModuleList
,
&
wm
->
ldr
.
InLoadOrderModuleList
);
status
=
server_init_process_done
()
;
if
(
status
!=
STATUS_SUCCESS
)
goto
error
;
if
((
status
=
alloc_process_stack
(
nt
))
!=
STATUS_SUCCESS
)
goto
error
;
if
(
(
status
=
server_init_process_done
())
!=
STATUS_SUCCESS
)
goto
error
;
actctx_init
();
load_path
=
NtCurrentTeb
()
->
Peb
->
ProcessParameters
->
DllPath
.
Buffer
;
...
...
@@ -2355,17 +2420,8 @@ void WINAPI LdrInitializeThunk( ULONG unknown1, ULONG unknown2, ULONG unknown3,
pthread_functions
.
sigprocmask
(
SIG_UNBLOCK
,
&
server_block_set
,
NULL
);
RtlEnterCriticalSection
(
&
loader_section
);
if
((
status
=
process_attach
(
wm
,
(
LPVOID
)
1
))
!=
STATUS_SUCCESS
)
{
if
(
last_failed_modref
)
ERR
(
"%s failed to initialize, aborting
\n
"
,
debugstr_w
(
last_failed_modref
->
ldr
.
BaseDllName
.
Buffer
)
+
1
);
goto
error
;
}
attach_implicitly_loaded_dlls
(
(
LPVOID
)
1
);
RtlLeaveCriticalSection
(
&
loader_section
);
status
=
wine_call_on_stack
(
attach_process_dlls
,
wm
,
NtCurrentTeb
()
->
Tib
.
StackBase
);
if
(
status
!=
STATUS_SUCCESS
)
goto
error
;
if
(
nt
->
FileHeader
.
Characteristics
&
IMAGE_FILE_LARGE_ADDRESS_AWARE
)
VIRTUAL_UseLargeAddressSpace
();
return
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment