Split out the resource functions for finer control of debug output.

svn path=/trunk/; revision=3832
This commit is contained in:
Robert Dickenson 2002-12-08 15:57:40 +00:00
parent 688e9b05d9
commit 61bb7ba7ad
9 changed files with 1407 additions and 1194 deletions

269
reactos/lib/ntdll/ldr/res.c Normal file
View file

@ -0,0 +1,269 @@
/* $Id: res.c,v 1.1 2002/12/08 15:57:40 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ntdll/ldr/res.c
* PURPOSE: Resource access for PE executables
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
* Robert Dickenson (robd@mok.lvcm.com)
*/
/*
* TODO:
* - any comments ??
*/
/* INCLUDES *****************************************************************/
#include <reactos/config.h>
#include <ddk/ntddk.h>
#include <windows.h>
#include <string.h>
#include <wchar.h>
#include <ntdll/ldr.h>
#include <ntos/minmax.h>
//#define NDEBUG
#define DBG
#include <ntdll/ntdll.h>
/* PROTOTYPES ****************************************************************/
/* FUNCTIONS *****************************************************************/
/*
Status = LdrFindResource_U (hModule,
&ResourceInfo,
RESOURCE_DATA_LEVEL,
&ResourceDataEntry);
*/
NTSTATUS STDCALL
LdrFindResource_U(PVOID BaseAddress,
PLDR_RESOURCE_INFO ResourceInfo,
ULONG Level,
PIMAGE_RESOURCE_DATA_ENTRY* ResourceDataEntry)
{
PIMAGE_RESOURCE_DIRECTORY ResDir;
PIMAGE_RESOURCE_DIRECTORY ResBase;
PIMAGE_RESOURCE_DIRECTORY_ENTRY ResEntry;
NTSTATUS Status = STATUS_SUCCESS;
ULONG EntryCount;
PWCHAR ws;
ULONG i;
ULONG Id;
//DPRINT("LdrFindResource_U()\n");
DPRINT("LdrFindResource_U(%08x, %08x, %d, %08x)\n", BaseAddress, ResourceInfo, Level, ResourceDataEntry);
/* Get the pointer to the resource directory */
ResDir = (PIMAGE_RESOURCE_DIRECTORY)RtlImageDirectoryEntryToData(BaseAddress,
TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &i);
if (ResDir == NULL) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
DPRINT("ResourceDirectory: %x Size: %d\n", (ULONG)ResDir, (int)i);
ResBase = ResDir;
/* Let's go into resource tree */
for (i = 0; i < Level; i++) {
DPRINT("ResDir: %x Level: %d\n", (ULONG)ResDir, i);
Id = ((PULONG)ResourceInfo)[i];
// ResourceInfo.Type = (ULONG)lpType;
// ResourceInfo.Name = (ULONG)lpName;
// ResourceInfo.Language = (ULONG)wLanguage;
EntryCount = ResDir->NumberOfNamedEntries;
DPRINT(" Id: %d NumberOfNamedEntries: %d\n", Id, EntryCount);
ResEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(ResDir + 1);
//DPRINT("ResEntry %x\n", (ULONG)ResEntry);
if (Id & 0xFFFF0000) {
/* Resource name is a unicode string */
DPRINT("ResEntry %x - Resource name is a unicode string\n", (ULONG)ResEntry);
DPRINT("EntryCount %d\n", (ULONG)EntryCount);
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
if (ResEntry->Name & 0x80000000) {
ws = (PWCHAR)((ULONG)ResDir + (ResEntry->Name & 0x7FFFFFFF));
if (!wcsncmp((PWCHAR)Id, ws + 1, *ws) &&
wcslen((PWCHAR)Id) == (int)*ws) {
goto found;
}
}
}
} else {
/* We use ID number instead of string */
DPRINT("ResEntry %x - Resource ID number instead of string\n", (ULONG)ResEntry);
DPRINT("EntryCount %d\n", (ULONG)EntryCount);
ResEntry += EntryCount;
EntryCount = ResDir->NumberOfIdEntries;
DPRINT("EntryCount %d\n", (ULONG)EntryCount);
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
DPRINT("EntryCount %d ResEntry %x\n", (ULONG)EntryCount, ResEntry);
DPRINT("ResEntry->Name %x Id %x\n", (ULONG)ResEntry->Name, Id);
if (ResEntry->Name == Id) {
DPRINT("ID entry found %x\n", Id);
goto found;
}
}
}
//DPRINT("Error %lu\n", i);
switch (i) {
case 0:
DPRINT("Error %lu - STATUS_RESOURCE_TYPE_NOT_FOUND\n", i);
return STATUS_RESOURCE_TYPE_NOT_FOUND;
case 1:
DPRINT("Error %lu - STATUS_RESOURCE_NAME_NOT_FOUND\n", i);
return STATUS_RESOURCE_NAME_NOT_FOUND;
case 2:
if (ResDir->NumberOfNamedEntries || ResDir->NumberOfIdEntries) {
/* Use the first available language */
ResEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)(ResDir + 1);
break;
}
DPRINT("Error %lu - STATUS_RESOURCE_LANG_NOT_FOUND\n", i);
return STATUS_RESOURCE_LANG_NOT_FOUND;
case 3:
DPRINT("Error %lu - STATUS_RESOURCE_DATA_NOT_FOUND\n", i);
return STATUS_RESOURCE_DATA_NOT_FOUND;
default:
DPRINT("Error %lu - STATUS_INVALID_PARAMETER\n", i);
return STATUS_INVALID_PARAMETER;
}
found:;
ResDir = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)ResBase +
(ResEntry->OffsetToData & 0x7FFFFFFF));
}
DPRINT("ResourceDataEntry: %x\n", (ULONG)ResDir);
if (ResourceDataEntry) {
*ResourceDataEntry = (PVOID)ResDir;
}
return Status;
}
NTSTATUS STDCALL
LdrAccessResource(IN PVOID BaseAddress,
IN PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry,
OUT PVOID* Resource OPTIONAL,
OUT PULONG Size OPTIONAL)
{
PIMAGE_SECTION_HEADER Section;
PIMAGE_NT_HEADERS NtHeader;
ULONG SectionRva;
ULONG SectionVa;
ULONG DataSize;
ULONG Offset = 0;
ULONG Data;
Data = (ULONG)RtlImageDirectoryEntryToData(BaseAddress,
TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &DataSize);
if (Data == 0) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
if ((ULONG)BaseAddress & 1) {
/* loaded as ordinary file */
NtHeader = RtlImageNtHeader((PVOID)((ULONG)BaseAddress & ~1UL));
Offset = (ULONG)BaseAddress - Data + NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
Section = RtlImageRvaToSection(NtHeader, BaseAddress, NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress);
if (Section == NULL) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
if (Section->Misc.VirtualSize < ResourceDataEntry->OffsetToData) {
SectionRva = RtlImageRvaToSection (NtHeader, BaseAddress, ResourceDataEntry->OffsetToData)->VirtualAddress;
SectionVa = RtlImageRvaToVa(NtHeader, BaseAddress, SectionRva, NULL);
Offset = SectionRva - SectionVa + Data - Section->VirtualAddress;
}
}
if (Resource) {
*Resource = (PVOID)(ResourceDataEntry->OffsetToData - Offset + (ULONG)BaseAddress);
}
if (Size) {
*Size = ResourceDataEntry->Size;
}
return STATUS_SUCCESS;
}
NTSTATUS STDCALL
LdrFindResourceDirectory_U(IN PVOID BaseAddress,
WCHAR** name,
DWORD level,
OUT PVOID* addr)
{
PIMAGE_RESOURCE_DIRECTORY ResDir;
PIMAGE_RESOURCE_DIRECTORY_ENTRY ResEntry;
ULONG EntryCount;
ULONG i;
NTSTATUS Status = STATUS_SUCCESS;
WCHAR* ws;
/* Get the pointer to the resource directory */
ResDir = (PIMAGE_RESOURCE_DIRECTORY)
RtlImageDirectoryEntryToData(BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &i);
if (ResDir == NULL) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
/* Let's go into resource tree */
for (i = 0; i < level; i++, name++) {
EntryCount = ResDir->NumberOfNamedEntries;
ResEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(ResDir + 1);
if ((ULONG)(*name) & 0xFFFF0000) {
/* Resource name is a unicode string */
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
if (ResEntry->Name & 0x80000000) {
ws = (WCHAR*)((ULONG)ResDir + (ResEntry->Name & 0x7FFFFFFF));
if (!wcsncmp(*name, ws + 1, *ws) && wcslen(*name) == (int)*ws) {
goto found;
}
}
}
} else {
/* We use ID number instead of string */
ResEntry += EntryCount;
EntryCount = ResDir->NumberOfIdEntries;
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
if (ResEntry->Name == (ULONG)(*name))
goto found;
}
}
switch (i) {
case 0:
return STATUS_RESOURCE_TYPE_NOT_FOUND;
case 1:
return STATUS_RESOURCE_NAME_NOT_FOUND;
case 2:
Status = STATUS_RESOURCE_LANG_NOT_FOUND;
/* Just use first language entry */
if (ResDir->NumberOfNamedEntries || ResDir->NumberOfIdEntries) {
ResEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)(ResDir + 1);
break;
}
return Status;
case 3:
return STATUS_RESOURCE_DATA_NOT_FOUND;
default:
return STATUS_INVALID_PARAMETER;
}
found:;
ResDir = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)ResDir + ResEntry->OffsetToData);
}
if (addr) {
*addr = (PVOID)ResDir;
}
return Status;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.46 2002/11/15 22:06:01 ekohl Exp $
/* $Id: startup.c,v 1.47 2002/12/08 15:57:40 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -64,20 +64,20 @@ LdrInitializeThunk (ULONG Unknown1,
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
current_entry =
NtCurrentPeb()->Ldr->InInitializationOrderModuleList.Flink;
NtCurrentPeb()->Ldr->InInitializationOrderModuleList.Flink;
while (current_entry !=
&NtCurrentPeb()->Ldr->InInitializationOrderModuleList)
{
current = CONTAINING_RECORD(current_entry, LDR_MODULE,
InInitializationOrderModuleList);
Entrypoint = (PDLLMAIN_FUNC)current->EntryPoint;
if (Entrypoint != NULL &&
current->BaseAddress != NtCurrentPeb()->ImageBaseAddress)
{
(VOID)Entrypoint(current->BaseAddress, DLL_THREAD_ATTACH, NULL);
}
current_entry = current_entry->Flink;
}
&NtCurrentPeb()->Ldr->InInitializationOrderModuleList)
{
current = CONTAINING_RECORD(current_entry, LDR_MODULE,
InInitializationOrderModuleList);
Entrypoint = (PDLLMAIN_FUNC)current->EntryPoint;
if (Entrypoint != NULL &&
current->BaseAddress != NtCurrentPeb()->ImageBaseAddress)
{
(VOID)Entrypoint(current->BaseAddress, DLL_THREAD_ATTACH, NULL);
}
current_entry = current_entry->Flink;
}
RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
return;
}
@ -88,8 +88,8 @@ LdrInitializeThunk (ULONG Unknown1,
DPRINT("ImageBase %x\n", ImageBase);
if (ImageBase <= (PVOID)0x1000)
{
DPRINT("ImageBase is null\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
DPRINT("ImageBase is null\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
}
NtGlobalFlag = Peb->NtGlobalFlag;
@ -101,8 +101,8 @@ LdrInitializeThunk (ULONG Unknown1,
PEDosHeader->e_lfanew == 0L ||
*(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC)
{
DbgPrint("Image has bad header\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
DbgPrint("Image has bad header\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
}
/* normalize process parameters */
@ -122,15 +122,15 @@ LdrInitializeThunk (ULONG Unknown1,
/* create process heap */
RtlInitializeHeapManager();
Peb->ProcessHeap = RtlCreateHeap(HEAP_GROWABLE,
(PVOID)HEAP_BASE,
NTHeaders->OptionalHeader.SizeOfHeapReserve,
NTHeaders->OptionalHeader.SizeOfHeapCommit,
NULL,
NULL);
(PVOID)HEAP_BASE,
NTHeaders->OptionalHeader.SizeOfHeapReserve,
NTHeaders->OptionalHeader.SizeOfHeapCommit,
NULL,
NULL);
if (Peb->ProcessHeap == 0)
{
DbgPrint("Failed to create process heap\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
DbgPrint("Failed to create process heap\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
/* initalize peb lock support */
@ -141,16 +141,16 @@ LdrInitializeThunk (ULONG Unknown1,
/* initialize tls bitmap */
RtlInitializeBitMap (&TlsBitMap,
Peb->TlsBitmapBits,
TLS_MINIMUM_AVAILABLE);
Peb->TlsBitmapBits,
TLS_MINIMUM_AVAILABLE);
Peb->TlsBitmap = &TlsBitMap;
Peb->TlsExpansionCounter = TLS_MINIMUM_AVAILABLE;
/* Initialize table of callbacks for the kernel. */
Peb->KernelCallbackTable =
RtlAllocateHeap(RtlGetProcessHeap(),
0,
sizeof(PVOID) * USER32_CALLBACK_MAXIMUM);
0,
sizeof(PVOID) * USER32_CALLBACK_MAXIMUM);
/* initalize loader lock */
RtlInitializeCriticalSection (&LoaderLock);
@ -158,12 +158,12 @@ LdrInitializeThunk (ULONG Unknown1,
/* create loader information */
Peb->Ldr = (PPEB_LDR_DATA)RtlAllocateHeap (Peb->ProcessHeap,
0,
sizeof(PEB_LDR_DATA));
0,
sizeof(PEB_LDR_DATA));
if (Peb->Ldr == NULL)
{
DbgPrint("Failed to create loader data\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
DbgPrint("Failed to create loader data\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
Peb->Ldr->Length = sizeof(PEB_LDR_DATA);
Peb->Ldr->Initialized = FALSE;
@ -178,21 +178,21 @@ LdrInitializeThunk (ULONG Unknown1,
/* add entry for ntdll */
NtModule = (PLDR_MODULE)RtlAllocateHeap (Peb->ProcessHeap,
0,
sizeof(LDR_MODULE));
0,
sizeof(LDR_MODULE));
if (NtModule == NULL)
{
DbgPrint("Failed to create loader module entry (NTDLL)\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
DbgPrint("Failed to create loader module entry (NTDLL)\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
memset(NtModule, 0, sizeof(LDR_MODULE));
NtModule->BaseAddress = (PVOID)&_image_base__;
NtModule->EntryPoint = 0; /* no entry point */
RtlCreateUnicodeString (&NtModule->FullDllName,
FullNtDllPath);
FullNtDllPath);
RtlCreateUnicodeString (&NtModule->BaseDllName,
L"ntdll.dll");
L"ntdll.dll");
NtModule->Flags = 0;
NtModule->LoadCount = -1; /* don't unload */
NtModule->TlsIndex = 0;
@ -204,9 +204,9 @@ LdrInitializeThunk (ULONG Unknown1,
NtModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
InsertTailList(&Peb->Ldr->InLoadOrderModuleList,
&NtModule->InLoadOrderModuleList);
&NtModule->InLoadOrderModuleList);
InsertTailList(&Peb->Ldr->InInitializationOrderModuleList,
&NtModule->InInitializationOrderModuleList);
&NtModule->InInitializationOrderModuleList);
#ifdef DBG
@ -216,12 +216,12 @@ LdrInitializeThunk (ULONG Unknown1,
/* add entry for executable (becomes first list entry) */
ExeModule = (PLDR_MODULE)RtlAllocateHeap (Peb->ProcessHeap,
0,
sizeof(LDR_MODULE));
0,
sizeof(LDR_MODULE));
if (ExeModule == NULL)
{
DbgPrint("Failed to create loader module infomation\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
DbgPrint("Failed to create loader module infomation\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
ExeModule->BaseAddress = Peb->ImageBaseAddress;
@ -233,13 +233,13 @@ LdrInitializeThunk (ULONG Unknown1,
}
RtlCreateUnicodeString(&ExeModule->FullDllName,
Peb->ProcessParameters->ImagePathName.Buffer);
Peb->ProcessParameters->ImagePathName.Buffer);
RtlCreateUnicodeString(&ExeModule->BaseDllName,
wcsrchr(ExeModule->FullDllName.Buffer, L'\\') + 1);
wcsrchr(ExeModule->FullDllName.Buffer, L'\\') + 1);
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n",
&ExeModule->BaseDllName,
&ExeModule->FullDllName);
&ExeModule->BaseDllName,
&ExeModule->FullDllName);
ExeModule->Flags = 0;
ExeModule->LoadCount = -1; /* don't unload */
@ -252,7 +252,7 @@ LdrInitializeThunk (ULONG Unknown1,
ExeModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
InsertHeadList(&Peb->Ldr->InLoadOrderModuleList,
&ExeModule->InLoadOrderModuleList);
&ExeModule->InLoadOrderModuleList);
#ifdef DBG
@ -269,8 +269,8 @@ LdrInitializeThunk (ULONG Unknown1,
/* Check before returning that we can run the image safely. */
if (EntryPoint == NULL)
{
DbgPrint("Failed to initialize image\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
DbgPrint("Failed to initialize image\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.75 2002/10/26 00:32:18 chorns Exp $
# $Id: makefile,v 1.76 2002/12/08 15:57:39 robd Exp $
PATH_TO_TOP = ../..
@ -68,6 +68,7 @@ TARGET_OBJECTS = \
$(STDLIB_OBJECTS) \
$(STRING_OBJECTS) \
stubs/stubs.o \
ldr/res.o \
ldr/utils.o \
$(CSR_OBJECTS)

View file

@ -1,4 +1,4 @@
/* $Id: error.c,v 1.11 2002/09/08 10:23:05 chorns Exp $
/* $Id: error.c,v 1.12 2002/12/08 15:57:38 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -826,12 +826,10 @@ RPC_NT_SS_CONTEXT_MISMATCH ERROR_INVALID_HANDLE
VOID
STDCALL
RtlAssert (
PVOID FailedAssertion,
RtlAssert(PVOID FailedAssertion,
PVOID FileName,
ULONG LineNumber,
PCHAR Message
)
PCHAR Message)
{
DbgPrint ("Assertion \'%s\' failed at %s line %d: %s\n",
(PCHAR)FailedAssertion,
@ -881,9 +879,9 @@ RtlNtStatusToDosErrorNoTeb(NTSTATUS Status)
if (!ret)
ret = Status; /* 0 means 1:1 mapping */
else if (ret == ERROR_MR_MID_NOT_FOUND)
{
{
DbgPrint("RTL: RtlNtStatusToDosErrorNoTeb(0x%lx): no valid W32 error mapping\n", Status);
}
}
return ret;
}
Table++;

View file

@ -1,4 +1,4 @@
/* $Id: largeint.c,v 1.9 2002/09/08 10:23:05 chorns Exp $
/* $Id: largeint.c,v 1.10 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -121,11 +121,9 @@ RtlExtendedLargeIntegerDivide (
LARGE_INTEGER
STDCALL
RtlExtendedMagicDivide (
LARGE_INTEGER Dividend,
RtlExtendedMagicDivide(LARGE_INTEGER Dividend,
LARGE_INTEGER MagicDivisor,
CCHAR ShiftCount
)
CCHAR ShiftCount)
{
UNIMPLEMENTED;
}

View file

@ -1,4 +1,4 @@
/* $Id: mem.c,v 1.11 2002/09/08 10:23:05 chorns Exp $
/* $Id: mem.c,v 1.12 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -18,7 +18,9 @@
ULONG
STDCALL
RtlCompareMemory(PVOID Source1, PVOID Source2, ULONG Length)
RtlCompareMemory(PVOID Source1,
PVOID Source2,
ULONG Length)
/*
* FUNCTION: Compares blocks of memory and returns the number of equal bytes
* ARGUMENTS:
@ -95,11 +97,7 @@ RtlFillMemory (
UCHAR Fill
)
{
memset (
Destination,
Fill,
Length
);
memset(Destination, Fill, Length);
}
VOID
@ -122,21 +120,6 @@ RtlFillMemoryUlong (
}
VOID
STDCALL
RtlZeroMemory (
PVOID Destination,
ULONG Length
)
{
RtlFillMemory (
Destination,
Length,
0
);
}
VOID
STDCALL
RtlMoveMemory (
@ -153,4 +136,19 @@ RtlMoveMemory (
}
VOID
STDCALL
RtlZeroMemory (
PVOID Destination,
ULONG Length
)
{
RtlFillMemory (
Destination,
Length,
0
);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: time.c,v 1.13 2002/09/30 20:57:54 hbirr Exp $
/* $Id: time.c,v 1.14 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -55,43 +55,11 @@ static __inline void NormalizeTimeFields(CSHORT *FieldToNormalize,
/* FUNCTIONS *****************************************************************/
VOID STDCALL
RtlTimeToElapsedTimeFields(IN PLARGE_INTEGER Time,
OUT PTIME_FIELDS TimeFields)
{
ULONGLONG ElapsedSeconds;
ULONG SecondsInDay;
ULONG SecondsInMinute;
/* Extract millisecond from time */
TimeFields->Milliseconds = (CSHORT)((Time->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
/* Compute elapsed seconds */
ElapsedSeconds = (ULONGLONG)Time->QuadPart / TICKSPERSEC;
/* Compute seconds within the day */
SecondsInDay = ElapsedSeconds % SECSPERDAY;
/* Compute elapsed minutes within the day */
SecondsInMinute = SecondsInDay % SECSPERHOUR;
/* Compute elapsed time of day */
TimeFields->Hour = (CSHORT)(SecondsInDay / SECSPERHOUR);
TimeFields->Minute = (CSHORT)(SecondsInMinute / SECSPERMIN);
TimeFields->Second = (CSHORT)(SecondsInMinute % SECSPERMIN);
/* Compute elapsed days */
TimeFields->Day = (CSHORT)(ElapsedSeconds / SECSPERDAY);
/* The elapsed number of months and days cannot be calculated */
TimeFields->Month = 0;
TimeFields->Year = 0;
}
VOID STDCALL
RtlTimeToTimeFields(PLARGE_INTEGER liTime,
PTIME_FIELDS TimeFields)
VOID
STDCALL
RtlTimeToTimeFields(
PLARGE_INTEGER liTime,
PTIME_FIELDS TimeFields)
{
const int *Months;
int LeapSecondCorrections, SecondsInDay, CurYear;
@ -169,11 +137,14 @@ RtlTimeToTimeFields(PLARGE_INTEGER liTime,
}
BOOLEAN STDCALL
RtlTimeFieldsToTime(PTIME_FIELDS tfTimeFields,
PLARGE_INTEGER Time)
BOOLEAN
STDCALL
RtlTimeFieldsToTime(
PTIME_FIELDS tfTimeFields,
PLARGE_INTEGER Time)
{
int CurYear, CurMonth;
int CurYear;
int CurMonth;
long long int rcTime;
TIME_FIELDS TimeFields = *tfTimeFields;
@ -233,9 +204,11 @@ RtlTimeFieldsToTime(PTIME_FIELDS tfTimeFields,
}
VOID STDCALL
RtlSecondsSince1970ToTime(ULONG SecondsSince1970,
PLARGE_INTEGER Time)
VOID
STDCALL
RtlSecondsSince1970ToTime(
ULONG SecondsSince1970,
PLARGE_INTEGER Time)
{
LONGLONG llTime;
@ -245,9 +218,11 @@ RtlSecondsSince1970ToTime(ULONG SecondsSince1970,
}
VOID STDCALL
RtlSecondsSince1980ToTime(ULONG SecondsSince1980,
PLARGE_INTEGER Time)
VOID
STDCALL
RtlSecondsSince1980ToTime(
ULONG SecondsSince1980,
PLARGE_INTEGER Time)
{
LONGLONG llTime;
@ -257,9 +232,11 @@ RtlSecondsSince1980ToTime(ULONG SecondsSince1980,
}
BOOLEAN STDCALL
RtlTimeToSecondsSince1970(PLARGE_INTEGER Time,
PULONG SecondsSince1970)
BOOLEAN
STDCALL
RtlTimeToSecondsSince1970(
PLARGE_INTEGER Time,
PULONG SecondsSince1970)
{
LARGE_INTEGER liTime;
@ -267,17 +244,19 @@ RtlTimeToSecondsSince1970(PLARGE_INTEGER Time,
liTime.QuadPart = liTime.QuadPart / TICKSPERSEC;
if (liTime.u.HighPart != 0)
return(FALSE);
return FALSE;
*SecondsSince1970 = liTime.u.LowPart;
return(TRUE);
return TRUE;
}
BOOLEAN STDCALL
RtlTimeToSecondsSince1980(PLARGE_INTEGER Time,
PULONG SecondsSince1980)
BOOLEAN
STDCALL
RtlTimeToSecondsSince1980(
PLARGE_INTEGER Time,
PULONG SecondsSince1980)
{
LARGE_INTEGER liTime;
@ -285,15 +264,16 @@ RtlTimeToSecondsSince1980(PLARGE_INTEGER Time,
liTime.QuadPart = liTime.QuadPart / TICKSPERSEC;
if (liTime.u.HighPart != 0)
return(FALSE);
return FALSE;
*SecondsSince1980 = liTime.u.LowPart;
return(TRUE);
return TRUE;
}
NTSTATUS STDCALL
NTSTATUS
STDCALL
RtlLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
PLARGE_INTEGER SystemTime)
{
@ -314,7 +294,8 @@ RtlLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
}
NTSTATUS STDCALL
NTSTATUS
STDCALL
RtlSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
PLARGE_INTEGER LocalTime)
{
@ -334,4 +315,40 @@ RtlSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
return(STATUS_SUCCESS);
}
VOID
STDCALL
RtlTimeToElapsedTimeFields(IN PLARGE_INTEGER Time,
OUT PTIME_FIELDS TimeFields)
{
ULONGLONG ElapsedSeconds;
ULONG SecondsInDay;
ULONG SecondsInMinute;
/* Extract millisecond from time */
TimeFields->Milliseconds = (CSHORT)((Time->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
/* Compute elapsed seconds */
ElapsedSeconds = (ULONGLONG)Time->QuadPart / TICKSPERSEC;
/* Compute seconds within the day */
SecondsInDay = ElapsedSeconds % SECSPERDAY;
/* Compute elapsed minutes within the day */
SecondsInMinute = SecondsInDay % SECSPERHOUR;
/* Compute elapsed time of day */
TimeFields->Hour = (CSHORT)(SecondsInDay / SECSPERHOUR);
TimeFields->Minute = (CSHORT)(SecondsInMinute / SECSPERMIN);
TimeFields->Second = (CSHORT)(SecondsInMinute % SECSPERMIN);
/* Compute elapsed days */
TimeFields->Day = (CSHORT)(ElapsedSeconds / SECSPERDAY);
/* The elapsed number of months and days cannot be calculated */
TimeFields->Month = 0;
TimeFields->Year = 0;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.24 2002/10/20 03:34:00 robd Exp $
/* $Id: unicode.c,v 1.25 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -21,9 +21,8 @@
WCHAR
STDCALL
RtlAnsiCharToUnicodeChar (
IN CHAR AnsiChar
)
RtlAnsiCharToUnicodeChar(
IN CHAR AnsiChar)
{
ULONG Size;
WCHAR UnicodeChar;
@ -45,9 +44,8 @@ RtlAnsiCharToUnicodeChar (
ULONG
STDCALL
RtlAnsiStringToUnicodeSize (
IN PANSI_STRING AnsiString
)
RtlAnsiStringToUnicodeSize(
IN PANSI_STRING AnsiString)
{
ULONG Size;
@ -64,8 +62,7 @@ STDCALL
RtlAnsiStringToUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PANSI_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -125,10 +122,9 @@ RtlAnsiStringToUnicodeString(
NTSTATUS
STDCALL
RtlAppendAsciizToString (
RtlAppendAsciizToString(
IN OUT PSTRING Destination,
IN PCSZ Source
)
IN PCSZ Source)
{
ULONG Length;
PCHAR Ptr;
@ -155,10 +151,9 @@ RtlAppendAsciizToString (
NTSTATUS
STDCALL
RtlAppendStringToString (
RtlAppendStringToString(
IN OUT PSTRING Destination,
IN PSTRING Source
)
IN PSTRING Source)
{
PCHAR Ptr;
@ -183,10 +178,9 @@ RtlAppendStringToString (
NTSTATUS
STDCALL
RtlAppendUnicodeStringToString (
RtlAppendUnicodeStringToString(
IN OUT PUNICODE_STRING Destination,
IN PUNICODE_STRING Source
)
IN PUNICODE_STRING Source)
{
PWCHAR Src;
PWCHAR Dest;
@ -244,7 +238,7 @@ RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
NTSTATUS
STDCALL
RtlCharToInteger (
RtlCharToInteger(
IN PCSZ String,
IN ULONG Base,
IN OUT PULONG Value)
@ -285,11 +279,10 @@ RtlCharToInteger (
LONG
STDCALL
RtlCompareString (
RtlCompareString(
IN PSTRING String1,
IN PSTRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG len1, len2;
PCHAR s1, s2;
@ -333,11 +326,10 @@ RtlCompareString (
LONG
STDCALL
RtlCompareUnicodeString (
RtlCompareUnicodeString(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG len1, len2;
PWCHAR s1, s2;
@ -381,10 +373,9 @@ RtlCompareUnicodeString (
VOID
STDCALL
RtlCopyString (
RtlCopyString(
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
IN PSTRING SourceString)
{
ULONG copylen, i;
PCHAR Src, Dest;
@ -414,10 +405,9 @@ RtlCopyString (
VOID
STDCALL
RtlCopyUnicodeString (
RtlCopyUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString
)
IN PUNICODE_STRING SourceString)
{
ULONG copylen, i;
PWCHAR Src, Dest;
@ -447,10 +437,9 @@ RtlCopyUnicodeString (
BOOLEAN
STDCALL
RtlCreateUnicodeString (
RtlCreateUnicodeString(
IN OUT PUNICODE_STRING Destination,
IN PWSTR Source
)
IN PWSTR Source)
{
ULONG Length;
@ -473,8 +462,10 @@ RtlCreateUnicodeString (
}
BOOLEAN STDCALL
RtlCreateUnicodeStringFromAsciiz (OUT PUNICODE_STRING Destination,
BOOLEAN
STDCALL
RtlCreateUnicodeStringFromAsciiz(
OUT PUNICODE_STRING Destination,
IN PCSZ Source)
{
ANSI_STRING AnsiString;
@ -493,11 +484,10 @@ RtlCreateUnicodeStringFromAsciiz (OUT PUNICODE_STRING Destination,
NTSTATUS
STDCALL
RtlDowncaseUnicodeString (
RtlDowncaseUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
ULONG i;
PWCHAR Src, Dest;
@ -545,10 +535,9 @@ RtlDowncaseUnicodeString (
BOOLEAN
STDCALL
RtlEqualComputerName (
RtlEqualComputerName(
IN PUNICODE_STRING ComputerName1,
IN PUNICODE_STRING ComputerName2
)
IN PUNICODE_STRING ComputerName2)
{
return RtlEqualDomainName (ComputerName1,
ComputerName2);
@ -586,11 +575,10 @@ RtlEqualDomainName (
BOOLEAN
STDCALL
RtlEqualString (
RtlEqualString(
IN PSTRING String1,
IN PSTRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG i;
CHAR c1, c2;
@ -627,11 +615,10 @@ RtlEqualString (
BOOLEAN
STDCALL
RtlEqualUnicodeString (
RtlEqualUnicodeString(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG i;
WCHAR wc1, wc2;
@ -669,9 +656,8 @@ RtlEqualUnicodeString (
VOID
STDCALL
RtlEraseUnicodeString (
IN PUNICODE_STRING String
)
RtlEraseUnicodeString(
IN PUNICODE_STRING String)
{
if (String->Buffer == NULL)
return;
@ -689,9 +675,8 @@ RtlEraseUnicodeString (
VOID
STDCALL
RtlFreeAnsiString (
IN PANSI_STRING AnsiString
)
RtlFreeAnsiString(
IN PANSI_STRING AnsiString)
{
if (AnsiString->Buffer == NULL)
return;
@ -708,9 +693,8 @@ RtlFreeAnsiString (
VOID
STDCALL
RtlFreeOemString (
IN POEM_STRING OemString
)
RtlFreeOemString(
IN POEM_STRING OemString)
{
if (OemString->Buffer == NULL)
return;
@ -727,9 +711,8 @@ RtlFreeOemString (
VOID
STDCALL
RtlFreeUnicodeString (
IN PUNICODE_STRING UnicodeString
)
RtlFreeUnicodeString(
IN PUNICODE_STRING UnicodeString)
{
if (UnicodeString->Buffer == NULL)
return;
@ -746,10 +729,9 @@ RtlFreeUnicodeString (
VOID
STDCALL
RtlInitAnsiString (
RtlInitAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString
)
IN PCSZ SourceString)
{
ULONG DestSize;
@ -770,10 +752,9 @@ RtlInitAnsiString (
VOID
STDCALL
RtlInitString (
RtlInitString(
IN OUT PSTRING DestinationString,
IN PCSZ SourceString
)
IN PCSZ SourceString)
{
ULONG DestSize;
@ -794,10 +775,9 @@ RtlInitString (
VOID
STDCALL
RtlInitUnicodeString (
RtlInitUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
)
IN PCWSTR SourceString)
{
ULONG DestSize;
@ -818,12 +798,11 @@ RtlInitUnicodeString (
NTSTATUS
STDCALL
RtlIntegerToChar (
RtlIntegerToChar(
IN ULONG Value,
IN ULONG Base,
IN ULONG Length,
IN OUT PCHAR String
)
IN OUT PCHAR String)
{
ULONG Radix;
CHAR temp[33];
@ -866,11 +845,10 @@ RtlIntegerToChar (
NTSTATUS
STDCALL
RtlIntegerToUnicodeString (
RtlIntegerToUnicodeString(
IN ULONG Value,
IN ULONG Base, /* optional */
IN OUT PUNICODE_STRING String
)
IN OUT PUNICODE_STRING String)
{
ANSI_STRING AnsiString;
CHAR Buffer[33];
@ -897,12 +875,11 @@ RtlIntegerToUnicodeString (
NTSTATUS
STDCALL
RtlLargeIntegerToChar (
RtlLargeIntegerToChar(
IN PLARGE_INTEGER Value,
IN ULONG Base,
IN ULONG Length,
IN OUT PCHAR String
)
IN OUT PCHAR String)
{
ULONG Radix;
CHAR temp[65];
@ -945,9 +922,8 @@ RtlLargeIntegerToChar (
ULONG
STDCALL
RtlOemStringToUnicodeSize (
IN POEM_STRING OemString
)
RtlOemStringToUnicodeSize(
IN POEM_STRING OemString)
{
ULONG Size;
@ -961,11 +937,10 @@ RtlOemStringToUnicodeSize (
NTSTATUS
STDCALL
RtlOemStringToUnicodeString (
RtlOemStringToUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN POEM_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1025,11 +1000,10 @@ RtlOemStringToUnicodeString (
BOOLEAN
STDCALL
RtlPrefixString (
RtlPrefixString(
PANSI_STRING String1,
PANSI_STRING String2,
BOOLEAN CaseInsensitive
)
BOOLEAN CaseInsensitive)
{
PCHAR pc1;
PCHAR pc2;
@ -1068,11 +1042,10 @@ RtlPrefixString (
BOOLEAN
STDCALL
RtlPrefixUnicodeString (
RtlPrefixUnicodeString(
PUNICODE_STRING String1,
PUNICODE_STRING String2,
BOOLEAN CaseInsensitive
)
BOOLEAN CaseInsensitive)
{
PWCHAR pc1;
PWCHAR pc2;
@ -1112,9 +1085,8 @@ RtlPrefixUnicodeString (
ULONG
STDCALL
RtlUnicodeStringToAnsiSize (
IN PUNICODE_STRING UnicodeString
)
RtlUnicodeStringToAnsiSize(
IN PUNICODE_STRING UnicodeString)
{
ULONG Size;
@ -1128,11 +1100,10 @@ RtlUnicodeStringToAnsiSize (
NTSTATUS
STDCALL
RtlUnicodeStringToAnsiString (
RtlUnicodeStringToAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1186,11 +1157,10 @@ RtlUnicodeStringToAnsiString (
NTSTATUS
STDCALL
RtlUnicodeStringToInteger (
RtlUnicodeStringToInteger(
IN PUNICODE_STRING String,
IN ULONG Base,
OUT PULONG Value
)
OUT PULONG Value)
{
PWCHAR Str;
ULONG lenmin = 0;
@ -1276,9 +1246,8 @@ RtlUnicodeStringToInteger (
ULONG
STDCALL
RtlUnicodeStringToOemSize (
IN PUNICODE_STRING UnicodeString
)
RtlUnicodeStringToOemSize(
IN PUNICODE_STRING UnicodeString)
{
ULONG Size;
@ -1292,11 +1261,10 @@ RtlUnicodeStringToOemSize (
NTSTATUS
STDCALL
RtlUnicodeStringToCountedOemString (
RtlUnicodeStringToCountedOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1359,11 +1327,10 @@ RtlUnicodeStringToCountedOemString (
NTSTATUS
STDCALL
RtlUnicodeStringToOemString (
RtlUnicodeStringToOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1426,9 +1393,7 @@ RtlUnicodeStringToOemString (
WCHAR
STDCALL
RtlUpcaseUnicodeChar (
IN WCHAR Source
)
RtlUpcaseUnicodeChar(IN WCHAR Source)
{
if (Source < L'a')
return Source;
@ -1444,11 +1409,10 @@ RtlUpcaseUnicodeChar (
NTSTATUS
STDCALL
RtlUpcaseUnicodeString (
RtlUpcaseUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
ULONG i;
PWCHAR Src, Dest;
@ -1485,11 +1449,10 @@ RtlUpcaseUnicodeString (
NTSTATUS
STDCALL
RtlUpcaseUnicodeStringToAnsiString (
RtlUpcaseUnicodeStringToAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1552,11 +1515,10 @@ RtlUpcaseUnicodeStringToAnsiString (
NTSTATUS
STDCALL
RtlUpcaseUnicodeStringToCountedOemString (
RtlUpcaseUnicodeStringToCountedOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1724,10 +1686,9 @@ RtlUpperChar (
VOID
STDCALL
RtlUpperString (
RtlUpperString(
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
IN PSTRING SourceString)
{
ULONG Length;
ULONG i;
@ -1752,41 +1713,33 @@ RtlUpperString (
ULONG
STDCALL
RtlxAnsiStringToUnicodeSize (
IN PANSI_STRING AnsiString
)
RtlxAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
{
return RtlAnsiStringToUnicodeSize (AnsiString);
return RtlAnsiStringToUnicodeSize(AnsiString);
}
ULONG
STDCALL
RtlxOemStringToUnicodeSize (
IN POEM_STRING OemString
)
RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
{
return RtlAnsiStringToUnicodeSize ((PANSI_STRING)OemString);
return RtlAnsiStringToUnicodeSize((PANSI_STRING)OemString);
}
ULONG
STDCALL
RtlxUnicodeStringToAnsiSize (
IN PUNICODE_STRING UnicodeString
)
RtlxUnicodeStringToAnsiSize(IN PUNICODE_STRING UnicodeString)
{
return RtlUnicodeStringToAnsiSize (UnicodeString);
return RtlUnicodeStringToAnsiSize(UnicodeString);
}
ULONG
STDCALL
RtlxUnicodeStringToOemSize (
IN PUNICODE_STRING UnicodeString
)
RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString)
{
return RtlUnicodeStringToAnsiSize (UnicodeString);
return RtlUnicodeStringToAnsiSize(UnicodeString);
}
/* EOF */