:: commit 0dc73b35299e7d0e01f17b6158d17c1921826e82

mintsuki <mintsuki@protonmail.com> — 2020-09-26 13:41

parents: 11240b59a5

Fix conv_mem_alloc bug introduced by e721c3c

diff --git a/limine.bin b/limine.bin
index 1ac1bbcf..f82b6593 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/fs/ext2.c b/stage2/fs/ext2.c
index a859663e..eb880d74 100644
--- a/stage2/fs/ext2.c
+++ b/stage2/fs/ext2.c
@@ -220,11 +220,11 @@ next:
 

         int r = strcmp(token, name);

 

-        conv_mem_rewind();

+        conv_mem_rewind(dir->name_len + 1);

 

         if (!r) {

             if (escape) {

-                conv_mem_rewind();

+                conv_mem_rewind(sizeof(struct ext2_inode));

                 return 0;

             } else {

                 // update the current inode

@@ -236,7 +236,7 @@ next:
         i += dir->rec_len;

     }

 

-    conv_mem_rewind();

+    conv_mem_rewind(sizeof(struct ext2_inode));

     return -1;

 }

 

diff --git a/stage2/mm/pmm.c b/stage2/mm/pmm.c
index 3d56a17d..3ea2a44a 100644
--- a/stage2/mm/pmm.c
+++ b/stage2/mm/pmm.c
@@ -264,9 +264,8 @@ extern symbol bss_end;
 static size_t bump_allocator_base = (size_t)bss_end;
 static size_t bump_allocator_limit = 0;
 
-void conv_mem_rewind(void) {
-    size_t *old_base = (size_t *)(bump_allocator_base - sizeof(size_t));
-    bump_allocator_base = *old_base;
+void conv_mem_rewind(size_t count) {
+    bump_allocator_base -= count;
 }
 
 void *conv_mem_alloc(size_t count) {
@@ -286,14 +285,9 @@ void *conv_mem_alloc_aligned(size_t count, size_t alignment) {
 
     size_t new_base = ALIGN_UP(bump_allocator_base, alignment);
     void *ret = (void *)new_base;
-
-    size_t *old_base = (size_t *)(new_base + count);
-    new_base += count + sizeof(size_t);
-
+    new_base += count;
     if (new_base >= bump_allocator_limit)
         panic("Memory allocation failed");
-
-    *old_base = bump_allocator_base;
     bump_allocator_base = new_base;
 
     // Zero out allocated space
diff --git a/stage2/mm/pmm.h b/stage2/mm/pmm.h
index 27e6ba48..493daa32 100644
--- a/stage2/mm/pmm.h
+++ b/stage2/mm/pmm.h
@@ -22,7 +22,7 @@ void *ext_mem_alloc_type(size_t count, uint32_t type);
 void *ext_mem_alloc_aligned(size_t count, size_t alignment);
 void *ext_mem_alloc_aligned_type(size_t count, size_t alignment, uint32_t type);
 
-void conv_mem_rewind(void);
+void conv_mem_rewind(size_t count);
 void *conv_mem_alloc(size_t count);
 void *conv_mem_alloc_aligned(size_t count, size_t alignment);
 
diff --git a/stage2/sys/smp.c b/stage2/sys/smp.c
index 4d7b4d0d..e833d0bf 100644
--- a/stage2/sys/smp.c
+++ b/stage2/sys/smp.c
@@ -126,7 +126,7 @@ struct smp_information *init_smp(size_t   *cpu_count,
                 if (!smp_start_ap(lapic->lapic_id, &gdtr, info_struct,
                                   longmode, lv5, (uint32_t)pagemap.top_level)) {
                     print("smp: FAILED to bring-up AP\n");
-                    conv_mem_rewind();
+                    conv_mem_rewind(sizeof(struct smp_information));
                     continue;
                 }
 
tab: 248 wrap: offon