mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
Updated.
svn path=/trunk/; revision=638
This commit is contained in:
parent
fa74a12186
commit
b0e64d6cf7
2 changed files with 52 additions and 26 deletions
|
@ -21,19 +21,19 @@ thread_main2(LPVOID param)
|
|||
|
||||
int main (void)
|
||||
{
|
||||
DWORD i;
|
||||
DWORD i=0;
|
||||
DWORD id;
|
||||
|
||||
printf("Creating %d threads\n",NR_THREADS);
|
||||
for (i=0;i<NR_THREADS;i++)
|
||||
{
|
||||
printf("Creating %d threads...\n",NR_THREADS);
|
||||
// for (i=0;i<NR_THREADS;i++)
|
||||
// {
|
||||
CreateThread(NULL,
|
||||
0,
|
||||
thread_main1,
|
||||
(LPVOID)i,
|
||||
0,
|
||||
&id);
|
||||
|
||||
#if 0
|
||||
CreateThread(NULL,
|
||||
0,
|
||||
thread_main2,
|
||||
|
@ -41,8 +41,11 @@ int main (void)
|
|||
0,
|
||||
&id);
|
||||
}
|
||||
#endif
|
||||
printf("Threads created...\n");
|
||||
|
||||
Sleep (5000);
|
||||
// Sleep (5000);
|
||||
SuspendThread (GetCurrentThread());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
#include <string.h>
|
||||
#include <internal/i386/segment.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#include <kernel32/kernel32.h>
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
HANDLE STDCALL CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||
|
@ -43,7 +47,6 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
|||
DWORD dwCreationFlags,
|
||||
LPDWORD lpThreadId)
|
||||
{
|
||||
NTSTATUS errCode;
|
||||
HANDLE ThreadHandle;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
CLIENT_ID ClientId;
|
||||
|
@ -51,6 +54,9 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
|||
INITIAL_TEB InitialTeb;
|
||||
BOOLEAN CreateSuspended = FALSE;
|
||||
PVOID BaseAddress;
|
||||
DWORD StackSize;
|
||||
ULONG BytesWritten;
|
||||
NTSTATUS Status;
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
|
@ -70,14 +76,22 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
|||
else
|
||||
CreateSuspended = FALSE;
|
||||
|
||||
StackSize = (dwStackSize == 0) ? 4096 : dwStackSize;
|
||||
|
||||
BaseAddress = 0;
|
||||
ZwAllocateVirtualMemory(hProcess,
|
||||
Status = NtAllocateVirtualMemory(hProcess,
|
||||
&BaseAddress,
|
||||
0,
|
||||
(PULONG)&dwStackSize,
|
||||
(PULONG)&StackSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("Could not allocate stack space!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DPRINT("Stack base address: %p\n", BaseAddress);
|
||||
|
||||
memset(&ThreadContext,0,sizeof(CONTEXT));
|
||||
ThreadContext.Eip = (LONG)lpStartAddress;
|
||||
|
@ -87,11 +101,13 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
|||
ThreadContext.SegDs = USER_DS;
|
||||
ThreadContext.SegCs = USER_CS;
|
||||
ThreadContext.SegSs = USER_DS;
|
||||
ThreadContext.Esp = (ULONG)(BaseAddress + dwStackSize);
|
||||
ThreadContext.Esp = (ULONG)(BaseAddress + StackSize - 8);
|
||||
ThreadContext.EFlags = (1<<1) + (1<<9);
|
||||
|
||||
/* write lpParameter to highest stack address */
|
||||
*((PBYTE)(BaseAddress + StackSize - 4)) = lpParameter;
|
||||
|
||||
errCode = NtCreateThread(&ThreadHandle,
|
||||
Status = NtCreateThread(&ThreadHandle,
|
||||
THREAD_ALL_ACCESS,
|
||||
&ObjectAttributes,
|
||||
hProcess,
|
||||
|
@ -99,6 +115,13 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
|||
&ThreadContext,
|
||||
&InitialTeb,
|
||||
CreateSuspended);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("NtCreateThread() failed!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( lpThreadId != NULL )
|
||||
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
||||
|
||||
|
|
Loading…
Reference in a new issue