diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-01-03 02:13:08 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-01-03 02:13:08 +0800 |
| commit | 10614e04929a6d109a5e90524e446b637aaf0c13 (patch) | |
| tree | eb11aeb7b641187f207e3b572c5184cf3526b463 /include/kernel | |
| parent | 1c8e37f63d413a559825020289178d442537449e (diff) | |
| download | lume-10614e04929a6d109a5e90524e446b637aaf0c13.tar.gz lume-10614e04929a6d109a5e90524e446b637aaf0c13.tar.xz | |
Fix: critical malloc size calculation bug
Summary:
- Fixed an integer arithmetic error in malloc() where 'nunits' was initialized to 0, causing incorrect heap sizing.
- This bug caused malloc to return pointers pointing to unmapped memory pages, leading to Store Page Fault (scause 15) at process boundaries.
- Switched memory allocator logic to use byte-based size calculation instead of K&R style units to prevent off-by-one errors.
Improvements:
- Shell now starts successfully without segfaults.
Diffstat (limited to 'include/kernel')
| -rw-r--r-- | include/kernel/proc_def.h | 4 | ||||
| -rw-r--r-- | include/kernel/riscv.h | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/include/kernel/proc_def.h b/include/kernel/proc_def.h index 06c80aa..5ce4c03 100644 --- a/include/kernel/proc_def.h +++ b/include/kernel/proc_def.h @@ -59,6 +59,10 @@ struct Proc struct Proc *next; struct Proc *prev; + + struct Proc *all_next; + struct Proc *all_prev; + int priority; int ticks; struct cpu *cpu; diff --git a/include/kernel/riscv.h b/include/kernel/riscv.h index e81976f..0c586a9 100644 --- a/include/kernel/riscv.h +++ b/include/kernel/riscv.h @@ -376,7 +376,8 @@ typedef uint64 *pagetable_t; // 512 PTEs #define PTE_X (1L << 3) #define PTE_U (1L << 4) // user can access - +// COW Flag (PTE bit 8) +#define PTE_COW (1L << 8) #if defined(LAB_MMAP) || defined(LAB_PGTBL) || defined(LAB_COW) #define PTE_LEAF(pte) (((pte) & PTE_R) | ((pte) & PTE_W) | ((pte) & PTE_X)) |
