pm.c
来自「适合KS8695X」· C语言 代码 · 共 934 行 · 第 1/2 页
C
934 行
/****************************************************************************
REMARKS:
Maps a shared memory block into process address space. Does nothing since
the memory blocks are already globally mapped into all processes.
****************************************************************************/
void * PMAPI PM_mapToProcess(
void *base,
ulong limit)
{
/* Not used anymore */
(void)base;
(void)limit;
return NULL;
}
/****************************************************************************
REMARKS:
Execute the POST on the secondary BIOS for a controller.
****************************************************************************/
ibool PMAPI PM_doBIOSPOST(
ushort axVal,
ulong BIOSPhysAddr,
void *mappedBIOS,
ulong BIOSLen)
{
/* This may not be possible in NT and should be done by the OS anyway */
(void)axVal;
(void)BIOSPhysAddr;
(void)mappedBIOS;
(void)BIOSLen;
return false;
}
/****************************************************************************
REMARKS:
Return a pointer to the real mode BIOS data area.
****************************************************************************/
void * PMAPI PM_getBIOSPointer(void)
{
/* Note that on NT this probably does not do what we expect! */
return PM_mapPhysicalAddr(0x400, 0x1000, true);
}
/****************************************************************************
REMARKS:
Return a pointer to 0xA0000 physical VGA graphics framebuffer.
****************************************************************************/
void * PMAPI PM_getA0000Pointer(void)
{
return PM_mapPhysicalAddr(0xA0000,0xFFFF,false);
}
/****************************************************************************
REMARKS:
Sleep for the specified number of milliseconds.
****************************************************************************/
void PMAPI PM_sleep(
ulong milliseconds)
{
/* We never use this in NT drivers */
(void)milliseconds;
}
/****************************************************************************
REMARKS:
Return the base I/O port for the specified COM port.
****************************************************************************/
int PMAPI PM_getCOMPort(int port)
{
/* TODO: Re-code this to determine real values using the Plug and Play */
/* manager for the OS. */
switch (port) {
case 0: return 0x3F8;
case 1: return 0x2F8;
case 2: return 0x3E8;
case 3: return 0x2E8;
}
return 0;
}
/****************************************************************************
REMARKS:
Return the base I/O port for the specified LPT port.
****************************************************************************/
int PMAPI PM_getLPTPort(int port)
{
/* TODO: Re-code this to determine real values using the Plug and Play */
/* manager for the OS. */
switch (port) {
case 0: return 0x3BC;
case 1: return 0x378;
case 2: return 0x278;
}
return 0;
}
/****************************************************************************
REMARKS:
Returns available memory. Not possible under Windows.
****************************************************************************/
void PMAPI PM_availableMemory(
ulong *physical,
ulong *total)
{
*physical = *total = 0;
}
/****************************************************************************
REMARKS:
OS specific shared libraries not supported inside a VxD
****************************************************************************/
PM_MODULE PMAPI PM_loadLibrary(
const char *szDLLName)
{
/* Not used in NT drivers */
(void)szDLLName;
return NULL;
}
/****************************************************************************
REMARKS:
OS specific shared libraries not supported inside a VxD
****************************************************************************/
void * PMAPI PM_getProcAddress(
PM_MODULE hModule,
const char *szProcName)
{
/* Not used in NT drivers */
(void)hModule;
(void)szProcName;
return NULL;
}
/****************************************************************************
REMARKS:
OS specific shared libraries not supported inside a VxD
****************************************************************************/
void PMAPI PM_freeLibrary(
PM_MODULE hModule)
{
/* Not used in NT drivers */
(void)hModule;
}
/****************************************************************************
REMARKS:
Function to find the first file matching a search criteria in a directory.
****************************************************************************/
void *PMAPI PM_findFirstFile(
const char *filename,
PM_findData *findData)
{
/* TODO: This function should start a directory enumeration search */
/* given the filename (with wildcards). The data should be */
/* converted and returned in the findData standard form. */
(void)filename;
(void)findData;
return PM_FILE_INVALID;
}
/****************************************************************************
REMARKS:
Function to find the next file matching a search criteria in a directory.
****************************************************************************/
ibool PMAPI PM_findNextFile(
void *handle,
PM_findData *findData)
{
/* TODO: This function should find the next file in directory enumeration */
/* search given the search criteria defined in the call to */
/* PM_findFirstFile. The data should be converted and returned */
/* in the findData standard form. */
(void)handle;
(void)findData;
return false;
}
/****************************************************************************
REMARKS:
Function to close the find process
****************************************************************************/
void PMAPI PM_findClose(
void *handle)
{
/* TODO: This function should close the find process. This may do */
/* nothing for some OS'es. */
(void)handle;
}
/****************************************************************************
REMARKS:
Function to determine if a drive is a valid drive or not. Under Unix this
function will return false for anything except a value of 3 (considered
the root drive, and equivalent to C: for non-Unix systems). The drive
numbering is:
1 - Drive A:
2 - Drive B:
3 - Drive C:
etc
****************************************************************************/
ibool PMAPI PM_driveValid(
char drive)
{
/* Not supported in NT drivers */
(void)drive;
return false;
}
/****************************************************************************
REMARKS:
Function to get the current working directory for the specififed drive.
Under Unix this will always return the current working directory regardless
of what the value of 'drive' is.
****************************************************************************/
void PMAPI PM_getdcwd(
int drive,
char *dir,
int len)
{
/* Not supported in NT drivers */
(void)drive;
(void)dir;
(void)len;
}
/****************************************************************************
PARAMETERS:
base - The starting physical base address of the region
size - The size in bytes of the region
type - Type to place into the MTRR register
RETURNS:
Error code describing the result.
REMARKS:
Function to enable write combining for the specified region of memory.
****************************************************************************/
int PMAPI PM_enableWriteCombine(
ulong base,
ulong size,
uint type)
{
return MTRR_enableWriteCombine(base,size,type);
}
/****************************************************************************
REMARKS:
Function to change the file attributes for a specific file.
****************************************************************************/
void PMAPI PM_setFileAttr(
const char *filename,
uint attrib)
{
NTSTATUS status;
ACCESS_MASK DesiredAccess = GENERIC_READ | GENERIC_WRITE;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG ShareAccess = FILE_SHARE_READ;
ULONG CreateDisposition = FILE_OPEN;
HANDLE FileHandle = NULL;
UNICODE_STRING *uniFile = NULL;
IO_STATUS_BLOCK IoStatusBlock;
FILE_BASIC_INFORMATION FileBasic;
char kernelFilename[PM_MAX_PATH+5];
ULONG FileAttributes = 0;
/* Convert file attribute flags */
if (attrib & PM_FILE_READONLY)
FileAttributes |= FILE_ATTRIBUTE_READONLY;
if (attrib & PM_FILE_ARCHIVE)
FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
if (attrib & PM_FILE_HIDDEN)
FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
if (attrib & PM_FILE_SYSTEM)
FileAttributes |= FILE_ATTRIBUTE_SYSTEM;
/* Add prefix for addressing the file system. "\??\" is short for "\DosDevices\" */
strcpy(kernelFilename, "\\??\\");
strcat(kernelFilename, filename);
/* Convert filename string to ansi string */
if ((uniFile = _PM_CStringToUnicodeString(kernelFilename)) == NULL)
goto Exit;
/* Must open a file to query it's attributes */
InitializeObjectAttributes (&ObjectAttributes,
uniFile,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
status = ZwCreateFile( &FileHandle,
DesiredAccess | SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
NULL, /*AllocationSize OPTIONAL, */
FILE_ATTRIBUTE_NORMAL,
ShareAccess,
CreateDisposition,
FILE_RANDOM_ACCESS, /*CreateOptions, */
NULL, /*EaBuffer OPTIONAL, */
0 /*EaLength (required if EaBuffer) */
);
if (!NT_SUCCESS (status))
goto Exit;
/* Query timestamps */
status = ZwQueryInformationFile(FileHandle,
&IoStatusBlock,
&FileBasic,
sizeof(FILE_BASIC_INFORMATION),
FileBasicInformation
);
if (!NT_SUCCESS (status))
goto Exit;
/* Change the four bits we change */
FileBasic.FileAttributes &= ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE
| FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
FileBasic.FileAttributes |= FileAttributes;
/* Set timestamps */
ZwSetInformationFile( FileHandle,
&IoStatusBlock,
&FileBasic,
sizeof(FILE_BASIC_INFORMATION),
FileBasicInformation
);
Exit:
if (FileHandle) ZwClose(FileHandle);
if (uniFile) _PM_FreeUnicodeString(uniFile);
return;
}
/****************************************************************************
REMARKS:
Function to get the file attributes for a specific file.
****************************************************************************/
uint PMAPI PM_getFileAttr(
const char *filename)
{
NTSTATUS status;
ACCESS_MASK DesiredAccess = GENERIC_READ | GENERIC_WRITE;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG ShareAccess = FILE_SHARE_READ;
ULONG CreateDisposition = FILE_OPEN;
HANDLE FileHandle = NULL;
UNICODE_STRING *uniFile = NULL;
IO_STATUS_BLOCK IoStatusBlock;
FILE_BASIC_INFORMATION FileBasic;
char kernelFilename[PM_MAX_PATH+5];
ULONG FileAttributes = 0;
uint retval = 0;
/* Add prefix for addressing the file system. "\??\" is short for "\DosDevices\" */
strcpy(kernelFilename, "\\??\\");
strcat(kernelFilename, filename);
/* Convert filename string to ansi string */
if ((uniFile = _PM_CStringToUnicodeString(kernelFilename)) == NULL)
goto Exit;
/* Must open a file to query it's attributes */
InitializeObjectAttributes (&ObjectAttributes,
uniFile,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
status = ZwCreateFile( &FileHandle,
DesiredAccess | SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
NULL, /*AllocationSize OPTIONAL, */
FILE_ATTRIBUTE_NORMAL,
ShareAccess,
CreateDisposition,
FILE_RANDOM_ACCESS, /*CreateOptions, */
NULL, /*EaBuffer OPTIONAL, */
0 /*EaLength (required if EaBuffer) */
);
if (!NT_SUCCESS (status))
goto Exit;
/* Query timestamps */
status = ZwQueryInformationFile(FileHandle,
&IoStatusBlock,
&FileBasic,
sizeof(FILE_BASIC_INFORMATION),
FileBasicInformation
);
if (!NT_SUCCESS (status))
goto Exit;
/* Translate the file attributes */
if (FileBasic.FileAttributes & FILE_ATTRIBUTE_READONLY)
retval |= PM_FILE_READONLY;
if (FileBasic.FileAttributes & FILE_ATTRIBUTE_ARCHIVE)
retval |= PM_FILE_ARCHIVE;
if (FileBasic.FileAttributes & FILE_ATTRIBUTE_HIDDEN)
retval |= PM_FILE_HIDDEN;
if (FileBasic.FileAttributes & FILE_ATTRIBUTE_SYSTEM)
retval |= PM_FILE_SYSTEM;
Exit:
if (FileHandle) ZwClose(FileHandle);
if (uniFile) _PM_FreeUnicodeString(uniFile);
return retval;
}
/****************************************************************************
REMARKS:
Function to create a directory.
****************************************************************************/
ibool PMAPI PM_mkdir(
const char *filename)
{
/* Not supported in NT drivers */
(void)filename;
return false;
}
/****************************************************************************
REMARKS:
Function to remove a directory.
****************************************************************************/
ibool PMAPI PM_rmdir(
const char *filename)
{
/* Not supported in NT drivers */
(void)filename;
return false;
}
/****************************************************************************
REMARKS:
Function to get the file time and date for a specific file.
****************************************************************************/
ibool PMAPI PM_getFileTime(
const char *filename,
ibool gmTime,
PM_time *time)
{
/* Not supported in NT drivers */
(void)filename;
(void)gmTime;
(void)time;
return false;
}
/****************************************************************************
REMARKS:
Function to set the file time and date for a specific file.
****************************************************************************/
ibool PMAPI PM_setFileTime(
const char *filename,
ibool gmTime,
PM_time *time)
{
/* Not supported in NT drivers */
(void)filename;
(void)gmTime;
(void)time;
return false;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?