From dfc6d0bbbd14df37d01faa3cd29220d5ea4823d7 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 14 Jul 2002 10:10:22 +0000 Subject: [PATCH] Tidy up some error values we're passing. Essentially remove the ERR_SEM errors, though these will need to be checked. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@211 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/port.c | 14 +++++++------- src/kernel/core/sem.c | 21 +++++++++------------ src/kernel/core/thread.c | 30 +++++++++++++++--------------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/kernel/core/port.c b/src/kernel/core/port.c index 7fcc28c4ba..f50f04bb88 100644 --- a/src/kernel/core/port.c +++ b/src/kernel/core/port.c @@ -348,7 +348,7 @@ delete_port(port_id id) kfree(old_name); // release the threads that were blocking on this port by deleting the sem - // read_port() will see the ERR_SEM_DELETED acq_sem() return value, and act accordingly + // read_port() will see the B_BAD_SEM_ID acq_sem() return value, and act accordingly delete_sem(r_sem); delete_sem(w_sem); @@ -529,12 +529,12 @@ port_buffer_size_etc(port_id id, res = acquire_sem_etc(ports[slot].read_sem, 1, flags & (B_TIMEOUT | B_CAN_INTERRUPT), timeout); GRAB_PORT_LOCK(ports[slot]); - if (res == ERR_SEM_DELETED) { + if (res == B_BAD_SEM_ID) { // somebody deleted the port RELEASE_PORT_LOCK(ports[slot]); return B_BAD_PORT_ID; } - if (res == ERR_SEM_TIMED_OUT) { + if (res == B_TIMED_OUT) { RELEASE_PORT_LOCK(ports[slot]); return B_TIMED_OUT; } @@ -663,12 +663,12 @@ read_port_etc(port_id id, // both threads will read in 2 different slots allocated above, simultaneously // slot is a thread-local variable - if (res == ERR_SEM_DELETED || res == EINTR) { + if (res == B_BAD_SEM_ID || res == EINTR) { /* somebody deleted the port or the sem went away */ return B_BAD_PORT_ID; } - if (res == ERR_SEM_TIMED_OUT) { + if (res == B_TIMED_OUT) { // timed out, or, if timeout=0, 'would block' return B_BAD_PORT_ID; } @@ -833,12 +833,12 @@ write_port_etc(port_id id, // both threads will write in 2 different slots allocated above, simultaneously // slot is a thread-local variable - if (res == ERR_SEM_DELETED || res == EINTR) { + if (res == B_BAD_PORT_ID || res == EINTR) { /* somebody deleted the port or the sem while we were waiting */ return B_BAD_PORT_ID; } - if (res == ERR_SEM_TIMED_OUT) { + if (res == B_TIMED_OUT) { // timed out, or, if timeout=0, 'would block' return B_TIMED_OUT; } diff --git a/src/kernel/core/sem.c b/src/kernel/core/sem.c index b03362716a..e25d29b47a 100644 --- a/src/kernel/core/sem.c +++ b/src/kernel/core/sem.c @@ -355,7 +355,7 @@ int acquire_sem_etc(sem_id id, int count, int flags, bigtime_t timeout) if(sems[slot].count - count < 0 && (flags & B_TIMEOUT) != 0 && timeout <= 0) { // immediate timeout - err = ERR_SEM_TIMED_OUT; + err = B_TIMED_OUT; goto err; } @@ -423,7 +423,7 @@ int acquire_sem_etc(sem_id id, int count, int flags, bigtime_t timeout) RELEASE_THREAD_LOCK(); if((flags & B_TIMEOUT) != 0) { - if(t->sem_errcode != ERR_SEM_TIMED_OUT) { + if(t->sem_errcode != B_TIMED_OUT) { // cancel the timer event, the sem may have been deleted or interrupted // with the timer still active timer_cancel_event(&timer); @@ -603,9 +603,10 @@ int _get_next_sem_info(proc_id proc, uint32 *cookie, struct sem_info *info, size return B_NO_MORE_SEMS; if (cookie == NULL) - return ERR_INVALID_ARGS; + return EINVAL; + /* prevents sems[].owner == -1 >= means owned by a port */ if (proc < 0) - return ERR_INVALID_ARGS; // prevents sems[].owner == -1 >= means owned by a port + return EINVAL; if (*cookie == NULL) { // return first found @@ -642,7 +643,7 @@ int _get_next_sem_info(proc_id proc, uint32 *cookie, struct sem_info *info, size int_restore_interrupts(state); if (slot == MAX_SEMS) - return ERR_SEM_NOT_FOUND; + return B_BAD_SEM_ID; *cookie = slot; return B_NO_ERROR; } @@ -657,7 +658,7 @@ int set_sem_owner(sem_id id, proc_id proc) if(id < 0) return B_BAD_SEM_ID; if (proc < NULL) - return ERR_INVALID_ARGS; + return EINVAL; // XXX: todo check if proc exists // if (proc_get_proc_struct(proc) == NULL) @@ -687,17 +688,13 @@ int set_sem_owner(sem_id id, proc_id proc) // this function must be entered with interrupts disabled and THREADLOCK held int sem_interrupt_thread(struct thread *t) { -// struct thread *t1; int slot; -// int state; struct thread_queue wakeup_queue; // dprintf("sem_interrupt_thread: called on thread %p (%d), blocked on sem 0x%x\n", t, t->id, t->sem_blocking); - if(t->state != THREAD_STATE_WAITING) - return ERR_INVALID_ARGS; - if(t->sem_blocking < 0) - return ERR_INVALID_ARGS; + if(t->state != THREAD_STATE_WAITING || t->sem_blocking < 0) + return EINVAL; if((t->sem_flags & B_CAN_INTERRUPT) == 0) return ERR_SEM_NOT_INTERRUPTABLE; diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index d1a2c3e5a9..8eb458cdf6 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -251,7 +251,7 @@ static int user_copy_arg_list(char **args, int argc, char ***kargs) largs = (char **)kmalloc((argc + 1) * sizeof(char *)); if(largs == NULL){ - return ERR_NO_MEMORY; + return ENOMEM; } // scan all parameters and copy to kernel space @@ -273,7 +273,7 @@ static int user_copy_arg_list(char **args, int argc, char ***kargs) largs[cnt] = (char *)kstrdup(buf); if(largs[cnt] == NULL){ - err = ERR_NO_MEMORY; + err = ENOMEM; goto error; } } @@ -407,7 +407,7 @@ static thread_id _create_thread(const char *name, proc_id pid, addr entry, void t = create_thread_struct(name); if(t == NULL) - return ERR_NO_MEMORY; + return ENOMEM; t->priority = priority == -1 ? THREAD_MEDIUM_PRIORITY : priority; t->state = THREAD_STATE_BIRTH; @@ -536,7 +536,7 @@ int thread_suspend_thread(thread_id id) if (t != NULL) { if (t->proc == kernel_proc) { // no way - retval = ERR_NOT_ALLOWED; + retval = EPERM; } else if (t->in_kernel == true) { t->pending_signals |= SIG_SUSPEND; retval = B_NO_ERROR; @@ -962,7 +962,7 @@ int thread_init(kernel_args *ka) t = create_thread_struct(temp); if(t == NULL) { panic("error creating idle thread struct\n"); - return ERR_NO_MEMORY; + return ENOMEM; } t->proc = proc_get_kernel_proc(); t->priority = THREAD_IDLE_PRIORITY; @@ -996,7 +996,7 @@ int thread_init(kernel_args *ka) death_stacks = (struct death_stack *)kmalloc(num_death_stacks * sizeof(struct death_stack)); if(death_stacks == NULL) { panic("error creating death stacks\n"); - return ERR_NO_MEMORY; + return ENOMEM; } { char temp[64]; @@ -1253,7 +1253,7 @@ static int _thread_kill_thread(thread_id id, bool wait_on) if(t != NULL) { if(t->proc == kernel_proc) { // can't touch this - rc = ERR_NOT_ALLOWED; + rc = EPERM; } else { deliver_signal(t, SIG_KILL); rc = B_NO_ERROR; @@ -1330,7 +1330,7 @@ int thread_wait_on_thread(thread_id id, int *retcode) rc = acquire_sem(sem); /* This thread died the way it should, dont ripple a non-error up */ - if (rc == ERR_SEM_DELETED) + if (rc == B_BAD_SEM_ID) rc = B_NO_ERROR; return rc; @@ -1732,7 +1732,7 @@ proc_id proc_create_proc(const char *path, const char *name, char **args, int ar p = create_proc_struct(name, false); if(p == NULL) - return ERR_NO_MEMORY; + return ENOMEM; pid = p->id; @@ -1745,12 +1745,12 @@ proc_id proc_create_proc(const char *path, const char *name, char **args, int ar // copy the args over pargs = (struct proc_arg *)kmalloc(sizeof(struct proc_arg)); if(pargs == NULL){ - err = ERR_NO_MEMORY; + err = ENOMEM; goto err1; } pargs->path = (char *)kstrdup(path); if(pargs->path == NULL){ - err = ERR_NO_MEMORY; + err = ENOMEM; goto err2; } pargs->argc = argc; @@ -1759,7 +1759,7 @@ proc_id proc_create_proc(const char *path, const char *name, char **args, int ar // create a new ioctx for this process p->ioctx = vfs_new_io_context(thread_get_current_thread()->proc->ioctx); if(!p->ioctx) { - err = ERR_NO_MEMORY; + err = ENOMEM; goto err3; } @@ -1876,7 +1876,7 @@ int user_proc_get_table(struct proc_info *pbuf, size_t len) if (count < max) return count; else - return ERR_NO_MEMORY; + return ENOMEM; } @@ -2019,7 +2019,7 @@ int user_getrlimit(int resource, struct rlimit * urlp) struct rlimit rl; if (urlp == NULL) { - return ERR_INVALID_ARGS; + return EINVAL; } if((addr)urlp >= KERNEL_BASE && (addr)urlp <= KERNEL_TOP) { return ERR_VM_BAD_USER_MEMORY; @@ -2061,7 +2061,7 @@ int user_setrlimit(int resource, const struct rlimit * urlp) struct rlimit rl; if (urlp == NULL) { - return ERR_INVALID_ARGS; + return EINVAL; } if((addr)urlp >= KERNEL_BASE && (addr)urlp <= KERNEL_TOP) { return ERR_VM_BAD_USER_MEMORY;