Initial revision

svn path=/trunk/; revision=8
This commit is contained in:
Rex Jolliff 1998-08-25 04:27:26 +00:00
parent 336c153bd9
commit 9e7d29f65a
121 changed files with 21313 additions and 0 deletions

27
reactos/doc/ddkfuncs.txt Normal file
View file

@ -0,0 +1,27 @@
This is a list of the functions documented in the ddk that have been
implemented
IoAllocateController
IoFreeController
IoCreateController
IoDeleteController
IoStartNextPacket
IoStartNextPacketByKey
IoStartPacket
IoSizeOfIrp
IoMarkIrpPending
IoFreeIrp
IoConnectInterrupt
IoDisconnectInterrupt
IoGetCurrentIrpStackLocation
IoGetNextIrpStackLocation
IoRequestDpc
IoInitializeDpc
IoInitializeTimer
IoStartTimer
IoStopTimer
Partially implemented
IoCreateDevice
IoCallDriver

19
reactos/doc/debug.txt Normal file
View file

@ -0,0 +1,19 @@
Some notes on debugging the ReactOS kernel
------------------------------------------
* Interpreting crashes
If the kernel causes a fatal cpu fault then it will print out a message and
halt. This message contains important information for debugging the problem,
look for these lines
Exception: xx(yy)
CS:EIP 20:zzzzzzzzzzzz
Here xx is the type of error, usually either 14 or 13 and yy is the error
code. Generally error codes 13 and 14 both mean the kernel tried to access
some memory in an invalid way. zzzzzzzzz is the address of the erronous
instruction.
* Debugging with bochs

11
reactos/drivers/readme Normal file
View file

@ -0,0 +1,11 @@
These are a selection of services for the ReactOS kernel. They include
parallel = parallel port driver
serial = serial port driver
mouse = mouse driver
null = null device driver
ide = IDE (hard disk) driver
keyboard = keyboard driver
loop = Allows accessing a file as a block device
scramdisk = Filesystem encryption driver
event = Sample driver demonstrating notifying a user thread using an event

284
reactos/include/ddk/iodef.h Normal file
View file

@ -0,0 +1,284 @@
typedef enum _IO_QUERY_DEVICE_DESCRIPTION
{
IoQueryDeviceIdentifier = 0,
IoQueryDeviceConfigurationData,
IoQueryDeviceComponentInformation,
IoQueryDeviceDataFormatMaximum,
} IO_QUERY_DEVICE_DESCRIPTION, *PIO_QUERY_DEVICE_DESCRIPTION;
typedef enum _CONFIGURATION_TYPE
{
DiskController,
ParallelController,
MaximumType,
} CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
typedef enum _CM_RESOURCE_TYPE
{
CmResourceTypePort = 1,
CmResourceTypeInterrupt,
CmResourceTypeMemory,
CmResourceTypeDma,
CmResourceTypeDeviceSpecific,
CmResourceTypeMaximum,
} CM_RESOURCE_TYPE;
typedef enum _CM_SHARE_DISPOSITION
{
CmResourceShareDeviceExclusive = 1,
CmResourceShareDriverExclusive,
CmResourceShareShared,
CmResourceShareMaximum,
} CM_SHARE_DISPOSITION;
enum
{
CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE,
CM_RESOURCE_INTERRUPT_LATCHED,
};
enum
{
CM_RESOURCE_PORT_MEMORY,
CM_RESOURCE_PORT_IO,
};
/*
* PURPOSE: Irp flags
*/
enum
{
/*
* Read any data from the actual backing media
*/
IRP_NOCACHE,
/*
* The I/O operation is performing paging
*/
IRP_PAGING_IO,
/*
* The IRP is for a mount operation
*/
IRP_MOUNT_COMPLETION,
/*
* The API expects synchronous behaviour
*/
IRP_SYNCHRONOUS_API,
/*
* The IRP is associated with a larger operation
*/
IRP_ASSOCIATED_IRP,
/*
* The AssociatedIrp.SystemBuffer field is valid
*/
IRP_BUFFERED_IO,
/*
* The system buffer was allocated from pool and should be deallocated
* by the I/O manager
*/
IRP_DEALLOCATE_BUFFER,
/*
* The IRP is for an input operation
*/
IRP_INPUT_OPERATION,
/*
* The paging operation should complete synchronously
*/
IRP_SYNCHRONOUS_PAGING_IO,
/*
* The IRP represents a filesystem create operation
*/
IRP_CREATE_OPERATION,
/*
* The IRP represents a filesystem read operation
*/
IRP_READ_OPERATION,
/*
* The IRP represents a filesystem write operation
*/
IRP_WRITE_OPERATION,
/*
* The IRP represents a filesystem close operation
*/
IRP_CLOSE_OPERATION,
/*
* Asynchronous behavior is advised but not required
*/
IRP_DEFER_IO_COMPLETION,
};
/*
* I/O operation flags
*/
enum
{
/*
* Force an access check even if opened in kernel mode
*/
SL_FORCE_ACCESS_CHECK,
/*
* The file being opened is a paging file
*/
SL_OPEN_PAGING_FILE,
SL_OPEN_TARGET_DIRECTORY,
SL_CASE_SENSITIVE,
SL_KEY_SPECIFIED,
SL_OVERRIDE_VERIFY_VOLUME,
SL_WRITE_THROUGH,
SL_FT_SEQUENTIAL_WRITE,
SL_FAIL_IMMEDIATELY,
SL_EXCLUSIVE_LOCK,
SL_RESTART_SCAN,
SL_RETURN_SINGLE_ENTRY,
SL_INDEX_SPECIFIED,
SL_WATCH_TREE,
SL_ALLOW_RAW_MOUNT,
SL_PENDING_RETURNED,
};
enum
{
SL_INVOKE_ON_SUCCESS = 1,
SL_INVOKE_ON_ERROR = 2,
SL_INVOKE_ON_CANCEL = 4,
};
/*
* Possible flags for the device object flags
*/
enum
{
DO_BUFFERED_IO = 0x1,
DO_DIRECT_IO = 0x2,
};
/*
* Possible device types
*/
enum
{
/*
* Standard define types
*/
FILE_DEVICE_BEEP,
FILE_DEVICE_CDROM,
FILE_DEVICE_CONTROLLER,
FILE_DEVICE_DISK,
FILE_DEVICE_INPORT_PORT,
FILE_DEVICE_KEYBOARD,
FILE_DEVICE_MIDI_IN,
FILE_DEVICE_MIDI_OUT,
FILE_DEVICE_MOUSE,
FILE_DEVICE_NULL,
FILE_DEVICE_PARALLEL_PORT,
FILE_DEVICE_PRINTER,
FILE_DEVICE_SCANNER,
FILE_DEVICE_SERIAL_MOUSE_PORT,
FILE_DEVICE_SERIAL_PORT,
FILE_DEVICE_SCREEN,
FILE_DEVICE_TAPE,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_VIDEO,
FILE_DEVICE_VIRTUAL_DISK,
FILE_DEVICE_WAVE_IN,
FILE_DEVICE_WAVE_OUT,
FILE_DEVICE_8042_PORT,
/*
* Values beyond this are reserved for ISVs
*/
FILE_DEVICE_FIRST_FREE = 32768
};
/*
* Possible device characteristics
*/
enum
{
FILE_REMOVABLE_MEDIA = 0x1,
FILE_READ_ONLY_DEVICE = 0x2,
FILE_FLOPPY_DISKETTE = 0x4,
FILE_WRITE_ONCE_MEDIA = 0x8,
FILE_REMOTE_DEVICE = 0x10,
};
/*
* PURPOSE: Bus types
*/
enum
{
Internal,
Isa,
MicroChannel,
TurboChannel,
PCIBus,
MaximumInterfaceType,
};
/*
* FIXME: These are not in the correct order
*/
enum
{
IRP_MJ_CREATE,
IRP_MJ_CREATE_NAMED_PIPE,
IRP_MJ_CLOSE,
IRP_MJ_READ,
IRP_MJ_WRITE,
IRP_MJ_QUERY_INFORMATION,
IRP_MJ_SET_INFORMATION,
IRP_MJ_QUERY_EA,
IRP_MJ_SET_EA,
IRP_MJ_FLUSH_BUFFERS,
IRP_MJ_QUERY_VOLUME_INFORMATION,
IRP_MJ_SET_VOLUME_INFORMATION,
IRP_MJ_DIRECTORY_CONTROL,
IRP_MJ_FILE_SYSTEM_CONTROL,
IRP_MJ_DEVICE_CONTROL,
IRP_MJ_INTERNAL_DEVICE_CONTROL,
IRP_MJ_SHUTDOWN,
IRP_MJ_LOCK_CONTROL,
IRP_MJ_CLEANUP,
IRP_MJ_CREATE_MAILSLOT,
IRP_MJ_QUERY_SECURITY,
IRP_MJ_SET_SECURITY,
IRP_MJ_QUERY_POWER,
IRP_MJ_SET_POWER,
IRP_MJ_DEVICE_CHANGE,
IRP_MJ_QUERY_QUOTA,
IRP_MJ_SET_QUOTA,
IRP_MJ_PNP_POWER,
IRP_MJ_MAXIMUM_FUNCTION,
};

View file

@ -0,0 +1,41 @@
typedef enum _KINTERRUPT_MODE
{
LevelSensitive,
Latched,
} KINTERRUPT_MODE;
typedef enum _EVENT_TYPE
{
NotificationEvent,
SynchronizationEvent,
} EVENT_TYPE;
typedef enum _KWAIT_REASON
{
Executive,
FreePage,
PageIn,
PoolAllocation,
DelayExecution,
Suspended,
UserRequest,
WrExecutive,
WrFreePage,
WrPageIn,
WrDelayExecution,
WrSuspended,
WrUserRequest,
WrQueue,
WrLpcReceive,
WrLpcReply,
WrVirtualMemory,
WrPageOut,
WrRendezvous,
Spare2,
Spare3,
Spare4,
Spare5,
Spare6,
WrKernel,
MaximumWaitReason,
} KWAIT_REASON;

View file

@ -0,0 +1,10 @@
typedef ULONG ACCESS_MODE, *PACCESS_MODE;
typedef struct _SECURITY_SUBJECT_CONTEXT
{
} SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
typedef struct _SECURITY_DESCRIPTOR_CONTEXT
{
} SECURITY_DESCRIPTOR_CONTEXT, *PSECURITY_DESCRIPTOR_CONTEXT;

View file

@ -0,0 +1,2 @@
extern KSPIN_LOCK DispatcherDatabaseLock;
extern BOOLEAN WaitSet;

View file

@ -0,0 +1,665 @@
;
; kernel32.def
;
; Exports for KERNEL32 DLL
;
; Copyright (C) 1996 Free Software Foundation, Inc.
;
; Author: Scott Christley <scottc@net-community.com>
; Date: 1996
;
; This file is part of the Windows32 API Library.
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Library General Public
; License as published by the Free Software Foundation; either
; version 2 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Library General Public License for more details.
;
; If you are interested in a warranty or support for this source code,
; contact Scott Christley <scottc@net-community.com> for more information.
;
; You should have received a copy of the GNU Library General Public
; License along with this library; see the file COPYING.LIB.
; If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;
LIBRARY KERNEL32
EXPORTS
AddAtomA@4
AddAtomW@4
AddConsoleAliasA@12
AddConsoleAliasW@12
AllocConsole@0
AreFileApisANSI@0
BackupRead@28
BackupSeek@24
BackupWrite@28
BaseAttachCompleteThunk@0
Beep@8
BeginUpdateResourceA@8
BeginUpdateResourceW@8
BuildCommDCBA@8
BuildCommDCBAndTimeoutsA@12
BuildCommDCBAndTimeoutsW@12
BuildCommDCBW@8
CallNamedPipeA@28
CallNamedPipeW@28
ClearCommBreak@4
ClearCommError@12
CloseConsoleHandle@4
CloseHandle@4
CloseProfileUserMapping@0
CmdBatNotification@4
CommConfigDialogA@12
CommConfigDialogW@12
CompareFileTime@8
CompareStringA@24
CompareStringW@24
ConnectNamedPipe@8
ConsoleMenuControl@12
ContinueDebugEvent@12
ConvertDefaultLocale@4
CopyFileA@12
CopyFileW@12
CreateConsoleScreenBuffer@20
CreateDirectoryA@8
CreateDirectoryExA@12
CreateDirectoryExW@12
CreateDirectoryW@8
CreateEventA@16
CreateEventW@16
CreateFileA@28
CreateFileMappingA@24
CreateFileMappingW@24
CreateFileW@28
CreateIoCompletionPort@16
CreateMailslotA@16
CreateMailslotW@16
CreateMutexA@12
CreateMutexW@12
CreateNamedPipeA@32
CreateNamedPipeW@32
CreatePipe@16
CreateProcessA@40
CreateProcessW@40
CreateRemoteThread@28
CreateSemaphoreA@16
CreateSemaphoreW@16
CreateTapePartition@16
CreateThread@24
CreateVirtualBuffer@12
DebugActiveProcess@4
DebugBreak@0
DefineDosDeviceA@12
DefineDosDeviceW@12
DeleteAtom@4
DeleteCriticalSection@4
DeleteFileA@4
DeleteFileW@4
DeviceIoControl@32
DisableThreadLibraryCalls@4
DisconnectNamedPipe@4
DosDateTimeToFileTime@12
DuplicateConsoleHandle@16
DuplicateHandle@28
EndUpdateResourceA@8
EndUpdateResourceW@8
EnterCriticalSection@4
EnumCalendarInfoA@16
EnumCalendarInfoW@16
EnumDateFormatsA@12
EnumDateFormatsW@12
EnumResourceLanguagesA@20
EnumResourceLanguagesW@20
EnumResourceNamesA@16
EnumResourceNamesW@16
EnumResourceTypesA@12
EnumResourceTypesW@12
EnumSystemCodePagesA@8
EnumSystemCodePagesW@8
EnumSystemLocalesA@8
EnumSystemLocalesW@8
EnumTimeFormatsA@12
EnumTimeFormatsW@12
EraseTape@12
EscapeCommFunction@8
ExitProcess@4
ExitThread@4
ExitVDM@8
ExpandEnvironmentStringsA@12
ExpandEnvironmentStringsW@12
ExpungeConsoleCommandHistoryA@4
ExpungeConsoleCommandHistoryW@4
ExtendVirtualBuffer@8
FatalAppExitA@8
FatalAppExitW@8
FatalExit@4
FileTimeToDosDateTime@12
FileTimeToLocalFileTime@8
FileTimeToSystemTime@8
FillConsoleOutputAttribute@20
FillConsoleOutputCharacterA@20
FillConsoleOutputCharacterW@20
FindAtomA@4
FindAtomW@4
FindClose@4
FindCloseChangeNotification@4
FindFirstChangeNotificationA@12
FindFirstChangeNotificationW@12
FindFirstFileA@8
FindFirstFileW@8
FindNextChangeNotification@4
FindNextFileA@8
FindNextFileW@8
FindResourceA@12
FindResourceExA@16
FindResourceExW@16
FindResourceW@12
FlushConsoleInputBuffer@4
FlushFileBuffers@4
FlushInstructionCache@12
FlushViewOfFile@8
FoldStringA@20
FoldStringW@20
FormatMessageA@28
FormatMessageW@28
FreeConsole@0
FreeEnvironmentStringsA@4
FreeEnvironmentStringsW@4
FreeLibrary@4
FreeLibraryAndExitThread@8
FreeResource@4
FreeVirtualBuffer@4
GenerateConsoleCtrlEvent@8
GetACP@0
GetAtomNameA@12
GetAtomNameW@12
GetBinaryType@8
GetBinaryTypeA@8
GetBinaryTypeW@8
GetCPInfo@8
GetCommConfig@12
GetCommMask@8
GetCommModemStatus@8
GetCommProperties@8
GetCommState@8
GetCommTimeouts@8
GetCommandLineA@0
GetCommandLineW@0
GetCompressedFileSizeA@8
GetCompressedFileSizeW@8
GetComputerNameA@8
GetComputerNameW@8
GetConsoleAliasA@16
GetConsoleAliasExesA@8
GetConsoleAliasExesLengthA@0
GetConsoleAliasExesLengthW@0
GetConsoleAliasExesW@8
GetConsoleAliasW@16
GetConsoleAliasesA@12
GetConsoleAliasesLengthA@4
GetConsoleAliasesLengthW@4
GetConsoleAliasesW@12
GetConsoleCP@0
GetConsoleCommandHistoryA@12
GetConsoleCommandHistoryLengthA@4
GetConsoleCommandHistoryLengthW@4
GetConsoleCommandHistoryW@12
GetConsoleCursorInfo@8
GetConsoleDisplayMode@4
GetConsoleFontInfo@16
GetConsoleFontSize@8
GetConsoleHardwareState@12
GetConsoleInputWaitHandle@0
GetConsoleMode@8
GetConsoleOutputCP@0
GetConsoleScreenBufferInfo@8
GetConsoleTitleA@8
GetConsoleTitleW@8
GetCurrencyFormatA@24
GetCurrencyFormatW@24
GetCurrentConsoleFont@12
GetCurrentDirectoryA@8
GetCurrentDirectoryW@8
GetCurrentProcess@0
GetCurrentProcessId@0
GetCurrentThread@0
GetCurrentThreadId@0
GetDateFormatA@24
GetDateFormatW@24
GetDefaultCommConfigA@12
GetDefaultCommConfigW@12
GetDiskFreeSpaceA@20
GetDiskFreeSpaceW@20
GetDriveTypeA@4
GetDriveTypeW@4
GetEnvironmentStrings@0
GetEnvironmentStringsA@0
GetEnvironmentStringsW@0
GetEnvironmentVariableA@12
GetEnvironmentVariableW@12
GetExitCodeProcess@8
GetExitCodeThread@8
GetFileAttributesA@4
GetFileAttributesW@4
GetFileInformationByHandle@8
GetFileSize@8
GetFileTime@16
GetFileType@4
GetFullPathNameA@16
GetFullPathNameW@16
GetHandleInformation@8
GetLargestConsoleWindowSize@4
GetLastError@0
GetLocalTime@4
GetLocaleInfoA@16
GetLocaleInfoW@16
GetLogicalDriveStringsA@8
GetLogicalDriveStringsW@8
GetLogicalDrives@0
GetMailslotInfo@20
GetModuleFileNameA@12
GetModuleFileNameW@12
GetModuleHandleA@4
GetModuleHandleW@4
GetNamedPipeHandleStateA@28
GetNamedPipeHandleStateW@28
GetNamedPipeInfo@20
GetNextVDMCommand@4
GetNumberFormatA@24
GetNumberFormatW@24
GetNumberOfConsoleFonts@0
GetNumberOfConsoleInputEvents@8
GetNumberOfConsoleMouseButtons@4
GetOEMCP@0
GetOverlappedResult@16
GetPriorityClass@4
GetPrivateProfileIntA@16
GetPrivateProfileIntW@16
GetPrivateProfileSectionA@16
GetPrivateProfileSectionNamesA@12
GetPrivateProfileSectionNamesW@12
GetPrivateProfileSectionW@16
GetPrivateProfileStringA@24
GetPrivateProfileStringW@24
GetPrivateProfileStructA@20
GetPrivateProfileStructW@20
GetProcAddress@8
GetProcessAffinityMask@12
GetProcessHeap@0
GetProcessHeaps@8
GetProcessShutdownParameters@8
GetProcessTimes@20
GetProcessVersion@4
GetProcessWorkingSetSize@12
GetProfileIntA@12
GetProfileIntW@12
GetProfileSectionA@12
GetProfileSectionW@12
GetProfileStringA@20
GetProfileStringW@20
GetQueuedCompletionStatus@20
GetShortPathNameA@12
GetShortPathNameW@12
GetStartupInfoA@4
GetStartupInfoW@4
GetStdHandle@4
GetStringTypeA@20
GetStringTypeExA@20
GetStringTypeExW@20
GetStringTypeW@16
GetSystemDefaultLCID@0
GetSystemDefaultLangID@0
GetSystemDirectoryA@8
GetSystemDirectoryW@8
GetSystemInfo@4
GetSystemPowerStatus@4
GetSystemTime@4
GetSystemTimeAdjustment@12
GetSystemTimeAsFileTime@4
GetTapeParameters@16
GetTapePosition@20
GetTapeStatus@4
GetTempFileNameA@16
GetTempFileNameW@16
GetTempPathA@8
GetTempPathW@8
GetThreadContext@8
_imp__GetThreadContext@8
GetThreadLocale@0
GetThreadPriority@4
GetThreadSelectorEntry@12
GetThreadTimes@20
GetTickCount@0
GetTimeFormatA@24
GetTimeFormatW@24
GetTimeZoneInformation@4
GetUserDefaultLCID@0
GetUserDefaultLangID@0
GetVDMCurrentDirectories@8
GetVersion@0
GetVersionExA@4
GetVersionExW@4
GetVolumeInformationA@32
GetVolumeInformationW@32
GetWindowsDirectoryA@8
GetWindowsDirectoryW@8
GlobalAddAtomA@4
GlobalAddAtomW@4
GlobalAlloc@8
GlobalCompact@4
GlobalDeleteAtom@4
GlobalFindAtomA@4
GlobalFindAtomW@4
GlobalFix@4
GlobalFlags@4
GlobalFree@4
GlobalGetAtomNameA@12
GlobalGetAtomNameW@12
GlobalHandle@4
GlobalLock@4
GlobalMemoryStatus@4
GlobalReAlloc@12
GlobalSize@4
GlobalUnWire@4
GlobalUnfix@4
GlobalUnlock@4
GlobalWire@4
HeapAlloc@12
HeapCompact@8
HeapCreate@12
HeapCreateTagsW@16
HeapDestroy@4
HeapExtend@16
HeapFree@12
HeapLock@4
HeapQueryTagW@20
HeapReAlloc@16
HeapSize@12
HeapSummary@12
HeapUnlock@4
HeapUsage@20
HeapValidate@12
HeapWalk@8
InitAtomTable@4
InitializeCriticalSection@4
InterlockedDecrement@4
InterlockedExchange@8
InterlockedIncrement@4
InvalidateConsoleDIBits@8
IsBadCodePtr@4
IsBadHugeReadPtr@8
IsBadHugeWritePtr@8
IsBadReadPtr@8
IsBadStringPtrA@8
IsBadStringPtrW@8
IsBadWritePtr@8
IsDBCSLeadByte@4
IsDBCSLeadByteEx@8
IsDebuggerPresent@0
IsValidCodePage@4
IsValidLocale@8
LCMapStringA@24
LCMapStringW@24
LeaveCriticalSection@4
LoadLibraryA@4
LoadLibraryExA@12
LoadLibraryExW@12
LoadLibraryW@4
LoadModule@8
LoadResource@8
LocalAlloc@8
LocalCompact@4
LocalFileTimeToFileTime@8
LocalFlags@4
LocalFree@4
LocalHandle@4
LocalLock@4
LocalReAlloc@12
LocalShrink@8
LocalSize@4
LocalUnlock@4
LockFile@20
LockFileEx@24
LockResource@4
MapViewOfFile@20
MapViewOfFileEx@24
MoveFileA@8
MoveFileExA@12
MoveFileExW@12
MoveFileW@8
MulDiv@12
MultiByteToWideChar@24
OpenConsoleW@16
OpenEventA@12
OpenEventW@12
OpenFile@12
OpenFileMappingA@12
OpenFileMappingW@12
OpenMutexA@12
OpenMutexW@12
OpenProcess@12
OpenProfileUserMapping@0
OpenSemaphoreA@12
OpenSemaphoreW@12
OutputDebugStringA@4
OutputDebugStringW@4
PeekConsoleInputA@16
PeekConsoleInputW@16
PeekNamedPipe@24
PostQueuedCompletionStatus@16
PrepareTape@12
PulseEvent@4
PurgeComm@8
QueryDosDeviceA@12
QueryDosDeviceW@12
QueryPerformanceCounter@4
QueryPerformanceFrequency@4
QueryWin31IniFilesMappedToRegistry@16
RaiseException@16
ReadConsoleA@20
ReadConsoleInputA@16
ReadConsoleInputW@16
ReadConsoleOutputA@20
ReadConsoleOutputAttribute@20
ReadConsoleOutputCharacterA@20
ReadConsoleOutputCharacterW@20
ReadConsoleOutputW@20
ReadConsoleW@20
ReadFile@20
ReadFileEx@20
ReadProcessMemory@20
RegisterConsoleVDM@44
RegisterWaitForInputIdle@4
RegisterWowBaseHandlers@4
RegisterWowExec@4
ReleaseMutex@4
ReleaseSemaphore@12
RemoveDirectoryA@4
RemoveDirectoryW@4
ResetEvent@4
ResumeThread@4
RtlFillMemory@12
RtlMoveMemory@12
RtlUnwind@16
RtlZeroMemory@8
ScrollConsoleScreenBufferA@20
ScrollConsoleScreenBufferW@20
SearchPathA@24
SearchPathW@24
SetCommBreak@4
SetCommConfig@12
SetCommMask@8
SetCommState@8
SetCommTimeouts@8
SetComputerNameA@4
SetComputerNameW@4
SetConsoleActiveScreenBuffer@4
SetConsoleCP@4
SetConsoleCommandHistoryMode@4
SetConsoleCtrlHandler@8
SetConsoleCursor@8
SetConsoleCursorInfo@8
SetConsoleCursorPosition@8
SetConsoleDisplayMode@12
SetConsoleFont@8
SetConsoleHardwareState@12
SetConsoleKeyShortcuts@16
SetConsoleMaximumWindowSize@8
SetConsoleMenuClose@4
SetConsoleMode@8
SetConsoleNumberOfCommandsA@8
SetConsoleNumberOfCommandsW@8
SetConsoleOutputCP@4
SetConsolePalette@12
SetConsoleScreenBufferSize@8
SetConsoleTextAttribute@8
SetConsoleTitleA@4
SetConsoleTitleW@4
SetConsoleWindowInfo@12
SetCurrentDirectoryA@4
SetCurrentDirectoryW@4
SetDefaultCommConfigA@12
SetDefaultCommConfigW@12
SetEndOfFile@4
SetEnvironmentVariableA@8
SetEnvironmentVariableW@8
SetErrorMode@4
SetEvent@4
SetFileApisToANSI@0
SetFileApisToOEM@0
SetFileAttributesA@8
SetFileAttributesW@8
SetFilePointer@16
SetFileTime@16
SetHandleCount@4
SetHandleInformation@12
SetLastConsoleEventActive@0
SetLastError@4
SetLocalTime@4
SetLocaleInfoA@12
SetLocaleInfoW@12
SetMailslotInfo@8
SetNamedPipeHandleState@16
SetPriorityClass@8
SetProcessShutdownParameters@8
SetProcessWorkingSetSize@12
SetStdHandle@8
SetSystemPowerState@8
SetSystemTime@4
SetSystemTimeAdjustment@8
SetTapeParameters@12
SetTapePosition@24
SetThreadAffinityMask@8
SetThreadContext@8
_imp__SetThreadContext@8
SetThreadLocale@4
SetThreadPriority@8
SetTimeZoneInformation@4
SetUnhandledExceptionFilter@4
SetVDMCurrentDirectories@8
SetVolumeLabelA@8
SetVolumeLabelW@8
SetupComm@12
ShowConsoleCursor@8
SizeofResource@8
Sleep@4
SleepEx@8
SuspendThread@4
SystemTimeToFileTime@8
SystemTimeToTzSpecificLocalTime@12
TerminateProcess@8
TerminateThread@8
TlsAlloc@0
TlsFree@4
TlsGetValue@4
TlsSetValue@8
TransactNamedPipe@28
TransmitCommChar@8
TrimVirtualBuffer@4
UnhandledExceptionFilter@4
UnlockFile@20
UnlockFileEx@20
UnmapViewOfFile@4
UpdateResourceA@24
UpdateResourceW@24
VDMConsoleOperation@8
VDMOperationStarted@4
VerLanguageNameA@12
VerLanguageNameW@12
VerifyConsoleIoHandle@4
VirtualAlloc@16
VirtualBufferExceptionHandler@12
VirtualFree@12
VirtualLock@8
VirtualProtect@16
VirtualProtectEx@20
VirtualQuery@12
VirtualQueryEx@16
VirtualUnlock@8
WaitCommEvent@12
WaitForDebugEvent@8
WaitForMultipleObjects@16
WaitForMultipleObjectsEx@20
WaitForSingleObject@8
WaitForSingleObjectEx@12
WaitNamedPipeA@8
WaitNamedPipeW@8
WideCharToMultiByte@32
WinExec@8
WriteConsoleA@20
WriteConsoleInputA@16
WriteConsoleInputVDMA@16
WriteConsoleInputVDMW@16
WriteConsoleInputW@16
WriteConsoleOutputA@20
WriteConsoleOutputAttribute@20
WriteConsoleOutputCharacterA@20
WriteConsoleOutputCharacterW@20
WriteConsoleOutputW@20
WriteConsoleW@20
WriteFile@20
WriteFileEx@20
WritePrivateProfileSectionA@12
WritePrivateProfileSectionW@12
WritePrivateProfileStringA@16
WritePrivateProfileStringW@16
WritePrivateProfileStructA@20
WritePrivateProfileStructW@20
WriteProcessMemory@20
WriteProfileSectionA@8
WriteProfileSectionW@8
WriteProfileStringA@12
WriteProfileStringW@12
WriteTapemark@16
_hread@12
_hwrite@12
_lclose@4
_lcreat@8
_llseek@12
_lopen@8
_lread@12
_lwrite@12
lstrcat@8
lstrcatA@8
lstrcatW@8
lstrcmp@8
lstrcmpA@8
lstrcmpW@8
lstrcmpi@8
lstrcmpiA@8
lstrcmpiW@8
lstrcpy@8
lstrcpyA@8
lstrcpyW@8
lstrcpyn@12
lstrcpynA@12
lstrcpynW@12
lstrlen@4
lstrlenA@4
lstrlenW@4

1053
reactos/lib/ntdll/ntdll.def Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,9 @@
; Machine generated, don't edit
NtAlertThread:
mov eax,4
lea edx,[esp+4]
int 2Eh
ret 14

View file

@ -0,0 +1,7 @@
#
# This defines the kernel entry points used by ntdll
#
# They have the following format
# <name> <system call number> <size of the parameters in bytes>
#
NtAlertThread 4 14

View file

@ -0,0 +1,70 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ex/fmutex.c
* PURPOSE: Implements fast mutexes
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID ExAcquireFastMutex(PFAST_MUTEX FastMutex)
{
KeEnterCriticalRegion();
ExAcquireFastMutexUnsafe(FastMutex);
}
VOID ExAcquireFastMutexUnsafe(PFAST_MUTEX FastMutex)
{
if (InterlockedDecrement(&(FastMutex->Count))==0)
{
return;
}
FastMutex->Contention++;
KeWaitForSingleObject(&(FastMutex->Event),Executive,KernelMode,
FALSE,NULL);
FastMutex->Owner=KeGetCurrentThread();
}
VOID ExInitializeFastMutex(PFAST_MUTEX FastMutex)
{
FastMutex->Count=1;
FastMutex->Owner=NULL;
FastMutex->Contention=0;
KeInitializeEvent(&(FastMutex->Event),SynchronizationEvent,FALSE);
}
VOID ExReleaseFastMutexUnsafe(PFAST_MUTEX FastMutex)
{
assert(FastMutex->Owner==KeGetCurrentThread());
FastMutex->Owner=NULL;
if (InterlockedIncrement(&(FastMutex->Count))<=0)
{
return;
}
KeSetEvent(&(FastMutex->Event),0,FALSE);
}
VOID ExReleaseFastMutex(PFAST_MUTEX FastMutex)
{
ExReleaseFastMutexUnsafe(FastMutex);
KeLeaveCriticalRegion();
}
BOOLEAN ExTryToAcquireFastMutex(PFAST_MUTEX FastMutex)
{
InterlockedCompareExchange(&(FastMutex->Count),0,0);
}

View file

@ -0,0 +1,45 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ex/interlck.c
* PURPOSE: Implements interlocked functions
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
INTERLOCKED_RESULT ExInterlockedDecrementLong(PLONG Addend,
PKSPIN_LOCK Lock)
{
UNIMPLEMENTED;
}
ULONG ExInterlockedExchangeUlong(PULONG Target,
ULONG Value,
PKSPIN_LOCK Lock)
{
UNIMPLEMENTED;
}
ULONG ExInterlockedAddUlong(PULONG Addend,
ULONG Increment,
PKSPIN_LOCK Lock)
{
UNIMPLEMENTED;
}
INTERLOCKED_RESULT ExInterlockedIncrementLong(PLONG Addend,
PKSPIN_LOCK Lock)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,133 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/excutive/resource.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
BOOLEAN ExAcquireResourceExclusive(PERESOURCE Resource, BOOLEAN Wait)
{
UNIMPLEMENTED;
}
BOOLEAN ExAcquireResourceExclusiveLite(PERESOURCE Resource, BOOLEAN Wait)
{
UNIMPLEMENTED;
}
BOOLEAN ExAcquireResourceSharedLite(PERESOURCE Resource, BOOLEAN Wait)
{
UNIMPLEMENTED;
}
VOID ExConvertExclusiveToSharedLite(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
ULONG ExGetExclusiveWaiterCount(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
BOOLEAN ExAcquireSharedStarveExclusive(PERESOURCE Resource, BOOLEAN Wait)
{
UNIMPLEMENTED;
}
BOOLEAN ExAcquireSharedWaitForExclusive(PERESOURCE Resource, BOOLEAN Wait)
{
UNIMPLEMENTED;
}
NTSTATUS ExDeleteResource(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
NTSTATUS ExDeleteResourceLite(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
ERESOURCE_THREAD ExGetCurrentResourceThread()
{
UNIMPLEMENTED;
}
ULONG ExGetSharedWaiterCount(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
NTSTATUS ExInitializeResource(PERESOURCE Resource)
{
}
NTSTATUS ExInitializeResourceLite(PERESOURCE Resource)
{
Resource->NumberOfSharedWaiters = 0;
Resource->NumberOfExclusiveWaiters = 0;
KeInitializeSpinLock(&Resource->SpinLock);
Resource->Flag=0;
KeInitializeEvent(&Resource->ExclusiveWaiters,SynchronizationEvent,
FALSE);
KeInitializeSemaphore(&Resource->SharedWaiters,5,0);
Resource->ActiveCount = 0;
}
BOOLEAN ExIsResourceAcquiredExclusiveLite(PERESOURCE Resource)
{
return(Resource->NumberOfExclusiveWaiters!=0);
}
BOOLEAN ExIsResourceAcquiredSharedLite(PERESOURCE Resource)
{
return(Resource->NumberOfSharedWaiters!=0);
}
VOID ExReinitializeResourceLite(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
VOID ExReleaseResource(PERESOURCE Resource)
{
UNIMPLEMENTED;
}
VOID ExReleaseResourceForThread(PERESOURCE Resource,
ERESOURCE_THREAD ResourceThreadId)
{
UNIMPLEMENTED;
}
VOID ExReleaseResourceForThreadLite(PERESOURCE Resource,
ERESOURCE_THREAD ResourceThreadId)
{
UNIMPLEMENTED;
}
BOOLEAN ExTryToAcquireResourceExclusiveLite(PERESOURCE Resource)
{
LARGE_INTEGER timeout;
timeout.HighPart = 0;
timeout.LowPart = 0;
KeWaitForSingleObject(&Resource->ExclusiveWaiters,Executive,KernelMode,
FALSE,&timeout);
}

View file

@ -0,0 +1,31 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/excutive/time.c
* PURPOSE: Time
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID ExLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
PLARGE_INTEGER SystemTime)
{
UNIMPLEMENTED;
}
VOID ExSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
PLARGE_INTEGER LocalTime)
{
UNIMPLEMENTED;
}

157
reactos/ntoskrnl/ex/work.c Normal file
View file

@ -0,0 +1,157 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/kernel/work.c
* PURPOSE: Manage system work queues
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 29/06/98: Created
*/
/* INCLUDES ******************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/debug.h>
/* TYPES *********************************************************************/
typedef struct
{
/*
* PURPOSE: Head of the list of waiting work items
*/
LIST_ENTRY Head;
/*
* PURPOSE: Sychronize access to the access
*/
KSPIN_LOCK Lock;
/*
* PURPOSE: Worker threads with nothing to do wait on this event
*/
KEVENT Busy;
/*
* PURPOSE: Thread associated with work queue
*/
HANDLE Thread;
} WORK_QUEUE, *PWORK_QUEUE;
/* GLOBALS *******************************************************************/
/*
* PURPOSE: Queue of items waiting to be processed at normal priority
*/
WORK_QUEUE normal_work_queue;
#define WAIT_INTERVAL (0)
/* FUNCTIONS ****************************************************************/
static NTSTATUS ExWorkerThreadEntryPoint(PVOID context)
/*
* FUNCTION: Entry point for a worker thread
* ARGUMENTS:
* context = Parameters
* RETURNS: Status
* NOTE: To kill a worker thread you must queue an item whose callback
* calls PsTerminateSystemThread
*/
{
PWORK_QUEUE param = (PWORK_QUEUE)context;
PWORK_QUEUE_ITEM item;
PLIST_ENTRY current;
while (1)
{
current = ExInterlockedRemoveHeadList(&param->Head,&param->Lock);
if (current!=NULL)
{
item = CONTAINING_RECORD(current,WORK_QUEUE_ITEM,Entry);
item->Routine(item->Context);
}
else
{
KeClearEvent(&param->Busy);
KeWaitForSingleObject((PVOID)&param->Busy,Executive,KernelMode,
FALSE,WAIT_INTERVAL);
}
};
}
static VOID ExKillWorkerThreadCallback(PVOID Context)
{
PsTerminateSystemThread(STATUS_SUCCESS);
}
void ExKillWorkerThreads(void)
/*
* FUNCTION: Kill all running worker threads in preparation for a shutdown
*/
{
WORK_QUEUE_ITEM item1;
ExInitializeWorkItem(&item1,ExKillWorkerThreadCallback,NULL);
ExQueueWorkItem(&item1,DelayedWorkQueue);
}
void ExInitializeWorkerThreads(void)
{
InitializeListHead(&normal_work_queue.Head);
KeInitializeSpinLock(&normal_work_queue.Lock);
KeInitializeEvent(&normal_work_queue.Busy,NotificationEvent,FALSE);
PsCreateSystemThread(&normal_work_queue.Thread,THREAD_ALL_ACCESS,
NULL,NULL,NULL,ExWorkerThreadEntryPoint,
&normal_work_queue);
}
VOID ExInitializeWorkItem(PWORK_QUEUE_ITEM Item,
PWORKER_THREAD_ROUTINE Routine,
PVOID Context)
/*
* FUNCTION: Initializes a work item to be processed by one of the system
* worker threads
* ARGUMENTS:
* Item = Pointer to the item to be initialized
* Routine = Routine to be called by the worker thread
* Context = Parameter to be passed to the callback
*/
{
ASSERT_IRQL(DISPATCH_LEVEL);
Item->Routine=Routine;
Item->Context=Context;
Item->Entry.Flink=NULL;
Item->Entry.Blink=NULL;
}
VOID ExQueueWorkItem(PWORK_QUEUE_ITEM WorkItem,
WORK_QUEUE_TYPE QueueType)
/*
* FUNCTION: Inserts a work item in a queue for one of the system worker
* threads to process
* ARGUMENTS:
* WorkItem = Item to insert
* QueueType = Queue to insert it in
*/
{
assert(WorkItem!=NULL);
ASSERT_IRQL(DISPATCH_LEVEL);
/*
* Insert the item in the appropiate queue and wake on any thread
* waiting for something to do
*/
switch(QueueType)
{
case DelayedWorkQueue:
ExInterlockedInsertTailList(&normal_work_queue.Head,&(WorkItem->Entry),
&normal_work_queue.Lock);
KeSetEvent(&normal_work_queue.Busy,IO_NO_INCREMENT,FALSE);
break;
};
}

View file

@ -0,0 +1,375 @@
#
# This lists all the symbols exported from the kernel to services
#
# NOTE: Give an export the name you normally call the function with
# This doesn't support overloading or class members
# Also the function should be defined with asmlinkage
#
#
#
DbgPrint
printk
ExAcquireFastMutex
ExAcquireFastMutexUnsafe
ExAcquireResourceExclusive
ExAcquireResourceExclusiveLite
ExAcquireResourceSharedLite
ExAcquireSharedStarveExclusive
ExAcquireSharedWaitForExclusive
ExAllocateFromNPagedLookasideList
ExAllocateFromPagedLookasideList
ExAllocateFromZone
ExAllocatePool
ExAllocatePoolWithQuota
ExAllocatePoolWithQuotaTag
ExAllocatePoolWithTag
ExConvertExclusiveToSharedLite
ExDeleteNPagedLookasideList
ExDeletePagedLookasideList
ExDeleteResource
ExDeleteResourceLite
ExExtendZone
ExFreePool
ExFreeToNPagedLookasideList
ExFreeToPagedLookasideList
ExFreeToZone
ExGetCurrentResourceThread
ExGetExclusiveWaiterCount
ExGetSharedWaiterCount
ExHookException
ExInitializeFastMutex
ExInitializeNPagedLookasideList
ExInitializePagedLookasideList
ExInitializeResource
ExInitializeResourceLite
ExInitializeSListHead
ExInitializeWorkItem
ExInitializeZone
ExInterlockedAddLargeInteger
ExInterlockedAddUlong
ExInterlockedAllocateFromZone
ExInterlockedDecrementLong
ExInterlockedExchangeUlong
ExInterlockedExtendZone
ExInterlockedFreeToZone
ExInterlockedIncrementLong
ExInterlockedInsertHeadList
ExInterlockedInsertTailList
ExInterlockedPopEntryList
ExInterlockedPopEntrySList
ExInterlockedPushEntryList
ExInterlockedPushEntrySList
ExInterlockedRemoveHeadList
ExIsFullZone
ExIsObjectInFirstZoneSegment
ExIsResourceAcquiredExclusiveLite
ExIsResourceAcquiredSharedLite
ExLocalTimeToSystemTime
ExQueryDepthSListHead
ExQueueWorkItem
ExRaiseStatus
ExReinitializeResourceLite
ExReleaseFastMutex
ExReleaseFastMutexUnsafe
ExReleaseResource
ExReleaseResourceForThread
ExReleaseResourceForThreadLite
ExSystemTimeToLocalTime
ExTryToAcquireFastMutex
ExTryToAcquireResourceExclusiveLite
InterlockedCompareExchange
InterlockedExchange
InterlockedExchangeAdd
InterlockedIncrement
HalAllocateCommonBuffer
HalAssignSlotResources
HalExamineMBR
HalFreeCommonBuffer
HalGetAdapter
HalGetBusData
HalGetBusDataByOffset
HalGetDmaAlignmentRequirement
HalGetInterruptVector
HalQuerySystemInformation
HalReadDmaCounter
HalSetBusData
HalSetBusDataByOffset
HalTranslateBusAddress
IoAcquireCancelSpinLock
IoAllocateAdapterChannel
IoAllocateController
IoAllocateErrorLogEntry
IoAllocateIrp
IoAllocateMdl
IoAssignArcName
IoAssignResources
IoAttachDevice
IoAttachDeviceByPointer
IoAttachDeviceToDeviceStack
IoBuildAsynchronousFsdRequest
IoBuildDeviceIoControlRequest
IoBuildPartialMdl
IoBuildSynchronousFsdRequest
IoCallDriver
IoCancelIrp
IoCheckShareAccess
IoCompleteRequest
IoConnectInterrupt
IoCreateController
IoCreateDevice
IoCreateNotificationEvent
IoCreateSymbolicLink
IoCreateSynchronizationEvent
IoCreateUnprotectedSymbolicLink
IoDeassignArcName
IoDeleteController
IoDeleteDevice
IoDeleteSymbolicLink
IoDetachDevice
IoDisconnectInterrupt
IoFlushAdapterBuffers
IoFreeAdapterChannel
IoFreeController
IoFreeIrp
IoFreeMapRegisters
IoFreeMdl
IoGetConfigurationInformation
IoGetCurrentIrpStackLocation
IoGetCurrentProcess
IoGetDeviceObjectPointer
IoGetDeviceToVerify
IoGetFileObjectGenericMapping
IoGetFunctionCodeFromCtlCode
IoGetInitialStack
IoGetNextIrpStackLocation
IoGetRelatedDeviceObject
IoInitializeDpcRequest
IoInitializeIrp
IoInitializeTimer
IoIsErrorUserInduced
IoIsTotalDeviceFailure
IoMakeAssociatedIrp
IoMapTransfer
IoMarkIrpPending
IoQueryDeviceDescription
IoRaiseHardError
IoRaiseInformationalHardError
IoReadPartitionTable
IoRegisterDriverReinitialization
IoRegisterShutdownNotification
IoReleaseCancelSpinLock
IoRemoveShareAccess
IoReportResourceUsage
IoRequestDpc
IoSetCancelRoutine
IoSetCompletionRoutine
IoSetHardErrorOrVerifyDevice
IoSetNextIrpStackLocation
IoSetPartitionInformation
IoSetShareAccess
IoSizeOfIrp
IoStartNextPacket
IoStartNextPacketByKey
IoStartPacket
IoStartTimer
IoStopTimer
IoUnregisterShutdownNotification
IoUpdateShareAccess
IoWriteErrorLogEntry
IoWritePartitionTable
KeAcquireSpinLock
KeAcquireSpinLockAtDpcLevel
KeBugCheck
KeBugCheckEx
KeCancelTimer
KeClearEvent
KeDelayExecutionThread
KeDeregisterBugCheckCallback
KeEnterCriticalRegion
KeFlushIoBuffers
KeGetCurrentIrql
KeGetCurrentProcessorNumber
KeGetDcacheFillSize
KeInitializeCallbackRecord
KeInitializeDeviceQueue
KeInitializeDpc
KeInitializeEvent
KeInitializeMutex
KeInitializeSemaphore
KeInitializeSpinLock
KeInitializeTimer
KeInitializeTimerEx
KeInsertByKeyDeviceQueue
KeInsertDeviceQueue
KeInsertQueueDpc
KeLeaveCriticalRegion
KeLowerIrql
KeQueryPerformanceCounter
KeQuerySystemTime
KeQueryTickCount
KeQueryTimeIncrement
KeRaiseIrql
KeReadStateEvent
KeReadStateMutex
KeReadStateSemaphore
KeReadStateTimer
KeRegisterBugCheckCallback
KeReleaseMutex
KeReleaseSemaphore
KeReleaseSpinLock
KeReleaseSpinLockFromDpcLevel
KeRemoveByKeyDeviceQueue
KeRemoveDeviceQueue
KeRemoveQueueDpc
KeResetEvent
KeSetBasePriorityThread
KeSetEvent
KeSetPriorityThread
KeSetTimer
KeSetTimerEx
KeStallExecutionProcessor
KeSynchronizeExecution
KeWaitForMultipleObjects
KeWaitForMutexObject
KeWaitForSingleObject
MmAllocateContiguousMemory
MmAllocateNonCachedMemory
MmBuildMdlForNonPagedPool
MmCreateMdl
MmFreeContiguousMemory
MmFreeNonCachedMemory
MmGetMdlByteCount
MmGetMdlByteOffset
MmGetMdlVirtualAddress
MmGetPhysicalAddress
MmGetSystemAddressForMdl
MmInitializeMdl
MmIsAddressValid
MmIsNonPagedSystemAddressValid
MmIsThisAnNtAsSystem
MmLockPagableCodeSection
MmLockPagableDataSection
MmLockPagableSectionByHandle
MmMapIoSpace
MmMapLockedPages
MmPageEntireDriver
MmResetDriverPaging
MmPrepareMdlForReuse
MmProbeAndLockPages
MmQuerySystemSize
MmSizeOfMdl
MmUnlockPages
MmUnlockPagableImageSection
MmUnmapIoSpace
MmUnmapLockedPages
ObDereferenceObject
ObReferenceObjectByHandle
ObReferenceObjectByPointer
PsCreateSystemThread
PsGetCurrentProcess
PsGetCurrentThread
PsTerminateSystemThread
InitializeListHead
InitializeObjectAttributes
InsertHeadList
InsertTailList
PopEntryList
PushEntryList
RemoveEntryList
RemoveHeadList
RemoveTailList
RtlAnsiStringToUnicodeSize
RtlAnsiStringToUnicodeString
RtlAppendUnicodeStringToString
RtlAppendUnicodeToString
RtlCharToInteger
RtlCheckRegistryKey
RtlCompareMemory
RtlCompareString
RtlCompareUnicodeString
RtlConvertLongToLargeInteger
RtlConvertUlongToLargeInteger
RtlCopyBytes
RtlCopyMemory
RtlCopyString
RtlCopyUnicodeString
RtlCreateRegistryKey
RtlCreateSecurityDescriptor
RtlDeleteRegistryValue
RtlEnlargedIntegerMultiply
RtlEnlargedUnsignedDivide
RtlEnlargedUnsignedMultiply
RtlEqualString
RtlEqualUnicodeString
RtlExtendedIntegerMultiply
RtlExtendedLargeIntegerDivide
RtlExtendedMagicDivide
RtlFillMemory
RtlFreeAnsiString
RtlFreeUnicodeString
RtlInitAnsiString
RtlInitString
RtlInitUnicodeString
RtlIntegerToUnicodeString
RtlLargeIntegerAdd
RtlLargeIntegerAnd
RtlLargeIntegerArithmeticShift
RtlLargeIntegerDivide
RtlLargeIntegerEqualTo
RtlLargeIntegerEqualToZero
RtlLargeIntegerGreaterThan
RtlLargeIntegerGreaterThanOrEqualTo
RtlLargeIntegerGreaterThanOrEqualToZero
RtlLargeIntegerGreaterThanZero
RtlLargeIntegerLessThan
RtlLargeIntegerLessThanOrEqualTo
RtlLargeIntegerLessThanZero
RtlLargeIntegerNegate
RtlLargeIntegerNotEqualTo
RtlLargeIntegerShiftLeft
RtlLargeIntegerShiftRight
RtlLargeIntegerSubtract
RtlLengthSecurityDescriptor
RtlMoveMemory
RtlQueryRegistryValues
RtlRetrieveUlong
RtlRetrieveUshort
RtlSetDaclSecurityDescriptor
RtlStoreUlong
RtlStoreUshort
RtlTimeFieldsToTime
RtlTimeToTimeFields
RtlUnicodeStringToAnsiString
RtlUnicodeStringToInteger
RtlUpcaseUnicodeString
RtlUpperString
RtlValidSecurityDescriptor
RtlWriteRegistryValue
RtlZeroMemory
SeAccessCheck
SeAssignSecurity
SeDeassignSecurity
SeSinglePrivilegeCheck
ZwClose
ZwCreateDirectoryObject
ZwCreateFile
ZwCreateKey
ZwDeleteKey
ZwEnumerateKey
ZwEnumerateValueKey
ZwFlushKey
ZwMakeTemporaryObject
ZwMapViewOfSection
ZwOpenFile
ZwOpenKey
ZwOpenSection
ZwQueryInformationFile
ZwQueryKey
ZwQueryValueKey
ZwReadFile
ZwSetInformationFile
ZwSetInformationThread
ZwSetValueKey
ZwUnmapViewOfSection
ZwWriteFile
sprintf

View file

@ -0,0 +1,140 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/hal/eisa.c
* PURPOSE: Interfaces to the PCI bus
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 05/06/98: Created
*/
/*
* NOTES: Sections copied from the Linux pci support
*/
/* INCLUDES ***************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/hal/page.h>
#include <internal/hal/segment.h>
/* TYPES ******************************************************************/
typedef struct
{
/*
* "_32_" if present
*/
unsigned int signature;
/*
* Entry point (physical address)
*/
unsigned long int entry;
/*
* Revision level
*/
unsigned char revision;
/*
* Length in paragraphs
*/
unsigned char length;
/*
* Checksum (so all bytes add up to zero)
*/
unsigned char checksum;
unsigned char reserved[5];
} bios32;
BOOLEAN bios32_detected = FALSE;
static struct
{
unsigned long address;
unsigned short segment;
} bios32_indirect = {0,KERNEL_CS};
/* FUNCTIONS **************************************************************/
#define BIOS32_SIGNATURE (('_' << 0)+('3'<<8)+('2'<<16)+('_'<<24))
BOOL static checksum(bios32* service_entry)
/*
* FUNCTION: Checks the checksum of a bios32 service entry
* ARGUMENTS:
* service_entry = Pointer to the service entry
* RETURNS: True if the sum of the bytes in the entry was zero
* False otherwise
*/
{
unsigned char* p = (unsigned char *)service_entry;
int i;
unsigned char sum=0;
for (i=0; i<(service_entry->length*16); i++)
{
sum=sum+p[i];
}
// printk("sum = %d\n",sum);
if (sum==0)
{
return(TRUE);
}
return(FALSE);
}
BOOLEAN Hal_bios32_is_service_present(ULONG service)
{
unsigned char return_code;
unsigned int address;
unsigned int length;
unsigned int entry;
__asm__("lcall (%%edi)"
: "=a" (return_code),
"=b" (address),
"=c" (length),
"=d" (entry)
: "0" (service),
"1" (0),
"D" (&bios32_indirect));
if (return_code==0)
{
return(address+entry);
}
return(0);
}
VOID Hal_bios32_probe()
/*
* FUNCTION: Probes for an BIOS32 extension
* RETURNS: True if detected
*/
{
int i;
for (i=0xe0000;i<=0xffff0;i++)
{
bios32* service_entry = (bios32 *)physical_to_linear(i);
if ( service_entry->signature != BIOS32_SIGNATURE )
{
continue;
}
// printk("Signature detected at %x\n",i);
if (!checksum(service_entry))
{
continue;
}
printk("BIOS32 detected at %x\n",i);
bios32_indirect.address = service_entry->entry;
bios32_detected=TRUE;
}
}

View file

@ -0,0 +1,79 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS HalAssignSlotResources(PUNICODE_STRING RegistryPath,
PUNICODE_STRING DriverClassName,
PDRIVER_OBJECT DriverObject,
PDEVICE_OBJECT DeviceObject,
INTERFACE_TYPE BusType,
ULONG BusNumber,
ULONG SlotNumber,
PCM_RESOURCE_LIST* AllocatedResources)
{
UNIMPLEMENTED;
}
ULONG HalGetBusData(BUS_DATA_TYPE BusDataType,
ULONG BusNumber,
ULONG SlotNumber,
PVOID Buffer,
ULONG Length)
{
UNIMPLEMENTED;
}
ULONG HalGetBusDataByOffset(BUS_DATA_TYPE BusDataType,
ULONG BusNumber,
ULONG SlotNumber,
PVOID Buffer,
ULONG Offset,
ULONG Length)
{
UNIMPLEMENTED;
}
ULONG HalSetBusData(BUS_DATA_TYPE BusDataType,
ULONG BusNumber,
ULONG SlotNumber,
PVOID Buffer,
ULONG Length)
{
UNIMPLEMENTED;
}
ULONG HalSetBusDataByOffset(BUS_DATA_TYPE BusDataType,
ULONG BusNumber,
ULONG SlotNumber,
PVOID Buffer,
ULONG Offset,
ULONG Length)
{
UNIMPLEMENTED;
}
BOOLEAN HalTranslateBusAddress(INTERFACE_TYPE InterfaceType,
ULONG BusNumber,
PHYSICAL_ADDRESS BusAddress,
PULONG AddressSpace,
PPHYSICAL_ADDRESS TranslatedAddress)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,132 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/dma.c
* PURPOSE: DMA functions
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* TYPES *********************************************************************/
#define MAP_REGISTER_SIZE (PAGESIZE)
#define NR_MAP_REGISTERS (32)
typedef struct
{
PVOID VirtualAddress;
PVOID PhysicalAddress;
} MAP_REGISTER, *PMAP_REGISTER;
/*
typedef struct _ADAPTER_OBJECT
{
DEVICE_DESCRIPTION desc;
KDEVICE_QUEUE wait_queue;
} ADAPTER_OBJECT, *PADAPTER_OBJECT
*/
/* GLOBALS *******************************************************************/
static PMAP_REGISTER map_registers[];
/* FUNCTIONS *****************************************************************/
VOID HalInitializeAdapterSupport()
{
/* ?? */
}
ULONG HalGetDmaAlignmentRequirement()
/*
* FUNCTION: Returns the size of the cache boundary
*/
{
return(1);
}
PVOID HalAllocateCommonBuffer(PADAPTER_OBJECT AdapterObject,
ULONG Length,
PPHYSICAL_ADDRESS LogicalAddress,
BOOLEAN CacheEnabled)
/*
* FUNCTION: Allocates memory that is visible to both the processor(s) and
* a dma device
* ARGUMENTS:
* AdapterObject = Adapter object representing the bus master or
* system dma controller
* Length = Number of bytes to allocate
* LogicalAddress = Logical address the driver can use to access the
* buffer
* CacheEnabled = Specifies if the memory can be cached
* RETURNS: The base virtual address of the memory allocated
* NULL on failure
*/
{/*
PVOID Buffer;
PHYSICAL_ADDRESS highest_address;
highest_address.HighPart = 0;
if (AdapterObject->Desc.Dma32BitAddresses )
{
highest_address.LowPart = 0xffffffff;
}
else
{
highest_address.LowPart = 0xfffff;
}
Buffer = MmAllocateContiguousMemory(Length,&highest_address);
LogicalAddress->HighPart = 0;
LogicalAddress->LowPart = MmGetPhysicalAddress(Buffer);
return(Buffer);*/
}
VOID HalFreeCommonBuffer(PADAPTER_OBJECT AdapterObject,
ULONG Length,
PHYSICAL_ADDRESS LogicalAddress,
PVOID VirtualAddress,
BOOLEAN CacheEnabled)
{
MmFreeContiguousMemory(VirtualAddress);
}
PADAPTER_OBJECT HalGetAdapter(PDEVICE_DESCRIPTION DeviceDescription,
PULONG NumberOfMapRegisters)
/*
* FUNCTION: Returns a pointer to an adapter object for the DMA device
* defined the device description structure
* ARGUMENTS:
* DeviceObject = Structure describing the attributes of the device
* NumberOfMapRegisters (OUT) = Returns the maximum number of map
* registers the device driver can
* allocate for DMA transfer operations
* RETURNS: The allocated adapter object on success
* NULL on failure
*/
{
/* PADAPTER_OBJECT adapter;
adapter = ExAllocatePool(NonPagedPool,sizeof(ADAPTER_OBJECT));
RtlCopyMemory(&adapter->desc,DeviceDescription,sizeof(DEVICE_DESCRIPTION));
*/
}
ULONG HalReadDmaCounter(PADAPTER_OBJECT AdapterObject)
{
UNIMPLEMENTED;
}
ULONG KeGetDcacheFillSize()
/*
* FUNCTION: Returns the microprocessor's data cache-line boundary in bytes
*/
{
return(1);
}

View file

@ -0,0 +1,224 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/exp.c
* PURPOSE: Handling exceptions
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* ??/??/??: Created
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <internal/kernel.h>
#include <internal/hal/segment.h>
#include <internal/hal/page.h>
/* GLOBALS *****************************************************************/
extern descriptor idt[256];
static exception_hook* exception_hooks[256]={NULL,};
#define _STR(x) #x
#define STR(x) _STR(x)
/* FUNCTIONS ****************************************************************/
#define EXCEPTION_HANDLER_WITH_ERROR(x,y) \
void exception_handler##y (void); \
__asm__("\n\t_exception_handler"##x":\n\t" \
"pushl %ds\n\t" \
"pushl $"##x"\n\t" \
"pusha\n\t" \
"movw $"STR(KERNEL_DS)",%ax\n\t" \
"movw %ax,%ds\n\t" \
"call _exception_handler\n\t" \
"popa\n\t" \
"addl $8,%esp\n\t" \
"iret\n\t")
#define EXCEPTION_HANDLER_WITHOUT_ERROR(x,y) \
asmlinkage void exception_handler##y (void); \
__asm__("\n\t_exception_handler"##x":\n\t" \
"pushl $0\n\t" \
"pushl %ds\n\t" \
"pushl $"##x"\n\t" \
"pusha\n\t" \
"movw $"STR(KERNEL_DS)",%ax\n\t" \
"movw %ax,%ds\n\t" \
"call _exception_handler\n\t" \
"popa\n\t" \
"addl $8,%esp\n\t" \
"iret\n\t")
asmlinkage void exception_handler_unknown(void);
__asm__("\n\t_exception_handler_unknown:\n\t"
"pushl $0\n\t"
"pushl %ds\n\t"
"pushl $0xff\n\t"
"pusha\n\t"
"movw $"STR(KERNEL_DS)",%ax\n\t"
"movw %ax,%ds\n\t"
"call _exception_handler\n\t"
"popa\n\t"
"addl $8,%esp\n\t"
"iret\n\t");
EXCEPTION_HANDLER_WITHOUT_ERROR("0",0);
EXCEPTION_HANDLER_WITHOUT_ERROR("1",1);
EXCEPTION_HANDLER_WITHOUT_ERROR("2",2);
EXCEPTION_HANDLER_WITHOUT_ERROR("3",3);
EXCEPTION_HANDLER_WITHOUT_ERROR("4",4);
EXCEPTION_HANDLER_WITHOUT_ERROR("5",5);
EXCEPTION_HANDLER_WITHOUT_ERROR("6",6);
EXCEPTION_HANDLER_WITHOUT_ERROR("7",7);
EXCEPTION_HANDLER_WITH_ERROR("8",8);
EXCEPTION_HANDLER_WITHOUT_ERROR("9",9);
EXCEPTION_HANDLER_WITH_ERROR("10",10);
EXCEPTION_HANDLER_WITH_ERROR("11",11);
EXCEPTION_HANDLER_WITH_ERROR("12",12);
EXCEPTION_HANDLER_WITH_ERROR("13",13);
/*
* The page fault handler is defined by the memory managment because it is
* special
*/
//EXCEPTION_HANDLER_WITH_ERROR("14",14);
asmlinkage void exception_handler14(void);
EXCEPTION_HANDLER_WITH_ERROR("15",15);
EXCEPTION_HANDLER_WITHOUT_ERROR("16",16);
extern unsigned int etext;
asmlinkage void exception_handler(unsigned int edi,
unsigned int esi, unsigned int ebp,
unsigned int esp, unsigned int ebx,
unsigned int edx, unsigned int ecx,
unsigned int eax,
unsigned int type,
unsigned int ds,
unsigned int error_code,
unsigned int eip,
unsigned int cs, unsigned int eflags,
unsigned int esp0, unsigned int ss0)
/*
* FUNCTION: Called by the lowlevel execption handlers to print an amusing
* message and halt the computer
* ARGUMENTS:
* Complete CPU context
*/
{
unsigned int cr2;
unsigned int i;
unsigned int* stack;
/*
* Activate any hook for the exception
*/
if (exception_hooks[type]!=NULL)
{
exception_hooks[type](NULL,type);
}
/*
* Print out the CPU registers
*/
printk("Exception: %d(%x)\n",type,error_code&0xffff);
printk("CS:EIP %x:%x\n",cs&0xffff,eip);
printk("EAX: %.8x EBX: %.8x ECX: %.8x\n",eax,ebx,ecx);
printk("EDX: %.8x EBP: %.8x ESI: %.8x\n",edx,ebp,esi);
printk("EDI: %.8x EFLAGS: %.8x ",edi,eflags);
if ((cs&0xffff)==KERNEL_CS)
{
printk("ESP %.8x\n",esp);
}
__asm__("movl %%cr2,%0\n\t"
: "=d" (cr2));
printk("cr2 %x\n",cr2);
if ((cs&0xffff)==KERNEL_CS)
{
printk("ESP %x\n",esp);
stack=(unsigned int *)(esp+24);
// #if 0
printk("Stack:\n");
for (i=0;i<16;i=i+4)
{
printk("%.8x %.8x %.8x %.8x\n",stack[i],stack[i+1],stack[i+2],
stack[i+3]);
}
printk("Frames:\n");
for (i=0;i<32;i++)
{
if (stack[i] > KERNEL_BASE &&
stack[i] < ((unsigned int)&etext) )
{
printk("%.8x ",stack[i]);
}
}
// #endif
}
else
{
printk("SS:ESP %x:%x\n",ss0,esp0);
}
for(;;);
}
static void set_interrupt_gate(unsigned int sel, unsigned int func)
{
idt[sel].a = (((int)func)&0xffff) +
(KERNEL_CS << 16);
idt[sel].b = 0x8f00 + (((int)func)&0xffff0000);
}
asmlinkage unsigned int ExHookException(exception_hook fn, unsigned int exp)
/*
* FUNCTION: Hook an exception
*/
{
if (exp>=256)
{
return(1);
}
exception_hooks[exp]=fn;
return(0);
}
asmlinkage void InitalizeExceptions(void)
/*
* FUNCTION: Initalize CPU exception handling
*/
{
int i;
set_interrupt_gate(0,(int)exception_handler0);
set_interrupt_gate(1,(int)exception_handler1);
set_interrupt_gate(2,(int)exception_handler2);
set_interrupt_gate(3,(int)exception_handler3);
set_interrupt_gate(4,(int)exception_handler4);
set_interrupt_gate(5,(int)exception_handler5);
set_interrupt_gate(6,(int)exception_handler6);
set_interrupt_gate(7,(int)exception_handler7);
set_interrupt_gate(8,(int)exception_handler8);
set_interrupt_gate(9,(int)exception_handler9);
set_interrupt_gate(10,(int)exception_handler10);
set_interrupt_gate(11,(int)exception_handler11);
set_interrupt_gate(12,(int)exception_handler12);
set_interrupt_gate(13,(int)exception_handler13);
set_interrupt_gate(14,(int)exception_handler14);
set_interrupt_gate(15,(int)exception_handler15);
set_interrupt_gate(16,(int)exception_handler16);
for (i=17;i<256;i++)
{
set_interrupt_gate(i,(int)exception_handler_unknown);
}
}

View file

@ -0,0 +1,43 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/hal/x86/halinit.c
* PURPOSE: Initalize the uniprocessor, x86 hal
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 11/06/98: Created
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/hal/hal.h>
/* FUNCTIONS ***************************************************************/
VOID HalInit(boot_param* bp)
{
InitalizeExceptions();
InitalizeIRQ();
/*
* Probe for a BIOS32 extension
*/
Hal_bios32_probe();
/*
* Probe for buses attached to the computer
* NOTE: Order is important here because ISA is the default
*/
#if 0
if (HalPciProbe())
{
return;
}
HalIsaProbe();
#endif
}

View file

@ -0,0 +1,81 @@
#define NR_TASKS 128
.globl _stext
.globl _idt
.globl _gdt
.globl _start
.globl _mainCRTStartup
.globl start
_stext:
_mainCRTStartup:
_start:
start:
lidt _idt_descr
lgdt _gdt_descr
movw $0x28,%ax
movw %ax,%ds
popl %eax
popl %eax
movl $_init_stack_top,%esp
pushl %eax
pushl $0
jmp __main
.data
_gdt:
.word 0
.word 0
.word 0
.word 0
.word 0x0000
.word 0x0000
.word 0xfa00
.word 0x00cc
.word 0x0000
.word 0x0000
.word 0xf200
.word 0x00cc
.word 0xffff
.word 0x0000
.word 0x9200
.word 0x00cf
.word 0xffff
.word 0x0000
.word 0x9a00
.word 0x00cf
.word 0xffff
.word 0x0000
.word 0x9200
.word 0x00cf
.fill 128,8,0
_idt_descr:
.word (256*8)-1
.long _idt
_gdt_descr:
/* .word ((6+128)*8)-1 */
.word ((6+NR_TASKS)*8)-1
.long _gdt
_idt:
.fill 256,8,0
_init_stack:
.fill 4096,1,0
_init_stack_top:
#if 0
_stext:
#endif

View file

@ -0,0 +1,369 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/hal/x86/irq.c
* PURPOSE: IRQ handling
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 29/05/98: Created
*/
/*
* NOTE: In general the PIC interrupt priority facilities are used to
* preserve the NT IRQL semantics, global interrupt disables are only used
* to keep the PIC in a consistent state
*
*/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <internal/stddef.h>
#include <internal/kernel.h>
#include <internal/bitops.h>
#include <internal/linkage.h>
#include <internal/string.h>
#include <internal/hal/segment.h>
#include <internal/hal/io.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *****************************************************************/
#define NR_IRQS (16)
#define IRQ_BASE (0x20)
asmlinkage void irq_handler_0(void);
asmlinkage void irq_handler_1(void);
asmlinkage void irq_handler_2(void);
asmlinkage void irq_handler_3(void);
asmlinkage void irq_handler_4(void);
asmlinkage void irq_handler_5(void);
asmlinkage void irq_handler_6(void);
asmlinkage void irq_handler_7(void);
asmlinkage void irq_handler_8(void);
asmlinkage void irq_handler_9(void);
asmlinkage void irq_handler_10(void);
asmlinkage void irq_handler_11(void);
asmlinkage void irq_handler_12(void);
asmlinkage void irq_handler_13(void);
asmlinkage void irq_handler_14(void);
asmlinkage void irq_handler_15(void);
static unsigned int irq_handler[NR_IRQS]=
{
(int)&irq_handler_0,
(int)&irq_handler_1,
(int)&irq_handler_2,
(int)&irq_handler_3,
(int)&irq_handler_4,
(int)&irq_handler_5,
(int)&irq_handler_6,
(int)&irq_handler_7,
(int)&irq_handler_8,
(int)&irq_handler_9,
(int)&irq_handler_10,
(int)&irq_handler_11,
(int)&irq_handler_12,
(int)&irq_handler_13,
(int)&irq_handler_14,
(int)&irq_handler_15,
};
/*
* PURPOSE: Object describing each isr
* NOTE: The data in this table is only modified at passsive level but can
* be accessed at any irq level.
*/
static LIST_ENTRY isr_table[NR_IRQS]={{NULL,NULL},};
static PKSPIN_LOCK isr_lock[NR_IRQS];
static KSPIN_LOCK isr_table_lock;
/* FUNCTIONS ****************************************************************/
#define PRESENT (0x8000)
#define I486_INTERRUPT_GATE (0xe00)
asmlinkage void KiInterruptDispatch(unsigned int irq)
/*
* FUNCTION: Calls the irq specific handler for an irq
* ARGUMENTS:
* irq = IRQ that has interrupted
*/
{
KIRQL old_level;
PKINTERRUPT isr;
PLIST_ENTRY current;
/*
* Notify the rest of the kernel of the raised irq level
*/
old_level = KeGetCurrentIrql();
DPRINT("old_level %d\n",old_level);
KeSetCurrentIrql(HIGH_LEVEL - irq);
/*
* Enable interrupts
* NOTE: Only higher priority interrupts will get through
*/
__asm__("sti\n\t");
if (irq==0)
{
KeTimerInterrupt();
}
else
{
DPRINT("KiInterruptDispatch(irq %x)\n",irq);
/*
* Iterate the list until one of the isr tells us its device interrupted
*/
current = isr_table[irq].Flink;
isr = CONTAINING_RECORD(current,KINTERRUPT,Entry);
DPRINT("current %x isr %x\n",current,isr);
while (current!=NULL && !isr->ServiceRoutine(isr,isr->ServiceContext))
{
current = current->Flink;
isr = CONTAINING_RECORD(current,KINTERRUPT,Entry);
DPRINT("current %x isr %x\n",current,isr);
}
}
/*
* Disable interrupts
*/
__asm__("cli\n\t");
/*
* Send EOI to the PIC
*/
outb(0x20,0x20);
if (irq>=8)
{
outb(0xa0,0x20);
}
/*
* Unmask the related irq
*/
if (irq<8)
{
outb(0x21,inb(0x21)&(~(1<<irq)));
}
else
{
outb(0xa1,inb(0xa1)&(~(1<<(irq-8))));
}
/*
* If the processor level will drop below dispatch level on return then
* issue a DPC queue drain interrupt
*/
if (old_level < DISPATCH_LEVEL)
{
KeSetCurrentIrql(DISPATCH_LEVEL);
__asm__("sti\n\t");
KiDispatchInterrupt(irq);
}
KeSetCurrentIrql(old_level);
}
void InitalizeIRQ(void)
{
int i;
/*
* First mask off all interrupts from pic
*/
outb(0x21,0xff);
outb(0xa1,0xff);
/*
* Setup the IDT entries to point to the interrupt handlers
*/
for (i=0;i<NR_IRQS;i++)
{
idt[IRQ_BASE+i].a=(irq_handler[i]&0xffff)+(KERNEL_CS<<16);
idt[IRQ_BASE+i].b=(irq_handler[i]&0xffff0000)+PRESENT+
I486_INTERRUPT_GATE;
InitializeListHead(&isr_table[i]);
}
}
NTSTATUS IoConnectInterrupt(PKINTERRUPT* InterruptObject,
PKSERVICE_ROUTINE ServiceRoutine,
PVOID ServiceContext,
PKSPIN_LOCK SpinLock,
ULONG Vector,
KIRQL Irql,
KIRQL SynchronizeIrql,
KINTERRUPT_MODE InterruptMode,
BOOLEAN ShareVector,
KAFFINITY ProcessorEnableMask,
BOOLEAN FloatingSave)
/*
* FUNCTION: Registers a driver's isr to be called when its device interrupts
* ARGUMENTS:
* InterruptObject (OUT) = Points to the interrupt object created on
* return
* ServiceRoutine = Routine to be called when the device interrupts
* ServiceContext = Parameter to be passed to ServiceRoutine
* SpinLock = Initalized spinlock that will be used to synchronize
* access between the isr and other driver routines. This is
* required if the isr handles more than one vector or the
* driver has more than one isr
* Vector = Interrupt vector to allocate
* (returned from HalGetInterruptVector)
* Irql = DIRQL returned from HalGetInterruptVector
* SynchronizeIrql = DIRQL at which the isr will execute. This must
* be the highest of all the DIRQLs returned from
* HalGetInterruptVector if the driver has multiple
* isrs
* InterruptMode = Specifies if the interrupt is LevelSensitive or
* Latched
* ShareVector = Specifies if the vector can be shared
* ProcessorEnableMask = Processors on the isr can run
* FloatingSave = TRUE if the floating point stack should be saved when
* the isr runs. Must be false for x86 drivers
* RETURNS: Status
* IRQL: PASSIVE_LEVEL
*/
{
KIRQL oldlvl;
KIRQL synch_oldlvl;
PKINTERRUPT ListHead;
ASSERT_IRQL(PASSIVE_LEVEL);
/*
* Check the parameters
*/
if (Vector >= NR_IRQS)
{
return(STATUS_INVALID_PARAMETER);
}
if (FloatingSave == TRUE)
{
return(STATUS_INVALID_PARAMETER);
}
/*
* Acquire the table spinlock
*/
KeAcquireSpinLock(&isr_table_lock,&oldlvl);
/*
* Check if the vector is already in use that we can share it
*/
ListHead = CONTAINING_RECORD(isr_table[Vector].Flink,KINTERRUPT,Entry);
if (!IsListEmpty(&isr_table[Vector]) &&
(ShareVector == FALSE || ListHead->Shareable==FALSE))
{
KeReleaseSpinLock(&isr_table_lock,oldlvl);
return(STATUS_INVALID_PARAMETER);
}
else
{
isr_lock[Vector]=ExAllocatePool(NonPagedPool,sizeof(KSPIN_LOCK));
KeInitializeSpinLock(isr_lock[Vector]);
isr_lock[Vector]->irql = SynchronizeIrql;
}
/*
* Initialize interrupt object
*/
(*InterruptObject)=ExAllocatePool(NonPagedPool,sizeof(KINTERRUPT));
if ((*InterruptObject)==NULL)
{
return(STATUS_INSUFFICIENT_RESOURCES);
}
(*InterruptObject)->ServiceContext = ServiceContext;
(*InterruptObject)->ServiceRoutine = ServiceRoutine;
(*InterruptObject)->Vector = Vector;
(*InterruptObject)->ProcessorEnableMask = ProcessorEnableMask;
(*InterruptObject)->SynchLevel = SynchronizeIrql;
(*InterruptObject)->Shareable = ShareVector;
(*InterruptObject)->FloatingSave = FALSE;
(*InterruptObject)->IrqLock = isr_lock[Vector];
KeRaiseIrql((*InterruptObject)->SynchLevel,&synch_oldlvl);
KeAcquireSpinLockAtDpcLevel((*InterruptObject)->IrqLock);
DPRINT("%x %x\n",isr_table[Vector].Flink,isr_table[Vector].Blink);
InsertTailList(&isr_table[Vector],&((*InterruptObject)->Entry));
DPRINT("%x %x\n",(*InterruptObject)->Entry.Flink,
(*InterruptObject)->Entry.Blink);
KeReleaseSpinLockFromDpcLevel((*InterruptObject)->IrqLock);
KeLowerIrql(synch_oldlvl);
/*
* Release the table spinlock
*/
KeReleaseSpinLock(&isr_table_lock,oldlvl);
return(STATUS_SUCCESS);
}
VOID IoDisconnectInterrupt(PKINTERRUPT InterruptObject)
/*
* FUNCTION: Releases a drivers isr
* ARGUMENTS:
* InterruptObject = isr to release
*/
{
KIRQL oldlvl;
KeRaiseIrql(InterruptObject->SynchLevel,&oldlvl);
KeAcquireSpinLockAtDpcLevel(InterruptObject->IrqLock);
RemoveEntryFromList(&isr_table[InterruptObject->Vector],
&InterruptObject->Entry);
KeReleaseSpinLockFromDpcLevel(InterruptObject->IrqLock);
KeLowerIrql(oldlvl);
}
ULONG HalGetInterruptVector(INTERFACE_TYPE InterfaceType,
ULONG BusNumber,
ULONG BusInterruptLevel,
ULONG BusInterruptVector,
PKIRQL Irql,
PKAFFINITY Affinity)
/*
* FUNCTION: Returns a mapped system interrupt vector for passing to
* IoConnectInterrupt
* ARGUMENTS:
* InterfaceType = Type bus the device is on
* BusNumber = Zero based number of the bus
* BusInterruptLevel = Bus specific interrupt level
* BusInterruptVector = Bus specific interrupt vector
* Irql (IN/OUT) = On entry the bus relative IRQL
* On exit the DIRQL
* Affinity (OUT) = Caller supplied storage for the interrupt
* affinity mask
* RETURNS: The mapped vector
*/
{
ULONG ret;
// ASSERT_IRQL(PASSIVE_LEVEL);
switch (InterfaceType)
{
case Internal:
*Irql = HIGH_LEVEL - BusInterruptVector;
ret = BusInterruptVector;
break;
default:
ret = -1;
printk("(%s:%d) Don't know that bus type\n",__FILE__,__LINE__);
break;
}
return(ret);
}

View file

@ -0,0 +1,106 @@
;
; This module has code to handle IRQs
;
%include "internal/hal/segment.inc"
bits 32
section .text
extern _KiInterruptDispatch
%macro IRQ_HANDLER_FIRST 1
global _irq_handler_%1
_irq_handler_%1:
;
; Save registers
;
pusha
push ds
;
; Load DS
;
mov ax,KERNEL_DS
mov ds,ax
;
; Mask the corresponding vector at the PIC
; NOTE: Since lower priority interrupts are masked until an EOI
; is sent to the PIC this preserves the IRQL semantics.
;
in al,0x21
or al,1<<%1
out 0x21,al
;
; Call the irq dispatcher (passing the IRQ number as an argument)
;
push dword %1
call _KiInterruptDispatch
;
; Restore stack, registers and return to interrupted routine
;
pop eax
pop ds
popa
iret
%endmacro
%macro IRQ_HANDLER_SECOND 1
global _irq_handler_%1
_irq_handler_%1:
;
; Save registers
;
pusha
push ds
;
; Load DS
;
mov ax,KERNEL_DS
mov ds,ax
;
; Mask the related vector at the PIC
;
in al,0xa1
or al,1<<(%1-8)
out 0xa1,al
;
; Call the irq dispatcher
;
push dword %1
call _KiInterruptDispatch
;
; Restore stack, registers and return to the interrupted routine
;
pop eax
pop ds
popa
iret
%endmacro
IRQ_HANDLER_FIRST 0
IRQ_HANDLER_FIRST 1
IRQ_HANDLER_FIRST 2
IRQ_HANDLER_FIRST 3
IRQ_HANDLER_FIRST 4
IRQ_HANDLER_FIRST 5
IRQ_HANDLER_FIRST 6
IRQ_HANDLER_FIRST 7
IRQ_HANDLER_SECOND 8
IRQ_HANDLER_SECOND 9
IRQ_HANDLER_SECOND 10
IRQ_HANDLER_SECOND 11
IRQ_HANDLER_SECOND 12
IRQ_HANDLER_SECOND 13
IRQ_HANDLER_SECOND 14
IRQ_HANDLER_SECOND 15

View file

@ -0,0 +1,139 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/hal/irql.c
* PURPOSE: Implements IRQLs
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/bitops.h>
#include <internal/hal/io.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ******************************************************************/
/*
* PURPOSE: Current irq level
*/
static KIRQL CurrentIrql = HIGH_LEVEL;
/* FUNCTIONS ****************************************************************/
static unsigned int pic_get_current_mask(void)
{
unsigned int mask;
mask = inb_p(0x21);
mask = mask | (inb_p(0xa1)<<8);
}
static unsigned int pic_set_current_mask(unsigned int mask)
{
outb_p(0x21,mask & 0xff);
outb_p(0xa1,(mask >> 8) & 0xff);
}
static void switch_irql(void)
/*
* FUNCTION: Switches to the current irql
* NOTE: Must be called with interrupt disabled
*/
{
unsigned int i;
if (CurrentIrql == HIGH_LEVEL)
{
pic_set_current_mask(0xffff);
return;
}
if (CurrentIrql > DISPATCH_LEVEL)
{
unsigned int current_mask = 0;
for (i=(CurrentIrql-DISPATCH_LEVEL);i>DISPATCH_LEVEL;i--)
{
set_bit(NR_DEVICE_SPECIFIC_LEVELS - i,&current_mask);
}
pic_set_current_mask(current_mask);
__asm__("sti\n\t");
return;
}
if (CurrentIrql <= DISPATCH_LEVEL)
{
pic_set_current_mask(0);
__asm__("sti\n\t");
return;
}
}
VOID KeSetCurrentIrql(KIRQL newlvl)
/*
* PURPOSE: Sets the current irq level without taking any action
*/
{
DPRINT("KeSetCurrentIrql(newlvl %x)\n",newlvl);
CurrentIrql = newlvl;
}
KIRQL KeGetCurrentIrql()
/*
* PURPOSE: Returns the current irq level
* RETURNS: The current irq level
*/
{
return(CurrentIrql);
}
VOID KeLowerIrql(KIRQL NewIrql)
/*
* PURPOSE: Restores the irq level on the current processor
* ARGUMENTS:
* NewIrql = Irql to lower to
*/
{
__asm__("cli\n\t");
DPRINT("NewIrql %x CurrentIrql %x\n",NewIrql,CurrentIrql);
assert(NewIrql <= CurrentIrql);
CurrentIrql = NewIrql;
switch_irql();
}
VOID KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
/*
* FUNCTION: Raises the hardware priority (irql)
* ARGUMENTS:
* NewIrql = Irql to raise to
* OldIrql (OUT) = Caller supplied storage for the previous irql
*/
{
/*
* sanity check
*/
// printk("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql,
// OldIrql);
if (NewIrql < CurrentIrql)
{
printk("%s:%d\n",__FILE__,__LINE__);
for(;;);
}
__asm__("cli\n\t");
*OldIrql = CurrentIrql;
CurrentIrql = NewIrql;
// *OldIrql = InterlockedExchange(&CurrentIrql,NewIrql);
DPRINT("NewIrql %x OldIrql %x CurrentIrql %x\n",NewIrql,*OldIrql,
CurrentIrql);
switch_irql();
}

View file

@ -0,0 +1,205 @@
.file "irql.c"
gcc2_compiled.:
___gnu_compiled_c:
.globl _CurrentIrql
.data
_CurrentIrql:
.byte 19
.text
.p2align 2
_pic_get_current_mask:
pushl %ebp
movl %esp,%ebp
/APP
inb $33,%al
outb %al,$0x80
inb $161,%al
outb %al,$0x80
/NO_APP
leave
ret
.p2align 2
_pic_set_current_mask:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
/APP
outb %al,$33
outb %al,$0x80
/NO_APP
shrl $8,%eax
/APP
outb %al,$161
outb %al,$0x80
/NO_APP
leave
ret
.p2align 2
_switch_irql:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
pushl %ebx
movb _CurrentIrql,%al
cmpb $19,%al
jne L62
pushl $65535
call _pic_set_current_mask
jmp L61
.align 2,0x90
L62:
cmpb $2,%al
jbe L71
movl $0,-4(%ebp)
movzbl _CurrentIrql,%eax
leal -2(%eax),%edx
cmpl $2,%edx
jbe L65
movl $16,%ebx
leal -4(%ebp),%ecx
.align 2,0x90
L67:
movl %ebx,%eax
subl %edx,%eax
/APP
btsl %eax,(%ecx)
sbbl %eax,%eax
/NO_APP
decl %edx
cmpl $2,%edx
ja L67
L65:
pushl -4(%ebp)
call _pic_set_current_mask
/APP
sti
/NO_APP
jmp L61
.align 2,0x90
L71:
pushl $0
call _pic_set_current_mask
/APP
sti
/NO_APP
L61:
movl -8(%ebp),%ebx
leave
ret
.p2align 2
.globl _KeSetCurrentIrql
_KeSetCurrentIrql:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movb %al,_CurrentIrql
leave
ret
.p2align 2
.globl _KeGetCurrentIrql
_KeGetCurrentIrql:
pushl %ebp
movl %esp,%ebp
movzbl _CurrentIrql,%eax
leave
ret
LC0:
.ascii "irql.c\0"
LC1:
.ascii "(%s:%d) \0"
LC2:
.ascii "NewIrql %x CurrentIrql %x\12\0"
LC3:
.ascii "Assertion NewIrql <= CurrentIrql failed at %s:%d\12\0"
.p2align 2
.globl _KeLowerIrql
_KeLowerIrql:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movb 8(%ebp),%bl
/APP
cli
/NO_APP
pushl $103
pushl $LC0
pushl $LC1
call _printk
movzbl _CurrentIrql,%eax
pushl %eax
movzbl %bl,%eax
pushl %eax
pushl $LC2
call _printk
addl $24,%esp
cmpb %bl,_CurrentIrql
jae L79
pushl $104
pushl $LC0
pushl $LC3
call _printk
.align 2,0x90
L82:
jmp L82
.align 2,0x90
L79:
movb %bl,_CurrentIrql
call _switch_irql
movl -4(%ebp),%ebx
leave
ret
LC4:
.ascii "%s:%d\12\0"
LC5:
.ascii "NewIrql %x OldIrql %x CurrentIrql %x\12\0"
.p2align 2
.globl _KeRaiseIrql
_KeRaiseIrql:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %ebx
movl 12(%ebp),%esi
movb 8(%ebp),%al
cmpb %al,_CurrentIrql
jbe L84
pushl $122
pushl $LC0
pushl $LC4
call _printk
.align 2,0x90
L87:
jmp L87
.align 2,0x90
L84:
/APP
cli
/NO_APP
movzbl %al,%ebx
pushl %ebx
pushl $_CurrentIrql
call _InterlockedExchange
movb %al,(%esi)
pushl $129
pushl $LC0
pushl $LC1
call _printk
movzbl _CurrentIrql,%eax
pushl %eax
movzbl (%esi),%eax
pushl %eax
pushl %ebx
pushl $LC5
call _printk
addl $28,%esp
call _switch_irql
leal -8(%ebp),%esp
popl %ebx
popl %esi
leave
ret
.comm ___ProcessHeap,4

View file

@ -0,0 +1,36 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/hal/eisa.c
* PURPOSE: Interfaces to the ISA bus
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 05/06/98: Created
*/
/* INCLUDES ***************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/hal/page.h>
/* FUNCTIONS *****************************************************************/
BOOL HalIsaProbe()
/*
* FUNCTION: Probes for an ISA bus
* RETURNS: True if detected
* NOTE: Since ISA is the default we are called last and always return
* true
*/
{
printk("Assuming ISA bus\n");
/*
* Probe for plug and play support
*/
}

View file

@ -0,0 +1,27 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/mbr.c
* PURPOSE: Functions for reading the master boot record (MBR)
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID HalExamineMBR(PDEVICE_OBJECT DeviceObject,
ULONG SectorSize,
ULONG MBRTypeIdentifier,
PVOID Buffer)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,27 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/mp.c
* PURPOSE: Multiprocessor stubs
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
ULONG KeGetCurrentProcessorNumber(VOID)
/*
* FUNCTION: Returns the system assigned number of the current processor
*/
{
return(0);
}

View file

@ -0,0 +1,205 @@
/*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel v0.0.2
* FILE: hal/page.cc
* PURPOSE: low level memory managment manipulation
* PROGRAMER: David Welch
* UPDATE HISTORY:
* 9/3/98: Created
*/
/* INCLUDES ***************************************************************/
#include <internal/kernel.h>
#include <internal/hal/page.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/bitops.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *****************************************************************/
#define PA_BIT_PRESENT (0)
#define PA_BIT_READWRITE (1)
#define PA_BIT_USER (2)
#define PA_PRESENT (1<<PA_BIT_PRESENT)
/* FUNCTIONS ***************************************************************/
/*
* The mark_page_xxxx manipulate the attributes of a page. Use the
* higher level functions for synchronization. These functions only work
* on present pages.
*/
void mark_page_not_present(unsigned int vaddr)
/*
* FUNCTION: Marks the page as not present
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
clear_bit(PA_BIT_PRESENT,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_present(unsigned int vaddr)
/*
* FUNCTION: Marks the page as present
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
set_bit(PA_BIT_PRESENT,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_not_writable(unsigned int vaddr)
/*
* FUNCTION: Marks the page as not writable by any process
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
clear_bit(PA_BIT_READWRITE,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_writable(unsigned int vaddr)
/*
* FUNCTION: Marks the page as writable by any process
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
set_bit(PA_BIT_READWRITE,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_user(unsigned int vaddr)
/*
* FUNCTION: Marks the page as user accessible
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
set_bit(PA_BIT_USER,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_system(unsigned int vaddr)
/*
* FUNCTION: Marks the page as system only
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
clear_bit(PA_BIT_USER,get_page_entry(vaddr));
FLUSH_TLB;
}
void set_page(unsigned int vaddr, unsigned int attributes,
unsigned int physaddr)
/*
* FUNCTION: Set the page entry of a virtual address
* ARGUMENTS:
* vaddr = Virtual address
* attributes = Access attributes for the page
* physaddr = Physical address to map the virtual address to
* NOTE: In future this won't flush the TLB
*/
{
DPRINT("set_page(vaddr %x attributes %x physaddr %x)\n",vaddr,
attributes,physaddr);
*get_page_entry(vaddr)=physaddr | attributes;
FLUSH_TLB;
}
PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vaddr)
/*
* FUNCTION: Returns the physical address corresponding to a virtual address
*/
{
DPRINT("get_page_physical_address(vaddr %x)\n",vaddr);
return(PAGE_MASK(*get_page_entry((unsigned int)vaddr)));
}
BOOL is_page_present(unsigned int vaddr)
/*
* FUNCTION: Tests if a page is present at the address
* RETURNS:
* True: If an access to the page would happen without any page faults
* False: If an access to the page would involve page faults
* NOTES: The information is only guarrented to remain true if the caller has
* locked the page. The function does not have any side effects when used
* from an irq handler so it can be used as a 'sanity' test when accessing a
* buffer from an irq.
*/
{
#if 0
unsigned int* page_dir = physical_to_linear(current_task->cr3);
#else
unsigned int* page_dir = get_page_directory();
#endif
unsigned int* page_tlb = NULL;
/*
* Check the page directory exists
*/
if (!(page_dir[VADDR_TO_PD_OFFSET(vaddr)]&PA_PRESENT))
{
return(FALSE);
}
page_tlb = (unsigned int *)physical_to_linear(
PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(vaddr)]));
if (!(page_tlb[VADDR_TO_PT_OFFSET(vaddr)/4]&PA_PRESENT))
{
return(FALSE);
}
return(TRUE);
}
unsigned int* get_page_entry(unsigned int vaddr)
/*
* FUNCTION: Returns a pointer to a page entry
* NOTE: This function will create a page table if none exists so just to
* check if mem exists use the is_page_present function
*/
{
unsigned int page_table;
unsigned int* page_tlb;
#if 0
unsigned int* page_dir = physical_to_linear(current_task->cr3);
#else
unsigned int* page_dir = get_page_directory();
#endif
DPRINT("vaddr %x ",vaddr);
page_tlb = (unsigned int *)physical_to_linear(
PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(vaddr)]));
DPRINT("page_tlb %x\n",page_tlb);
if (PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(vaddr)])==0)
{
DPRINT("Creating new page directory\n",0);
page_table = get_free_page(); // Returns a physical address
page_tlb=(unsigned int *)physical_to_linear(page_table);
memset(page_tlb,0,PAGESIZE);
page_dir[VADDR_TO_PD_OFFSET(vaddr)]=page_table+0x7;
}
return(&page_tlb[VADDR_TO_PT_OFFSET(vaddr)/4]);
}

View file

@ -0,0 +1,40 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/hal/eisa.c
* PURPOSE: Interfaces to the PCI bus
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 05/06/98: Created
*/
/*
* NOTES: Sections copied from the Linux pci support
*/
/* INCLUDES ***************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/hal/page.h>
/* FUNCTIONS **************************************************************/
#define PCI_SERVICE (('$' << 0) + ('P' << 8) + ('C' << 16) + ('I'<<24))
BOOL HalPciProbe()
/*
* FUNCTION: Probes for an PCI bus
* RETURNS: True if detected
*/
{
if (Hal_bios32_is_service_present(PCI_SERVICE))
{
printk("Detected PCI service\n");
return(TRUE);
}
return(FALSE);
}

View file

@ -0,0 +1,247 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/printk.c
* PURPOSE: Writing to the console
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* ??/??/??: Created
* 05/06/98: Implemented BSOD
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/string.h>
#include <internal/hal/page.h>
#include <internal/hal/io.h>
#include <internal/debug.h>
/* GLOBALS ******************************************************************/
/*
* PURPOSE: Current cursor position
*/
static unsigned int cursorx=0, cursory=0;
static unsigned int lines_seen = 0;
#define NR_ROWS 25
#define NR_COLUMNS 80
#define VIDMEM_BASE 0xb8000
/*
* PURPOSE: Points to the base of text mode video memory
*/
static char* vidmem = (char *)(VIDMEM_BASE + IDMAP_BASE);
#define CRTC_COMMAND 0x3d4
#define CRTC_DATA 0x3d5
#define CRTC_CURLO 0x0f
#define CRTC_CURHI 0x0e
/*
* PURPOSE: This flag is set to true if the system is in HAL managed
* console mode. This is initially true then once the graphics drivers
* initialize, it is turned off, HAL console mode is reentered if a fatal
* error occurs or on system shutdown
*/
static unsigned int in_hal_console = 1;
/*
* PURPOSE: Defines the hal console video mode
*/
static unsigned char mode03[] = {0x67,0x00,0x03,0x00,0x03,0x00,0x02,
0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,
0x1f,0x00,0x4f,0x0e,0x0f,0x00,0x00,
0x00,0x00,0x9c,0x0e,0x8f,0x28,0x01,
0x96,0xb9,0xa3,0xff,0x00,0x00,0x00,
0x00,0x00,0x10,0x0e,0x00,0xff,0x00,
0x00,0x01,0x02,0x03,0x04,0x05,0x06,
0x07,0x10,0x11,0x12,0x13,0x14,0x15,
0x16,0x17,0x0c,0x00,0x0f,0x08,0x00};
/* FUNCTIONS ***************************************************************/
void HalSwitchToBlueScreen(void)
/*
* FUNCTION: Switches the monitor to text mode and writes a blue background
* NOTE: This function is entirely self contained and can be used from any
* graphics mode.
*/
{
/*
* Sanity check
*/
if (in_hal_console)
{
return;
}
/*
* Reset the cursor position
*/
cursorx=0;
cursory=0;
/*
* This code section is taken from the sample routines by
* Jeff Morgan (kinfira@hotmail.com)
*/
}
void HalDisplayString(char* string)
/*
* FUNCTION: Switches the screen to HAL console mode (BSOD) if not there
* already and displays a string
* ARGUMENT:
* string = ASCII string to display
* NOTE: Use with care because there is no support for returning from BSOD
* mode
*/
{
if (!in_hal_console)
{
HalSwitchToBlueScreen();
}
printk("%s",string);
}
static void putchar(char c)
/*
* FUNCTION: Writes a character to the console and updates the cursor position
* ARGUMENTS:
* c = the character to write
* NOTE: This function handles newlines as well
*/
{
char* address;
int offset;
int i;
switch(c)
{
case '\n':
cursory++;
cursorx=0;
lines_seen++;
break;
default:
vidmem[(cursorx*2) + (cursory*80*2)]=c;
vidmem[(cursorx*2) + (cursory*80*2)+1]=0x7;
cursorx++;
if (cursorx>=NR_COLUMNS)
{
cursory++;
lines_seen++;
cursorx=0;
}
}
#if 0
if (lines_seen == 24)
{
char str[] = "--- press escape to continue";
lines_seen = 0;
for (i=0;str[i]!=0;i++)
{
vidmem[NR_COLUMNS*(NR_ROWS-1)*2+i*2]=str[i];
vidmem[NR_COLUMNS*(NR_ROWS-1)*2+i*2+1]=0x7;
}
while (inb_p(0x60)!=0x81);
memset(&vidmem[NR_COLUMNS*(NR_ROWS-1)*2],0,NR_COLUMNS*2);
}
#endif
if (cursory>=NR_ROWS)
{
memcpy(vidmem,&vidmem[NR_COLUMNS*2],
NR_COLUMNS*(NR_ROWS-1)*2);
memset(&vidmem[NR_COLUMNS*(NR_ROWS-1)*2],0,NR_COLUMNS*2);
cursory=24;
}
/*
* Set the cursor position
*/
offset=cursory*NR_COLUMNS;
offset=offset+cursorx;
outb_p(CRTC_COMMAND,CRTC_CURLO);
outb_p(CRTC_DATA,offset);
outb_p(CRTC_COMMAND,CRTC_CURHI);
offset>>=8;
outb_p(CRTC_DATA,offset);
}
asmlinkage void printk(const char* fmt, ...)
/*
* FUNCTION: Print a formatted string to the hal console
* ARGUMENTS: As for printf
* NOTE: So it can used from irq handlers this function disables interrupts
* during its execution, they are restored to the previous state on return
*/
{
char buffer[256];
char* str=buffer;
va_list ap;
unsigned int eflags;
/*
* Because this is used by alomost every subsystem including irqs it
* must be atomic. The following code sequence disables interrupts after
* saving the previous state of the interrupt flag
*/
__asm__("pushf\n\tpop %0\n\tcli\n\t"
: "=m" (eflags)
: /* */);
/*
* Process the format string into a fixed length buffer using the
* standard C RTL function
*/
va_start(ap,fmt);
vsprintf(buffer,fmt,ap);
va_end(ap);
while ((*str)!=0)
{
putchar(*str);
str++;
}
/*
* Restore the interrupt flag
*/
__asm__("push %0\n\tpopf\n\t"
:
: "m" (eflags));
}
int bad_user_access_length(void)
{
printk("Bad user access length\n");
}
ULONG DbgPrint(PCH Format, ...)
{
UNIMPLEMENTED;
}
void InitConsole(boot_param* bp)
/*
* FUNCTION: Initalize the console
* ARGUMENTS:
* bp = Parameters setup by the boot loader
*/
{
cursorx=bp->cursorx;
cursory=bp->cursory;
}

View file

@ -0,0 +1,5 @@
HAL_OBJECTS = hal/x86/head.o hal/x86/irq.o hal/x86/exp.o hal/x86/isa.o \
hal/x86/pci.o hal/x86/irqhand.o hal/x86/page.o hal/x86/halinit.o \
hal/x86/irql.o hal/x86/bios32.o hal/x86/thread.o hal/x86/spinlock.o \
hal/x86/printk.o hal/x86/mp.o hal/x86/dma.o hal/x86/bus.o hal/x86/mbr.o \
hal/x86/sysinfo.o

View file

@ -0,0 +1,104 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/spinlock.c
* PURPOSE: Implements spinlocks
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 3/6/98: Created
*/
/*
* NOTE: On a uniprocessor machine spinlocks are implemented by raising
* the irq level
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS ***************************************************************/
BOOLEAN KeSynchronizeExecution(PKINTERRUPT Interrupt,
PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
PVOID SynchronizeContext)
/*
* FUNCTION: Synchronizes the execution of a given routine with the ISR
* of a given interrupt object
* ARGUMENTS:
* Interrupt = Interrupt object to synchronize with
* SynchronizeRoutine = Routine to call whose execution is
* synchronized with the ISR
* SynchronizeContext = Parameter to pass to the synchronized routine
* RETURNS: TRUE if the operation succeeded
*/
{
KIRQL oldlvl;
BOOLEAN ret;
KeRaiseIrql(Interrupt->SynchLevel,&oldlvl);
KeAcquireSpinLockAtDpcLevel(Interrupt->IrqLock);
ret = SynchronizeRoutine(SynchronizeContext);
KeReleaseSpinLockFromDpcLevel(Interrupt->IrqLock);
KeLowerIrql(oldlvl);
return(ret);
}
VOID KeInitializeSpinLock(PKSPIN_LOCK SpinLock)
/*
* FUNCTION: Initalizes a spinlock
* ARGUMENTS:
* SpinLock = Caller supplied storage for the spinlock
*/
{
SpinLock->irql = DISPATCH_LEVEL;
}
VOID KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock)
/*
* FUNCTION: Acquires a spinlock when the caller is already running at
* dispatch level
* ARGUMENTS:
* SpinLock = Spinlock to acquire
*/
{
}
VOID KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock)
/*
* FUNCTION: Releases a spinlock when the caller was running at dispatch
* level before acquiring it
* ARGUMENTS:
* SpinLock = Spinlock to release
*/
{
}
VOID KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
/*
* FUNCTION: Acquires a spinlock
* ARGUMENTS:
* SpinLock = Spinlock to acquire
* OldIrql (OUT) = Caller supplied storage for the previous irql
*/
{
KeRaiseIrql(DISPATCH_LEVEL,OldIrql);
}
VOID KeReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL NewIrql)
/*
* FUNCTION: Releases a spinlock
* ARGUMENTS:
* SpinLock = Spinlock to release
* NewIrql = Irql level before acquiring the spinlock
*/
{
KeLowerIrql(NewIrql);
}

View file

@ -0,0 +1,9 @@
/*
* COPYRIGHT: See COPYRIGHT in the top level source
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/syscall.c
* PURPOSE: Handles calls from user mode
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 21/07/98: Created
*/

View file

@ -0,0 +1,25 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID HalQuerySystemInformation()
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,163 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/hal/x86/thread.c
* PURPOSE: HAL multitasking functions
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 27/06/98: Created
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/psmgr.h>
#include <internal/string.h>
#include <internal/hal/hal.h>
#include <internal/hal/segment.h>
#include <internal/hal/page.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ***************************************************************/
#define FIRST_TSS_SELECTOR (KERNEL_DS + 0x8)
#define FIRST_TSS_OFFSET (FIRST_TSS_SELECTOR / 8)
/* FUNCTIONS **************************************************************/
void HalTaskSwitch(PKTHREAD thread)
/*
* FUNCTION: Switch tasks
* ARGUMENTS:
* thread = Thread to switch to
* NOTE: This function will not return until the current thread is scheduled
* again
*/
{
__asm__("pushfl\n\t"
"cli\n\t"
"ljmp %0\n\t"
"popfl\n\t"
: /* No outputs */
: "m" (*(((unsigned char *)(&(thread->context.nr)))-4) )
: "ax","dx");
}
static unsigned int allocate_tss_descriptor(void)
/*
* FUNCTION: Allocates a slot within the GDT to describe a TSS
* RETURNS: The offset within the GDT of the slot allocated on succcess
* Zero on failure
*/
{
unsigned int i;
for (i=0;i<16;i++)
{
if (gdt[FIRST_TSS_OFFSET + i].a==0 &&
gdt[FIRST_TSS_OFFSET + i].b==0)
{
return(FIRST_TSS_OFFSET + i);
}
}
return(0);
}
static void begin_thread(PKSTART_ROUTINE fn, PVOID start_context)
/*
* FUNCTION: This function is the start point for all new threads
* ARGUMENTS:
* fn = Actual start point of the thread
* start_context = Parameter to pass to the start routine
* RETURNS: Can't
*/
{
NTSTATUS ret;
DPRINT("begin_thread %x %x\n",fn,start_context);
KeLowerIrql(PASSIVE_LEVEL);
ret = fn(start_context);
PsTerminateSystemThread(ret);
for(;;);
}
BOOLEAN HalInitTask(PKTHREAD thread, PKSTART_ROUTINE fn,
PVOID StartContext)
/*
* FUNCTION: Initializes the HAL portion of a thread object
* ARGUMENTS:
* thread = Object describes the thread
* fn = Entrypoint for the thread
* StartContext = parameter to pass to the thread entrypoint
* RETURNS: True if the function succeeded
*/
{
unsigned int desc = allocate_tss_descriptor();
unsigned int length = sizeof(hal_thread_state) - 1;
unsigned int base = (unsigned int)(&(thread->context));
unsigned int* kernel_stack = ExAllocatePool(NonPagedPool,4096);
/*
* Make sure
*/
assert(sizeof(hal_thread_state)>=0x68);
/*
* Setup a TSS descriptor
*/
gdt[desc].a = (length & 0xffff) | ((base & 0xffff) << 16);
gdt[desc].b = ((base & 0xff0000)>>16) | 0x8900 | (length & 0xf0000)
| (base & 0xff000000);
/*
* Initialize the stack for the thread (including the two arguments to
* the general start routine).
*/
kernel_stack[1023] = (unsigned int)StartContext;
kernel_stack[1022] = (unsigned int)fn;
kernel_stack[1021] = NULL;
/*
* Initialize the thread context
*/
memset(&thread->context,0,sizeof(hal_thread_state));
thread->context.ldt = 0;
thread->context.eflags = (1<<1)+(1<<9);
thread->context.iomap_base = FIELD_OFFSET(hal_thread_state,io_bitmap);
thread->context.esp0 = &kernel_stack[1021];
thread->context.ss0 = KERNEL_DS;
thread->context.esp = &kernel_stack[1021];
thread->context.ss = KERNEL_DS;
thread->context.cs = KERNEL_CS;
thread->context.eip = (unsigned long)begin_thread;
thread->context.io_bitmap[0] = 0xff;
thread->context.cr3 = ((unsigned int)get_page_directory()) - IDMAP_BASE;
thread->context.ds = KERNEL_DS;
thread->context.es = KERNEL_DS;
thread->context.fs = KERNEL_DS;
thread->context.gs = KERNEL_DS;
thread->context.nr = desc * 8;
return(TRUE);
}
void HalInitFirstTask(PKTHREAD thread)
/*
* FUNCTION: Called to setup the HAL portion of a thread object for the
* initial thread
*/
{
/*
* Initialize the thread context
*/
HalInitTask(thread,NULL,NULL);
/*
* Load the task register
*/
__asm__("ltr %%ax"
: /* no output */
: "a" (FIRST_TSS_OFFSET*8));
}

View file

@ -0,0 +1,46 @@
;
;
%include "internal/hal/segment.inc"
bits 32
section .text
extern _SystemServiceTable
_kernel_mode_call_handler:
;
; Save some registers
;
push ds
push es
push esi
push edi
;
; Transfer the parameters from user mode
;
push USER_DS
pop es
mov edx,esi
mov esp,edi
mov ecx,_SystemServiceTable[eax*4]
sub esp,ecx
cld
rep movsb
;
; Call the actual service routine
;
mov eax,_SystemServiceTable[eax*4+4]
jmp eax
;
; Restore registers and return
;
pop edi
pop esi
pop es
pop ds
ret

View file

@ -0,0 +1,60 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/adapter.c
* PURPOSE: DMA handling
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS IoAllocateAdapterChannel(PADAPTER_OBJECT AdapterObject,
PDEVICE_OBJECT DeviceObject,
ULONG NumberOfMapRegisters,
PDRIVER_CONTROL ExecutionRoutine,
PVOID Context)
{
UNIMPLEMENTED;
}
BOOLEAN IoFlushAdapterBuffers(PADAPTER_OBJECT AdapterObject,
PMDL Mdl,
PVOID MapRegisterBase,
PVOID CurrentVa,
ULONG Length,
BOOLEAN WriteToDevice)
{
UNIMPLEMENTED;
}
PHYSICAL_ADDRESS IoMapTransfer(PADAPTER_OBJECT AdapterObject,
PMDL Mdl,
PVOID MapRegisterBase,
PVOID CurrentVa,
PULONG Length,
BOOLEAN WriteToDevice)
{
UNIMPLEMENTED;
}
VOID IoFreeAdapterChannel(PADAPTER_OBJECT AdapterObject)
{
UNIMPLEMENTED;
}
VOID IoFreeMapRegisters(PADAPTER_OBJECT AdapterObject,
PVOID MapRegisterBase,
ULONG NumberOfMapRegisters)
{
UNIMPLEMENTED;
}

30
reactos/ntoskrnl/io/arc.c Normal file
View file

@ -0,0 +1,30 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID IoAssignArcName(PUNICODE_STRING ArcName,
PUNICODE_STRING DeviceName)
{
IoCreateSymbolicLink(ArcName,DeviceName);
}
VOID IoDeassignArcName(PUNICODE_STRING ArcName)
{
IoDeleteSymbolicLink(ArcName);
}

View file

@ -0,0 +1,62 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/cancel.c
* PURPOSE: Cancel routine
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *******************************************************************/
static KSPIN_LOCK CancelSpinLock;
/* FUNCTIONS *****************************************************************/
BOOLEAN IoCancelIrp(PIRP Irp)
{
KIRQL oldlvl;
DPRINT("IoCancelIrp(Irp %x)\n",Irp);
IoAcquireCancelSpinLock(&oldlvl);
Irp->Cancel = TRUE;
if (Irp->CancelRoutine==NULL)
{
return(FALSE);
}
Irp->CancelRoutine(Irp->Stack[0].DeviceObject,Irp);
IoReleaseCancelSpinLock(&oldlvl);
return(TRUE);
}
VOID IoInitCancelHandling(VOID)
{
KeInitializeSpinLock(&CancelSpinLock);
}
VOID IoAcquireCancelSpinLock(PKIRQL Irql)
{
KeAcquireSpinLock(&CancelSpinLock,Irql);
}
VOID IoReleaseCancelSpinLock(KIRQL Irql)
{
KeReleaseSpinLock(&CancelSpinLock,Irql);
}
PDRIVER_CANCEL IoSetCancelRoutine(PIRP Irp, PDRIVER_CANCEL CancelRoutine)
{
return((PDRIVER_CANCEL)InterlockedExchange((PULONG)&Irp->CancelRoutine,
(ULONG)CancelRoutine));
}

View file

@ -0,0 +1,145 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/cntrller.c
* PURPOSE: Implements the controller object
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* TYPES ********************************************************************/
typedef struct
/*
* PURPOSE: A entry in the queue waiting for a controller object
*/
{
KDEVICE_QUEUE_ENTRY Entry;
PDEVICE_OBJECT DeviceObject;
PDRIVER_CONTROL ExecutionRoutine;
PVOID Context;
} CONTROLLER_QUEUE_ENTRY, *PCONTROLLER_QUEUE_ENTRY;
/* FUNCTIONS *****************************************************************/
VOID IoAllocateController(PCONTROLLER_OBJECT ControllerObject,
PDEVICE_OBJECT DeviceObject,
PDRIVER_CONTROL ExecutionRoutine,
PVOID Context)
/*
* FUNCTION: Sets up a call to a driver-supplied ControllerControl routine
* as soon as the device controller, represented by the given controller
* object, is available to carry out an I/O operation for the target device,
* represented by the given device object.
* ARGUMENTS:
* ControllerObject = Driver created controller object
* DeviceObject = Target device for the current irp
* ExecutionRoutine = Routine to be called when the device is available
* Context = Driver supplied context to be passed on to the above routine
* NOTE: Is the below implementation correct.
*/
{
PCONTROLLER_QUEUE_ENTRY entry;
IO_ALLOCATION_ACTION Result;
assert(KeGetCurrentIrql()==DISPATCH_LEVEL);
entry=ExAllocatePool(NonPagedPool,sizeof(CONTROLLER_QUEUE_ENTRY));
assert(entry!=NULL);
entry->DeviceObject = DeviceObject;
entry->ExecutionRoutine = ExecutionRoutine;
entry->Context = Context;
if (KeInsertDeviceQueue(&ControllerObject->DeviceWaitQueue,&entry->Entry))
{
return;
}
Result = ExecutionRoutine(DeviceObject,DeviceObject->CurrentIrp,
NULL,Context);
if (Result == DeallocateObject)
{
IoFreeController(ControllerObject);
ExFreePool(entry);
}
}
PCONTROLLER_OBJECT IoCreateController(ULONG Size)
/*
* FUNCTION: Allocates memory and initializes a controller object
* ARGUMENTS:
* Size = Size (in bytes) to be allocated for the controller extension
* RETURNS: A pointer to the created object
*/
{
PCONTROLLER_OBJECT controller;
assert(KeGetCurrentIrql()==PASSIVE_LEVEL);
controller = ExAllocatePool(NonPagedPool,sizeof(CONTROLLER_OBJECT));
if (controller==NULL)
{
return(NULL);
}
controller->ControllerExtension=ExAllocatePool(NonPagedPool,Size);
if (controller->ControllerExtension==NULL)
{
ExFreePool(controller);
return(NULL);
}
KeInitializeDeviceQueue(&controller->DeviceWaitQueue);
return(controller);
}
VOID IoDeleteController(PCONTROLLER_OBJECT ControllerObject)
/*
* FUNCTION: Removes a given controller object from the system
* ARGUMENTS:
* ControllerObject = Controller object to be released
*/
{
assert(KeGetCurrentIrql()==PASSIVE_LEVEL);
ExFreePool(ControllerObject->ControllerExtension);
ExFreePool(ControllerObject);
}
VOID IoFreeController(PCONTROLLER_OBJECT ControllerObject)
/*
* FUNCTION: Releases a previously allocated controller object when a
* device has finished an I/O request
* ARGUMENTS:
* ControllerObject = Controller object to be released
*/
{
PKDEVICE_QUEUE_ENTRY QEntry = KeRemoveDeviceQueue(&ControllerObject->
DeviceWaitQueue);
CONTROLLER_QUEUE_ENTRY* Entry = CONTAINING_RECORD(QEntry,
CONTROLLER_QUEUE_ENTRY,
Entry);
IO_ALLOCATION_ACTION Result;
if (QEntry==NULL)
{
return;
}
Result = Entry->ExecutionRoutine(Entry->DeviceObject,
Entry->DeviceObject->CurrentIrp,NULL,
Entry->Context);
if (Result == DeallocateObject)
{
ExFreePool(Entry);
}
}

View file

@ -0,0 +1,101 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/iomgr/create.cc
* PURPOSE: Handling file create/open apis
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 24/05/98: Created
*/
/* INCLUDES ***************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/objmgr.h>
#include <internal/iomgr.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *************************************************************/
NTSTATUS ZwCreateFile(PHANDLE FileHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PIO_STATUS_BLOCK IoStatusBlock,
PLARGE_INTEGER AllocateSize,
ULONG FileAttributes,
ULONG ShareAccess,
ULONG CreateDisposition,
ULONG CreateOptions,
PVOID EaBuffer,
ULONG EaLength)
{
UNIMPLEMENTED;
}
NTSTATUS ZwOpenFile(PHANDLE FileHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG ShareAccess,
ULONG OpenOptions)
{
UNIMPLEMENTED;
}
HANDLE STDCALL CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
PDEVICE_OBJECT DeviceObject;
PIRP Irp;
HANDLE hfile;
UNICODE_STRING filename;
ANSI_STRING afilename;
RtlInitAnsiString(&afilename,lpFileName);
RtlAnsiStringToUnicodeString(&filename,&afilename,TRUE);
DeviceObject = ObLookupObject(NULL,&filename);
DPRINT("Sending IRP for IRP_MJ_CREATE to %x\n",DeviceObject);
if (DeviceObject==NULL)
{
DPRINT("(%s:%d) Object not found\n",__FILE__,__LINE__);
return(NULL);
}
hfile = ObAddHandle(DeviceObject);
/*
* Tell the device we are openining it
*/
Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
if (Irp==NULL)
{
return(NULL);
}
DPRINT("Preparing IRP\n");
/*
* Set up the stack location
*/
Irp->Stack[Irp->CurrentLocation].MajorFunction = IRP_MJ_CREATE;
Irp->Stack[Irp->CurrentLocation].MinorFunction = 0;
Irp->Stack[Irp->CurrentLocation].Flags = 0;
Irp->Stack[Irp->CurrentLocation].Control = 0;
Irp->Stack[Irp->CurrentLocation].DeviceObject = DeviceObject;
// Irp->Stack[Irp->StackPtr].FileObject = &files[hfile];
DPRINT("Sending IRP\n");
IoCallDriver(DeviceObject,Irp);
DPRINT("Returning %x\n",hfile);
return(hfile);
}

View file

@ -0,0 +1,186 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/iomgr/device.cc
* PURPOSE: Manage devices
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 15/05/98: Created
*/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/iomgr.h>
#include <internal/objmgr.h>
#include <internal/string.h>
//#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS ***************************************************************/
NTSTATUS IoAttachDeviceByPointer(PDEVICE_OBJECT SourceDevice,
PDEVICE_OBJECT TargetDevice)
{
UNIMPLEMENTED;
}
VOID IoDeleteDevice(PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
}
PDEVICE_OBJECT IoGetRelatedDeviceObject(PFILE_OBJECT FileObject)
{
return(FileObject->DeviceObject);
}
NTSTATUS IoGetDeviceObjectPointer(PUNICODE_STRING ObjectName,
ACCESS_MASK DesiredAccess,
PFILE_OBJECT* FileObject,
PDEVICE_OBJECT* DeviceObject)
{
UNIMPLEMENTED;
}
VOID IoDetachDevice(PDEVICE_OBJECT TargetDevice)
{
UNIMPLEMENTED;
}
PDEVICE_OBJECT IoAttachDeviceToDeviceStack(PDEVICE_OBJECT SourceDevice,
PDEVICE_OBJECT TargetDevice)
{
UNIMPLEMENTED;
}
VOID IoRegisterDriverReinitialization(PDRIVER_OBJECT DriverObject,
PDRIVER_REINITIALIZE ReinitRoutine,
PVOID Context)
{
UNIMPLEMENTED;
}
NTSTATUS InitalizeLoadedDriver(PDRIVER_INITIALIZE entry)
/*
* FUNCTION: Called to initalize a loaded driver
* ARGUMENTS:
*/
{
NTSTATUS ret;
PDRIVER_OBJECT DriverObject;
/*
* Allocate memory for a driver object
* NOTE: The object only becomes system visible once the associated
* device objects are intialized
*/
DriverObject=ExAllocatePool(NonPagedPool,sizeof(DRIVER_OBJECT));
if (DriverObject==NULL)
{
printk("%s:%d\n",__FILE__,__LINE__);
return(STATUS_INSUFFICIENT_RESOURCES);
}
memset(DriverObject,sizeof(DRIVER_OBJECT),0);
/*
* Initalize the driver
* FIXME: Registry in general please
*/
if ((ret=entry(DriverObject,NULL))!=STATUS_SUCCESS)
{
DPRINT("Failed to load driver (status %x)\n",ret);
ExFreePool(DriverObject);
return(ret);
}
return(STATUS_SUCCESS);
}
NTSTATUS IoAttachDevice(PDEVICE_OBJECT SourceDevice,
PUNICODE_STRING TargetDevice,
PDEVICE_OBJECT* AttachedDevice)
/*
* FUNCTION: Layers a device over the highest device in a device stack
* ARGUMENTS:
* SourceDevice = Device to attached
* TargetDevice = Name of the target device
* AttachedDevice (OUT) = Caller storage for the device attached to
*/
{
UNIMPLEMENTED;
}
NTSTATUS IoCreateDevice(PDRIVER_OBJECT DriverObject,
ULONG DeviceExtensionSize,
PUNICODE_STRING DeviceName,
DEVICE_TYPE DeviceType,
ULONG DeviceCharacteristics,
BOOLEAN Exclusive,
PDEVICE_OBJECT* DeviceObject)
/*
* FUNCTION: Allocates memory for and intializes a device object for use for
* a driver
* ARGUMENTS:
* DriverObject : Driver object passed by iomgr when the driver was
* loaded
* DeviceExtensionSize : Number of bytes for the device extension
* DeviceName : Unicode name of device
* DeviceType : Device type
* DeviceCharacteristics : Bit mask of device characteristics
* Exclusive : True if only one thread can access the device at a
* time
* RETURNS:
* Success or failure
* DeviceObject : Contains a pointer to allocated device object
* if the call succeeded
* NOTES: See the DDK documentation for more information
*/
{
PDEVICE_OBJECT dev;
OBJECT_ATTRIBUTES dev_attr;
HANDLE devh;
InitializeObjectAttributes(&dev_attr,DeviceName,0,NULL,NULL);
dev = ObGenericCreateObject(&devh,0,&dev_attr,OBJTYP_DEVICE);
*DeviceObject=NULL;
if (dev==NULL)
{
return(STATUS_INSUFFICIENT_RESOURCES);
}
if (DriverObject->DeviceObject==NULL)
{
DriverObject->DeviceObject = dev;
dev->NextDevice=NULL;
}
else
{
dev->NextDevice=DriverObject->DeviceObject;
DriverObject->DeviceObject=dev;
}
dev->DriverObject = DriverObject;
dev->CurrentIrp=NULL;
dev->Flags=0;
dev->DeviceExtension=ExAllocatePool(NonPagedPool,DeviceExtensionSize);
if (DeviceExtensionSize > 0 && dev->DeviceExtension==NULL)
{
ExFreePool(dev);
return(STATUS_INSUFFICIENT_RESOURCES);
}
dev->DeviceType=DeviceType;
dev->StackSize=1;
dev->AlignmentRequirement=1;
*DeviceObject=dev;
return(STATUS_SUCCESS);
}

33
reactos/ntoskrnl/io/dpc.c Normal file
View file

@ -0,0 +1,33 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID IoInitializeDpcRequest(PDEVICE_OBJECT DeviceObject,
PIO_DPC_ROUTINE DpcRoutine)
{
KeInitializeDpc(&DeviceObject->Dpc,(PKDEFERRED_ROUTINE)DpcRoutine,
DeviceObject);
}
VOID IoRequestDpc(PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context)
{
KeInsertQueueDpc(&DeviceObject->Dpc,Irp,Context);
}

View file

@ -0,0 +1,50 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/iomgr/drvlck.c
* PURPOSE: Managing driver managing
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle)
{
UNIMPLEMENTED;
}
VOID MmLockPagableSectionByHandle(PVOID ImageSectionHandle)
{
UNIMPLEMENTED;
}
PVOID MmLockPagableCodeSection(PVOID AddressWithinSection)
{
UNIMPLEMENTED;
}
PVOID MmLockPagableDataSection(PVOID AddressWithinSection)
{
UNIMPLEMENTED;
}
VOID MmPageEntireDriver(PVOID AddressWithinSection)
{
UNIMPLEMENTED;
}
VOID MmResetDriverPaging(PVOID AddressWithinSection)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,30 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PVOID IoAllocateErrorLogEntry(PVOID IoObject, UCHAR EntrySize)
{
UNIMPLEMENTED;
}
VOID IoWriteErrorLogEntry(PVOID ElEntry)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,57 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
BOOLEAN IoIsErrorUserInduced(NTSTATUS Status)
{
switch(Status)
{
case STATUS_DEVICE_NOT_READY:
case STATUS_IO_TIMEOUT:
case STATUS_MEDIA_WRITE_PROTECTED:
case STATUS_NO_MEDIA_IN_DRIVE:
case STATUS_VERIFY_REQUIRED:
case STATUS_UNRECOGNIZED_MEDIA:
case STATUS_WRONG_VOLUME:
return(TRUE);
}
return(FALSE);
}
VOID IoSetHardErrorOrVerifyDevice(PIRP Irp, PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
}
VOID IoRaiseHardError(PIRP Irp, PVPB Vpb, PDEVICE_OBJECT RealDeviceObject)
{
UNIMPLEMENTED;
}
BOOLEAN IoIsTotalDeviceFailure(NTSTATUS Status)
{
UNIMPLEMENTED;
}
BOOLEAN IoRaiseInformationalHardError(NTSTATUS ErrorStatus,
PUNICODE_STRING String,
PKTHREAD Thread)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,32 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/event.c
* PURPOSE: Implements named events
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PKEVENT IoCreateNotificationEvent(PUNICODE_STRING EventName,
PHANDLE EventHandle)
{
UNIMPLEMENTED;
}
PKEVENT IoCreateSynchronizationEvent(PUNICODE_STRING EventName,
PHANDLE EventHandle)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,44 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/fdisk.c
* PURPOSE: Handling fixed disks
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS IoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
ULONG SectorSize,
BOOLEAN ReturnRecognizedPartitions,
struct _DRIVE_LAYOUT_INFORMATION** PBuffer)
{
UNIMPLEMENTED;
}
NTSTATUS IoSetPartitionInformation(PDEVICE_OBJECT DeviceObject,
ULONG SectorSize,
ULONG PartitionNumber,
ULONG PartitionType)
{
UNIMPLEMENTED;
}
NTSTATUS IoWritePartitionTable(PDEVICE_OBJECT DeviceObject,
ULONG SectorSize,
ULONG SectorsPerTrack,
ULONG NumberOfHeads,
struct _DRIVE_LAYOUT_INFORMATION* PBuffer)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,42 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/io/file.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS ZwQueryInformationFile(HANDLE FileHandle,
PIO_STATUS_BLOCK IoStatusBlock,
PVOID FileInformation,
ULONG Length,
FILE_INFORMATION_CLASS FileInformationClass)
{
UNIMPLEMENTED;
}
NTSTATUS ZwSetInformationFile(HANDLE FileHandle,
PIO_STATUS_BLOCK IoStatusBlock,
PVOID FileInformation,
ULONG Length,
FILE_INFORMATION_CLASS FileInformationClass)
{
UNIMPLEMENTED;
}
PGENERIC_MAPPING IoGetFileObjectGenericMapping()
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,24 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
ULONG IoGetFunctionCodeFromCtlCode(ULONG ControlCode)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,55 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/iomgr.c
* PURPOSE: Initializes the io manager
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 29/07/98: Created
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/objmgr.h>
/* GLOBALS *******************************************************************/
OBJECT_TYPE DeviceObjectType = {{NULL,0,0},
0,
0,
ULONG_MAX,
ULONG_MAX,
sizeof(DEVICE_OBJECT),
0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
/* FUNCTIONS ****************************************************************/
VOID IoInit(VOID)
{
OBJECT_ATTRIBUTES attr;
HANDLE handle;
UNICODE_STRING string;
ANSI_STRING astring;
ObRegisterType(OBJTYP_DEVICE,&DeviceObjectType);
RtlInitAnsiString(&astring,"\\Device");
RtlAnsiStringToUnicodeString(&string,&astring,TRUE);
InitializeObjectAttributes(&attr,&string,0,NULL,NULL);
ZwCreateDirectoryObject(&handle,0,&attr);
IoInitCancelHandling();
}

295
reactos/ntoskrnl/io/irp.c Normal file
View file

@ -0,0 +1,295 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/irp.c
* PURPOSE: Handle IRPs
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 24/05/98: Created
*/
/* NOTES *******************************************************************
*
* Layout of an IRP
*
* ################
* # Headers #
* ################
* # #
* # Variable #
* # length list #
* # of io stack #
* # locations #
* # #
* ################
*
*
*
*/
/* INCLUDES ****************************************************************/
#include <internal/string.h>
#include <internal/kernel.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS ****************************************************************/
PDEVICE_OBJECT IoGetDeviceToVerify(PETHREAD Thread)
/*
* FUNCTION: Returns a pointer to the device, representing a removable-media
* device, that is the target of the given thread's I/O request
*/
{
UNIMPLEMENTED;
}
VOID IoFreeIrp(PIRP Irp)
/*
* FUNCTION: Releases a caller allocated irp
* ARGUMENTS:
* Irp = Irp to free
*/
{
ExFreePool(Irp);
}
PIRP IoMakeAssociatedIrp(PIRP Irp, CCHAR StackSize)
/*
* FUNCTION: Allocates and initializes an irp to associated with a master irp
* ARGUMENTS:
* Irp = Master irp
* StackSize = Number of stack locations to be allocated in the irp
* RETURNS: The irp allocated
*/
{
PIRP AssocIrp;
AssocIrp = IoAllocateIrp(StackSize,FALSE);
UNIMPLEMENTED;
}
VOID IoMarkIrpPending(PIRP Irp)
/*
* FUNCTION: Marks the specified irp, indicating further processing will
* be required by other driver routines
* ARGUMENTS:
* Irp = Irp to mark
*/
{
IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED;
}
PIRP IoBuildAsynchronousFsdRequest(ULONG MajorFunction,
PDEVICE_OBJECT DeviceObject,
PVOID Buffer,
ULONG Length,
PLARGE_INTEGER StartingOffset,
PIO_STATUS_BLOCK IoStatusBlock)
{
UNIMPLEMENTED;
}
PIRP IoBuildDeviceIoControlRequest(ULONG IoControlCode,
PDEVICE_OBJECT DeviceObject,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength,
BOOLEAN InternalDeviceIoControl,
PKEVENT Event,
PIO_STATUS_BLOCK IoStatusBlock)
{
UNIMPLEMENTED;
}
PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
PDEVICE_OBJECT DeviceObject,
PVOID Buffer,
ULONG Length,
PLARGE_INTEGER StartingOffset,
PKEVENT Event,
PIO_STATUS_BLOCK IoStatusBlock)
{
PDRIVER_OBJECT DriverObject = DeviceObject->DriverObject;
PIRP irp;
PIO_STACK_LOCATION StackPtr;
/*
* Allocate an IRP for the transfer
*/
irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
if (irp==NULL)
{
printk("Failed to allocate IRP\n");
return(FALSE);
}
/*
* Prepare the parameter in the next IO stack location
*/
StackPtr = IoGetNextIrpStackLocation(irp);
StackPtr->MajorFunction = MajorFunction;
StackPtr->MinorFunction = 0;
StackPtr->Flags = 0;
StackPtr->Control = 0;
}
USHORT IoSizeOfIrp(CCHAR StackSize)
/*
* FUNCTION: Determines the size of an IRP
* ARGUMENTS:
* StackSize = number of stack locations in the IRP
* RETURNS: The size of the IRP in bytes
*/
{
return(sizeof(IRP)+((StackSize-1)*sizeof(IO_STACK_LOCATION)));
}
VOID IoInitializeIrp(PIRP Irp, USHORT PacketSize, CCHAR StackSize)
/*
* FUNCTION: Initalizes an irp allocated by the caller
* ARGUMENTS:
* Irp = IRP to initalize
* PacketSize = Size in bytes of the IRP
* StackSize = Number of stack locations in the IRP
*/
{
assert(Irp!=NULL);
memset(Irp,0,PacketSize);
Irp->CurrentLocation=StackSize;
Irp->Tail.Overlay.CurrentStackLocation=IoGetCurrentIrpStackLocation(Irp);
}
PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
/*
* FUNCTION: Gets a pointer to the callers location in the I/O stack in
* the given IRP
* ARGUMENTS:
* Irp = Points to the IRP
* RETURNS: A pointer to the stack location
*/
{
return(&Irp->Stack[Irp->CurrentLocation]);
}
VOID IoSetNextIrpStackLocation(PIRP Irp)
{
Irp->CurrentLocation--;
Irp->Tail.Overlay.CurrentStackLocation--;
}
PIO_STACK_LOCATION IoGetNextIrpStackLocation(PIRP Irp)
/*
* FUNCTION: Gives a higher level driver access to the next lower driver's
* I/O stack location
* ARGUMENTS:
* Irp = points to the irp
* RETURNS: A pointer to the stack location
*/
{
assert(Irp!=NULL);
DPRINT("Irp %x Irp->StackPtr %x\n",Irp,Irp->CurrentLocation);
return(&Irp->Stack[Irp->CurrentLocation-1]);
}
NTSTATUS IoCallDriver(PDEVICE_OBJECT DevObject, PIRP irp)
/*
* FUNCTION: Sends an IRP to the next lower driver
*/
{
PDRIVER_OBJECT drv = DevObject->DriverObject;
IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(irp);
irp->Tail.Overlay.CurrentStackLocation--;
irp->CurrentLocation--;
DPRINT("Io stack address %x\n",param);
DPRINT("Function %d Routine %x\n",param->MajorFunction,
drv->MajorFunction[param->MajorFunction]);
DPRINT("IRP_MJ_CREATE %d\n",IRP_MJ_CREATE);
return(drv->MajorFunction[param->MajorFunction](DevObject,irp));
}
PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota)
/*
* FUNCTION: Allocates an IRP
* ARGUMENTS:
* StackSize = the size of the stack required for the irp
* ChargeQuota = Charge allocation to current threads quota
* RETURNS: Irp allocated
*/
{
PIRP Irp;
DPRINT("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",StackSize,
ChargeQuota);
if (ChargeQuota)
{
Irp = ExAllocatePoolWithQuota(NonPagedPool,IoSizeOfIrp(StackSize));
}
else
{
Irp = ExAllocatePool(NonPagedPool,IoSizeOfIrp(StackSize));
}
if (Irp==NULL)
{
return(NULL);
}
Irp->CurrentLocation=StackSize;
DPRINT("Irp %x Irp->StackPtr %d\n",Irp,Irp->CurrentLocation);
return(Irp);
}
VOID IoSetCompletionRoutine(PIRP Irp,
PIO_COMPLETION_ROUTINE CompletionRoutine,
PVOID Context,
BOOLEAN InvokeOnSuccess,
BOOLEAN InvokeOnError,
BOOLEAN InvokeOnCancel)
{
IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(Irp);
param->CompletionRoutine=CompletionRoutine;
param->CompletionContext=Context;
if (InvokeOnSuccess)
{
param->Control = SL_INVOKE_ON_SUCCESS;
}
if (InvokeOnError)
{
param->Control = param->Control | SL_INVOKE_ON_ERROR;
}
if (InvokeOnCancel)
{
param->Control = param->Control | SL_INVOKE_ON_CANCEL;
}
}
VOID IoCompleteRequest(IRP* Irp, CCHAR PriorityBoost)
/*
* FUNCTION: Indicates the caller has finished all processing for a given
* I/O request and is returning the given IRP to the I/O manager
* ARGUMENTS:
* Irp = Irp to be cancelled
* PriorityBoost = Increment by which to boost the priority of the
* thread making the request
*/
{
unsigned int i;
for (i=0;i<0;i++)
{
if (Irp->Stack[i].CompletionRoutine!=NULL)
{
Irp->Stack[i].CompletionRoutine(Irp->Stack[i].DeviceObject,Irp,
Irp->Stack[i].CompletionContext);
}
}
}

69
reactos/ntoskrnl/io/mdl.c Normal file
View file

@ -0,0 +1,69 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <internal/hal/page.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PMDL IoAllocateMdl(PVOID VirtualAddress,
ULONG Length,
BOOLEAN SecondaryBuffer,
BOOLEAN ChargeQuota,
PIRP Irp)
{
PMDL Mdl;
if (ChargeQuota)
{
Mdl = ExAllocatePoolWithQuota(NonPagedPool,
MmSizeOfMdl(VirtualAddress,Length));
}
else
{
Mdl = ExAllocatePool(NonPagedPool,MmSizeOfMdl(VirtualAddress,Length));
}
MmInitializeMdl(Mdl,VirtualAddress,Length);
if (Irp!=NULL && !SecondaryBuffer)
{
Irp->MdlAddress = Mdl;
}
return(Mdl);
}
VOID IoBuildPartialMdl(PMDL SourceMdl,
PMDL TargetMdl,
PVOID VirtualAddress,
ULONG Length)
{
PULONG TargetPages = (PULONG)(TargetMdl + 1);
PULONG SourcePages = (PULONG)(SourceMdl + 1);
ULONG Va;
ULONG Delta = (PAGE_ROUND_DOWN(VirtualAddress) - (ULONG)SourceMdl->StartVa)/
PAGESIZE;
for (Va = 0; Va < (PAGE_ROUND_UP(Length)/PAGESIZE); Va++)
{
TargetPages[Va] = SourcePages[Va+Delta];
}
}
VOID IoFreeMdl(PMDL Mdl)
{
MmUnmapLockedPages(MmGetSystemAddressForMdl(Mdl),Mdl);
MmUnlockPages(Mdl);
ExFreePool(Mdl);
}

View file

@ -0,0 +1,29 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/iomgr/process.c
* PURPOSE: Process functions that, bizarrely, are in the iomgr
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PEPROCESS IoGetCurrentProcess()
{
return(PsGetCurrentProcess());
}
PVOID IoGetInitialStack()
{
UNIMPLEMENTED;
}

112
reactos/ntoskrnl/io/queue.c Normal file
View file

@ -0,0 +1,112 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/queue.c
* PURPOSE: Implement device queueing
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
/* INCLUDES ******************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID IoStartNextPacketByKey(PDEVICE_OBJECT DeviceObject,
BOOLEAN Cancelable,
ULONG Key)
/*
* FUNCTION: Dequeues the next packet from the given device object's
* associated device queue according to a specified sort-key value and calls
* the drivers StartIo routine with that IRP
* ARGUMENTS:
* DeviceObject = Device object for which the irp is to dequeued
* Cancelable = True if IRPs in the key can be canceled
* Key = Sort key specifing which entry to remove from the queue
*/
{
PKDEVICE_QUEUE_ENTRY entry;
PIRP Irp;
KIRQL oldirql;
entry = KeRemoveByKeyDeviceQueue(&DeviceObject->DeviceQueue,Key);
if (entry!=NULL)
{
Irp = CONTAINING_RECORD(entry,IRP,Tail.Overlay.DeviceQueueEntry);
DeviceObject->DriverObject->DriverStartIo(DeviceObject,Irp);
}
}
VOID IoStartNextPacket(PDEVICE_OBJECT DeviceObject, BOOLEAN Cancelable)
/*
* FUNCTION: Removes the next packet from the device's queue and calls
* the driver's StartIO
* ARGUMENTS:
* DeviceObject = Device
* Cancelable = True if irps in the queue can be canceled
*/
{
PKDEVICE_QUEUE_ENTRY entry;
PIRP Irp;
KIRQL oldirql;
entry = KeRemoveDeviceQueue(&DeviceObject->DeviceQueue);
if (entry!=NULL)
{
Irp = CONTAINING_RECORD(entry,IRP,Tail.Overlay.DeviceQueueEntry);
DeviceObject->DriverObject->DriverStartIo(DeviceObject,Irp);
}
}
VOID IoStartPacket(PDEVICE_OBJECT DeviceObject,
PIRP Irp, PULONG Key, PDRIVER_CANCEL CancelFunction)
/*
* FUNCTION: Either call the device's StartIO routine with the packet or,
* if the device is busy, queue it.
* ARGUMENTS:
* DeviceObject = Device to start the packet on
* Irp = Irp to queue
* Key = Where to insert the irp
* If zero then insert in the tail of the queue
* CancelFunction = Optional function to cancel the irqp
*/
{
BOOLEAN stat;
KIRQL oldirql;
ASSERT_IRQL(DISPATCH_LEVEL);
IoAcquireCancelSpinLock(&oldirql);
if (CancelFunction != NULL)
{
Irp->CancelRoutine = CancelFunction;
}
if (Key!=0)
{
stat = KeInsertByKeyDeviceQueue(&DeviceObject->DeviceQueue,
&Irp->Tail.Overlay.DeviceQueueEntry,
*Key);
}
else
{
stat = KeInsertDeviceQueue(&DeviceObject->DeviceQueue,
&Irp->Tail.Overlay.DeviceQueueEntry);
}
IoReleaseCancelSpinLock(oldirql);
if (!stat)
{
DeviceObject->DriverObject->DriverStartIo(DeviceObject,Irp);
}
}

View file

@ -0,0 +1,59 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/resource.c
* PURPOSE: Hardware resource managment
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PCONFIGURATION_INFORMATION IoGetConfigurationInformation()
{
UNIMPLEMENTED;
}
NTSTATUS IoReportResourceUsage(PUNICODE_STRING DriverClassName,
PDRIVER_OBJECT DriverObject,
PCM_RESOURCE_LIST DriverList,
ULONG DriverListSize,
PDEVICE_OBJECT DeviceObject,
PCM_RESOURCE_LIST DeviceList,
ULONG DeviceListSize,
BOOLEAN OverrideConflict,
PBOOLEAN ConflictDetected)
{
UNIMPLEMENTED;
}
NTSTATUS IoAssignResources(PUNICODE_STRING RegistryPath,
PUNICODE_STRING DriverClassName,
PDRIVER_OBJECT DriverObject,
PDEVICE_OBJECT DeviceObject,
PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
PCM_RESOURCE_LIST* AllocatedResources)
{
UNIMPLEMENTED;
}
NTSTATUS IoQueryDeviceDescription(PINTERFACE_TYPE BusType,
PULONG BusNumber,
PCONFIGURATION_TYPE ControllerType,
PULONG ControllerNumber,
PCONFIGURATION_TYPE PeripheralType,
PULONG PeripheralNumber,
PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
PVOID Context)
{
UNIMPLEMENTED;
}

228
reactos/ntoskrnl/io/rw.c Normal file
View file

@ -0,0 +1,228 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/rw.c
* PURPOSE: Implements read/write APIs
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 30/05/98: Created
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/iomgr.h>
#include <internal/string.h>
#include <internal/objmgr.h>
//#define NDEBUG
#include <internal/debug.h>
#ifndef NDEBUG
#define DPRINT1(x) printk(x)
#else
#define DPRINT1(x)
#endif
/* FUNCTIONS ***************************************************************/
NTSTATUS ZwReadFile(HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
PVOID Buffer,
ULONG Length,
PLARGE_INTEGER ByteOffset,
PULONG Key)
{
UNIMPLEMENTED;
}
NTSTATUS ZwWriteFile(HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
PVOID Buffer,
ULONG Length,
PLARGE_INTEGER ByteOffset,
PULONG Key)
{
UNIMPLEMENTED;
}
static BOOL WriteDevice(PDEVICE_OBJECT dev, LPVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped)
{
PDRIVER_OBJECT drv = dev->DriverObject;
PIRP irp;
PIO_STACK_LOCATION StackPtr;
DPRINT("dev %x drv %x\n",dev,drv);
/*
* Build an irp for the transfer
*/
irp = IoAllocateIrp(dev->StackSize,TRUE);
if (irp==NULL)
{
printk("Failed to allocate IRP\n");
return(FALSE);
}
/*
* Prepare the user buffer
*/
DPRINT1("Preparing user buffer\n");
irp->UserBuffer = (LPVOID)lpBuffer; // This handles the 'neither' method
if (dev->Flags&DO_BUFFERED_IO)
{
DPRINT1("Doing buffer i/o\n");
irp->AssociatedIrp.SystemBuffer = (PVOID)
ExAllocatePool(NonPagedPool,nNumberOfBytesToWrite);
if (irp->AssociatedIrp.SystemBuffer==NULL)
{
return(FALSE);
}
memcpy(irp->AssociatedIrp.SystemBuffer,lpBuffer,nNumberOfBytesToWrite);
irp->UserBuffer = NULL;
}
if (dev->Flags&DO_DIRECT_IO)
{
DPRINT1("Doing direct i/o\n");
irp->MdlAddress = MmCreateMdl(NULL,lpBuffer,nNumberOfBytesToWrite);
MmProbeAndLockPages(irp->MdlAddress,UserMode,IoWriteAccess);
irp->UserBuffer = NULL;
irp->AssociatedIrp.SystemBuffer = NULL;
}
/*
* Set up the stack location
*/
StackPtr = IoGetNextIrpStackLocation(irp);
StackPtr->MajorFunction = IRP_MJ_WRITE;
StackPtr->MinorFunction = 0;
StackPtr->Flags = 0;
StackPtr->Control = 0;
StackPtr->DeviceObject = dev;
StackPtr->FileObject = NULL;
StackPtr->Parameters.Write.Length = nNumberOfBytesToWrite;
DPRINT1("Sending IRP\n");
IoCallDriver(dev,irp);
/*
* Free the above buffer
*/
}
WINBOOL STDCALL WriteFile(HANDLE hFile, LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped)
{
COMMON_BODY_HEADER* hdr = ObGetObjectByHandle(hFile);
if (hdr->Type==OBJTYP_DEVICE)
{
return(WriteDevice(hdr,lpBuffer,nNumberOfBytesToWrite,
lpNumberOfBytesWritten,lpOverlapped));
}
return(FALSE);
}
static BOOL ReadDevice(PDEVICE_OBJECT dev, LPVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped)
{
PDRIVER_OBJECT drv = dev->DriverObject;
PIRP irp;
PIO_STACK_LOCATION StackPtr;
DPRINT("dev %x drv %x\n",dev,drv);
/*
* Build an irp for the transfer
*/
irp = IoAllocateIrp(dev->StackSize,TRUE);
if (irp==NULL)
{
printk("Failed to allocate IRP\n");
return(FALSE);
}
/*
* Prepare the user buffer
*/
DPRINT1("Preparing user buffer\n");
irp->UserBuffer = (LPVOID)lpBuffer; // This handles the 'neither' method
if (dev->Flags&DO_BUFFERED_IO)
{
DPRINT1("Doing buffer i/o\n");
irp->AssociatedIrp.SystemBuffer = (PVOID)
ExAllocatePool(NonPagedPool,nNumberOfBytesToWrite);
if (irp->AssociatedIrp.SystemBuffer==NULL)
{
return(FALSE);
}
memcpy(irp->AssociatedIrp.SystemBuffer,lpBuffer,nNumberOfBytesToWrite);
irp->UserBuffer = NULL;
}
if (dev->Flags&DO_DIRECT_IO)
{
DPRINT1("Doing direct i/o\n");
irp->MdlAddress = MmCreateMdl(NULL,lpBuffer,nNumberOfBytesToWrite);
MmProbeAndLockPages(irp->MdlAddress,UserMode,IoWriteAccess);
irp->UserBuffer = NULL;
irp->AssociatedIrp.SystemBuffer = NULL;
}
/*
* Set up the stack location
*/
StackPtr = IoGetNextIrpStackLocation(irp);
StackPtr->MajorFunction = IRP_MJ_READ;
StackPtr->MinorFunction = 0;
StackPtr->Flags = 0;
StackPtr->Control = 0;
StackPtr->DeviceObject = dev;
StackPtr->FileObject = NULL;
StackPtr->Parameters.Write.Length = nNumberOfBytesToWrite;
DPRINT1("Sending IRP\n");
IoCallDriver(dev,irp);
/*
* Free the above buffer
*/
DPRINT1("Finished ReadDevice\n");
}
WINBOOL STDCALL ReadFile(HANDLE hFile, LPVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped)
{
COMMON_BODY_HEADER* hdr = ObGetObjectByHandle(hFile);
if (hdr->Type==OBJTYP_DEVICE)
{
return(ReadDevice((PDEVICE_OBJECT)hdr,lpBuffer,nNumberOfBytesToWrite,
lpNumberOfBytesWritten,lpOverlapped));
}
return(FALSE);
}

View file

@ -0,0 +1,47 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID IoUpdateShareAccess(PFILE_OBJECT FileObject, PSHARE_ACCESS ShareAccess)
{
UNIMPLEMENTED;
}
NTSTATUS IoCheckShareAccess(ACCESS_MASK DesiredAccess,
ULONG DesiredShareAccess,
PFILE_OBJECT FileObject,
PSHARE_ACCESS ShareAccess,
BOOLEAN Update)
{
UNIMPLEMENTED;
}
VOID IoRemoveShareAccess(PFILE_OBJECT FileObject,
PSHARE_ACCESS ShareAccess)
{
UNIMPLEMENTED;
}
VOID IoSetShareAccess(ACCESS_MASK DesiredAccess,
ULONG DesiredShareAccess,
PFILE_OBJECT FileObject,
PSHARE_ACCESS ShareAccess)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,29 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/shutdown.c
* PURPOSE: Implements shutdown notification
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
}
VOID IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,36 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/iomgr/symlink.c
* PURPOSE: Implements symbolic links
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS IoCreateUnprotectedSymbolicLink(PUNICODE_STRING SymbolicLinkName,
PUNICODE_STRING DeviceName)
{
UNIMPLEMENTED;
}
NTSTATUS IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName,
PUNICODE_STRING DeviceName)
{
UNIMPLEMENTED;
}
NTSTATUS IoDeleteSymbolicLink(PUNICODE_STRING DeviceName)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,66 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/iomgr/timer.c
* PURPOSE: IO timers
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
PIO_TIMER_ROUTINE TimerRoutine,
PVOID Context)
/*
* FUNCTION: Sets up a driver-supplied IoTimer routine associated with a given
* device object
* ARGUMENTS:
* DeviceObject = Device object whose timer is be initialized
* TimerRoutine = Driver supplied routine which will be called once per
* second if the timer is active
* Context = Driver supplied context to be passed to the TimerRoutine
* RETURNS: Status
*/
{
DeviceObject->Timer = ExAllocatePool(NonPagedPool,sizeof(IO_TIMER));
KeInitializeTimer(&(DeviceObject->Timer->timer));
KeInitializeDpc(&(DeviceObject->Timer->dpc),TimerRoutine,Context);
}
VOID IoStartTimer(PDEVICE_OBJECT DeviceObject)
/*
* FUNCTION: Starts a timer so the driver-supplied IoTimer routine will be
* called once per second
* ARGUMENTS:
* DeviceObject = Device whose timer is to be started
*/
{
LARGE_INTEGER li;
li.HighPart = -1;
li.LowPart = 10000000;
KeSetTimerEx(&DeviceObject->Timer->timer,li,1000,
&(DeviceObject->Timer->dpc));
}
VOID IoStopTimer(PDEVICE_OBJECT DeviceObject)
/*
* FUNCTION: Disables for a specified device object so the driver-supplied
* IoTimer is not called
* ARGUMENTS:
* DeviceObject = Device whose timer is to be stopped
*/
{
KeCancelTimer(&(DeviceObject->Timer->timer));
}

20
reactos/ntoskrnl/ke/apc.c Normal file
View file

@ -0,0 +1,20 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/apc.c
* PURPOSE: Possible implementation of APCs
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/

83
reactos/ntoskrnl/ke/bug.c Normal file
View file

@ -0,0 +1,83 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* GLOBALS ******************************************************************/
static LIST_ENTRY BugcheckCallbackListHead = {NULL,NULL};
/* FUNCTIONS *****************************************************************/
BOOLEAN KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
{
UNIMPLEMENTED;
}
VOID KeInitializeBugCheck(VOID)
{
InitializeListHead(&BugcheckCallbackListHead);
}
VOID KeInitializeCallbackRecord(PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
{
}
BOOLEAN KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
PVOID Buffer,
ULONG Length,
PUCHAR Component)
{
InsertTailList(&BugcheckCallbackListHead,&CallbackRecord->Entry);
CallbackRecord->Length=Length;
CallbackRecord->Buffer=Buffer;
CallbackRecord->Component=Component;
CallbackRecord->CallbackRoutine=CallbackRoutine;
}
asmlinkage VOID KeBugCheckEx(ULONG BugCheckCode,
ULONG BugCheckParameter1,
ULONG BugCheckParameter2,
ULONG BugCheckParameter3,
ULONG BugCheckParameter4)
/*
* FUNCTION: Brings the system down in a controlled manner when an
* inconsistency that might otherwise cause corruption has been detected
* ARGUMENTS:
* BugCheckCode = Specifies the reason for the bug check
* BugCheckParameter[1-4] = Additional information about bug
* RETURNS: Doesn't
*/
{
printk("Bug detected (code %x param %x %x %x %x)\n",BugCheckCode,
BugCheckParameter1,BugCheckParameter2,BugCheckParameter3,
BugCheckParameter4);
for(;;);
}
asmlinkage VOID KeBugCheck(ULONG BugCheckCode)
/*
* FUNCTION: Brings the system down in a controlled manner when an
* inconsistency that might otherwise cause corruption has been detected
* ARGUMENTS:
* BugCheckCode = Specifies the reason for the bug check
* RETURNS: Doesn't
*/
{
KeBugCheckEx(BugCheckCode,0,0,0,0);
}

View file

@ -0,0 +1,21 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/kernel/catch.c
* PURPOSE: Exception handling
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
/* FUNCTIONS ****************************************************************/
VOID ExRaiseStatus(NTSTATUS Status)
{
printk("ExRaiseStatus(%d)\n",Status);
for(;;);
}

View file

@ -0,0 +1,29 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/critical.c
* PURPOSE: Implement critical regions
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID KeEnterCriticalRegion()
{
UNIMPLEMENTED;
}
VOID KeLeaveCriticalRegion()
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,26 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/kernel/dispatch.c
* PURPOSE: Handles a dispatch interrupt
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
/* FUNCTIONS ****************************************************************/
void KiDispatchInterrupt(unsigned int irq)
/*
* FUNCTION: Called after an irq when the interrupted processor was at a lower
* level than DISPATCH_LEVEL
*/
{
KeExpireTimers();
KeDrainDpcQueue();
PsDispatchThread();
}

114
reactos/ntoskrnl/ke/dpc.c Normal file
View file

@ -0,0 +1,114 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/kernel/dpc.cc
* PURPOSE: Handle DPCs (Delayed Procedure Calls)
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 28/05/98: Created
*/
/*
* NOTE: See also the higher level support routines in mkernel/iomgr/iodpc.cc
*/
/* INCLUDES ***************************************************************/
#include <ddk/ntddk.h>
#include <internal/kernel.h>
/* TYPES *******************************************************************/
/* GLOBALS ******************************************************************/
LIST_ENTRY DpcQueueHead;
/* FUNCTIONS ****************************************************************/
VOID KeInitializeDpc(PKDPC Dpc, PKDEFERRED_ROUTINE DeferredRoutine,
PVOID DeferredContext)
/*
* FUNCTION: Initalizes a DPC
* ARGUMENTS:
* Dpc = Caller supplied DPC to be initialized
* DeferredRoutine = Associated DPC callback
* DeferredContext = Parameter to be passed to the callback
* NOTE: Callers must be running at IRQL PASSIVE_LEVEL
*/
{
Dpc->Type=0;
Dpc->DeferredRoutine=DeferredRoutine;
Dpc->DeferredContext=DeferredContext;
Dpc->Lock=0;
}
void KeDrainDpcQueue(void)
/*
* FUNCTION: Called to execute queued dpcs
*/
{
PLIST_ENTRY current_entry = ExInterlockedRemoveHeadList(&DpcQueueHead,NULL);
PKDPC current = CONTAINING_RECORD(&current_entry,KDPC,DpcListEntry);
while (current_entry!=NULL)
{
current->DeferredRoutine(current,current->DeferredContext,
current->SystemArgument1,
current->SystemArgument2);
current_entry = ExInterlockedRemoveHeadList(&DpcQueueHead,NULL);
current = CONTAINING_RECORD(&current_entry,KDPC,DpcListEntry);
}
}
BOOLEAN KeRemoveQueueDpc(PKDPC Dpc)
/*
* FUNCTION: Removes DPC object from the system dpc queue
* ARGUMENTS:
* Dpc = DPC to remove
* RETURNS: TRUE if the DPC was in the queue
* FALSE otherwise
*/
{
if (!Dpc->Lock)
{
return(FALSE);
}
ExInterlockedRemoveEntryList(&DpcQueueHead,&Dpc->DpcListEntry,NULL);
Dpc->Lock=0;
}
BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1,
PVOID SystemArgument2)
/*
* FUNCTION: Queues a DPC for execution when the IRQL of a processor
* drops below DISPATCH_LEVEL
* ARGUMENTS:
* Dpc = Initalizes DPC
* SystemArguments[1-2] = Undocumented
* RETURNS: TRUE if the DPC object wasn't already in the queue
* FALSE otherwise
*/
{
dpc->Number=0;
dpc->Importance=Medium;
dpc->SystemArgument1=SystemArgument1;
dpc->SystemArgument2=SystemArgument2;
if (dpc->Lock)
{
return(FALSE);
}
ExInterlockedInsertHeadList(&DpcQueueHead,&dpc->DpcListEntry,NULL);
dpc->Lock=1;
return(TRUE);
}
void KeInitDpc(void)
/*
* FUNCTION: Initialize DPC handling
*/
{
InitializeListHead(&DpcQueueHead);
}

View file

@ -0,0 +1,46 @@
/*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel v0.0.2
* FILE: kernel/error.cc
* PURPOSE: Error reason setting/getting
* PROGRAMMER: David Welch
* UPDATE HISTORY:
* 16/4/98: Created
*/
/* INCLUDE *****************************************************************/
#include <windows.h>
/* GLOBALS *****************************************************************/
/*
* Last error code (this should be per process)
*/
DWORD error_code;
/* FUNCTIONS ***************************************************************/
DWORD STDCALL GetLastError(VOID)
/*
* FUNCTION: Get the detailed error (if any) from the last function
* RECEIVES: Nothing
* RETURNS:
* The error code
*/
{
return(error_code);
}
VOID STDCALL SetLastError(DWORD dwErrCode)
/*
* FUNCTION: Set the last error code
* RECEIVES:
* dwErrCode = the error code to set
* RETURNS: Nothing
*/
{
error_code=dwErrCode;
}

View file

@ -0,0 +1,56 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/event.c
* PURPOSE: Implements event
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/wait.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS ****************************************************************/
VOID KeClearEvent(PKEVENT Event)
{
Event->Header.SignalState=FALSE; // (??) Is this atomic
}
VOID KeInitializeEvent(PKEVENT Event, EVENT_TYPE Type, BOOLEAN State)
{
Event->Header.Type = Type;
Event->Header.Absolute = 0;
Event->Header.Inserted = 0;
Event->Header.Size = sizeof(KEVENT) / sizeof(ULONG);
Event->Header.SignalState = State;
InitializeListHead(&(Event->Header.WaitListHead));
}
LONG KeReadStateEvent(PKEVENT Event)
{
return(Event->Header.SignalState);
}
LONG KeResetEvent(PKEVENT Event)
{
return(InterlockedExchange(&(Event->Header.SignalState),0));
}
LONG KeSetEvent(PKEVENT Event, KPRIORITY Increment, BOOLEAN Wait)
{
int ret;
KIRQL oldlvl;
KeAcquireSpinLock(&DispatcherDatabaseLock,&oldlvl);
ret = InterlockedExchange(&(Event->Header.SignalState),1);
KeDispatcherObjectWake((DISPATCHER_HEADER *)Event);
KeReleaseSpinLock(&DispatcherDatabaseLock,oldlvl);
}

View file

@ -0,0 +1,748 @@
/*
* This file was machine generated by export
* Don't edit
*
*
*/
#include <internal/symbol.h>
#ifdef __cplusplus
extern "C" {
#endif
void DbgPrint(void);
void printk(void);
void ExAcquireFastMutex(void);
void ExAcquireFastMutexUnsafe(void);
void ExAcquireResourceExclusive(void);
void ExAcquireResourceExclusiveLite(void);
void ExAcquireResourceSharedLite(void);
void ExAcquireSharedStarveExclusive(void);
void ExAcquireSharedWaitForExclusive(void);
void ExAllocateFromNPagedLookasideList(void);
void ExAllocateFromPagedLookasideList(void);
void ExAllocateFromZone(void);
void ExAllocatePool(void);
void ExAllocatePoolWithQuota(void);
void ExAllocatePoolWithQuotaTag(void);
void ExAllocatePoolWithTag(void);
void ExConvertExclusiveToSharedLite(void);
void ExDeleteNPagedLookasideList(void);
void ExDeletePagedLookasideList(void);
void ExDeleteResource(void);
void ExDeleteResourceLite(void);
void ExExtendZone(void);
void ExFreePool(void);
void ExFreeToNPagedLookasideList(void);
void ExFreeToPagedLookasideList(void);
void ExFreeToZone(void);
void ExGetCurrentResourceThread(void);
void ExGetExclusiveWaiterCount(void);
void ExGetSharedWaiterCount(void);
void ExHookException(void);
void ExInitializeFastMutex(void);
void ExInitializeNPagedLookasideList(void);
void ExInitializePagedLookasideList(void);
void ExInitializeResource(void);
void ExInitializeResourceLite(void);
void ExInitializeSListHead(void);
void ExInitializeWorkItem(void);
void ExInitializeZone(void);
void ExInterlockedAddLargeInteger(void);
void ExInterlockedAddUlong(void);
void ExInterlockedAllocateFromZone(void);
void ExInterlockedDecrementLong(void);
void ExInterlockedExchangeUlong(void);
void ExInterlockedExtendZone(void);
void ExInterlockedFreeToZone(void);
void ExInterlockedIncrementLong(void);
void ExInterlockedInsertHeadList(void);
void ExInterlockedInsertTailList(void);
void ExInterlockedPopEntryList(void);
void ExInterlockedPopEntrySList(void);
void ExInterlockedPushEntryList(void);
void ExInterlockedPushEntrySList(void);
void ExInterlockedRemoveHeadList(void);
void ExIsFullZone(void);
void ExIsObjectInFirstZoneSegment(void);
void ExIsResourceAcquiredExclusiveLite(void);
void ExIsResourceAcquiredSharedLite(void);
void ExLocalTimeToSystemTime(void);
void ExQueryDepthSListHead(void);
void ExQueueWorkItem(void);
void ExRaiseStatus(void);
void ExReinitializeResourceLite(void);
void ExReleaseFastMutex(void);
void ExReleaseFastMutexUnsafe(void);
void ExReleaseResource(void);
void ExReleaseResourceForThread(void);
void ExReleaseResourceForThreadLite(void);
void ExSystemTimeToLocalTime(void);
void ExTryToAcquireFastMutex(void);
void ExTryToAcquireResourceExclusiveLite(void);
void InterlockedCompareExchange(void);
void InterlockedExchange(void);
void InterlockedExchangeAdd(void);
void InterlockedIncrement(void);
void HalAllocateCommonBuffer(void);
void HalAssignSlotResources(void);
void HalExamineMBR(void);
void HalFreeCommonBuffer(void);
void HalGetAdapter(void);
void HalGetBusData(void);
void HalGetBusDataByOffset(void);
void HalGetDmaAlignmentRequirement(void);
void HalGetInterruptVector(void);
void HalQuerySystemInformation(void);
void HalReadDmaCounter(void);
void HalSetBusData(void);
void HalSetBusDataByOffset(void);
void HalTranslateBusAddress(void);
void IoAcquireCancelSpinLock(void);
void IoAllocateAdapterChannel(void);
void IoAllocateController(void);
void IoAllocateErrorLogEntry(void);
void IoAllocateIrp(void);
void IoAllocateMdl(void);
void IoAssignArcName(void);
void IoAssignResources(void);
void IoAttachDevice(void);
void IoAttachDeviceByPointer(void);
void IoAttachDeviceToDeviceStack(void);
void IoBuildAsynchronousFsdRequest(void);
void IoBuildDeviceIoControlRequest(void);
void IoBuildPartialMdl(void);
void IoBuildSynchronousFsdRequest(void);
void IoCallDriver(void);
void IoCancelIrp(void);
void IoCheckShareAccess(void);
void IoCompleteRequest(void);
void IoConnectInterrupt(void);
void IoCreateController(void);
void IoCreateDevice(void);
void IoCreateNotificationEvent(void);
void IoCreateSymbolicLink(void);
void IoCreateSynchronizationEvent(void);
void IoCreateUnprotectedSymbolicLink(void);
void IoDeassignArcName(void);
void IoDeleteController(void);
void IoDeleteDevice(void);
void IoDeleteSymbolicLink(void);
void IoDetachDevice(void);
void IoDisconnectInterrupt(void);
void IoFlushAdapterBuffers(void);
void IoFreeAdapterChannel(void);
void IoFreeController(void);
void IoFreeIrp(void);
void IoFreeMapRegisters(void);
void IoFreeMdl(void);
void IoGetConfigurationInformation(void);
void IoGetCurrentIrpStackLocation(void);
void IoGetCurrentProcess(void);
void IoGetDeviceObjectPointer(void);
void IoGetDeviceToVerify(void);
void IoGetFileObjectGenericMapping(void);
void IoGetFunctionCodeFromCtlCode(void);
void IoGetInitialStack(void);
void IoGetNextIrpStackLocation(void);
void IoGetRelatedDeviceObject(void);
void IoInitializeDpcRequest(void);
void IoInitializeIrp(void);
void IoInitializeTimer(void);
void IoIsErrorUserInduced(void);
void IoIsTotalDeviceFailure(void);
void IoMakeAssociatedIrp(void);
void IoMapTransfer(void);
void IoMarkIrpPending(void);
void IoQueryDeviceDescription(void);
void IoRaiseHardError(void);
void IoRaiseInformationalHardError(void);
void IoReadPartitionTable(void);
void IoRegisterDriverReinitialization(void);
void IoRegisterShutdownNotification(void);
void IoReleaseCancelSpinLock(void);
void IoRemoveShareAccess(void);
void IoReportResourceUsage(void);
void IoRequestDpc(void);
void IoSetCancelRoutine(void);
void IoSetCompletionRoutine(void);
void IoSetHardErrorOrVerifyDevice(void);
void IoSetNextIrpStackLocation(void);
void IoSetPartitionInformation(void);
void IoSetShareAccess(void);
void IoSizeOfIrp(void);
void IoStartNextPacket(void);
void IoStartNextPacketByKey(void);
void IoStartPacket(void);
void IoStartTimer(void);
void IoStopTimer(void);
void IoUnregisterShutdownNotification(void);
void IoUpdateShareAccess(void);
void IoWriteErrorLogEntry(void);
void IoWritePartitionTable(void);
void KeAcquireSpinLock(void);
void KeAcquireSpinLockAtDpcLevel(void);
void KeBugCheck(void);
void KeBugCheckEx(void);
void KeCancelTimer(void);
void KeClearEvent(void);
void KeDelayExecutionThread(void);
void KeDeregisterBugCheckCallback(void);
void KeEnterCriticalRegion(void);
void KeFlushIoBuffers(void);
void KeGetCurrentIrql(void);
void KeGetCurrentProcessorNumber(void);
void KeGetDcacheFillSize(void);
void KeInitializeCallbackRecord(void);
void KeInitializeDeviceQueue(void);
void KeInitializeDpc(void);
void KeInitializeEvent(void);
void KeInitializeMutex(void);
void KeInitializeSemaphore(void);
void KeInitializeSpinLock(void);
void KeInitializeTimer(void);
void KeInitializeTimerEx(void);
void KeInsertByKeyDeviceQueue(void);
void KeInsertDeviceQueue(void);
void KeInsertQueueDpc(void);
void KeLeaveCriticalRegion(void);
void KeLowerIrql(void);
void KeQueryPerformanceCounter(void);
void KeQuerySystemTime(void);
void KeQueryTickCount(void);
void KeQueryTimeIncrement(void);
void KeRaiseIrql(void);
void KeReadStateEvent(void);
void KeReadStateMutex(void);
void KeReadStateSemaphore(void);
void KeReadStateTimer(void);
void KeRegisterBugCheckCallback(void);
void KeReleaseMutex(void);
void KeReleaseSemaphore(void);
void KeReleaseSpinLock(void);
void KeReleaseSpinLockFromDpcLevel(void);
void KeRemoveByKeyDeviceQueue(void);
void KeRemoveDeviceQueue(void);
void KeRemoveQueueDpc(void);
void KeResetEvent(void);
void KeSetBasePriorityThread(void);
void KeSetEvent(void);
void KeSetPriorityThread(void);
void KeSetTimer(void);
void KeSetTimerEx(void);
void KeStallExecutionProcessor(void);
void KeSynchronizeExecution(void);
void KeWaitForMultipleObjects(void);
void KeWaitForMutexObject(void);
void KeWaitForSingleObject(void);
void MmAllocateContiguousMemory(void);
void MmAllocateNonCachedMemory(void);
void MmBuildMdlForNonPagedPool(void);
void MmCreateMdl(void);
void MmFreeContiguousMemory(void);
void MmFreeNonCachedMemory(void);
void MmGetMdlByteCount(void);
void MmGetMdlByteOffset(void);
void MmGetMdlVirtualAddress(void);
void MmGetPhysicalAddress(void);
void MmGetSystemAddressForMdl(void);
void MmInitializeMdl(void);
void MmIsAddressValid(void);
void MmIsNonPagedSystemAddressValid(void);
void MmIsThisAnNtAsSystem(void);
void MmLockPagableCodeSection(void);
void MmLockPagableDataSection(void);
void MmLockPagableSectionByHandle(void);
void MmMapIoSpace(void);
void MmMapLockedPages(void);
void MmPageEntireDriver(void);
void MmResetDriverPaging(void);
void MmPrepareMdlForReuse(void);
void MmProbeAndLockPages(void);
void MmQuerySystemSize(void);
void MmSizeOfMdl(void);
void MmUnlockPages(void);
void MmUnlockPagableImageSection(void);
void MmUnmapIoSpace(void);
void MmUnmapLockedPages(void);
void ObDereferenceObject(void);
void ObReferenceObjectByHandle(void);
void ObReferenceObjectByPointer(void);
void PsCreateSystemThread(void);
void PsGetCurrentProcess(void);
void PsGetCurrentThread(void);
void PsTerminateSystemThread(void);
void InitializeListHead(void);
void InitializeObjectAttributes(void);
void InsertHeadList(void);
void InsertTailList(void);
void PopEntryList(void);
void PushEntryList(void);
void RemoveEntryList(void);
void RemoveHeadList(void);
void RemoveTailList(void);
void RtlAnsiStringToUnicodeSize(void);
void RtlAnsiStringToUnicodeString(void);
void RtlAppendUnicodeStringToString(void);
void RtlAppendUnicodeToString(void);
void RtlCharToInteger(void);
void RtlCheckRegistryKey(void);
void RtlCompareMemory(void);
void RtlCompareString(void);
void RtlCompareUnicodeString(void);
void RtlConvertLongToLargeInteger(void);
void RtlConvertUlongToLargeInteger(void);
void RtlCopyBytes(void);
void RtlCopyMemory(void);
void RtlCopyString(void);
void RtlCopyUnicodeString(void);
void RtlCreateRegistryKey(void);
void RtlCreateSecurityDescriptor(void);
void RtlDeleteRegistryValue(void);
void RtlEnlargedIntegerMultiply(void);
void RtlEnlargedUnsignedDivide(void);
void RtlEnlargedUnsignedMultiply(void);
void RtlEqualString(void);
void RtlEqualUnicodeString(void);
void RtlExtendedIntegerMultiply(void);
void RtlExtendedLargeIntegerDivide(void);
void RtlExtendedMagicDivide(void);
void RtlFillMemory(void);
void RtlFreeAnsiString(void);
void RtlFreeUnicodeString(void);
void RtlInitAnsiString(void);
void RtlInitString(void);
void RtlInitUnicodeString(void);
void RtlIntegerToUnicodeString(void);
void RtlLargeIntegerAdd(void);
void RtlLargeIntegerAnd(void);
void RtlLargeIntegerArithmeticShift(void);
void RtlLargeIntegerDivide(void);
void RtlLargeIntegerEqualTo(void);
void RtlLargeIntegerEqualToZero(void);
void RtlLargeIntegerGreaterThan(void);
void RtlLargeIntegerGreaterThanOrEqualTo(void);
void RtlLargeIntegerGreaterThanOrEqualToZero(void);
void RtlLargeIntegerGreaterThanZero(void);
void RtlLargeIntegerLessThan(void);
void RtlLargeIntegerLessThanOrEqualTo(void);
void RtlLargeIntegerLessThanZero(void);
void RtlLargeIntegerNegate(void);
void RtlLargeIntegerNotEqualTo(void);
void RtlLargeIntegerShiftLeft(void);
void RtlLargeIntegerShiftRight(void);
void RtlLargeIntegerSubtract(void);
void RtlLengthSecurityDescriptor(void);
void RtlMoveMemory(void);
void RtlQueryRegistryValues(void);
void RtlRetrieveUlong(void);
void RtlRetrieveUshort(void);
void RtlSetDaclSecurityDescriptor(void);
void RtlStoreUlong(void);
void RtlStoreUshort(void);
void RtlTimeFieldsToTime(void);
void RtlTimeToTimeFields(void);
void RtlUnicodeStringToAnsiString(void);
void RtlUnicodeStringToInteger(void);
void RtlUpcaseUnicodeString(void);
void RtlUpperString(void);
void RtlValidSecurityDescriptor(void);
void RtlWriteRegistryValue(void);
void RtlZeroMemory(void);
void SeAccessCheck(void);
void SeAssignSecurity(void);
void SeDeassignSecurity(void);
void SeSinglePrivilegeCheck(void);
void ZwClose(void);
void ZwCreateDirectoryObject(void);
void ZwCreateFile(void);
void ZwCreateKey(void);
void ZwDeleteKey(void);
void ZwEnumerateKey(void);
void ZwEnumerateValueKey(void);
void ZwFlushKey(void);
void ZwMakeTemporaryObject(void);
void ZwMapViewOfSection(void);
void ZwOpenFile(void);
void ZwOpenKey(void);
void ZwOpenSection(void);
void ZwQueryInformationFile(void);
void ZwQueryKey(void);
void ZwQueryValueKey(void);
void ZwReadFile(void);
void ZwSetInformationFile(void);
void ZwSetInformationThread(void);
void ZwSetValueKey(void);
void ZwUnmapViewOfSection(void);
void ZwWriteFile(void);
void sprintf(void);
#ifdef __cplusplus
}
#endif
export symbol_table[]={
{"_DbgPrint",(unsigned int)DbgPrint},
{"_printk",(unsigned int)printk},
{"_ExAcquireFastMutex",(unsigned int)ExAcquireFastMutex},
{"_ExAcquireFastMutexUnsafe",(unsigned int)ExAcquireFastMutexUnsafe},
{"_ExAcquireResourceExclusive",(unsigned int)ExAcquireResourceExclusive},
{"_ExAcquireResourceExclusiveLite",(unsigned int)ExAcquireResourceExclusiveLite},
{"_ExAcquireResourceSharedLite",(unsigned int)ExAcquireResourceSharedLite},
{"_ExAcquireSharedStarveExclusive",(unsigned int)ExAcquireSharedStarveExclusive},
{"_ExAcquireSharedWaitForExclusive",(unsigned int)ExAcquireSharedWaitForExclusive},
{"_ExAllocateFromNPagedLookasideList",(unsigned int)ExAllocateFromNPagedLookasideList},
{"_ExAllocateFromPagedLookasideList",(unsigned int)ExAllocateFromPagedLookasideList},
{"_ExAllocateFromZone",(unsigned int)ExAllocateFromZone},
{"_ExAllocatePool",(unsigned int)ExAllocatePool},
{"_ExAllocatePoolWithQuota",(unsigned int)ExAllocatePoolWithQuota},
{"_ExAllocatePoolWithQuotaTag",(unsigned int)ExAllocatePoolWithQuotaTag},
{"_ExAllocatePoolWithTag",(unsigned int)ExAllocatePoolWithTag},
{"_ExConvertExclusiveToSharedLite",(unsigned int)ExConvertExclusiveToSharedLite},
{"_ExDeleteNPagedLookasideList",(unsigned int)ExDeleteNPagedLookasideList},
{"_ExDeletePagedLookasideList",(unsigned int)ExDeletePagedLookasideList},
{"_ExDeleteResource",(unsigned int)ExDeleteResource},
{"_ExDeleteResourceLite",(unsigned int)ExDeleteResourceLite},
{"_ExExtendZone",(unsigned int)ExExtendZone},
{"_ExFreePool",(unsigned int)ExFreePool},
{"_ExFreeToNPagedLookasideList",(unsigned int)ExFreeToNPagedLookasideList},
{"_ExFreeToPagedLookasideList",(unsigned int)ExFreeToPagedLookasideList},
{"_ExFreeToZone",(unsigned int)ExFreeToZone},
{"_ExGetCurrentResourceThread",(unsigned int)ExGetCurrentResourceThread},
{"_ExGetExclusiveWaiterCount",(unsigned int)ExGetExclusiveWaiterCount},
{"_ExGetSharedWaiterCount",(unsigned int)ExGetSharedWaiterCount},
{"_ExHookException",(unsigned int)ExHookException},
{"_ExInitializeFastMutex",(unsigned int)ExInitializeFastMutex},
{"_ExInitializeNPagedLookasideList",(unsigned int)ExInitializeNPagedLookasideList},
{"_ExInitializePagedLookasideList",(unsigned int)ExInitializePagedLookasideList},
{"_ExInitializeResource",(unsigned int)ExInitializeResource},
{"_ExInitializeResourceLite",(unsigned int)ExInitializeResourceLite},
{"_ExInitializeSListHead",(unsigned int)ExInitializeSListHead},
{"_ExInitializeWorkItem",(unsigned int)ExInitializeWorkItem},
{"_ExInitializeZone",(unsigned int)ExInitializeZone},
{"_ExInterlockedAddLargeInteger",(unsigned int)ExInterlockedAddLargeInteger},
{"_ExInterlockedAddUlong",(unsigned int)ExInterlockedAddUlong},
{"_ExInterlockedAllocateFromZone",(unsigned int)ExInterlockedAllocateFromZone},
{"_ExInterlockedDecrementLong",(unsigned int)ExInterlockedDecrementLong},
{"_ExInterlockedExchangeUlong",(unsigned int)ExInterlockedExchangeUlong},
{"_ExInterlockedExtendZone",(unsigned int)ExInterlockedExtendZone},
{"_ExInterlockedFreeToZone",(unsigned int)ExInterlockedFreeToZone},
{"_ExInterlockedIncrementLong",(unsigned int)ExInterlockedIncrementLong},
{"_ExInterlockedInsertHeadList",(unsigned int)ExInterlockedInsertHeadList},
{"_ExInterlockedInsertTailList",(unsigned int)ExInterlockedInsertTailList},
{"_ExInterlockedPopEntryList",(unsigned int)ExInterlockedPopEntryList},
{"_ExInterlockedPopEntrySList",(unsigned int)ExInterlockedPopEntrySList},
{"_ExInterlockedPushEntryList",(unsigned int)ExInterlockedPushEntryList},
{"_ExInterlockedPushEntrySList",(unsigned int)ExInterlockedPushEntrySList},
{"_ExInterlockedRemoveHeadList",(unsigned int)ExInterlockedRemoveHeadList},
{"_ExIsFullZone",(unsigned int)ExIsFullZone},
{"_ExIsObjectInFirstZoneSegment",(unsigned int)ExIsObjectInFirstZoneSegment},
{"_ExIsResourceAcquiredExclusiveLite",(unsigned int)ExIsResourceAcquiredExclusiveLite},
{"_ExIsResourceAcquiredSharedLite",(unsigned int)ExIsResourceAcquiredSharedLite},
{"_ExLocalTimeToSystemTime",(unsigned int)ExLocalTimeToSystemTime},
{"_ExQueryDepthSListHead",(unsigned int)ExQueryDepthSListHead},
{"_ExQueueWorkItem",(unsigned int)ExQueueWorkItem},
{"_ExRaiseStatus",(unsigned int)ExRaiseStatus},
{"_ExReinitializeResourceLite",(unsigned int)ExReinitializeResourceLite},
{"_ExReleaseFastMutex",(unsigned int)ExReleaseFastMutex},
{"_ExReleaseFastMutexUnsafe",(unsigned int)ExReleaseFastMutexUnsafe},
{"_ExReleaseResource",(unsigned int)ExReleaseResource},
{"_ExReleaseResourceForThread",(unsigned int)ExReleaseResourceForThread},
{"_ExReleaseResourceForThreadLite",(unsigned int)ExReleaseResourceForThreadLite},
{"_ExSystemTimeToLocalTime",(unsigned int)ExSystemTimeToLocalTime},
{"_ExTryToAcquireFastMutex",(unsigned int)ExTryToAcquireFastMutex},
{"_ExTryToAcquireResourceExclusiveLite",(unsigned int)ExTryToAcquireResourceExclusiveLite},
{"_InterlockedCompareExchange",(unsigned int)InterlockedCompareExchange},
{"_InterlockedExchange",(unsigned int)InterlockedExchange},
{"_InterlockedExchangeAdd",(unsigned int)InterlockedExchangeAdd},
{"_InterlockedIncrement",(unsigned int)InterlockedIncrement},
{"_HalAllocateCommonBuffer",(unsigned int)HalAllocateCommonBuffer},
{"_HalAssignSlotResources",(unsigned int)HalAssignSlotResources},
{"_HalExamineMBR",(unsigned int)HalExamineMBR},
{"_HalFreeCommonBuffer",(unsigned int)HalFreeCommonBuffer},
{"_HalGetAdapter",(unsigned int)HalGetAdapter},
{"_HalGetBusData",(unsigned int)HalGetBusData},
{"_HalGetBusDataByOffset",(unsigned int)HalGetBusDataByOffset},
{"_HalGetDmaAlignmentRequirement",(unsigned int)HalGetDmaAlignmentRequirement},
{"_HalGetInterruptVector",(unsigned int)HalGetInterruptVector},
{"_HalQuerySystemInformation",(unsigned int)HalQuerySystemInformation},
{"_HalReadDmaCounter",(unsigned int)HalReadDmaCounter},
{"_HalSetBusData",(unsigned int)HalSetBusData},
{"_HalSetBusDataByOffset",(unsigned int)HalSetBusDataByOffset},
{"_HalTranslateBusAddress",(unsigned int)HalTranslateBusAddress},
{"_IoAcquireCancelSpinLock",(unsigned int)IoAcquireCancelSpinLock},
{"_IoAllocateAdapterChannel",(unsigned int)IoAllocateAdapterChannel},
{"_IoAllocateController",(unsigned int)IoAllocateController},
{"_IoAllocateErrorLogEntry",(unsigned int)IoAllocateErrorLogEntry},
{"_IoAllocateIrp",(unsigned int)IoAllocateIrp},
{"_IoAllocateMdl",(unsigned int)IoAllocateMdl},
{"_IoAssignArcName",(unsigned int)IoAssignArcName},
{"_IoAssignResources",(unsigned int)IoAssignResources},
{"_IoAttachDevice",(unsigned int)IoAttachDevice},
{"_IoAttachDeviceByPointer",(unsigned int)IoAttachDeviceByPointer},
{"_IoAttachDeviceToDeviceStack",(unsigned int)IoAttachDeviceToDeviceStack},
{"_IoBuildAsynchronousFsdRequest",(unsigned int)IoBuildAsynchronousFsdRequest},
{"_IoBuildDeviceIoControlRequest",(unsigned int)IoBuildDeviceIoControlRequest},
{"_IoBuildPartialMdl",(unsigned int)IoBuildPartialMdl},
{"_IoBuildSynchronousFsdRequest",(unsigned int)IoBuildSynchronousFsdRequest},
{"_IoCallDriver",(unsigned int)IoCallDriver},
{"_IoCancelIrp",(unsigned int)IoCancelIrp},
{"_IoCheckShareAccess",(unsigned int)IoCheckShareAccess},
{"_IoCompleteRequest",(unsigned int)IoCompleteRequest},
{"_IoConnectInterrupt",(unsigned int)IoConnectInterrupt},
{"_IoCreateController",(unsigned int)IoCreateController},
{"_IoCreateDevice",(unsigned int)IoCreateDevice},
{"_IoCreateNotificationEvent",(unsigned int)IoCreateNotificationEvent},
{"_IoCreateSymbolicLink",(unsigned int)IoCreateSymbolicLink},
{"_IoCreateSynchronizationEvent",(unsigned int)IoCreateSynchronizationEvent},
{"_IoCreateUnprotectedSymbolicLink",(unsigned int)IoCreateUnprotectedSymbolicLink},
{"_IoDeassignArcName",(unsigned int)IoDeassignArcName},
{"_IoDeleteController",(unsigned int)IoDeleteController},
{"_IoDeleteDevice",(unsigned int)IoDeleteDevice},
{"_IoDeleteSymbolicLink",(unsigned int)IoDeleteSymbolicLink},
{"_IoDetachDevice",(unsigned int)IoDetachDevice},
{"_IoDisconnectInterrupt",(unsigned int)IoDisconnectInterrupt},
{"_IoFlushAdapterBuffers",(unsigned int)IoFlushAdapterBuffers},
{"_IoFreeAdapterChannel",(unsigned int)IoFreeAdapterChannel},
{"_IoFreeController",(unsigned int)IoFreeController},
{"_IoFreeIrp",(unsigned int)IoFreeIrp},
{"_IoFreeMapRegisters",(unsigned int)IoFreeMapRegisters},
{"_IoFreeMdl",(unsigned int)IoFreeMdl},
{"_IoGetConfigurationInformation",(unsigned int)IoGetConfigurationInformation},
{"_IoGetCurrentIrpStackLocation",(unsigned int)IoGetCurrentIrpStackLocation},
{"_IoGetCurrentProcess",(unsigned int)IoGetCurrentProcess},
{"_IoGetDeviceObjectPointer",(unsigned int)IoGetDeviceObjectPointer},
{"_IoGetDeviceToVerify",(unsigned int)IoGetDeviceToVerify},
{"_IoGetFileObjectGenericMapping",(unsigned int)IoGetFileObjectGenericMapping},
{"_IoGetFunctionCodeFromCtlCode",(unsigned int)IoGetFunctionCodeFromCtlCode},
{"_IoGetInitialStack",(unsigned int)IoGetInitialStack},
{"_IoGetNextIrpStackLocation",(unsigned int)IoGetNextIrpStackLocation},
{"_IoGetRelatedDeviceObject",(unsigned int)IoGetRelatedDeviceObject},
{"_IoInitializeDpcRequest",(unsigned int)IoInitializeDpcRequest},
{"_IoInitializeIrp",(unsigned int)IoInitializeIrp},
{"_IoInitializeTimer",(unsigned int)IoInitializeTimer},
{"_IoIsErrorUserInduced",(unsigned int)IoIsErrorUserInduced},
{"_IoIsTotalDeviceFailure",(unsigned int)IoIsTotalDeviceFailure},
{"_IoMakeAssociatedIrp",(unsigned int)IoMakeAssociatedIrp},
{"_IoMapTransfer",(unsigned int)IoMapTransfer},
{"_IoMarkIrpPending",(unsigned int)IoMarkIrpPending},
{"_IoQueryDeviceDescription",(unsigned int)IoQueryDeviceDescription},
{"_IoRaiseHardError",(unsigned int)IoRaiseHardError},
{"_IoRaiseInformationalHardError",(unsigned int)IoRaiseInformationalHardError},
{"_IoReadPartitionTable",(unsigned int)IoReadPartitionTable},
{"_IoRegisterDriverReinitialization",(unsigned int)IoRegisterDriverReinitialization},
{"_IoRegisterShutdownNotification",(unsigned int)IoRegisterShutdownNotification},
{"_IoReleaseCancelSpinLock",(unsigned int)IoReleaseCancelSpinLock},
{"_IoRemoveShareAccess",(unsigned int)IoRemoveShareAccess},
{"_IoReportResourceUsage",(unsigned int)IoReportResourceUsage},
{"_IoRequestDpc",(unsigned int)IoRequestDpc},
{"_IoSetCancelRoutine",(unsigned int)IoSetCancelRoutine},
{"_IoSetCompletionRoutine",(unsigned int)IoSetCompletionRoutine},
{"_IoSetHardErrorOrVerifyDevice",(unsigned int)IoSetHardErrorOrVerifyDevice},
{"_IoSetNextIrpStackLocation",(unsigned int)IoSetNextIrpStackLocation},
{"_IoSetPartitionInformation",(unsigned int)IoSetPartitionInformation},
{"_IoSetShareAccess",(unsigned int)IoSetShareAccess},
{"_IoSizeOfIrp",(unsigned int)IoSizeOfIrp},
{"_IoStartNextPacket",(unsigned int)IoStartNextPacket},
{"_IoStartNextPacketByKey",(unsigned int)IoStartNextPacketByKey},
{"_IoStartPacket",(unsigned int)IoStartPacket},
{"_IoStartTimer",(unsigned int)IoStartTimer},
{"_IoStopTimer",(unsigned int)IoStopTimer},
{"_IoUnregisterShutdownNotification",(unsigned int)IoUnregisterShutdownNotification},
{"_IoUpdateShareAccess",(unsigned int)IoUpdateShareAccess},
{"_IoWriteErrorLogEntry",(unsigned int)IoWriteErrorLogEntry},
{"_IoWritePartitionTable",(unsigned int)IoWritePartitionTable},
{"_KeAcquireSpinLock",(unsigned int)KeAcquireSpinLock},
{"_KeAcquireSpinLockAtDpcLevel",(unsigned int)KeAcquireSpinLockAtDpcLevel},
{"_KeBugCheck",(unsigned int)KeBugCheck},
{"_KeBugCheckEx",(unsigned int)KeBugCheckEx},
{"_KeCancelTimer",(unsigned int)KeCancelTimer},
{"_KeClearEvent",(unsigned int)KeClearEvent},
{"_KeDelayExecutionThread",(unsigned int)KeDelayExecutionThread},
{"_KeDeregisterBugCheckCallback",(unsigned int)KeDeregisterBugCheckCallback},
{"_KeEnterCriticalRegion",(unsigned int)KeEnterCriticalRegion},
{"_KeFlushIoBuffers",(unsigned int)KeFlushIoBuffers},
{"_KeGetCurrentIrql",(unsigned int)KeGetCurrentIrql},
{"_KeGetCurrentProcessorNumber",(unsigned int)KeGetCurrentProcessorNumber},
{"_KeGetDcacheFillSize",(unsigned int)KeGetDcacheFillSize},
{"_KeInitializeCallbackRecord",(unsigned int)KeInitializeCallbackRecord},
{"_KeInitializeDeviceQueue",(unsigned int)KeInitializeDeviceQueue},
{"_KeInitializeDpc",(unsigned int)KeInitializeDpc},
{"_KeInitializeEvent",(unsigned int)KeInitializeEvent},
{"_KeInitializeMutex",(unsigned int)KeInitializeMutex},
{"_KeInitializeSemaphore",(unsigned int)KeInitializeSemaphore},
{"_KeInitializeSpinLock",(unsigned int)KeInitializeSpinLock},
{"_KeInitializeTimer",(unsigned int)KeInitializeTimer},
{"_KeInitializeTimerEx",(unsigned int)KeInitializeTimerEx},
{"_KeInsertByKeyDeviceQueue",(unsigned int)KeInsertByKeyDeviceQueue},
{"_KeInsertDeviceQueue",(unsigned int)KeInsertDeviceQueue},
{"_KeInsertQueueDpc",(unsigned int)KeInsertQueueDpc},
{"_KeLeaveCriticalRegion",(unsigned int)KeLeaveCriticalRegion},
{"_KeLowerIrql",(unsigned int)KeLowerIrql},
{"_KeQueryPerformanceCounter",(unsigned int)KeQueryPerformanceCounter},
{"_KeQuerySystemTime",(unsigned int)KeQuerySystemTime},
{"_KeQueryTickCount",(unsigned int)KeQueryTickCount},
{"_KeQueryTimeIncrement",(unsigned int)KeQueryTimeIncrement},
{"_KeRaiseIrql",(unsigned int)KeRaiseIrql},
{"_KeReadStateEvent",(unsigned int)KeReadStateEvent},
{"_KeReadStateMutex",(unsigned int)KeReadStateMutex},
{"_KeReadStateSemaphore",(unsigned int)KeReadStateSemaphore},
{"_KeReadStateTimer",(unsigned int)KeReadStateTimer},
{"_KeRegisterBugCheckCallback",(unsigned int)KeRegisterBugCheckCallback},
{"_KeReleaseMutex",(unsigned int)KeReleaseMutex},
{"_KeReleaseSemaphore",(unsigned int)KeReleaseSemaphore},
{"_KeReleaseSpinLock",(unsigned int)KeReleaseSpinLock},
{"_KeReleaseSpinLockFromDpcLevel",(unsigned int)KeReleaseSpinLockFromDpcLevel},
{"_KeRemoveByKeyDeviceQueue",(unsigned int)KeRemoveByKeyDeviceQueue},
{"_KeRemoveDeviceQueue",(unsigned int)KeRemoveDeviceQueue},
{"_KeRemoveQueueDpc",(unsigned int)KeRemoveQueueDpc},
{"_KeResetEvent",(unsigned int)KeResetEvent},
{"_KeSetBasePriorityThread",(unsigned int)KeSetBasePriorityThread},
{"_KeSetEvent",(unsigned int)KeSetEvent},
{"_KeSetPriorityThread",(unsigned int)KeSetPriorityThread},
{"_KeSetTimer",(unsigned int)KeSetTimer},
{"_KeSetTimerEx",(unsigned int)KeSetTimerEx},
{"_KeStallExecutionProcessor",(unsigned int)KeStallExecutionProcessor},
{"_KeSynchronizeExecution",(unsigned int)KeSynchronizeExecution},
{"_KeWaitForMultipleObjects",(unsigned int)KeWaitForMultipleObjects},
{"_KeWaitForMutexObject",(unsigned int)KeWaitForMutexObject},
{"_KeWaitForSingleObject",(unsigned int)KeWaitForSingleObject},
{"_MmAllocateContiguousMemory",(unsigned int)MmAllocateContiguousMemory},
{"_MmAllocateNonCachedMemory",(unsigned int)MmAllocateNonCachedMemory},
{"_MmBuildMdlForNonPagedPool",(unsigned int)MmBuildMdlForNonPagedPool},
{"_MmCreateMdl",(unsigned int)MmCreateMdl},
{"_MmFreeContiguousMemory",(unsigned int)MmFreeContiguousMemory},
{"_MmFreeNonCachedMemory",(unsigned int)MmFreeNonCachedMemory},
{"_MmGetMdlByteCount",(unsigned int)MmGetMdlByteCount},
{"_MmGetMdlByteOffset",(unsigned int)MmGetMdlByteOffset},
{"_MmGetMdlVirtualAddress",(unsigned int)MmGetMdlVirtualAddress},
{"_MmGetPhysicalAddress",(unsigned int)MmGetPhysicalAddress},
{"_MmGetSystemAddressForMdl",(unsigned int)MmGetSystemAddressForMdl},
{"_MmInitializeMdl",(unsigned int)MmInitializeMdl},
{"_MmIsAddressValid",(unsigned int)MmIsAddressValid},
{"_MmIsNonPagedSystemAddressValid",(unsigned int)MmIsNonPagedSystemAddressValid},
{"_MmIsThisAnNtAsSystem",(unsigned int)MmIsThisAnNtAsSystem},
{"_MmLockPagableCodeSection",(unsigned int)MmLockPagableCodeSection},
{"_MmLockPagableDataSection",(unsigned int)MmLockPagableDataSection},
{"_MmLockPagableSectionByHandle",(unsigned int)MmLockPagableSectionByHandle},
{"_MmMapIoSpace",(unsigned int)MmMapIoSpace},
{"_MmMapLockedPages",(unsigned int)MmMapLockedPages},
{"_MmPageEntireDriver",(unsigned int)MmPageEntireDriver},
{"_MmResetDriverPaging",(unsigned int)MmResetDriverPaging},
{"_MmPrepareMdlForReuse",(unsigned int)MmPrepareMdlForReuse},
{"_MmProbeAndLockPages",(unsigned int)MmProbeAndLockPages},
{"_MmQuerySystemSize",(unsigned int)MmQuerySystemSize},
{"_MmSizeOfMdl",(unsigned int)MmSizeOfMdl},
{"_MmUnlockPages",(unsigned int)MmUnlockPages},
{"_MmUnlockPagableImageSection",(unsigned int)MmUnlockPagableImageSection},
{"_MmUnmapIoSpace",(unsigned int)MmUnmapIoSpace},
{"_MmUnmapLockedPages",(unsigned int)MmUnmapLockedPages},
{"_ObDereferenceObject",(unsigned int)ObDereferenceObject},
{"_ObReferenceObjectByHandle",(unsigned int)ObReferenceObjectByHandle},
{"_ObReferenceObjectByPointer",(unsigned int)ObReferenceObjectByPointer},
{"_PsCreateSystemThread",(unsigned int)PsCreateSystemThread},
{"_PsGetCurrentProcess",(unsigned int)PsGetCurrentProcess},
{"_PsGetCurrentThread",(unsigned int)PsGetCurrentThread},
{"_PsTerminateSystemThread",(unsigned int)PsTerminateSystemThread},
{"_InitializeListHead",(unsigned int)InitializeListHead},
{"_InitializeObjectAttributes",(unsigned int)InitializeObjectAttributes},
{"_InsertHeadList",(unsigned int)InsertHeadList},
{"_InsertTailList",(unsigned int)InsertTailList},
{"_PopEntryList",(unsigned int)PopEntryList},
{"_PushEntryList",(unsigned int)PushEntryList},
{"_RemoveEntryList",(unsigned int)RemoveEntryList},
{"_RemoveHeadList",(unsigned int)RemoveHeadList},
{"_RemoveTailList",(unsigned int)RemoveTailList},
{"_RtlAnsiStringToUnicodeSize",(unsigned int)RtlAnsiStringToUnicodeSize},
{"_RtlAnsiStringToUnicodeString",(unsigned int)RtlAnsiStringToUnicodeString},
{"_RtlAppendUnicodeStringToString",(unsigned int)RtlAppendUnicodeStringToString},
{"_RtlAppendUnicodeToString",(unsigned int)RtlAppendUnicodeToString},
{"_RtlCharToInteger",(unsigned int)RtlCharToInteger},
{"_RtlCheckRegistryKey",(unsigned int)RtlCheckRegistryKey},
{"_RtlCompareMemory",(unsigned int)RtlCompareMemory},
{"_RtlCompareString",(unsigned int)RtlCompareString},
{"_RtlCompareUnicodeString",(unsigned int)RtlCompareUnicodeString},
{"_RtlConvertLongToLargeInteger",(unsigned int)RtlConvertLongToLargeInteger},
{"_RtlConvertUlongToLargeInteger",(unsigned int)RtlConvertUlongToLargeInteger},
{"_RtlCopyBytes",(unsigned int)RtlCopyBytes},
{"_RtlCopyMemory",(unsigned int)RtlCopyMemory},
{"_RtlCopyString",(unsigned int)RtlCopyString},
{"_RtlCopyUnicodeString",(unsigned int)RtlCopyUnicodeString},
{"_RtlCreateRegistryKey",(unsigned int)RtlCreateRegistryKey},
{"_RtlCreateSecurityDescriptor",(unsigned int)RtlCreateSecurityDescriptor},
{"_RtlDeleteRegistryValue",(unsigned int)RtlDeleteRegistryValue},
{"_RtlEnlargedIntegerMultiply",(unsigned int)RtlEnlargedIntegerMultiply},
{"_RtlEnlargedUnsignedDivide",(unsigned int)RtlEnlargedUnsignedDivide},
{"_RtlEnlargedUnsignedMultiply",(unsigned int)RtlEnlargedUnsignedMultiply},
{"_RtlEqualString",(unsigned int)RtlEqualString},
{"_RtlEqualUnicodeString",(unsigned int)RtlEqualUnicodeString},
{"_RtlExtendedIntegerMultiply",(unsigned int)RtlExtendedIntegerMultiply},
{"_RtlExtendedLargeIntegerDivide",(unsigned int)RtlExtendedLargeIntegerDivide},
{"_RtlExtendedMagicDivide",(unsigned int)RtlExtendedMagicDivide},
{"_RtlFillMemory",(unsigned int)RtlFillMemory},
{"_RtlFreeAnsiString",(unsigned int)RtlFreeAnsiString},
{"_RtlFreeUnicodeString",(unsigned int)RtlFreeUnicodeString},
{"_RtlInitAnsiString",(unsigned int)RtlInitAnsiString},
{"_RtlInitString",(unsigned int)RtlInitString},
{"_RtlInitUnicodeString",(unsigned int)RtlInitUnicodeString},
{"_RtlIntegerToUnicodeString",(unsigned int)RtlIntegerToUnicodeString},
{"_RtlLargeIntegerAdd",(unsigned int)RtlLargeIntegerAdd},
{"_RtlLargeIntegerAnd",(unsigned int)RtlLargeIntegerAnd},
{"_RtlLargeIntegerArithmeticShift",(unsigned int)RtlLargeIntegerArithmeticShift},
{"_RtlLargeIntegerDivide",(unsigned int)RtlLargeIntegerDivide},
{"_RtlLargeIntegerEqualTo",(unsigned int)RtlLargeIntegerEqualTo},
{"_RtlLargeIntegerEqualToZero",(unsigned int)RtlLargeIntegerEqualToZero},
{"_RtlLargeIntegerGreaterThan",(unsigned int)RtlLargeIntegerGreaterThan},
{"_RtlLargeIntegerGreaterThanOrEqualTo",(unsigned int)RtlLargeIntegerGreaterThanOrEqualTo},
{"_RtlLargeIntegerGreaterThanOrEqualToZero",(unsigned int)RtlLargeIntegerGreaterThanOrEqualToZero},
{"_RtlLargeIntegerGreaterThanZero",(unsigned int)RtlLargeIntegerGreaterThanZero},
{"_RtlLargeIntegerLessThan",(unsigned int)RtlLargeIntegerLessThan},
{"_RtlLargeIntegerLessThanOrEqualTo",(unsigned int)RtlLargeIntegerLessThanOrEqualTo},
{"_RtlLargeIntegerLessThanZero",(unsigned int)RtlLargeIntegerLessThanZero},
{"_RtlLargeIntegerNegate",(unsigned int)RtlLargeIntegerNegate},
{"_RtlLargeIntegerNotEqualTo",(unsigned int)RtlLargeIntegerNotEqualTo},
{"_RtlLargeIntegerShiftLeft",(unsigned int)RtlLargeIntegerShiftLeft},
{"_RtlLargeIntegerShiftRight",(unsigned int)RtlLargeIntegerShiftRight},
{"_RtlLargeIntegerSubtract",(unsigned int)RtlLargeIntegerSubtract},
{"_RtlLengthSecurityDescriptor",(unsigned int)RtlLengthSecurityDescriptor},
{"_RtlMoveMemory",(unsigned int)RtlMoveMemory},
{"_RtlQueryRegistryValues",(unsigned int)RtlQueryRegistryValues},
{"_RtlRetrieveUlong",(unsigned int)RtlRetrieveUlong},
{"_RtlRetrieveUshort",(unsigned int)RtlRetrieveUshort},
{"_RtlSetDaclSecurityDescriptor",(unsigned int)RtlSetDaclSecurityDescriptor},
{"_RtlStoreUlong",(unsigned int)RtlStoreUlong},
{"_RtlStoreUshort",(unsigned int)RtlStoreUshort},
{"_RtlTimeFieldsToTime",(unsigned int)RtlTimeFieldsToTime},
{"_RtlTimeToTimeFields",(unsigned int)RtlTimeToTimeFields},
{"_RtlUnicodeStringToAnsiString",(unsigned int)RtlUnicodeStringToAnsiString},
{"_RtlUnicodeStringToInteger",(unsigned int)RtlUnicodeStringToInteger},
{"_RtlUpcaseUnicodeString",(unsigned int)RtlUpcaseUnicodeString},
{"_RtlUpperString",(unsigned int)RtlUpperString},
{"_RtlValidSecurityDescriptor",(unsigned int)RtlValidSecurityDescriptor},
{"_RtlWriteRegistryValue",(unsigned int)RtlWriteRegistryValue},
{"_RtlZeroMemory",(unsigned int)RtlZeroMemory},
{"_SeAccessCheck",(unsigned int)SeAccessCheck},
{"_SeAssignSecurity",(unsigned int)SeAssignSecurity},
{"_SeDeassignSecurity",(unsigned int)SeDeassignSecurity},
{"_SeSinglePrivilegeCheck",(unsigned int)SeSinglePrivilegeCheck},
{"_ZwClose",(unsigned int)ZwClose},
{"_ZwCreateDirectoryObject",(unsigned int)ZwCreateDirectoryObject},
{"_ZwCreateFile",(unsigned int)ZwCreateFile},
{"_ZwCreateKey",(unsigned int)ZwCreateKey},
{"_ZwDeleteKey",(unsigned int)ZwDeleteKey},
{"_ZwEnumerateKey",(unsigned int)ZwEnumerateKey},
{"_ZwEnumerateValueKey",(unsigned int)ZwEnumerateValueKey},
{"_ZwFlushKey",(unsigned int)ZwFlushKey},
{"_ZwMakeTemporaryObject",(unsigned int)ZwMakeTemporaryObject},
{"_ZwMapViewOfSection",(unsigned int)ZwMapViewOfSection},
{"_ZwOpenFile",(unsigned int)ZwOpenFile},
{"_ZwOpenKey",(unsigned int)ZwOpenKey},
{"_ZwOpenSection",(unsigned int)ZwOpenSection},
{"_ZwQueryInformationFile",(unsigned int)ZwQueryInformationFile},
{"_ZwQueryKey",(unsigned int)ZwQueryKey},
{"_ZwQueryValueKey",(unsigned int)ZwQueryValueKey},
{"_ZwReadFile",(unsigned int)ZwReadFile},
{"_ZwSetInformationFile",(unsigned int)ZwSetInformationFile},
{"_ZwSetInformationThread",(unsigned int)ZwSetInformationThread},
{"_ZwSetValueKey",(unsigned int)ZwSetValueKey},
{"_ZwUnmapViewOfSection",(unsigned int)ZwUnmapViewOfSection},
{"_ZwWriteFile",(unsigned int)ZwWriteFile},
{"_sprintf",(unsigned int)sprintf},
{NULL,NULL},
};

View file

@ -0,0 +1,180 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PURPOSE: ReactOS kernel
* FILE: ntoskrnl/ke/device.c
* PURPOSE: Implement device queues
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 08/07/98: Created
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID InsertBeforeEntryInList(PLIST_ENTRY Head, PLIST_ENTRY After,
PLIST_ENTRY Entry)
{
if (After->Blink!=NULL)
{
After->Blink->Flink = Entry;
}
else
{
Head->Flink = Entry;
}
Entry->Blink = After->Blink;
Entry->Flink = After;
After->Blink = Entry;
}
BOOLEAN KeInsertByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
ULONG SortKey)
{
KIRQL oldlvl;
PLIST_ENTRY current;
PKDEVICE_QUEUE_ENTRY entry;
DeviceQueueEntry->Key=SortKey;
KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
if (!DeviceQueue->Busy)
{
DeviceQueue->Busy=TRUE;
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(FALSE);
}
current=DeviceQueue->ListHead.Flink;
while (current!=NULL)
{
entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry);
if (entry->Key < SortKey)
{
InsertBeforeEntryInList(&DeviceQueue->ListHead,
&DeviceQueueEntry->Entry,current);
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(TRUE);
}
current = current->Flink;
}
InsertTailList(&DeviceQueue->ListHead,&DeviceQueueEntry->Entry);
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(TRUE);
}
PKDEVICE_QUEUE_ENTRY KeRemoveByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
ULONG SortKey)
{
KIRQL oldlvl;
PLIST_ENTRY current;
PKDEVICE_QUEUE_ENTRY entry;
assert_irql(DISPATCH_LEVEL);
assert(DeviceQueue!=NULL);
assert(DeviceQueue->Busy);
KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
if (IsListEmpty(&DeviceQueue->ListHead))
{
DeviceQueue->Busy=FALSE;
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(NULL);
}
current = DeviceQueue->ListHead.Flink;
for(;;)
{
entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry);
if (entry->Key < SortKey || current->Flink == NULL)
{
RemoveEntryFromList(&DeviceQueue->ListHead,current);
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(entry);
}
current = current->Flink;
}
}
PKDEVICE_QUEUE_ENTRY KeRemoveDeviceQueue(PKDEVICE_QUEUE DeviceQueue)
/*
* FUNCTION: Removes an entry from a device queue
* ARGUMENTS:
* DeviceQueue = Queue to remove the entry
* RETURNS: The removed entry
*/
{
KIRQL oldlvl;
PLIST_ENTRY list_entry;
PKDEVICE_QUEUE_ENTRY entry;
assert_irql(DISPATCH_LEVEL);
assert(DeviceQueue!=NULL);
assert(DeviceQueue->Busy);
KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
list_entry = RemoveHeadList(&DeviceQueue->ListHead);
if (list_entry==NULL)
{
DeviceQueue->Busy=FALSE;
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(NULL);
}
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
entry = CONTAINING_RECORD(list_entry,KDEVICE_QUEUE_ENTRY,Entry);
return(entry);
}
VOID KeInitializeDeviceQueue(PKDEVICE_QUEUE DeviceQueue)
/*
* FUNCTION: Intializes a device queue
* ARGUMENTS:
* DeviceQueue = Device queue to initialize
*/
{
assert(DeviceQueue!=NULL);
InitializeListHead(&DeviceQueue->ListHead);
DeviceQueue->Busy=FALSE;
KeInitializeSpinLock(&DeviceQueue->Lock);
}
BOOLEAN KeInsertDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
/*
* FUNCTION: Inserts an entry in a device queue
* ARGUMENTS:
* DeviceQueue = Queue to insert the entry in
* DeviceQueueEntry = Entry to insert
* RETURNS: False is the device queue wasn't busy
* True otherwise
*/
{
KIRQL oldlvl;
KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
if (!DeviceQueue->Busy)
{
DeviceQueue->Busy=TRUE;
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(FALSE);
}
InsertTailList(&DeviceQueue->ListHead,&DeviceQueueEntry->Entry);
DeviceQueueEntry->Key=0;
KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
return(TRUE);
}

175
reactos/ntoskrnl/ke/main.c Normal file
View file

@ -0,0 +1,175 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/main.c
* PURPOSE: Initalizes the kernel
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 28/05/98: Created
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <coff.h>
#include <internal/kernel.h>
#include <internal/version.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/symbol.h>
#include <internal/module.h>
#include <internal/hal/page.h>
#include <internal/hal/segment.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS ****************************************************************/
void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
unsigned int len)
/*
* FUNCTION: Sets a hardware breakpoint
* ARGUMENTS:
* i = breakpoint to set (0 to 3)
* addr = linear address to break on
* type = Type of access to break on
* len = length of the variable to watch
* NOTES:
* The variable to watch must be aligned to its length (i.e. a dword
* breakpoint must be aligned to a dword boundary)
*
* A fatal exception will be generated on the access to the variable.
* It is (at the moment) only really useful for catching undefined
* pointers if you know the variable effected but not the buggy
* routine.
*
* FIXME: Extend to call out to kernel debugger on breakpoint
* Add support for I/O breakpoints
* REFERENCES: See the i386 programmer manual for more details
*/
{
unsigned int mask;
if (i>3)
{
printk("Invalid breakpoint index at %s:%d\n",__FILE__,__LINE__);
return;
}
/*
* Load the linear address
*/
switch (i)
{
case 0:
__asm("movl %0,%%db0\n\t"
: /* no outputs */
: "d" (addr));
break;
case 1:
__asm__("movl %0,%%db1\n\t"
: /* no outputs */
: "d" (addr));
break;
case 2:
__asm__("movl %0,%%db2\n\t"
: /* no outputs */
: "d" (addr));
break;
case 3:
__asm__("movl %0,%%db3\n\t"
: /* no outputs */
: "d" (addr));
break;
}
/*
* Setup mask for dr7
*/
mask = (len<<(16 + 2 + i*4)) + (type<<(16 + i*4)) + (1<<(i*2));
__asm__("movl %%db7,%%eax\n\t"
"orl %0,%%eax\n\t"
"movl %%eax,%%db7\n\t"
: /* no outputs */
: "d" (mask)
: "ax");
}
asmlinkage void _main(boot_param* _bp)
/*
* FUNCTION: Called by the boot loader to start the kernel
* ARGUMENTS:
* _bp = Pointer to boot parameters initialized by the boot loader
* NOTE: The boot parameters are stored in low memory which will become
* invalid after the memory managment is initialized so we make a local copy.
*/
{
unsigned int i;
unsigned int start;
/*
* Copy the parameters to a local buffer because lowmem will go away
*/
boot_param bp;
memcpy(&bp,_bp,sizeof(bp));
/*
* Initalize the console (before printing anything)
*/
InitConsole(&bp);
printk("Starting ReactOS "KERNEL_VERSION"\n");
/*
* Initalize various critical subsystems
*/
HalInit(&bp);
MmInitalize(&bp);
KeInitDpc();
KeInitializeBugCheck();
KeInitializeDispatcher();
InitializeTimer();
/*
* Allow interrupts
*/
KeLowerIrql(PASSIVE_LEVEL);
KeCalibrateTimerLoop();
ObjNamespcInit();
PsMgrInit();
IoInit();
/*
* Initalize loaded modules
*/
DPRINT("%d files loaded\n",bp.nr_files);
start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]) +
PAGESIZE;
for (i=1;i<bp.nr_files;i++)
{
DPRINT("start %x length %d\n",start,bp.module_length[i]);
process_boot_module(start);
start=start+PAGE_ROUND_UP(bp.module_length[i])+PAGESIZE;
}
/*
* Enter shell
*/
TstBegin();
/*
* Enter idle loop
*/
printk("Finished main()\n");
for (;;);
}

View file

@ -0,0 +1,361 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/module.c
* PURPOSE: Loading kernel components
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 28/05/98: Created
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <coff.h>
#include <ddk/ntddk.h>
#include <internal/iomgr.h>
#include <internal/kernel.h>
#include <internal/symbol.h>
#include <internal/string.h>
#include <internal/mm.h>
#include <internal/module.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS **************************************************************/
static unsigned int get_kernel_symbol_addr(char* name)
/*
* FUNCTION: Get the address of a kernel symbol
* ARGUMENTS:
* name = symbol name
* RETURNS: The address of the symbol on success
* NULL on failure
*/
{
int i=0;
while (symbol_table[i].name!=NULL)
{
if (strcmp(symbol_table[i].name,name)==0)
{
return(symbol_table[i].value);
}
i++;
}
return(0);
}
static void get_symbol_name(module* mod, unsigned int i, char* name)
/*
* FUNCTION: Get the name of a symbol from a loaded module by ordinal
* ARGUMENTS:
* mod = module
* i = index of symbol
* name (OUT) = pointer to a string where the symbol name will be
* stored
*/
{
if (mod->sym_list[i].e.e_name[0]!=0)
{
strncpy(name,mod->sym_list[i].e.e_name,8);
}
else
{
strcpy(name,&mod->str_tab[mod->sym_list[i].e.e.e_offset]);
}
}
static unsigned int get_symbol_value(module* mod, unsigned int i)
/*
* FUNCTION: Get the value of a module defined symbol
* ARGUMENTS:
* mod = module
* i = index of symbol
* RETURNS: The value of the symbol
* NOTE: This fixes up references to known sections
*/
{
char name[255];
get_symbol_name(mod,i,name);
// DPRINT("name %s ",name);
/*
* Check if the symbol is a section we have relocated
*/
if (strcmp(name,".text")==0)
{
return(mod->text_base);
}
if (strcmp(name,".data")==0)
{
return(mod->data_base);
}
if (strcmp(name,".bss")==0)
{
return(mod->bss_base);
}
return(mod->sym_list[i].e_value);
}
static int do_reloc32_reloc(module* mod, SCNHDR* scn, RELOC* reloc)
/*
* FUNCTION: Performs a reloc32 relocation on a loaded module
* ARGUMENTS:
* mod = module to perform the relocation on
* scn = Section to perform the relocation in
* reloc = Pointer to a data structure describing the relocation
* RETURNS: Success or failure
* NOTE: This fixes up an undefined reference to a kernel function in a module
*/
{
char name[255];
unsigned int val;
unsigned int * loc;
memset(name,0,255);
get_symbol_name(mod,reloc->r_symndx,name);
val = get_kernel_symbol_addr(name);
if (val==0)
{
printk("Undefined symbol %s in module\n",name);
return(0);
}
// DPRINT("REL32 value %x name %s\n",val,name);
// printk("value %x\n",val);
loc=(unsigned int *)(mod->base+reloc->r_vaddr);
// printk("old %x ",*loc);
(*loc) = (*loc) + val - mod->base + scn->s_vaddr;
// printk("new %x\n",*loc);
return(1);
}
static int do_addr32_reloc(module* mod, SCNHDR* scn, RELOC* reloc)
/*
* FUNCTION: Performs a addr32 relocation on a loaded module
* ARGUMENTS:
* mod = module to perform the relocation on
* scn = Section to perform the relocation in
* reloc = Pointer to a data structure describing the relocation
* RETURNS: Success or failure
* NOTE: This fixes up a relocation needed when changing the base address of a
* module
*/
{
unsigned int value;
unsigned int * loc;
// printk("ADDR32 ");
value=get_symbol_value(mod,reloc->r_symndx);
// printk("value %x\n",value);
loc=(unsigned int *)(mod->base+reloc->r_vaddr);
// DPRINT("ADDR32 loc %x value %x *loc %x ",loc,value,*loc);
*loc=(*loc)+mod->base;
// *loc = value;
// *loc=(*loc)+value
// DPRINT("*loc %x\n",*loc);
return(1);
}
static BOOLEAN do_reloc(module* mod, unsigned int scn_idx)
/*
* FUNCTION: Do the relocations for a module section
* ARGUMENTS:
* mod = Pointer to the module
* scn_idx = Index of the section to be relocated
* RETURNS: Success or failure
*/
{
SCNHDR* scn = &mod->scn_list[scn_idx];
RELOC* reloc = (RELOC *)(mod->raw_data_off + scn->s_relptr);
int j;
DPRINT("scn_idx %d name %.8s relocs %d\n",scn_idx,
mod->scn_list[scn_idx].s_name,scn->s_nreloc);
for (j=0;j<scn->s_nreloc;j++)
{
// printk("vaddr %x ",reloc->r_vaddr);
// printk("symndex %x ",reloc->r_symndx);
switch(reloc->r_type)
{
case RELOC_ADDR32:
if (!do_addr32_reloc(mod,scn,reloc))
{
return(0);
}
break;
case RELOC_REL32:
if (!do_reloc32_reloc(mod,scn,reloc))
{
return(0);
}
break;
default:
printk("Unknown relocation type %x at %d in module\n",
reloc->r_type,j);
return(0);
}
reloc = (RELOC *)(((unsigned int)reloc) + sizeof(RELOC));
}
DPRINT("Done relocations for %.8s\n",mod->scn_list[scn_idx].s_name);
return(1);
}
BOOLEAN process_boot_module(unsigned int start)
/*
* FUNCTION: Processes and initializes a module whose disk image has been
* loaded
* ARGUMENTS:
* start = start of the module in memory
* RETURNS: Success or failure
*/
{
FILHDR hdr;
AOUTHDR ohdr;
module* mod;
unsigned int entry=0;
unsigned int found_entry=0;
PDRIVER_INITIALIZE func;
int i;
DPRINT("n = %x\n",*((unsigned int *)start));
mod=(module *)ExAllocatePool(NonPagedPool,sizeof(module));
DPRINT("magic %x\n",((FILHDR *)start)->f_magic);
memcpy(&hdr,(void *)start,FILHSZ);
if (I386BADMAG(hdr))
{
printk("(%s:%d) Module has bad magic value (%x)\n",__FILE__,
__LINE__,hdr.f_magic);
return(0);
}
memcpy(&ohdr,(void *)(start+FILHSZ),AOUTSZ);
mod->sym_list = (SYMENT *)(start + hdr.f_symptr);
mod->str_tab = (char *)(start + hdr.f_symptr +
hdr.f_nsyms * SYMESZ);
mod->scn_list = (SCNHDR *)(start+FILHSZ+hdr.f_opthdr);
mod->size=0;
mod->raw_data_off = start;
/*
* Determine the length of the module
*/
for (i=0;i<hdr.f_nscns;i++)
{
DPRINT("Section name: %.8s\n",mod->scn_list[i].s_name);
DPRINT("size %x vaddr %x size %x\n",mod->size,
mod->scn_list[i].s_vaddr,mod->scn_list[i].s_size);
if (mod->scn_list[i].s_flags & STYP_TEXT)
{
mod->text_base=mod->scn_list[i].s_vaddr;
}
if (mod->scn_list[i].s_flags & STYP_DATA)
{
mod->data_base=mod->scn_list[i].s_vaddr;
}
if (mod->scn_list[i].s_flags & STYP_BSS)
{
mod->bss_base=mod->scn_list[i].s_vaddr;
}
if (mod->size <
(mod->scn_list[i].s_vaddr + mod->scn_list[i].s_size))
{
mod->size = mod->size + mod->scn_list[i].s_vaddr +
mod->scn_list[i].s_size;
}
}
mod->base = (unsigned int)VirtualAlloc((LPVOID)0,mod->size,MEM_COMMIT,
PAGE_SYSTEM + PAGE_EXECUTE_READWRITE);
if (mod->base == 0)
{
printk("Failed to allocated section for module\n");
return(0);
}
/*
* Adjust section vaddrs for allocated area
*/
mod->data_base=mod->data_base+mod->base;
mod->text_base=mod->text_base+mod->base;
mod->bss_base=mod->bss_base+mod->base;
/*
* Relocate module and fixup imports
*/
for (i=0;i<hdr.f_nscns;i++)
{
if (mod->scn_list[i].s_flags & STYP_TEXT ||
mod->scn_list[i].s_flags & STYP_DATA)
{
memcpy((void *)(mod->base + mod->scn_list[i].s_vaddr),
(void *)(start + mod->scn_list[i].s_scnptr),
mod->scn_list[i].s_size);
if (!do_reloc(mod,i))
{
DPRINT("Relocation failed for section %s\n",
mod->scn_list[i].s_name);
return(0);
}
}
if (mod->scn_list[i].s_flags & STYP_BSS)
{
memset((void *)(mod->base + mod->scn_list[i].s_vaddr),0,
mod->scn_list[i].s_size);
}
}
DPRINT("Allocate base: %x\n",mod->base);
/*
* Find the entry point
*/
for (i=0;i<hdr.f_nsyms;i++)
{
char name[255];
get_symbol_name(mod,i,name);
if (strcmp(name,"_DriverEntry")==0)
{
entry = mod->sym_list[i].e_value;
found_entry=1;
DPRINT("Found entry at %x\n",entry);
}
}
if (!found_entry)
{
printk("No module entry point defined\n");
return(0);
}
/*
* Call the module initalization routine
*/
func = (PDRIVER_INITIALIZE)(mod->base + entry);
return(InitalizeLoadedDriver(func));
}

View file

@ -0,0 +1,49 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/mutex.c
* PURPOSE: Implements mutex
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID KeInitializeMutex(PKMUTEX Mutex, ULONG Level)
{
Mutex->Header.Type=2;
Mutex->Header.SignalState=TRUE;
Mutex->Header.Size = 8;
Mutex->OwnerThread = NULL;
Mutex->ApcDisable = 0;
InitializeListHead(&Mutex->Header.WaitListHead);
}
LONG KeReadStateMutex(PKMUTEX Mutex)
{
return(Mutex->Header.SignalState);
}
LONG KeReleaseMutex(PKMUTEX Mutex, BOOLEAN Wait)
{
UNIMPLEMENTED;
}
NTSTATUS KeWaitForMutexObject(PKMUTEX Mutex,
KWAIT_REASON WaitReason,
KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Timeout)
{
return(KeWaitForSingleObject(Mutex,WaitReason,WaitMode,Alertable,Timeout));
}

40
reactos/ntoskrnl/ke/sem.c Normal file
View file

@ -0,0 +1,40 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/sem.c
* PURPOSE: Implements kernel semaphores
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID KeInitializeSemaphore(PKSEMAPHORE Semaphore,
LONG Count,
LONG Limit)
{
UNIMPLEMENTED;
}
LONG KeReadStateSemaphore(PKSEMAPHORE Semaphore)
{
UNIMPLEMENTED;
}
LONG KeReleaseSemaphore(PKSEMAPHORE Semaphore,
KPRIORITY Increment,
LONG Adjustment,
BOOLEAN Wait)
{
UNIMPLEMENTED;
}

407
reactos/ntoskrnl/ke/timer.c Normal file
View file

@ -0,0 +1,407 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/timer.c
* PURPOSE: Handle timers
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 28/05/98: Created
*/
/* NOTES ******************************************************************/
/*
* System time units are 100-nanosecond intervals
*/
/* INCLUDES ***************************************************************/
#include <limits.h>
#include <internal/stddef.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/hal/page.h>
#include <internal/string.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* TYPES *****************************************************************/
#define TIMER_IRQ 0
/* GLOBALS ****************************************************************/
/*
* Current time
*/
static unsigned long long system_time = 0;
/*
* Number of timer interrupts since initialisation
*/
static volatile unsigned long long ticks=0;
/*
* The increment in the system clock every timer tick (in system time units)
*
* = (1/18.2)*10^9
*
*/
#define CLOCK_INCREMENT (54945055)
/*
* PURPOSE: List of timers
*/
static LIST_ENTRY timer_list_head = {NULL,NULL};
static KSPIN_LOCK timer_list_lock;
#define MICROSECONDS_TO_CALIBRATE (1000000)
#define MICROSECONDS_PER_TICK (54945)
#define MICROSECONDS_IN_A_SECOND (10000000)
#define TICKS_PER_SECOND_APPROX (18)
static unsigned int loops_per_microsecond = 17;
/* FUNCTIONS **************************************************************/
void KeCalibrateTimerLoop()
{
unsigned int start_tick;
unsigned int end_tick;
unsigned int nr_ticks;
unsigned int i;
return;
for (i=0;i<5;i++)
{
start_tick = ticks;
while (start_tick==ticks);
KeStallExecutionProcessor(MICROSECONDS_TO_CALIBRATE);
end_tick = ticks;
while (end_tick==ticks);
nr_ticks = end_tick - start_tick;
loops_per_microsecond = (loops_per_microsecond * MICROSECONDS_TO_CALIBRATE)
/ (nr_ticks*MICROSECONDS_PER_TICK);
printk("nr_ticks %d\n",nr_ticks);
printk("loops_per_microsecond %d\n",loops_per_microsecond);
printk("Processor speed (approx) %d\n",
(6*loops_per_microsecond)/1000);
if (nr_ticks == (TICKS_PER_SECOND_APPROX * MICROSECONDS_TO_CALIBRATE)
/ MICROSECONDS_IN_A_SECOND)
{
printk("Testing loop\n");
KeStallExecutionProcessor(10000);
printk("Finished loop\n");
return;
}
}
}
NTSTATUS KeDelayExecutionThread(KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Interval)
{
UNIMPLEMENTED;
}
VOID KeStallExecutionProcessor(ULONG MicroSeconds)
{
unsigned int i;
for (i=0; i<(loops_per_microsecond*MicroSeconds) ;i++)
{
__asm__("nop\n\t");
}
}
static inline void ULLToLargeInteger(unsigned long long src,
PLARGE_INTEGER dest)
{
dest->LowPart = src & 0xffffffff;
dest->HighPart = (src>>32);
}
static inline void SLLToLargeInteger(signed long long src,
PLARGE_INTEGER dest)
{
if (src > 0)
{
dest->LowPart = src & 0xffffffff;
dest->HighPart = (src>>32);
}
else
{
src = -src;
dest->LowPart = src & 0xffffffff;
dest->HighPart = -(src>>32);
}
}
static inline signed long long LargeIntegerToSLL(PLARGE_INTEGER src)
{
signed long long r;
r = src->LowPart;
if (src->HighPart >= 0)
{
r = r | (((unsigned long long)src->HighPart)<<32);
}
else
{
r = r | (((unsigned long long)(-(src->HighPart)))<<32);
r = -r;
}
return(r);
}
LARGE_INTEGER KeQueryPerformanceCounter(PLARGE_INTEGER PerformanceFreq)
/*
* FUNCTION: Queries the finest grained running count avaiable in the system
* ARGUMENTS:
* PerformanceFreq (OUT) = The routine stores the number of
* performance counters tick per second here
* RETURNS: The performance counter value in HERTZ
* NOTE: Returns the system tick count or the time-stamp on the pentium
*/
{
PerformanceFreq->HighPart=0;
PerformanceFreq->LowPart=0;
}
ULONG KeQueryTimeIncrement(VOID)
/*
* FUNCTION: Gets the increment (in 100-nanosecond units) that is added to
* the system clock every time the clock interrupts
* RETURNS: The increment
*/
{
return(CLOCK_INCREMENT);
}
VOID KeQuerySystemTime(PLARGE_INTEGER CurrentTime)
/*
* FUNCTION: Gets the current system time
* ARGUMENTS:
* CurrentTime (OUT) = The routine stores the current time here
* NOTE: The time is the number of 100-nanosecond intervals since the
* 1st of January, 1601.
*/
{
ULLToLargeInteger(system_time,CurrentTime);
}
BOOLEAN KeSetTimer(PKTIMER Timer, LARGE_INTEGER DueTime, PKDPC Dpc)
/*
* FUNCTION: Sets the absolute or relative interval at which a timer object
* is to be set to the signaled state and optionally supplies a
* CustomTimerDpc to be executed when the timer expires.
* ARGUMENTS:
* Timer = Points to a previously initialized timer object
* DueTimer = If positive then absolute time to expire at
* If negative then the relative time to expire at
* Dpc = If non-NULL then a dpc to be called when the timer expires
* RETURNS: True if the timer was already in the system timer queue
* False otherwise
*/
{
return(KeSetTimerEx(Timer,DueTime,0,Dpc));
}
BOOLEAN KeSetTimerEx(PKTIMER Timer, LARGE_INTEGER DueTime, LONG Period,
PKDPC Dpc)
/*
* FUNCTION: Sets the absolute or relative interval at which a timer object
* is to be set to the signaled state and optionally supplies a
* CustomTimerDpc to be executed when the timer expires.
* ARGUMENTS:
* Timer = Points to a previously initialized timer object
* DueTimer = If positive then absolute time to expire at
* If negative then the relative time to expire at
* Dpc = If non-NULL then a dpc to be called when the timer expires
* RETURNS: True if the timer was already in the system timer queue
* False otherwise
*/
{
KIRQL oldlvl;
KeAcquireSpinLock(&timer_list_lock,&oldlvl);
Timer->dpc=Dpc;
Timer->period=Period;
Timer->expire_time = LargeIntegerToSLL(&DueTime);
if (Timer->expire_time < 0)
{
Timer->expire_time = system_time - Timer->expire_time;
Timer->signaled = FALSE;
}
if (Timer->running)
{
KeReleaseSpinLock(&timer_list_lock,oldlvl);
return(TRUE);
}
InsertTailList(&timer_list_head,&Timer->entry);
KeReleaseSpinLock(&timer_list_lock,oldlvl);
return(FALSE);
}
BOOLEAN KeCancelTimer(PKTIMER Timer)
/*
* FUNCTION: Removes a timer from the system timer list
* ARGUMENTS:
* Timer = timer to cancel
* RETURNS: True if the timer was running
* False otherwise
*/
{
KIRQL oldlvl;
KeAcquireSpinLock(&timer_list_lock,&oldlvl);
if (!Timer->running)
{
return(FALSE);
}
RemoveEntryFromList(&timer_list_head,&Timer->entry);
KeReleaseSpinLock(&timer_list_lock,oldlvl);
return(TRUE);
}
BOOLEAN KeReadStateTimer(PKTIMER Timer)
{
return(Timer->signaled);
}
VOID KeInitializeTimer(PKTIMER Timer)
/*
* FUNCTION: Initalizes a kernel timer object
* ARGUMENTS:
* Timer = caller supplied storage for the timer
* NOTE: This function initializes a notification timer
*/
{
KeInitializeTimerEx(Timer,NotificationTimer);
}
VOID KeInitializeTimerEx(PKTIMER Timer, TIMER_TYPE Type)
/*
* FUNCTION: Initializes a kernel timer object
* ARGUMENTS:
* Timer = caller supplied storage for the timer
* Type = the type of timer (notification or synchronization)
* NOTE: When a notification type expires all waiting threads are released
* and the timer remains signalled until it is explicitly reset. When a
* syncrhonization timer expires its state is set to signalled until a
* single waiting thread is released and then the timer is reset.
*/
{
Timer->running=FALSE;
Timer->type=Type;
Timer->signaled=FALSE;
}
VOID KeQueryTickCount(PLARGE_INTEGER TickCount)
/*
* FUNCTION: Returns the number of ticks since the system was booted
* ARGUMENTS:
* TickCount (OUT) = Points to storage for the number of ticks
*/
{
ULLToLargeInteger(ticks,TickCount);
}
static void HandleExpiredTimer(PKTIMER current)
{
if (current->dpc!=NULL)
{
current->dpc->DeferredRoutine(current->dpc,
current->dpc->DeferredContext,
current->dpc->SystemArgument1,
current->dpc->SystemArgument2);
}
current->signaled=TRUE;
if (current->period !=0)
{
current->expire_time = current->expire_time + current->period;
}
else
{
RemoveEntryFromList(&timer_list_head,&current->entry);
current->running=FALSE;
}
}
void KeExpireTimers(void)
{
PLIST_ENTRY current_entry = timer_list_head.Flink;
PKTIMER current = CONTAINING_RECORD(current_entry,KTIMER,entry);
KIRQL oldlvl;
KeAcquireSpinLock(&timer_list_lock,&oldlvl);
while (current_entry!=NULL)
{
if (system_time == current->expire_time)
{
HandleExpiredTimer(current);
}
current_entry = current_entry->Flink;
current = CONTAINING_RECORD(current_entry,KTIMER,entry);
}
KeReleaseSpinLock(&timer_list_lock,oldlvl);
}
VOID KeTimerInterrupt(VOID)
/*
* FUNCTION: Handles a timer interrupt
*/
{
char str[16];
char* vidmem=(char *)physical_to_linear(0xb8000 + 160 - 16);
int i;
/*
* Increment the number of timers ticks
*/
ticks++;
system_time = system_time + CLOCK_INCREMENT;
/*
* Display the tick count in the top left of the screen as a debugging
* aid
*/
sprintf(str,"%.8u",ticks);
for (i=0;i<8;i++)
{
*vidmem=str[i];
vidmem++;
*vidmem=0x7;
vidmem++;
}
return(TRUE);
}
void InitializeTimer(void)
/*
* FUNCTION: Initializes timer irq handling
* NOTE: This is only called once from main()
*/
{
InitializeListHead(&timer_list_head);
KeInitializeSpinLock(&timer_list_lock);
/*
* Calculate the starting time for the system clock
*/
}

View file

@ -0,0 +1,82 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS project
* FILE: ntoskrnl/ps/wait.c
* PURPOSE: Manages non-busy waiting
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 21/07/98: Created
*/
/* NOTES ********************************************************************
*
*/
/* INCLUDES ******************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/wait.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ******************************************************************/
KSPIN_LOCK DispatcherDatabaseLock;
BOOLEAN WaitSet;
/* FUNCTIONS *****************************************************************/
VOID KeDispatcherObjectWake(DISPATCHER_HEADER* hdr)
{
PKWAIT_BLOCK current;
PLIST_ENTRY current_entry;
DPRINT("Entering KeDispatcherObjectWake(hdr %x)\n",hdr);
DPRINT("hdr->WaitListHead %x hdr->WaitListHead.Flink %x\n",
&hdr->WaitListHead,hdr->WaitListHead.Flink);
while ((current_entry=RemoveHeadList(&hdr->WaitListHead))!=NULL)
{
current = CONTAINING_RECORD(current_entry,KWAIT_BLOCK,
WaitListEntry);
DPRINT("Waking %x\n",current->Thread);
PsWakeThread(current->Thread);
};
}
NTSTATUS KeWaitForSingleObject(PVOID Object,
KWAIT_REASON WaitReason,
KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Timeout)
{
DISPATCHER_HEADER* hdr = (DISPATCHER_HEADER *)Object;
KWAIT_BLOCK blk;
DPRINT("Entering KeWaitForSingleObject(Object %x)\n",Object);
blk.Object=Object;
blk.Thread=KeGetCurrentThread();
InsertTailList(&hdr->WaitListHead,&blk.WaitListEntry);
PsSuspendThread();
}
NTSTATUS KeWaitForMultipleObjects(ULONG Count,
PVOID Object[],
WAIT_TYPE WaitType,
KWAIT_REASON WaitReason,
KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Timeout,
PKWAIT_BLOCK WaitBlockArray)
{
UNIMPLEMENTED;
}
VOID KeInitializeDispatcher(VOID)
{
KeInitializeSpinLock(&DispatcherDatabaseLock);
}

View file

@ -0,0 +1,281 @@
/*
* COPYRIGHT: See copying in the top level directory
* PROJECT: ReactOS kernel
* FILE: include/pe.h
* PURPOSE: Contains portable executable format definitions
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 26/05/98: Created
*/
/* NOTES
*
* This is taken from the Tool Interface Standard (TIS) Formats Specification
* for Windows
*/
#ifndef __PE_H
#define __PE_H
/*
* CPU types
*/
enum
{
CPU_UNKNOWN,
CPU_I386 = 0x14c,
CPU_I486 = 0x14d,
CPU_PENTIUM = 0x14e,
CPU_MIPS_I = 0x162,
CPU_MIPS_II = 0x163,
CPU_MIPS_III = 0x166,
};
/*
* Image flags
*/
enum
{
IMG_PROGRAM = 0,
IMG_EXECUTABLE = 0,
IMG_FIXED = 0x200,
IMG_LIBRARY = 0x2000,
};
/*
* Subsystems
*/
enum
{
SUBSYS_UNKNOWN,
SUBSYS_NATIVE,
SUBSYS_WINDOWS_GUI,
SUBSYS_WINDOWS_CHARACTER,
SUBSYS_OS2_CHARACTER,
SUBSYS_POSIX_CHARACTER,
};
enum
{
DLL_PERPROCESS_LIB_INITIALIZATION,
DLL_PERPROCESS_LIB_TERMINATION,
DLL_PERTHREAD_LIB_INITIALIZATION,
DLL_PERTHREAD_LIB_TERMINATION,
};
enum
{
OBJ_CODE = 0x20,
OBJ_INITIALIZED_DATA = 0x40,
OBJ_UNINITIALIZED_DATA = 0x80,
OBJ_NOCACHE = 0x40000000,
OBJ_NONPAGEABLE = 0x80000000,
OBJ_SHARED = 0x10000000,
OBJ_EXECUTABLE = 0x20000000,
OBJ_READABLE = 0x40000000,
OBJ_WRITEABLE = 0x80000000
};
typedef struct
{
/*
* PURPOSE: Signature, current value is 'PE'
*/
unsigned char signature[4];
/*
* PURPOSE: CPU required for the image to run
*/
unsigned short int cpu;
/*
* PURPOSE: Number of entries in the object table
*/
unsigned short int nr_objects;
/*
* PURPOSE: Time and date when image was created
*/
unsigned long int time_date_stamp;
unsigned short int reserved1;
unsigned short int reserved2;
/*
* PURPOSE: Number of bytes in the header following the flags field
*/
unsigned short int nt_hdr_size;
/*
* PURPOSE: Image flags
*/
unsigned short int flags;
unsigned char reserved3;
/*
* PURPOSE: Major/minor version number of the linker
*/
unsigned char linker_major_ver;
unsigned char linker_minor_ver;
unsigned char reserved4;
unsigned long int reserved5;
unsigned long int reserved6;
/*
* PURPOSE: Entry point relative to the image base
*/
unsigned long int entry;
unsigned long int reserved7;
unsigned long int reserved8;
/*
* PURPOSE: Virtual base of image. This will be the virtual address of
* the first byte of file. It must be a multiple of 64k
*/
unsigned long int image_base;
/*
* PURPOSE: Object alignment factor
*/
unsigned long int object_align;
/*
* PURPOSE: Alignment factor used to align image pages
*/
unsigned long int file_align;
/*
* PURPOSE: OS version required to run this image
*/
unsigned short int os_version;
/*
* PURPOSE: User specified version number
*/
unsigned short int user_version;
/*
* PURPOSE: Subsystem version required
*/
unsigned short int subsys_version;
unsigned long int reserved9;
/*
* PURPOSE: Size of the image in bytes (including all headers)
*/
unsigned long int image_size;
/*
* PURPOSE: Header size (Total of DOS header, PE header and object table)
*/
unsigned long int hdr_size;
/*
* PURPOSE: Checksum for entire file
*/
unsigned long int checksum;
/*
* PURPOSE: Subsystem required to run this image
*/
unsigned short int subsystem;
/*
* PURPOSE: Special loader requirements
*/
unsigned short int dll_flags;
/*
* PURPOSE: Stack size needed for image
*/
unsigned long int stack_reserve_size;
/*
* PURPOSE: Stack size to be committed
*/
unsigned long int stack_commit_size;
/*
* PURPOSE: Size of local heap to reserve
*/
unsigned long int heap_reserve_size;
/*
* PURPOSE: Size of local heap to commit
*/
unsigned long int heap_commit_size;
unsigned long int reserved10;
/*
* PURPOSE: Size of the array that follows
*/
unsigned long int nr_rvas;
unsigned long int export_table_rva;
unsigned long int export_table_size;
unsigned long int import_table_rva;
unsigned long int import_table_size;
unsigned long int resource_tlb_rva;
unsigned long int resource_tlb_size;
unsigned long int exception_table_rva;
unsigned long int exception_table_size;
unsigned long int security_table_rva;
unsigned long int security_table_size;
unsigned long int fixup_table_rva;
unsigned long int fixup_table_size;
unsigned long int debug_table_rva;
unsigned long int debug_table_size;
unsigned long int image_description_rva;
unsigned long int image_description_size;
unsigned long int mach_specific_rva;
unsigned long int mach_specific_size;
unsigned long int tls_rva;
unsigned long int tls_size;
} PE_header;
typedef struct
/*
* PURPOSE: Defines an entry in the image object table
*/
{
/*
* PURPOSE: Name of object
*/
unsigned char name[8];
/*
* PURPOSE: Size to allocate in memory
*/
unsigned long int virtual_size;
/*
* PURPOSE: Base address of object relative to the image base
*/
unsigned long int rva;
/*
* PURPOSE: Size of initialized data
*/
unsigned long int physical_size;
/*
* PURPOSE: Offset relative to the beginning of the image of the
* data for the object
*/
unsigned long int physical_offset;
unsigned long int reserved[3];
/*
* PURPOSE: Object flags
*/
unsigned long int object_flags;
} PE_ObjectTableEntry;
#endif /* __PE_H */

646
reactos/ntoskrnl/ldr/pe.h Normal file
View file

@ -0,0 +1,646 @@
typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
WORD e_cp; // Pages in file
WORD e_crlc; // Relocations
WORD e_cparhdr; // Size of header in paragraphs
WORD e_minalloc; // Minimum extra paragraphs needed
WORD e_maxalloc; // Maximum extra paragraphs needed
WORD e_ss; // Initial (relative) SS value
WORD e_sp; // Initial SP value
WORD e_csum; // Checksum
WORD e_ip; // Initial IP value
WORD e_cs; // Initial (relative) CS value
WORD e_lfarlc; // File address of relocation table
WORD e_ovno; // Overlay number
WORD e_res[4]; // Reserved words
WORD e_oemid; // OEM identifier (for e_oeminfo)
WORD e_oeminfo; // OEM information; e_oemid specific
WORD e_res2[10]; // Reserved words
LONG e_lfanew; // File address of new exe header
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
typedef struct _IMAGE_FILE_HEADER {
WORD Machine;
WORD NumberOfSections;
DWORD TimeDateStamp;
DWORD PointerToSymbolTable;
DWORD NumberOfSymbols;
WORD SizeOfOptionalHeader;
WORD Characteristics;
} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
#define IMAGE_SIZEOF_FILE_HEADER 20
#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file.
#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file.
#define IMAGE_FILE_SYSTEM 0x1000 // System File.
#define IMAGE_FILE_DLL 0x2000 // File is a DLL.
#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine
#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
#define IMAGE_FILE_MACHINE_UNKNOWN 0
#define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
#define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0x160 big-endian
#define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian
#define IMAGE_FILE_MACHINE_R10000 0x168 // MIPS little-endian
#define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP
#define IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM PowerPC Little-Endian
//
// Directory format.
//
typedef struct _IMAGE_DATA_DIRECTORY {
DWORD VirtualAddress;
DWORD Size;
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
//
// Optional header format.
//
typedef struct _IMAGE_OPTIONAL_HEADER {
//
// Standard fields.
//
WORD Magic;
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint;
DWORD BaseOfCode;
DWORD BaseOfData;
//
// NT additional fields.
//
DWORD ImageBase;
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
typedef struct _IMAGE_NT_HEADERS {
DWORD Signature;
IMAGE_FILE_HEADER FileHeader;
IMAGE_OPTIONAL_HEADER OptionalHeader;
} IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
// Directory Entries
#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP)
#define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers
#define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table
//
// Section header format.
//
#define IMAGE_SIZEOF_SHORT_NAME 8
typedef struct _IMAGE_SECTION_HEADER {
BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
union {
DWORD PhysicalAddress;
DWORD VirtualSize;
} Misc;
DWORD VirtualAddress;
DWORD SizeOfRawData;
DWORD PointerToRawData;
DWORD PointerToRelocations;
DWORD PointerToLinenumbers;
WORD NumberOfRelocations;
WORD NumberOfLinenumbers;
DWORD Characteristics;
} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
#define IMAGE_SIZEOF_SECTION_HEADER 40
//
// Export Format
//
typedef struct _IMAGE_EXPORT_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
DWORD Name;
DWORD Base;
DWORD NumberOfFunctions;
DWORD NumberOfNames;
PDWORD *AddressOfFunctions;
PDWORD *AddressOfNames;
PWORD *AddressOfNameOrdinals;
} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
//
// Import Format
//
typedef struct _IMAGE_IMPORT_BY_NAME {
WORD Hint;
BYTE Name[1];
} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
#define IMAGE_ORDINAL_FLAG 0x80000000
#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
//
// Resource Format.
//
//
// Resource directory consists of two counts, following by a variable length
// array of directory entries. The first count is the number of entries at
// beginning of the array that have actual names associated with each entry.
// The entries are in ascending order, case insensitive strings. The second
// count is the number of entries that immediately follow the named entries.
// This second count identifies the number of entries that have 16-bit integer
// Ids as their name. These entries are also sorted in ascending order.
//
// This structure allows fast lookup by either name or number, but for any
// given resource entry only one form of lookup is supported, not both.
// This is consistant with the syntax of the .RC file and the .RES file.
//
// Predefined resource types ... there may be some more, but I don't have
// the information yet. .....sang cho.....
#define RT_NEWRESOURCE 0x2000
#define RT_ERROR 0x7fff
#define RT_CURSOR 1
#define RT_BITMAP 2
#define RT_ICON 3
#define RT_MENU 4
#define RT_DIALOG 5
#define RT_STRING 6
#define RT_FONTDIR 7
#define RT_FONT 8
#define RT_ACCELERATORS 9
#define RT_RCDATA 10
#define RT_MESSAGETABLE 11
#define RT_GROUP_CURSOR 12
#define RT_GROUP_ICON 14
#define RT_VERSION 16
#define NEWBITMAP (RT_BITMAP|RT_NEWRESOURCE)
#define NEWMENU (RT_MENU|RT_NEWRESOURCE)
#define NEWDIALOG (RT_DIALOG|RT_NEWRESOURCE)
typedef struct _IMAGE_RESOURCE_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
WORD NumberOfNamedEntries;
WORD NumberOfIdEntries;
// IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[1];
} IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
#define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
#define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
//
// Each directory contains the 32-bit Name of the entry and an offset,
// relative to the beginning of the resource directory of the data associated
// with this directory entry. If the name of the entry is an actual text
// string instead of an integer Id, then the high order bit of the name field
// is set to one and the low order 31-bits are an offset, relative to the
// beginning of the resource directory of the string, which is of type
// IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
// low-order 16-bits are the integer Id that identify this resource directory
// entry. If the directory entry is yet another resource directory (i.e. a
// subdirectory), then the high order bit of the offset field will be
// set to indicate this. Otherwise the high bit is clear and the offset
// field points to a resource data entry.
//
typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
DWORD Name;
DWORD OffsetToData;
} IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
//
// For resource directory entries that have actual string names, the Name
// field of the directory entry points to an object of the following type.
// All of these string objects are stored together after the last resource
// directory entry and before the first resource data object. This minimizes
// the impact of these variable length objects on the alignment of the fixed
// size directory entry objects.
//
typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
WORD Length;
CHAR NameString[ 1 ];
} IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
WORD Length;
WCHAR NameString[ 1 ];
} IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
//
// Each resource data entry describes a leaf node in the resource directory
// tree. It contains an offset, relative to the beginning of the resource
// directory of the data for the resource, a size field that gives the number
// of bytes of data at that offset, a CodePage that should be used when
// decoding code point values within the resource data. Typically for new
// applications the code page would be the unicode code page.
//
typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
DWORD OffsetToData;
DWORD Size;
DWORD CodePage;
DWORD Reserved;
} IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
// Menu Resources ... added by .....sang cho....
// Menu resources are composed of a menu header followed by a sequential list
// of menu items. There are two types of menu items: pop-ups and normal menu
// itmes. The MENUITEM SEPARATOR is a special case of a normal menu item with
// an empty name, zero ID, and zero flags.
typedef struct _IMAGE_MENU_HEADER{
WORD wVersion; // Currently zero
WORD cbHeaderSize; // Also zero
} IMAGE_MENU_HEADER, *PIMAGE_MENU_HEADER;
typedef struct _IMAGE_POPUP_MENU_ITEM{
WORD fItemFlags;
WCHAR szItemText[1];
} IMAGE_POPUP_MENU_ITEM, *PIMAGE_POPUP_MENU_ITEM;
typedef struct _IMAGE_NORMAL_MENU_ITEM{
WORD fItemFlags;
WORD wMenuID;
WCHAR szItemText[1];
} IMAGE_NORMAL_MENU_ITEM, *PIMAGE_NORMAL_MENU_ITEM;
#define GRAYED 0x0001 // GRAYED keyword
#define INACTIVE 0x0002 // INACTIVE keyword
#define BITMAP 0x0004 // BITMAP keyword
#define OWNERDRAW 0x0100 // OWNERDRAW keyword
#define CHECKED 0x0008 // CHECKED keyword
#define POPUP 0x0010 // used internally
#define MENUBARBREAK 0x0020 // MENUBARBREAK keyword
#define MENUBREAK 0x0040 // MENUBREAK keyword
#define ENDMENU 0x0080 // used internally
// Dialog Box Resources .................. added by sang cho.
// A dialog box is contained in a single resource and has a header and
// a portion repeated for each control in the dialog box.
// The item DWORD IStyle is a standard window style composed of flags found
// in WINDOWS.H.
// The default style for a dialog box is:
// WS_POPUP | WS_BORDER | WS_SYSMENU
//
// The itme marked "Name or Ordinal" are :
// If the first word is an 0xffff, the next two bytes contain an ordinal ID.
// Otherwise, the first one or more WORDS contain a double-null-terminated string.
// An empty string is represented by a single WORD zero in the first location.
//
// The WORD wPointSize and WCHAR szFontName entries are present if the FONT
// statement was included for the dialog box. This can be detected by checking
// the entry IStyle. If IStyle & DS_SETFONT ( which is 0x40), then these
// entries will be present.
typedef struct _IMAGE_DIALOG_BOX_HEADER1{
DWORD IStyle;
DWORD IExtendedStyle; // New for Windows NT
WORD nControls; // Number of Controls
WORD x;
WORD y;
WORD cx;
WORD cy;
// N_OR_O MenuName; // Name or Ordinal ID
// N_OR_O ClassName; // Name or Ordinal ID
// WCHAR szCaption[];
// WORD wPointSize; // Only here if FONT set for dialog
// WCHAR szFontName[]; // This too
} IMAGE_DIALOG_HEADER, *PIMAGE_DIALOG_HEADER;
typedef union _NAME_OR_ORDINAL{ // Name or Ordinal ID
struct _ORD_ID{
WORD flgId;
WORD Id;
} ORD_ID;
WCHAR szName[1];
} NAME_OR_ORDINAL, *PNAME_OR_ORDINAL;
// The data for each control starts on a DWORD boundary (which may require
// some padding from the previous control), and its format is as follows:
typedef struct _IMAGE_CONTROL_DATA{
DWORD IStyle;
DWORD IExtendedStyle;
WORD x;
WORD y;
WORD cx;
WORD cy;
WORD wId;
// N_OR_O ClassId;
// N_OR_O Text;
// WORD nExtraStuff;
} IMAGE_CONTROL_DATA, *PIMAGE_CONTROL_DATA;
#define BUTTON 0x80
#define EDIT 0x81
#define STATIC 0x82
#define LISTBOX 0x83
#define SCROLLBAR 0x84
#define COMBOBOX 0x85
// The various statements used in a dialog script are all mapped to these
// classes along with certain modifying styles. The values for these styles
// can be found in WINDOWS.H. All dialog controls have the default styles
// of WS_CHILD and WS_VISIBLE. A list of the default styles used follows:
//
// Statement Default Class Default Styles
// CONTROL None WS_CHILD|WS_VISIBLE
// LTEXT STATIC ES_LEFT
// RTEXT STATIC ES_RIGHT
// CTEXT STATIC ES_CENTER
// LISTBOX LISTBOX WS_BORDER|LBS_NOTIFY
// CHECKBOX BUTTON BS_CHECKBOX|WS_TABSTOP
// PUSHBUTTON BUTTON BS_PUSHBUTTON|WS_TABSTOP
// GROUPBOX BUTTON BS_GROUPBOX
// DEFPUSHBUTTON BUTTON BS_DFPUSHBUTTON|WS_TABSTOP
// RADIOBUTTON BUTTON BS_RADIOBUTTON
// AUTOCHECKBOX BUTTON BS_AUTOCHECKBOX
// AUTO3STATE BUTTON BS_AUTO3STATE
// AUTORADIOBUTTON BUTTON BS_AUTORADIOBUTTON
// PUSHBOX BUTTON BS_PUSHBOX
// STATE3 BUTTON BS_3STATE
// EDITTEXT EDIT ES_LEFT|WS_BORDER|WS_TABSTOP
// COMBOBOX COMBOBOX None
// ICON STATIC SS_ICON
// SCROLLBAR SCROLLBAR None
///
#define WS_OVERLAPPED 0x00000000L
#define WS_POPUP 0x80000000L
#define WS_CHILD 0x40000000L
#define WS_CLIPSIBLINGS 0x04000000L
#define WS_CLIPCHILDREN 0x02000000L
#define WS_VISIBLE 0x10000000L
#define WS_DISABLED 0x08000000L
#define WS_MINIMIZE 0x20000000L
#define WS_MAXIMIZE 0x01000000L
#define WS_CAPTION 0x00C00000L
#define WS_BORDER 0x00800000L
#define WS_DLGFRAME 0x00400000L
#define WS_VSCROLL 0x00200000L
#define WS_HSCROLL 0x00100000L
#define WS_SYSMENU 0x00080000L
#define WS_THICKFRAME 0x00040000L
#define WS_MINIMIZEBOX 0x00020000L
#define WS_MAXIMIZEBOX 0x00010000L
#define WS_GROUP 0x00020000L
#define WS_TABSTOP 0x00010000L
// other aliases
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
#define WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU)
#define WS_CHILDWINDOW (WS_CHILD)
#define WS_TILED WS_OVERLAPPED
#define WS_ICONIC WS_MINIMIZE
#define WS_SIZEBOX WS_THICKFRAME
#define WS_TILEDWINDOW WS_OVERLAPPEDWINDOW
#define WS_EX_DLGMODALFRAME 0x00000001L
#define WS_EX_NOPARENTNOTIFY 0x00000004L
#define WS_EX_TOPMOST 0x00000008L
#define WS_EX_ACCEPTFILES 0x00000010L
#define WS_EX_TRANSPARENT 0x00000020L
#define BS_PUSHBUTTON 0x00000000L
#define BS_DEFPUSHBUTTON 0x00000001L
#define BS_CHECKBOX 0x00000002L
#define BS_AUTOCHECKBOX 0x00000003L
#define BS_RADIOBUTTON 0x00000004L
#define BS_3STATE 0x00000005L
#define BS_AUTO3STATE 0x00000006L
#define BS_GROUPBOX 0x00000007L
#define BS_USERBUTTON 0x00000008L
#define BS_AUTORADIOBUTTON 0x00000009L
#define BS_OWNERDRAW 0x0000000BL
#define BS_LEFTTEXT 0x00000020L
#define ES_LEFT 0x00000000L
#define ES_CENTER 0x00000001L
#define ES_RIGHT 0x00000002L
#define ES_MULTILINE 0x00000004L
#define ES_UPPERCASE 0x00000008L
#define ES_LOWERCASE 0x00000010L
#define ES_PASSWORD 0x00000020L
#define ES_AUTOVSCROLL 0x00000040L
#define ES_AUTOHSCROLL 0x00000080L
#define ES_NOHIDESEL 0x00000100L
#define ES_OEMCONVERT 0x00000400L
#define ES_READONLY 0x00000800L
#define ES_WANTRETURN 0x00001000L
#define LBS_NOTIFY 0x0001L
#define LBS_SORT 0x0002L
#define LBS_NOREDRAW 0x0004L
#define LBS_MULTIPLESEL 0x0008L
#define LBS_OWNERDRAWFIXED 0x0010L
#define LBS_OWNERDRAWVARIABLE 0x0020L
#define LBS_HASSTRINGS 0x0040L
#define LBS_USETABSTOPS 0x0080L
#define LBS_NOINTEGRALHEIGHT 0x0100L
#define LBS_MULTICOLUMN 0x0200L
#define LBS_WANTKEYBOARDINPUT 0x0400L
#define LBS_EXTENDEDSEL 0x0800L
#define LBS_DISABLENOSCROLL 0x1000L
#define SS_LEFT 0x00000000L
#define SS_CENTER 0x00000001L
#define SS_RIGHT 0x00000002L
#define SS_ICON 0x00000003L
#define SS_BLACKRECT 0x00000004L
#define SS_GRAYRECT 0x00000005L
#define SS_WHITERECT 0x00000006L
#define SS_BLACKFRAME 0x00000007L
#define SS_GRAYFRAME 0x00000008L
#define SS_WHITEFRAME 0x00000009L
#define SS_SIMPLE 0x0000000BL
#define SS_LEFTNOWORDWRAP 0x0000000CL
#define SS_BITMAP 0x0000000EL
//
// Debug Format
//
typedef struct _IMAGE_DEBUG_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
DWORD Type;
DWORD SizeOfData;
DWORD AddressOfRawData;
DWORD PointerToRawData;
} IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
#define IMAGE_DEBUG_TYPE_UNKNOWN 0
#define IMAGE_DEBUG_TYPE_COFF 1
#define IMAGE_DEBUG_TYPE_CODEVIEW 2
#define IMAGE_DEBUG_TYPE_FPO 3
#define IMAGE_DEBUG_TYPE_MISC 4
#define IMAGE_DEBUG_TYPE_EXCEPTION 5
#define IMAGE_DEBUG_TYPE_FIXUP 6
#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
typedef struct _IMAGE_DEBUG_MISC {
DWORD DataType; // type of misc data, see defines
DWORD Length; // total length of record, rounded to four
// byte multiple.
BOOLEAN Unicode; // TRUE if data is unicode string
BYTE Reserved[ 3 ];
BYTE Data[ 1 ]; // Actual data
} IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
//
// Debugging information can be stripped from an image file and placed
// in a separate .DBG file, whose file name part is the same as the
// image file name part (e.g. symbols for CMD.EXE could be stripped
// and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
// flag in the Characteristics field of the file header. The beginning of
// the .DBG file contains the following structure which captures certain
// information from the image file. This allows a debug to proceed even if
// the original image file is not accessable. This header is followed by
// zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
// IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
// the image file contain file offsets relative to the beginning of the
// .DBG file.
//
// If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
// is left in the image file, but not mapped. This allows a debugger to
// compute the name of the .DBG file, from the name of the image in the
// IMAGE_DEBUG_MISC structure.
//
typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
WORD Signature;
WORD Flags;
WORD Machine;
WORD Characteristics;
DWORD TimeDateStamp;
DWORD CheckSum;
DWORD ImageBase;
DWORD SizeOfImage;
DWORD NumberOfSections;
DWORD ExportedNamesSize;
DWORD DebugDirectorySize;
DWORD SectionAlignment;
DWORD Reserved[2];
} IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
#define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
#define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
#define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 // when DBG was updated, the
// old checksum didn't match.
//
// End Image Format
//
#define SIZE_OF_NT_SIGNATURE sizeof (DWORD)
#define MAXRESOURCENAME 13
/* global macros to define header offsets into file */
/* offset to PE file signature */
#define NTSIGNATURE(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew))
/* DOS header identifies the NT PEFile signature dword
the PEFILE header exists just after that dword */
#define PEFHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE))
/* PE optional header is immediately after PEFile header */
#define OPTHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE + \
sizeof (IMAGE_FILE_HEADER)))
/* section headers are immediately after PE optional header */
#define SECHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE + \
sizeof (IMAGE_FILE_HEADER) + \
sizeof (IMAGE_OPTIONAL_HEADER)))
typedef struct tagImportDirectory
{
DWORD dwRVAFunctionNameList;
DWORD dwUseless1;
DWORD dwUseless2;
DWORD dwRVAModuleName;
DWORD dwRVAFunctionAddressList;
}IMAGE_IMPORT_MODULE_DIRECTORY, * PIMAGE_IMPORT_MODULE_DIRECTORY;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,59 @@
all: kimage
#
# Defines $(HAL_OBJECTS)
#
include hal/x86/sources
RTL_OBJECTS = rtl/vsprintf.o rtl/lookas.o rtl/unicode.o rtl/strtok.o \
rtl/time.o rtl/unalign.o rtl/mem.o rtl/largeint.o rtl/ctype.o \
rtl/list.o rtl/slist.o rtl/interlck.o
KE_OBJECTS = ke/main.o ke/timer.o ke/error.o ke/catch.o ke/exports.o \
ke/module.o ke/dpc.o ke/wait.o ke/kqueue.o ke/dispatch.o \
ke/sem.o ke/critical.o ke/event.o ke/apc.o ke/bug.o \
ke/mutex.o
MM_OBJECTS = mm/mm.o mm/freelist.o mm/pool.o mm/pageflt.o mm/virtual.o \
mm/mdl.o mm/zone.o mm/cont.o mm/ncache.o mm/iospace.o \
mm/section.o
IO_OBJECTS = io/iomgr.o io/create.o io/irp.o io/device.o io/rw.o \
io/queue.o io/drvlck.o io/timer.o io/share.o io/errlog.o \
io/shutdown.o io/fdisk.o io/cancel.o io/error.o io/arc.o \
io/dpc.o io/symlink.o io/adapter.o io/cntrller.o io/mdl.o \
io/resource.o io/event.o io/process.o io/file.o io/ioctrl.o
OB_OBJECTS = ob/object.o ob/handle.o ob/namespc.o
PS_OBJECTS = ps/psmgr.o ps/thread.o ps/process.o
EX_OBJECTS = ex/work.o ex/fmutex.o ex/resource.o ex/time.o ex/interlck.o
SE_OBJECTS = se/semgr.o
CFG_OBJECTS = cfg/registry.o
TST_OBJECTS = tst/test.o
OBJECTS = $(HAL_OBJECTS) $(KE_OBJECTS) $(RTL_OBJECTS) $(MM_OBJECTS) \
$(IO_OBJECTS) $(OB_OBJECTS) $(PS_OBJECTS) $(EX_OBJECTS) \
$(SE_OBJECTS) $(CFG_OBJECTS) $(TST_OBJECTS)
utils/export/export$(EXE_POSTFIX): utils/export/export.c
$(NATIVE_CC) -g utils/export/export.c -o utils/export/export$(EXE_POSTFIX)
ke/exports.o: exports.lst utils/export/export$(EXE_POSTFIX)
utils/export/export$(EXE_POSTFIX) < exports.lst > ke/exports.c
$(CC) $(CFLAGS) -c ke/exports.c -o ke/exports.o
kimage: $(OBJECTS)
$(LD) --defsym _end=end --defsym _etext=etext --oformat=$(KERNEL_BFD_TARGET) -Ttext c0000000 $(LDFLAGS) $(OBJECTS) -o kimage
$(NM) --numeric-sort kimage > kernel.sym
$(OBJCOPY) -O binary kimage kimage.bin
dummy:
include ../rules.mak

View file

@ -0,0 +1,30 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/mm/cont.c
* PURPOSE: Manages continuous memory
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PVOID MmAllocateContiguousMemory(ULONG NumberOfBytes,
PHYSICAL_ADDRESS HighestAcceptableAddress)
{
UNIMPLEMENTED;
}
VOID MmFreeContiguousMemory(PVOID BaseAddress)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,205 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/mm/freelist.cc
* PURPOSE: Handle the list of free physical pages
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 27/05/98: Created
* 18/08/98: Added a fix from Robert Bergkvist
*/
/*
* NOTE: The list of free pages is implemented as an unsorted double linked
* list. This should make added or removing pages fast when you don't care
* about the physical address. Because the entirety of physical memory is
* mapped from 0xd0000000 upwards it is easy to do a mapping between
* physical and linear address.
*/
/* INCLUDES ****************************************************************/
#include <internal/stddef.h>
#include <internal/hal/page.h>
#include <internal/mm.h>
#include <internal/kernel.h>
#include <internal/bitops.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* TYPES *******************************************************************/
typedef struct _free_page
/*
* PURPOSE: At the start of every region of free physical pages
*/
{
struct _free_page* next;
struct _free_page* previous;
unsigned int nr_pages;
} free_page_hdr;
/* GLOBALS ****************************************************************/
/*
* PURPOSE: Points to the first page in the free list
*/
free_page_hdr* free_page_list_head=NULL;
/* FUNCTIONS *************************************************************/
void free_page(unsigned int physical_base, unsigned int nr)
/*
* FUNCTION: Add a physically continuous range of pages to the free list
* ARGUMENTS:
* physical_base = The first physical address to free
* nr = the size of the region (in pages) to free
* NOTES: This function attempts to keep the list partially unfragmented
*/
{
unsigned int eflags;
free_page_hdr* hdr=NULL;
DPRINT("Freeing %x to %x\n",physical_base,physical_base
+ (nr*PAGESIZE));
/*
* This must be atomic
*/
__asm__("pushf\n\tpop %0\n\tcli\n\t"
: "=d" (eflags));
/*
*
*/
hdr = (free_page_hdr *)physical_to_linear(physical_base);
DPRINT("free_page_hdr %x\n",hdr);
DPRINT("free_page_list_head %x\n",free_page_list_head);
if (free_page_list_head!=NULL)
{
free_page_list_head->previous=hdr;
}
hdr->next=free_page_list_head;
hdr->previous=NULL;
hdr->nr_pages = nr;
free_page_list_head=hdr;
__asm__("push %0\n\tpopf\n\t"
:
: "d" (eflags));
}
unsigned int get_dma_page(unsigned int max_address)
/*
* FUNCTION: Gets a page with a restricted max physical address (i.e.
* suitable for dma)
* ARGUMENTS:
* max_address = The maximum address usable by the caller
* RETURNS:
* The physical address of the page if it succeeds
* NULL if it fails.
* NOTES: This is very inefficent because the list isn't sorted. On the
* other hand sorting the list would be quite expensive especially if dma
* is only used infrequently. Perhaps a special cache of dma pages should
* be maintained?
*/
{
free_page_hdr* current=NULL;
if (free_page_list_head==NULL)
{
printk("CRITICAL: Unable to allocate page\n");
KeBugCheck(KBUG_OUT_OF_MEMORY);
}
/*
* Walk the free page list looking for suitable memory
*/
current = free_page_list_head;
while (current!=NULL)
{
if ( ((int)current) < max_address)
{
/*
* We take the first page from the region
*/
free_page_hdr* nhdr = (free_page_hdr *)(((int)current)+PAGESIZE);
if (current->previous!=NULL)
{
current->previous->next=nhdr;
}
if (current->next!=NULL)
{
current->next->previous=nhdr;
}
nhdr->next=current->next;
nhdr->previous=current->previous;
nhdr->nr_pages=current->nr_pages-1;
if (free_page_list_head==current)
{
free_page_list_head=nhdr;
}
return ((int)current);
}
current=current->next;
}
return(NULL);
}
unsigned int get_free_page(void)
/*
* FUNCTION: Allocates a page
* RETURNS: The physical address of the page allocated
*/
{
unsigned int addr;
/*
* This must be atomic wrt everything
*/
unsigned int eflags;
__asm__("pushf\n\tpop %0\n\tcli\n\t"
: "=d" (eflags));
CHECKPOINT;
/*
* If we are totally out of memory then panic
*/
if (free_page_list_head==NULL)
{
printk("CRITICAL: Unable to allocate page\n");
KeBugCheck(KBUG_OUT_OF_MEMORY);
}
CHECKPOINT;
addr = 0;
CHECKPOINT;
if (free_page_list_head->nr_pages>1)
{
free_page_list_head->nr_pages--;
addr = ((unsigned int)free_page_list_head) +
(free_page_list_head->nr_pages * PAGESIZE);
}
else
{
addr = (unsigned int)free_page_list_head;
free_page_list_head = free_page_list_head -> next;
}
CHECKPOINT;
__asm__("push %0\n\tpopf\n\t"
:
: "d" (eflags));
addr = addr - (IDMAP_BASE);
DPRINT("allocated %x\n",addr);
CHECKPOINT;
return(addr);
}

View file

@ -0,0 +1,31 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/base/bug.c
* PURPOSE: Graceful system shutdown if a bug is detected
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PVOID MmMapIoSpace(PHYSICAL_ADDRESS PhysicalAddress,
ULONG NumberOfBytes,
BOOLEAN CacheEnable)
{
UNIMPLEMENTED;
}
VOID MmUnmapIoSpace(PVOID BaseAddress, ULONG NumberOfBytes)
{
UNIMPLEMENTED;
}

127
reactos/ntoskrnl/mm/lock.c Normal file
View file

@ -0,0 +1,127 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/mm/lock.c
* PURPOSE: Locking/unlocking virtual memory areas
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
BOOL VirtualUnlock(LPVOID lpAddress, DWORD cbSize)
/*
* FUNCTION: Unlocks pages from the virtual address space of the current
* process
* ARGUMENTS:
* lpAddress = Beginning of the region to unlock
* cbSize = Size (in bytes) of the region to unlock
* RETURNS: Success or failure
*/
{
return(FALSE);
}
BOOL VirtualLock(LPVOID lpvAddress, DWORD cbSize)
/*
* FUNCTION: Prevents range of memory from being swapped out
* RECEIVES:
* lpvAddress - The base of the range to lock
* cbSize - The size of the range to lock
* RETURNS:
* TRUE - the function succeeds
* FALSE - the function failed (use GetLastError for details)
*
* NOTES: I'm guessing the kernel loads every page as well as locking it.
*/
{
unsigned int first_page = PAGE_ROUND_DOWN((int)lpvAddress);
unsigned int length = PAGE_ROUND_DOWN( ((int)lpvAddress) + cbSize) -
first_page;
memory_area* marea=NULL;
memory_area* current=NULL;
unsigned int i;
/*
* Check the process isn't trying to lock too much
*/
if ( ((length/PAGESIZE)+1) > 30)
{
SetLastError(0);
return(FALSE);
}
/*
* Find the corresponding vmarea(s)
*/
marea = find_first_marea(memory_area_list_head,first_page,
length);
if (marea==NULL)
{
SetLastError(0);
return(FALSE);
}
/*
* Check the memory areas are committed, continuous and not
* PAGE_NOACCESS
*/
current=marea;
if (current->base != first_page)
{
SetLastError(0);
return(FALSE);
}
while (current!=NULL && current->base < (first_page+length) )
{
if (!(current->state & MEM_COMMIT) ||
current->access & PAGE_NOACCESS)
{
SetLastError(0);
return(FALSE);
}
if ( current->next==NULL)
{
if ((current->base + current->length) !=
(first_page+length) )
{
SetLastError(0);
return(FALSE);
}
}
else
{
if ( (current->base+current->length) !=
current->next->base)
{
SetLastError(0);
return(FALSE);
}
}
current=current->next;
}
/*
* Lock/load the areas in memory
* (the pages aren't loaded just by touching them to avoid the
* overhead of a page fault)
*/
current=marea;
while (current!=NULL && current->base < (first_page+length) )
{
marea->lock = TRUE;
for (i=0; i<current->length; i++)
{
if (!current->load_page(marea,i))
{
/*
* If the page couldn't be loaded we unlock
* the locked pages and abort
*/
VirtualUnlock(lpvAddress,
current->base+i-PAGESIZE);
SetLastError(0);
return(FALSE);
}
}
}
return(TRUE);
}

224
reactos/ntoskrnl/mm/mdl.c Normal file
View file

@ -0,0 +1,224 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/mm/mdl.cc
* PURPOSE: Manipulates MDLs
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 27/05/98: Created
*/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/hal/page.h>
#include <internal/string.h>
#include <internal/debug.h>
/* FUNCTIONS ***************************************************************/
VOID MmUnlockPages(PMDL MemoryDescriptorList)
{
UNIMPLEMENTED;
}
PVOID MmMapLockedPages(PMDL MemoryDescriptorList, KPROCESSOR_MODE AccessMode)
{
UNIMPLEMENTED;
}
VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL MemoryDescriptorList)
{
UNIMPLEMENTED;
}
VOID MmPrepareMdlForReuse(PMDL Mdl)
{
UNIMPLEMENTED;
}
VOID KeFlushIoBuffers(PMDL Mdl, BOOLEAN ReadOperation, BOOLEAN DmaOperation)
{
/* NOP on the x86 */
/* See ntddk.h from Windows 98 DDK */
}
VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode,
LOCK_OPERATION Operation)
/*
* FUNCTION: Probes the specified pages, makes them resident and locks them
* ARGUMENTS:
* Mdl = MDL to probe
* AccessMode = Access at which to probe the buffer
* Operation = Operation to probe for
*/
{
/*
* Find the memory area containing the buffer
*/
ULONG* mdl_pages=NULL;
int i;
memory_area* marea=find_first_marea(memory_area_list_head,
(ULONG)Mdl->StartVa,
Mdl->ByteCount);
/*
* Check the area is valid
*/
if (marea==NULL || (marea->base+marea->length) < ((ULONG)Mdl->StartVa))
{
ExRaiseStatus(STATUS_INVALID_PARAMETER);
}
/*
* Check the permissions
*/
switch(Operation)
{
case IoReadAccess:
if (marea->access&PAGE_GUARD || marea->access&PAGE_NOACCESS)
{
ExRaiseStatus(STATUS_INVALID_PARAMETER);
}
break;
case IoWriteAccess:
case IoModifyAccess:
if (marea->access&PAGE_GUARD || marea->access&PAGE_READONLY)
{
ExRaiseStatus(STATUS_INVALID_PARAMETER);
}
break;
default:
printk("Invalid operation type at %s:%d in %s\n",__FILE__,__LINE__,
__FUNCTION__);
KeBugCheck(UNEXPECTED_KERNEL_MODE_TRAP);
}
/*
* Lock the memory area
* (We can't allow it to be freed while an I/O operation to it is
* ongoing)
*/
/*
* Lock the pages
*/
mdl_pages = (ULONG *)(Mdl + sizeof(MDL));
for (i=0;i<(PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE);i++)
{
if (!is_page_present(PAGE_ROUND_DOWN(Mdl->StartVa) + (i*PAGESIZE)))
{
marea->load_page(marea,PAGE_ROUND_DOWN(Mdl->StartVa) + (i*PAGESIZE)
- marea->base);
}
mdl_pages[i]=MmGetPhysicalAddress((PVOID)(PAGE_ROUND_DOWN(Mdl->StartVa)
+(i*PAGESIZE)));
}
}
ULONG MmGetMdlByteCount(PMDL Mdl)
/*
*
*/
{
return(Mdl->ByteCount);
}
ULONG MmGetMdlByteOffset(PMDL Mdl)
/*
* FUNCTION: Returns the byte offset within its page of the buffer described
* by the given MDL
* ARGUMENTS:
* Mdl = the mdl to query
* RETURNS: The offset in bytes
*/
{
return(Mdl->ByteOffset);
}
ULONG MmSizeOfMdl(PVOID Base, ULONG Length)
/*
* FUNCTION: Returns the number of bytes to allocate for an MDL describing
* the given address range
* ARGUMENTS:
* Base = base virtual address
* Length = number of bytes to map
*/
{
unsigned int len=PAGE_ROUND_UP(Length)/PAGESIZE;
if (!IS_PAGE_ALIGNED(Base))
{
len++;
}
return(sizeof(MDL)+(len*sizeof(ULONG)));
}
PVOID MmGetMdlVirtualAddress(PMDL Mdl)
{
return(Mdl->StartVa + Mdl->ByteOffset);
}
PVOID MmGetSystemAddressForMdl(PMDL Mdl)
{
Mdl->MappedSystemVa = MmMapLockedPages(Mdl,KernelMode);
return(Mdl->MappedSystemVa);
}
VOID MmBuildMdlForNonPagedPool(PMDL Mdl)
{
int va;
for (va=0; va<Mdl->Size; va++)
{
((PULONG)(Mdl + 1))[va] = MmGetPhysicalAddress(
Mdl->StartVa+ (va * PAGESIZE));
}
}
VOID MmInitializeMdl(PMDL MemoryDescriptorList, PVOID Base, ULONG Length)
{
memset(MemoryDescriptorList,0,sizeof(MDL));
MemoryDescriptorList->StartVa = PAGE_ROUND_DOWN(Base);
MemoryDescriptorList->ByteOffset = Base - PAGE_ROUND_DOWN(Base);
MemoryDescriptorList->MdlFlags = 0;
MemoryDescriptorList->ByteCount = Length;
MemoryDescriptorList->Size = PAGE_ROUND_UP(Length) / PAGESIZE;
if (!IS_PAGE_ALIGNED(Base))
{
MemoryDescriptorList->Size = MemoryDescriptorList->Size
+ sizeof(ULONG);
}
MemoryDescriptorList->Process = PsGetCurrentProcess();
}
PMDL MmCreateMdl(PMDL MemoryDescriptorList, PVOID Base, ULONG Length)
/*
* FUNCTION: Allocates and initalizes an MDL
* ARGUMENTS:
* MemoryDescriptorList = Points to MDL to initalize. If this is
* NULL then one is allocated
* Base = Base virtual address of the buffer
* Length = Length in bytes of the buffer
* RETURNS: A pointer to initalized MDL
*/
{
if (MemoryDescriptorList == NULL)
{
MemoryDescriptorList = (PMDL)ExAllocatePool(NonPagedPool,sizeof(MDL));
if (MemoryDescriptorList==NULL)
{
return(NULL);
}
}
MmInitializeMdl(MemoryDescriptorList,Base,Length);
return(MemoryDescriptorList);
}

173
reactos/ntoskrnl/mm/mm.c Normal file
View file

@ -0,0 +1,173 @@
/*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
* FILE: mm/mm.c
* PURPOSE: kernel memory managment functions
* PROGRAMMER: David Welch
* UPDATE HISTORY:
* Created 9/4/98
*/
/* INCLUDES *****************************************************************/
#include <internal/stddef.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/kernel.h>
#include <internal/pool.h>
#include <internal/bitops.h>
#include <internal/string.h>
#include <internal/hal/page.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *****************************************************************/
/*
* Size of extended memory (kb) (fixed for now)
*/
#define EXTENDED_MEMORY_SIZE (3*1024*1024)
/*
* Compiler defined symbol
*/
extern unsigned int stext;
extern unsigned int etext;
extern unsigned int end;
/* FUNCTIONS ****************************************************************/
BOOLEAN MmIsThisAnNtAsSystem()
{
UNIMPLEMENTED
}
MM_SYSTEM_SIZE MmQuerySystemSize()
{
UNIMPLEMENTED;
}
void MmInitalize(boot_param* bp)
/*
* FUNCTION: Initalize memory managment
*/
{
unsigned int kernel_len = bp->end_mem - bp->start_mem;
unsigned int first_krnl_phys_addr;
unsigned int last_krnl_phys_addr;
int i;
DPRINT("InitalizeMM()\n");
CHECKPOINT;
/*
* Unmap low memory
*/
(get_page_directory())[0]=0;
FLUSH_TLB;
CHECKPOINT;
/*
* Free all pages not used for kernel memory
* (we assume the kernel occupies a continuous range of physical
* memory)
*/
first_krnl_phys_addr = bp->start_mem;
last_krnl_phys_addr = bp->end_mem;
DPRINT("first krnl %x\nlast krnl %x\n",first_krnl_phys_addr,
last_krnl_phys_addr);
/*
* Free physical memory not used by the kernel
*/
if (first_krnl_phys_addr < 0xa0000)
{
free_page(0x2000,(first_krnl_phys_addr/PAGESIZE)-2);
free_page(last_krnl_phys_addr+PAGESIZE,
(0xa0000 - last_krnl_phys_addr - PAGESIZE)/PAGESIZE);
free_page(1024*1024,EXTENDED_MEMORY_SIZE/4096);
}
else
{
free_page(0x2000,(0xa0000/PAGESIZE)-2);
free_page(1024*1024,
(first_krnl_phys_addr-(1024*1024))/PAGESIZE);
free_page(last_krnl_phys_addr+PAGESIZE,
((EXTENDED_MEMORY_SIZE+(1024*1024))
-last_krnl_phys_addr)/PAGESIZE);
}
CHECKPOINT;
/*
* Create a trap for null pointer references and protect text
* segment
*/
CHECKPOINT;
DPRINT("stext %x etext %x\n",(int)&stext,(int)&etext);
for (i=PAGE_ROUND_UP(((int)&stext));
i<PAGE_ROUND_DOWN(((int)&etext));i=i+PAGESIZE)
{
mark_page_not_writable(i);
}
DPRINT("end %x\n",(int)&end);
for (i=PAGE_ROUND_UP(KERNEL_BASE+kernel_len);
i<(KERNEL_BASE+PAGE_TABLE_SIZE);i=i+PAGESIZE)
{
set_page(i,0,0);
}
FLUSH_TLB;
CHECKPOINT;
/*
* Intialize memory areas
*/
VirtualInit(bp);
}
#if 0
void* MmMapIoSpace(unsigned int physical_address, unsigned int size,
unsigned int cachable)
/*
* FUNCTION: Make a portion of io space accessible to a device driver
*/
{
/*
* Determine here if the mapping is legel
*/
/*
* Find an address to place the mapping
*/
memory_area_desc* current = memory_area_list_head;
memory_area_desc* new_area=ExAllocateMemory(sizeof(memory_area_desc));
size = PAGE_ROUND_UP(size);
while (current!=NULL)
{
if ( current->next==NULL ||
(current->next->base - (current->base+current->length))
>= size)
{
new_area->base=current->base+current->length;
new_area->length=size;
new_area->next=current->next;
current->next=new_area;
}
current=current->next;
}
/*
* Map the desired physical memory
*/
for (int i=0;i<size;i++)
{
set_page(new_area->base+i,
PA_READ | PA_WRITE | PA_EXECUTE | PA_SYSTEM,
physical_address+i);
}
return((void *)new_area->base);
}
#endif

View file

@ -0,0 +1,29 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/mm/cont.c
* PURPOSE: Manages non-cached memory
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PVOID MmAllocateNonCachedMemory(ULONG NumberOfBytes)
{
UNIMPLEMENTED;
}
VOID MmFreeNonCachedMemory(PVOID BaseAddress, ULONG NumberOfBytes)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,24 @@
%include 'internal/hal/segment.inc'
BITS 32
GLOBAL _exception_handler14
EXTERN _exception_handler
EXTERN _page_fault_handler
segment .text
_exception_handler14:
cli
push ds
push dword 14
pushad
mov ax,KERNEL_DS
mov ds,ax
call _page_fault_handler
cmp eax,0
jne _ret_from_exp
call _exception_handler
_ret_from_exp:
popad
add esp,12
iretd

652
reactos/ntoskrnl/mm/pool.c Normal file
View file

@ -0,0 +1,652 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/pool.c
* PURPOSE: Implements the kernel memory pool
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 27/05/98: Created
* 10/06/98: Bug fixes by Iwan Fatahi (i_fatahi@hotmail.com)
* in take_block (if current bigger than required)
* in remove_from_used_list
* in ExFreePool
*/
/* INCLUDES ****************************************************************/
#include <internal/stddef.h>
#include <internal/mm.h>
#include <internal/hal/page.h>
#include <internal/pool.h>
#include <internal/bitops.h>
#include <internal/kernel.h>
#define NDEBUG
#include <internal/debug.h>
#include <ddk/ntddk.h>
/* TYPES *******************************************************************/
/*
* fields present at the start of a block (this is for internal use only)
*/
typedef struct _block_hdr
{
unsigned int size;
struct _block_hdr* previous;
struct _block_hdr* next;
} block_hdr;
/* GLOBALS *****************************************************************/
/*
* Memory managment initalized symbol for the base of the pool
*/
extern unsigned int kernel_pool_base;
/*
* Pointer to the first block in the free list
*/
static block_hdr* free_list_head = NULL;
static block_hdr* used_list_head = NULL;
static unsigned int nr_free_blocks = 0;
static unsigned int nr_used_blocks = 0;
#define ALLOC_MAP_SIZE (NONPAGED_POOL_SIZE / PAGESIZE)
/*
* One bit for each page in the kmalloc region
* If set then the page is used by a kmalloc block
*/
static unsigned int alloc_map[ALLOC_MAP_SIZE/32]={0,};
/* FUNCTIONS ***************************************************************/
static void validate_free_list(void)
/*
* FUNCTION: Validate the integrity of the list of free blocks
*/
{
block_hdr* current=free_list_head;
unsigned int blocks_seen=0;
while (current!=NULL)
{
unsigned int base_addr = (int)current;
if (base_addr < (kernel_pool_base) ||
(base_addr+current->size) >
(kernel_pool_base)+NONPAGED_POOL_SIZE)
{
printk("Block %x found outside pool area\n",current);
printk("Size %d\n",current->size);
printk("Limits are %x %x\n",kernel_pool_base,
kernel_pool_base+NONPAGED_POOL_SIZE);
KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
}
blocks_seen++;
if (blocks_seen > nr_free_blocks)
{
printk("Too many blocks on list\n");
KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
}
// verify_for_write(base_addr,current->size);
if (current->next!=NULL&&current->next->previous!=current)
{
printk("%s:%d:Break in list (current %x next %x "
"current->next->previous %x)\n",
__FILE__,__LINE__,current,current->next,
current->next->previous);
KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
}
current=current->next;
}
}
static void validate_used_list(void)
/*
* FUNCTION: Validate the integrity of the list of used blocks
*/
{
block_hdr* current=used_list_head;
unsigned int blocks_seen=0;
while (current!=NULL)
{
unsigned int base_addr = (int)current;
if (base_addr < (kernel_pool_base) ||
(base_addr+current->size) >
(kernel_pool_base)+NONPAGED_POOL_SIZE)
{
printk("Block %x found outside pool area\n",current);
for(;;);
}
blocks_seen++;
if (blocks_seen > nr_used_blocks)
{
printk("Too many blocks on list\n");
for(;;);
}
// verify_for_write(base_addr,current->size);
if (current->next!=NULL&&current->next->previous!=current)
{
printk("Break in list (current %x next %x)\n",
current,current->next);
for(;;);
}
current=current->next;
}
}
static void check_duplicates(block_hdr* blk)
/*
* FUNCTION: Check a block has no duplicates
* ARGUMENTS:
* blk = block to check
* NOTE: Bug checks if duplicates are found
*/
{
unsigned int base = (int)blk;
unsigned int last = ((int)blk) + +sizeof(block_hdr) + blk->size;
block_hdr* current=free_list_head;
while (current!=NULL)
{
if ( (int)current > base && (int)current < last )
{
printk("intersecting blocks on list\n");
for(;;);
}
if ( (int)current < base &&
((int)current + current->size + sizeof(block_hdr))
> base )
{
printk("intersecting blocks on list\n");
for(;;);
}
current=current->next;
}
current=used_list_head;
while (current!=NULL)
{
if ( (int)current > base && (int)current < last )
{
printk("intersecting blocks on list\n");
for(;;);
}
if ( (int)current < base &&
((int)current + current->size + sizeof(block_hdr))
> base )
{
printk("intersecting blocks on list\n");
for(;;);
}
current=current->next;
}
}
static void validate_kernel_pool(void)
/*
* FUNCTION: Checks the integrity of the kernel memory heap
*/
{
block_hdr* current=NULL;
validate_free_list();
validate_used_list();
current=free_list_head;
while (current!=NULL)
{
check_duplicates(current);
current=current->next;
}
current=used_list_head;
while (current!=NULL)
{
check_duplicates(current);
current=current->next;
}
}
static void add_to_free_list(block_hdr* blk)
/*
* FUNCTION: add the block to the free list (internal)
*/
{
blk->next=free_list_head;
blk->previous=NULL;
if (free_list_head!=NULL)
{
free_list_head->previous=blk;
}
free_list_head=blk;
nr_free_blocks++;
}
static void add_to_used_list(block_hdr* blk)
/*
* FUNCTION: add the block to the used list (internal)
*/
{
blk->next=used_list_head;
blk->previous=NULL;
if (used_list_head!=NULL)
{
used_list_head->previous=blk;
}
used_list_head=blk;
nr_used_blocks++;
}
static void remove_from_free_list(block_hdr* current)
{
if (current->next==NULL&&current->previous==NULL)
{
free_list_head=NULL;
}
else
{
if (current->previous!=NULL)
{
current->previous->next=current->next;
}
if (current->next!=NULL)
{
DPRINT("current->previous %x\n",current->previous);
current->next->previous=current->previous;
}
}
nr_free_blocks--;
}
#ifdef BROKEN_VERSION_OF_REMOVE_FROM_FREE_LIST
static void remove_from_free_list(block_hdr* current)
{
if (current->next==NULL&&current->previous==NULL)
{
free_list_head=NULL;
}
else
{
if (current->next==NULL)
{
current->previous->next=NULL;
}
else
{
current->previous->next=current->next;
}
if (current->previous==NULL)
{
current->next->previous=NULL;
}
else
{
current->next->previous=current->previous;
}
}
nr_free_blocks--;
}
#endif
static void remove_from_used_list(block_hdr* current)
{
if (current->next==NULL&&current->previous==NULL)
{
used_list_head=NULL;
}
else
{
if (current->previous==NULL)
{
current->next->previous=NULL;
used_list_head=current->next;
}
else
{
current->previous->next=current->next;
}
if (current->next!=NULL)
{
current->next->previous=current->previous;
}
else
{
current->previous->next=NULL;
}
}
nr_used_blocks--;
}
inline static void* block_to_address(block_hdr* blk)
/*
* FUNCTION: Translate a block header address to the corresponding block
* address (internal)
*/
{
return ( (void *) ((int)blk + sizeof(block_hdr)) );
}
inline static block_hdr* address_to_block(void* addr)
{
return (block_hdr *)
( ((int)addr) - sizeof(block_hdr) );
}
static unsigned int alloc_pool_region(unsigned int nr_pages)
/*
* FUNCTION: Allocates a region of pages within the nonpaged pool area
*/
{
unsigned int start = 0;
unsigned int length = 0;
unsigned int i,j;
DPRINT("alloc_pool_region(nr_pages = %d)\n",nr_pages);
for (i=1; i<ALLOC_MAP_SIZE;i++)
{
if (!test_bit(i%32,&alloc_map[i/32]))
{
if (length == 0)
{
start=i;
length = 1;
}
else
{
length++;
}
if (length==nr_pages)
{
DPRINT("found region at %d for %d\n",start,
length);
for (j=start;j<(start+length);j++)
{
DPRINT("Writing %x\n",&alloc_map[j/32]);
set_bit(j%32,&alloc_map[j/32]);
}
DPRINT("returning %x\n",(start*PAGESIZE)
+kernel_pool_base);
return((start*PAGESIZE)+kernel_pool_base);
}
}
else
{
start=0;
length=0;
}
}
printk("CRITICAL: Out of kmalloc space\n");
for(;;);
return(0);
}
static block_hdr* grow_kernel_pool(unsigned int size)
/*
* FUNCTION: Grow the executive heap to accomodate a block of at least 'size'
* bytes
*/
{
unsigned int total_size = size + sizeof(block_hdr);
unsigned int nr_pages = PAGE_ROUND_UP(total_size) / PAGESIZE;
unsigned int start = alloc_pool_region(nr_pages);
block_hdr* used_blk=NULL;
block_hdr* free_blk=NULL;
int i;
DPRINT("growing heap for block size %d, ",size);
DPRINT("start %x\n",start);
for (i=0;i<nr_pages;i++)
{
set_page(start+(i*PAGESIZE),PA_SYSTEM | PA_WRITE | PA_READ,
get_free_page());
}
if ((PAGESIZE-(total_size%PAGESIZE))>(2*sizeof(block_hdr)))
{
used_blk = (struct _block_hdr *)start;
DPRINT("Creating block at %x\n",start);
used_blk->size = size;
add_to_used_list(used_blk);
free_blk = (block_hdr *)(start + sizeof(block_hdr) + size);
DPRINT("Creating block at %x\n",free_blk);
free_blk->size = (nr_pages * PAGESIZE) -((sizeof(block_hdr)*2) + size);
add_to_free_list(free_blk);
}
else
{
used_blk = (struct _block_hdr *)start;
used_blk->size = nr_pages * PAGESIZE;
add_to_used_list(used_blk);
}
validate_kernel_pool();
return(used_blk);
}
static void* take_block(block_hdr* current, unsigned int size)
/*
* FUNCTION: Allocate a used block of least 'size' from the specified
* free block
* RETURNS: The address of the created memory block
*/
{
/*
* If the block is much bigger than required then split it and
* return a pointer to the allocated section. If the difference
* between the sizes is marginal it makes no sense to have the
* extra overhead
*/
if (current->size > (1 + size + sizeof(block_hdr)))
{
/*
* Replace the bigger block with a smaller block in the
* same position in the list
*/
block_hdr* free_blk = (block_hdr *)(((int)current)
+ sizeof(block_hdr) + size);
free_blk->next = current->next;
free_blk->previous = current->previous;
if (current->next)
{
current->next->previous = free_blk;
}
if (current->previous)
{
current->previous->next = free_blk;
}
free_blk->size = current->size - (sizeof(block_hdr) + size);
if (current==free_list_head)
{
free_list_head=free_blk;
}
current->size=size;
add_to_used_list(current);
validate_kernel_pool();
return(block_to_address(current));
}
/*
* Otherwise allocate the whole block
*/
remove_from_free_list(current);
add_to_used_list(current);
validate_kernel_pool();
return(block_to_address(current));
}
asmlinkage VOID ExFreePool(PVOID block)
/*
* FUNCTION: Releases previously allocated memory
* ARGUMENTS:
* block = block to free
*/
{
block_hdr* blk=address_to_block(block);
DPRINT("(%s:%d) freeing block %x\n",__FILE__,__LINE__,blk);
validate_kernel_pool();
/*
* Please don't change the order
*/
remove_from_used_list(blk);
add_to_free_list(blk);
validate_kernel_pool();
}
#define CACHE_ALIGNMENT (16)
PVOID ExAllocatePool(ULONG type, ULONG size)
/*
* FUNCTION: Allocates memory from the pool
* ARGUMENTS:
* size = minimum size of the block to be allocated
* type = the type of memory to use for the block
* RETURNS:
* the address of the block if it succeeds
*/
{
PVOID Block;
if (type == NonPagedPoolCacheAligned ||
type == NonPagedPoolCacheAlignedMustS)
{
size = size + CACHE_ALIGNMENT;
}
switch(type)
{
case NonPagedPool:
case NonPagedPoolMustSucceed:
case NonPagedPoolCacheAligned:
case NonPagedPoolCacheAlignedMustS:
Block = ExAllocateNonPagedPool(type,size);
break;
case PagedPool:
case PagedPoolCacheAligned:
Block = ExAllocatePagedPool(type,size);
break;
default:
return(NULL);
};
if ((type==NonPagedPoolMustSucceed || type==NonPagedPoolCacheAlignedMustS)
&& Block==NULL)
{
KeBugCheck(MUST_SUCCEED_POOL_EMPTY);
}
if (type == NonPagedPoolCacheAligned ||
type == NonPagedPoolCacheAlignedMustS)
{
Block = Block + CACHE_ALIGNMENT - (((int)Block)%CACHE_ALIGNMENT);
}
return(Block);
}
static PVOID ExAllocatePagedPool(ULONG type, ULONG size)
{
UNIMPLEMENTED;
}
static PVOID ExAllocateNonPagedPool(ULONG type, ULONG size)
{
block_hdr* current=NULL;
DPRINT("kmalloc(size %d)\n",size);
validate_kernel_pool();
/*
* accomodate this useful idiom
*/
if (size==0)
{
return(NULL);
}
/*
* Look for an already created block of sufficent size
*/
current=free_list_head;
while (current!=NULL)
{
DPRINT("current %x size %x next %x\n",current,current->size,
current->next);
if (current->size>=size)
{
DPRINT("found block %x of size %d\n",current,size);
return(take_block(current,size));
}
current=current->next;
}
/*
* Otherwise create a new block
*/
return(block_to_address(grow_kernel_pool(size)));
}
PVOID ExAllocatePoolWithQuota(POOL_TYPE PoolType, ULONG NumberOfBytes)
{
PVOID Block;
PKTHREAD current = KeGetCurrentThread();
Block = ExAllocatePool(PoolType,NumberOfBytes);
switch(PoolType)
{
case NonPagedPool:
case NonPagedPoolMustSucceed:
case NonPagedPoolCacheAligned:
case NonPagedPoolCacheAlignedMustS:
// current->NPagedPoolQuota = current->NPagedPoolQuota - NumberOfBytes;
break;
case PagedPool:
case PagedPoolCacheAligned:
// current->PagedPoolQuota = current->PagedPoolQuota - NumberOfBytes;
break;
};
return(Block);
}
PVOID ExAllocatePoolWithQuotaTag(POOL_TYPE PoolType, ULONG NumberOfBytes,
ULONG Tag)
{
PVOID Block;
Block=ExAllocatePoolWithQuota(PoolType,NumberOfBytes+sizeof(ULONG));
((ULONG *)Block)[0]=Tag;
return(Block+4);
}
PVOID ExAllocatePoolWithTag(POOL_TYPE PoolType, ULONG NumberOfBytes,
ULONG Tag)
/*
* FUNCTION: Allocates pool memory and inserts a caller supplied tag before
* the block allocated
* ARGUMENTS:
* PoolType = Type of memory to allocate
* NumberOfBytes = Number of bytes to allocate
* Tag = Tag
* RETURNS: The address of the block allocated
*/
{
PVOID Block;
Block=ExAllocatePool(PoolType,NumberOfBytes+sizeof(ULONG));
((ULONG *)Block)[0]=Tag;
return(Block+4);
}

View file

@ -0,0 +1,45 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c
* PURPOSE: Implements section objects
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS ZwOpenSection(PHANDLE SectionHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes)
{
UNIMPLEMENTED;
}
NTSTATUS ZwMapViewOfSection(HANDLE SectionHandle,
HANDLE ProcessHandle,
PVOID* BaseAddress,
ULONG ZeroBits,
ULONG CommitSize,
PLARGE_INTEGER SectionOffset,
PULONG ViewSize,
SECTION_INHERIT InheritDisposition,
ULONG AllocationType,
ULONG Protect)
{
UNIMPLEMENTED;
}
NTSTATUS ZwUnmapViewOfSection(HANDLE ProcessHandle, PVOID BaseAddress)
{
UNIMPLEMENTED;
}

View file

@ -0,0 +1,500 @@
/*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel v0.0.2
* FILE: mm/virtual.cc
* PURPOSE: implementing the Virtualxxx section of the win32 api
* PROGRAMMER: David Welch
* UPDATE HISTORY:
* 09/4/98: Created
* 10/6/98: Corrections from Fatahi (i_fatahi@hotmail.com)
*/
/* INCLUDE *****************************************************************/
#include <windows.h>
#include <internal/hal/segment.h>
#include <internal/mm.h>
#include <internal/hal/page.h>
#define NDEBUG
#include <internal/debug.h>
/* TYPES *******************************************************************/
/*
* These two are statically declared because mm is initalized before the
* memory pool
*/
static memory_area kernel_area_desc;
static memory_area kernel_pool_desc;
/*
* Head of the list of system memory areas
*/
memory_area* system_memory_area_list_head=&kernel_area_desc;
/*
* Head of the list of user memory areas (this should be per process)
*/
memory_area* memory_area_list_head=NULL;
/*
* The base address of the kmalloc region
*/
unsigned int kernel_pool_base = 0;
/* FUNCTIONS ****************************************************************/
void VirtualInit(boot_param* bp)
/*
* FUNCTION: Intialize the memory areas list
* ARGUMENTS:
* bp = Pointer to the boot parameters
* kernel_len = Length of the kernel
*/
{
unsigned int kernel_len = bp->end_mem - bp->start_mem;
DPRINT("VirtualInit() %x\n",bp);
/*
* Setup the system area descriptor list
*/
kernel_area_desc.base = KERNEL_BASE;
kernel_area_desc.length = kernel_len;
kernel_area_desc.next = &kernel_pool_desc;
kernel_area_desc.load_page=NULL;
/*
* The kmalloc area starts one page after the kernel area
*/
kernel_pool_desc.base = KERNEL_BASE+ PAGE_ROUND_UP(kernel_len) + PAGESIZE;
kernel_pool_desc.length = NONPAGED_POOL_SIZE;
kernel_pool_desc.next = NULL;
kernel_pool_desc.load_page=NULL;
kernel_pool_base = kernel_pool_desc.base;
DPRINT("kmalloc_region_base %x\n",kernel_pool_base);
}
memory_area* find_first_marea(memory_area* list_head, unsigned int base,
unsigned int length)
/*
* FUNCTION: Returns the first memory area starting in the region or the last
* one before the start of the region
* ARGUMENTS:
* list_head = Head of the list of memory areas to search
* base = base address of the region
* length = length of the region
* RETURNS: A pointer to the area found or
* NULL if the region was before the first region on the list
*/
{
memory_area* current=list_head;
for (;;)
{
if (current==NULL)
{
return(NULL);
}
if (current->base == base && length==0)
{
return(current);
}
if (current->base >= base)
{
if (current->base < (base+length))
{
return(current);
}
else
{
return(current->previous);
}
}
if (current->next==NULL)
{
return(current);
}
current=current->next;
}
return(NULL);
}
asmlinkage int page_fault_handler(unsigned int edi,
unsigned int esi, unsigned int ebp,
unsigned int esp, unsigned int ebx,
unsigned int edx, unsigned int ecx,
unsigned int eax,
unsigned int type,
unsigned int ds,
unsigned short int error_code,
unsigned int eip,
unsigned int cs, unsigned int eflags,
unsigned int esp0, unsigned int ss0)
/*
* FUNCTION: Handle a page fault
*/
{
memory_area* marea=NULL;
/*
* Get the address for the page fault
*/
unsigned int cr2;
__asm__("movl %%cr2,%0\n\t" : "=d" (cr2));
DPRINT("Page fault at address %x with eip %x\n",cr2,eip);
cr2 = PAGE_ROUND_DOWN(cr2);
/*
* Find the memory area for the faulting address
*/
if (cr2>=KERNEL_BASE)
{
/*
* Check permissions
*/
if (cs!=KERNEL_CS)
{
printk("%s:%d\n",__FILE__,__LINE__);
return(0);
}
marea=find_first_marea(system_memory_area_list_head,cr2,
PAGESIZE);
}
else
{
marea=find_first_marea(memory_area_list_head,cr2,
PAGESIZE);
}
/*
* If the access was to an invalid area of memory raise an exception
*/
if (marea==NULL || marea->load_page==NULL)
{
printk("%s:%d\n",__FILE__,__LINE__);
return(0);
}
/*
* Check the access was within the area
*/
if (cr2 > (marea->base + marea->length) || cr2 < marea->base)
{
DPRINT("base was %x length %x\n",marea->base,marea->length);
DPRINT("%s:%d\n",__FILE__,__LINE__);
return(0);
}
/*
* Call the region specific page fault handler
*/
return(marea->load_page(marea,cr2 - marea->base));
}
static LPVOID allocate_marea(DWORD dwSize, DWORD flAllocationType,
DWORD flProtect, memory_area** list_head,
unsigned int last_addr,
BOOL (*fn)(memory_area* marea,
unsigned int address))
/*
* FUNCTION:
*/
{
memory_area* current=*list_head;
memory_area* ndesc=NULL;
while (current!=NULL)
{
last_addr = PAGE_ROUND_UP(current->base + current->length);
current=current->next;
}
ndesc = ExAllocatePool(NonPagedPool,sizeof(memory_area));
ndesc->access=flProtect;
ndesc->state=flAllocationType;
ndesc->lock=FALSE;
ndesc->base=last_addr+PAGESIZE;
ndesc->length=dwSize;
ndesc->previous=current;
if (current!=NULL)
{
ndesc->next=current->next;
current->next=ndesc;
if (current->next!=NULL)
{
current->next->previous=ndesc;
}
}
else
{
*list_head=ndesc;
ndesc->next=NULL;
ndesc->previous=NULL;
}
ndesc->load_page=fn;
DPRINT("VirtualAlloc() returning %x\n",ndesc->base);
return((LPVOID)ndesc->base);
}
void commit_region_free(memory_area* marea)
/*
* FUNCTION: Decommits the region
*/
{
int i;
for (i=0;i<marea->length;i=i+PAGESIZE)
{
if (is_page_present(marea->base+marea->length))
{
free_page(MmGetPhysicalAddress(marea->base+marea->length),1);
}
}
}
BOOL commit_region_load_page(memory_area* marea, unsigned int address)
/*
* FUNCTION: Handles a page fault on a committed region of memory
* ARGUMENTS:
* marea = memory area
* address = address of faulting access
* RETURNS: TRUE if the page was loaded
* FALSE if an exception should be generated
*/
{
set_page(marea->base+address,0x7,get_free_page());
return(TRUE);
}
asmlinkage LPVOID STDCALL VirtualAlloc(LPVOID lpAddress, DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect)
{
/*
* FUNCTION: Create a memory area
* ARGUMENTS:
* lpAddress = the base address of the area or NULL if the system
* decides the base
* dwSize = the size of the area
* flAllocationType = the type of allocation
* MEM_COMMIT = accessible
* MEM_RESERVE = not accessible but can't be allocated
* flProtect = what protection to give the area
* RETURNS: The base address of the block
*/
DPRINT("VirtualAlloc() lpAddress %x dwSize %x flAllocationType %x ",
lpAddress,dwSize,flAllocationType);
DPRINT("flProtect %x\n",flProtect);
if (lpAddress==NULL)
{
/*
* We decide the address
*/
if (flProtect & PAGE_SYSTEM)
{
return(allocate_marea(dwSize,flAllocationType,
flProtect,&system_memory_area_list_head,
KERNEL_BASE,commit_region_load_page));
}
else
{
return(allocate_marea(dwSize,flAllocationType,
flProtect,&memory_area_list_head,PAGESIZE,
commit_region_load_page));
}
}
else
{
memory_area* marea=NULL;
if (lpAddress < ((PVOID)KERNEL_BASE))
{
marea=find_first_marea(memory_area_list_head,
(unsigned int)lpAddress,dwSize);
}
else
{
marea=find_first_marea(system_memory_area_list_head,
(unsigned int)lpAddress,dwSize);
}
/*
* Check someone hasn't already allocated that area
*/
if (marea!=NULL && marea->base <= (unsigned int)lpAddress &&
(marea->base + marea->length) > (unsigned int)lpAddress)
{
SetLastError(ERROR_INVALID_DATA);
return(0);
}
/*
* Grab the area
*/
}
}
BOOL WINAPI VirtualFreeEx(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize,
DWORD dwFreeType)
/*
* FUNCTION: Releases, decommits or both a region of memory within the
* virtual address of a specified process
* ARGUMENTS:
* hProcess = Process to act on
* lpAddress = starting virtual address to free
* dwSize = Size in bytes of the memory region to free
* dwFreeType = Type of free operation
* RETURNS: On success non-zero
* On failure zero
* NOTE: This tries to optimize for the most common case which is for
* regions to be decommitted in large chunks. If a process alternatedly
* decommitted every other page in a region this function would be extremely
* inefficent.
*/
{
memory_area* marea = NULL;
/*
* Check our permissions for hProcess here
*/
/*
* Get the list of memory areas corresponding to hProcess here
*/
/*
* Do the business
*/
if (dwFreeType==MEM_RELEASE)
{
if (dwSize!=0)
{
SetLastError(ERROR_INVALID_BLOCK_LENGTH);
return(0);
}
marea = find_first_marea(memory_area_list_head,(unsigned int)lpAddress,
1);
if (marea==NULL || marea->base!=((int)lpAddress))
{
SetLastError(ERROR_INVALID_BLOCK);
return(0);
}
/*
* Ask the memory area to destroy itself
*/
marea->free(marea);
/*
* Change the area attributes
*/
marea->access=PAGE_NOACCESS;
marea->state=MEM_FREE;
marea->type=MEM_PRIVATE;
}
else
{
}
}
BOOL WINAPI VirtualProtectEx(HANDLE hProcess, LPVOID lpAddress,
DWORD dwSize, DWORD flNewProtect, PDWORD lpflOldProtect)
/*
* FUNCTION:
*/
{
}
DWORD WINAPI VirtualQueryEx(HANDLE hProcess, LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer, DWORD dwLength)
/*
* FUNCTION: Provides information about a range of pages within the virtual
* address space of a specified process.
* ARGUMENTS:
* hProcess = Handle of process
* lpAddress = Address of region
* lpBuffer = Buffer to store information
* dwLength = length of region
* RETURNS: The number of bytes transferred into the buffer
*/
{
/*
* Find the memory area
*/
memory_area* marea = find_first_marea(memory_area_list_head,
(unsigned int) lpAddress,
dwLength);
/*
* Check it exists
*/
if (marea==NULL || marea->base!=((int)lpAddress))
{
SetLastError(0);
return(0);
}
lpBuffer->BaseAddress = (void *)lpAddress;
lpBuffer->AllocationBase = (void *)marea->base;
lpBuffer->AllocationProtect = marea->initial_access;
lpBuffer->RegionSize = marea->length;
lpBuffer->State = marea->state;
lpBuffer->Protect = marea->access;
lpBuffer->Type = marea->type;
return(sizeof(MEMORY_BASIC_INFORMATION));
}
BOOLEAN MmIsNonPagedSystemAddressValid(PVOID VirtualAddress)
{
UNIMPLEMENTED;
}
BOOLEAN MmIsAddressValid(PVOID VirtualAddress)
/*
* FUNCTION: Checks whether the given address is valid for a read or write
* ARGUMENTS:
* VirtualAddress = address to check
* RETURNS: True if the access would be valid
* False if the access would cause a page fault
* NOTES: This function checks whether a byte access to the page would
* succeed. Is this realistic for RISC processors which don't
* allow byte granular access?
*/
{
memory_area* marea;
if (VirtualAddress >= (PVOID)KERNEL_BASE)
{
marea = find_first_marea(system_memory_area_list_head,
(unsigned int)VirtualAddress,1);
}
else
{
marea = find_first_marea(memory_area_list_head,
(unsigned int)VirtualAddress,1);
}
if (marea==NULL)
{
return(FALSE);
}
if (marea->access == PAGE_NOACCESS || marea->access & PAGE_GUARD ||
marea->state == MEM_FREE || marea->state == MEM_RESERVE)
{
return(FALSE);
}
return(TRUE);
}

158
reactos/ntoskrnl/mm/zone.c Normal file
View file

@ -0,0 +1,158 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: mkernel/mm/zone.c
* PURPOSE: Implements zone buffers
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/kernel.h>
/* FUNCTIONS ***************************************************************/
inline static PZONE_ENTRY block_to_entry(PVOID Block)
{
return( (PZONE_ENTRY)(Block - sizeof(ZONE_ENTRY)) );
}
inline static PVOID entry_to_block(PZONE_ENTRY Entry)
{
return( (PVOID)( ((PVOID)Entry) + sizeof(ZONE_ENTRY)));
}
BOOLEAN ExIsObjectInFirstZoneSegment(PZONE_HEADER Zone, PVOID Object)
{
PVOID Base = (PVOID)(Zone + sizeof(ZONE_HEADER) + sizeof(ZONE_SEGMENT) +
sizeof(ZONE_ENTRY));
PZONE_SEGMENT seg = (PZONE_SEGMENT)(Zone + sizeof(ZONE_HEADER));
ULONG length = seg->size;
return( (Object > Base) && (Object < (Base + length)));
}
NTSTATUS ExExtendZone(PZONE_HEADER Zone, PVOID Segment, ULONG SegmentSize)
{
PZONE_ENTRY entry;
PZONE_SEGMENT seg;
unsigned int i;
seg = (PZONE_SEGMENT)Segment;
seg->size = SegmentSize;
PushEntryList(&Zone->SegmentList,&seg->Entry);
entry = (PZONE_ENTRY)( ((PVOID)seg) + sizeof(ZONE_SEGMENT) );
for (i=0;i<(SegmentSize / Zone->BlockSize);i++)
{
PushEntryList(&Zone->FreeList,&entry->Entry);
entry = (PZONE_ENTRY)(((PVOID)entry) + sizeof(ZONE_ENTRY) +
Zone->BlockSize);
}
return(STATUS_SUCCESS);
}
NTSTATUS ExInterlockedExtendZone(PZONE_HEADER Zone, PVOID Segment,
ULONG SegmentSize, PKSPIN_LOCK Lock)
{
NTSTATUS ret;
KIRQL oldlvl;
KeAcquireSpinLock(Lock,&oldlvl);
ret = ExExtendZone(Zone,Segment,SegmentSize);
KeReleaseSpinLock(Lock,oldlvl);
return(ret);
}
BOOLEAN ExIsFullZone(PZONE_HEADER Zone)
{
return(Zone->FreeList.Next==NULL);
}
PVOID ExAllocateFromZone(PZONE_HEADER Zone)
/*
* FUNCTION: Allocate a block from a zone
* ARGUMENTS:
* Zone = Zone to allocate from
* RETURNS: The base address of the block allocated
*/
{
PSINGLE_LIST_ENTRY list_entry = PopEntryList(&Zone->FreeList);
PZONE_ENTRY entry = CONTAINING_RECORD(list_entry,ZONE_ENTRY,Entry);
return(entry_to_block(entry));
}
PVOID ExFreeToZone(PZONE_HEADER Zone, PVOID Block)
/*
* FUNCTION: Frees a block from a zone
* ARGUMENTS:
* Zone = Zone the block was allocated from
* Block = Block to free
*/
{
PZONE_ENTRY entry = block_to_entry(Block);
PZONE_ENTRY ret = entry_to_block((PZONE_ENTRY)Zone->FreeList.Next);
PushEntryList(&Zone->FreeList,&entry->Entry);
return(ret);
}
NTSTATUS ExInitializeZone(PZONE_HEADER Zone, ULONG BlockSize,
PVOID InitialSegment, ULONG InitialSegmentSize)
/*
* FUNCTION: Initalizes a zone header
* ARGUMENTS:
* Zone = zone header to be initialized
* BlockSize = Size (in bytes) of the allocation size of the zone
* InitialSegment = Initial segment of storage allocated by the
* caller
* InitialSegmentSize = Initial size of the segment
*/
{
unsigned int i;
PZONE_SEGMENT seg;
PZONE_ENTRY entry;
Zone->FreeList.Next=NULL;
Zone->SegmentList.Next=NULL;
Zone->BlockSize=BlockSize;
Zone->TotalSegmentSize = InitialSegmentSize;
seg = (PZONE_SEGMENT)InitialSegment;
seg->size = InitialSegmentSize;
PushEntryList(&Zone->SegmentList,&seg->Entry);
entry = (PZONE_ENTRY)( ((PVOID)seg) + sizeof(ZONE_SEGMENT) );
for (i=0;i<(InitialSegmentSize / BlockSize);i++)
{
PushEntryList(&Zone->FreeList,&entry->Entry);
entry = (PZONE_ENTRY)(((PVOID)entry) + sizeof(ZONE_ENTRY) + BlockSize);
}
}
PVOID ExInterlockedFreeToZone(PZONE_HEADER Zone, PVOID Block,
PKSPIN_LOCK Lock)
{
KIRQL oldlvl;
PVOID ret;
KeAcquireSpinLock(Lock,&oldlvl);
ret=ExFreeToZone(Zone,Block);
KeReleaseSpinLock(Lock,oldlvl);
return(ret);
}
PVOID ExInterlockedAllocateFromZone(PZONE_HEADER Zone, PKSPIN_LOCK Lock)
{
PVOID ret;
KIRQL oldlvl;
KeAcquireSpinLock(Lock,&oldlvl);
ret=ExAllocateFromZone(Zone);
KeReleaseSpinLock(Lock,oldlvl);
return(ret);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,174 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ob/handle.c
* PURPOSE: Managing handles
* PROGRAMMER: David Welch (welch@mcmail.com)
* REVISION HISTORY:
* 17/06/98: Created
*/
/* INCLUDES ****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/objmgr.h>
#include <internal/string.h>
#include <internal/pool.h>
#define NDEBUG
#include <internal/debug.h>
/* TYPES *******************************************************************/
/*
* PURPOSE: Defines a handle
*/
typedef struct
{
PVOID obj;
} HANDLE_REP;
#define HANDLE_BLOCK_ENTRIES ((PAGESIZE-sizeof(LIST_ENTRY))/sizeof(HANDLE_REP))
/*
* PURPOSE: Defines a page's worth of handles
*/
typedef struct
{
LIST_ENTRY entry;
HANDLE_REP handles[HANDLE_BLOCK_ENTRIES];
} HANDLE_BLOCK;
/* GLOBALS *****************************************************************/
/*
* PURPOSE: Head of the list of handle blocks
*/
LIST_ENTRY handle_list_head = {NULL,NULL};
KSPIN_LOCK handle_list_lock;
/* FUNCTIONS ***************************************************************/
VOID ObjDestroyHandleTable(VOID)
/*
* FUNCTION: Destroys the current process's handle table
* NOTE: No references to handles in the table should be made during this
* operation
*/
{
PLIST_ENTRY current=ExInterlockedRemoveHeadList(&handle_list_head,
&handle_list_lock);
unsigned int i;
while (current!=NULL)
{
HANDLE_BLOCK* blk = (HANDLE_BLOCK *)current;
/*
* Deference every handle in block
*/
for (i=0;i<HANDLE_BLOCK_ENTRIES;i++)
{
ObDereferenceObject(blk->handles[i].obj);
}
/*
* Free the block
*/
ExFreePool(blk);
current = ExInterlockedRemoveHeadList(&handle_list_head,
&handle_list_lock);
}
}
VOID ObjInitializeHandleTable(HANDLE parent)
/*
* FUNCTION: Initializes a handle table for the current process
* ARGUMENTS:
* parent = Parent process (or NULL if this is the first process)
*/
{
InitializeListHead(&handle_list_head);
KeInitializeSpinLock(&handle_list_lock);
}
PVOID ObGetObjectByHandle(HANDLE h)
/*
* FUNCTION: Translate a handle to the corresponding object
* ARGUMENTS:
* h = Handle to translate
* RETURNS: The object
*/
{
LIST_ENTRY* current = handle_list_head.Flink;
unsigned int handle = ((unsigned int)h) - 1;
unsigned int count=handle/HANDLE_BLOCK_ENTRIES;
HANDLE_BLOCK* blk = NULL;
unsigned int i;
for (i=0;i<count;i++)
{
current = current->Flink;
if (current==NULL)
{
return(NULL);
}
}
blk = (HANDLE_BLOCK *)current;
return(blk->handles[handle%HANDLE_BLOCK_ENTRIES].obj);
}
HANDLE ObAddHandle(PVOID obj)
/*
* FUNCTION: Add a handle referencing an object
* ARGUMENTS:
* obj = Object body that the handle should refer to
* RETURNS: The created handle
* NOTE: THe handle is valid only in the context of the current process
*/
{
LIST_ENTRY* current = handle_list_head.Flink;
unsigned int handle=1;
unsigned int i;
HANDLE_BLOCK* new_blk = NULL;
DPRINT("ObAddHandle(obj %)\n",obj);
/*
* Scan through the currently allocated handle blocks looking for a free
* slot
*/
while (current!=NULL)
{
HANDLE_BLOCK* blk = (HANDLE_BLOCK *)current;
DPRINT("Current %x\n",current);
for (i=0;i<HANDLE_BLOCK_ENTRIES;i++)
{
DPRINT("Considering slot %d containing %x\n",i,blk->handles[i]);
if (blk->handles[i].obj==NULL)
{
blk->handles[i].obj=obj;
return((HANDLE)(handle+i));
}
}
handle = handle + HANDLE_BLOCK_ENTRIES;
current = current->Flink;
}
/*
* Add a new handle block to the end of the list
*/
new_blk = (HANDLE_BLOCK *)ExAllocatePool(NonPagedPool,sizeof(HANDLE_BLOCK));
memset(new_blk,0,sizeof(HANDLE_BLOCK));
ExInterlockedInsertTailList(&handle_list_head,&new_blk->entry,
&handle_list_lock);
new_blk->handles[0].obj=obj;
return((HANDLE)handle);
}

View file

@ -0,0 +1,363 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ob/namespc.c
* PURPOSE: Manages the system namespace
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 22/05/98: Created
*/
/* INCLUDES ***************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/objmgr.h>
#include <internal/string.h>
#include <internal/kernel.h>
#include <wstring.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ****************************************************************/
OBJECT_TYPE DirectoryObjectType = {{0,0,NULL},
0,
0,
ULONG_MAX,
ULONG_MAX,
sizeof(DEVICE_OBJECT),
0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
static struct
{
OBJECT_HEADER hdr;
// DIRECTORY_OBJECT directory;
LIST_ENTRY head;
} namespc_root;
/* FUNCTIONS **************************************************************/
void ObjNamespcInit(void)
/*
* FUNCTION: Initialize the object manager namespace
*/
{
ANSI_STRING ansi_str;
ObInitializeObjectHeader(OBJTYP_DIRECTORY,NULL,&namespc_root.hdr);
InitializeListHead(&namespc_root.head);
RtlInitAnsiString(&ansi_str,"Directory");
RtlAnsiStringToUnicodeString(&DirectoryObjectType.TypeName,&ansi_str,
TRUE);
ObRegisterType(OBJTYP_DIRECTORY,&DirectoryObjectType);
}
NTSTATUS ZwCreateDirectoryObject(PHANDLE DirectoryHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes)
/*
* FUNCTION: Creates or opens a directory object (a container for other
* objects)
* ARGUMENTS:
* DirectoryHandle (OUT) = Caller supplied storage for the handle
* of the directory
* DesiredAccess = Access desired to the directory
* ObjectAttributes = Object attributes initialized with
* InitializeObjectAttributes
* RETURNS: Status
*/
{
PDIRECTORY_OBJECT dir;
dir = ObGenericCreateObject(DirectoryHandle,DesiredAccess,ObjectAttributes,
OBJTYP_DIRECTORY);
/*
* Initialize the object body
*/
InitializeListHead(&dir->head);
return(STATUS_SUCCESS);
}
PWSTR Rtlstrrchr(PUNICODE_STRING string, WCHAR c)
{
int i;
DPRINT("string->Length %d\n",string->Length);
for (i=(string->Length-1);i>=0;i--)
{
if (string->Buffer[i]==c)
{
return(&string->Buffer[i]);
}
}
return(NULL);
}
VOID InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes,
PUNICODE_STRING ObjectName,
ULONG Attributes,
HANDLE RootDirectory,
PSECURITY_DESCRIPTOR SecurityDescriptor)
/*
* FUNCTION: Sets up a parameter of type OBJECT_ATTRIBUTES for a
* subsequent call to ZwCreateXXX or ZwOpenXXX
* ARGUMENTS:
* InitializedAttributes (OUT) = Caller supplied storage for the
* object attributes
* ObjectName = Full path name for object
* Attributes = Attributes for the object
* RootDirectory = Where the object should be placed or NULL
* SecurityDescriptor = Ignored
*
* NOTE:
* Either ObjectName is a fully qualified pathname or a path relative
* to RootDirectory
*/
{
UNICODE_STRING path;
PWSTR name = NULL;
PDIRECTORY_OBJECT parent_dir;
DPRINT("InitalizeObjectAttributes(ObjectName %w)\n",ObjectName->Buffer);
if (RootDirectory!=NULL)
{
ObReferenceObjectByHandle(RootDirectory,DIRECTORY_TRAVERSE,NULL,
UserMode,(PVOID*)&parent_dir,NULL);
}
else
{
parent_dir = HEADER_TO_BODY((POBJECT_HEADER)&namespc_root);
}
ASSERT_IRQL(PASSIVE_LEVEL);
path.Buffer = ExAllocatePool(NonPagedPool,
ObjectName->Length*sizeof(WCHAR));
path.MaximumLength = ObjectName->Length;
RtlCopyUnicodeString(&path,ObjectName);
/*
* Seperate the path into the name of the object and the name of its
* direct parent directory
*/
name = Rtlstrrchr(&path,'\\');
*name=0;
/*
* Find the objects parent directory
*/
DPRINT("parent_dir %x\n",&(parent_dir->Type));
parent_dir=(PDIRECTORY_OBJECT)ObLookupObject(parent_dir,&path);
if (parent_dir==NULL)
{
return;
}
/*
* Make sure the parent directory doesn't disappear
*/
ObReferenceObjectByPointer(parent_dir,DIRECTORY_CREATE_OBJECT,NULL,
UserMode);
InitializedAttributes->Attributes = Attributes;
InitializedAttributes->parent = parent_dir;
RtlInitUnicodeString(&InitializedAttributes->name,name+1);
InitializedAttributes->path = path;
}
int _wcscmp(wchar_t* str1, wchar_t* str2)
{
while ( (*str1)==(*str2) )
{
str1++;
str2++;
if ( (*str1)==((wchar_t)0) && (*str1)==((wchar_t)0) )
{
return(0);
}
}
return( (*str1) - (*str2) );
}
static PVOID ObDirLookup(PDIRECTORY_OBJECT dir, PWSTR name)
/*
* FUNCTION: Looks up an entry within a namespace directory
* ARGUMENTS:
* dir = Directory to lookup in
* name = Entry name to find
* RETURNS: A pointer to the object body if found
* NULL otherwise
*/
{
LIST_ENTRY* current = ((PDIRECTORY_OBJECT)dir)->head.Flink;
POBJECT_HEADER current_obj;
DPRINT("ObDirLookup(dir %x, name %w\n",dir,name);
while (current!=NULL)
{
current_obj = CONTAINING_RECORD(current,OBJECT_HEADER,entry);
DPRINT("current_obj->name %w\n",current_obj->name.Buffer);
if ( _wcscmp(current_obj->name.Buffer, name)==0)
{
return(current_obj);
}
current = current->Flink;
}
return(NULL);
}
VOID ObCreateEntry(PDIRECTORY_OBJECT parent,POBJECT_HEADER Object)
/*
* FUNCTION: Add an entry to a namespace directory
* ARGUMENTS:
* parent = directory to add in
* name = Name to give the entry
* Object = Header of the object to add the entry for
*/
{
DPRINT("ObjCreateEntry(%x,%x,%x,%w)\n",parent,Object,Object->name.Buffer,
Object->name.Buffer);
DPRINT("root type %d\n",namespc_root.hdr.Type);
DPRINT("%x\n",&(namespc_root.hdr.Type));
DPRINT("type %x\n",&(parent->Type));
DPRINT("type %x\n",&(BODY_TO_HEADER(parent)->Type));
DPRINT("type %d\n",parent->Type);
assert(parent->Type == OBJTYP_DIRECTORY);
/*
* Insert ourselves in our parents list
*/
InsertTailList(&parent->head,&Object->entry);
}
wchar_t* _wcschr(wchar_t* str, wchar_t ch)
{
while ((*str)!=((wchar_t)0))
{
if ((*str)==ch)
{
return(str);
}
str++;
}
return(NULL);
}
PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string)
/*
* FUNCTION: Lookup an object within the system namespc
* ARGUMENTS:
* root = Directory to start lookup from
* _string = Pathname to lookup
* RETURNS: On success a pointer to the object body
* On failure NULL
*/
{
PWSTR current;
PWSTR next;
PDIRECTORY_OBJECT current_dir = root;
POBJECT_HEADER current_hdr;
PWSTR string;
DPRINT("root %x string %w\n",root,_string->Buffer);
if (root==NULL)
{
current_dir = HEADER_TO_BODY(&(namespc_root.hdr));
}
/*
* Bit of a hack this
*/
if (_string->Buffer[0]==0)
{
DPRINT("current_dir %x\n",current_dir);
DPRINT("type %d\n",current_dir->Type);
return(current_dir);
}
string=(PWSTR)ExAllocatePool(NonPagedPool,(_string->Length+1)*2);
wcscpy(string,_string->Buffer);
DPRINT("string = %w\n",string);
if (string[0]!='\\')
{
printk("(%s:%d) Non absolute pathname passed to %s\n",__FILE__,
__LINE__,__FUNCTION__);
return(NULL);
}
current = string+1;
DPRINT("current %w\n",current);
next = _wcschr(string+1,'\\');
if (next!=NULL)
{
*next=0;
}
DPRINT("next %x\n",next);
while (next!=NULL)
{
DPRINT("Scanning %w next %w current %x\n",current,next+1,
current_dir);
/*
* Check the current object is a directory
*/
if (current_dir->Type!=OBJTYP_DIRECTORY)
{
printk("(%s:%d) Bad path component\n",__FILE__,
__LINE__);
ExFreePool(string);
return(NULL);
}
/*
* Lookup the next component of the path in the directory
*/
current_hdr=(PDIRECTORY_OBJECT)ObDirLookup(current_dir,current);
if (current_hdr==NULL)
{
printk("(%s:%d) Path component not found\n",__FILE__,
__LINE__);
ExFreePool(string);
return(NULL);
}
current_dir = HEADER_TO_BODY(current_hdr);
current = next+1;
next = _wcschr(next+1,'\\');
if (next!=NULL)
{
*next=0;
}
}
DPRINT("current_dir %x current %x\n",current_dir,current);
DPRINT("current %w\n",current);
current_hdr = ObDirLookup(current_dir,current);
if (current_hdr==NULL)
{
ExFreePool(string);
return(NULL);
}
DPRINT("Returning %x %x\n",current_hdr,HEADER_TO_BODY(current_hdr));
ExFreePool(string);
return(HEADER_TO_BODY(current_hdr));
}

View file

@ -0,0 +1,230 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ob/object.c
* PURPOSE: Implements generic object managment functions
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 10/06/98: Created
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/objmgr.h>
#include <internal/kernel.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ****************************************************************/
/*
* List of pointers to object types
*/
static POBJECT_TYPE ObjectTypes[OBJTYP_MAX]={NULL,};
/* FUNCTIONS ************************************************************/
NTSTATUS ZwMakeTemporaryObject(HANDLE Handle)
{
UNIMPLEMENTED;
}
PVOID ObGenericCreateObject(PHANDLE Handle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
CSHORT Type)
{
POBJECT_HEADER hdr = NULL;
DPRINT("ObGenericCreateObject(Handle %x ObjectAttributes %x Type %x)\n",
Handle,ObjectAttributes,Type);
/*
* Allocate the object body and header
*/
hdr=(POBJECT_HEADER)ExAllocatePool(NonPagedPool,OBJECT_ALLOC_SIZE(Type));
if (hdr==NULL)
{
return(NULL);
}
/*
* Initialize the object header
*/
if (ObjectAttributes!=NULL)
{
ObInitializeObjectHeader(Type,&ObjectAttributes->name,hdr);
}
else
{
ObInitializeObjectHeader(Type,NULL,hdr);
}
// DPRINT("ObjectAttributes->parent->Type %d\n",
// ObjectAttributes->parent->Type);
if (ObjectAttributes!=NULL)
{
/*
* Add the object to its parent directory
*/
DPRINT("hdr->name.Buffer %x\n",hdr->name.Buffer);
ObCreateEntry(ObjectAttributes->parent,hdr);
}
DPRINT("Handle %x\n",Handle);
*Handle = ObAddHandle(HEADER_TO_BODY(hdr));
return(HEADER_TO_BODY(hdr));
}
ULONG ObSizeOf(CSHORT Type)
{
return(ObjectTypes[Type]->PagedPoolCharge);
}
VOID ObRegisterType(CSHORT id, POBJECT_TYPE type)
/*
* FUNCTION: Registers a new type of object
* ARGUMENTS:
* typ = Pointer to the type definition to register
*/
{
DPRINT("ObRegisterType(id %d, type %x)\n",id,type);
ObjectTypes[id]=type;
}
VOID ObInitializeObjectHeader(CSHORT id, PUNICODE_STRING name,
POBJECT_HEADER obj)
/*
* FUNCTION: Creates a new object
* ARGUMENT:
* id = Identifier for the type of object
* obj = Pointer to the header of the object
*/
{
if (name!=NULL)
{
DPRINT("ObInitializeObjectHeader(id %d name %w obj %x)\n",id,
name->Buffer,obj);
}
else
{
DPRINT("ObInitializeObjectHeader(id %d name %x obj %x)\n",id,
name,obj);
}
obj->HandleCount = 0;
obj->RefCount = 0;
obj->Type = id;
if (name==NULL)
{
obj->name.Length=0;
obj->name.Buffer=NULL;
}
else
{
obj->name.Length = 0;
obj->name.MaximumLength = name->Length;
obj->name.Buffer = ExAllocatePool(NonPagedPool,
(name->Length+1)*sizeof(WCHAR));
DPRINT("obj->name.Buffer %x\n",obj->name.Buffer);
RtlCopyUnicodeString(&obj->name,name);
DPRINT("obj->name.Buffer %x\n",obj->name.Buffer);
}
}
NTSTATUS ObReferenceObjectByPointer(PVOID ObjectBody,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode)
/*
* FUNCTION: Increments the pointer reference count for a given object
* ARGUMENTS:
* ObjectBody = Object's body
* DesiredAccess = Desired access to the object
* ObjectType = Points to the object type structure
* AccessMode = Type of access check to perform
* RETURNS: Status
*/
{
POBJECT_HEADER Object = BODY_TO_HEADER(ObjectBody);
DPRINT("ObReferenceObjectByPointer(%x %x)\n",ObjectBody,Object);
Object->RefCount++;
return(STATUS_SUCCESS);
}
VOID ObDereferenceObject(PVOID ObjectBody)
/*
* FUNCTION: Decrements a given object's reference count and performs
* retention checks
* ARGUMENTS:
* ObjectBody = Body of the object
*/
{
POBJECT_HEADER Object = BODY_TO_HEADER(ObjectBody);
Object->RefCount--;
}
NTSTATUS ZwClose(HANDLE Handle)
/*
* FUNCTION: Closes a handle reference to an object
* ARGUMENTS:
* Handle = handle to close
* RETURNS: Status
*/
{
PVOID ObjectBody;
ASSERT_IRQL(PASSIVE_LEVEL);
ObjectBody = ObGetObjectByHandle(Handle);
if (ObjectBody == NULL)
{
return(STATUS_INVALID_HANDLE);
}
ObDereferenceObject(ObjectBody);
return(STATUS_SUCCESS);
}
NTSTATUS ObReferenceObjectByHandle(HANDLE Handle,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode,
PVOID* Object,
POBJECT_HANDLE_INFORMATION
HandleInformationPtr
)
/*
* FUNCTION: Increments the reference count for an object and returns a
* pointer to its body
* ARGUMENTS:
* Handle = Handle for the object
* DesiredAccess = Desired access to the object
* ObjectType
* AccessMode
* Object (OUT) = Points to the object body on return
* HandleInformation (OUT) = Contains information about the handle
* on return
* RETURNS: Status
*/
{
PVOID ObjectBody;
ASSERT_IRQL(PASSIVE_LEVEL);
assert(HandleInformation==NULL);
assert(Object!=NULL);
assert(Handle!=NULL);
ObjectBody = ObGetObjectByHandle(Handle);
if (ObjectBody == NULL)
{
return(STATUS_INVALID_HANDLE);
}
return(ObReferenceObjectByPointer(ObjectBody,DesiredAccess,
ObjectType,AccessMode));
}

Some files were not shown because too many files have changed in this diff Show more