mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Changed kernel32 to compile as a dll
svn path=/trunk/; revision=338
This commit is contained in:
parent
00f2fc414e
commit
3f0a7424cb
20 changed files with 1182 additions and 1814 deletions
|
@ -10,8 +10,6 @@ int mainCRTStartup(PWSTR args)
|
||||||
{
|
{
|
||||||
int nRet;
|
int nRet;
|
||||||
|
|
||||||
KERNEL32_Init(args);
|
|
||||||
|
|
||||||
// SetUnhandledExceptionFilter(NULL);
|
// SetUnhandledExceptionFilter(NULL);
|
||||||
|
|
||||||
// _fpreset();
|
// _fpreset();
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
all: args.bin
|
all: args.exe
|
||||||
|
|
||||||
OBJECTS= ../common/crt0.o args.o
|
OBJECTS= ../common/crt0.o args.o
|
||||||
LIBS= ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a
|
LIBS= ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a
|
||||||
|
|
||||||
args.bin: $(OBJECTS) $(LIBS)
|
args.exe: $(OBJECTS) $(LIBS)
|
||||||
$(CC) -specs=../../specs -Ttext 0x10000 $(OBJECTS) $(LIBS) -lgcc \
|
$(CC) -specs=../../specs $(OBJECTS) $(LIBS) -lgcc -o args.exe
|
||||||
-o args.exe
|
|
||||||
$(NM) --numeric-sort args.exe > args.sym
|
$(NM) --numeric-sort args.exe > args.sym
|
||||||
../../ntoskrnl/utils/pe2bin/pe2bin$(EXE_POSTFIX) 0x10000 args.exe \
|
|
||||||
args.bin
|
include ../../rules.mak
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
#include <ddk/ntddk.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
void main()
|
|
||||||
{
|
{
|
||||||
NtDisplayString("Hello world\n");
|
printf("Hello world\n");
|
||||||
ExitProcess(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
all: hello.bin
|
all: hello.exe
|
||||||
|
|
||||||
OBJECTS = ../common/crt0.o hello.o
|
OBJECTS = hello.o
|
||||||
|
|
||||||
hello.bin: $(OBJECTS)
|
hello.exe: $(OBJECTS) $(LIBS)
|
||||||
$(LD) -Ttext 0x10000 $(OBJECTS) ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a -o hello.exe
|
$(CC) $(OBJECTS) -o hello.exe
|
||||||
$(OBJCOPY) -O binary hello.exe hello.bin
|
|
||||||
|
|
||||||
include ../../rules.mak
|
include ../../rules.mak
|
||||||
|
|
|
@ -2,9 +2,7 @@ all: ide.sys
|
||||||
|
|
||||||
OBJECTS = ide.o ../../../ntoskrnl/ntoskrnl.a
|
OBJECTS = ide.o ../../../ntoskrnl/ntoskrnl.a
|
||||||
|
|
||||||
# --def ide.def --def ide.def
|
|
||||||
ide.sys: $(OBJECTS)
|
ide.sys: $(OBJECTS)
|
||||||
$(DLLTOOL) --dllname ide.sys --output-lib ide.a
|
|
||||||
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end \
|
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end \
|
||||||
-Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext \
|
-Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext \
|
||||||
-Wl,--base-file,base.tmp $(OBJECTS)
|
-Wl,--base-file,base.tmp $(OBJECTS)
|
||||||
|
@ -12,5 +10,6 @@ ide.sys: $(OBJECTS)
|
||||||
$(DLLTOOL) --dllname ide.sys --base-file base.tmp \
|
$(DLLTOOL) --dllname ide.sys --base-file base.tmp \
|
||||||
--output-exp temp.exp
|
--output-exp temp.exp
|
||||||
- $(RM) base.tmp
|
- $(RM) base.tmp
|
||||||
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -specs=../../svc_specs -mdll -o ide.sys $(OBJECTS) -Wl,temp.exp
|
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 \
|
||||||
|
-specs=../../svc_specs -mdll -o ide.sys $(OBJECTS) -Wl,temp.exp
|
||||||
- $(RM) temp.exp
|
- $(RM) temp.exp
|
||||||
|
|
|
@ -325,6 +325,15 @@ DWORD RtlNtStatusToDosError(NTSTATUS StatusCode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BOOL WINAPI RtlDestroyHeap(HANDLE hheap);
|
||||||
|
LPVOID STDCALL RtlReAllocHeap(HANDLE hheap, DWORD flags, LPVOID ptr,
|
||||||
|
DWORD size);
|
||||||
|
HANDLE WINAPI RtlGetProcessHeap(VOID);
|
||||||
|
BOOL WINAPI RtlLockHeap(HANDLE hheap);
|
||||||
|
BOOL WINAPI RtlUnlockHeap(HANDLE hheap);
|
||||||
|
UINT RtlCompactHeap(HANDLE hheap, DWORD flags);
|
||||||
|
DWORD WINAPI RtlSizeHeap(HANDLE hheap, DWORD flags, PVOID pmem);
|
||||||
|
BOOL WINAPI RtlValidateHeap(HANDLE hheap, DWORD flags, PVOID pmem);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __DDK_RTL_H */
|
#endif /* __DDK_RTL_H */
|
||||||
|
|
78
reactos/lib/kernel32/k32_specs
Normal file
78
reactos/lib/kernel32/k32_specs
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
*asm:
|
||||||
|
|
||||||
|
|
||||||
|
*asm_final:
|
||||||
|
|
||||||
|
|
||||||
|
*cpp:
|
||||||
|
-remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE}
|
||||||
|
|
||||||
|
*cc1:
|
||||||
|
%(cc1_spec)
|
||||||
|
|
||||||
|
*cc1plus:
|
||||||
|
|
||||||
|
|
||||||
|
*endfile:
|
||||||
|
|
||||||
|
|
||||||
|
*link:
|
||||||
|
%{mwindows:--subsystem windows} %{mdll:--dll -e _DllMainCRTStartup@12}
|
||||||
|
|
||||||
|
*lib:
|
||||||
|
|
||||||
|
|
||||||
|
*libgcc:
|
||||||
|
-lgcc
|
||||||
|
|
||||||
|
*startfile:
|
||||||
|
|
||||||
|
|
||||||
|
*switches_need_spaces:
|
||||||
|
|
||||||
|
|
||||||
|
*signed_char:
|
||||||
|
%{funsigned-char:-D__CHAR_UNSIGNED__}
|
||||||
|
|
||||||
|
*predefines:
|
||||||
|
-Di386 -D_WIN32 -DWIN32 -D__WIN32__ -D__MINGW32__ -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) _D_stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -Asystem(winnt) -Acpu(i386) -Amachine(i386)
|
||||||
|
|
||||||
|
*cross_compile:
|
||||||
|
1
|
||||||
|
|
||||||
|
*version:
|
||||||
|
egcs-2.91.57
|
||||||
|
|
||||||
|
*multilib:
|
||||||
|
. ;
|
||||||
|
|
||||||
|
*multilib_defaults:
|
||||||
|
|
||||||
|
|
||||||
|
*multilib_extra:
|
||||||
|
|
||||||
|
|
||||||
|
*multilib_matches:
|
||||||
|
|
||||||
|
|
||||||
|
*linker:
|
||||||
|
collect2
|
||||||
|
|
||||||
|
*cpp_486:
|
||||||
|
%{!ansi:-Di486} -D__i486 -D__i486__
|
||||||
|
|
||||||
|
*cpp_586:
|
||||||
|
%{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
|
||||||
|
|
||||||
|
*cpp_686:
|
||||||
|
%{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
|
||||||
|
|
||||||
|
*cpp_cpu_default:
|
||||||
|
%(cpp_586)
|
||||||
|
|
||||||
|
*cpp_cpu:
|
||||||
|
-Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__ %{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)} %{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)} %{mcpu=pentiumpro:%(cpp_686)} %{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}
|
||||||
|
|
||||||
|
*cc1_cpu:
|
||||||
|
%{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{mno-486:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mno-386:-mcpu=i486 -march=i486} %{mno-pentium:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mno-pentiumpro:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,15 @@
|
||||||
all: kernel32.a
|
|
||||||
|
ifneq ($(HOST),mingw32-windows)
|
||||||
|
ifneq ($(HOST),mingw32-linux)
|
||||||
|
DLLTARGET=kernel32.a
|
||||||
|
else
|
||||||
|
DLLTARGET=kernel32.dll
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
DLLTARGET=kernel32.dll
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: $(DLLTARGET)
|
||||||
|
|
||||||
SYNCH_OBJECTS = synch/critical.o synch/event.o synch/wait.o
|
SYNCH_OBJECTS = synch/critical.o synch/event.o synch/wait.o
|
||||||
|
|
||||||
|
@ -19,7 +30,7 @@ PROCESS_OBJECTS = process/proc.o process/cmdline.o
|
||||||
|
|
||||||
STRING_OBJECTS = string/lstring.o
|
STRING_OBJECTS = string/lstring.o
|
||||||
|
|
||||||
INTERNAL_OBJECTS = internal/dprintf.o internal/init.o internal/string.o
|
INTERNAL_OBJECTS = internal/dprintf.o internal/string.o
|
||||||
|
|
||||||
EXCEPT_OBJECTS = except/except.o
|
EXCEPT_OBJECTS = except/except.o
|
||||||
|
|
||||||
|
@ -28,10 +39,25 @@ OBJECTS = $(MISC_OBJECTS) $(FILE_OBJECTS) $(THREAD_OBJECTS) \
|
||||||
$(PROCESS_OBJECTS) $(STRING_OBJECTS) $(MEM_OBJECTS) $(NLS_OBJECTS) \
|
$(PROCESS_OBJECTS) $(STRING_OBJECTS) $(MEM_OBJECTS) $(NLS_OBJECTS) \
|
||||||
$(INTERNAL_OBJECTS) $(SYNCH_OBJECTS) $(EXCEPT_OBJECTS)
|
$(INTERNAL_OBJECTS) $(SYNCH_OBJECTS) $(EXCEPT_OBJECTS)
|
||||||
|
|
||||||
|
|
||||||
kernel32.a: $(OBJECTS)
|
kernel32.a: $(OBJECTS)
|
||||||
$(AR) rcs kernel32.a $(OBJECTS)
|
$(AR) csr kernel32.a $(OBJECTS)
|
||||||
|
|
||||||
dummy:
|
kernel32.dll: $(DLLMAIN) $(OBJECTS) kernel32.def
|
||||||
|
$(LD) -r $(OBJECTS) -o kernel32.o
|
||||||
|
$(DLLTOOL) --dllname kernel32.dll --def kernel32.def \
|
||||||
|
--output-lib kernel32.a
|
||||||
|
$(CC) -specs=k32_specs -mdll -o junk.tmp \
|
||||||
|
-Wl,--base-file,base.tmp kernel32.o ../ntdll/ntdll.a
|
||||||
|
- $(RM) junk.tmp
|
||||||
|
$(DLLTOOL) --dllname kernel32.dll --base-file base.tmp \
|
||||||
|
--output-exp temp.exp --def kernel32.def
|
||||||
|
- $(RM) base.tmp
|
||||||
|
$(CC) -specs=k32_specs -mdll -o kernel32.dll kernel32.o ../ntdll/ntdll.a\
|
||||||
|
-Wl,--image-base,0x70000000 \
|
||||||
|
-Wl,--file-alignment,0x1000 \
|
||||||
|
-Wl,--section-alignment,0x1000 \
|
||||||
|
-Wl,temp.exp
|
||||||
|
- $(RM) temp.exp
|
||||||
|
$(NM) --numeric-sort kernel32.dll > kernel32.sym
|
||||||
|
|
||||||
include ../../rules.mak
|
include ../../rules.mak
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,10 +13,7 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <kernel32/proc.h>
|
#include <kernel32/proc.h>
|
||||||
|
|
||||||
WINBOOL
|
WINBOOL STDCALL DllMain (HANDLE hInst,
|
||||||
STDCALL
|
|
||||||
DllMain (
|
|
||||||
HANDLE hInst,
|
|
||||||
ULONG ul_reason_for_call,
|
ULONG ul_reason_for_call,
|
||||||
LPVOID lpReserved);
|
LPVOID lpReserved);
|
||||||
|
|
||||||
|
@ -25,10 +22,10 @@ DllMain (
|
||||||
NT_TEB *Teb;
|
NT_TEB *Teb;
|
||||||
|
|
||||||
|
|
||||||
|
BOOL WINAPI DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
||||||
|
{
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
WINBOOL STDCALL DllMain (HANDLE hInst,
|
WINBOOL STDCALL DllMain (HANDLE hInst,
|
||||||
ULONG ul_reason_for_call,
|
ULONG ul_reason_for_call,
|
||||||
|
|
45
reactos/lib/ntdll/Makefile_rex
Normal file
45
reactos/lib/ntdll/Makefile_rex
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
ifneq ($(HOST),mingw32-windows)
|
||||||
|
ifneq ($(HOST),mingw32-linux)
|
||||||
|
DLLTARGET=ntdll.a
|
||||||
|
DLLMAIN=
|
||||||
|
else
|
||||||
|
DLLTARGET=ntdll.dll
|
||||||
|
DLLMAIN=main/dllmain.o
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
DLLTARGET=ntdll.dll
|
||||||
|
DLLMAIN=main/dllmain.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: $(DLLTARGET)
|
||||||
|
|
||||||
|
OBJECTS = napi.o ldr/startup.o rtl/largeint.o rtl/namespc.o rtl/unicode.o \
|
||||||
|
stdio/vsprintf.o string/ctype.o string/memcpy.o string/memset.o \
|
||||||
|
string/strcat.o string/strcmp.o string/strcpy.o string/stricmp.o \
|
||||||
|
string/strlen.o string/strncmp.o string/strncpy.o string/strnlen.o \
|
||||||
|
string/strrchr.o string/wstring.o stubs/stubs.o rtl/heap.o \
|
||||||
|
rtl/critical.o rtl/mem.o
|
||||||
|
|
||||||
|
ntdll.a: $(OBJECTS)
|
||||||
|
$(AR) csr ntdll.a $(OBJECTS)
|
||||||
|
|
||||||
|
ntdll.dll: $(DLLMAIN) $(OBJECTS) def/ntdll.def
|
||||||
|
$(LD) -r $(DLLMAIN) $(OBJECTS) -o ntdll.o
|
||||||
|
$(DLLTOOL) --dllname ntdll.dll --def def/ntdll.def \
|
||||||
|
--output-lib ntdll.a
|
||||||
|
$(CC) -specs=ntdll_specs -mdll -o junk.tmp \
|
||||||
|
-Wl,--base-file,base.tmp ntdll.o
|
||||||
|
- $(RM) junk.tmp
|
||||||
|
$(DLLTOOL) --dllname ntdll.dll --base-file base.tmp \
|
||||||
|
--output-exp temp.exp --def def/ntdll.def
|
||||||
|
- $(RM) base.tmp
|
||||||
|
$(CC) -specs=ntdll_specs -mdll -o ntdll.dll ntdll.o \
|
||||||
|
-Wl,--entry=_LdrStartup \
|
||||||
|
-Wl,--image-base,0x80000000 \
|
||||||
|
-Wl,--file-alignment,0x1000 \
|
||||||
|
-Wl,--section-alignment,0x1000 \
|
||||||
|
-Wl,temp.exp
|
||||||
|
- $(RM) temp.exp
|
||||||
|
$(NM) --numeric-sort ntdll.dll > ntdll.sym
|
||||||
|
|
||||||
|
include ../../rules.mak
|
|
@ -420,6 +420,17 @@ ZwReplyWaitSendChannel@12
|
||||||
ZwSendWaitReplyChannel@16
|
ZwSendWaitReplyChannel@16
|
||||||
ZwSetContextChannel@4
|
ZwSetContextChannel@4
|
||||||
ZwYieldExecution@0
|
ZwYieldExecution@0
|
||||||
|
RtlAllocateHeap@12
|
||||||
|
RtlCreateHeap@24
|
||||||
|
RtlCompactHeap
|
||||||
|
RtlDestroyHeap@4
|
||||||
|
RtlFreeHeap@12
|
||||||
|
RtlGetProcessHeap@0
|
||||||
|
RtlLockHeap@4
|
||||||
|
RtlReAllocHeap@16
|
||||||
|
RtlSizeHeap@12
|
||||||
|
RtlUnlockHeap@4
|
||||||
|
RtlValidateHeap@12
|
||||||
RtlInitAnsiString
|
RtlInitAnsiString
|
||||||
RtlInitUnicodeString
|
RtlInitUnicodeString
|
||||||
RtlLargeIntegerDivide
|
RtlLargeIntegerDivide
|
||||||
|
@ -428,6 +439,7 @@ RtlEnlargedIntegerMultiply
|
||||||
RtlEnlargedUnsignedMultiply
|
RtlEnlargedUnsignedMultiply
|
||||||
RtlExtendedIntegerMultiply
|
RtlExtendedIntegerMultiply
|
||||||
isalpha
|
isalpha
|
||||||
|
iswlower
|
||||||
memcpy
|
memcpy
|
||||||
memset
|
memset
|
||||||
strcat
|
strcat
|
||||||
|
@ -438,6 +450,7 @@ strncpy
|
||||||
strlen
|
strlen
|
||||||
strrchr
|
strrchr
|
||||||
toupper
|
toupper
|
||||||
|
towupper
|
||||||
wcscpy
|
wcscpy
|
||||||
wcschr
|
wcschr
|
||||||
wcscat
|
wcscat
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
#include <internal/string.h>
|
#include <internal/string.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#define NDEBUG
|
//#define NDEBUG
|
||||||
#include <ntdll/ntdll.h>
|
#include <ntdll/ntdll.h>
|
||||||
|
|
||||||
VOID WINAPI __RtlInitHeap(LPVOID base, ULONG minsize, ULONG maxsize);
|
PVOID WINAPI __RtlInitHeap(LPVOID base, ULONG minsize, ULONG maxsize);
|
||||||
|
|
||||||
/* MACROS ********************************************************************/
|
/* MACROS ********************************************************************/
|
||||||
|
|
||||||
#define RVA(m, b) ((ULONG)b + m->BaseAddress)
|
#define RVA(m, b) ((ULONG)b + m)
|
||||||
|
|
||||||
/* TYPEDEFS ******************************************************************/
|
/* TYPEDEFS ******************************************************************/
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@ typedef struct _DLL
|
||||||
|
|
||||||
static DLL DllListHead;
|
static DLL DllListHead;
|
||||||
|
|
||||||
|
#define HEAP_BASE (0xa0000000)
|
||||||
|
|
||||||
/* FORWARD DECLARATIONS ******************************************************/
|
/* FORWARD DECLARATIONS ******************************************************/
|
||||||
|
|
||||||
static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle);
|
static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle);
|
||||||
|
@ -83,12 +85,126 @@ static NTSTATUS LdrMapSections(PVOID ImageBase, HANDLE SectionHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS LdrLoadDll(PDLL* Base, PCHAR Name)
|
static NTSTATUS LdrLoadDll(PDLL* Base, PCHAR Name)
|
||||||
|
{
|
||||||
|
char fqname[255] = "\\??\\C:\\reactos\\system\\";
|
||||||
|
ANSI_STRING AnsiString;
|
||||||
|
UNICODE_STRING UnicodeString;
|
||||||
|
OBJECT_ATTRIBUTES FileObjectAttributes;
|
||||||
|
char BlockBuffer[1024];
|
||||||
|
PIMAGE_DOS_HEADER DosHeader;
|
||||||
|
NTSTATUS Status;
|
||||||
|
PIMAGE_NT_HEADERS NTHeaders;
|
||||||
|
PEPFUNC DllStartupAddr;
|
||||||
|
ULONG ImageBase, ImageSize, InitialViewSize;
|
||||||
|
HANDLE FileHandle, SectionHandle;
|
||||||
|
PDLL DllDesc;
|
||||||
|
|
||||||
|
DPRINT("LdrLoadDll(Base %x, Name %s)\n",Base,Name);
|
||||||
|
|
||||||
|
strcat(fqname, Name);
|
||||||
|
|
||||||
|
DPRINT("fqname %s\n",fqname);
|
||||||
|
|
||||||
|
RtlInitAnsiString(&AnsiString,fqname);
|
||||||
|
RtlAnsiStringToUnicodeString(&UnicodeString,&AnsiString,TRUE);
|
||||||
|
|
||||||
|
InitializeObjectAttributes(&FileObjectAttributes,
|
||||||
|
&UnicodeString,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
DPRINT("Opening dll\n");
|
||||||
|
Status = ZwOpenFile(&FileHandle, FILE_ALL_ACCESS, &FileObjectAttributes,
|
||||||
|
NULL, 0, 0);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("Dll open failed ");
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 1024, 0, 0);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("Dll header read failed ");
|
||||||
|
ZwClose(FileHandle);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
|
||||||
|
if (DosHeader->e_magic != IMAGE_DOS_MAGIC ||
|
||||||
|
DosHeader->e_lfanew == 0L ||
|
||||||
|
*(PULONG)((PUCHAR)BlockBuffer + DosHeader->e_lfanew) != IMAGE_PE_MAGIC)
|
||||||
|
{
|
||||||
|
DPRINT("NTDLL format invalid\n");
|
||||||
|
ZwClose(FileHandle);
|
||||||
|
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
|
||||||
|
ImageBase = NTHeaders->OptionalHeader.ImageBase;
|
||||||
|
ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
|
||||||
|
|
||||||
|
DPRINT("ImageBase %x\n",ImageBase);
|
||||||
|
DllStartupAddr = ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint;
|
||||||
|
|
||||||
|
/* Create a section for NTDLL */
|
||||||
|
Status = ZwCreateSection(&SectionHandle,
|
||||||
|
SECTION_ALL_ACCESS,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
PAGE_READWRITE,
|
||||||
|
MEM_COMMIT,
|
||||||
|
FileHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("NTDLL create section failed ");
|
||||||
|
ZwClose(FileHandle);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Map the NTDLL into the process */
|
||||||
|
InitialViewSize = DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
|
||||||
|
+ sizeof(IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections;
|
||||||
|
Status = ZwMapViewOfSection(SectionHandle,
|
||||||
|
NtCurrentProcess(),
|
||||||
|
(PVOID *)&ImageBase,
|
||||||
|
0,
|
||||||
|
InitialViewSize,
|
||||||
|
NULL,
|
||||||
|
&InitialViewSize,
|
||||||
|
0,
|
||||||
|
MEM_COMMIT,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("NTDLL map view of secion failed ");
|
||||||
|
ZwClose(FileHandle);
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
ZwClose(FileHandle);
|
||||||
|
|
||||||
|
DllDesc = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DLL));
|
||||||
|
DllDesc->Headers = NTHeaders;
|
||||||
|
DllDesc->BaseAddress = ImageBase;
|
||||||
|
DllDesc->Next = DllListHead.Next;
|
||||||
|
DllDesc->Prev = &DllListHead;
|
||||||
|
DllListHead.Next->Prev = DllDesc;
|
||||||
|
DllListHead.Next = DllDesc;
|
||||||
|
|
||||||
|
LdrPEStartup(ImageBase, SectionHandle);
|
||||||
|
|
||||||
|
*Base = DllDesc;
|
||||||
|
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static NTSTATUS LdrFindDll(PDLL* Base, PCHAR Name)
|
||||||
{
|
{
|
||||||
PIMAGE_EXPORT_DIRECTORY ExportDir;
|
PIMAGE_EXPORT_DIRECTORY ExportDir;
|
||||||
DLL* current;
|
DLL* current;
|
||||||
PIMAGE_OPTIONAL_HEADER OptionalHeader;
|
PIMAGE_OPTIONAL_HEADER OptionalHeader;
|
||||||
|
|
||||||
DPRINT("LdrLoadDll(Name %s)\n",Name);
|
DPRINT("LdrFindDll(Name %s)\n",Name);
|
||||||
|
|
||||||
current = &DllListHead;
|
current = &DllListHead;
|
||||||
do
|
do
|
||||||
|
@ -98,8 +214,6 @@ static NTSTATUS LdrLoadDll(PDLL* Base, PCHAR Name)
|
||||||
IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
|
IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
|
||||||
ExportDir = ((ULONG)ExportDir + (ULONG)current->BaseAddress);
|
ExportDir = ((ULONG)ExportDir + (ULONG)current->BaseAddress);
|
||||||
|
|
||||||
DPRINT("ExportDir %x\n",ExportDir);
|
|
||||||
DPRINT("Scanning %x\n",ExportDir->Name);
|
|
||||||
DPRINT("Scanning %s\n",ExportDir->Name + current->BaseAddress);
|
DPRINT("Scanning %s\n",ExportDir->Name + current->BaseAddress);
|
||||||
if (strcmp(ExportDir->Name + current->BaseAddress, Name) == 0)
|
if (strcmp(ExportDir->Name + current->BaseAddress, Name) == 0)
|
||||||
{
|
{
|
||||||
|
@ -110,10 +224,10 @@ static NTSTATUS LdrLoadDll(PDLL* Base, PCHAR Name)
|
||||||
current = current->Next;
|
current = current->Next;
|
||||||
} while (current != &DllListHead);
|
} while (current != &DllListHead);
|
||||||
|
|
||||||
return(STATUS_UNSUCCESSFUL);
|
DPRINT("Failed to find dll %s\n",Name);
|
||||||
}
|
|
||||||
|
|
||||||
#define HEAP_BASE (0xa0000000)
|
return(LdrLoadDll(Base, Name));
|
||||||
|
}
|
||||||
|
|
||||||
/* LdrStartup
|
/* LdrStartup
|
||||||
* FUNCTION:
|
* FUNCTION:
|
||||||
|
@ -125,7 +239,6 @@ VOID LdrStartup(HANDLE SectionHandle, DWORD ImageBase)
|
||||||
{
|
{
|
||||||
PEPFUNC EntryPoint;
|
PEPFUNC EntryPoint;
|
||||||
PIMAGE_DOS_HEADER PEDosHeader;
|
PIMAGE_DOS_HEADER PEDosHeader;
|
||||||
char buffer[512];
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PIMAGE_NT_HEADERS NTHeaders;
|
PIMAGE_NT_HEADERS NTHeaders;
|
||||||
|
|
||||||
|
@ -161,12 +274,26 @@ VOID LdrStartup(HANDLE SectionHandle, DWORD ImageBase)
|
||||||
ZwTerminateProcess(NULL,STATUS_UNSUCCESSFUL);
|
ZwTerminateProcess(NULL,STATUS_UNSUCCESSFUL);
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("Transferring control to image\n");
|
DPRINT("Transferring control to image at %x\n",EntryPoint);
|
||||||
Status = EntryPoint();
|
Status = EntryPoint();
|
||||||
ZwTerminateProcess(NtCurrentProcess(),Status);
|
ZwTerminateProcess(NtCurrentProcess(),Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PVOID LdrGetExport(PDLL Module, PUCHAR SymbolName)
|
static PVOID LdrGetExportByOrdinal(PDLL Module, ULONG Ordinal)
|
||||||
|
{
|
||||||
|
PIMAGE_EXPORT_DIRECTORY ExportDir;
|
||||||
|
USHORT* ExOrdinals;
|
||||||
|
|
||||||
|
ExportDir = (Module->BaseAddress +
|
||||||
|
(Module->Headers->OptionalHeader.
|
||||||
|
DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress));
|
||||||
|
|
||||||
|
ExOrdinals = (USHORT*)RVA(Module->BaseAddress,
|
||||||
|
ExportDir->AddressOfNameOrdinals);
|
||||||
|
return(ExOrdinals[Ordinal - ExportDir->Base]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PVOID LdrGetExportByName(PDLL Module, PUCHAR SymbolName)
|
||||||
{
|
{
|
||||||
PIMAGE_EXPORT_DIRECTORY ExportDir;
|
PIMAGE_EXPORT_DIRECTORY ExportDir;
|
||||||
PDWORD* ExFunctions;
|
PDWORD* ExFunctions;
|
||||||
|
@ -184,43 +311,25 @@ static PVOID LdrGetExport(PDLL Module, PUCHAR SymbolName)
|
||||||
DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress));
|
DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress));
|
||||||
|
|
||||||
/* Get header pointers */
|
/* Get header pointers */
|
||||||
ExNames = (PDWORD*)RVA(Module, ExportDir->AddressOfNames);
|
ExNames = (PDWORD*)RVA(Module->BaseAddress, ExportDir->AddressOfNames);
|
||||||
ExOrdinals = (USHORT*)RVA(Module, ExportDir->AddressOfNameOrdinals);
|
ExOrdinals = (USHORT*)RVA(Module->BaseAddress,
|
||||||
ExFunctions = (PDWORD*)RVA(Module, ExportDir->AddressOfFunctions);
|
ExportDir->AddressOfNameOrdinals);
|
||||||
|
ExFunctions = (PDWORD*)RVA(Module->BaseAddress,
|
||||||
|
ExportDir->AddressOfFunctions);
|
||||||
for (i=0; i<ExportDir->NumberOfFunctions; i++)
|
for (i=0; i<ExportDir->NumberOfFunctions; i++)
|
||||||
{
|
{
|
||||||
ExName = RVA(Module, ExNames[i]);
|
ExName = RVA(Module->BaseAddress, ExNames[i]);
|
||||||
if (strcmp(ExName,SymbolName) == 0)
|
if (strcmp(ExName,SymbolName) == 0)
|
||||||
{
|
{
|
||||||
Ordinal = ExOrdinals[i];
|
Ordinal = ExOrdinals[i];
|
||||||
return(RVA(Module, ExFunctions[Ordinal]));
|
return(RVA(Module->BaseAddress, ExFunctions[Ordinal]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
static NTSTATUS LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders,
|
||||||
{
|
DWORD ImageBase)
|
||||||
int i;
|
|
||||||
PVOID SectionBase;
|
|
||||||
NTSTATUS Status;
|
|
||||||
PEPFUNC EntryPoint;
|
|
||||||
PIMAGE_DOS_HEADER DosHeader;
|
|
||||||
PIMAGE_NT_HEADERS NTHeaders;
|
|
||||||
PIMAGE_SECTION_HEADER SectionList;
|
|
||||||
char buffer[512];
|
|
||||||
PDLL Module;
|
|
||||||
|
|
||||||
DosHeader = (PIMAGE_DOS_HEADER) ImageBase;
|
|
||||||
NTHeaders = (PIMAGE_NT_HEADERS)(ImageBase + DosHeader->e_lfanew);
|
|
||||||
SectionList = (PIMAGE_SECTION_HEADER) (ImageBase + DosHeader->e_lfanew +
|
|
||||||
sizeof(ULONG) + sizeof(IMAGE_FILE_HEADER) + sizeof(IMAGE_OPTIONAL_HEADER));
|
|
||||||
|
|
||||||
/* Initialize Image sections */
|
|
||||||
LdrMapSections(ImageBase, SectionHandle, NTHeaders);
|
|
||||||
|
|
||||||
/* FIXME: if actual load address is different from ImageBase, then reloc */
|
|
||||||
if (ImageBase != (DWORD) NTHeaders->OptionalHeader.ImageBase)
|
|
||||||
{
|
{
|
||||||
USHORT NumberOfEntries;
|
USHORT NumberOfEntries;
|
||||||
PUSHORT pValue16;
|
PUSHORT pValue16;
|
||||||
|
@ -229,13 +338,14 @@ static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
||||||
PULONG pValue32;
|
PULONG pValue32;
|
||||||
PRELOCATION_DIRECTORY RelocationDir;
|
PRELOCATION_DIRECTORY RelocationDir;
|
||||||
PRELOCATION_ENTRY RelocationBlock;
|
PRELOCATION_ENTRY RelocationBlock;
|
||||||
|
int i;
|
||||||
|
|
||||||
RelocationRVA = NTHeaders->OptionalHeader.DataDirectory[
|
RelocationRVA = NTHeaders->OptionalHeader.DataDirectory[
|
||||||
IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
|
IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
|
||||||
if (RelocationRVA)
|
if (RelocationRVA)
|
||||||
{
|
{
|
||||||
RelocationDir = (PRELOCATION_DIRECTORY)
|
RelocationDir = (PRELOCATION_DIRECTORY)((PCHAR)ImageBase +
|
||||||
((PCHAR)ImageBase + RelocationRVA);
|
RelocationRVA);
|
||||||
while (RelocationDir->SizeOfBlock)
|
while (RelocationDir->SizeOfBlock)
|
||||||
{
|
{
|
||||||
Delta32 = (unsigned long)(ImageBase -
|
Delta32 = (unsigned long)(ImageBase -
|
||||||
|
@ -271,13 +381,13 @@ static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
||||||
|
|
||||||
case TYPE_RELOC_HIGHADJ:
|
case TYPE_RELOC_HIGHADJ:
|
||||||
/* FIXME: do the highadjust fixup */
|
/* FIXME: do the highadjust fixup */
|
||||||
DPRINT(
|
DPRINT("TYPE_RELOC_HIGHADJ fixup not implemented"
|
||||||
"TYPE_RELOC_HIGHADJ fixup not implemented, sorry\n");
|
", sorry\n");
|
||||||
return 0;
|
return(STATUS_UNSUCCESSFUL);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DPRINT("unexpected fixup type\n");
|
DPRINT("unexpected fixup type\n");
|
||||||
return 0;
|
return(STATUS_UNSUCCESSFUL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RelocationRVA += RelocationDir->SizeOfBlock;
|
RelocationRVA += RelocationDir->SizeOfBlock;
|
||||||
|
@ -285,14 +395,16 @@ static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
||||||
RelocationRVA);
|
RelocationRVA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: do import fixups/load required libraries */
|
static NTSTATUS LdrFixupImports(PIMAGE_NT_HEADERS NTHeaders,
|
||||||
/* Resolve Import Library references */
|
DWORD ImageBase)
|
||||||
if (NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].
|
|
||||||
VirtualAddress != 0)
|
|
||||||
{
|
{
|
||||||
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
|
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
|
||||||
|
ULONG Ordinal;
|
||||||
|
PDLL Module;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
/* Process each import module */
|
/* Process each import module */
|
||||||
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
|
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
|
||||||
|
@ -300,15 +412,12 @@ static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
||||||
DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||||
while (ImportModuleDirectory->dwRVAModuleName)
|
while (ImportModuleDirectory->dwRVAModuleName)
|
||||||
{
|
{
|
||||||
DWORD LibraryBase;
|
PVOID *ImportAddressList;
|
||||||
PIMAGE_DOS_HEADER LibDosHeader;
|
|
||||||
PIMAGE_NT_HEADERS LibNTHeaders;
|
|
||||||
PVOID *ImportAddressList; // was pImpAddr
|
|
||||||
PULONG FunctionNameList;
|
PULONG FunctionNameList;
|
||||||
DWORD pName;
|
DWORD pName;
|
||||||
PWORD pHint;
|
PWORD pHint;
|
||||||
|
|
||||||
Status = LdrLoadDll(&Module,
|
Status = LdrFindDll(&Module,
|
||||||
(PCHAR)(ImageBase +
|
(PCHAR)(ImageBase +
|
||||||
ImportModuleDirectory->dwRVAModuleName));
|
ImportModuleDirectory->dwRVAModuleName));
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
@ -336,44 +445,66 @@ static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
||||||
/* Walk through function list and fixup addresses */
|
/* Walk through function list and fixup addresses */
|
||||||
while(*FunctionNameList != 0L)
|
while(*FunctionNameList != 0L)
|
||||||
{
|
{
|
||||||
if ((*FunctionNameList) & 0x80000000) // hint
|
if ((*FunctionNameList) & 0x80000000)
|
||||||
{
|
{
|
||||||
// *ImportAddressList = LibraryExports[(*FunctionNameList) & 0x7fffffff];
|
Ordinal = (*FunctionNameList) & 0x7fffffff;
|
||||||
DPRINT("Import by ordinal unimplemented\n");
|
*ImportAddressList = LdrGetExportByOrdinal(Module, Ordinal);
|
||||||
for(;;);
|
|
||||||
}
|
}
|
||||||
else // hint-name
|
else
|
||||||
{
|
{
|
||||||
pName = (DWORD)(ImageBase + *FunctionNameList + 2);
|
pName = (DWORD)(ImageBase + *FunctionNameList + 2);
|
||||||
pHint = (PWORD)(ImageBase + *FunctionNameList);
|
pHint = (PWORD)(ImageBase + *FunctionNameList);
|
||||||
|
|
||||||
/* FIXME: verify name */
|
*ImportAddressList = LdrGetExportByName(Module,pName);
|
||||||
|
if ((*ImportAddressList) == NULL)
|
||||||
if (strcmp(pName,"vsprintf")==0)
|
|
||||||
{
|
{
|
||||||
DPRINT("Fixing up reference to %s at %x\n",
|
return(STATUS_UNSUCCESSFUL);
|
||||||
pName,ImportAddressList);
|
|
||||||
DPRINT("pHint %x\n",pHint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*ImportAddressList = LdrGetExport(Module,pName);
|
|
||||||
}
|
}
|
||||||
/* FIXME: verify value of hint */
|
|
||||||
|
|
||||||
ImportAddressList++;
|
ImportAddressList++;
|
||||||
FunctionNameList++;
|
FunctionNameList++;
|
||||||
}
|
}
|
||||||
ImportModuleDirectory++;
|
ImportModuleDirectory++;
|
||||||
}
|
}
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: locate the entry point for the image */
|
static PEPFUNC LdrPEStartup(DWORD ImageBase, HANDLE SectionHandle)
|
||||||
EntryPoint = NTHeaders->OptionalHeader.ImageBase +
|
{
|
||||||
NTHeaders->OptionalHeader.AddressOfEntryPoint;
|
NTSTATUS Status;
|
||||||
|
PEPFUNC EntryPoint;
|
||||||
|
PIMAGE_DOS_HEADER DosHeader;
|
||||||
|
PIMAGE_NT_HEADERS NTHeaders;
|
||||||
|
|
||||||
return EntryPoint;
|
DosHeader = (PIMAGE_DOS_HEADER) ImageBase;
|
||||||
|
NTHeaders = (PIMAGE_NT_HEADERS)(ImageBase + DosHeader->e_lfanew);
|
||||||
|
|
||||||
|
/* Initialize Image sections */
|
||||||
|
LdrMapSections(ImageBase, SectionHandle, NTHeaders);
|
||||||
|
|
||||||
|
if (ImageBase != (DWORD) NTHeaders->OptionalHeader.ImageBase)
|
||||||
|
{
|
||||||
|
Status = LdrPerformRelocations(NTHeaders, ImageBase);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].
|
||||||
|
VirtualAddress != 0)
|
||||||
|
{
|
||||||
|
Status = LdrFixupImports(NTHeaders, ImageBase);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EntryPoint = ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint;
|
||||||
|
|
||||||
|
return(EntryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
//#define NDEBUG
|
#define NDEBUG
|
||||||
#include <ntdll/ntdll.h>
|
#include <ntdll/ntdll.h>
|
||||||
|
|
||||||
#define HEAP_VALIDATE
|
#define HEAP_VALIDATE
|
||||||
|
@ -753,7 +753,7 @@ PVOID STDCALL RtlAllocateHeap(HANDLE Heap,
|
||||||
DPRINT("HeapAlloc(hheap 0x%lX, flags 0x%lX, size 0x%lX )\n",
|
DPRINT("HeapAlloc(hheap 0x%lX, flags 0x%lX, size 0x%lX )\n",
|
||||||
(ULONG) Heap, Flags, (ULONG) Size );
|
(ULONG) Heap, Flags, (ULONG) Size );
|
||||||
#ifdef HEAP_VALIDATE
|
#ifdef HEAP_VALIDATE
|
||||||
HeapValidate(Heap, 0, 0);
|
RtlValidateHeap(Heap, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
if(( Flags | pheap->Flags) & HEAP_NO_SERIALIZE )
|
if(( Flags | pheap->Flags) & HEAP_NO_SERIALIZE )
|
||||||
RtlEnterCriticalSection(&(pheap->Synchronize));
|
RtlEnterCriticalSection(&(pheap->Synchronize));
|
||||||
|
@ -768,7 +768,7 @@ PVOID STDCALL RtlAllocateHeap(HANDLE Heap,
|
||||||
|
|
||||||
DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval);
|
DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval);
|
||||||
|
|
||||||
HeapValidate(Heap, 0, 0);
|
RtlValidateHeap(Heap, 0, 0);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
|
|
||||||
|
@ -788,7 +788,7 @@ LPVOID STDCALL RtlReAllocHeap(HANDLE hheap, DWORD flags, LPVOID ptr,
|
||||||
DPRINT("HeapReAlloc( 0x%lX, 0x%lX, 0x%lX, 0x%lX )\n",
|
DPRINT("HeapReAlloc( 0x%lX, 0x%lX, 0x%lX, 0x%lX )\n",
|
||||||
(ULONG) hheap, flags, (ULONG) ptr, size );
|
(ULONG) hheap, flags, (ULONG) ptr, size );
|
||||||
#ifdef HEAP_VALIDATE
|
#ifdef HEAP_VALIDATE
|
||||||
HeapValidate(hheap, 0, 0);
|
RtlValidateHeap(hheap, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE )
|
if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE )
|
||||||
RtlEnterCriticalSection(&(pheap->Synchronize));
|
RtlEnterCriticalSection(&(pheap->Synchronize));
|
||||||
|
@ -821,7 +821,7 @@ BOOLEAN STDCALL RtlFreeHeap(HANDLE Heap, ULONG Flags, PVOID Address)
|
||||||
DPRINT("HeapFree( 0x%lX, 0x%lX, 0x%lX )\n",
|
DPRINT("HeapFree( 0x%lX, 0x%lX, 0x%lX )\n",
|
||||||
(ULONG) Heap, Flags, (ULONG) Address );
|
(ULONG) Heap, Flags, (ULONG) Address );
|
||||||
#ifdef HEAP_VALIDATE
|
#ifdef HEAP_VALIDATE
|
||||||
HeapValidate(Heap, 0, 0);
|
RtlValidateHeap(Heap, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
if(( Flags | pheap->Flags) & HEAP_NO_SERIALIZE )
|
if(( Flags | pheap->Flags) & HEAP_NO_SERIALIZE )
|
||||||
RtlEnterCriticalSection(&(pheap->Synchronize));
|
RtlEnterCriticalSection(&(pheap->Synchronize));
|
||||||
|
@ -849,9 +849,9 @@ BOOLEAN STDCALL RtlFreeHeap(HANDLE Heap, ULONG Flags, PVOID Address)
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* GetProcessHeap -- KERNEL32 *
|
* GetProcessHeap -- KERNEL32 *
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
HANDLE WINAPI GetProcessHeap(VOID)
|
HANDLE WINAPI RtlGetProcessHeap(VOID)
|
||||||
{
|
{
|
||||||
DPRINT("GetProcessHeap()\n");
|
DPRINT("RtlGetProcessHeap()\n");
|
||||||
return (HANDLE) __ProcessHeap;
|
return (HANDLE) __ProcessHeap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -891,7 +891,6 @@ DWORD WINAPI RtlEnumProcessHeaps(DWORD maxheaps, PHANDLE phandles )
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* HeapLock -- KERNEL32 *
|
* HeapLock -- KERNEL32 *
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
BOOL WINAPI RtlLockHeap(HANDLE hheap)
|
BOOL WINAPI RtlLockHeap(HANDLE hheap)
|
||||||
{
|
{
|
||||||
PHEAP pheap=hheap;
|
PHEAP pheap=hheap;
|
||||||
|
@ -905,7 +904,6 @@ BOOL WINAPI RtlLockHeap(HANDLE hheap)
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* HeapUnlock -- KERNEL32 *
|
* HeapUnlock -- KERNEL32 *
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
BOOL WINAPI RtlUnlockHeap(HANDLE hheap)
|
BOOL WINAPI RtlUnlockHeap(HANDLE hheap)
|
||||||
{
|
{
|
||||||
PHEAP pheap=hheap;
|
PHEAP pheap=hheap;
|
||||||
|
@ -922,7 +920,6 @@ BOOL WINAPI RtlUnlockHeap(HANDLE hheap)
|
||||||
* NT uses this function to compact moveable blocks and other things *
|
* NT uses this function to compact moveable blocks and other things *
|
||||||
* Here it does not compact, but it finds the largest free region *
|
* Here it does not compact, but it finds the largest free region *
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
UINT RtlCompactHeap(HANDLE hheap, DWORD flags)
|
UINT RtlCompactHeap(HANDLE hheap, DWORD flags)
|
||||||
{
|
{
|
||||||
PHEAP pheap=hheap;
|
PHEAP pheap=hheap;
|
||||||
|
@ -955,7 +952,7 @@ UINT RtlCompactHeap(HANDLE hheap, DWORD flags)
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* HeapSize -- KERNEL32 *
|
* HeapSize -- KERNEL32 *
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
DWORD WINAPI HeapSize(HANDLE hheap, DWORD flags, LPCVOID pmem)
|
DWORD WINAPI RtlSizeHeap(HANDLE hheap, DWORD flags, LPCVOID pmem)
|
||||||
{
|
{
|
||||||
PHEAP pheap=(PHEAP) hheap;
|
PHEAP pheap=(PHEAP) hheap;
|
||||||
PHEAP_BLOCK palloc=((PHEAP_BLOCK)pmem-1);
|
PHEAP_BLOCK palloc=((PHEAP_BLOCK)pmem-1);
|
||||||
|
@ -995,7 +992,7 @@ DWORD WINAPI HeapSize(HANDLE hheap, DWORD flags, LPCVOID pmem)
|
||||||
* *
|
* *
|
||||||
* NOTE: only implemented in NT *
|
* NOTE: only implemented in NT *
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem)
|
BOOL WINAPI RtlValidateHeap(HANDLE hheap, DWORD flags, LPCVOID pmem)
|
||||||
{
|
{
|
||||||
PHEAP pheap=(PHEAP)hheap;
|
PHEAP pheap=(PHEAP)hheap;
|
||||||
PHEAP_BLOCK pcheck;
|
PHEAP_BLOCK pcheck;
|
||||||
|
|
|
@ -43,14 +43,18 @@ ULONG RtlAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS RtlAnsiStringToUnicodeString(IN OUT PUNICODE_STRING DestinationString,
|
NTSTATUS RtlAnsiStringToUnicodeString(IN OUT PUNICODE_STRING DestinationString,
|
||||||
IN PANSI_STRING SourceString, IN BOOLEAN AllocateDestinationString)
|
IN PANSI_STRING SourceString,
|
||||||
|
IN BOOLEAN AllocateDestinationString)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
if(AllocateDestinationString==TRUE) {
|
if (AllocateDestinationString == TRUE)
|
||||||
// DestinationString->Buffer=ExAllocatePool(NonPagedPool, (SourceString->Length+1)*2);
|
{
|
||||||
|
DestinationString->Buffer=RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
0,
|
||||||
|
(SourceString->Length+1)*2);
|
||||||
DestinationString->MaximumLength=SourceString->Length;
|
DestinationString->MaximumLength=SourceString->Length;
|
||||||
};
|
}
|
||||||
|
|
||||||
DestinationString->Length=SourceString->Length;
|
DestinationString->Length=SourceString->Length;
|
||||||
memset(DestinationString->Buffer, 0, SourceString->Length*2);
|
memset(DestinationString->Buffer, 0, SourceString->Length*2);
|
||||||
|
@ -61,14 +65,14 @@ NTSTATUS RtlAnsiStringToUnicodeString(IN OUT PUNICODE_STRING DestinationString,
|
||||||
|
|
||||||
SourceString->Buffer++;
|
SourceString->Buffer++;
|
||||||
DestinationString->Buffer++;
|
DestinationString->Buffer++;
|
||||||
};
|
}
|
||||||
*DestinationString->Buffer=0;
|
*DestinationString->Buffer=0;
|
||||||
|
|
||||||
SourceString->Buffer-=SourceString->Length;
|
SourceString->Buffer-=SourceString->Length;
|
||||||
DestinationString->Buffer-=SourceString->Length;
|
DestinationString->Buffer-=SourceString->Length;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
};
|
}
|
||||||
|
|
||||||
NTSTATUS RtlAppendUnicodeStringToString(IN OUT PUNICODE_STRING Destination,
|
NTSTATUS RtlAppendUnicodeStringToString(IN OUT PUNICODE_STRING Destination,
|
||||||
IN PUNICODE_STRING Source)
|
IN PUNICODE_STRING Source)
|
||||||
|
@ -315,16 +319,19 @@ VOID RtlInitAnsiString(IN OUT PANSI_STRING DestinationString,
|
||||||
{
|
{
|
||||||
unsigned long DestSize;
|
unsigned long DestSize;
|
||||||
|
|
||||||
if(SourceString==NULL) {
|
if(SourceString==NULL)
|
||||||
|
{
|
||||||
DestinationString->Length=0;
|
DestinationString->Length=0;
|
||||||
DestinationString->MaximumLength=0;
|
DestinationString->MaximumLength=0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
DestSize=strlen((const char *)SourceString);
|
DestSize=strlen((const char *)SourceString);
|
||||||
DestinationString->Length=DestSize;
|
DestinationString->Length=DestSize;
|
||||||
DestinationString->MaximumLength=DestSize+1;
|
DestinationString->MaximumLength=DestSize+1;
|
||||||
};
|
}
|
||||||
DestinationString->Buffer=(PCHAR)SourceString;
|
DestinationString->Buffer=(PCHAR)SourceString;
|
||||||
};
|
}
|
||||||
|
|
||||||
VOID RtlInitString(IN OUT PSTRING DestinationString,
|
VOID RtlInitString(IN OUT PSTRING DestinationString,
|
||||||
IN PCSZ SourceString)
|
IN PCSZ SourceString)
|
||||||
|
|
|
@ -29,7 +29,7 @@ LOADERS = dos
|
||||||
#
|
#
|
||||||
# Select the device drivers and filesystems you want
|
# Select the device drivers and filesystems you want
|
||||||
#
|
#
|
||||||
KERNEL_SERVICES = parallel keyboard blues null mouse serial sound ide test sdisk \
|
KERNEL_SERVICES = parallel keyboard blues null mouse serial sound ide \
|
||||||
minix vfat ext2
|
minix vfat ext2
|
||||||
|
|
||||||
APPS = hello shell args
|
APPS = hello shell args
|
||||||
|
|
|
@ -174,15 +174,8 @@ asmlinkage void _main(boot_param* _bp)
|
||||||
*/
|
*/
|
||||||
LdrLoadAutoConfigDrivers();
|
LdrLoadAutoConfigDrivers();
|
||||||
|
|
||||||
#ifdef KRNL_TEST
|
|
||||||
/*
|
/*
|
||||||
* Test various features of the kernel
|
* Launch initial process
|
||||||
*/
|
|
||||||
TstBegin();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Launch initial thread
|
|
||||||
*/
|
*/
|
||||||
LdrLoadInitialProcess();
|
LdrLoadInitialProcess();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
all: ntoskrnl.exe utils/pe2bin/pe2bin$(EXE_POSTFIX)
|
all: objects ntoskrnl.exe
|
||||||
|
|
||||||
#
|
#
|
||||||
# Defines $(HAL_OBJECTS)
|
# Defines $(HAL_OBJECTS)
|
||||||
|
@ -45,14 +45,15 @@ SE_OBJECTS = se/semgr.o
|
||||||
|
|
||||||
CM_OBJECTS = cm/registry.o
|
CM_OBJECTS = cm/registry.o
|
||||||
|
|
||||||
TST_OBJECTS = tst/test.o
|
|
||||||
|
|
||||||
DBG_OBJECTS = dbg/brkpoint.o dbg/errinfo.o
|
DBG_OBJECTS = dbg/brkpoint.o dbg/errinfo.o
|
||||||
|
|
||||||
LDR_OBJECTS = ldr/loader.o
|
LDR_OBJECTS = ldr/loader.o
|
||||||
|
|
||||||
CC_OBJECTS = cc/cacheman.o cc/block.o
|
CC_OBJECTS = cc/cacheman.o cc/block.o
|
||||||
|
|
||||||
|
objects: ../ntoskrnl/objects
|
||||||
|
mkdir objects
|
||||||
|
|
||||||
objects/hal.o: $(HAL_OBJECTS)
|
objects/hal.o: $(HAL_OBJECTS)
|
||||||
$(LD) -r $(HAL_OBJECTS) -o objects/hal.o
|
$(LD) -r $(HAL_OBJECTS) -o objects/hal.o
|
||||||
|
|
||||||
|
@ -83,9 +84,6 @@ objects/se.o: $(SE_OBJECTS)
|
||||||
objects/cm.o: $(CM_OBJECTS)
|
objects/cm.o: $(CM_OBJECTS)
|
||||||
$(LD) -r $(CM_OBJECTS) -o objects/cm.o
|
$(LD) -r $(CM_OBJECTS) -o objects/cm.o
|
||||||
|
|
||||||
objects/tst.o: $(TST_OBJECTS)
|
|
||||||
$(LD) -r $(TST_OBJECTS) -o objects/tst.o
|
|
||||||
|
|
||||||
objects/dbg.o: $(DBG_OBJECTS)
|
objects/dbg.o: $(DBG_OBJECTS)
|
||||||
$(LD) -r $(DBG_OBJECTS) -o objects/dbg.o
|
$(LD) -r $(DBG_OBJECTS) -o objects/dbg.o
|
||||||
|
|
||||||
|
@ -100,12 +98,9 @@ objects/cc.o: $(CC_OBJECTS)
|
||||||
|
|
||||||
OBJECTS = objects/hal.o objects/ke.o objects/rtl.o objects/mm.o \
|
OBJECTS = objects/hal.o objects/ke.o objects/rtl.o objects/mm.o \
|
||||||
objects/io.o objects/ob.o objects/ps.o objects/ex.o \
|
objects/io.o objects/ob.o objects/ps.o objects/ex.o \
|
||||||
objects/se.o objects/cm.o objects/tst.o objects/dbg.o\
|
objects/se.o objects/cm.o objects/dbg.o\
|
||||||
objects/nt.o objects/cc.o objects/ldr.o
|
objects/nt.o objects/cc.o objects/ldr.o
|
||||||
|
|
||||||
utils/pe2bin/pe2bin$(EXE_POSTFIX): utils/pe2bin/pe2bin.c
|
|
||||||
$(NATIVE_CC) -I../include -g utils/pe2bin/pe2bin.c -o utils/pe2bin/pe2bin$(EXE_POSTFIX)
|
|
||||||
|
|
||||||
utils/export/export$(EXE_POSTFIX): utils/export/export.c
|
utils/export/export$(EXE_POSTFIX): utils/export/export.c
|
||||||
$(NATIVE_CC) -g utils/export/export.c -o utils/export/export$(EXE_POSTFIX)
|
$(NATIVE_CC) -g utils/export/export.c -o utils/export/export$(EXE_POSTFIX)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue