diff --git a/paw/stos/head/ob/object.h b/paw/stos/head/ob/object.h index a7c6bd1..668b3bc 100644 --- a/paw/stos/head/ob/object.h +++ b/paw/stos/head/ob/object.h @@ -9,11 +9,15 @@ #ifndef _OB_OBJECT_H_ #define _OB_OBJECT_H_ 1 +#include #include /* Maximum size of system object names */ #define OBJECT_NAMESZ 32 +/* Slut tag for pool allocations */ +#define OBJECT_POOL_TAG 'OB' + /* * Represents valid object types * @@ -52,4 +56,17 @@ typedef struct { USIZE EntryCount; } OBJECT_DIRECTORY; +/* + * Allocate and create a new objec + * + * @Name: Object name + * @Type: Object type + * @Data: Actual backing data + * @Result: Result is written here + */ +ST_STATUS ObCreateObject( + const CHAR *Name, OBJECT_TYPE Type, + VOID *Data, ST_OBJECT **Result +); + #endif /* !_OB_OBJECT_H_ */ diff --git a/paw/stos/ke/Makefile b/paw/stos/ke/Makefile index df70295..790ebff 100644 --- a/paw/stos/ke/Makefile +++ b/paw/stos/ke/Makefile @@ -16,6 +16,7 @@ CFILES += $(shell find ../lib -name "*.c") CFILES += $(shell find ../drivers -name "*.c") CFILES += $(shell find ../mm -name "*.c") CFILES += $(shell find ../ex -name "*.c") +CFILES += $(shell find ../ob -name "*.c") CFILES += $(shell find bpal -name "*.c") CFILES += $(shell find synch -name "*.c") DFILES = $(CFILES:.c=.d) diff --git a/paw/stos/ob/ob.c b/paw/stos/ob/ob.c new file mode 100644 index 0000000..d4061b4 --- /dev/null +++ b/paw/stos/ob/ob.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Object manager + * Author: Chloe M. + */ + +#include +#include +#include + +ST_STATUS +ObCreateObject(const CHAR *Name, OBJECT_TYPE Type, VOID *Data, ST_OBJECT **Result) +{ + ST_OBJECT *Object; + USIZE NameLen; + + if (Name == NULL || Result == NULL) { + return STATUS_INVALID_PARAM; + } + + NameLen = RtlStrLen(Name); + if (NameLen >= OBJECT_NAMESZ - 1) { + return STATUS_NAME_TOO_LONG; + } + + Object = ExAllocatePoolWithTag( + POOL_NON_PAGED, + sizeof(*Object), + OBJECT_POOL_TAG + ); + + if (Object == NULL) { + return STATUS_NO_MEMORY; + } + + RtlMemCpy(Object->Name, Name, NameLen); + Object->Name[NameLen] = '\0'; + Object->RefCount = 1; + Object->Type = Type; + Object->Data = Data; + *Result = Object; + return STATUS_SUCCESS; +}