kernel
Loading...
Searching...
No Matches
me.h
Go to the documentation of this file.
1#ifndef MATANEL_EXECUTIVE_H
2#define MATANEL_EXECUTIVE_H
3
4/*++
5
6Module Name:
7
8 me.h
9
10Purpose:
11
12 This module contains the header files & prototypes required for the executive layer of MatanelOS.
13
14Author:
15
16 slep (Matanel) 2025.
17
18Revision History:
19
20--*/
21
22#define MSR_IA32_DEBUGCTL 0x1D9
23#define MSR_LASTBRANCH_TOS 0x1C9
24#define MSR_LASTBRANCH_FROM0 0x680
25#define MSR_LASTBRANCH_TO0 0x6C0
26#define DPC_TARGET_CURRENT 0xFF
27
28#include <stdint.h>
29#include <stdbool.h>
30#include "annotations.h"
31#include "macros.h"
32#include "../mtstatus.h"
35
36// Other includes:
37#include "mm.h"
38#include "mh.h"
39#include "ms.h"
40#include "core.h"
41// ------------------ UNIONS ------------------
42
43// ------------------ ENUMERATORS ------------------
44
45#define TICK_MS 4
51
56
64
65
66// DEPRECATED - New list should be in BUGCODES.H explaining each with its parameters. TODO
67// Bugcheck error code enums, use same exception list from CPU.
68typedef enum _BUGCHECK_CODES {
89 MEMORY_MAP_SIZE_OVERRUN = 0xBEEF, // The memory map has grown beyond the limit (unused).
90 MANUALLY_INITIATED_CRASH = 0xBABE, // A function has manually initiated a bugcheck for testing/unknown reasons with this specific code.
91 BAD_PAGING = 0xBAD, // A paging function that fails when it shouldn't.
92 BLOCK_DEVICE_LIMIT_REACHED = 0x420, // Something tried to register a block device, but the limit has been reached, bugcheck system.
93 NULL_POINTER_DEREFERENCE = 0xDEAD, // Attempted dereference of a null pointer.
94 FILESYSTEM_PANIC = 0xFA11, // FileSystem PANIC, usually something wrong has happened
95 UNABLE_TO_INIT_TRACELASTFUNC = 0xACE, // TraceLastFunc init failed in kernel_main
96 FRAME_LIMIT_REACHED = 0xBADA55, // frame limit reached when trying to allocate a physical frame.
97 IRQL_NOT_LESS_OR_EQUAL = 0x1337, // Access to functions while going over the max IRQL set for them. Or lowering to higher IRQL than current IRQL.
98 IRQL_NOT_GREATER_OR_EQUAL = 0x1338, // Raising IRQL to an IRQL level that is lower than the current one.
99 INVALID_IRQL_SUPPLIED = 0x69420, // Invalid IRQL supplied to raising / lowering IRQL.
100 NULL_CTX_RECEIVED = 0xF1FA, // A null context frame has been received to a function.
101 THREAD_EXIT_FAILURE = 0x123123FF, // A thread exitted but did not schedule (somehow).
102 BAD_AHCI_COUNT, // AHCI Count has went over the required limit
103 AHCI_INIT_FAILED, // Initialization of AHCI has failed..
104 MEMORY_LIMIT_REACHED, // The amount of physical memory has reached its maximum, allocation has failed.
105 HEAP_ALLOCATION_FAILED, // Allocating from the HEAP failed for an unknown reason.
106 NULL_THREAD, // A thread given to the scheduler is NULL.
107 FATAL_IRQL_CORRUPTION, // IRQL Has been corrupted, somehow. Probably a buffer overflow.
108 THREAD_ID_CREATION_FAILURE, // Creation of a TID (Thread ID) has failed due to reaching maximum TIDs in use by the system.
109 FRAME_ALLOCATION_FAILED, // Allocating a physical frame from the frame bitmap has failed.
110 FRAME_BITMAP_CREATION_FAILURE, // Creating the frame bitmap resulted in a failure.
111 ASSERTION_FAILURE, // Runtime Assertion Failure (assert())
116 GUARD_PAGE_DEREFERENCE, // A guard page has been dereferenced.
117 KERNEL_STACK_OVERFLOWN, // A kernel stack has been overflown (and didnt hit the guard page) (detected by canary)
118 KMODE_EXCEPTION_NOT_HANDLED, // A kernel mode exception hasn't been handled (an __except block hasn't been handled)
139
140// ------------------ STRUCTURES ------------------
141
142typedef void (*DebugCallback)(void*);
143
148
149typedef struct _WAIT_BLOCK {
150 struct _SINGLE_LINKED_LIST WaitBlockList; // List entry of the current wait block of the thread.
151 void* Object; // Pointer to the object it is currently waiting on (indicated which one by WaitReason)
152 enum _WAIT_REASON WaitReason; // Defines which object the thread is currently waiting on (indicated by the _WAIT_REASON Enumerator)
154
155typedef struct _TRAP_FRAME {
156 uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
157 uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax;
158 uint64_t vector;
159 uint64_t error_code;
160 uint64_t rip;
161 uint64_t cs;
162 uint64_t rflags;
163 uint64_t rsp;
164 uint64_t ss;
166
167typedef enum _DEBUG_ACCESS_MODE {
168 DEBUG_ACCESS_EXECUTE = 0b00, // Break on instruction execution
169 DEBUG_ACCESS_WRITE = 0b01, // Break on data writes
170 DEBUG_ACCESS_IO = 0b10, // Break on I/O read or write (legacy)
171 DEBUG_ACCESS_READWRITE = 0b11 // Break on data reads or writes
173
174typedef enum _DEBUG_LENGTH {
177 DEBUG_LEN_QWORD = 0b10, // Only valid in long mode
180
181typedef struct _DBG_CALLBACK_INFO {
182 void* Address; /* breakpoint address (DRx) */
183 PTRAP_FRAME trap; /* trap frame captured */
184 int BreakIdx; /* which DRx (0..3) fired */
185 uint64_t Dr6; /* raw DR6 value at time of trap */
187
188// Forward declaration
189struct _DPC;
190
191typedef void (DEFERRED_ROUTINE)(
192 struct _DPC* Dpc,
193 void* DeferredContext,
194 void* SystemArgument1,
195 void* SystemArgument2
196 );
197
199
200typedef struct _DPC {
201 // Next/Prev pointers for doubly linked list of DPCs.
203
204 // Pointer to deferred routine.
209
210 // Points to the DPC_DATA struct of the current processor when queued
211 // If NULL, the DPC is NOT queued.
212 volatile void* DpcData;
213
214 // Determines if it goes to tail or head of queue.
216
217 // Determines to which CPU this DPC is supposed to be executed on, this allows multiple re-entracy.
218 uint8_t CpuNumber; // 0xFF means current CPU, else its per lapic id.
220
221typedef enum _CPU_FLAGS {
222 CPU_ONLINE = 1 << 0, // 0b0001
223 CPU_HALTED = 1 << 1, // 0b0010
224 CPU_DOING_IPI = 1 << 2, // 0b0100
225 CPU_UNAVAILABLE = 1 << 3 // 0b1000
227
228// DPC Embedded struct into CPU.
229typedef struct _DPC_DATA {
232 volatile uint32_t DpcQueueDepth;
233 volatile uint32_t DpcCount; // Statistics
235
236typedef struct _APC {
237 uint8_t unsetupped;
239
240#define LASTFUNC_BUFFER_SIZE 128
241#define LASTFUNC_HISTORY_SIZE 25
242
243#define KERNEL_CS 0x08 // Entry 1: Kernel Code
244#define KERNEL_DS 0x10 // Entry 2: Kernel Data
245#define KERNEL_SS 0x10 // Same as KERNEL_DS (data segment used for stack)
246#define USER_DS 0x1B // Entry 3: User Data
247#define USER_CS 0x23 // Entry 4: User Code (CPL=3)
248#define USER_SS USER_DS // Same as USER_DS
249#define INITIAL_RFLAGS 0x202
250#define USER_RFLAGS 0x246 // IF=1, IOPL=0
251
259
260typedef struct _IPROCESS {
261 uintptr_t PageDirectoryPhysical; // Physical Address of the PML4 of the process.
262 struct _SPINLOCK ProcessLock; // Internal Spinlock for process field manipulation safety.
263 uint32_t ProcessState; // Current process state.
265
266typedef struct _ITHREAD {
267 struct _TRAP_FRAME TrapRegisters; // Trap Registers used for context switching, saving, and alternation.
268 uint32_t ThreadState; // Current thread state, presented by the THREAD_STATE enumerator.
269 void* StackBase; // Base of the thread's stack (allocated), used for also freeing it by the memory manager (Mm).
270 bool IsLargeStack; // Indicates if the stack allocated to the thread is a LargeStack or not. (Kernel stack only)
271 void* KernelStack; // The threads stack when in kernel space.
272 enum _TimeSliceTicks TimeSlice; // Current timeslice remaining until thread's forceful pre-emption.
273 enum _TimeSliceTicks TimeSliceAllocated; // Original timeslice given to the thread, used for restoration when it's current one is over.
274 enum _PRIVILEGE_MODE PreviousMode; // Previous mode of the thread (used to indicate whether it called a kernel service in kernel mode, or in user mode)
275 struct _APC_STATE ApcState; // Current thread's APC State.
276 struct _WAIT_BLOCK WaitBlock; // Wait block of the current thread, defines a list of which events the thread is waiting on (mutex event, general sleeping)
278
279// Note to self: Re-organize this to match more of the KPRCB style, that style is way more consistent across the board (Separates between scheduler and Processor, yada yada)
280typedef struct _PROCESSOR {
281 struct _PROCESSOR* self; // A pointer to the current CPU Struct, used internally by functions, see MtStealThread in scheduler.c, or MeGetCurrentProcessor.
282 // If this is ever switched from a 4 byte integer, check assembly for direct cmp. (like in sleep.asm)
283 enum _IRQL currentIrql; // An integer that represents the current interrupt request level of the CPU. Declares which LAPIC & IOAPIC interrupts are masked
284 volatile bool schedulerEnabled; // A boolean value that indicates if the scheduler is allowed to be called after an interrupt.
285 struct _ITHREAD* currentThread; // Current thread that is being executed in the CPU.
286 struct _Queue readyQueue; // Queue of thread pointers to be scheduled.
287 uint32_t ID; // ID is also the index for cpus (e.g cpus[3] so .ID is 3)
288 uint32_t lapic_ID; // Internal APIC id of the CPU.
289 void* VirtStackTop; // Pointer to top of CPU Stack.
290 void* tss; // Task State Segment ptr.
291 void* Rsp0; // General RSP for interrupts & syscalls (entry only) & exceptions.
292 void* IstPFStackTop; // Page Fault IST Stack
293 void* IstDFStackTop; // Double Fault IST Stack
294 volatile uint64_t flags; // CPU Flags (CPU_FLAGS enum), contains the current state of the CPU, in bitfields.
295 bool schedulePending; // A boolean value that indicates if a schedule is currently pending on the CPU
296 uint64_t* gdt; // A pointer to the current GDT of the CPU (set in the CPUs AP entry), does not include BSP GDT.
297 struct _DPC* CurrentDeferredRoutine; // Current deferred routine that is executed by the CPU.
298 struct _ETHREAD* idleThread; // Idle thread for the current CPU.
299 volatile uint64_t MailboxLock; // 0 = Free, 1 = Locked by a sender
300 volatile uint64_t IpiSeq;
301 volatile enum _CPU_ACTION IpiAction; // IPI Action specified in the function.
302 volatile IPI_PARAMS IpiParameter; // Optional parameter for IPI's, usually used for functions, primarily TLB Shootdowns.
303 volatile uint32_t* LapicAddressVirt; // Virtual address of the Local APIC MMIO Address (mapped)
304 uintptr_t LapicAddressPhys; // Physical address of the Local APIC MMIO
305
306 /* Statically Special Allocated DPCs */
309 /* End Statically Special Allocated DPCs */
310
311 // Additional DPC Fields
312 DPC_DATA DpcData; // The main DPC queue
313 volatile bool DpcRoutineActive; // TRUE if inside MeRetireDPCs
314 volatile uint32_t TimerRequest; // Non-zero if timers need processing (unused)
315 uintptr_t TimerHand; // Context for timer expiration (unused)
316
317 // Additional APC Fields
318 volatile bool ApcRoutineActive; // True if inside MeRetireAPCs
319
320 // Fields for depth and performance analysis
324
325 // Interrupt requests
326 volatile bool DpcInterruptRequested; // True if we requested an interrupt to handle deferred procedure calls.
327 volatile bool ApcInterruptRequested; // (Undeveloped yet) True if we requested an interrupt for APCs.
328
329 // Scheduler Lock
331
332 // Per CPU Lookaside pools
335
336 struct _DEBUG_ENTRY DebugEntry[4]; // Per CPU Structure that contains debug entries for each debug register.
339
340 // Zombie Thread (for deferred reference deletion)
342
343 // Syscall data
344 uint64_t UserRsp; // User saved RSP during syscall handling.
345 uint64_t SystemCallCount; // Counter of system call that have been executed in the system. (including invalid ones)
347
348// ------------------ FUNCTIONS ------------------
349
350
352void
354 IN enum _BUGCHECK_CODES BugCheckCode
355);
356
358void
360 IN enum _BUGCHECK_CODES BugCheckCode,
361 IN void* BugCheckParameter1,
362 IN void* BugCheckParameter2,
363 IN void* BugCheckParameter3,
364 IN void* BugCheckParameter4
365);
366
370 // Routine Description:
371 // This function returns the current address of the PROCESSOR struct. - Note this should only be used in kernel mode with the appropriate GS value.
372{
373 return (PPROCESSOR)__readgsqword(0); // Only works because we have a self pointer at offset 0 in the struct.
374}
375
377void
379
380{
382 // Acquire the spinlock. (FIXME MsAcquireSpinlockAtSynchLevel(&cpu->SchedulerLock)
383 while (__sync_lock_test_and_set(&cpu->SchedulerLock.locked, 1)) {
384 __asm__ volatile("pause" ::: "memory"); /* x86 pause — CPU relax hint */
385 }
386 // Memory barrier to prevent instruction reordering
387 __asm__ volatile("" ::: "memory");
388 cpu->schedulerEnabled = false;
389}
390
392void
394
395{
397 cpu->schedulerEnabled = true;
398 // Release the spinlock. (FIXME MsReleaseSpinlockFromSynchLevel(&cpu->SchedulerLock)
399 __asm__ volatile("" ::: "memory");
400 __sync_lock_release(&cpu->SchedulerLock.locked);
401}
402
403extern uint32_t g_cpuCount;
404
406uint8_t
408
409{
410 return (uint8_t)g_cpuCount; // The reason we cast to uint8_t is because we would never have more than 255 Cpus in the system, not guranteed, though, :)
411}
412
414IRQL
416
417/*++
418
419 Routine description : Retrieves the IRQL of the current processor.
420
421 Arguments:
422
423 None.
424
425 Return Values:
426
427 Current IRQL at time of call.
428
429--*/
430
431{
432#ifdef DEBUG
433 IRQL returningIrql = (IRQL)__readgsqword(FIELD_OFFSET(PROCESSOR, currentIrql));
434 if (returningIrql > HIGH_LEVEL) MeBugCheck(INVALID_IRQL_SUPPLIED);
435 return returningIrql;
436#else
437 return (IRQL)__readgsqword(FIELD_OFFSET(PROCESSOR, currentIrql));
438#endif
439}
440
441
445
446/*++
447
448 Routine description : Retrieves the current running thread on the processor.
449
450 Arguments:
451
452 None.
453
454 Return Values:
455
456 Current thread running on time of call (this thread)
457
458--*/
459
460{
461 return (PITHREAD)__readgsqword(FIELD_OFFSET(PROCESSOR, currentThread));
462}
463
465bool
467
468{
469 return (bool)__readgsqword(FIELD_OFFSET(PROCESSOR, DpcRoutineActive));
470}
471
473bool
475 void
476)
477
478{
480}
481
483uint32_t
485 void
486)
487
488{
489 // Return the Index of the CPUs array, stored in the ID field of the current Processor block.
490 return (uint32_t)__readgsqword(FIELD_OFFSET(PROCESSOR, ID));
491}
492
493void
495 IN PPROCESSOR CPU,
496 IN bool InitializeStandardRoutine,
497 IN bool AreYouAP
498);
499
500void
502 IN IRQL NewIrql,
503 OUT PIRQL OldIrql
504);
505
506void
508 IN IRQL NewIrql
509);
510
511void
513 IN IRQL NewIrql
514);
515
516void
518 IN PDPC Dpc,
519 IN uint32_t CpuNumber
520);
521
522void
524 IN PDPC DpcAllocated,
525 IN PDEFERRED_ROUTINE DeferredRoutine,
526 IN void* DeferredContext,
527 IN DPC_PRIORITY DeferredPriority
528);
529
530bool
532 IN PDPC Dpc,
533 IN void* SystemArgument1,
534 IN void* SystemArgument2
535);
536
537bool
539 IN PDPC Dpc
540);
541
542void
544 void
545);
546
547void CleanStacks(DPC* dpc, void* thread, void* allocatedDPC, void* arg4);
548void ReapOb(DPC* dpc, void* DeferredContext, void* SystemArgument1, void* SystemArgument2);
549void InitScheduler(void);
550
551void
553 IN PIPROCESS Process,
554 OUT PAPC_STATE ApcState
555);
556
557void
559 IN PAPC_STATE ApcState
560);
561
563void
564Schedule(void);
565
569 void
570)
571
572{
573 PITHREAD CurrentThread = MeGetCurrentThread();
574 if (CurrentThread) {
575 return CurrentThread->PreviousMode;
576 }
577 else {
578 // No thread is active on the current processor (not even a kernel one), this is early init.
579 return KernelMode;
580 }
581}
582
583void
585 IN bool EnabledBefore
586);
587
588bool
590 void
591);
592
593bool
595 void
596);
597
598// smp.c
599PPROCESSOR MeGetProcessorBlock(uint8_t ProcessorNumber);
600
601#endif
#define FORCEINLINE
Definition annotations.h:23
#define NORETURN
Definition annotations.h:14
#define IN
Definition annotations.h:8
#define OUT
Definition annotations.h:9
struct _TRAP_FRAME TRAP_FRAME
Definition core.h:55
struct _IPROCESS IPROCESS
Definition core.h:39
struct _ITHREAD ITHREAD
Definition core.h:35
IPROCESS * PIPROCESS
Definition core.h:40
struct _PROCESSOR PROCESSOR
Definition core.h:47
_IRQL
Definition core.h:14
@ HIGH_LEVEL
Definition core.h:22
PROCESSOR * PPROCESSOR
Definition core.h:48
enum _IRQL IRQL
enum _IRQL * PIRQL
EPROCESS * PEPROCESS
Definition core.h:52
ITHREAD * PITHREAD
Definition core.h:36
TRAP_FRAME * PTRAP_FRAME
Definition core.h:56
struct _DOUBLY_LINKED_LIST DOUBLY_LINKED_LIST
FORCEINLINE uint64_t __readgsqword(uint64_t offset)
Definition intrin.h:243
#define FIELD_OFFSET(t, f)
Definition macros.h:67
NORETURN void Schedule(void)
Definition scheduler.c:110
struct _WAIT_BLOCK * PWAIT_BLOCK
enum _TimeSliceTicks * PTimeSliceTicks
bool MeDisableInterrupts(void)
Definition irql.c:203
void MeDetachProcess(IN PAPC_STATE ApcState)
Definition attach.c:90
NORETURN void MeBugCheck(IN enum _BUGCHECK_CODES BugCheckCode)
Definition bugcheck.c:220
struct _ITHREAD * PITHREAD
struct _APC * PAPC
void MeRetireDPCs(void)
Definition dpc.c:223
struct _APC_STATE APC_STATE
_BUGCHECK_CODES
Definition me.h:68
@ MANUALLY_INITIATED_CRASH
Definition me.h:90
@ NULL_POINTER_DEREFERENCE
Definition me.h:93
@ CRITICAL_PROCESS_DIED
Definition me.h:135
@ OVERFLOW
Definition me.h:73
@ FILESYSTEM_PANIC
Definition me.h:94
@ BAD_POOL_CALLER
Definition me.h:122
@ MEMORY_LIMIT_REACHED
Definition me.h:104
@ SEVERE_MACHINE_CHECK
Definition me.h:87
@ ATTEMPTED_WRITE_TO_READONLY_MEMORY
Definition me.h:123
@ COPROCESSOR_SEGMENT_OVERRUN
Definition me.h:78
@ FRAME_LIMIT_REACHED
Definition me.h:96
@ HEAP_ALLOCATION_FAILED
Definition me.h:105
@ NO_COPROCESSOR
Definition me.h:76
@ CID_TABLE_NULL
Definition me.h:133
@ MEMORY_CORRUPT_HEADER
Definition me.h:113
@ PAGE_FAULT
Definition me.h:83
@ PAGE_FAULT_IN_FREED_NONPAGED_POOL
Definition me.h:125
@ PSMGR_INIT_FAILED
Definition me.h:130
@ FLOATING_POINT_ERROR
Definition me.h:85
@ GUARD_PAGE_DEREFERENCE
Definition me.h:116
@ MEMORY_INVALID_FREE
Definition me.h:112
@ IRQL_NOT_GREATER_OR_EQUAL
Definition me.h:98
@ THREAD_EXIT_FAILURE
Definition me.h:101
@ ASSERTION_FAILURE
Definition me.h:111
@ PFN_DATABASE_INIT_FAILURE
Definition me.h:119
@ MEMORY_MAP_SIZE_OVERRUN
Custom ones.
Definition me.h:89
@ ATTEMPTED_SWITCH_FROM_DPC
Definition me.h:127
@ SINGLE_STEP
Definition me.h:70
@ KMODE_EXCEPTION_NOT_HANDLED
Definition me.h:118
@ DIVIDE_BY_ZERO
Definition me.h:69
@ NULL_THREAD
Definition me.h:106
@ KERNEL_STACK_OVERFLOWN
Definition me.h:117
@ BREAKPOINT
Definition me.h:72
@ ALIGNMENT_CHECK
Definition me.h:86
@ BAD_PAGING
Definition me.h:91
@ BLOCK_DEVICE_LIMIT_REACHED
Definition me.h:92
@ NON_MASKABLE_INTERRUPT
Definition me.h:71
@ INVALID_OPCODE
Definition me.h:75
@ POOL_INIT_FAILURE
Definition me.h:121
@ INVALID_TSS
Definition me.h:79
@ FRAME_BITMAP_CREATION_FAILURE
Definition me.h:110
@ BAD_AHCI_COUNT
Definition me.h:102
@ NULL_CTX_RECEIVED
Definition me.h:100
@ MEMORY_DOUBLE_FREE
Definition me.h:114
@ INVALID_INTERRUPT_REQUEST
Definition me.h:128
@ FRAME_ALLOCATION_FAILED
Definition me.h:109
@ DPC_NOT_INITIALIZED
Definition me.h:132
@ UNABLE_TO_INIT_TRACELASTFUNC
Definition me.h:95
@ INVALID_INITIALIZATION_PHASE
Definition me.h:124
@ THREAD_ID_CREATION_FAILURE
Definition me.h:108
@ PAGE_FAULT_IN_FREED_PAGED_POOL
Definition me.h:126
@ PSWORKER_INIT_FAILED
Definition me.h:131
@ DOUBLE_FAULT
Definition me.h:77
@ MANUALLY_INITIATED_CRASH2
Definition me.h:129
@ STACK_SEGMENT_OVERRUN
Definition me.h:81
@ GENERAL_PROTECTION_FAULT
Definition me.h:82
@ VA_SPACE_INIT_FAILURE
Definition me.h:120
@ ATTEMPTED_EXECUTE_OF_NOEXECUTE_MEMORY
Definition me.h:137
@ SEGMENT_SELECTOR_NOTPRESENT
Definition me.h:80
@ AHCI_INIT_FAILED
Definition me.h:103
@ WORKER_THREAD_ATTEMPTED_TERMINATION
Definition me.h:136
@ INVALID_PROCESS_ATTACH_ATTEMPT
Definition me.h:134
@ IRQL_NOT_LESS_OR_EQUAL
Definition me.h:97
@ BOUNDS_CHECK
Definition me.h:74
@ INVALID_IRQL_SUPPLIED
Definition me.h:99
@ FATAL_IRQL_CORRUPTION
Definition me.h:107
@ RESERVED
Definition me.h:84
@ MEMORY_CORRUPT_FOOTER
Definition me.h:115
void MeRaiseIrql(IN IRQL NewIrql, OUT PIRQL OldIrql)
Definition irql.c:62
FORCEINLINE PITHREAD MeGetCurrentThread(void)
Definition me.h:444
FORCEINLINE bool MeIsExecutingDpc(void)
Definition me.h:466
bool MeAreInterruptsEnabled(void)
Definition irql.c:227
FORCEINLINE bool MeIsAttachedProcess(void)
Definition me.h:474
bool MeRemoveQueueDpc(IN PDPC Dpc)
Definition dpc.c:168
enum _DEBUG_ACCESS_MODE DEBUG_ACCESS_MODE
void DEFERRED_ROUTINE(struct _DPC *Dpc, void *DeferredContext, void *SystemArgument1, void *SystemArgument2)
Definition me.h:191
bool MeInsertQueueDpc(IN PDPC Dpc, IN void *SystemArgument1, IN void *SystemArgument2)
Definition dpc.c:48
PPROCESSOR MeGetProcessorBlock(uint8_t ProcessorNumber)
Definition smp.c:196
FORCEINLINE IRQL MeGetCurrentIrql(void)
Definition me.h:415
NORETURN void MeBugCheckEx(IN enum _BUGCHECK_CODES BugCheckCode, IN void *BugCheckParameter1, IN void *BugCheckParameter2, IN void *BugCheckParameter3, IN void *BugCheckParameter4)
Definition bugcheck.c:245
enum _DPC_PRIORITY DPC_PRIORITY
struct _DPC_DATA * PDPC_DATA
void(* DebugCallback)(void *)
Definition me.h:142
struct _TRAP_FRAME * PTRAP_FRAME
_WAIT_REASON
Definition me.h:52
@ Sleeping
Definition me.h:54
@ Mutex
Definition me.h:53
void MeEnableInterrupts(IN bool EnabledBefore)
Definition irql.c:216
FORCEINLINE uint32_t MeGetCurrentProcessorNumber(void)
Definition me.h:484
struct _DBG_CALLBACK_INFO DBG_CALLBACK_INFO
DEFERRED_ROUTINE * PDEFERRED_ROUTINE
Definition me.h:198
_DEBUG_LENGTH
Definition me.h:174
@ DEBUG_LEN_QWORD
Definition me.h:177
@ DEBUG_LEN_WORD
Definition me.h:176
@ DEBUG_LEN_BYTE
Definition me.h:175
@ DEBUG_LEN_DWORD
Definition me.h:178
void MeInitializeDpc(IN PDPC DpcAllocated, IN PDEFERRED_ROUTINE DeferredRoutine, IN void *DeferredContext, IN DPC_PRIORITY DeferredPriority)
Definition dpc.c:385
FORCEINLINE void MeReleaseSchedulerLock(void)
Definition me.h:393
void MeInitializeProcessor(IN PPROCESSOR CPU, IN bool InitializeStandardRoutine, IN bool AreYouAP)
Definition meinit.c:172
enum _DEBUG_LENGTH DEBUG_LENGTH
struct _APC APC
_DPC_PRIORITY
Definition me.h:57
@ SYSTEM_PRIORITY
Definition me.h:62
@ MEDIUM_PRIORITY
Definition me.h:60
@ NO_PRIORITY
Definition me.h:58
@ HIGH_PRIORITY
Definition me.h:61
@ LOW_PRIORITY
Definition me.h:59
struct _DPC DPC
void MeSetTargetProcessorDpc(IN PDPC Dpc, IN uint32_t CpuNumber)
Definition dpc.c:351
void CleanStacks(DPC *dpc, void *thread, void *allocatedDPC, void *arg4)
struct _APC_STATE * PAPC_STATE
FORCEINLINE uint8_t MeGetActiveProcessorCount(void)
Definition me.h:407
struct _DEBUG_ENTRY DEBUG_ENTRY
void ReapOb(DPC *dpc, void *DeferredContext, void *SystemArgument1, void *SystemArgument2)
Definition dpc.c:19
void MeAttachProcess(IN PIPROCESS Process, OUT PAPC_STATE ApcState)
Definition attach.c:24
void _MeSetIrql(IN IRQL NewIrql)
Definition irql.c:158
struct _DPC_DATA DPC_DATA
void MeLowerIrql(IN IRQL NewIrql)
Definition irql.c:102
enum _CPU_FLAGS CPU_FLAGS
FORCEINLINE void MeAcquireSchedulerLock(void)
Definition me.h:378
FORCEINLINE PPROCESSOR MeGetCurrentProcessor(void)
Definition me.h:369
enum _TimeSliceTicks TimeSliceTicks
FORCEINLINE PRIVILEGE_MODE MeGetPreviousMode(void)
Definition me.h:568
struct _WAIT_BLOCK WAIT_BLOCK
_CPU_FLAGS
Definition me.h:221
@ CPU_ONLINE
Definition me.h:222
@ CPU_UNAVAILABLE
Definition me.h:225
@ CPU_HALTED
Definition me.h:223
@ CPU_DOING_IPI
Definition me.h:224
enum _BUGCHECK_CODES BUGCHECK_CODES
_DEBUG_ACCESS_MODE
Definition me.h:167
@ DEBUG_ACCESS_READWRITE
Definition me.h:171
@ DEBUG_ACCESS_EXECUTE
Definition me.h:168
@ DEBUG_ACCESS_IO
Definition me.h:170
@ DEBUG_ACCESS_WRITE
Definition me.h:169
enum _WAIT_REASON WAIT_REASON
void InitScheduler(void)
Definition scheduler.c:27
struct _DPC * PDPC
_TimeSliceTicks
Definition me.h:46
@ HIGH_TIMESLICE_TICKS
Definition me.h:49
@ LOW_TIMESLICE_TICKS
Definition me.h:47
@ DEFAULT_TIMESLICE_TICKS
Definition me.h:48
#define TICK_MS
Definition me.h:45
_CPU_ACTION
Definition mh.h:88
struct _IPI_PARAMS IPI_PARAMS
#define MAX_POOL_DESCRIPTORS
Definition mm.h:174
struct _POOL_DESCRIPTOR POOL_DESCRIPTOR
enum _PRIVILEGE_MODE PRIVILEGE_MODE
_PRIVILEGE_MODE
Definition mm.h:370
@ KernelMode
Definition mm.h:371
struct _SPINLOCK SPINLOCK
uint32_t g_cpuCount
Definition smp.c:128
bool SavedThreadAttached
Definition me.h:257
bool AttachedToProcess
Definition me.h:255
IRQL PreviousIrql
Definition me.h:256
uint64_t SavedCr3
Definition me.h:253
PEPROCESS SavedApcProcess
Definition me.h:254
Definition me.h:236
uint8_t unsetupped
Definition me.h:237
PTRAP_FRAME trap
Definition me.h:183
uint64_t Dr6
Definition me.h:185
void * Address
Definition me.h:182
DebugCallback Callback
Definition me.h:146
void * Address
Definition me.h:145
volatile uint32_t DpcQueueDepth
Definition me.h:232
SPINLOCK DpcLock
Definition me.h:231
DOUBLY_LINKED_LIST DpcListHead
Definition me.h:230
volatile uint32_t DpcCount
Definition me.h:233
Definition me.h:200
DOUBLY_LINKED_LIST DpcListEntry
Definition me.h:202
void * SystemArgument1
Definition me.h:207
volatile void * DpcData
Definition me.h:212
void * DeferredContext
Definition me.h:206
void * SystemArgument2
Definition me.h:208
enum _DPC_PRIORITY priority
Definition me.h:215
uint8_t CpuNumber
Definition me.h:218
PDEFERRED_ROUTINE DeferredRoutine
Definition me.h:205
Definition ps.h:182
struct _SPINLOCK ProcessLock
Definition me.h:262
uint32_t ProcessState
Definition me.h:263
uintptr_t PageDirectoryPhysical
Definition me.h:261
Definition me.h:266
uint32_t ThreadState
Definition me.h:268
void * StackBase
Definition me.h:269
bool IsLargeStack
Definition me.h:270
enum _PRIVILEGE_MODE PreviousMode
Definition me.h:274
enum _TimeSliceTicks TimeSlice
Definition me.h:272
void * KernelStack
Definition me.h:271
struct _WAIT_BLOCK WaitBlock
Definition me.h:276
struct _TRAP_FRAME TrapRegisters
Definition me.h:267
enum _TimeSliceTicks TimeSliceAllocated
Definition me.h:273
struct _APC_STATE ApcState
Definition me.h:275
struct _DPC ReaperDPC
Definition me.h:308
uint64_t UserRsp
Definition me.h:344
uint32_t DpcRequestRate
Definition me.h:323
struct _DPC * CurrentDeferredRoutine
Definition me.h:297
struct _Queue readyQueue
Definition me.h:286
volatile IPI_PARAMS IpiParameter
Definition me.h:302
volatile bool schedulerEnabled
Definition me.h:284
struct _DEBUG_ENTRY DebugEntry[4]
Definition me.h:336
PITHREAD ZombieThread
Definition me.h:341
void * IstIpiStackTop
Definition me.h:338
SPINLOCK SchedulerLock
Definition me.h:330
uint32_t MinimumDpcRate
Definition me.h:322
uint32_t ID
Definition me.h:287
uintptr_t TimerHand
Definition me.h:315
struct _ETHREAD * idleThread
Definition me.h:298
enum _IRQL currentIrql
Definition me.h:283
uint32_t lapic_ID
Definition me.h:288
volatile bool DpcRoutineActive
Definition me.h:313
struct _ITHREAD * currentThread
Definition me.h:285
volatile uint64_t flags
Definition me.h:294
POOL_DESCRIPTOR LookasidePoolsNx[MAX_POOL_DESCRIPTORS]
Definition me.h:334
uint32_t MaximumDpcQueueDepth
Definition me.h:321
uint64_t * gdt
Definition me.h:296
volatile bool DpcInterruptRequested
Definition me.h:326
DPC_DATA DpcData
Definition me.h:312
void * IstTimerStackTop
Definition me.h:337
volatile uint64_t MailboxLock
Definition me.h:299
void * Rsp0
Definition me.h:291
volatile uint32_t TimerRequest
Definition me.h:314
void * tss
Definition me.h:290
volatile uint64_t IpiSeq
Definition me.h:300
enum _CPU_ACTION IpiAction
Definition me.h:301
struct _DPC TimerExpirationDPC
Definition me.h:307
POOL_DESCRIPTOR LookasidePools[MAX_POOL_DESCRIPTORS]
Definition me.h:333
struct _PROCESSOR * self
Definition me.h:281
bool schedulePending
Definition me.h:295
volatile bool ApcRoutineActive
Definition me.h:318
uintptr_t LapicAddressPhys
Definition me.h:304
void * VirtStackTop
Definition me.h:289
void * IstDFStackTop
Definition me.h:293
uint64_t SystemCallCount
Definition me.h:345
void * IstPFStackTop
Definition me.h:292
volatile uint32_t * LapicAddressVirt
Definition me.h:303
volatile bool ApcInterruptRequested
Definition me.h:327
Definition ms.h:52
Definition ms.h:36
volatile uint32_t locked
Definition ms.h:37
uint64_t r14
Definition me.h:156
uint64_t r8
Definition me.h:156
uint64_t r9
Definition me.h:156
uint64_t rbx
Definition me.h:157
uint64_t ss
Definition me.h:164
uint64_t rdi
Definition me.h:157
uint64_t r10
Definition me.h:156
uint64_t vector
Definition me.h:158
uint64_t r13
Definition me.h:156
uint64_t rdx
Definition me.h:157
uint64_t r12
Definition me.h:156
uint64_t r15
Definition me.h:156
uint64_t rsp
Definition me.h:163
uint64_t rip
Definition me.h:160
uint64_t rcx
Definition me.h:157
uint64_t rbp
Definition me.h:157
uint64_t r11
Definition me.h:156
uint64_t error_code
Definition me.h:159
uint64_t rflags
Definition me.h:162
uint64_t rsi
Definition me.h:157
uint64_t cs
Definition me.h:161
uint64_t rax
Definition me.h:157
void * Object
Definition me.h:151
struct _SINGLE_LINKED_LIST WaitBlockList
Definition me.h:150
enum _WAIT_REASON WaitReason
Definition me.h:152