introduce a stable NTL_DDK driver ABI to replace direct HAL_API and kernel-header access in drivers, add code/kernel/io_ddk.c and code/public/ntlite/ddk/ headers, change DriverEntry to take (const NTL_DDK*, NTL_DRIVER_INIT*), update kmain to build the DDK once via IoInitializeDdk/IoGetDdk and hand it to both boot and runtime drivers, downgrade code/public/ntlite/ddi/io_driver.h to a legacy I/O model header pulling from ntlite/ddk instead of kernel internals, move code/third_party/lwip into code/drivers/net/lwip/third_party, fix up lwip_sources.txt and build.c include paths to match, split build.c's single CFLAGS macro into COMMON/KERNEL/USER/BOOT/DRIVER cflags.
This commit is contained in:
1 parent
08329516ba
commit
485a6bbfe7
385 files changed
+1822
-1079
No files matched your search
@@ -0,0 +1,86 @@
|
||||
// Public nt-lite DDK synchronization declarations.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <intrin.h>
|
||||
#include <ntlite/ddi/hal_api.h>
|
||||
#include <ntlite/ddk/irql.h>
|
||||
|
||||
// Legacy spinlock storage used by current driver-visible objects.
|
||||
typedef struct SPINLOCK {
|
||||
volatile long Locked;
|
||||
} SPINLOCK;
|
||||
|
||||
#define SPINLOCK_INIT { 0 }
|
||||
|
||||
#define KI_SPINLOCK_IRQL_SHIFT ((unsigned)(sizeof(uintptr_t) * 8u - 8u))
|
||||
#define KI_SPINLOCK_FLAGS_MASK (~(((uintptr_t)0xFFu) << KI_SPINLOCK_IRQL_SHIFT))
|
||||
|
||||
// Packs the interrupt flags and prior IRQL into a spinlock cookie.
|
||||
static __forceinline uintptr_t KiPackSpinlockCookie(uintptr_t flags, KIRQL oldIrql) {
|
||||
return (flags & KI_SPINLOCK_FLAGS_MASK) |
|
||||
(((uintptr_t)oldIrql) << KI_SPINLOCK_IRQL_SHIFT);
|
||||
}
|
||||
|
||||
// Extracts the saved interrupt flags from a spinlock cookie.
|
||||
static __forceinline uintptr_t KiSpinlockCookieFlags(uintptr_t cookie) {
|
||||
return cookie & KI_SPINLOCK_FLAGS_MASK;
|
||||
}
|
||||
|
||||
// Extracts the saved IRQL from a spinlock cookie.
|
||||
static __forceinline KIRQL KiSpinlockCookieIrql(uintptr_t cookie) {
|
||||
return (KIRQL)(cookie >> KI_SPINLOCK_IRQL_SHIFT);
|
||||
}
|
||||
|
||||
// Acquires a spinlock and raises to at least DISPATCH_LEVEL.
|
||||
static __forceinline uintptr_t KeAcquireSpinlock(SPINLOCK* sl) {
|
||||
uintptr_t flags = HalDisableInterrupts();
|
||||
|
||||
KIRQL oldIrql = KeGetCurrentIrql();
|
||||
if (oldIrql < DISPATCH_LEVEL)
|
||||
KeRaiseIrql(DISPATCH_LEVEL);
|
||||
|
||||
while (_InterlockedCompareExchange(&sl->Locked, 1, 0) != 0)
|
||||
_mm_pause();
|
||||
|
||||
return KiPackSpinlockCookie(flags, oldIrql);
|
||||
}
|
||||
|
||||
// Releases a spinlock and restores the caller's saved IRQL and interrupt state.
|
||||
static __forceinline void KeReleaseSpinlock(SPINLOCK* sl, uintptr_t cookie) {
|
||||
uintptr_t flags = KiSpinlockCookieFlags(cookie);
|
||||
KIRQL oldIrql = KiSpinlockCookieIrql(cookie);
|
||||
|
||||
_InterlockedExchange(&sl->Locked, 0);
|
||||
KeLowerIrql(oldIrql);
|
||||
HalRestoreInterrupts(flags);
|
||||
}
|
||||
|
||||
// Attempts to acquire a spinlock without blocking.
|
||||
static __forceinline int KeTryAcquireSpinlock(SPINLOCK* sl, uintptr_t* outCookie) {
|
||||
uintptr_t flags = HalDisableInterrupts();
|
||||
|
||||
KIRQL oldIrql = KeGetCurrentIrql();
|
||||
if (oldIrql < DISPATCH_LEVEL)
|
||||
KeRaiseIrql(DISPATCH_LEVEL);
|
||||
|
||||
if (_InterlockedCompareExchange(&sl->Locked, 1, 0) == 0) {
|
||||
*outCookie = KiPackSpinlockCookie(flags, oldIrql);
|
||||
return 1;
|
||||
}
|
||||
|
||||
KeLowerIrql(oldIrql);
|
||||
HalRestoreInterrupts(flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Acquires a spinlock for DPC-level code.
|
||||
static __forceinline uintptr_t KeAcquireSpinlockRaiseToDpc(SPINLOCK* sl) {
|
||||
return KeAcquireSpinlock(sl);
|
||||
}
|
||||
|
||||
// Releases a spinlock acquired for DPC-level code.
|
||||
static __forceinline void KeReleaseSpinlockFromDpc(SPINLOCK* sl, uintptr_t cookie) {
|
||||
KeReleaseSpinlock(sl, cookie);
|
||||
}
|
||||
Reference in new issue
Block a user