init commit of lab2_challenge2

lab2_challenge2_singlepageheap
Zhiyuan Shao 3 years ago
parent 5b9d0b55ea
commit 4af955a59d

@ -4,8 +4,9 @@ Copyright License
The PKE software is:
Copyright (c) 2021, Zhiyuan Shao (zyshao@hust.edu.cn),
Yi Gui (gy163email@163.com),
Yan Jiao (773709579@qq.com),
Yixin Song (474309045@qq.com),
Ziming Yuan (1223962053@qq.com),
Boyang Li (liboyang_hust@163.com),
Huazhong University of Science and Technology
Permission is hereby granted, free of charge, to any person obtaining

@ -70,7 +70,7 @@ USER_OBJS := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(USER_CPPS)))
USER_TARGET := $(OBJ_DIR)/app_sum_sequence
USER_TARGET := $(OBJ_DIR)/app_singlepageheap
#------------------------targets------------------------
$(OBJ_DIR):
@-mkdir -p $(OBJ_DIR)

@ -0,0 +1,24 @@
/*
* Below is the given application for lab2_challenge2_singlepageheap.
* This app performs malloc memory.
*/
#include "user_lib.h"
#include "util/types.h"
#include "util/string.h"
int main(void) {
char str[20] = "hello world.";
char *m = (char *)better_malloc(100);
char *p = (char *)better_malloc(50);
if((uint64)p - (uint64)m > 512 ){
printu("you need to manage the vm space precisely!");
exit(-1);
}
better_free((void *)m);
strcpy(p,str);
printu("%s\n",p);
exit(0);
return 0;
}

@ -1,28 +0,0 @@
/*
* The application of lab2_3.
*/
#include "user_lib.h"
#include "util/types.h"
//
// compute the summation of an arithmetic sequence. for a given "n", compute
// result = n + (n-1) + (n-2) + ... + 0
// sum_sequence() calls itself recursively till 0. The recursive call, however,
// may consume more memory (from stack) than a physical 4KB page, leading to a page fault.
// PKE kernel needs to improved to handle such page fault by expanding the stack.
//
uint64 sum_sequence(uint64 n) {
if (n == 0)
return 0;
else
return sum_sequence( n-1 ) + n;
}
int main(void) {
// we need a large enough "n" to trigger pagefaults in the user stack
uint64 n = 1000;
printu("Summation of an arithmetic sequence from 0 to %ld is: %ld \n", n, sum_sequence(1000) );
exit(0);
}

@ -51,15 +51,15 @@ int exit(int code) {
}
//
// lib call to naive_malloc
// lib call to better_malloc
//
void* naive_malloc() {
return (void*)do_user_call(SYS_user_allocate_page, 0, 0, 0, 0, 0, 0, 0);
void* better_malloc(int n) {
return (void*)do_user_call(SYS_user_allocate_page, n, 0, 0, 0, 0, 0, 0);
}
//
// lib call to naive_free
// lib call to better_free
//
void naive_free(void* va) {
void better_free(void* va) {
do_user_call(SYS_user_free_page, (uint64)va, 0, 0, 0, 0, 0, 0);
}

@ -4,5 +4,5 @@
int printu(const char *s, ...);
int exit(int code);
void* naive_malloc();
void naive_free(void* va);
void* better_malloc(int n);
void better_free(void* va);

Loading…
Cancel
Save