Skip to content

Instantly share code, notes, and snippets.

@Blazefrost
Created August 18, 2016 21:13
Show Gist options
  • Save Blazefrost/6697bcad035cdb91bfb1a5f0bbeab670 to your computer and use it in GitHub Desktop.
Save Blazefrost/6697bcad035cdb91bfb1a5f0bbeab670 to your computer and use it in GitHub Desktop.
From 934c3b1a8ef95a5f613d88b39248065e298723f7 Mon Sep 17 00:00:00 2001
From: Marcell Haritopoulos <marcellharitopoulos@gmail.com>
Date: Thu, 18 Aug 2016 20:50:49 +0200
Subject: [PATCH 1/2] Initialize page table after allocating it
---
selfie.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/selfie.c b/selfie.c
index ac2d478cbc17d06..5efa7067170e236 100644
--- a/selfie.c
+++ b/selfie.c
@@ -6339,6 +6339,7 @@ int createID(int seed) {
int* allocateContext(int ID, int parentID) {
int* context;
+ int page;
if (freeContexts == (int*) 0)
context = malloc(4 * SIZEOFINTSTAR + 6 * SIZEOFINT);
@@ -6362,9 +6363,15 @@ int* allocateContext(int ID, int parentID) {
setRegHi(context, 0);
setRegLo(context, 0);
- // allocate memory for page table
+ // allocate and initialize memory for page table
// TODO: save and reuse memory for page table
setPT(context, malloc(VIRTUALMEMORYSIZE / PAGESIZE * WORDSIZE));
+ page = 0;
+ while (page < VIRTUALMEMORYSIZE / PAGESIZE)
+ {
+ *(getPT(context) + page) = 0;
+ page = page + 1;
+ }
// heap starts where it is safe to start
setBreak(context, maxBinaryLength);
@@ -6693,4 +6700,4 @@ int main(int argc, int* argv) {
}
return 0;
-}
\ No newline at end of file
+}
--
2.9.3
From c32125bfcb4076871201da9f049334a7e45286ae Mon Sep 17 00:00:00 2001
From: Marcell Haritopoulos <marcellharitopoulos@gmail.com>
Date: Thu, 18 Aug 2016 22:50:23 +0200
Subject: [PATCH 2/2] Initialize ZR to 0 after allocating it
---
selfie.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/selfie.c b/selfie.c
index 5efa7067170e236..bd9f49a7b0b3dd6 100644
--- a/selfie.c
+++ b/selfie.c
@@ -6362,6 +6362,7 @@ int* allocateContext(int ID, int parentID) {
setRegHi(context, 0);
setRegLo(context, 0);
+ *(getRegs(context)+REG_ZR) = 0;
// allocate and initialize memory for page table
// TODO: save and reuse memory for page table
--
2.9.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment