From be365dea3006832a5412e6851a75b1ad4b1f1412 Mon Sep 17 00:00:00 2001 From: Zhiyuan Shao Date: Fri, 17 Jun 2022 11:56:01 +0800 Subject: [PATCH] init commit of lab2_challenge1 --- LICENSE.txt | 5 +++-- user/app_sum_sequence.c | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index ffe4849..f2723e6 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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 diff --git a/user/app_sum_sequence.c b/user/app_sum_sequence.c index 809d341..957e2f4 100644 --- a/user/app_sum_sequence.c +++ b/user/app_sum_sequence.c @@ -1,5 +1,6 @@ /* - * The application of lab2_3. + * The application of lab2_challenge1_pagefault. + * Based on application of lab2_3. */ #include "user_lib.h" @@ -12,17 +13,24 @@ // 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) { +uint64 sum_sequence(uint64 n, int *p) { if (n == 0) return 0; else - return sum_sequence( n-1 ) + n; + return *p=sum_sequence( n-1, p+1 ) + n; } int main(void) { - // we need a large enough "n" to trigger pagefaults in the user stack - uint64 n = 1000; + // FIRST, we need a large enough "n" to trigger pagefaults in the user stack + uint64 n = 1024; + + // alloc a page size array(int) to store the result of every step + // the max limit of the number is 4kB/4 = 1024 + + // SECOND, we use array out of bound to trigger pagefaults in an invalid address + int *ans = (int *)naive_malloc(); + + printu("Summation of an arithmetic sequence from 0 to %ld is: %ld \n", n, sum_sequence(n+1, ans) ); - printu("Summation of an arithmetic sequence from 0 to %ld is: %ld \n", n, sum_sequence(1000) ); exit(0); }