diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-11 20:35:20 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-11 20:55:58 +0100 |
| commit | 5ce25ae3b5d8666d373f7d7e336546ce8508c213 (patch) | |
| tree | 4aacb570241c1005590a47ac49adb4b75a8ffd8d | |
| parent | f7ad4d9216b488f76ed4b3c8e423cd926e134b9d (diff) | |
fixes
32 files changed, 170 insertions, 99 deletions
diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 6d1cc25..0ac59e8 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -24,21 +24,12 @@ find_package(Clang REQUIRED) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin) foreach(p ${programs}) - set(cflags " \ - -g \ - ") - - set(ldflags " \ - ") - ExternalProject_Add(${p}_wnix SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/${p} BUILD_ALWAYS ON CMAKE_ARGS -D CMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_LIST_DIR}/wasm-clang-toolchain.cmake - -D CMAKE_C_FLAGS=${cflags} - -D CMAKE_EXE_LINKER_FLAGS=${ldflags} - -D CMAKE_BUILD_TYPE=Release + -D CMAKE_BUILD_TYPE=Debug -D CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} -D CMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/programs/initd/CMakeLists.txt b/programs/initd/CMakeLists.txt index 500782a..2152169 100644 --- a/programs/initd/CMakeLists.txt +++ b/programs/initd/CMakeLists.txt @@ -18,14 +18,5 @@ cmake_minimum_required(VERSION 3.13) include(GNUInstallDirs) project(initd C) add_executable(${PROJECT_NAME} initd.c) -add_subdirectory(../wnix ${CMAKE_CURRENT_BINARY_DIR}/wnix) -target_link_libraries(${PROJECT_NAME} PRIVATE wnix) -# TODO: Debugging symbols could still be there, but nwc still has issues. -add_custom_target(${PROJECT_NAME}_strip ALL - ${CMAKE_STRIP} ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} - BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} -) -add_dependencies(${PROJECT_NAME}_strip ${PROJECT_NAME}) -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) +include(wnix_program) +wnix_program() diff --git a/programs/wasm-clang-toolchain.cmake b/programs/wasm-clang-toolchain.cmake index 450b0f9..a6890f8 100644 --- a/programs/wasm-clang-toolchain.cmake +++ b/programs/wasm-clang-toolchain.cmake @@ -28,10 +28,7 @@ set(CMAKE_C_FLAGS " \ -nostdlib \ ") set(CMAKE_EXE_LINKER_FLAGS "\ + ${CMAKE_EXE_LINKER_FLAGS} \ -Wl,--threads=1 \ - --target=wasm32-unknown-unknown-wasm \ - -fno-exceptions \ - -nostdinc \ - -nostdlib \ ") set(CMAKE_STRIP ${WASI_SDK_STRIP}) diff --git a/src/aio/src/close.c b/src/aio/src/close.c index 68c5dd7..c2c3673 100644 --- a/src/aio/src/close.c +++ b/src/aio/src/close.c @@ -22,8 +22,8 @@ int aio_close(struct fs_fd *const fd) { - if (fd->mp && fd->mp->fs) - return fd->mp->fs->close(fd); + if (fd->mp.fs) + return fd->mp.fs->close(fd); return -1; } diff --git a/src/aio/src/read.c b/src/aio/src/read.c index f57c3b0..f15ee8d 100644 --- a/src/aio/src/read.c +++ b/src/aio/src/read.c @@ -52,7 +52,7 @@ struct aio *aio_read(const struct fs_read *const fr, struct aio *aio = NULL; struct read *const r = malloc(sizeof *r); struct fs_fd *const fd = fr->fd; - const struct fs *const fs = fd->mp->fs; + const struct fs *const fs = fd->mp.fs; if (!r || !(aio = malloc(sizeof *aio))) goto failure; diff --git a/src/aio/src/read_nb.c b/src/aio/src/read_nb.c index 133a75a..a86ad89 100644 --- a/src/aio/src/read_nb.c +++ b/src/aio/src/read_nb.c @@ -23,7 +23,7 @@ int aio_read_nb(const struct fs_read *const fr) { const struct fs_fd *const fd = fr->fd; - const struct fs *const fs = fd->mp->fs; + const struct fs *const fs = fd->mp.fs; return fs->read_nb(fr); } diff --git a/src/aio/src/write.c b/src/aio/src/write.c index 75f167f..562a772 100644 --- a/src/aio/src/write.c +++ b/src/aio/src/write.c @@ -52,7 +52,7 @@ struct aio *aio_write(const struct fs_write *const fw, struct aio *aio = NULL; struct write *const w = malloc(sizeof *w); struct fs_fd *const fd = fw->fd; - const struct fs *const fs = fd->mp->fs; + const struct fs *const fs = fd->mp.fs; if (!w || !(aio = malloc(sizeof *aio))) goto failure; diff --git a/src/bin/src/proc/pc.c b/src/bin/src/proc/pc.c index 746e418..28b2f44 100644 --- a/src/bin/src/proc/pc.c +++ b/src/bin/src/proc/pc.c @@ -187,7 +187,6 @@ static int append_value(struct dynstr *const d, return dynstr_append(d, fmt[v->type], v->value); } -#include <drv/ps1/bios.h> static enum nw_state write_value(void *const user, struct nw_next *const next) { struct bin_proc *const p = user; @@ -195,7 +194,7 @@ static enum nw_state write_value(void *const user, struct nw_next *const next) struct dynstr *const d = &db->dstr; struct nw_dbg_value v; - dynstr_init(d); + dynstr_free(d); if (nw_dbg_value(&db->dbg, &v) || dynstr_append(d, ";ok:") @@ -203,7 +202,6 @@ static enum nw_state write_value(void *const user, struct nw_next *const next) || dynstr_append(d, "\n")) return NW_FATAL; - Printf(">> %s", d->str); return reply(user, next, d->str); } @@ -390,7 +388,6 @@ static int cmd_g(struct bin_proc *const p, const char *const s, nw_dbg_global(&d->dbg, index); *next = (const struct nw_next){.fn = write_value, .user = p}; return 0; - return 1; } static int cmd_l(struct bin_proc *const p, const char *const s, @@ -573,8 +570,6 @@ static enum nw_state check_lf(void *const user, struct nw_next *const next) const char b = dbg->b; const size_t max = 128; - Printf("%c", b); - if (b == ';') { dynstr_free(d); @@ -623,8 +618,6 @@ static enum nw_state check_start(void *const user, struct nw_next *const next) struct bin_proc *const p = user; struct bin_dbg *const d = &p->dbg; - Printf("<< %c", d->b); - if (d->b == ';') { if (read_string(p, next)) @@ -632,8 +625,6 @@ static enum nw_state check_start(void *const user, struct nw_next *const next) } else if (read_byte(p)) return NW_FATAL; - else - Printf("(%#hhx)\n", d->b); return NW_AGAIN; } diff --git a/src/drv/ps1/sio/src/next.c b/src/drv/ps1/sio/src/next.c index 4c330ab..6926943 100644 --- a/src/drv/ps1/sio/src/next.c +++ b/src/drv/ps1/sio/src/next.c @@ -27,8 +27,10 @@ int drv_ps1_sio_next(struct sio_fifo *const f) struct sio_req *const next = f->head->next; free(f->head); - f->next = next ? next->f : NULL; - f->head = next; + + if (!(f->head = next)) + f->tail = NULL; + return 0; } diff --git a/src/fs/devfs/src/open.c b/src/fs/devfs/src/open.c index 551061f..229ff49 100644 --- a/src/fs/devfs/src/open.c +++ b/src/fs/devfs/src/open.c @@ -49,7 +49,7 @@ int devfs_open(const struct fs_open *const o, const struct fs_mp *const mp, *o->fd = (const struct fs_fd) { .inode = *inode, - .mp = mp + .mp = *mp }; *r = (const struct fs_ret){.f = done, .args = op}; diff --git a/src/fs/devfs/src/read.c b/src/fs/devfs/src/read.c index e968eb2..d7214ff 100644 --- a/src/fs/devfs/src/read.c +++ b/src/fs/devfs/src/read.c @@ -58,7 +58,7 @@ int devfs_read(const struct fs_read *const fr, struct fs_ret *const r) { struct read *re = NULL; struct fs_fd *const fd = fr->fd; - const struct fs_mp *const mp = fd->mp; + const struct fs_mp *const mp = &fd->mp; const struct inode *const inode = fd->inode.memi; const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name); diff --git a/src/fs/devfs/src/read_nb.c b/src/fs/devfs/src/read_nb.c index 2f30d5c..75b6c25 100644 --- a/src/fs/devfs/src/read_nb.c +++ b/src/fs/devfs/src/read_nb.c @@ -25,7 +25,7 @@ int devfs_read_nb(const struct fs_read *const fr) { struct fs_fd *const fd = fr->fd; - const struct fs_mp *const mp = fd->mp; + const struct fs_mp *const mp = &fd->mp; const struct inode *const inode = fd->inode.memi; const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name); diff --git a/src/fs/devfs/src/write.c b/src/fs/devfs/src/write.c index 392666c..fbb0ac8 100644 --- a/src/fs/devfs/src/write.c +++ b/src/fs/devfs/src/write.c @@ -55,7 +55,7 @@ static enum state wait(void *const args) int devfs_write(const struct fs_write *const fw, struct fs_ret *const r) { struct fs_fd *const fd = fw->fd; - const struct fs_mp *const mp = fd->mp; + const struct fs_mp *const mp = &fd->mp; const struct inode *const inode = fd->inode.memi; const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name); struct write *const w = malloc(sizeof *w); diff --git a/src/fs/include/fs/fs.h b/src/fs/include/fs/fs.h index aebe1db..60c1788 100644 --- a/src/fs/include/fs/fs.h +++ b/src/fs/include/fs/fs.h @@ -126,7 +126,8 @@ struct fs_fd int error; off_t start, offset, size; struct fs_fd_prv *prv; - const struct fs_mp *mp, *tgt_mp; + struct fs_mp mp; + const struct fs_mp *tgt_mp; union inode_result inode, tgt_inode; }; diff --git a/src/fs/include/fs/inode.h b/src/fs/include/fs/inode.h index fc24d74..a7759f9 100644 --- a/src/fs/include/fs/inode.h +++ b/src/fs/include/fs/inode.h @@ -48,7 +48,7 @@ struct inode struct timespec atim, mtim, ctim; struct inode *parent, *child, *left, *right; struct inode_prv *prv; - void (*free)(void *); + void (*dealloc)(void *); }; union inode_result diff --git a/src/fs/iso9660/src/mount.c b/src/fs/iso9660/src/mount.c index 83e7a6d..941d4f9 100644 --- a/src/fs/iso9660/src/mount.c +++ b/src/fs/iso9660/src/mount.c @@ -35,7 +35,7 @@ struct mount struct fs_ret *r; struct fs_mount mount; struct iso9660_header header; - const struct fs_mp *mp; + struct fs_mp mp; }; static void free_mount(struct mount *const m) @@ -43,7 +43,7 @@ static void free_mount(struct mount *const m) if (!m) return; - m->mp->fs->close(&m->fd); + m->mp.fs->close(&m->fd); free(m->src); free(m->tgt); free(m); @@ -71,7 +71,7 @@ static enum state read_header(void *const args) { struct mount *const m = args; struct fs_fd *const fd = &m->fd; - const struct fs *const fs = m->mp->fs; + const struct fs *const fs = m->mp.fs; const struct fs_read r = { .buf = &m->header, @@ -134,7 +134,7 @@ static int search_done(const enum state state, const char *const relpath, if (mp->fs->open(&o, mp, inode, m->r)) goto failure; - m->mp = mp; + m->mp = *mp; return 0; failure: diff --git a/src/fs/iso9660/src/open.c b/src/fs/iso9660/src/open.c index 1ea6ad7..9818719 100644 --- a/src/fs/iso9660/src/open.c +++ b/src/fs/iso9660/src/open.c @@ -30,7 +30,7 @@ struct open struct inode inode; struct fs_fd *fd; struct fs_ret *pr, r; - const struct fs_mp *mp; + struct fs_mp mp; }; static int search_done(const enum state state, const char *const relpath, @@ -59,9 +59,9 @@ static int search_done(const enum state state, const char *const relpath, .start = mpinode->prv->offset, .tgt_inode.cachei = op->inode, .size = mpinode->size, - .tgt_mp = op->mp, + .tgt_mp = &op->mp, .inode = *inode, - .mp = mp + .mp = *mp }; *op->pr = op->r; @@ -91,7 +91,7 @@ int iso9660_open(const struct fs_open *const o, const struct fs_mp *const mp, { .fd = o->fd, .inode = *i, - .mp = mp, + .mp = *mp, .pr = r, .r = *r }; diff --git a/src/fs/iso9660/src/search.c b/src/fs/iso9660/src/search.c index a7a5150..959e8d5 100644 --- a/src/fs/iso9660/src/search.c +++ b/src/fs/iso9660/src/search.c @@ -40,7 +40,7 @@ struct id struct search { union inode_result *inode; - const struct fs_mp *src_mp; + struct fs_mp src_mp; struct iso9660_entry entry; const char *src, *path; struct fs_ret r, *pr; @@ -59,14 +59,22 @@ static void free_search(struct search *const s) { if (!s) return; - else if (s->src_mp) - s->src_mp->fs->close(&s->fd); + + const struct fs *const fs = s->src_mp.fs; + + if (fs) + fs->close(&s->fd); free(s->buf); free(s->token); free(s); } +static void dealloc(void *const p) +{ + free(p); +} + static int set_inode(struct search *const s, const struct iso9660_entry *const e, const struct id *const id) { @@ -97,7 +105,7 @@ static int set_inode(struct search *const s, .name = namedup, .mode = 0555, .atim = atim, - .free = free, + .dealloc = dealloc, .ctim = ts, .mtim = ts, .prv = p @@ -287,7 +295,7 @@ static enum state entry_read(void *const args) } char *const buf = s->id.buf; - const struct fs_mp *const mp = s->fd.mp; + const struct fs_mp *const mp = &s->fd.mp; const struct fs_read r = { .buf = buf, @@ -328,7 +336,7 @@ static int prepare_entry(struct search *const s) }; s->offset = s->fd.offset; - return s->src_mp->fs->read(&r, s->pr); + return s->src_mp.fs->read(&r, s->pr); } static int next_entry(struct search *const s) @@ -483,7 +491,7 @@ static enum state read_pvd(void *const args) fd->offset = 16 * ISO9660_SECTOR_SZ; - if (s->src_mp->fs->read(&r, s->pr)) + if (s->src_mp.fs->read(&r, s->pr)) goto failure; return STATE_AGAIN; @@ -505,7 +513,7 @@ static int src_done(const enum state state, const char *const relpath, return -1; } - s->src_mp = mp; + s->src_mp = *mp; *s->pr = (const struct fs_ret) { .f = read_pvd, diff --git a/src/fs/src/inode/free.c b/src/fs/src/inode/free.c index 3eca47d..294b1f5 100644 --- a/src/fs/src/inode/free.c +++ b/src/fs/src/inode/free.c @@ -26,8 +26,8 @@ void inode_free(struct inode *const i) inode_free(i->child); free(i->name); - if (i->free) - i->free(i->prv); + if (i->dealloc) + i->dealloc(i->prv); } free(i); diff --git a/src/fs/src/inode/search.c b/src/fs/src/inode/search.c index 4715dd2..07b65ed 100644 --- a/src/fs/src/inode/search.c +++ b/src/fs/src/inode/search.c @@ -35,10 +35,14 @@ struct search static void free_search(struct search *const s) { + if (!s) + return; + + free(s->mp); free(s); } -static enum state search_mp(struct search *const s) +static int search_mp(struct search *const s) { const struct inode_search *const is = &s->search; const struct fs_mp *const cur = &s->mp[s->mp_i], @@ -51,48 +55,48 @@ static enum state search_mp(struct search *const s) relpath += strlen(s->mp[s->mp_i].tgt); if (fs && fs->iops.search(relpath, cur, &s->inode, s->r)) - return STATE_FATAL; + return -1; s->mp_i++; - return STATE_AGAIN; + return 0; } static enum state search(void *const args) { + enum state ret = STATE_FATAL; struct search *const s = args; const struct inode_search *const is = &s->search; if (!s->mp) { - const int ret = is->done(STATE_FATAL, NULL, NULL, NULL, is->args); - - free_search(s); - return ret ? STATE_FATAL : STATE_AGAIN; + if (!is->done(STATE_FATAL, NULL, NULL, NULL, is->args)) + ret = STATE_AGAIN; } else if (s->mp_i < s->n) - return search_mp(s); + { + if (!search_mp(s)) + return STATE_AGAIN; + } else { const char *relpath = is->path; + const struct fs_mp mp = s->mp[s->n - 1]; for (size_t i = 0; i < s->n; i++) relpath += strlen(s->mp[i].tgt); - const int ret = is->done(STATE_OK, relpath, &s->mp[s->n - 1], - &s->inode, is->args); - - free_search(s); - return ret ? STATE_FATAL : STATE_AGAIN; + if (!is->done(STATE_OK, relpath, &mp, &s->inode, is->args)) + ret = STATE_AGAIN; } - return STATE_FATAL; + free_search(s); + return ret; } int inode_search(const struct inode_search *const is, struct fs_ret *const r) { - struct search *s = NULL; size_t n; - /* TODO: do not check for errors yet. */ + struct search *s = NULL; struct fs_mp *const mp = fs_mps_from_path(is->path, &n); if (!(s = malloc(sizeof *s))) diff --git a/src/libc/CMakeLists.txt b/src/libc/CMakeLists.txt index 309e47a..a57be2a 100644 --- a/src/libc/CMakeLists.txt +++ b/src/libc/CMakeLists.txt @@ -21,11 +21,10 @@ set(src add_library(c ${src}) add_subdirectory(src) add_subdirectory(newlib) +target_compile_options(c PRIVATE -ffreestanding) target_include_directories(c PUBLIC include printf PRIVATE private_include tinyalloc) -target_compile_definitions(c PRIVATE TA_DISABLE_SPLIT TA_DISABLE_COMPACT) - if(NOT LIBC_FREESTANDING) target_link_libraries(c PRIVATE aio fs drv) endif() diff --git a/src/libc/include/stdlib.h b/src/libc/include/stdlib.h index 8f97ea3..2704fca 100644 --- a/src/libc/include/stdlib.h +++ b/src/libc/include/stdlib.h @@ -34,10 +34,10 @@ typedef struct int abs(int __v); long labs(long __v); long long llabs(long long __v); -void *malloc(size_t __n); -void *calloc(size_t __nemb, size_t __size); -void *realloc(void *__ptr, size_t __size); -void free(void *__p); +void *__malloc(size_t __n); +void *__calloc(size_t __nemb, size_t __size); +void *__realloc(void *__ptr, size_t __size); +void __free(void *__p); long strtol(const char *__s, char **__end, int __base); long long strtoll(const char *__s, char **__end, int __base); unsigned long strtoul(const char *__s, char **__end, int __base); @@ -45,4 +45,73 @@ unsigned long long strtoull(const char *__s, char **__end, int __base); void __abort(const char *__file, int __lineno); div_t div(int __numerator, int __denominator); +#if 1 +#define malloc(__n) __malloc(__n) +#define calloc(__n, __sz) __calloc(__n, __sz) +#define realloc(__p, __n) __realloc(__p, __n) +#define free(__p) __free(__p) +#else +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define RESET "\x1b[0m" + +#define malloc(__n) ({void *__p; \ + Printf(GREEN "-> %s:%d (%s)", __FILE__, __LINE__, __func__); \ + __p = __malloc(__n); \ + Printf(", p=%p" RESET "\n", __p); \ + int Printf(const char *, ...); \ + size_t ta_num_free(); \ + size_t ta_num_used(); \ + size_t ta_num_fresh(); \ + Printf("%s: free=%lu, used=%lu, fresh=%lu\n", __func__, \ + (unsigned long)ta_num_free(), \ + (unsigned long)ta_num_used(), \ + (unsigned long)ta_num_fresh()); \ + __p;}) + +#define realloc(__p, __n) ({void *__np; \ + Printf(YELLOW "-> %s:%d (%s)", __FILE__, __LINE__, __func__); \ + __np = __realloc(__p, __n); \ + Printf(", np=%p" RESET "\n", __np); \ + int Printf(const char *, ...); \ + size_t ta_num_free(); \ +size_t ta_num_used(); \ +size_t ta_num_fresh(); \ + Printf("%s: free=%lu, used=%lu, fresh=%lu\n", __func__, \ + (unsigned long)ta_num_free(), \ + (unsigned long)ta_num_used(), \ + (unsigned long)ta_num_fresh()); \ + __np;}) + +#define calloc(__n, __sz) ({void *__p; \ + Printf(YELLOW "-> %s:%d (%s)", __FILE__, __LINE__, __func__); \ + __p = __calloc(__n, __sz); \ + Printf(", p=%p" RESET "\n", __p); \ + int Printf(const char *, ...); \ + size_t ta_num_free(); \ +size_t ta_num_used(); \ +size_t ta_num_fresh(); \ + Printf("%s: free=%lu, used=%lu, fresh=%lu\n", __func__, \ + (unsigned long)ta_num_free(), \ + (unsigned long)ta_num_used(), \ + (unsigned long)ta_num_fresh()); \ + __p;}) + +#define free(__p) ({ \ + int Printf(const char *, ...); \ + Printf(RED "<- %s:%d (%s), p=%p" RESET "\n", \ + __FILE__, __LINE__, __func__, __p); \ + size_t ta_num_free(); \ + size_t ta_num_used(); \ + size_t ta_num_fresh(); \ + __free(__p);\ + Printf("%s: free=%lu, used=%lu, fresh=%lu\n", \ + __func__, \ + (unsigned long)ta_num_free(), \ + (unsigned long)ta_num_used(), \ + (unsigned long)ta_num_fresh()); \ + }) +#endif + #endif diff --git a/src/libc/src/ps1/CMakeLists.txt b/src/libc/src/ps1/CMakeLists.txt index 54012df..1bab87a 100644 --- a/src/libc/src/ps1/CMakeLists.txt +++ b/src/libc/src/ps1/CMakeLists.txt @@ -20,4 +20,3 @@ target_sources(c PRIVATE ) target_link_libraries(c PRIVATE drv_ps1_bios) -target_compile_options(c PRIVATE -ffreestanding) diff --git a/src/libc/src/stdlib/calloc.c b/src/libc/src/stdlib/calloc.c index c5e1dee..1e331d1 100644 --- a/src/libc/src/stdlib/calloc.c +++ b/src/libc/src/stdlib/calloc.c @@ -20,7 +20,7 @@ #include <stddef.h> #include <string.h> -void *calloc(const size_t nemb, const size_t size) +void *__calloc(const size_t nemb, const size_t size) { const size_t n = nemb * size; void *const ret = malloc(n); diff --git a/src/libc/src/stdlib/free.c b/src/libc/src/stdlib/free.c index 1986c48..3916ff3 100644 --- a/src/libc/src/stdlib/free.c +++ b/src/libc/src/stdlib/free.c @@ -20,7 +20,7 @@ #include <libc/malloc.h> #include <stdlib.h> -void free(void *const ptr) +void __free(void *const ptr) { if (!ptr) return; diff --git a/src/libc/src/stdlib/malloc.c b/src/libc/src/stdlib/malloc.c index 81bdeb5..786f314 100644 --- a/src/libc/src/stdlib/malloc.c +++ b/src/libc/src/stdlib/malloc.c @@ -22,12 +22,12 @@ #include <errno.h> #include <stdint.h> -void *malloc(const size_t n) +void *__malloc(const size_t n) { if (!__malloc_ta_init) { /* README.md states 16 is a "good default value". */ - if (!ta_init(1024, 16, sizeof (intmax_t))) + if (!ta_init(300, 16, sizeof (intmax_t))) abort(); __malloc_ta_init = 1; diff --git a/src/libc/src/stdlib/realloc.c b/src/libc/src/stdlib/realloc.c index dabfc05..2b9c205 100644 --- a/src/libc/src/stdlib/realloc.c +++ b/src/libc/src/stdlib/realloc.c @@ -17,9 +17,26 @@ */ #include <tinyalloc.h> +#include <libc/malloc.h> +#include <errno.h> +#include <stdint.h> #include <stdlib.h> -void *realloc(void *const ptr, const size_t size) +void *__realloc(void *const ptr, const size_t size) { - return ta_realloc(ptr, size); + if (!__malloc_ta_init) + { + /* README.md states 16 is a "good default value". */ + if (!ta_init(1024, 16, sizeof (intmax_t))) + abort(); + + __malloc_ta_init = 1; + } + + void *const ret = ta_realloc(ptr, size); + + if (!ret) + errno = ENOMEM; + + return ret; } diff --git a/src/libc/src/unistd/sbrk.c b/src/libc/src/unistd/sbrk.c index 459d476..b41c192 100644 --- a/src/libc/src/unistd/sbrk.c +++ b/src/libc/src/unistd/sbrk.c @@ -31,7 +31,7 @@ void *sbrk(const intptr_t increment) if (base + increment >= __ram_end) return NULL; - void *p = base; + void *const p = base; base += increment; return p; diff --git a/src/loop/src/rm_aio.c b/src/loop/src/rm_aio.c index 5d4f159..5401d97 100644 --- a/src/loop/src/rm_aio.c +++ b/src/loop/src/rm_aio.c @@ -34,6 +34,8 @@ int loop_rm_aio(struct aio *const aio) if (next) next->prev = NULL; + else + loop_aio_tail = NULL; } else if ((prev->next = next)) next->prev = prev; diff --git a/src/page/private_include/page/types.h b/src/page/private_include/page/types.h index ae1ff99..66bc9a1 100644 --- a/src/page/private_include/page/types.h +++ b/src/page/private_include/page/types.h @@ -27,7 +27,7 @@ struct page_ops { int (*read)(struct page *p, void *buf, size_t n, unsigned long addr); int (*write)(struct page *p, const void *buf, size_t n, unsigned long addr); - void (*free)(struct page *p); + void (*dealloc)(struct page *p); }; struct page diff --git a/src/page/src/free.c b/src/page/src/free.c index f9b72fb..bf3bf25 100644 --- a/src/page/src/free.c +++ b/src/page/src/free.c @@ -30,6 +30,6 @@ void page_free(struct page *const p) if (p->prev) p->prev->next = p->next; - p->ops->free(p); + p->ops->dealloc(p); free(p); } diff --git a/src/page/src/mem/ops.c b/src/page/src/mem/ops.c index 843b82a..d240f4b 100644 --- a/src/page/src/mem/ops.c +++ b/src/page/src/mem/ops.c @@ -23,5 +23,5 @@ const struct page_ops page_mem_ops = { .read = page_mem_read, .write = page_mem_write, - .free = page_mem_free + .dealloc = page_mem_free }; |
