Corrected ntdll mapping bug

Implemented prototype lpc mechanism

svn path=/trunk/; revision=795
This commit is contained in:
David Welch 1999-11-25 10:47:58 +00:00
parent 1a0765f6c5
commit 9b614b887d
19 changed files with 723 additions and 386 deletions

View file

@ -41,7 +41,7 @@ FS_DRIVERS = vfat
# FS_DRIVERS = minix ext2 template # FS_DRIVERS = minix ext2 template
KERNEL_SERVICES = $(DEVICE_DRIVERS) $(FS_DRIVERS) KERNEL_SERVICES = $(DEVICE_DRIVERS) $(FS_DRIVERS)
APPS = args hello shell test cat bench apc shm APPS = args hello shell test cat bench apc shm lpc
# APPS = cmd # APPS = cmd
all: buildno $(COMPONENTS) $(DLLS) $(SUBSYS) $(LOADERS) $(KERNEL_SERVICES) $(APPS) all: buildno $(COMPONENTS) $(DLLS) $(SUBSYS) $(LOADERS) $(KERNEL_SERVICES) $(APPS)

View file

@ -0,0 +1,61 @@
#include <ddk/ntddk.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
HANDLE OutputHandle;
HANDLE InputHandle;
void debug_printf(char* fmt, ...)
{
va_list args;
char buffer[255];
va_start(args,fmt);
vsprintf(buffer,fmt,args);
WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
va_end(args);
}
void main(int argc, char* argv[])
{
UNICODE_STRING PortName;
NTSTATUS Status;
HANDLE PortHandle;
LPC_MESSAGE Request;
char buffer[255];
printf("Lpc client\n");
RtlInitUnicodeString(&PortName, L"\\TestPort");
printf("Connecting to port\n");
Status = NtConnectPort(&PortHandle,
&PortName,
NULL,
0,
0,
0,
0,
0);
if (!NT_SUCCESS(Status))
{
printf("Failed to connect\n");
return;
}
strcpy(buffer, GetCommandLineA());
Request.Buffer = buffer;
Status = NtRequestWaitReplyPort(PortHandle,
NULL,
&Request);
if (!NT_SUCCESS(Status))
{
printf("Failed to send request\n");
return;
}
printf("Succeeded\n");
}

View file

@ -0,0 +1,99 @@
#include <ddk/ntddk.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
HANDLE OutputHandle;
HANDLE InputHandle;
void debug_printf(char* fmt, ...)
{
va_list args;
char buffer[255];
va_start(args,fmt);
vsprintf(buffer,fmt,args);
WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
va_end(args);
}
void main(int argc, char* argv[])
{
UNICODE_STRING PortName;
OBJECT_ATTRIBUTES ObjectAttributes;
NTSTATUS Status;
HANDLE NamedPortHandle;
HANDLE PortHandle;
printf("Lpc test server\n");
RtlInitUnicodeString(&PortName, L"\\TestPort");
InitializeObjectAttributes(&ObjectAttributes,
&PortName,
0,
NULL,
NULL);
printf("Creating port\n");
Status = NtCreatePort(&NamedPortHandle,
0,
&ObjectAttributes,
0,
0);
if (!NT_SUCCESS(Status))
{
printf("Failed to create port\n");
return;
}
printf("Listening for connections\n");
Status = NtListenPort(NamedPortHandle,
0);
if (!NT_SUCCESS(Status))
{
printf("Failed to listen for connections\n");
return;
}
printf("Accepting connections\n");
Status = NtAcceptConnectPort(NamedPortHandle,
&PortHandle,
0,
0,
0,
0);
if (!NT_SUCCESS(Status))
{
printf("Failed to accept connection\n");
return;
}
printf("Completing connection\n");
Status = NtCompleteConnectPort(PortHandle);
if (!NT_SUCCESS(Status))
{
printf("Failed to complete connection\n");
return;
}
for(;;)
{
LPC_MESSAGE Request;
char buffer[255];
Request.Buffer = buffer;
Status = NtRequestWaitReplyPort(PortHandle,
&Request,
NULL);
if (!NT_SUCCESS(Status))
{
printf("Failed to receive request\n");
return;
}
printf("Message contents are <%s>\n", Request.Buffer);
}
}

View file

@ -1,24 +1,51 @@
# $Id: makefile,v 1.3 1999/07/17 23:10:12 ea Exp $ #
# ReactOS Operating System #
# LPC test #
CC=gcc SRV_OBJECTS= ../common/crt0.o lpcsrv.o
LD=ld CLT_OBJECTS= ../common/crt0.o lpcclt.o
CFLAGS=-I../../include
PROGS= lpcsrv.exe lpcclt.exe
BASE_CFLAGS = -I../../include
LIBS = ../../lib/crtdll/crtdll.a ../../lib/kernel32/kernel32.a \
../../lib/ntdll/ntdll.a
all: $(PROGS)
.phony: all
clean:
- $(RM) lpcsrv.o
- $(RM) lpcsrv.exe
- $(RM) lpcsrv.sym
.phony: clean
floppy: $(PROGS:%=$(FLOPPY_DIR)/apps/%)
$(PROGS:%=$(FLOPPY_DIR)/apps/%): $(FLOPPY_DIR)/apps/%: %
ifeq ($(DOSCLI),yes)
$(CP) $* $(FLOPPY_DIR)\apps\$*
else
$(CP) $* $(FLOPPY_DIR)/apps/$*
endif
dist: $(PROGS:%=../../$(DIST_DIR)/apps/%)
$(PROGS:%=../../$(DIST_DIR)/apps/%): ../../$(DIST_DIR)/apps/%: %
ifeq ($(DOSCLI),yes)
$(CP) $* ..\..\$(DIST_DIR)\apps\$*
else
$(CP) $* ../../$(DIST_DIR)/apps/$*
endif
lpcsrv.exe: $(SRV_OBJECTS) $(LIBS)
$(LD) $(SRV_OBJECTS) $(LIBS) -o lpcsrv.exe
$(NM) --numeric-sort lpcsrv.exe > lpcsrv.sym
lpcclt.exe: $(CLT_OBJECTS) $(LIBS)
$(LD) $(CLT_OBJECTS) $(LIBS) -o lpcclt.exe
$(NM) --numeric-sort lpcclt.exe > lpcclt.sym
all: conport.exe creport.exe simpless.exe include ../../rules.mak
conport.exe: conport.o dumpinfo.o
$(CC) -o conport conport.o dumpinfo.o
creport.exe: creport.o dumpinfo.o.
$(CC) -o creport creport.o dumpinfo.o
simpless.exe: simpless.o dumpinfo.o.
$(CC) -o simpless simpless.o dumpinfo.o
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
#EOF

