Files
nt-lite/code/kernel/ob_object.h
T

35 lines
1.1 KiB
C

#pragma once
// ob_object.h - executive object model
// Every resource the kernel tracks is a typed, reference-counted OBJECT.
// The OBJECT header must be the first member of any derived struct.
#include <stdint.h>
#include <stddef.h>
#include <ke_status.h>
typedef enum OBJECT_TYPE {
ObjectTypeProcess = 1,
ObjectTypeThread = 2,
ObjectTypeMutex = 3,
ObjectTypeSemaphore = 4,
ObjectTypeEvent = 5,
ObjectTypeQueue = 6,
ObjectTypeFile = 7,
ObjectTypeDir = 8,
} OBJECT_TYPE;
typedef struct OBJECT {
OBJECT_TYPE Type;
volatile long RefCount; // interlocked; long = 4 bytes on MSVC x64
void (*Destroy)(struct OBJECT* self);
} OBJECT;
// Increment the reference count. Call whenever ownership is shared.
void ObReferenceObject(OBJECT* object);
// Decrement. Calls Destroy() and frees the object when count reaches zero.
void ObDereferenceObject(OBJECT* object);
// Allocate a zeroed object of the given size from kernel pool.
// Caller must fill Type and Destroy before publishing the pointer.
OBJECT* ObAllocateObject(OBJECT_TYPE type, size_t size);