123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972 |
- /*++
- Copyright (c) 2014 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- info.c
- Abstract:
- This module implements support for the get and set system information
- calls.
- Author:
- Evan Green 10-Apr-2014
- Environment:
- Kernel
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <minoca/kernel/kernel.h>
- #include <minoca/fw/smbios.h>
- #include "kep.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- KSTATUS
- KepGetSetSystemInformation (
- BOOL FromKernelMode,
- SYSTEM_INFORMATION_SUBSYSTEM Subsystem,
- UINTN InformationType,
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetSetKeSystemInformation (
- BOOL FromKernelMode,
- KE_INFORMATION_TYPE InformationType,
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetSystemVersion (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetFirmwareTable (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetFirmwareType (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetProcessorUsage (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetProcessorCount (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- KSTATUS
- KepGetKernelCommandLine (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- SYSTEM_FIRMWARE_TYPE KeSystemFirmwareType = SystemFirmwareUnknown;
- PKERNEL_COMMAND_LINE KeCommandLine = NULL;
- //
- // ------------------------------------------------------------------ Functions
- //
- KERNEL_API
- KSTATUS
- KeGetSetSystemInformation (
- SYSTEM_INFORMATION_SUBSYSTEM Subsystem,
- UINTN InformationType,
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets or sets system information.
- Arguments:
- Subsystem - Supplies the subsystem to query or set information of.
- InformationType - Supplies the information type, which is specific to
- the subsystem. The type of this value is generally
- <subsystem>_INFORMATION_TYPE (eg IO_INFORMATION_TYPE).
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- STATUS_SUCCESS if the information was successfully queried or set.
- STATUS_BUFFER_TOO_SMALL if the buffer size specified was too small. The
- required buffer size will be returned in the data size parameter.
- STATUS_DATA_LENGTH_MISMATCH if the buffer size was not correct. The
- correct buffer size will be returned in the data size parameter.
- STATUS_INVALID_PARAMETER if the given subsystem or information type is
- not known.
- Other status codes on other failures.
- --*/
- {
- KSTATUS Status;
- Status = KepGetSetSystemInformation(TRUE,
- Subsystem,
- InformationType,
- Data,
- DataSize,
- Set);
- return Status;
- }
- KERNEL_API
- PKERNEL_ARGUMENT
- KeGetKernelArgument (
- PKERNEL_ARGUMENT Start,
- PCSTR Component,
- PCSTR Name
- )
- /*++
- Routine Description:
- This routine looks up a kernel command line argument.
- Arguments:
- Start - Supplies an optional pointer to the previous command line argument
- to start from. Supply NULL here initially.
- Component - Supplies a pointer to the component string to look up.
- Name - Supplies a pointer to the argument name to look up.
- Return Value:
- Returns a pointer to a matching kernel argument on success.
- NULL if no argument could be found.
- --*/
- {
- PKERNEL_ARGUMENT Argument;
- UINTN ArgumentIndex;
- PKERNEL_COMMAND_LINE Line;
- BOOL Match;
- Line = KeCommandLine;
- if (Line == NULL) {
- return NULL;
- }
- ArgumentIndex = 0;
- Argument = &(Line->Arguments[ArgumentIndex]);
- if (Start != NULL) {
- while ((ArgumentIndex < Line->ArgumentCount) &&
- (Argument != Start)) {
- Argument += 1;
- ArgumentIndex += 1;
- }
- //
- // If the argument was never found or is the last argument, nothing
- // new will be found.
- //
- if (ArgumentIndex >= Line->ArgumentCount - 1) {
- return NULL;
- }
- Argument += 1;
- ArgumentIndex += 1;
- }
- while (ArgumentIndex < Line->ArgumentCount) {
- Match = RtlAreStringsEqual(Component,
- Argument->Component,
- KERNEL_MAX_COMMAND_LINE);
- if (Match != FALSE) {
- Match = RtlAreStringsEqual(Name,
- Argument->Name,
- KERNEL_MAX_COMMAND_LINE);
- if (Match != FALSE) {
- return Argument;
- }
- }
- ArgumentIndex += 1;
- Argument += 1;
- }
- return NULL;
- }
- INTN
- KeSysGetSetSystemInformation (
- PVOID SystemCallParameter
- )
- /*++
- Routine Description:
- This routine implements the user mode system call for getting and setting
- system information.
- Arguments:
- SystemCallParameter - Supplies a pointer to the parameters supplied with
- the system call. This structure will be a stack-local copy of the
- actual parameters passed from user-mode.
- Return Value:
- STATUS_SUCCESS or positive integer on success.
- Error status code on failure.
- --*/
- {
- PVOID Buffer;
- UINTN CopySize;
- KSTATUS CopyStatus;
- PSYSTEM_CALL_GET_SET_SYSTEM_INFORMATION Request;
- KSTATUS Status;
- Buffer = NULL;
- Request = SystemCallParameter;
- //
- // Create a paged pool buffer to hold the data.
- //
- CopySize = 0;
- if (Request->DataSize != 0) {
- Buffer = MmAllocatePagedPool(Request->DataSize,
- KE_INFORMATION_ALLOCATION_TAG);
- if (Buffer == NULL) {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto SysGetSetSystemInformationEnd;
- }
- CopySize = Request->DataSize;
- //
- // Copy the data into the kernel mode buffer.
- //
- Status = MmCopyFromUserMode(Buffer,
- Request->Data,
- Request->DataSize);
- if (!KSUCCESS(Status)) {
- goto SysGetSetSystemInformationEnd;
- }
- }
- Status = KepGetSetSystemInformation(FALSE,
- Request->Subsystem,
- Request->InformationType,
- Buffer,
- &(Request->DataSize),
- Request->Set);
- //
- // Copy the data back into user mode, even on set operations.
- //
- if (CopySize > Request->DataSize) {
- CopySize = Request->DataSize;
- }
- if (CopySize != 0) {
- CopyStatus = MmCopyToUserMode(Request->Data, Buffer, CopySize);
- if ((KSUCCESS(Status)) && (!KSUCCESS(CopyStatus))) {
- Status = CopyStatus;
- }
- }
- SysGetSetSystemInformationEnd:
- if (Buffer != NULL) {
- MmFreePagedPool(Buffer);
- }
- return Status;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
- KSTATUS
- KepGetSetSystemInformation (
- BOOL FromKernelMode,
- SYSTEM_INFORMATION_SUBSYSTEM Subsystem,
- UINTN InformationType,
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets or sets system information.
- Arguments:
- FromKernelMode - Supplies a boolean indicating whether or not this request
- (and the buffer associated with it) originates from user mode (FALSE)
- or kernel mode (TRUE).
- Subsystem - Supplies the subsystem to query or set information of.
- InformationType - Supplies the information type, which is specific to
- the subsystem. The type of this value is generally
- <subsystem>_INFORMATION_TYPE (eg IO_INFORMATION_TYPE).
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- STATUS_SUCCESS if the information was successfully queried or set.
- STATUS_BUFFER_TOO_SMALL if the buffer size specified was too small. The
- required buffer size will be returned in the data size parameter.
- STATUS_DATA_LENGTH_MISMATCH if the buffer size was not correct. The
- correct buffer size will be returned in the data size parameter.
- STATUS_INVALID_PARAMETER if the given subsystem or information type is
- not known.
- Other status codes on other failures.
- --*/
- {
- KSTATUS Status;
- switch (Subsystem) {
- case SystemInformationKe:
- Status = KepGetSetKeSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- case SystemInformationIo:
- Status = IoGetSetSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- case SystemInformationMm:
- Status = MmGetSetSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- case SystemInformationPs:
- Status = PsGetSetSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- case SystemInformationHl:
- Status = HlGetSetSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- case SystemInformationSp:
- Status = SpGetSetSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- case SystemInformationPm:
- Status = PmGetSetSystemInformation(FromKernelMode,
- InformationType,
- Data,
- DataSize,
- Set);
- break;
- default:
- Status = STATUS_INVALID_PARAMETER;
- *DataSize = 0;
- break;
- }
- return Status;
- }
- KSTATUS
- KepGetSetKeSystemInformation (
- BOOL FromKernelMode,
- KE_INFORMATION_TYPE InformationType,
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets or sets system information.
- Arguments:
- FromKernelMode - Supplies a boolean indicating whether or not this request
- (and the buffer associated with it) originates from user mode (FALSE)
- or kernel mode (TRUE).
- InformationType - Supplies the information type.
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- KSTATUS Status;
- switch (InformationType) {
- case KeInformationSystemVersion:
- Status = KepGetSystemVersion(Data, DataSize, Set);
- break;
- case KeInformationFirmwareTable:
- Status = KepGetFirmwareTable(Data, DataSize, Set);
- break;
- case KeInformationFirmwareType:
- Status = KepGetFirmwareType(Data, DataSize, Set);
- break;
- case KeInformationProcessorUsage:
- Status = KepGetProcessorUsage(Data, DataSize, Set);
- break;
- case KeInformationProcessorCount:
- Status = KepGetProcessorCount(Data, DataSize, Set);
- break;
- case KeInformationKernelCommandLine:
- Status = KepGetKernelCommandLine(Data, DataSize, Set);
- break;
- case KeInformationBannerThread:
- Status = KepSetBannerThread(Data, DataSize, Set);
- break;
- default:
- Status = STATUS_INVALID_PARAMETER;
- *DataSize = 0;
- break;
- }
- return Status;
- }
- KSTATUS
- KepGetSystemVersion (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets OS version information.
- Arguments:
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- ULONG BufferSize;
- KSTATUS Status;
- SYSTEM_VERSION_INFORMATION VersionInformation;
- PSYSTEM_VERSION_INFORMATION VersionInformationPointer;
- if (Set != FALSE) {
- Status = STATUS_ACCESS_DENIED;
- return Status;
- }
- //
- // If the data is at least big enough to hold the version information
- // structure, then try to get everything.
- //
- if (*DataSize >= sizeof(SYSTEM_VERSION_INFORMATION)) {
- BufferSize = *DataSize - sizeof(SYSTEM_VERSION_INFORMATION);
- VersionInformationPointer = Data;
- Status = KeGetSystemVersion(VersionInformationPointer,
- Data + sizeof(SYSTEM_VERSION_INFORMATION),
- &BufferSize);
- if (KSUCCESS(Status)) {
- //
- // Make the string pointers into offsets for user mode.
- //
- if (VersionInformationPointer->ProductName != NULL) {
- VersionInformationPointer->ProductName =
- (PVOID)((UINTN)(VersionInformationPointer->ProductName) -
- (UINTN)Data);
- }
- if (VersionInformationPointer->BuildString != NULL) {
- VersionInformationPointer->BuildString =
- (PVOID)((UINTN)(VersionInformationPointer->BuildString) -
- (UINTN)Data);
- }
- }
- //
- // The data isn't even big enough for the version information structure.
- // Call out to get the true size.
- //
- } else {
- VersionInformationPointer = &VersionInformation;
- BufferSize = 0;
- KeGetSystemVersion(VersionInformationPointer,
- NULL,
- &BufferSize);
- Status = STATUS_BUFFER_TOO_SMALL;
- }
- BufferSize += sizeof(SYSTEM_VERSION_INFORMATION);
- *DataSize = BufferSize;
- return Status;
- }
- KSTATUS
- KepGetFirmwareTable (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets a system firmware table.
- Arguments:
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- PDESCRIPTION_HEADER AcpiTable;
- ULONG Length;
- PSMBIOS_ENTRY_POINT SmbiosTable;
- KSTATUS Status;
- if (Set != FALSE) {
- return STATUS_ACCESS_DENIED;
- }
- Status = PsCheckPermission(PERMISSION_SYSTEM_ADMINISTRATOR);
- if (!KSUCCESS(Status)) {
- return Status;
- }
- if (*DataSize < sizeof(DESCRIPTION_HEADER)) {
- *DataSize = sizeof(DESCRIPTION_HEADER);
- return STATUS_BUFFER_TOO_SMALL;
- }
- AcpiTable = AcpiFindTable(*((PULONG)Data), NULL);
- if (AcpiTable == NULL) {
- *DataSize = 0;
- return STATUS_NOT_FOUND;
- }
- if (*((PULONG)Data) == SMBIOS_ANCHOR_STRING_VALUE) {
- SmbiosTable = (PSMBIOS_ENTRY_POINT)AcpiTable;
- Length = sizeof(SMBIOS_ENTRY_POINT) + SmbiosTable->StructureTableLength;
- } else {
- Length = AcpiTable->Length;
- }
- if (*DataSize < Length) {
- *DataSize = Length;
- return STATUS_BUFFER_TOO_SMALL;
- }
- RtlCopyMemory(Data, AcpiTable, Length);
- *DataSize = Length;
- return STATUS_SUCCESS;
- }
- KSTATUS
- KepGetFirmwareType (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets the platform firmware type.
- Arguments:
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- if (Set != FALSE) {
- return STATUS_ACCESS_DENIED;
- }
- if (*DataSize < sizeof(ULONG)) {
- *DataSize = sizeof(ULONG);
- return STATUS_BUFFER_TOO_SMALL;
- }
- *((PULONG)Data) = KeSystemFirmwareType;
- *DataSize = sizeof(ULONG);
- return STATUS_SUCCESS;
- }
- KSTATUS
- KepGetProcessorUsage (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets processor usage information.
- Arguments:
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- PPROCESSOR_USAGE_INFORMATION Information;
- UINTN ProcessorCount;
- KSTATUS Status;
- if (Set != FALSE) {
- return STATUS_ACCESS_DENIED;
- }
- Status = PsCheckPermission(PERMISSION_RESOURCES);
- if (!KSUCCESS(Status)) {
- return Status;
- }
- if (*DataSize != sizeof(PROCESSOR_USAGE_INFORMATION)) {
- *DataSize = sizeof(PROCESSOR_USAGE_INFORMATION);
- return STATUS_DATA_LENGTH_MISMATCH;
- }
- Information = Data;
- Information->CycleCounterFrequency = HlQueryProcessorCounterFrequency();
- if (Information->ProcessorNumber == (UINTN)-1) {
- KeGetTotalProcessorCycleAccounting(&(Information->Usage));
- } else {
- ProcessorCount = KeGetActiveProcessorCount();
- if (Information->ProcessorNumber > ProcessorCount) {
- Information->ProcessorNumber = ProcessorCount;
- return STATUS_OUT_OF_BOUNDS;
- }
- Status = KeGetProcessorCycleAccounting(Information->ProcessorNumber,
- &(Information->Usage));
- return Status;
- }
- return STATUS_SUCCESS;
- }
- KSTATUS
- KepGetProcessorCount (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets processor count information.
- Arguments:
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- PPROCESSOR_COUNT_INFORMATION Information;
- KSTATUS Status;
- if (Set != FALSE) {
- return STATUS_ACCESS_DENIED;
- }
- Status = PsCheckPermission(PERMISSION_RESOURCES);
- if (!KSUCCESS(Status)) {
- return Status;
- }
- if (*DataSize != sizeof(PROCESSOR_COUNT_INFORMATION)) {
- *DataSize = sizeof(PROCESSOR_COUNT_INFORMATION);
- return STATUS_DATA_LENGTH_MISMATCH;
- }
- Information = Data;
- Information->MaxProcessorCount = HlGetMaximumProcessorCount();
- Information->ActiveProcessorCount = KeGetActiveProcessorCount();
- return STATUS_SUCCESS;
- }
- KSTATUS
- KepGetKernelCommandLine (
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets the kernel command line information.
- Arguments:
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the
- data buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or
- a set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- if (Set != FALSE) {
- return STATUS_ACCESS_DENIED;
- }
- if (KeCommandLine == NULL) {
- return STATUS_NOT_FOUND;
- }
- if (*DataSize < KeCommandLine->LineSize) {
- *DataSize = KeCommandLine->LineSize;
- return STATUS_BUFFER_TOO_SMALL;
- }
- RtlCopyMemory(Data, KeCommandLine->Line, KeCommandLine->LineSize);
- return STATUS_SUCCESS;
- }
|