View file

@ -1,4 +1,4 @@
/* $Id: zw.h,v 1.20 1999/11/24 11:51:42 dwelch Exp $ /* $Id: zw.h,v 1.21 1999/11/25 10:47:53 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -5177,15 +5177,6 @@ NtConnectPort (
IN DWORD Unknown6, IN DWORD Unknown6,
IN ULONG Flags IN ULONG Flags
); );
/*NTSTATUS
STDCALL
NtCreatePort (
IN POBJECT_ATTRIBUTES PortAttributes OPTIONAL,
OUT PHANDLE PortHandle,
IN ACCESS_MASK GrantedAccess,
IN DWORD Unknown3,
IN ULONG Flags
);*/
NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle, NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle,
ACCESS_MASK DesiredAccess, ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_ATTRIBUTES ObjectAttributes,
@ -5216,13 +5207,13 @@ NTSTATUS
STDCALL STDCALL
NtReplyPort ( /* @8 */ NtReplyPort ( /* @8 */
IN HANDLE PortHandle, IN HANDLE PortHandle,
IN PLPC_REPLY LpcReply /* guess */ IN PLPC_MESSAGE LpcReply /* guess */
); );
NTSTATUS NTSTATUS
STDCALL STDCALL
NtReplyWaitReceivePort ( /* @16 */ NtReplyWaitReceivePort ( /* @16 */
IN HANDLE PortHandle, IN HANDLE PortHandle,
IN PLPC_REPLY LpcReply, /* guess */ IN PLPC_MESSAGE LpcReply, /* guess */
OUT PLPC_MESSAGE LpcMessage, /* guess */ OUT PLPC_MESSAGE LpcMessage, /* guess */
OUT PULONG MessageLength /* guess */ OUT PULONG MessageLength /* guess */
); );
@ -5230,7 +5221,7 @@ NTSTATUS
STDCALL STDCALL
NtReplyWaitReplyPort ( /* @8 */ NtReplyWaitReplyPort ( /* @8 */
IN HANDLE PortHandle, IN HANDLE PortHandle,
IN OUT PLPC_REPLY LpcReply /* guess */ IN OUT PLPC_MESSAGE LpcReply /* guess */
); );
NTSTATUS NTSTATUS
STDCALL STDCALL
@ -5242,8 +5233,8 @@ NTSTATUS
STDCALL STDCALL
NtRequestWaitReplyPort ( /* @12 */ NtRequestWaitReplyPort ( /* @12 */
IN HANDLE PortHandle, IN HANDLE PortHandle,
IN OUT PLPC_REPLY LpcReply, /* guess */ IN OUT PLPC_MESSAGE LpcReply, /* guess */
IN TIME * TimeToWait /* guess */ OUT PLPC_MESSAGE LpcRequest /* guess */
); );
NTSTATUS NTSTATUS
STDCALL STDCALL

View file

@ -11,21 +11,12 @@ enum {
} LPC_MESSAGE_TYPE; } LPC_MESSAGE_TYPE;
typedef typedef struct _LPC_MESSAGE
struct _LPC_REPLY
{ {
DWORD ReplyValue; LPC_MESSAGE_TYPE Type;
ULONG Length;
} LPC_REPLY, * PLPC_REPLY; PVOID Buffer; /* Page aligned! */
DWORD Flags; /* To be defined */
typedef
struct _LPC_MESSAGE
{
LPC_MESSAGE_TYPE Type;
ULONG Length;
PVOID Buffer; /* Page aligned! */
DWORD Flags; /* To be defined */
} LPC_MESSAGE, * PLPC_MESSAGE; } LPC_MESSAGE, * PLPC_MESSAGE;

View file

@ -113,4 +113,7 @@ NTSTATUS MmUnmapViewOfSection(PEPROCESS Process,
PMEMORY_AREA MemoryArea); PMEMORY_AREA MemoryArea);
PVOID MiTryToSharePageInSection(PSECTION_OBJECT Section, ULONG Offset); PVOID MiTryToSharePageInSection(PSECTION_OBJECT Section, ULONG Offset);
NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
#endif #endif

View file

@ -22,3 +22,5 @@ cp subsys/win32k/win32k.sys $1/reactos/system32/drivers
cp apps/apc/apc.exe $1/reactos/bin cp apps/apc/apc.exe $1/reactos/bin
cp apps/shm/shmsrv.exe $1/reactos/bin cp apps/shm/shmsrv.exe $1/reactos/bin
cp apps/shm/shmclt.exe $1/reactos/bin cp apps/shm/shmclt.exe $1/reactos/bin
cp apps/lpc/lpcsrv.exe $1/reactos/bin
cp apps/lpc/lpcclt.exe $1/reactos/bin

View file

