Fork me on GitHub

root/mm/alloc.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. kmalloc
  2. kfree

   1 /*
   2  * fiwix/mm/alloc.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/mm.h>
   9 #include <fiwix/stdio.h>
  10 #include <fiwix/string.h>
  11 
  12 /*
  13  * The implementation of kernel memory allocation is extremely simple, it works
  14  * with a granularity of PAGE_SIZE (4096 bytes). There is indeed a lot of room
  15  * for improvements here.
  16  */
  17 unsigned int kmalloc(void)
  18 {
  19         struct page *pg;
  20         unsigned int addr;
  21 
  22         if((pg = get_free_page())) {
  23                 addr = pg->page << PAGE_SHIFT;
  24                 return P2V(addr);
  25         }
  26 
  27         /* out of memory! */
  28         return 0;
  29 }
  30 
  31 void kfree(unsigned int addr)
  32 {
  33         addr = V2P(addr);
  34         release_page(addr >> PAGE_SHIFT);
  35 }

/* [previous][next][first][last][top][bottom][index][help] */