diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/elf.c | 2 | ||||
-rw-r--r-- | src/user/include/knob/format.h | 6 | ||||
-rw-r--r-- | src/user/knob/format.c | 3 | ||||
-rw-r--r-- | src/user/knob/heap.c | 28 |
4 files changed, 36 insertions, 3 deletions
diff --git a/src/kernel/elf.c b/src/kernel/elf.c index 07cff91..8113c14 100644 --- a/src/kernel/elf.c +++ b/src/kernel/elf.c @@ -104,6 +104,8 @@ bool try_elf_run(const struct drive *d, const char *path, const char *pass_old_v continue; void *pma = pd_user_allocate(pd, entry->vma, (entry->vms - 1) / 4096 + 1, entry->flags & PH_WRITABLE); fmcpy(pma, d, h, entry->fa, entry->fs); + for (uint8_t *pma_i = pma + entry->fs; pma_i < pma + entry->vms; ++pma_i) + *pma_i = 0; } free_pages(phtable, phtable_pages); diff --git a/src/user/include/knob/format.h b/src/user/include/knob/format.h index 89402c0..d55036c 100644 --- a/src/user/include/knob/format.h +++ b/src/user/include/knob/format.h @@ -5,8 +5,8 @@ #include <stdint.h> bool try_sntoi(const char *s, uint32_t n, uint32_t *out); -void itosz(uint32_t i, char *out); -void itosz_h8(uint8_t i, char *out); -void itosz_h32(uint32_t i, char *out); +void itosz(uint32_t i, char *out) __attribute__ ((access (write_only, 2))); +void itosz_h8(uint8_t i, char *out) __attribute__ ((access (write_only, 2))); +void itosz_h32(uint32_t i, char *out) __attribute__ ((access (write_only, 2))); #endif
\ No newline at end of file diff --git a/src/user/knob/format.c b/src/user/knob/format.c index 645fb73..593b20c 100644 --- a/src/user/knob/format.c +++ b/src/user/knob/format.c @@ -12,6 +12,7 @@ bool try_sntoi(const char *s, uint32_t n, uint32_t *out) { return true; } +__attribute__ ((access (write_only, 2))) void itosz(uint32_t i, char *out) { if (!i) { *(uint16_t *)out = (uint16_t)'0'; @@ -32,12 +33,14 @@ void itosz(uint32_t i, char *out) { const char *const hex_digits = "0123456789abcdef"; +__attribute__ ((access (write_only, 2))) void itosz_h8(uint8_t i, char *out) { out[0] = hex_digits[i >> 4]; out[1] = hex_digits[i & 0xf]; out[2] = '\0'; } +__attribute__ ((access (write_only, 2))) void itosz_h32(uint32_t i, char *out) { for (uint8_t digit = 0; digit < 8; ++digit) out[digit] = hex_digits[(i >> (28 - digit * 4)) & 0xf]; diff --git a/src/user/knob/heap.c b/src/user/knob/heap.c index ec21129..49f9339 100644 --- a/src/user/knob/heap.c +++ b/src/user/knob/heap.c @@ -24,9 +24,23 @@ static void add_header(struct block_header *bh) { __attribute__ ((malloc)) void *get_block(uint32_t bytes) { +//char nbuf[11]; +//tell_user_sz("[heap::get_block]\n first_block = 0x"); +//itosz_h32((uint32_t)first_block, nbuf); +//tell_user_sz(nbuf); +//tell_user_sz("\n"); struct block_header *header = 0; for (struct block_header *ptr = first_block; ptr; ptr = ptr->next) { + //tell_user_sz(" ptr = 0x"); + //itosz_h32((uint32_t)ptr, nbuf); + //tell_user_sz(nbuf); + //tell_user_sz("\n &ptr->allocated = 0x"); + //itosz_h32((uint32_t)&ptr->allocated, nbuf); + //tell_user_sz(nbuf); + //tell_user_sz("\n ptr->allocated = "); + //tell_user_sz(ptr->allocated ? "true\n" : "false\n"); + if (ptr->allocated) continue; if (ptr->length == bytes) { @@ -49,7 +63,14 @@ void *get_block(uint32_t bytes) { if (!header) { uint32_t size_with_header = bytes + sizeof(struct block_header); if (!(size_with_header % 4096)) { + //tell_user_sz(" allocate "); + //itosz(size_with_header / 4096, nbuf); + //tell_user_sz(nbuf); + //tell_user_sz(" pages = 0x"); header = _allocate_ram(size_with_header / 4096); + //itosz_h32((uint32_t)header, nbuf); + //tell_user_sz(nbuf); + //tell_user_sz("\n"); if (!header) return 0; header->length = bytes; @@ -57,7 +78,14 @@ void *get_block(uint32_t bytes) { } else { uint32_t pages = (bytes + sizeof(struct block_header) * 2) / 4096 + 1; + //tell_user_sz(" allocate "); + //itosz(pages, nbuf); + //tell_user_sz(nbuf); + //tell_user_sz(" pages = 0x"); header = _allocate_ram(pages); + //itosz_h32((uint32_t)header, nbuf); + //tell_user_sz(nbuf); + //tell_user_sz("\n"); if (!header) return 0; header->length = bytes; |