Files
nt-lite/code/public/ntlite/ddk/object.h
T

75 lines
2.4 KiB
C

// Public nt-lite DDK object declarations.
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
// Kernel object type identifiers used by the shared object header.
typedef enum OBJECT_TYPE {
ObjectTypeProcess = 1,
ObjectTypeThread = 2,
ObjectTypeMutex = 3,
ObjectTypeSemaphore = 4,
ObjectTypeEvent = 5,
ObjectTypeQueue = 6,
ObjectTypeFile = 7,
ObjectTypeDir = 8,
ObjectTypeAsyncIo = 9,
ObjectTypeSocket = 10,
ObjectTypeDevice = 11,
ObjectTypeDriver = 12,
ObjectTypeUsbDevice = 13,
ObjectTypeUsbPipe = 14,
ObjectTypeFileMapping = 15,
ObjectTypeSurface = 16,
ObjectTypeImageSection = 18,
ObjectTypeTimer = 19,
ObjectTypeDisplayClock = 20,
ObjectTypeAudioEndpoint = 21,
ObjectTypeAudioStream = 22,
ObjectTypeSecurityContext = 23,
ObjectTypePort = 24,
ObjectTypeVolume = 25,
ObjectTypeVolumeManager = 26,
ObjectTypeInputManager = 27,
ObjectTypeDisplayManager = 28,
ObjectTypePipeEndpoint = 29,
ObjectTypeServiceRegistration = 30,
} OBJECT_TYPE;
typedef enum OBJECT_LIFETIME_STATE {
ObjectAlive = 1,
ObjectDying,
ObjectDead
} OBJECT_LIFETIME_STATE;
#define OBJECT_FLAG_INSERTED 0x00000001u
#define OBJECT_FLAG_UNLINKED 0x00000002u
// Object header embedded by kernel and driver-owned reference-counted objects.
typedef struct OBJECT {
OBJECT_TYPE Type;
volatile int32_t RefCount;
volatile int32_t LifetimeState;
volatile uint32_t Flags;
void (*Destroy)(struct OBJECT* self);
} OBJECT;
// Initializes an embedded object header with one live reference.
__declspec(dllexport) void ObInitializeObjectHeader(OBJECT* object, OBJECT_TYPE type);
// Acquires a reference only while the object is alive and inserted.
// The caller must stabilize the pointer through its owning lock or reference.
__declspec(dllexport) bool ObTryReferenceObject(OBJECT* object);
// Increments an object's reference count and stops on stale-object misuse.
__declspec(dllexport) void ObReferenceObject(OBJECT* object);
// Decrements an object's reference count and destroys it when it reaches zero.
__declspec(dllexport) void ObDereferenceObject(OBJECT* object);
// Allocates a zeroed object of the given size.
__declspec(dllexport) OBJECT* ObAllocateObject(OBJECT_TYPE type, size_t size);