Miscellaneous implementation of kernel32 stubs.

Changed the implementation of ReadFileEx.

svn path=/trunk/; revision=678
This commit is contained in:
Boudewijn Dekker 1999-10-02 20:20:44 +00:00
parent 3174c5069a
commit 1d786dd865
7 changed files with 460 additions and 204 deletions

View file

@ -20,6 +20,9 @@
/* FUNCTIONS ****************************************************************/
WINBOOL STDCALL WriteFile(HANDLE hFile,
LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
@ -74,13 +77,13 @@ WINBOOL STDCALL WriteFile(HANDLE hFile,
return(TRUE);
}
WINBOOL STDCALL KERNEL32_ReadFile(HANDLE hFile,
WINBOOL STDCALL ReadFile(HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverLapped,
LPOVERLAPPED_COMPLETION_ROUTINE
lpCompletionRoutine)
LPOVERLAPPED lpOverLapped)
{
HANDLE hEvent = NULL;
LARGE_INTEGER Offset;
@ -106,7 +109,7 @@ WINBOOL STDCALL KERNEL32_ReadFile(HANDLE hFile,
errCode = NtReadFile(hFile,
hEvent,
(PIO_APC_ROUTINE)lpCompletionRoutine,
NULL,
NULL,
IoStatusBlock,
lpBuffer,
@ -127,18 +130,61 @@ WINBOOL STDCALL KERNEL32_ReadFile(HANDLE hFile,
return(TRUE);
}
WINBOOL STDCALL ReadFile(HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverLapped)
VOID ApcRoutine(PVOID ApcContext, struct _IO_STATUS_BLOCK* IoStatusBlock, ULONG NumberOfBytesTransfered)
{
return(KERNEL32_ReadFile(hFile,
lpBuffer,
nNumberOfBytesToRead,
lpNumberOfBytesRead,
lpOverLapped,
NULL));
DWORD dwErrorCode;
LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine = (LPOVERLAPPED_COMPLETION_ROUTINE)ApcContext;
dwErrorCode = RtlNtStatusToDosError( IoStatusBlock->Status);
lpCompletionRoutine( dwErrorCode, NumberOfBytesTransfered, (LPOVERLAPPED)IoStatusBlock );
}
WINBOOL WriteFileEx(
HANDLE hFile,
LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPOVERLAPPED lpOverLapped,
LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
{
LARGE_INTEGER Offset;
NTSTATUS errCode;
PIO_STATUS_BLOCK IoStatusBlock;
PLARGE_INTEGER ptrOffset;
DPRINT("WriteFileEx(hFile %x)\n",hFile);
if (lpOverLapped == NULL)
return FALSE;
Offset.u.LowPart = lpOverLapped->Offset;
Offset.u.HighPart = lpOverLapped->OffsetHigh;
lpOverLapped->Internal = STATUS_PENDING;
IoStatusBlock = (PIO_STATUS_BLOCK)lpOverLapped;
ptrOffset = &Offset;
errCode = NtWriteFile(hFile,
NULL,
ApcRoutine,
lpCompletionRoutine,
IoStatusBlock,
(PVOID)lpBuffer,
nNumberOfBytesToWrite,
ptrOffset,
NULL);
if (!NT_SUCCESS(errCode))
{
SetLastError(RtlNtStatusToDosError(errCode));
DPRINT("WriteFileEx() failed\n");
return FALSE;
}
DPRINT("WriteFileEx() succeeded\n");
return(TRUE);
}
WINBOOL STDCALL ReadFileEx(HANDLE hFile,
@ -147,10 +193,36 @@ WINBOOL STDCALL ReadFileEx(HANDLE hFile,
LPOVERLAPPED lpOverLapped,
LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
return(KERNEL32_ReadFile(hFile,
LARGE_INTEGER Offset;
NTSTATUS errCode;
PIO_STATUS_BLOCK IoStatusBlock;
PLARGE_INTEGER ptrOffset;
if (lpOverLapped == NULL)
return FALSE;
Offset.u.LowPart = lpOverLapped->Offset;
Offset.u.HighPart = lpOverLapped->OffsetHigh;
lpOverLapped->Internal = STATUS_PENDING;
IoStatusBlock = (PIO_STATUS_BLOCK)lpOverLapped;
ptrOffset = &Offset;
errCode = NtReadFile(hFile,
NULL,
ApcRoutine,
lpCompletionRoutine,
IoStatusBlock,
lpBuffer,
nNumberOfBytesToRead,
NULL,
lpOverLapped,
lpCompletionRoutine));
ptrOffset,
NULL);
if (!NT_SUCCESS(errCode))
{
SetLastError(RtlNtStatusToDosError(errCode));
return(FALSE);
}
return(TRUE);
}

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.25 1999/09/27 20:58:44 ariadne Exp $
# $Id: makefile,v 1.26 1999/10/02 20:20:42 ariadne Exp $
#
# ReactOS Operating System
#
@ -32,7 +32,7 @@ FILE_OBJECTS = file/file.o file/curdir.o file/lfile.o file/dir.o \
file/create.o file/find.o file/copy.o file/pipe.o \
file/move.o file/lock.o file/rw.o file/delete.o
MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o mem/section.o
MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o mem/section.o mem/isbad.o
NLS_OBJECTS = nls/codepage.o nls/cpmisc.o nls/cptable.o\
nls/cp37.o nls/cp437.o nls/cp500.o nls/cp737.o nls/cp775.o nls/cp850.o nls/cp852.o nls/cp855.o nls/cp857.o\

View file

@ -0,0 +1,111 @@
#include <windows.h>
WINBOOL
STDCALL
IsBadReadPtr( CONST VOID *lp, UINT ucb )
{
MEMORY_BASIC_INFORMATION MemoryInformation;
if ( ucb == 0 )
return FALSE;
VirtualQuery( lp, &MemoryInformation, sizeof(MEMORY_BASIC_INFORMATION) );
if ( MemoryInformation.State != MEM_COMMIT )
return FALSE;
if ( MemoryInformation.RegionSize < ucb )
return FALSE;
if ( MemoryInformation.Protect == PAGE_EXECUTE )
return FALSE;
if ( MemoryInformation.Protect == PAGE_NOACCESS )
return FALSE;
return TRUE;
}
WINBOOL
STDCALL
IsBadHugeReadPtr( CONST VOID *lp, UINT ucb )
{
return IsBadReadPtr(lp,ucb);
}
WINBOOL
STDCALL
IsBadCodePtr( FARPROC lpfn )
{
MEMORY_BASIC_INFORMATION MemoryInformation;
VirtualQuery( lpfn, &MemoryInformation, sizeof(MEMORY_BASIC_INFORMATION) );
if ( MemoryInformation.State != MEM_COMMIT )
return FALSE;
if ( MemoryInformation.Protect == PAGE_EXECUTE || MemoryInformation.Protect == PAGE_EXECUTE_READ)
return TRUE;
return FALSE;
}
WINBOOL
STDCALL IsBadWritePtr( LPVOID lp, UINT ucb )
{
MEMORY_BASIC_INFORMATION MemoryInformation;
if ( ucb == 0 )
return FALSE;
VirtualQuery( lp, &MemoryInformation, sizeof(MEMORY_BASIC_INFORMATION) );
if ( MemoryInformation.State != MEM_COMMIT )
return FALSE;
if ( MemoryInformation.RegionSize < ucb )
return FALSE;
if ( MemoryInformation.Protect == PAGE_READONLY)
return FALSE;
if ( MemoryInformation.Protect == PAGE_EXECUTE || MemoryInformation.Protect == PAGE_EXECUTE_READ)
return FALSE;
if ( MemoryInformation.Protect == PAGE_NOACCESS )
return FALSE;
return TRUE;
}
WINBOOL
STDCALL
IsBadHugeWritePtr(
LPVOID lp,
UINT ucb
)
{
return IsBadWritePtr(lp,ucb);
}
WINBOOL
STDCALL
IsBadStringPtrW( LPCWSTR lpsz, UINT ucchMax )
{
UINT Len = wcsnlen(lpsz+1,ucchMax>>1);
return IsBadReadPtr(lpsz,Len<<1);
}
WINBOOL
STDCALL
IsBadStringPtrA( LPCSTR lpsz, UINT ucchMax )
{
UINT Len = strnlen(lpsz+1,ucchMax);
return IsBadReadPtr(lpsz,Len);
}

View file

@ -101,3 +101,80 @@ WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess,
}
return(TRUE);
}
WINBOOL
STDCALL
VirtualLock (
LPVOID lpAddress,
DWORD dwSize
)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtLockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
return TRUE;
}
DWORD
STDCALL
VirtualQuery (
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
{
return VirtualQueryEx (NtCurrentProcess(),lpAddress, lpBuffer, dwLength );
}
#define MemoryBasicInformation 0
DWORD
STDCALL
VirtualQueryEx (
HANDLE hProcess,
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
{
NTSTATUS Status;
ULONG ResultLength;
Status = NtQueryVirtualMemory(
hProcess,(LPVOID)lpAddress,
MemoryBasicInformation, lpBuffer,
sizeof(MEMORY_BASIC_INFORMATION),
&ResultLength );
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return ResultLength;
}
return ResultLength;
}
WINBOOL
STDCALL
VirtualUnlock (
LPVOID lpAddress,
DWORD dwSize
)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtUnlockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
return TRUE;
}

View file

@ -346,3 +346,153 @@ FreeEnvironmentStringsW(
return TRUE;
}
int ExpandVariableA(
LPCSTR lpSrc, LPSTR lpDst, DWORD nSize , DWORD *nWritten)
{
int nVar = 0;
LPSTR lpVar;
LPSTR lpEnd;
if ( nWritten == NULL )
return -1;
if ( *lpSrc != '%' ) {
return -1;
}
lpVar = (LPSTR)lpSrc;
lpVar++;
lpEnd = strchr( lpVar, '%' );
if ( lpEnd == NULL ) {
return -1;
}
else
*lpEnd = 0;
nWritten = GetEnvironmentVariableA(lpVar,lpDst,nSize);
*lpEnd = '%';
if ( nWritten == 0 )
return -1;
if ( nWritten > nSize )
return -1;
return (lpEnd - lpVar) -1;
}
DWORD STDCALL ExpandEnvironmentStringsA(
LPCSTR lpSrc, LPSTR lpDst, DWORD nSize
)
{
DWORD v;
DWORD bw;
while(*lpSrc != 0 && nSize > 0 )
{
if ( *lpSrc == '%' ) {
v = ExpandVariableA(lpSrc,lpDst,nSize , &bw);
if ( v == -1 ) {
*lpDst = *lpSrc;
lpDst++;
lpSrc++;
nSize--;
}
else {
lpSrc+=v;
lpDst+=bw;
nSize-=bw;
}
}
else {
*lpDst = *lpSrc;
lpDst++;
lpSrc++;
nSize--;
}
}
}
int ExpandVariableW(
LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize , DWORD *nWritten)
{
LPWSTR lpVar;
LPWSTR lpEnd;
if ( nWritten == NULL )
return -1;
if ( *lpSrc != L'%' ) {
return -1;
}
lpVar = (LPWSTR)lpSrc;
lpVar++;
lpEnd = wcschr( lpVar, L'%' );
if ( lpEnd == NULL ) {
return -1;
}
else
*lpEnd = 0;
nWritten = GetEnvironmentVariableW(lpVar,lpDst,nSize);
*lpEnd = L'%';
if ( nWritten == 0 )
return -1;
if ( nWritten > nSize )
return -1;
return ((lpEnd - lpVar)/2) -1;
}
DWORD STDCALL ExpandEnvironmentStringsW(
LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize
)
{
DWORD v;
DWORD bw;
while(*lpSrc != 0 && nSize > 0 )
{
if ( *lpSrc == L'%' ) {
v = ExpandVariableW(lpSrc,lpDst,nSize , &bw);
if ( v == -1 ) {
*lpDst = *lpSrc;
lpDst++;
lpSrc++;
nSize--;
}
else {
lpSrc+=v;
lpDst+=bw;
nSize-=bw;
}
}
else {
*lpDst = *lpSrc;
lpDst++;
lpSrc++;
nSize--;
}
}
}

View file

@ -1,4 +1,4 @@
/* $Id: stubs.c,v 1.4 1999/09/27 20:58:44 ariadne Exp $
/* $Id: stubs.c,v 1.5 1999/10/02 20:20:44 ariadne Exp $
*
* KERNEL32.DLL stubs (unimplemented functions)
* Remove from this file, if you implement them.
@ -815,30 +815,6 @@ ExitVDM (
}
DWORD
STDCALL
ExpandEnvironmentStringsW (
LPCWSTR lpSrc,
LPWSTR lpDst,
DWORD nSize
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
DWORD
STDCALL
ExpandEnvironmentStringsA (
LPCSTR lpSrc,
LPSTR lpDst,
DWORD nSize
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
DWORD
@ -2751,87 +2727,6 @@ InvalidateConsoleDIBits (
}
WINBOOL
STDCALL
IsBadCodePtr (
FARPROC lpfn
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
IsBadHugeReadPtr (
CONST VOID * lp,
UINT ucb
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
IsBadHugeWritePtr (
LPVOID lp,
UINT ucb
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
IsBadReadPtr (
CONST VOID * lp,
UINT ucb
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
IsBadStringPtrA (
LPCSTR lpsz,
UINT ucchMax
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
IsBadStringPtrW (
LPCWSTR lpsz,
UINT ucchMax
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
IsBadWritePtr (
LPVOID lp,
UINT ucb
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
@ -3893,16 +3788,6 @@ SizeofResource (
}
WINBOOL
STDCALL
TerminateThread (
HANDLE hThread,
DWORD dwExitCode
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
LPVOID
@ -4063,56 +3948,8 @@ VirtualBufferExceptionHandler (
}
WINBOOL
STDCALL
VirtualLock (
LPVOID lpAddress,
DWORD dwSize
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
DWORD
STDCALL
VirtualQuery (
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
DWORD
STDCALL
VirtualQueryEx (
HANDLE hProcess,
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
WINBOOL
STDCALL
VirtualUnlock (
LPVOID lpAddress,
DWORD dwSize
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL
STDCALL
@ -4209,19 +4046,7 @@ WriteConsoleInputVDMW (
}
WINBOOL
STDCALL
WriteFileEx (
HANDLE hFile,
LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPOVERLAPPED lpOverlapped,
LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
WINBOOL

View file

@ -269,6 +269,27 @@ DWORD STDCALL ResumeThread(HANDLE hThread)
return PreviousResumeCount;
}
WINBOOL
STDCALL
TerminateThread (
HANDLE hThread,
DWORD dwExitCode
)
{
NTSTATUS errCode;
errCode = NtTerminateThread(hThread,
dwExitCode);
if (!NT_SUCCESS(errCode))
{
SetLastError(RtlNtStatusToDosError(errCode));
return FALSE;
}
return TRUE;
}
DWORD STDCALL SuspendThread(HANDLE hThread)
{
NTSTATUS errCode;