Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-21fa
project04
Commits
8fe74be2
Commit
8fe74be2
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Fix #4
parent
dd227c9f
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/memlib.c
+16
-19
src/memlib.c
with
16 additions
and
19 deletions
+16
-19
src/memlib.c
View file @
8fe74be2
...
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help