Created
November 12, 2012 01:43
-
-
Save jontonsoup/4057083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************************** | |
* Title: Kernel Memory Allocator | |
* ------------------------------------------------------------------------- | |
* Purpose: Kernel memory allocator based on the resource map algorithm | |
* Author: Stefan Birrer | |
* Version: $Revision: 1.2 $ | |
* Last Modification: $Date: 2009/10/31 21:28:52 $ | |
* File: $RCSfile: kma_rm.c,v $ | |
* Copyright: 2004 Northwestern University | |
***************************************************************************/ | |
/*************************************************************************** | |
* ChangeLog: | |
* ------------------------------------------------------------------------- | |
* $Log: kma_rm.c,v $ | |
* Revision 1.2 2009/10/31 21:28:52 jot836 | |
* This is the current version of KMA project 3. | |
* It includes: | |
* - the most up-to-date handout (F'09) | |
* - updated skeleton including | |
* file-driven test harness, | |
* trace generator script, | |
* support for evaluating efficiency of algorithm (wasted memory), | |
* gnuplot support for plotting allocation and waste, | |
* set of traces for all students to use (including a makefile and README of the settings), | |
* - different version of the testsuite for use on the submission site, including: | |
* scoreboard Python scripts, which posts the top 5 scores on the course webpage | |
* | |
* Revision 1.1 2005/10/24 16:07:09 sbirrer | |
* - skeleton | |
* | |
* Revision 1.2 2004/11/05 15:45:56 sbirrer | |
* - added size as a parameter to kma_free | |
* | |
* Revision 1.1 2004/11/03 23:04:03 sbirrer | |
* - initial version for the kernel memory allocator project | |
* | |
***************************************************************************/ | |
#ifdef KMA_RM | |
#define __KMA_IMPL__ | |
/************System include***********************************************/ | |
#include <assert.h> | |
#include <stdlib.h> | |
/************Private include**********************************************/ | |
#include "kpage.h" | |
#include "kma.h" | |
/************Defines and Typedefs*****************************************/ | |
/* #defines and typedefs should have their names in all caps. | |
* Global variables begin with g. Global constants with k. Local | |
* variables should be in all lower case. When initializing | |
* structures and arrays, line everything up in neat columns. | |
*/ | |
typedef struct { | |
struct block* base; | |
int size; | |
} block; | |
/************Global Variables*********************************************/ | |
unsigned long *base = NULL; | |
/************Function Prototypes******************************************/ | |
void init(); | |
/************External Declaration*****************************************/ | |
/**************Implementation***********************************************/ | |
void init() | |
{ | |
kpage_t *page = get_page(); | |
base = (unsigned long *)page->ptr; | |
block* b = (block*) page->ptr; | |
b->base = page->ptr; | |
b->size = page->size; | |
} | |
void* | |
kma_malloc(kma_size_t size) | |
{ | |
if(base == NULL) | |
{ | |
init(); | |
} | |
else if(size > 8192) | |
{ | |
return NULL; | |
} | |
else | |
{ | |
} | |
} | |
void | |
kma_free(void* ptr, kma_size_t size) | |
{ | |
} | |
#endif // KMA_RM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment