#include #include #include #include #include #include #include #include Slab handleSlab; void Handle_GlobalInit() { Slab_Init(&handleSlab, "Handle Objects", sizeof(Handle), 16); } DEFINE_SLAB(Handle, &handleSlab); void Handle_Init(Process *proc) { int i; for (i = 0; i < PROCESS_HANDLE_SLOTS; i++) { TAILQ_INIT(&proc->handles[i]); } } uint64_t Handle_Add(Process *proc, Handle *handle) { int slot; handle->fd = proc->nextFD; proc->nextFD++; handle->processId = proc->pid; slot = handle->fd % PROCESS_HANDLE_SLOTS; TAILQ_INSERT_HEAD(&proc->handles[slot], handle, handleList); return handle->fd; } void Handle_Remove(Process *proc, Handle *handle) { int slot = handle->fd % PROCESS_HANDLE_SLOTS; TAILQ_REMOVE(&proc->handles[slot], handle, handleList); } Handle * Handle_Lookup(Process *proc, uint64_t fd) { int slot = fd % PROCESS_HANDLE_SLOTS; Handle *handle; TAILQ_FOREACH(handle, &proc->handles[slot], handleList) { if (handle->fd == fd) return handle; } return NULL; }