📄 malloc.c
字号:
/* * GeekOS memory allocation API * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu> * $Revision: 1.12 $ * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". */#include <geekos/screen.h>#include <geekos/int.h>#include <geekos/bget.h>#include <geekos/kassert.h>#include <geekos/malloc.h>/* * Initialize the heap starting at given address and occupying * specified number of bytes. */void Init_Heap(ulong_t start, ulong_t size){ /*Print("Creating kernel heap: start=%lx, size=%ld\n", start, size);*/ bpool((void*) start, size);}/* * Dynamically allocate a buffer of given size. * Returns null if there is not enough memory to satisfy the * allocation. */void* Malloc(ulong_t size){ void *result; bool iflag; KASSERT(size > 0); iflag = Begin_Int_Atomic(); result = bget(size); End_Int_Atomic(iflag); return result;}/* * Free a buffer allocated with Malloc() or Malloc(). */void Free(void* buf){ bool iflag; iflag = Begin_Int_Atomic(); brel(buf); End_Int_Atomic(iflag);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -