9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3b9beed3020a69117793163daad3832a44138677
parent 0c7db7a7f3e86176a9adc7453d51c590c98be8bb
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  1 Nov 2020 10:18:35 +0100

os9: Set errno in alloc()

Change-Id: I4b3dcc488361a137f3aba3329887f8eb8735dc8f

Diffstat:
Msrc/os9/alloc.c | 13++++++++++---
Msrc/os9/proc.c | 20+++++++++++---------
2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/os9/alloc.c b/src/os9/alloc.c @@ -1,5 +1,6 @@ #include <os9/os9.h> +#include <errno.h> #include <string.h> #ifndef NR_BUFFERS @@ -25,8 +26,10 @@ allocb(int n) static mutex_t m; lock(&m); - if (n >= NR_BUFFERS - npages) + if (n >= NR_BUFFERS - npages) { + errno = ENOMEM; goto end; + } addr= buffertab[npages]; npages += n; end: @@ -51,16 +54,20 @@ alloc(size_t size) goto end; } - if (lockalloc) + if (lockalloc) { + errno = 1; /* TODO: What can I do here???? */ goto end; + } if (!heap) heap = allocb(HEAPSIZ); n = (size-1) / sizeof(union bucket) + 1; size = n * sizeof(union bucket); - if (used > SIZE_MAX - size) + if (used > SIZE_MAX - size) { + errno = ENOMEM; goto end; + } bp = heap + used; used += size; end: diff --git a/src/os9/proc.c b/src/os9/proc.c @@ -108,9 +108,10 @@ newspace(Nspace *from) { Nspace *ns; - ns = alloc(sizeof(*ns)); - if (from) - *ns = *from; + if ((ns = alloc(sizeof(*ns))) == NULL) + return NULL; + + *ns = (from) ? *from : (Nspace) {0}; initref(&ns->ref); return ns; @@ -121,9 +122,10 @@ newfds(Fdset *from) { Fdset *fds; - fds = alloc(sizeof(*fds)); - if (from) - *fds = *from; + if ((fds = alloc(sizeof(*fds))) == NULL) + return NULL; + + *fds = (from) ? *from : (Fdset) {0}; initref(&fds->ref); return fds; @@ -134,9 +136,9 @@ newmap(Map *from) { Map *mp; - mp = alloc(sizeof(*mp)); - if (from) - *mp = *from; + if ((mp = alloc(sizeof(*mp))) == NULL) + return NULL; + *mp = *from; initref(&mp->ref); return mp;