#include "memory/MemoryManager.h" #include "thread/Spinlock.h" #include Spinlock alloc_lock; extern "C" int liballoc_lock() { alloc_lock.acquire(); return !alloc_lock.locked(); // Sanity check: the spinlock should be locked (return 0) } extern "C" int liballoc_unlock() { alloc_lock.release(); return 0; // No sanity check this time because another thread could have acquired the lock the instant we let go of // it. } extern "C" void* liballoc_alloc(size_t count) { return MemoryManager::get_pages(count); } extern "C" int liballoc_free(void* addr, size_t count) { MemoryManager::release_pages(addr, count); return 0; }