@ -1,4 +1,4 @@
; $Id: ntdll.edf,v 1.12 1999/11/20 21:46:16 ekohl Exp $ ; $Id: ntdll.edf,v 1.13 1999/11/25 10:47:55 dwelch Exp $
; ;
; ReactOS Operating System ; ReactOS Operating System
; ;
@ -572,4 +572,5 @@ LdrGetExportByOrdinal
LdrLoadDll LdrLoadDll
LdrMapNTDllForProcess LdrMapNTDllForProcess
LdrUnloadDll LdrUnloadDll
LdrAccessResource
LdrFindResource_U

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.11 1999/11/24 11:51:45 dwelch Exp $ /* $Id: startup.c,v 1.12 1999/11/25 10:47:55 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -36,11 +36,8 @@ extern HANDLE __ProcessHeap;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS NTSTATUS LdrMapNTDllForProcess (HANDLE ProcessHandle,
LdrMapNTDllForProcess ( PHANDLE PtrNTDllSectionHandle)
HANDLE ProcessHandle,
PHANDLE PtrNTDllSectionHandle
)
{ {
ULONG InitialViewSize; ULONG InitialViewSize;
NTSTATUS Status; NTSTATUS Status;

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.16 1999/11/24 11:51:45 dwelch Exp $ /* $Id: utils.c,v 1.17 1999/11/25 10:47:56 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -59,11 +59,8 @@ LdrFindDll (PDLL* Dll,PCHAR Name);
* *
*/ */
NTSTATUS NTSTATUS LdrLoadDll (PDLL* Dll,
LdrLoadDll ( PCHAR Name)
PDLL * Dll,
PCHAR Name
)
{ {
char fqname [255] = "\\??\\C:\\reactos\\system32\\"; char fqname [255] = "\\??\\C:\\reactos\\system32\\";
ANSI_STRING AnsiString; ANSI_STRING AnsiString;
@ -111,8 +108,8 @@ LdrLoadDll (
* Open the DLL's image file. * Open the DLL's image file.
*/ */
if ( LdrFindDll(Dll,fqname) == STATUS_SUCCESS ) if (LdrFindDll(Dll, Name) == STATUS_SUCCESS)
return STATUS_SUCCESS; return STATUS_SUCCESS;
RtlInitAnsiString( RtlInitAnsiString(
@ -226,21 +223,21 @@ LdrLoadDll (
Status = ZwMapViewOfSection( Status = ZwMapViewOfSection(
SectionHandle, SectionHandle,
NtCurrentProcess(), NtCurrentProcess(),
(PVOID *) & ImageBase, (PVOID*)&ImageBase,
0, 0,
InitialViewSize, InitialViewSize,
NULL, NULL,
& InitialViewSize, &InitialViewSize,
0, 0,
MEM_COMMIT, MEM_COMMIT,
PAGE_READWRITE PAGE_READWRITE
); );
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NTDLL.LDR: map view of section failed "); dprintf("NTDLL.LDR: map view of section failed (Status %x)",
ZwClose(FileHandle); Status);
ZwClose(FileHandle);
return Status; return(Status);
} }
ZwClose(FileHandle); ZwClose(FileHandle);
@ -258,7 +255,9 @@ LdrLoadDll (
LdrDllListHead.Next = (*Dll); LdrDllListHead.Next = (*Dll);
if ( (*Dll)->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL == IMAGE_FILE_DLL ) { if (((*Dll)->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL) ==
IMAGE_FILE_DLL)
{
Entrypoint = Entrypoint =
(PDLLMAIN_FUNC) LdrPEStartup( (PDLLMAIN_FUNC) LdrPEStartup(
@ -306,60 +305,54 @@ LdrLoadDll (
* NOTE * NOTE
* *
*/ */
static static NTSTATUS LdrFindDll(PDLL* Dll, PCHAR Name)
NTSTATUS
LdrFindDll (
PDLL * Dll,
PCHAR Name
)
{ {
PIMAGE_EXPORT_DIRECTORY ExportDir; PIMAGE_EXPORT_DIRECTORY ExportDir;
DLL * current; DLL * current;
PIMAGE_OPTIONAL_HEADER OptionalHeader; PIMAGE_OPTIONAL_HEADER OptionalHeader;
// DPRINT("NTDLL.LdrFindDll(Name %s)\n", Name);
current = & LdrDllListHead;
DPRINT("NTDLL.LdrFindDll(Name %s)\n", Name);
// NULL is the current process
current = & LdrDllListHead;
if ( Name == NULL ) {
*Dll = current; // NULL is the current process
return STATUS_SUCCESS;
} if ( Name == NULL )
{
do *Dll = current;
{ return STATUS_SUCCESS;
OptionalHeader = & current->Headers->OptionalHeader; }
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
OptionalHeader->DataDirectory[ do
IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; {
ExportDir = (PIMAGE_EXPORT_DIRECTORY) OptionalHeader = & current->Headers->OptionalHeader;
((ULONG)ExportDir + (ULONG)current->BaseAddress); ExportDir = (PIMAGE_EXPORT_DIRECTORY)
OptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]
.VirtualAddress;
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
((ULONG)ExportDir + (ULONG)current->BaseAddress);
// DPRINT("Scanning %x %x %x\n", DPRINT("Scanning %x %x %x\n",ExportDir->Name,
// ExportDir->Name, current->BaseAddress,
// current->BaseAddress, (ExportDir->Name + current->BaseAddress));
// (ExportDir->Name + current->BaseAddress) DPRINT("Scanning %s %s\n",
// ); ExportDir->Name + current->BaseAddress, Name);
// DPRINT("Scanning %s\n",
// ExportDir->Name + current->BaseAddress
// );
if (strcmp(ExportDir->Name + current->BaseAddress, Name) == 0)
{
*Dll = current;
current->ReferenceCount++;
return STATUS_SUCCESS;
}
current = current->Next; if (strcmp(ExportDir->Name + current->BaseAddress, Name) == 0)
{
} while (current != & LdrDllListHead); *Dll = current;
current->ReferenceCount++;
return STATUS_SUCCESS;
}
current = current->Next;
} while (current != & LdrDllListHead);
DPRINT("Failed to find dll %s\n",Name); DPRINT("Failed to find dll %s\n",Name);
return -1; return -1;
} }
@ -700,61 +693,54 @@ LdrPerformRelocations (
* NOTE * NOTE
* *
*/ */
static static NTSTATUS LdrFixupImports(PIMAGE_NT_HEADERS NTHeaders,
NTSTATUS PVOID ImageBase)
LdrFixupImports (
PIMAGE_NT_HEADERS NTHeaders,
PVOID ImageBase
)
{ {
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory; PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
ULONG Ordinal; ULONG Ordinal;
PDLL Module; PDLL Module;
NTSTATUS Status; NTSTATUS Status;
/* /*
* Process each import module. * Process each import module.
*/ */
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY) ( ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)(
ImageBase ImageBase + NTHeaders->OptionalHeader
+ NTHeaders->OptionalHeader .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] .VirtualAddress);
.VirtualAddress
); while (ImportModuleDirectory->dwRVAModuleName)
while (ImportModuleDirectory->dwRVAModuleName) {
{ PVOID * ImportAddressList;
PVOID * ImportAddressList; PULONG FunctionNameList;
PULONG FunctionNameList; DWORD pName;
DWORD pName; PWORD pHint;
PWORD pHint;
Status = LdrLoadDll( DPRINT("ImportModule->Directory->dwRVAModuleName %s\n",
& Module, (PCHAR)(ImageBase + ImportModuleDirectory->dwRVAModuleName));
(PCHAR) (
ImageBase Status = LdrLoadDll(&Module,
+ ImportModuleDirectory->dwRVAModuleName (PCHAR)(ImageBase
) +ImportModuleDirectory->dwRVAModuleName));
); if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(Status)) {
{ return Status;
return Status; }
} /*
/* * Get the import address list.
* Get the import address list. */
*/ ImportAddressList = (PVOID *)(NTHeaders->OptionalHeader.ImageBase
ImportAddressList = (PVOID *) ( + ImportModuleDirectory->dwRVAFunctionAddressList);
NTHeaders->OptionalHeader.ImageBase
+ ImportModuleDirectory->dwRVAFunctionAddressList /*
); * Get the list of functions to import.
/* */
* Get the list of functions to import. if (ImportModuleDirectory->dwRVAFunctionNameList != 0)
*/ {
if (ImportModuleDirectory->dwRVAFunctionNameList != 0)
{
FunctionNameList = (PULONG) ( FunctionNameList = (PULONG) (
ImageBase ImageBase
+ ImportModuleDirectory->dwRVAFunctionNameList + ImportModuleDirectory->dwRVAFunctionNameList
); );
} }
else else
@ -797,6 +783,7 @@ LdrFixupImports (
); );
if ((*ImportAddressList) == NULL) if ((*ImportAddressList) == NULL)
{ {
dprintf("Failed to import %s\n", pName);
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
} }
@ -837,132 +824,116 @@ LdrFixupImports (
* NOTE * NOTE
* *
*/ */
PEPFUNC PEPFUNC LdrPEStartup (PVOID ImageBase,
LdrPEStartup ( HANDLE SectionHandle)
PVOID ImageBase,
HANDLE SectionHandle
)
{ {
NTSTATUS Status; NTSTATUS Status;
PEPFUNC EntryPoint; PEPFUNC EntryPoint;
PIMAGE_DOS_HEADER DosHeader; PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders; PIMAGE_NT_HEADERS NTHeaders;
/*
/* * Overlay DOS and WNT headers structures
* Overlay DOS and WNT headers structures * to the DLL's image.
* to the DLL's image. */
*/ DosHeader = (PIMAGE_DOS_HEADER) ImageBase;
DosHeader = (PIMAGE_DOS_HEADER) ImageBase; NTHeaders = (PIMAGE_NT_HEADERS) (ImageBase + DosHeader->e_lfanew);
NTHeaders = (PIMAGE_NT_HEADERS) (ImageBase + DosHeader->e_lfanew);
/* /*
* Initialize image sections. * Initialize image sections.
*/ */
LdrMapSections( LdrMapSections(NtCurrentProcess(),
NtCurrentProcess(), ImageBase,
ImageBase, SectionHandle,
SectionHandle, NTHeaders);
NTHeaders
); /*
/* * If the base address is different from the
* If the base address is different from the * one the DLL is actually loaded, perform any
* one the DLL is actually loaded, perform any * relocation.
* relocation. */
*/ if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase)
if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase) {
{ Status = LdrPerformRelocations(NTHeaders, ImageBase);
Status = LdrPerformRelocations( if (!NT_SUCCESS(Status))
NTHeaders, {
ImageBase dprintf("LdrPerformRelocations() failed\n");
); return NULL;
if (!NT_SUCCESS(Status)) }
{ }
dprintf("LdrPerformRelocations() failed\n");
return NULL; /*
} * If the DLL's imports symbols from other
} * modules, fixup the imported calls entry points.
/* */
* If the DLL's imports symbols from other if (NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
* modules, fixup the imported calls entry points. .VirtualAddress != 0)
*/ {
if (NTHeaders->OptionalHeader DPRINT("About to fixup imports\n");
.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] Status = LdrFixupImports(NTHeaders, ImageBase);
.VirtualAddress != 0) if (!NT_SUCCESS(Status))
{ {
Status = LdrFixupImports( dprintf("LdrFixupImports() failed\n");
NTHeaders, return NULL;
ImageBase }
); }
if (!NT_SUCCESS(Status))
{ /*
dprintf("LdrFixupImports() failed\n"); * Compute the DLL's entry point's address.
return NULL; */
} EntryPoint = (PEPFUNC) (ImageBase
} + NTHeaders->OptionalHeader.AddressOfEntryPoint);
/* DPRINT("LdrPEStartup() = %x\n",EntryPoint);
* Compute the DLL's entry point's address. return EntryPoint;
*/
EntryPoint = (PEPFUNC) (
ImageBase
+ NTHeaders->OptionalHeader.AddressOfEntryPoint
);
DPRINT("LdrPEStartup() = %x\n",EntryPoint);
return EntryPoint;
} }
NTSTATUS LdrUnloadDll(PDLL Dll) NTSTATUS LdrUnloadDll(PDLL Dll)
{ {
PDLLMAIN_FUNC Entrypoint;
PDLLMAIN_FUNC Entrypoint; NTSTATUS Status;
NTSTATUS Status;
if ( Dll == NULL || Dll == &LdrDllListHead )
return -1;
if ( Dll->ReferenceCount > 1 ) {
Dll->ReferenceCount--;
return STATUS_SUCCESS;
}
if ( Dll->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL == IMAGE_FILE_DLL ) {
Entrypoint =
(PDLLMAIN_FUNC) LdrPEStartup(
Dll->BaseAddress,
Dll->SectionHandle
);
if (Entrypoint != NULL)
{
DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
if (FALSE == Entrypoint(
Dll,
DLL_PROCESS_DETACH,
NULL
))
{
DPRINT("NTDLL.LDR: DLL failed to detach\n");
return -1;
}
else
{
DPRINT("NTDLL.LDR: DLL detached successfully\n");
}
}
else
{
DPRINT("NTDLL.LDR: Entrypoint is NULL for \n");
}
}
Status = ZwUnmapViewOfSection(
NtCurrentProcess(),
Dll->BaseAddress
);
ZwClose(Dll->SectionHandle);
return Status; if ( Dll == NULL || Dll == &LdrDllListHead )
return -1;
if ( Dll->ReferenceCount > 1 )
{
Dll->ReferenceCount--;
return STATUS_SUCCESS;
}
if ( Dll->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL == IMAGE_FILE_DLL ) {
Entrypoint = (PDLLMAIN_FUNC) LdrPEStartup(Dll->BaseAddress,
Dll->SectionHandle);
if (Entrypoint != NULL)
{
DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
if (FALSE == Entrypoint(Dll,
DLL_PROCESS_DETACH,
NULL))
{
DPRINT("NTDLL.LDR: DLL failed to detach\n");
return -1;
}
else
{
DPRINT("NTDLL.LDR: DLL detached successfully\n");
}
}
else
{
DPRINT("NTDLL.LDR: Entrypoint is NULL for \n");
}
}
Status = ZwUnmapViewOfSection(NtCurrentProcess(),
Dll->BaseAddress);
ZwClose(Dll->SectionHandle);
return Status;
} }
static IMAGE_RESOURCE_DIRECTORY_ENTRY * LdrGetNextEntry(IMAGE_RESOURCE_DIRECTORY *ResourceDir, LPCWSTR ResourceName, ULONG Offset) static IMAGE_RESOURCE_DIRECTORY_ENTRY * LdrGetNextEntry(IMAGE_RESOURCE_DIRECTORY *ResourceDir, LPCWSTR ResourceName, ULONG Offset)

View file

@ -147,14 +147,14 @@ static void print_address(PVOID address)
if (address >= current->Base && if (address >= current->Base &&
address < (current->Base + current->Length)) address < (current->Base + current->Length))
{ {
DbgPrint("<%w: %x>\n", current->Name, DbgPrint("<%w: %x>", current->Name,
address - current->Base); address - current->Base);
return; return;
} }
current_entry = current_entry->Flink; current_entry = current_entry->Flink;
} }
DbgPrint("<%x>\n", address); DbgPrint("<%x>", address);
} }
asmlinkage void exception_handler(unsigned int edi, asmlinkage void exception_handler(unsigned int edi,
@ -240,8 +240,9 @@ asmlinkage void exception_handler(unsigned int edi,
DbgPrint("Exception: %d(%x)\n",type,error_code&0xffff); DbgPrint("Exception: %d(%x)\n",type,error_code&0xffff);
} }
DbgPrint("CS:EIP %x:%x\n",cs&0xffff,eip); DbgPrint("CS:EIP %x:%x\n",cs&0xffff,eip);
DbgPrint("CS:EIP %x"); DbgPrint("CS:EIP %x:", cs&0xffff);
print_address(eip); print_address(eip);
DbgPrint("\n");
__asm__("movl %%cr2,%0\n\t" __asm__("movl %%cr2,%0\n\t"
: "=d" (cr2)); : "=d" (cr2));
__asm__("movl %%cr3,%0\n\t" __asm__("movl %%cr3,%0\n\t"
@ -301,6 +302,7 @@ asmlinkage void exception_handler(unsigned int edi,
{ {
// DbgPrint(" %.8x", stack[i]); // DbgPrint(" %.8x", stack[i]);
print_address(stack[i]); print_address(stack[i]);
DbgPrint(" ");
} }
} }
} }
@ -323,8 +325,8 @@ asmlinkage void exception_handler(unsigned int edi,
} }
} }
DPRINT1("Killing current task\n"); DbgPrint("\n");
for(;;); DbgPrint("Killing current task\n");
KeLowerIrql(PASSIVE_LEVEL); KeLowerIrql(PASSIVE_LEVEL);
if ((cs&0xffff) == USER_CS) if ((cs&0xffff) == USER_CS)
{ {

View file

@ -1,4 +1,4 @@
# $Id: makefile_rex,v 1.37 1999/11/15 15:56:16 ekohl Exp $ # $Id: makefile_rex,v 1.38 1999/11/25 10:47:57 dwelch Exp $
# #
# ReactOS Operating System # ReactOS Operating System
# #
@ -35,7 +35,7 @@ MM_OBJECTS = mm/mm.o mm/freelist.o mm/pool.o mm/virtual.o \
mm/mdl.o mm/zone.o mm/special.o mm/paging.o \ mm/mdl.o mm/zone.o mm/special.o mm/paging.o \
mm/section.o mm/marea.o mm/ppool.o mm/npool.o mm/section.o mm/marea.o mm/ppool.o mm/npool.o
MM_I386_OBJECTS = mm/i386/page.o MM_I386_OBJECTS = mm/i386/page.o mm/i386/memsafe.o
IO_OBJECTS = io/iomgr.o io/create.o io/irp.o io/device.o io/rw.o \ IO_OBJECTS = io/iomgr.o io/create.o io/irp.o io/device.o io/rw.o \
io/queue.o io/drvlck.o io/timer.o io/share.o io/errlog.o \ io/queue.o io/drvlck.o io/timer.o io/share.o io/errlog.o \

View file

@ -0,0 +1,74 @@
.globl _MmSafeCopyFromUser
.globl _MmSafeCopyFromUserEnd
.globl _MmSafeCopyToUser
.globl _MmSafeCopyToUserEnd
/*
* NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src,
* ULONG NumberOfBytes)
*/
_MmSafeCopyFromUser:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushl %ecx
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
/*
* Default return code
*/
movl $0,%eax
/*
* This is really a synthetic instruction since if we incur a
* pagefault then eax will be set to an appropiate STATUS code
*/
rep movsb
popl %ecx
popl %edi
popl %esi
ret
_MmSafeCopyFromUserEnd:
/*
* NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src,
* ULONG NumberOfBytes)
*/
_MmSafeCopyToUser:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushl %ecx
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
/*
* Default return code
*/
movl $0,%eax
/*
* This is really a synthetic instruction since if we incur a
* pagefault then eax will be set to an appropiate STATUS code
*/
rep movsb
popl %ecx
popl %edi
popl %esi
ret
_MemSafeCopyToUser:

View file

@ -19,8 +19,8 @@
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
static LIST_ENTRY SystemAreaList = {NULL,NULL}; static LIST_ENTRY SystemAreaList;
static KSPIN_LOCK SystemAreaListLock = {0,}; static KSPIN_LOCK SystemAreaListLock;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -573,6 +573,7 @@ NTSTATUS MmCreateMemoryArea(KPROCESSOR_MODE Mode,
+(PAGESIZE*2)); +(PAGESIZE*2));
if ((*BaseAddress)==0) if ((*BaseAddress)==0)
{ {
DPRINT("No suitable gap\n");
MmUnlockMemoryAreaListByMode(Mode,&oldlvl); MmUnlockMemoryAreaListByMode(Mode,&oldlvl);
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
@ -585,6 +586,7 @@ NTSTATUS MmCreateMemoryArea(KPROCESSOR_MODE Mode,
*BaseAddress, *BaseAddress,
Length)!=NULL) Length)!=NULL)
{ {
DPRINT("Memory area already occupied\n");
MmUnlockMemoryAreaList(*BaseAddress,&oldlvl); MmUnlockMemoryAreaList(*BaseAddress,&oldlvl);
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }

View file

@ -1,4 +1,4 @@
/* $Id: section.c,v 1.16 1999/11/24 11:51:52 dwelch Exp $ /* $Id: section.c,v 1.17 1999/11/25 10:47:57 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -366,6 +366,8 @@ NTSTATUS STDCALL NtMapViewOfSection(HANDLE SectionHandle,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("ObReferenceObjectByHandle(ProcessHandle, ...) failed (%x)\n",
Status);
ObDereferenceObject(Section); ObDereferenceObject(Section);
return Status; return Status;
} }

View file

@ -568,14 +568,21 @@ NTSTATUS STDCALL NtWriteVirtualMemory(IN HANDLE ProcessHandle,
KeAttachProcess(Process); KeAttachProcess(Process);
DPRINT("Attached to process copying memory\n");
SystemAddress = MmGetSystemAddressForMdl(Mdl); SystemAddress = MmGetSystemAddressForMdl(Mdl);
memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite); memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite);
DPRINT("Done copy\n");
KeDetachProcess(); KeDetachProcess();
ObDereferenceObject(Process); ObDereferenceObject(Process);
*NumberOfBytesWritten = NumberOfBytesToWrite; *NumberOfBytesWritten = NumberOfBytesToWrite;
DPRINT("Finished NtWriteVirtualMemory()\n");
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -1,4 +1,4 @@
/* $Id: port.c,v 1.9 1999/11/24 11:51:53 dwelch Exp $ /* $Id: port.c,v 1.10 1999/11/25 10:47:58 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -25,14 +25,17 @@
#include <string.h> #include <string.h>
#include <internal/string.h> #include <internal/string.h>
//#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* TYPES ********************************************************************/ /* TYPES ********************************************************************/
#define EPORT_WAIT_FOR_CONNECT (1) #define EPORT_INACTIVE (0)
#define EPORT_WAIT_FOR_ACCEPT (2) #define EPORT_WAIT_FOR_CONNECT (1)
#define EPORT_WAIT_FOR_COMPLETE (3) #define EPORT_WAIT_FOR_ACCEPT (2)
#define EPORT_CONNECTED (4) #define EPORT_WAIT_FOR_COMPLETE_SRV (3)
#define EPORT_WAIT_FOR_COMPLETE_CLT (4)
#define EPORT_CONNECTED (5)
typedef struct _QUEUED_MESSAGE typedef struct _QUEUED_MESSAGE
{ {
@ -41,7 +44,6 @@ typedef struct _QUEUED_MESSAGE
PVOID Buffer; PVOID Buffer;
DWORD Flags; DWORD Flags;
PEPROCESS Sender; PEPROCESS Sender;
PMDL BufferMdl;
} QUEUED_MESSAGE, *PQUEUED_MESSAGE; } QUEUED_MESSAGE, *PQUEUED_MESSAGE;
typedef struct _EPORT typedef struct _EPORT
@ -49,8 +51,11 @@ typedef struct _EPORT
KSPIN_LOCK Lock; KSPIN_LOCK Lock;
ULONG State; ULONG State;
KEVENT Event; KEVENT Event;
struct _EPORT* ForeignPort; struct _EPORT* OtherPort;
ULONG NumberOfQueuedMessages;
QUEUED_MESSAGE Msg; QUEUED_MESSAGE Msg;
PEPROCESS ConnectingProcess;
struct _EPORT* ConnectingPort;
} EPORT, *PEPORT; } EPORT, *PEPORT;
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
@ -84,6 +89,18 @@ NTSTATUS NiInitPort(VOID)
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
static NTSTATUS NiInitializePort(PEPORT Port)
{
memset(Port, 0, sizeof(EPORT));
KeInitializeSpinLock(&Port->Lock);
KeInitializeEvent(&Port->Event, NotificationEvent, FALSE);
Port->State = EPORT_INACTIVE;
Port->OtherPort = NULL;
Port->NumberOfQueuedMessages = 0;
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle, NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle,
ACCESS_MASK DesiredAccess, ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_ATTRIBUTES ObjectAttributes,
@ -91,9 +108,10 @@ NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle,
DWORD a4) DWORD a4)
{ {
PEPORT Port; PEPORT Port;
NTSTATUS Status;
Port = ObCreateObject(PortHandle, Port = ObCreateObject(PortHandle,
DesiredAccess, 1, // DesiredAccess
ObjectAttributes, ObjectAttributes,
ExPortType); ExPortType);
if (Port == NULL) if (Port == NULL)
@ -101,53 +119,60 @@ NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle,
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
KeInitializeSpinLock(&Port->Lock); Status = NiInitializePort(Port);
KeInitializeEvent(&Port->Event, NotificationEvent, FALSE);
Port->State = EPORT_WAIT_FOR_CONNECT;
Port->ForeignPort = NULL;
return(STATUS_SUCCESS); return(Status);
} }
NTSTATUS STDCALL NtAcceptConnectPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtAcceptConnectPort (IN HANDLE PortHandle,
OUT PHANDLE ConnectedPort, OUT PHANDLE OurPortHandle,
DWORD a2, DWORD a2,
DWORD a3, DWORD a3,
DWORD a4, DWORD a4,
DWORD a5) DWORD a5)
{ {
NTSTATUS Status; NTSTATUS Status;
PEPORT Port; PEPORT NamedPort;
PEPORT OurPort;
Status = ObReferenceObjectByHandle(PortHandle, Status = ObReferenceObjectByHandle(PortHandle,
0, /* AccessRequired */ 1, /* AccessRequired */
ExPortType, ExPortType,
UserMode, UserMode,
(PVOID*)&Port, (PVOID*)&NamedPort,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return(Status); return(Status);
} }
if (Port->State != EPORT_WAIT_FOR_ACCEPT) if (NamedPort->State != EPORT_WAIT_FOR_ACCEPT)
{ {
ObDereferenceObject(NamedPort);
return(STATUS_INVALID_PARAMETER); return(STATUS_INVALID_PARAMETER);
} }
Status = ObCreateHandle(PsGetCurrentProcess(), /*
Port->ForeignPort, * Create a port object for our side of the connection
0, /* DesiredAccess */ */
FALSE, OurPort = ObCreateObject(OurPortHandle,
ConnectedPort); 1,
if (!NT_SUCCESS(Status)) NULL,
{ ExPortType);
return(Status);
}
KeSetEvent(&Port->ForeignPort->Event, IO_NO_INCREMENT, FALSE); /*
* Connect the two port
*/
OurPort->OtherPort = NamedPort->ConnectingPort;
OurPort->OtherPort->OtherPort = OurPort;
OurPort->State = EPORT_WAIT_FOR_COMPLETE_SRV;
OurPort->OtherPort->State = EPORT_WAIT_FOR_COMPLETE_CLT;
Port->ForeignPort->State = EPORT_WAIT_FOR_COMPLETE; NamedPort->State = EPORT_INACTIVE;
NamedPort->ConnectingProcess = NULL;
NamedPort->ConnectingPort = NULL;
ObDereferenceObject(NamedPort);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -156,23 +181,29 @@ NTSTATUS STDCALL NtAcceptConnectPort (IN HANDLE PortHandle,
NTSTATUS STDCALL NtCompleteConnectPort (HANDLE PortHandle) NTSTATUS STDCALL NtCompleteConnectPort (HANDLE PortHandle)
{ {
NTSTATUS Status; NTSTATUS Status;
PEPORT Port; PEPORT OurPort;
Status = ObReferenceObjectByHandle(PortHandle, Status = ObReferenceObjectByHandle(PortHandle,
0, /* AccessRequired */ 1, /* AccessRequired */
ExPortType, ExPortType,
UserMode, UserMode,
(PVOID*)&Port, (PVOID*)&OurPort,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return(Status); return(Status);
} }
Port->ForeignPort->State = EPORT_CONNECTED; if (OurPort->State != EPORT_WAIT_FOR_COMPLETE_SRV)
Port->State = EPORT_CONNECTED; {
ObDereferenceObject(OurPort);
return(Status);
}
KeSetEvent(&Port->ForeignPort->Event, IO_NO_INCREMENT, FALSE); OurPort->State = EPORT_CONNECTED;
OurPort->OtherPort->State = EPORT_CONNECTED;
KeSetEvent(&OurPort->OtherPort->Event, IO_NO_INCREMENT, FALSE);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -186,46 +217,66 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort,
IN DWORD a5, IN DWORD a5,
IN DWORD a6, IN DWORD a6,
IN ULONG Flags) IN ULONG Flags)
/*
* FUNCTION: Connect to a named port and wait for the other side to
* accept the connection
*/
{ {
NTSTATUS Status; NTSTATUS Status;
PEPORT ForeignPort; PEPORT NamedPort;
PEPORT Port; PEPORT OurPort;
HANDLE OurPortHandle;
Status = ObReferenceObjectByName(PortName, Status = ObReferenceObjectByName(PortName,
0, 0,
NULL, NULL,
0, /* DesiredAccess */ 1, /* DesiredAccess */
ExPortType, ExPortType,
UserMode, UserMode,
NULL, NULL,
(PVOID*)&ForeignPort); (PVOID*)&NamedPort);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return(Status); return(Status);
} }
if (ForeignPort->State != EPORT_WAIT_FOR_CONNECT) if (NamedPort->State != EPORT_WAIT_FOR_CONNECT)
{ {
ObDereferenceObject(NamedPort);
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
Port = ObCreateObject(ConnectedPort, /*
0, /* DesiredAccess */ * Create a port to represent our side of the connection
PortAttributes, */
ExPortType); OurPort = ObCreateObject(&OurPortHandle,
if (Port == NULL) 1,
{ PortAttributes,
return(STATUS_UNSUCCESSFUL); ExPortType);
} NiInitializePort(OurPort);
KeInitializeSpinLock(&Port->Lock); /*
KeInitializeEvent(&Port->Event, NotificationEvent, FALSE); *
Port->State = EPORT_WAIT_FOR_ACCEPT; */
Port->ForeignPort = ForeignPort; NamedPort->ConnectingProcess = PsGetCurrentProcess();
NamedPort->State = EPORT_WAIT_FOR_ACCEPT;
NamedPort->ConnectingPort = OurPort;
ForeignPort->State = EPORT_WAIT_FOR_ACCEPT; /*
* Tell the other side they have a connection
*/
KeSetEvent(&NamedPort->Event, IO_NO_INCREMENT, FALSE);
KeSetEvent(&ForeignPort->Event, IO_NO_INCREMENT, FALSE); /*
* Wait for them to accept our connection
*/
KeWaitForSingleObject(&NamedPort->Event,
UserRequest,
UserMode,
FALSE,
NULL);
*ConnectedPort = OurPortHandle;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -240,21 +291,36 @@ NTSTATUS STDCALL NtImpersonateClientOfPort (IN HANDLE PortHandle,
NTSTATUS STDCALL NtListenPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtListenPort (IN HANDLE PortHandle,
IN DWORD QueueSize /* guess */) IN DWORD QueueSize /* guess */)
/*
* FUNCTION: Listen on a named port and wait for a connection attempt
*/
{ {
NTSTATUS Status; NTSTATUS Status;
PEPORT Port; PEPORT Port;
DPRINT("NtListenPort(PortHandle %x, QueueSize %d)\n",
PortHandle, QueueSize);
Status = ObReferenceObjectByHandle(PortHandle, Status = ObReferenceObjectByHandle(PortHandle,
0, /* AccessRequired */ 1, /* AccessRequired */
ExPortType, ExPortType,
UserMode, UserMode,
(PVOID*)&Port, (PVOID*)&Port,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Failed to reference object (status %x)\n",
Status);
return(Status); return(Status);
} }
if (Port->State != EPORT_INACTIVE)
{
ObDereferenceObject(Port);
return(STATUS_INVALID_PARAMETER);
}
Port->State = EPORT_WAIT_FOR_CONNECT;
Status = KeWaitForSingleObject(&Port->Event, Status = KeWaitForSingleObject(&Port->Event,
UserRequest, UserRequest,
UserMode, UserMode,
@ -276,14 +342,14 @@ NTSTATUS STDCALL NtQueryInformationPort (IN HANDLE PortHandle,
NTSTATUS STDCALL NtReplyPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtReplyPort (IN HANDLE PortHandle,
IN PLPC_REPLY LpcReply /* guess */) IN PLPC_MESSAGE LpcReply /* guess */)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
NTSTATUS STDCALL NtReplyWaitReceivePort ( IN HANDLE PortHandle, NTSTATUS STDCALL NtReplyWaitReceivePort ( IN HANDLE PortHandle,
IN PLPC_REPLY LpcReply, /* guess */ IN PLPC_MESSAGE LpcReply, /* guess */
OUT PLPC_MESSAGE LpcMessage, /* guess */ OUT PLPC_MESSAGE LpcMessage, /* guess */
OUT PULONG MessageLength /* guess */) OUT PULONG MessageLength /* guess */)
{ {
@ -292,7 +358,7 @@ NTSTATUS STDCALL NtReplyWaitReceivePort ( IN HANDLE PortHandle,
NTSTATUS STDCALL NtReplyWaitReplyPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtReplyWaitReplyPort (IN HANDLE PortHandle,
IN OUT PLPC_REPLY LpcReply /* guess */) IN OUT PLPC_MESSAGE LpcReply /* guess */)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
@ -301,11 +367,19 @@ NTSTATUS STDCALL NtReplyWaitReplyPort (IN HANDLE PortHandle,
NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle,
IN PLPC_MESSAGE LpcMessage /* guess */) IN PLPC_MESSAGE LpcMessage /* guess */)
{ {
NTSTATUS Status; return(NtRequestWaitReplyPort(PortHandle, NULL, LpcMessage));
}
NTSTATUS STDCALL NtRequestWaitReplyPort(IN HANDLE PortHandle,
IN OUT PLPC_MESSAGE LpcReply, /* guess */
OUT PLPC_MESSAGE LpcMessage /* guess */)
{
NTSTATUS Status;
PEPORT Port; PEPORT Port;
Status = ObReferenceObjectByHandle(PortHandle, Status = ObReferenceObjectByHandle(PortHandle,
0, /* AccessRequired */ 1, /* AccessRequired */
ExPortType, ExPortType,
UserMode, UserMode,
(PVOID*)&Port, (PVOID*)&Port,
@ -315,29 +389,61 @@ NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle,
return(Status); return(Status);
} }
Port->Msg.Type = LpcMessage->Type; if (LpcMessage != NULL)
Port->Msg.Length = LpcMessage->Length; {
Port->Msg.Buffer = LpcMessage->Buffer; /*
Port->Msg.Flags = LpcMessage->Flags; * Put the message on the other port's queue
Port->Msg.Sender = PsGetCurrentProcess(); */
Port->Msg.BufferMdl = MmCreateMdl(NULL, Port->Msg.Type = LpcMessage->Type;
LpcMessage->Buffer, Port->Msg.Length = LpcMessage->Length;
LpcMessage->Length); Port->Msg.Buffer = ExAllocatePool(NonPagedPool, Port->Msg.Length);
MmProbeAndLockPages(Port->Msg.BufferMdl, memcpy(Port->Msg.Buffer, LpcMessage->Buffer, Port->Msg.Length);
UserMode, Port->Msg.Flags = LpcMessage->Flags;
IoReadAccess); Port->Msg.Sender = PsGetCurrentProcess();
Port->NumberOfQueuedMessages++;
/*
* Wake up the other side (if it's waiting)
*/
KeSetEvent(&Port->OtherPort->Event, IO_NO_INCREMENT, FALSE);
}
/*
* If we aren't waiting for a reply then return
*/
if (LpcReply == NULL)
{
ObDereferenceObject(Port);
return(STATUS_SUCCESS);
}
/*
* Wait the other side to reply to you
*/
KeWaitForSingleObject(&Port->Event,
UserRequest,
UserMode,
FALSE,
NULL);
/*
* Copy the received message into the process's address space
*/
LpcReply->Length = Port->OtherPort->Msg.Length;
LpcReply->Type = Port->OtherPort->Msg.Type;
memcpy(LpcReply->Buffer, Port->OtherPort->Msg.Buffer, LpcReply->Length);
LpcReply->Flags = Port->OtherPort->Msg.Flags;
/*
* Deallocate the message and remove it from the other side's queue
*/
ExFreePool(Port->OtherPort->Msg.Buffer);
Port->OtherPort->NumberOfQueuedMessages--;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL NtRequestWaitReplyPort(IN HANDLE PortHandle,
IN OUT PLPC_REPLY LpcReply, /* guess */
IN TIME* TimeToWait /* guess */)
{
UNIMPLEMENTED;
}
/********************************************************************** /**********************************************************************
* NAME SYSTEM * NAME SYSTEM

View file

@ -1,4 +1,4 @@
/* $Id: init.c,v 1.2 1999/10/24 17:07:57 rex Exp $ /* $Id: init.c,v 1.3 1999/11/25 10:47:58 dwelch Exp $
* *
* init.c - Session Manager initialization * init.c - Session Manager initialization
* *
@ -63,6 +63,7 @@ InitSessionManager(
#endif #endif
/* Start the simple shell (shell.exe) */ /* Start the simple shell (shell.exe) */
DisplayString(L"Executing shell\n");
RtlInitUnicodeString(&CmdLineW, RtlInitUnicodeString(&CmdLineW,
L"\\??\\C:\\reactos\\system32\\shell.exe"); L"\\??\\C:\\reactos\\system32\\shell.exe");
Status = RtlCreateUserProcess(&CmdLineW, Status = RtlCreateUserProcess(&CmdLineW,