Commit 8fe74be2 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Fix #4

parent dd227c9f
No related merge requests found
Showing with 16 additions and 19 deletions
+16 -19
......@@ -3,15 +3,15 @@
* allows us to interleave calls from the student's malloc package
* with the system's malloc package in libc.
*/
#include "memlib.h"
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <errno.h>
#include "memlib.h"
#include <sys/mman.h>
#define MAX_HEAP (100*(1<<20)) /* 100 MB */
#define MAX_HEAP (100 * (1 << 20)) /* 100 MB */
/* private variables */
static uint8_t *heap;
......@@ -21,18 +21,14 @@ static uint8_t *mem_brk;
* mem_init - initialize the memory system model
*/
void mem_init() {
heap = mmap(
(void *) 0x800000000, /* suggested start*/
MAX_HEAP, /* length */
PROT_READ | PROT_WRITE, /* heap can be read or written */
MAP_PRIVATE | MAP_ANONYMOUS, /* initialize region with zeros */
-1, /* fd (unused) */
0 /* offset (unused) */
heap = mmap((void *) 0x800000000, /* suggested start*/
MAX_HEAP, /* length */
PROT_READ | PROT_WRITE, /* heap can be read or written */
MAP_PRIVATE | MAP_ANONYMOUS, /* initialize region with zeros */
-1, /* fd (unused) */
0 /* offset (unused) */
);
/* Fill heap with garbage since it is uninitialized. */
memset(heap, 0xCC, MAX_HEAP);
/* Heap is initially empty. */
mem_reset_brk();
}
......@@ -49,6 +45,9 @@ void mem_deinit() {
*/
void mem_reset_brk() {
mem_brk = heap;
/* Fill heap with garbage since it is uninitialized. */
memset(heap, 0xCC, MAX_HEAP);
}
/*
......@@ -79,15 +78,13 @@ void *mem_heap_lo() {
/*
* mem_heap_hi - return address of last heap byte
*/
void *mem_heap_hi()
{
void *mem_heap_hi() {
return mem_brk - 1;
}
/*
* mem_heapsize() - returns the heap size in bytes
*/
size_t mem_heapsize()
{
size_t mem_heapsize() {
return mem_brk - heap;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment