Modify kalloc for RISCV only supports -2GB to 2GB in link script file

This commit is contained in:
songyanguang 2024-12-19 20:50:29 +08:00
parent 2087cb7d33
commit 64ba03adef
1 changed files with 6 additions and 2 deletions

View File

@ -33,13 +33,17 @@ Modification:
#include "actracer.h" #include "actracer.h"
#include "buddy.h" #include "buddy.h"
#ifndef V2P_LINK
#define V2P_LINK V2P
#endif
struct KBuddy kern_virtmem_buddy; struct KBuddy kern_virtmem_buddy;
struct KBuddy user_phy_freemem_buddy; struct KBuddy user_phy_freemem_buddy;
extern uintptr_t kernel_data_end[]; extern uintptr_t kernel_data_end[];
bool module_phymem_init() bool module_phymem_init()
{ {
uintptr_t kern_freemem_start = V2P(kernel_data_end); uintptr_t kern_freemem_start = V2P_LINK(kernel_data_end);
uintptr_t kern_freemem_end = PHY_USER_FREEMEM_BASE; uintptr_t kern_freemem_end = PHY_USER_FREEMEM_BASE;
uintptr_t user_freemem_start = PHY_USER_FREEMEM_BASE; uintptr_t user_freemem_start = PHY_USER_FREEMEM_BASE;
uintptr_t user_freemem_end = PHY_MEM_STOP; uintptr_t user_freemem_end = PHY_MEM_STOP;
@ -55,7 +59,7 @@ char* kalloc(uintptr_t size)
if (mem_alloc == NULL) { if (mem_alloc == NULL) {
return NULL; return NULL;
} }
assert((uintptr_t)mem_alloc >= V2P(&kernel_data_end) && (uintptr_t)mem_alloc < PHY_USER_FREEMEM_BASE); assert((uintptr_t)mem_alloc >= V2P_LINK(&kernel_data_end) && (uintptr_t)mem_alloc < PHY_USER_FREEMEM_BASE);
mem_alloc = P2V(mem_alloc); mem_alloc = P2V(mem_alloc);
if ((uintptr_t)mem_alloc < KERN_MEM_BASE) { if ((uintptr_t)mem_alloc < KERN_MEM_BASE) {
DEBUG("Error Alloc: %x by size: %d (Caused by double free)\n", mem_alloc, size); DEBUG("Error Alloc: %x by size: %d (Caused by double free)\n", mem_alloc, size);