clean up and standardize types across the codebase, unify atomic operations, improve UTF-8 handling throughout the system, remove obsolete input and named queue interfaces, redesign process preparation and creation, tighten IPC and service boundaries, improve error handling and reliability, minor documentation cleanup, fix doom surfaces, fix panic in ini parsing.
This commit is contained in:
1 parent
899225f551
commit
c0ad63c27f
226 files changed
+6562
-4147
No files matched your search
+13
-16
@@ -1,10 +1,11 @@
|
||||
// Kernel capability handles. This file owns process-local handle identity, grant delegation, and revocation.
|
||||
|
||||
#include <ntlite/atomic.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <intrin.h>
|
||||
#include <kernel/ke_handle.h>
|
||||
#include <kernel/ke_process.h>
|
||||
#include <kernel/ke_named_queue.h>
|
||||
#include <kernel/ke_debug.h>
|
||||
#include <kernel/io_file.h>
|
||||
#include <kernel/ke_audio.h>
|
||||
@@ -14,8 +15,8 @@
|
||||
#include <ntlite/port.h>
|
||||
|
||||
typedef struct CAPABILITY_GRANT {
|
||||
volatile long RefCount;
|
||||
volatile long Revoked;
|
||||
volatile int32_t RefCount;
|
||||
volatile int32_t Revoked;
|
||||
uint32_t Depth;
|
||||
SYS_RIGHTS MaximumAccess;
|
||||
OBJECT* Target;
|
||||
@@ -62,7 +63,7 @@ static KE_HANDLE_ENTRY* KiFindHandleLocked(KE_HANDLE_TABLE* table, SYS_HANDLE ha
|
||||
// Acquires one grant reference while its owner still stabilizes the pointer.
|
||||
static void KiReferenceGrant(CAPABILITY_GRANT* grant) {
|
||||
if (!grant) return;
|
||||
long refs = _InterlockedIncrement(&grant->RefCount);
|
||||
int32_t refs = NtlAtomicIncrement32(&grant->RefCount);
|
||||
if (refs <= 1) {
|
||||
KePanic(KE_PANIC_CODE_GENERIC,
|
||||
"capability: invalid grant reference grant=0x%016llX refs=%ld\n",
|
||||
@@ -74,7 +75,7 @@ static void KiReferenceGrant(CAPABILITY_GRANT* grant) {
|
||||
// Releases one grant and recursively drops its immutable parent chain.
|
||||
static void KiDereferenceGrant(CAPABILITY_GRANT* grant) {
|
||||
while (grant) {
|
||||
long refs = _InterlockedDecrement(&grant->RefCount);
|
||||
int32_t refs = NtlAtomicDecrement32(&grant->RefCount);
|
||||
if (refs > 0) return;
|
||||
if (refs < 0) {
|
||||
KePanic(KE_PANIC_CODE_GENERIC,
|
||||
@@ -92,17 +93,17 @@ static void KiDereferenceGrant(CAPABILITY_GRANT* grant) {
|
||||
}
|
||||
|
||||
// Returns whether a grant and every ancestor remain unrevoked.
|
||||
static int KiGrantIsActive(const CAPABILITY_GRANT* grant) {
|
||||
static bool KiGrantIsActive(const CAPABILITY_GRANT* grant) {
|
||||
const CAPABILITY_GRANT* current = grant;
|
||||
uint32_t depth = 0;
|
||||
while (current) {
|
||||
if (_InterlockedCompareExchange((volatile long*)¤t->Revoked, 0, 0) != 0)
|
||||
return 0;
|
||||
if (NtlAtomicLoad32(¤t->Revoked) != 0)
|
||||
return false;
|
||||
current = current->Parent;
|
||||
if (++depth > KE_CAPABILITY_MAX_DEPTH)
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Creates a root grant and takes the target object's lifetime reference.
|
||||
@@ -246,7 +247,7 @@ SYS_RIGHTS KeGetValidHandleRights(OBJECT_TYPE type) {
|
||||
return management | SYS_RIGHT_QUERY | SYS_RIGHT_WAIT | SYS_EVENT_RIGHT_SIGNAL;
|
||||
case ObjectTypeQueue:
|
||||
return management | SYS_RIGHT_QUERY | SYS_QUEUE_RIGHT_SEND |
|
||||
SYS_QUEUE_RIGHT_RECEIVE | SYS_QUEUE_RIGHT_PUBLISH;
|
||||
SYS_QUEUE_RIGHT_RECEIVE;
|
||||
case ObjectTypeFile:
|
||||
return management | SYS_RIGHT_QUERY | SYS_FILE_RIGHT_READ_DATA |
|
||||
SYS_FILE_RIGHT_WRITE_DATA | SYS_FILE_RIGHT_LOCK |
|
||||
@@ -271,8 +272,6 @@ SYS_RIGHTS KeGetValidHandleRights(OBJECT_TYPE type) {
|
||||
return management | SYS_RIGHT_QUERY | SYS_RIGHT_WAIT |
|
||||
SYS_SURFACE_RIGHT_MAP_READ | SYS_SURFACE_RIGHT_MAP_WRITE |
|
||||
SYS_SURFACE_RIGHT_COMMIT;
|
||||
case ObjectTypeInputQueue:
|
||||
return management | SYS_RIGHT_QUERY | SYS_RIGHT_WAIT | SYS_INPUT_QUEUE_RIGHT_READ;
|
||||
case ObjectTypeTimer:
|
||||
return management | SYS_RIGHT_QUERY | SYS_RIGHT_WAIT | SYS_TIMER_RIGHT_SET;
|
||||
case ObjectTypeDisplayClock:
|
||||
@@ -395,7 +394,6 @@ KSTATUS KeCloseHandle(PROCESS* process, SYS_HANDLE handle) {
|
||||
OBJECT* object = entry->Grant->Target;
|
||||
if (object && object->Type == ObjectTypeFile)
|
||||
closeStatus = IoFlushFile((FILE_OBJECT*)object);
|
||||
KeNamedQueueUnpublishHandle(process, handle, object);
|
||||
KiHandleClosed(object);
|
||||
KiDereferenceGrant(entry->Grant);
|
||||
MmFreePool(entry);
|
||||
@@ -533,7 +531,7 @@ KSTATUS KeRevokeHandle(PROCESS* process, SYS_HANDLE handle) {
|
||||
return NTLSTATUS_CAPABILITY_REVOKED;
|
||||
}
|
||||
|
||||
_InterlockedExchange(&entry->Grant->Revoked, 1);
|
||||
NtlAtomicExchange32(&entry->Grant->Revoked, 1);
|
||||
KeReleaseSpinlock(&table->Lock, flags);
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
@@ -757,7 +755,6 @@ void KeRundownHandleTable(PROCESS* process) {
|
||||
if (!entry) break;
|
||||
|
||||
OBJECT* object = entry->Grant->Target;
|
||||
KeNamedQueueUnpublishHandle(process, entry->Handle, object);
|
||||
KiHandleClosed(object);
|
||||
KiDereferenceGrant(entry->Grant);
|
||||
MmFreePool(entry);
|
||||
|
||||
Reference in new issue
Block a user