This commit is contained in:
2025-09-15 22:35:15 +02:00
parent ce63020b34
commit 0a5523f234
22 changed files with 374 additions and 177 deletions

View File

@ -8,11 +8,10 @@
#include <log.h>
extern void main(void);
extern uint8_t _bss_start;
extern uint8_t _bss_end;
void clearbss(void) {
extern uint8_t _bss_start;
extern uint8_t _bss_end;
uint8_t *ps = &_bss_start;
uint8_t *pe = &_bss_end;
size_t sz = pe - ps;

View File

@ -46,7 +46,7 @@ int RELEASE_LOCK(SpinLock *sl) {
}
int INITIAL_LOCK(SpinLock *sl) {
spinlock_release(sl);
spinlock_init(sl);
return 0;
}
@ -79,12 +79,17 @@ void *sbrk(ptrdiff_t inc) {
return heap_end;
}
uint8_t *oldh = heap_end;
uint8_t *newh = heap_end + inc;
uint8_t *oldbrk = heap_end;
uint8_t *newbrk = heap_end + inc;
if (newbrk < heap_start) {
return (void *)-1;
}
if (inc > 0) {
if (newh > heap_commit) {
size_t extra = _roundpage((size_t)(newh - heap_commit));
if (newbrk > heap_commit) {
size_t need = (size_t)(newbrk - heap_commit);
size_t extra = _roundpage(need);
uint8_t *maddr = NULL;
int32_t ret = mman_map(NULL, extra, MMAN_MAP_PF_RW, 0, &maddr);
if (ret != E_OK || maddr == NULL) {
@ -92,39 +97,7 @@ void *sbrk(ptrdiff_t inc) {
}
heap_commit += extra;
}
heap_end = newh;
} else {
heap_end = newh;
}
return oldh;
#if 0
if (!heap_end) {
heap_end = heap_start;
}
if (inc == 0) {
return heap_end;
}
uint8_t *oldh = heap_end;
uint8_t *newh = heap_end + inc;
if (inc > 0) {
size_t allocsz = _roundpage((size_t)(newh - oldh));
uint8_t *maddr = NULL;
int32_t ret = mman_map(NULL, allocsz, MMAN_MAP_PF_RW, 0, &maddr);
if (ret != E_OK || maddr == NULL) {
return (void *)-1;
}
if (!heap_start) {
heap_start = maddr;
}
oldh = heap_end ? heap_end : maddr;
heap_end = oldh + allocsz;
} else {
heap_end = newh;
}
return oldh;
#endif
heap_end = newbrk;
return (void *)oldbrk;
}