diff --git a/reactos/ntoskrnl/cc/view.c b/reactos/ntoskrnl/cc/view.c index a0d0bfa3033..8e6cf7ad6de 100644 --- a/reactos/ntoskrnl/cc/view.c +++ b/reactos/ntoskrnl/cc/view.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: view.c,v 1.27 2001/08/03 09:36:18 ei Exp $ +/* $Id: view.c,v 1.28 2001/09/02 15:38:46 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -126,7 +126,8 @@ CcRosGetCacheSegment(PBCB Bcb, current_entry = Bcb->CacheSegmentListHead.Flink; while (current_entry != &Bcb->CacheSegmentListHead) { - current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbListEntry); + current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, + BcbListEntry); if (current->FileOffset <= FileOffset && (current->FileOffset + Bcb->CacheSegmentSize) > FileOffset) { diff --git a/reactos/ntoskrnl/ex/power.c b/reactos/ntoskrnl/ex/power.c index c1fa7242d60..d34d1b59d4b 100644 --- a/reactos/ntoskrnl/ex/power.c +++ b/reactos/ntoskrnl/ex/power.c @@ -23,12 +23,14 @@ /* FUNCTIONS *****************************************************************/ NTSTATUS STDCALL -NtSetSystemPowerState(VOID) +NtSetSystemPowerState(IN POWER_ACTION SystemAction, + IN SYSTEM_POWER_STATE MinSystemState, + IN ULONG Flags) { - UNIMPLEMENTED; + /* Windows 2000 only */ + return(STATUS_UNIMPLEMENTED); } - NTSTATUS STDCALL NtShutdownSystem(IN SHUTDOWN_ACTION Action) { diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index ff3f1f12d03..87682084011 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -1,4 +1,4 @@ -/* $Id: sysinfo.c,v 1.11 2001/04/22 23:06:57 ea Exp $ +/* $Id: sysinfo.c,v 1.12 2001/09/02 15:38:46 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -21,27 +21,167 @@ extern ULONG NtGlobalFlag; /* FIXME: it should go in a ddk/?.h */ /* FUNCTIONS *****************************************************************/ -NTSTATUS -STDCALL -NtQuerySystemEnvironmentValue ( - IN PUNICODE_STRING Name, - OUT PVOID Value, - IN ULONG Length, - IN OUT PULONG ReturnLength - ) +NTSTATUS STDCALL +NtQuerySystemEnvironmentValue (IN PUNICODE_STRING UnsafeName, + OUT PVOID UnsafeValue, + IN ULONG Length, + IN OUT PULONG UnsafeReturnLength) { - UNIMPLEMENTED; + PWCH WNameBuffer; + NTSTATUS Status; + USHORT NameLength; + ANSI_STRING AName; + UNICODE_STRING Name; + BOOLEAN Result; + PCH Value; + ANSI_STRING AValue; + UNICODE_STRING WValue; + ULONG ReturnLength; + + /* + * Copy the name to kernel space if necessary and convert it to ANSI. + */ + if (ExGetPreviousMode() != KernelMode) + { + Status = MmSafeCopyFromUser(&NameLength, &UnsafeName->Length, + sizeof(NameLength)); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + WNameBuffer = ExAllocatePool(NonPagedPool, NameLength + sizeof(WCHAR)); + if (WNameBuffer != NULL) + { + return(STATUS_NO_MORE_MEMORY); + } + memset(WNameBuffer, 0, NameLength + sizeof(WCHAR)); + + Status = MmSafeCopyFromUser(WNameBuffer, UnsafeName->Buffer, + NameLength * sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + { + ExFreePool(WNameBuffer); + return(Status); + } + WNameBuffer[NameLength / sizeof(WCHAR)] = 0; + + RtlInitUnicodeString(&Name, WNameBuffer); + Status = RtlUnicodeStringToAnsiString(&AName, &Name, TRUE); + if (!NT_SUCCESS(Status)) + { + RtlFreeUnicodeString(&Name); + return(Status); + } + } + else + { + RtlUnicodeStringToAnsiString(&AName, UnsafeName, TRUE); + } + + /* + * Create a temporary buffer for the value + */ + ValueBuffer = ExAllocatePool(NonPagedPool, Length); + if (ValueBuffer == NULL) + { + RtlFreeAnsiString(&AName); + if (ExGetPreviousMode() != KernelMode) + { + RtlFreeUnicodeString(&Name); + } + return(STATUS_NO_MORE_MEMORY); + } + + /* + * Get the environment variable + */ + Result = HalGetEnvironmentVariable(AName->Buffer, Value, Length); + if (!Result) + { + RtlFreeAnsiString(&AName); + if (ExGetPreviousMode() != KernelMode) + { + RtlFreeUnicodeString(&Name); + } + ExFreePool(Value); + return(STATUS_UNSUCCESSFUL); + } + + /* + * Convert the result to ANSI. + */ + RtlInitAnsiString(&AValue, Value); + Status = RtlAnsiStringToUnicodeString(&WValue, &AValue, TRUE); + if (!NT_SUCCESS(Status)) + { + RtlFreeAnsiString(&AName); + if (ExGetPreviousMode() != KernelMode) + { + RtlFreeUnicodeString(&Name); + } + ExFreePool(Value); + return(Status); + } + ReturnLength = WValue->Length; + + /* + * Copy the result back to the caller. + */ + if (ExGetPreviousMode() != KernelMode) + { + Status = MmCopyToUser(UnsafeValue, WValue->Buffer, ReturnLength); + if (!NT_SUCCESS(Status)) + { + RtlFreeAnsiString(&AName); + if (ExGetPreviousMode() != KernelMode) + { + RtlFreeUnicodeString(&Name); + } + ExFreePool(Value); + RtlFreeUnicodeString(&WValue); + return(Status); + } + + Status = MmCopyToUser(UnsafeReturnLength, &ReturnLength, sizeof(ULONG)); + if (!NT_SUCCESS(Status)) + { + RtlFreeAnsiString(&AName); + if (ExGetPreviousMode() != KernelMode) + { + RtlFreeUnicodeString(&Name); + } + ExFreePool(Value); + RtlFreeUnicodeString(&WValue); + return(Status); + } + } + else + { + memcpy(UnsafeValue, WValue->Buffer, ReturnLength); + memcpy(UnsafeReturnLength, &ReturnLength, sizeof(ULONG)); + } + + /* + * Free temporary buffers. + */ + RtlFreeAnsiString(&AName); + if (ExGetPreviousMode() != KernelMode) + { + RtlFreeUnicodeString(&Name); + } + ExFreePool(Value); + RtlFreeUnicodeString(&WValue); + + return(STATUS_SUCCESS); } -NTSTATUS -STDCALL -NtSetSystemEnvironmentValue ( - IN PUNICODE_STRING VariableName, - IN PUNICODE_STRING Value - ) +NTSTATUS STDCALL +NtSetSystemEnvironmentValue (IN PUNICODE_STRING UnsafeVariableName, + IN PUNICODE_STRING Value) { - UNIMPLEMENTED; + UNIMPLEMENTED; }