diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:01:38 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:01:38 +0100 |
commit | f7d30133221896638f7bf4f66c504255c4b14f48 (patch) | |
tree | 5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/pr/src/md/unix | |
parent | 26b297510a11758727438df4669357a2a2bc42ce (diff) | |
download | UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip |
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/pr/src/md/unix')
25 files changed, 1413 insertions, 3362 deletions
diff --git a/nsprpub/pr/src/md/unix/aix.c b/nsprpub/pr/src/md/unix/aix.c index 43f0d58de..c632c5790 100644 --- a/nsprpub/pr/src/md/unix/aix.c +++ b/nsprpub/pr/src/md/unix/aix.c @@ -73,7 +73,7 @@ int _pr_aix_send_file_use_disabled = 0; void _MD_EarlyInit(void) { void *main_app_handle; - char *evp; + char *evp; main_app_handle = dlopen(NULL, RTLD_NOW); PR_ASSERT(NULL != main_app_handle); @@ -85,10 +85,11 @@ void _MD_EarlyInit(void) } dlclose(main_app_handle); - if (evp = getenv("NSPR_AIX_SEND_FILE_USE_DISABLED")) { - if (1 == atoi(evp)) - _pr_aix_send_file_use_disabled = 1; - } + if (evp = getenv("NSPR_AIX_SEND_FILE_USE_DISABLED")) { + if (1 == atoi(evp)) { + _pr_aix_send_file_use_disabled = 1; + } + } #if defined(AIX_TIMERS) _MD_AixIntervalInit(); @@ -110,13 +111,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } @@ -130,7 +131,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PR_IMPLEMENT(PRStatus) _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PR_IMPLEMENT(PRStatus) @@ -145,7 +146,7 @@ PR_IMPLEMENT(PRStatus) _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -193,17 +194,17 @@ int _MD_SELECT(int width, fd_set *r, fd_set *w, fd_set *e, struct timeval *t) if (!aix_select_fcn) { void *aix_handle; - aix_handle = dlopen("/unix", RTLD_NOW); - if (!aix_handle) { - PR_SetError(PR_UNKNOWN_ERROR, 0); - return -1; - } - aix_select_fcn = (int(*)())dlsym(aix_handle,"select"); + aix_handle = dlopen("/unix", RTLD_NOW); + if (!aix_handle) { + PR_SetError(PR_UNKNOWN_ERROR, 0); + return -1; + } + aix_select_fcn = (int(*)())dlsym(aix_handle,"select"); dlclose(aix_handle); - if (!aix_select_fcn) { - PR_SetError(PR_UNKNOWN_ERROR, 0); - return -1; - } + if (!aix_select_fcn) { + PR_SetError(PR_UNKNOWN_ERROR, 0); + return -1; + } } rv = (*aix_select_fcn)(width, r, w, e, t); return rv; @@ -216,17 +217,17 @@ int _MD_POLL(void *listptr, unsigned long nfds, long timeout) if (!aix_poll_fcn) { void *aix_handle; - aix_handle = dlopen("/unix", RTLD_NOW); - if (!aix_handle) { - PR_SetError(PR_UNKNOWN_ERROR, 0); - return -1; - } - aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll"); + aix_handle = dlopen("/unix", RTLD_NOW); + if (!aix_handle) { + PR_SetError(PR_UNKNOWN_ERROR, 0); + return -1; + } + aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll"); dlclose(aix_handle); - if (!aix_poll_fcn) { - PR_SetError(PR_UNKNOWN_ERROR, 0); - return -1; - } + if (!aix_poll_fcn) { + PR_SetError(PR_UNKNOWN_ERROR, 0); + return -1; + } } rv = (*aix_poll_fcn)(listptr, nfds, timeout); return rv; @@ -251,51 +252,51 @@ void _pr_aix_dummy() #include "pratom.h" -#define _PR_AIX_ATOMIC_LOCK -1 +#define _PR_AIX_ATOMIC_LOCK -1 PR_IMPLEMENT(void) PR_StackPush(PRStack *stack, PRStackElem *stack_elem) { -PRStackElem *addr; -boolean_t locked = TRUE; - - /* Is it safe to cast a pointer to an int? */ - PR_ASSERT(sizeof(int) == sizeof(PRStackElem *)); - do { - while ((addr = stack->prstk_head.prstk_elem_next) == - (PRStackElem *)_PR_AIX_ATOMIC_LOCK) - ; - locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next, - (int) addr, _PR_AIX_ATOMIC_LOCK); - } while (locked == TRUE); - stack_elem->prstk_elem_next = addr; - _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem); + PRStackElem *addr; + boolean_t locked = TRUE; + + /* Is it safe to cast a pointer to an int? */ + PR_ASSERT(sizeof(int) == sizeof(PRStackElem *)); + do { + while ((addr = stack->prstk_head.prstk_elem_next) == + (PRStackElem *)_PR_AIX_ATOMIC_LOCK) + ; + locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next, + (int) addr, _PR_AIX_ATOMIC_LOCK); + } while (locked == TRUE); + stack_elem->prstk_elem_next = addr; + _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem); return; } PR_IMPLEMENT(PRStackElem *) PR_StackPop(PRStack *stack) { -PRStackElem *element; -boolean_t locked = TRUE; - - /* Is it safe to cast a pointer to an int? */ - PR_ASSERT(sizeof(int) == sizeof(PRStackElem *)); - do { - while ((element = stack->prstk_head.prstk_elem_next) == - (PRStackElem *) _PR_AIX_ATOMIC_LOCK) - ; - locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next, - (int)element, _PR_AIX_ATOMIC_LOCK); - } while (locked == TRUE); - - if (element == NULL) { - _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL); - } else { - _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, - (int) element->prstk_elem_next); - } - return element; + PRStackElem *element; + boolean_t locked = TRUE; + + /* Is it safe to cast a pointer to an int? */ + PR_ASSERT(sizeof(int) == sizeof(PRStackElem *)); + do { + while ((element = stack->prstk_head.prstk_elem_next) == + (PRStackElem *) _PR_AIX_ATOMIC_LOCK) + ; + locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next, + (int)element, _PR_AIX_ATOMIC_LOCK); + } while (locked == TRUE); + + if (element == NULL) { + _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL); + } else { + _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, + (int) element->prstk_elem_next); + } + return element; } -#endif /* _PR_HAVE_ATOMIC_CAS */ +#endif /* _PR_HAVE_ATOMIC_CAS */ diff --git a/nsprpub/pr/src/md/unix/aixwrap.c b/nsprpub/pr/src/md/unix/aixwrap.c index cb5b413f1..853825196 100644 --- a/nsprpub/pr/src/md/unix/aixwrap.c +++ b/nsprpub/pr/src/md/unix/aixwrap.c @@ -4,7 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * File: aixwrap.c + * File: aixwrap.c * Description: * This file contains a single function, _MD_SELECT(), which simply * invokes the select() function. This file is used in an ugly diff --git a/nsprpub/pr/src/md/unix/bsdi.c b/nsprpub/pr/src/md/unix/bsdi.c index 095547ed5..e625003f7 100644 --- a/nsprpub/pr/src/md/unix/bsdi.c +++ b/nsprpub/pr/src/md/unix/bsdi.c @@ -25,7 +25,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); @@ -45,7 +45,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -60,7 +60,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -82,6 +82,6 @@ _MD_CREATE_THREAD( PRUint32 stackSize) { PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for BSDI."); - return PR_FAILURE; + return PR_FAILURE; } #endif /* ! _PR_PTHREADS */ diff --git a/nsprpub/pr/src/md/unix/darwin.c b/nsprpub/pr/src/md/unix/darwin.c index 719fc30f2..6135e082f 100644 --- a/nsprpub/pr/src/md/unix/darwin.c +++ b/nsprpub/pr/src/md/unix/darwin.c @@ -48,13 +48,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #if !defined(_PR_PTHREADS) if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } @@ -68,7 +68,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -83,7 +83,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -105,7 +105,7 @@ _MD_CREATE_THREAD( PRUint32 stackSize) { PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Darwin."); - return PR_FAILURE; + return PR_FAILURE; } #endif /* ! _PR_PTHREADS */ diff --git a/nsprpub/pr/src/md/unix/freebsd.c b/nsprpub/pr/src/md/unix/freebsd.c index a66a81284..19af17a44 100644 --- a/nsprpub/pr/src/md/unix/freebsd.c +++ b/nsprpub/pr/src/md/unix/freebsd.c @@ -25,13 +25,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) sigsetjmp(CONTEXT(t), 1); + (void) sigsetjmp(CONTEXT(t), 1); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } @@ -45,7 +45,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -60,7 +60,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -82,6 +82,6 @@ _MD_CREATE_THREAD( PRUint32 stackSize) { PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for FreeBSD."); - return PR_FAILURE; + return PR_FAILURE; } #endif /* ! _PR_PTHREADS */ diff --git a/nsprpub/pr/src/md/unix/hpux.c b/nsprpub/pr/src/md/unix/hpux.c index 56fddba29..bf72567fd 100644 --- a/nsprpub/pr/src/md/unix/hpux.c +++ b/nsprpub/pr/src/md/unix/hpux.c @@ -84,7 +84,7 @@ void _MD_EarlyInit(void) if(!setjmp(jb)) { newstack = (char *) PR_MALLOC(PIDOOMA_STACK_SIZE); - oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE); + oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE); memcpy(newstack, oldstack, BACKTRACE_SIZE); *(((int *) jb) + 1) = (int) (newstack + BACKTRACE_SIZE); longjmp(jb, 1); @@ -98,13 +98,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } @@ -118,7 +118,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -133,7 +133,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -208,7 +208,7 @@ strchr(const char *s, int c) * A.09.07, and B.10.10) dumps core if called with: * 1. First operand with address = 1(mod 4). * 2. Size = 1(mod 4) - * 3. Last byte of the second operand is the last byte of the page and + * 3. Last byte of the second operand is the last byte of the page and * next page is not accessible(not mapped or protected) * Thus, using the following naive version (tons of optimizations are * possible;^) @@ -217,13 +217,15 @@ strchr(const char *s, int c) int memcmp(const void *s1, const void *s2, size_t n) { register unsigned char *p1 = (unsigned char *) s1, - *p2 = (unsigned char *) s2; + *p2 = (unsigned char *) s2; while (n-- > 0) { - register int r = ((int) ((unsigned int) *p1)) - - ((int) ((unsigned int) *p2)); - if (r) return r; + register int r = ((int) ((unsigned int) *p1)) + - ((int) ((unsigned int) *p2)); + if (r) { + return r; + } p1++; p2++; } - return 0; + return 0; } diff --git a/nsprpub/pr/src/md/unix/irix.c b/nsprpub/pr/src/md/unix/irix.c deleted file mode 100644 index c57a07b33..000000000 --- a/nsprpub/pr/src/md/unix/irix.c +++ /dev/null @@ -1,1648 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "primpl.h" - -#include <signal.h> - -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include <sys/mman.h> -#include <sys/syssgi.h> -#include <sys/time.h> -#include <sys/immu.h> -#include <sys/utsname.h> -#include <sys/sysmp.h> -#include <sys/pda.h> -#include <sys/prctl.h> -#include <sys/wait.h> -#include <sys/resource.h> -#include <sys/procfs.h> -#include <task.h> -#include <dlfcn.h> - -static void _MD_IrixIntervalInit(void); - -#if defined(_PR_PTHREADS) -/* - * for compatibility with classic nspr - */ -void _PR_IRIX_CHILD_PROCESS() -{ -} -#else /* defined(_PR_PTHREADS) */ - -static void irix_detach_sproc(void); -char *_nspr_sproc_private; /* ptr. to private region in every sproc */ - -extern PRUintn _pr_numCPU; - -typedef struct nspr_arena { - PRCList links; - usptr_t *usarena; -} nspr_arena; - -#define ARENA_PTR(qp) \ - ((nspr_arena *) ((char*) (qp) - offsetof(nspr_arena , links))) - -static usptr_t *alloc_new_arena(void); - -PRCList arena_list = PR_INIT_STATIC_CLIST(&arena_list); -ulock_t arena_list_lock; -nspr_arena first_arena; -int _nspr_irix_arena_cnt = 1; - -PRCList sproc_list = PR_INIT_STATIC_CLIST(&sproc_list); -ulock_t sproc_list_lock; - -typedef struct sproc_data { - void (*entry) (void *, size_t); - unsigned inh; - void *arg; - caddr_t sp; - size_t len; - int *pid; - int creator_pid; -} sproc_data; - -typedef struct sproc_params { - PRCList links; - sproc_data sd; -} sproc_params; - -#define SPROC_PARAMS_PTR(qp) \ - ((sproc_params *) ((char*) (qp) - offsetof(sproc_params , links))) - -long _nspr_irix_lock_cnt = 0; -long _nspr_irix_sem_cnt = 0; -long _nspr_irix_pollsem_cnt = 0; - -usptr_t *_pr_usArena; -ulock_t _pr_heapLock; - -usema_t *_pr_irix_exit_sem; -PRInt32 _pr_irix_exit_now = 0; -PRInt32 _pr_irix_process_exit_code = 0; /* exit code for PR_ProcessExit */ -PRInt32 _pr_irix_process_exit = 0; /* process exiting due to call to - PR_ProcessExit */ - -int _pr_irix_primoridal_cpu_fd[2] = { -1, -1 }; -static void (*libc_exit)(int) = NULL; -static void *libc_handle = NULL; - -#define _NSPR_DEF_INITUSERS 100 /* default value of CONF_INITUSERS */ -#define _NSPR_DEF_INITSIZE (4 * 1024 * 1024) /* 4 MB */ - -int _irix_initusers = _NSPR_DEF_INITUSERS; -int _irix_initsize = _NSPR_DEF_INITSIZE; - -PRIntn _pr_io_in_progress, _pr_clock_in_progress; - -PRInt32 _pr_md_irix_sprocs_created, _pr_md_irix_sprocs_failed; -PRInt32 _pr_md_irix_sprocs = 1; -PRCList _pr_md_irix_sproc_list = -PR_INIT_STATIC_CLIST(&_pr_md_irix_sproc_list); - -sigset_t ints_off; -extern sigset_t timer_set; - -#if !defined(PR_SETABORTSIG) -#define PR_SETABORTSIG 18 -#endif -/* - * terminate the entire application if any sproc exits abnormally - */ -PRBool _nspr_terminate_on_error = PR_TRUE; - -/* - * exported interface to set the shared arena parameters - */ -void _PR_Irix_Set_Arena_Params(PRInt32 initusers, PRInt32 initsize) -{ - _irix_initusers = initusers; - _irix_initsize = initsize; -} - -static usptr_t *alloc_new_arena() -{ - return(usinit("/dev/zero")); -} - -static PRStatus new_poll_sem(struct _MDThread *mdthr, int val) -{ -PRIntn _is; -PRStatus rv = PR_SUCCESS; -usema_t *sem = NULL; -PRCList *qp; -nspr_arena *arena; -usptr_t *irix_arena; -PRThread *me = _MD_GET_ATTACHED_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(_is); - _PR_LOCK(arena_list_lock); - for (qp = arena_list.next; qp != &arena_list; qp = qp->next) { - arena = ARENA_PTR(qp); - sem = usnewpollsema(arena->usarena, val); - if (sem != NULL) { - mdthr->cvar_pollsem = sem; - mdthr->pollsem_arena = arena->usarena; - break; - } - } - if (sem == NULL) { - /* - * If no space left in the arena allocate a new one. - */ - if (errno == ENOMEM) { - arena = PR_NEWZAP(nspr_arena); - if (arena != NULL) { - irix_arena = alloc_new_arena(); - if (irix_arena) { - PR_APPEND_LINK(&arena->links, &arena_list); - _nspr_irix_arena_cnt++; - arena->usarena = irix_arena; - sem = usnewpollsema(arena->usarena, val); - if (sem != NULL) { - mdthr->cvar_pollsem = sem; - mdthr->pollsem_arena = arena->usarena; - } else - rv = PR_FAILURE; - } else { - PR_DELETE(arena); - rv = PR_FAILURE; - } - - } else - rv = PR_FAILURE; - } else - rv = PR_FAILURE; - } - _PR_UNLOCK(arena_list_lock); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(_is); - if (rv == PR_SUCCESS) - _MD_ATOMIC_INCREMENT(&_nspr_irix_pollsem_cnt); - return rv; -} - -static void free_poll_sem(struct _MDThread *mdthr) -{ -PRIntn _is; -PRThread *me = _MD_GET_ATTACHED_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(_is); - usfreepollsema(mdthr->cvar_pollsem, mdthr->pollsem_arena); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(_is); - _MD_ATOMIC_DECREMENT(&_nspr_irix_pollsem_cnt); -} - -static PRStatus new_lock(struct _MDLock *lockp) -{ -PRIntn _is; -PRStatus rv = PR_SUCCESS; -ulock_t lock = NULL; -PRCList *qp; -nspr_arena *arena; -usptr_t *irix_arena; -PRThread *me = _MD_GET_ATTACHED_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(_is); - _PR_LOCK(arena_list_lock); - for (qp = arena_list.next; qp != &arena_list; qp = qp->next) { - arena = ARENA_PTR(qp); - lock = usnewlock(arena->usarena); - if (lock != NULL) { - lockp->lock = lock; - lockp->arena = arena->usarena; - break; - } - } - if (lock == NULL) { - /* - * If no space left in the arena allocate a new one. - */ - if (errno == ENOMEM) { - arena = PR_NEWZAP(nspr_arena); - if (arena != NULL) { - irix_arena = alloc_new_arena(); - if (irix_arena) { - PR_APPEND_LINK(&arena->links, &arena_list); - _nspr_irix_arena_cnt++; - arena->usarena = irix_arena; - lock = usnewlock(irix_arena); - if (lock != NULL) { - lockp->lock = lock; - lockp->arena = arena->usarena; - } else - rv = PR_FAILURE; - } else { - PR_DELETE(arena); - rv = PR_FAILURE; - } - - } else - rv = PR_FAILURE; - } else - rv = PR_FAILURE; - } - _PR_UNLOCK(arena_list_lock); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(_is); - if (rv == PR_SUCCESS) - _MD_ATOMIC_INCREMENT(&_nspr_irix_lock_cnt); - return rv; -} - -static void free_lock(struct _MDLock *lockp) -{ -PRIntn _is; -PRThread *me = _MD_GET_ATTACHED_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(_is); - usfreelock(lockp->lock, lockp->arena); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(_is); - _MD_ATOMIC_DECREMENT(&_nspr_irix_lock_cnt); -} - -void _MD_FREE_LOCK(struct _MDLock *lockp) -{ - PRIntn _is; - PRThread *me = _MD_GET_ATTACHED_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(_is); - free_lock(lockp); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(_is); -} - -/* - * _MD_get_attached_thread - * Return the thread pointer of the current thread if it is attached. - * - * This function is needed for Irix because the thread-local-storage is - * implemented by mmapin'g a page with the MAP_LOCAL flag. This causes the - * sproc-private page to inherit contents of the page of the caller of sproc(). - */ -PRThread *_MD_get_attached_thread(void) -{ - - if (_MD_GET_SPROC_PID() == get_pid()) - return _MD_THIS_THREAD(); - else - return 0; -} - -/* - * _MD_get_current_thread - * Return the thread pointer of the current thread (attaching it if - * necessary) - */ -PRThread *_MD_get_current_thread(void) -{ -PRThread *me; - - me = _MD_GET_ATTACHED_THREAD(); - if (NULL == me) { - me = _PRI_AttachThread( - PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0); - } - PR_ASSERT(me != NULL); - return(me); -} - -/* - * irix_detach_sproc - * auto-detach a sproc when it exits - */ -void irix_detach_sproc(void) -{ -PRThread *me; - - me = _MD_GET_ATTACHED_THREAD(); - if ((me != NULL) && (me->flags & _PR_ATTACHED)) { - _PRI_DetachThread(); - } -} - - -PRStatus _MD_NEW_LOCK(struct _MDLock *lockp) -{ - PRStatus rv; - PRIntn is; - PRThread *me = _MD_GET_ATTACHED_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); - rv = new_lock(lockp); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - return rv; -} - -static void -sigchld_handler(int sig) -{ - pid_t pid; - int status; - - /* - * If an sproc exited abnormally send a SIGKILL signal to all the - * sprocs in the process to terminate the application - */ - while ((pid = waitpid(0, &status, WNOHANG)) > 0) { - if (WIFSIGNALED(status) && ((WTERMSIG(status) == SIGSEGV) || - (WTERMSIG(status) == SIGBUS) || - (WTERMSIG(status) == SIGABRT) || - (WTERMSIG(status) == SIGILL))) { - - prctl(PR_SETEXITSIG, SIGKILL); - _exit(status); - } - } -} - -static void save_context_and_block(int sig) -{ -PRThread *me = _PR_MD_CURRENT_THREAD(); -_PRCPU *cpu = _PR_MD_CURRENT_CPU(); - - /* - * save context - */ - (void) setjmp(me->md.jb); - /* - * unblock the suspending thread - */ - if (me->cpu) { - /* - * I am a cpu thread, not a user-created GLOBAL thread - */ - unblockproc(cpu->md.suspending_id); - } else { - unblockproc(me->md.suspending_id); - } - /* - * now, block current thread - */ - blockproc(getpid()); -} - -/* -** The irix kernel has a bug in it which causes async connect's which are -** interrupted by a signal to fail terribly (EADDRINUSE is returned). -** We work around the bug by blocking signals during the async connect -** attempt. -*/ -PRInt32 _MD_irix_connect( - PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout) -{ - PRInt32 rv; - sigset_t oldset; - - sigprocmask(SIG_BLOCK, &ints_off, &oldset); - rv = connect(osfd, addr, addrlen); - sigprocmask(SIG_SETMASK, &oldset, 0); - - return(rv); -} - -#include "prprf.h" - -/********************************************************************/ -/********************************************************************/ -/*************** Various thread like things for IRIX ****************/ -/********************************************************************/ -/********************************************************************/ - -void *_MD_GetSP(PRThread *t) -{ - PRThread *me = _PR_MD_CURRENT_THREAD(); - void *sp; - - if (me == t) - (void) setjmp(t->md.jb); - - sp = (void *)(t->md.jb[JB_SP]); - PR_ASSERT((sp >= (void *) t->stack->stackBottom) && - (sp <= (void *) (t->stack->stackBottom + t->stack->stackSize))); - return(sp); -} - -void _MD_InitLocks() -{ - char buf[200]; - char *init_users, *init_size; - - PR_snprintf(buf, sizeof(buf), "/dev/zero"); - - if (init_users = getenv("_NSPR_IRIX_INITUSERS")) - _irix_initusers = atoi(init_users); - - if (init_size = getenv("_NSPR_IRIX_INITSIZE")) - _irix_initsize = atoi(init_size); - - usconfig(CONF_INITUSERS, _irix_initusers); - usconfig(CONF_INITSIZE, _irix_initsize); - usconfig(CONF_AUTOGROW, 1); - usconfig(CONF_AUTORESV, 1); - if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0) { - perror("PR_Init: unable to config mutex arena"); - exit(-1); - } - - _pr_usArena = usinit(buf); - if (!_pr_usArena) { - fprintf(stderr, - "PR_Init: Error - unable to create lock/monitor arena\n"); - exit(-1); - } - _pr_heapLock = usnewlock(_pr_usArena); - _nspr_irix_lock_cnt++; - - arena_list_lock = usnewlock(_pr_usArena); - _nspr_irix_lock_cnt++; - - sproc_list_lock = usnewlock(_pr_usArena); - _nspr_irix_lock_cnt++; - - _pr_irix_exit_sem = usnewsema(_pr_usArena, 0); - _nspr_irix_sem_cnt = 1; - - first_arena.usarena = _pr_usArena; - PR_INIT_CLIST(&first_arena.links); - PR_APPEND_LINK(&first_arena.links, &arena_list); -} - -/* _PR_IRIX_CHILD_PROCESS is a private API for Server group */ -void _PR_IRIX_CHILD_PROCESS() -{ -extern PRUint32 _pr_global_threads; - - PR_ASSERT(_PR_MD_CURRENT_CPU() == _pr_primordialCPU); - PR_ASSERT(_pr_numCPU == 1); - PR_ASSERT(_pr_global_threads == 0); - /* - * save the new pid - */ - _pr_primordialCPU->md.id = getpid(); - _MD_SET_SPROC_PID(getpid()); -} - -static PRStatus pr_cvar_wait_sem(PRThread *thread, PRIntervalTime timeout) -{ - int rv; - -#ifdef _PR_USE_POLL - struct pollfd pfd; - int msecs; - - if (timeout == PR_INTERVAL_NO_TIMEOUT) - msecs = -1; - else - msecs = PR_IntervalToMilliseconds(timeout); -#else - struct timeval tv, *tvp; - fd_set rd; - - if(timeout == PR_INTERVAL_NO_TIMEOUT) - tvp = NULL; - else { - tv.tv_sec = PR_IntervalToSeconds(timeout); - tv.tv_usec = PR_IntervalToMicroseconds( - timeout - PR_SecondsToInterval(tv.tv_sec)); - tvp = &tv; - } - FD_ZERO(&rd); - FD_SET(thread->md.cvar_pollsemfd, &rd); -#endif - - /* - * call uspsema only if a previous select call on this semaphore - * did not timeout - */ - if (!thread->md.cvar_pollsem_select) { - rv = _PR_WAIT_SEM(thread->md.cvar_pollsem); - PR_ASSERT(rv >= 0); - } else - rv = 0; -again: - if(!rv) { -#ifdef _PR_USE_POLL - pfd.events = POLLIN; - pfd.fd = thread->md.cvar_pollsemfd; - rv = _MD_POLL(&pfd, 1, msecs); -#else - rv = _MD_SELECT(thread->md.cvar_pollsemfd + 1, &rd, NULL,NULL,tvp); -#endif - if ((rv == -1) && (errno == EINTR)) { - rv = 0; - goto again; - } - PR_ASSERT(rv >= 0); - } - - if (rv > 0) { - /* - * acquired the semaphore, call uspsema next time - */ - thread->md.cvar_pollsem_select = 0; - return PR_SUCCESS; - } else { - /* - * select timed out; must call select, not uspsema, when trying - * to acquire the semaphore the next time - */ - thread->md.cvar_pollsem_select = 1; - return PR_FAILURE; - } -} - -PRStatus _MD_wait(PRThread *thread, PRIntervalTime ticks) -{ - if ( thread->flags & _PR_GLOBAL_SCOPE ) { - _MD_CHECK_FOR_EXIT(); - if (pr_cvar_wait_sem(thread, ticks) == PR_FAILURE) { - _MD_CHECK_FOR_EXIT(); - /* - * wait timed out - */ - _PR_THREAD_LOCK(thread); - if (thread->wait.cvar) { - /* - * The thread will remove itself from the waitQ - * of the cvar in _PR_WaitCondVar - */ - thread->wait.cvar = NULL; - thread->state = _PR_RUNNING; - _PR_THREAD_UNLOCK(thread); - } else { - _PR_THREAD_UNLOCK(thread); - /* - * This thread was woken up by a notifying thread - * at the same time as a timeout; so, consume the - * extra post operation on the semaphore - */ - _MD_CHECK_FOR_EXIT(); - pr_cvar_wait_sem(thread, PR_INTERVAL_NO_TIMEOUT); - } - _MD_CHECK_FOR_EXIT(); - } - } else { - _PR_MD_SWITCH_CONTEXT(thread); - } - return PR_SUCCESS; -} - -PRStatus _MD_WakeupWaiter(PRThread *thread) -{ - PRThread *me = _PR_MD_CURRENT_THREAD(); - PRIntn is; - - PR_ASSERT(_pr_md_idle_cpus >= 0); - if (thread == NULL) { - if (_pr_md_idle_cpus) - _MD_Wakeup_CPUs(); - } else if (!_PR_IS_NATIVE_THREAD(thread)) { - if (_pr_md_idle_cpus) - _MD_Wakeup_CPUs(); - } else { - PR_ASSERT(_PR_IS_NATIVE_THREAD(thread)); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); - _MD_CVAR_POST_SEM(thread); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - } - return PR_SUCCESS; -} - -void create_sproc (void (*entry) (void *, size_t), unsigned inh, - void *arg, caddr_t sp, size_t len, int *pid) -{ -sproc_params sparams; -char data; -int rv; -PRThread *me = _PR_MD_CURRENT_THREAD(); - - if (!_PR_IS_NATIVE_THREAD(me) && (_PR_MD_CURRENT_CPU()->id == 0)) { - *pid = sprocsp(entry, /* startup func */ - inh, /* attribute flags */ - arg, /* thread param */ - sp, /* stack address */ - len); /* stack size */ - } else { - sparams.sd.entry = entry; - sparams.sd.inh = inh; - sparams.sd.arg = arg; - sparams.sd.sp = sp; - sparams.sd.len = len; - sparams.sd.pid = pid; - sparams.sd.creator_pid = getpid(); - _PR_LOCK(sproc_list_lock); - PR_APPEND_LINK(&sparams.links, &sproc_list); - rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1); - PR_ASSERT(rv == 1); - _PR_UNLOCK(sproc_list_lock); - blockproc(getpid()); - } -} - -/* - * _PR_MD_WAKEUP_PRIMORDIAL_CPU - * - * wakeup cpu 0 - */ - -void _PR_MD_WAKEUP_PRIMORDIAL_CPU() -{ -char data = '0'; -int rv; - - rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1); - PR_ASSERT(rv == 1); -} - -/* - * _PR_MD_primordial_cpu - * - * process events that need to executed by the primordial cpu on each - * iteration through the idle loop - */ - -void _PR_MD_primordial_cpu() -{ -PRCList *qp; -sproc_params *sp; -int pid; - - _PR_LOCK(sproc_list_lock); - while ((qp = sproc_list.next) != &sproc_list) { - sp = SPROC_PARAMS_PTR(qp); - PR_REMOVE_LINK(&sp->links); - pid = sp->sd.creator_pid; - (*(sp->sd.pid)) = sprocsp(sp->sd.entry, /* startup func */ - sp->sd.inh, /* attribute flags */ - sp->sd.arg, /* thread param */ - sp->sd.sp, /* stack address */ - sp->sd.len); /* stack size */ - unblockproc(pid); - } - _PR_UNLOCK(sproc_list_lock); -} - -PRStatus _MD_CreateThread(PRThread *thread, -void (*start)(void *), -PRThreadPriority priority, -PRThreadScope scope, -PRThreadState state, -PRUint32 stackSize) -{ - typedef void (*SprocEntry) (void *, size_t); - SprocEntry spentry = (SprocEntry)start; - PRIntn is; - PRThread *me = _PR_MD_CURRENT_THREAD(); - PRInt32 pid; - PRStatus rv; - - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); - thread->md.cvar_pollsem_select = 0; - thread->flags |= _PR_GLOBAL_SCOPE; - - thread->md.cvar_pollsemfd = -1; - if (new_poll_sem(&thread->md,0) == PR_FAILURE) { - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - return PR_FAILURE; - } - thread->md.cvar_pollsemfd = - _PR_OPEN_POLL_SEM(thread->md.cvar_pollsem); - if ((thread->md.cvar_pollsemfd < 0)) { - free_poll_sem(&thread->md); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - return PR_FAILURE; - } - - create_sproc(spentry, /* startup func */ - PR_SALL, /* attribute flags */ - (void *)thread, /* thread param */ - NULL, /* stack address */ - stackSize, &pid); /* stack size */ - if (pid > 0) { - _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs_created); - _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs); - rv = PR_SUCCESS; - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - return rv; - } else { - close(thread->md.cvar_pollsemfd); - thread->md.cvar_pollsemfd = -1; - free_poll_sem(&thread->md); - thread->md.cvar_pollsem = NULL; - _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs_failed); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - return PR_FAILURE; - } -} - -void _MD_CleanThread(PRThread *thread) -{ - if (thread->flags & _PR_GLOBAL_SCOPE) { - close(thread->md.cvar_pollsemfd); - thread->md.cvar_pollsemfd = -1; - free_poll_sem(&thread->md); - thread->md.cvar_pollsem = NULL; - } -} - -void _MD_SetPriority(_MDThread *thread, PRThreadPriority newPri) -{ - return; -} - -extern void _MD_unix_terminate_waitpid_daemon(void); - -void -_MD_CleanupBeforeExit(void) -{ - extern PRInt32 _pr_cpus_exit; - - _MD_unix_terminate_waitpid_daemon(); - - _pr_irix_exit_now = 1; - if (_pr_numCPU > 1) { - /* - * Set a global flag, and wakeup all cpus which will notice the flag - * and exit. - */ - _pr_cpus_exit = getpid(); - _MD_Wakeup_CPUs(); - while(_pr_numCPU > 1) { - _PR_WAIT_SEM(_pr_irix_exit_sem); - _pr_numCPU--; - } - } - /* - * cause global threads on the recycle list to exit - */ - _PR_DEADQ_LOCK; - if (_PR_NUM_DEADNATIVE != 0) { - PRThread *thread; - PRCList *ptr; - - ptr = _PR_DEADNATIVEQ.next; - while( ptr != &_PR_DEADNATIVEQ ) { - thread = _PR_THREAD_PTR(ptr); - _MD_CVAR_POST_SEM(thread); - ptr = ptr->next; - } - } - _PR_DEADQ_UNLOCK; - while(_PR_NUM_DEADNATIVE > 1) { - _PR_WAIT_SEM(_pr_irix_exit_sem); - _PR_DEC_DEADNATIVE; - } -} - -#ifdef _PR_HAVE_SGI_PRDA_PROCMASK -extern void __sgi_prda_procmask(int); -#endif - -PRStatus -_MD_InitAttachedThread(PRThread *thread, PRBool wakeup_parent) -{ - PRStatus rv = PR_SUCCESS; - - if (thread->flags & _PR_GLOBAL_SCOPE) { - if (new_poll_sem(&thread->md,0) == PR_FAILURE) { - return PR_FAILURE; - } - thread->md.cvar_pollsemfd = - _PR_OPEN_POLL_SEM(thread->md.cvar_pollsem); - if ((thread->md.cvar_pollsemfd < 0)) { - free_poll_sem(&thread->md); - return PR_FAILURE; - } - if (_MD_InitThread(thread, PR_FALSE) == PR_FAILURE) { - close(thread->md.cvar_pollsemfd); - thread->md.cvar_pollsemfd = -1; - free_poll_sem(&thread->md); - thread->md.cvar_pollsem = NULL; - return PR_FAILURE; - } - } - return rv; -} - -PRStatus -_MD_InitThread(PRThread *thread, PRBool wakeup_parent) -{ - struct sigaction sigact; - PRStatus rv = PR_SUCCESS; - - if (thread->flags & _PR_GLOBAL_SCOPE) { - thread->md.id = getpid(); - setblockproccnt(thread->md.id, 0); - _MD_SET_SPROC_PID(getpid()); -#ifdef _PR_HAVE_SGI_PRDA_PROCMASK - /* - * enable user-level processing of sigprocmask(); this is an - * undocumented feature available in Irix 6.2, 6.3, 6.4 and 6.5 - */ - __sgi_prda_procmask(USER_LEVEL); -#endif - /* - * set up SIGUSR1 handler; this is used to save state - */ - sigact.sa_handler = save_context_and_block; - sigact.sa_flags = SA_RESTART; - /* - * Must mask clock interrupts - */ - sigact.sa_mask = timer_set; - sigaction(SIGUSR1, &sigact, 0); - - - /* - * PR_SETABORTSIG is a new command implemented in a patch to - * Irix 6.2, 6.3 and 6.4. This causes a signal to be sent to all - * sprocs in the process when one of them terminates abnormally - * - */ - if (prctl(PR_SETABORTSIG, SIGKILL) < 0) { - /* - * if (errno == EINVAL) - * - * PR_SETABORTSIG not supported under this OS. - * You may want to get a recent kernel rollup patch that - * supports this feature. - */ - } - /* - * SIGCLD handler for detecting abormally-terminating - * sprocs and for reaping sprocs - */ - sigact.sa_handler = sigchld_handler; - sigact.sa_flags = SA_RESTART; - sigact.sa_mask = ints_off; - sigaction(SIGCLD, &sigact, NULL); - } - return rv; -} - -/* - * PR_Cleanup should be executed on the primordial sproc; migrate the thread - * to the primordial cpu - */ - -void _PR_MD_PRE_CLEANUP(PRThread *me) -{ -PRIntn is; -_PRCPU *cpu = _pr_primordialCPU; - - PR_ASSERT(cpu); - - me->flags |= _PR_BOUND_THREAD; - - if (me->cpu->id != 0) { - _PR_INTSOFF(is); - _PR_RUNQ_LOCK(cpu); - me->cpu = cpu; - me->state = _PR_RUNNABLE; - _PR_ADD_RUNQ(me, cpu, me->priority); - _PR_RUNQ_UNLOCK(cpu); - _MD_Wakeup_CPUs(); - - _PR_MD_SWITCH_CONTEXT(me); - - _PR_FAST_INTSON(is); - PR_ASSERT(me->cpu->id == 0); - } -} - -/* - * process exiting - */ -PR_EXTERN(void ) _MD_exit(PRIntn status) -{ -PRThread *me = _PR_MD_CURRENT_THREAD(); - - /* - * the exit code of the process is the exit code of the primordial - * sproc - */ - if (!_PR_IS_NATIVE_THREAD(me) && (_PR_MD_CURRENT_CPU()->id == 0)) { - /* - * primordial sproc case: call _exit directly - * Cause SIGKILL to be sent to other sprocs - */ - prctl(PR_SETEXITSIG, SIGKILL); - _exit(status); - } else { - int rv; - char data; - sigset_t set; - - /* - * non-primordial sproc case: cause the primordial sproc, cpu 0, - * to wakeup and call _exit - */ - _pr_irix_process_exit = 1; - _pr_irix_process_exit_code = status; - rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1); - PR_ASSERT(rv == 1); - /* - * block all signals and wait for SIGKILL to terminate this sproc - */ - sigfillset(&set); - sigsuspend(&set); - /* - * this code doesn't (shouldn't) execute - */ - prctl(PR_SETEXITSIG, SIGKILL); - _exit(status); - } -} - -/* - * Override the exit() function in libc to cause the process to exit - * when the primodial/main nspr thread calls exit. Calls to exit by any - * other thread simply result in a call to the exit function in libc. - * The exit code of the process is the exit code of the primordial - * sproc. - */ - -void exit(int status) -{ -PRThread *me, *thr; -PRCList *qp; - - if (!_pr_initialized) { - if (!libc_exit) { - - if (!libc_handle) - libc_handle = dlopen("libc.so",RTLD_NOW); - if (libc_handle) - libc_exit = (void (*)(int)) dlsym(libc_handle, "exit"); - } - if (libc_exit) - (*libc_exit)(status); - else - _exit(status); - } - - me = _PR_MD_CURRENT_THREAD(); - - if (me == NULL) /* detached thread */ - (*libc_exit)(status); - - PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || - (_PR_MD_CURRENT_CPU())->id == me->cpu->id); - - if (me->flags & _PR_PRIMORDIAL) { - - me->flags |= _PR_BOUND_THREAD; - - PR_ASSERT((_PR_MD_CURRENT_CPU())->id == me->cpu->id); - if (me->cpu->id != 0) { - _PRCPU *cpu = _pr_primordialCPU; - PRIntn is; - - _PR_INTSOFF(is); - _PR_RUNQ_LOCK(cpu); - me->cpu = cpu; - me->state = _PR_RUNNABLE; - _PR_ADD_RUNQ(me, cpu, me->priority); - _PR_RUNQ_UNLOCK(cpu); - _MD_Wakeup_CPUs(); - - _PR_MD_SWITCH_CONTEXT(me); - - _PR_FAST_INTSON(is); - } - - PR_ASSERT((_PR_MD_CURRENT_CPU())->id == 0); - - if (prctl(PR_GETNSHARE) > 1) { -#define SPROC_EXIT_WAIT_TIME 5 - int sleep_cnt = SPROC_EXIT_WAIT_TIME; - - /* - * sprocs still running; caue cpus and recycled global threads - * to exit - */ - _pr_irix_exit_now = 1; - if (_pr_numCPU > 1) { - _MD_Wakeup_CPUs(); - } - _PR_DEADQ_LOCK; - if (_PR_NUM_DEADNATIVE != 0) { - PRThread *thread; - PRCList *ptr; - - ptr = _PR_DEADNATIVEQ.next; - while( ptr != &_PR_DEADNATIVEQ ) { - thread = _PR_THREAD_PTR(ptr); - _MD_CVAR_POST_SEM(thread); - ptr = ptr->next; - } - } - - while (sleep_cnt-- > 0) { - if (waitpid(0, NULL, WNOHANG) >= 0) - sleep(1); - else - break; - } - prctl(PR_SETEXITSIG, SIGKILL); - } - (*libc_exit)(status); - } else { - /* - * non-primordial thread; simply call exit in libc. - */ - (*libc_exit)(status); - } -} - - -void -_MD_InitRunningCPU(_PRCPU *cpu) -{ - extern int _pr_md_pipefd[2]; - - _MD_unix_init_running_cpu(cpu); - cpu->md.id = getpid(); - _MD_SET_SPROC_PID(getpid()); - if (_pr_md_pipefd[0] >= 0) { - _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0]; -#ifndef _PR_USE_POLL - FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu)); -#endif - } -} - -void -_MD_ExitThread(PRThread *thread) -{ - if (thread->flags & _PR_GLOBAL_SCOPE) { - _MD_ATOMIC_DECREMENT(&_pr_md_irix_sprocs); - _MD_CLEAN_THREAD(thread); - _MD_SET_CURRENT_THREAD(NULL); - } -} - -void -_MD_SuspendCPU(_PRCPU *cpu) -{ - PRInt32 rv; - - cpu->md.suspending_id = getpid(); - rv = kill(cpu->md.id, SIGUSR1); - PR_ASSERT(rv == 0); - /* - * now, block the current thread/cpu until woken up by the suspended - * thread from it's SIGUSR1 signal handler - */ - blockproc(getpid()); - -} - -void -_MD_ResumeCPU(_PRCPU *cpu) -{ - unblockproc(cpu->md.id); -} - -#if 0 -/* - * save the register context of a suspended sproc - */ -void get_context(PRThread *thr) -{ - int len, fd; - char pidstr[24]; - char path[24]; - - /* - * open the file corresponding to this process in procfs - */ - sprintf(path,"/proc/%s","00000"); - len = strlen(path); - sprintf(pidstr,"%d",thr->md.id); - len -= strlen(pidstr); - sprintf(path + len,"%s",pidstr); - fd = open(path,O_RDONLY); - if (fd >= 0) { - (void) ioctl(fd, PIOCGREG, thr->md.gregs); - close(fd); - } - return; -} -#endif /* 0 */ - -void -_MD_SuspendThread(PRThread *thread) -{ - PRInt32 rv; - - PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) && - _PR_IS_GCABLE_THREAD(thread)); - - thread->md.suspending_id = getpid(); - rv = kill(thread->md.id, SIGUSR1); - PR_ASSERT(rv == 0); - /* - * now, block the current thread/cpu until woken up by the suspended - * thread from it's SIGUSR1 signal handler - */ - blockproc(getpid()); -} - -void -_MD_ResumeThread(PRThread *thread) -{ - PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) && - _PR_IS_GCABLE_THREAD(thread)); - (void)unblockproc(thread->md.id); -} - -/* - * return the set of processors available for scheduling procs in the - * "mask" argument - */ -PRInt32 _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask) -{ - PRInt32 nprocs, rv; - struct pda_stat *pstat; -#define MAX_PROCESSORS 32 - - nprocs = sysmp(MP_NPROCS); - if (nprocs < 0) - return(-1); - pstat = (struct pda_stat*)PR_MALLOC(sizeof(struct pda_stat) * nprocs); - if (pstat == NULL) - return(-1); - rv = sysmp(MP_STAT, pstat); - if (rv < 0) { - PR_DELETE(pstat); - return(-1); - } - /* - * look at the first 32 cpus - */ - nprocs = (nprocs > MAX_PROCESSORS) ? MAX_PROCESSORS : nprocs; - *mask = 0; - while (nprocs) { - if ((pstat->p_flags & PDAF_ENABLED) && - !(pstat->p_flags & PDAF_ISOLATED)) { - *mask |= (1 << pstat->p_cpuid); - } - nprocs--; - pstat++; - } - return 0; -} - -static char *_thr_state[] = { - "UNBORN", - "RUNNABLE", - "RUNNING", - "LOCK_WAIT", - "COND_WAIT", - "JOIN_WAIT", - "IO_WAIT", - "SUSPENDED", - "DEAD" -}; - -void _PR_List_Threads() -{ - PRThread *thr; - void *handle; - struct _PRCPU *cpu; - PRCList *qp; - int len, fd; - char pidstr[24]; - char path[24]; - prpsinfo_t pinfo; - - - printf("\n%s %-s\n"," ","LOCAL Threads"); - printf("%s %-s\n"," ","----- -------"); - printf("%s %-14s %-10s %-12s %-3s %-10s %-10s %-12s\n\n"," ", - "Thread", "State", "Wait-Handle", - "Cpu","Stk-Base","Stk-Sz","SP"); - for (qp = _PR_ACTIVE_LOCAL_THREADQ().next; - qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) { - thr = _PR_ACTIVE_THREAD_PTR(qp); - printf("%s 0x%-12x %-10s "," ",thr,_thr_state[thr->state]); - if (thr->state == _PR_LOCK_WAIT) - handle = thr->wait.lock; - else if (thr->state == _PR_COND_WAIT) - handle = thr->wait.cvar; - else - handle = NULL; - if (handle) - printf("0x%-10x ",handle); - else - printf("%-12s "," "); - printf("%-3d ",thr->cpu->id); - printf("0x%-8x ",thr->stack->stackBottom); - printf("0x%-8x ",thr->stack->stackSize); - printf("0x%-10x\n",thr->md.jb[JB_SP]); - } - - printf("\n%s %-s\n"," ","GLOBAL Threads"); - printf("%s %-s\n"," ","------ -------"); - printf("%s %-14s %-6s %-12s %-12s %-12s %-12s\n\n"," ","Thread", - "Pid","State","Wait-Handle", - "Stk-Base","Stk-Sz"); - - for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next; - qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) { - thr = _PR_ACTIVE_THREAD_PTR(qp); - if (thr->cpu != NULL) - continue; /* it is a cpu thread */ - printf("%s 0x%-12x %-6d "," ",thr,thr->md.id); - /* - * check if the sproc is still running - * first call prctl(PR_GETSHMASK,pid) to check if - * the process is part of the share group (the pid - * could have been recycled by the OS) - */ - if (prctl(PR_GETSHMASK,thr->md.id) < 0) { - printf("%-12s\n","TERMINATED"); - continue; - } - /* - * Now, check if the sproc terminated and is in zombie - * state - */ - sprintf(path,"/proc/pinfo/%s","00000"); - len = strlen(path); - sprintf(pidstr,"%d",thr->md.id); - len -= strlen(pidstr); - sprintf(path + len,"%s",pidstr); - fd = open(path,O_RDONLY); - if (fd >= 0) { - if (ioctl(fd, PIOCPSINFO, &pinfo) < 0) - printf("%-12s ","TERMINATED"); - else if (pinfo.pr_zomb) - printf("%-12s ","TERMINATED"); - else - printf("%-12s ",_thr_state[thr->state]); - close(fd); - } else { - printf("%-12s ","TERMINATED"); - } - - if (thr->state == _PR_LOCK_WAIT) - handle = thr->wait.lock; - else if (thr->state == _PR_COND_WAIT) - handle = thr->wait.cvar; - else - handle = NULL; - if (handle) - printf("%-12x ",handle); - else - printf("%-12s "," "); - printf("0x%-10x ",thr->stack->stackBottom); - printf("0x%-10x\n",thr->stack->stackSize); - } - - printf("\n%s %-s\n"," ","CPUs"); - printf("%s %-s\n"," ","----"); - printf("%s %-14s %-6s %-12s \n\n"," ","Id","Pid","State"); - - - for (qp = _PR_CPUQ().next; qp != &_PR_CPUQ(); qp = qp->next) { - cpu = _PR_CPU_PTR(qp); - printf("%s %-14d %-6d "," ",cpu->id,cpu->md.id); - /* - * check if the sproc is still running - * first call prctl(PR_GETSHMASK,pid) to check if - * the process is part of the share group (the pid - * could have been recycled by the OS) - */ - if (prctl(PR_GETSHMASK,cpu->md.id) < 0) { - printf("%-12s\n","TERMINATED"); - continue; - } - /* - * Now, check if the sproc terminated and is in zombie - * state - */ - sprintf(path,"/proc/pinfo/%s","00000"); - len = strlen(path); - sprintf(pidstr,"%d",cpu->md.id); - len -= strlen(pidstr); - sprintf(path + len,"%s",pidstr); - fd = open(path,O_RDONLY); - if (fd >= 0) { - if (ioctl(fd, PIOCPSINFO, &pinfo) < 0) - printf("%-12s\n","TERMINATED"); - else if (pinfo.pr_zomb) - printf("%-12s\n","TERMINATED"); - else - printf("%-12s\n","RUNNING"); - close(fd); - } else { - printf("%-12s\n","TERMINATED"); - } - - } - fflush(stdout); -} -#endif /* defined(_PR_PTHREADS) */ - -PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) -{ -#if !defined(_PR_PTHREADS) - if (isCurrent) { - (void) setjmp(t->md.jb); - } - *np = sizeof(t->md.jb) / sizeof(PRWord); - return (PRWord *) (t->md.jb); -#else - *np = 0; - return NULL; -#endif -} - -void _MD_EarlyInit(void) -{ -#if !defined(_PR_PTHREADS) - char *eval; - int fd; - extern int __ateachexit(void (*func)(void)); - - sigemptyset(&ints_off); - sigaddset(&ints_off, SIGALRM); - sigaddset(&ints_off, SIGIO); - sigaddset(&ints_off, SIGCLD); - - if (eval = getenv("_NSPR_TERMINATE_ON_ERROR")) - _nspr_terminate_on_error = (0 == atoi(eval) == 0) ? PR_FALSE : PR_TRUE; - - fd = open("/dev/zero",O_RDWR , 0); - if (fd < 0) { - perror("open /dev/zero failed"); - exit(1); - } - /* - * Set up the sproc private data area. - * This region exists at the same address, _nspr_sproc_private, for - * every sproc, but each sproc gets a private copy of the region. - */ - _nspr_sproc_private = (char*)mmap(0, _pr_pageSize, PROT_READ | PROT_WRITE, - MAP_PRIVATE| MAP_LOCAL, fd, 0); - if (_nspr_sproc_private == (void*)-1) { - perror("mmap /dev/zero failed"); - exit(1); - } - _MD_SET_SPROC_PID(getpid()); - close(fd); - __ateachexit(irix_detach_sproc); -#endif - _MD_IrixIntervalInit(); -} /* _MD_EarlyInit */ - -void _MD_IrixInit(void) -{ -#if !defined(_PR_PTHREADS) - struct sigaction sigact; - PRThread *me = _PR_MD_CURRENT_THREAD(); - int rv; - -#ifdef _PR_HAVE_SGI_PRDA_PROCMASK - /* - * enable user-level processing of sigprocmask(); this is an undocumented - * feature available in Irix 6.2, 6.3, 6.4 and 6.5 - */ - __sgi_prda_procmask(USER_LEVEL); -#endif - - /* - * set up SIGUSR1 handler; this is used to save state - * during PR_SuspendAll - */ - sigact.sa_handler = save_context_and_block; - sigact.sa_flags = SA_RESTART; - sigact.sa_mask = ints_off; - sigaction(SIGUSR1, &sigact, 0); - - /* - * Change the name of the core file from core to core.pid, - * This is inherited by the sprocs created by this process - */ -#ifdef PR_COREPID - prctl(PR_COREPID, 0, 1); -#endif - /* - * Irix-specific terminate on error processing - */ - /* - * PR_SETABORTSIG is a new command implemented in a patch to - * Irix 6.2, 6.3 and 6.4. This causes a signal to be sent to all - * sprocs in the process when one of them terminates abnormally - * - */ - if (prctl(PR_SETABORTSIG, SIGKILL) < 0) { - /* - * if (errno == EINVAL) - * - * PR_SETABORTSIG not supported under this OS. - * You may want to get a recent kernel rollup patch that - * supports this feature. - * - */ - } - /* - * PR_SETEXITSIG - send the SIGCLD signal to the parent - * sproc when any sproc terminates - * - * This is used to cause the entire application to - * terminate when any sproc terminates abnormally by - * receipt of a SIGSEGV, SIGBUS or SIGABRT signal. - * If this is not done, the application may seem - * "hung" to the user because the other sprocs may be - * waiting for resources held by the - * abnormally-terminating sproc. - */ - prctl(PR_SETEXITSIG, 0); - - sigact.sa_handler = sigchld_handler; - sigact.sa_flags = SA_RESTART; - sigact.sa_mask = ints_off; - sigaction(SIGCLD, &sigact, NULL); - - /* - * setup stack fields for the primordial thread - */ - me->stack->stackSize = prctl(PR_GETSTACKSIZE); - me->stack->stackBottom = me->stack->stackTop - me->stack->stackSize; - - rv = pipe(_pr_irix_primoridal_cpu_fd); - PR_ASSERT(rv == 0); -#ifndef _PR_USE_POLL - _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0]; - FD_SET(_pr_irix_primoridal_cpu_fd[0], &_PR_FD_READ_SET(me->cpu)); -#endif - - libc_handle = dlopen("libc.so",RTLD_NOW); - PR_ASSERT(libc_handle != NULL); - libc_exit = (void (*)(int)) dlsym(libc_handle, "exit"); - PR_ASSERT(libc_exit != NULL); - /* dlclose(libc_handle); */ - -#endif /* _PR_PTHREADS */ - - _PR_UnixInit(); -} - -/**************************************************************************/ -/************** code and such for NSPR 2.0's interval times ***************/ -/**************************************************************************/ - -#define PR_PSEC_PER_SEC 1000000000000ULL /* 10^12 */ - -#ifndef SGI_CYCLECNTR_SIZE -#define SGI_CYCLECNTR_SIZE 165 /* Size user needs to use to read CC */ -#endif - -static PRIntn mmem_fd = -1; -static PRIntn clock_width = 0; -static void *iotimer_addr = NULL; -static PRUint32 pr_clock_mask = 0; -static PRUint32 pr_clock_shift = 0; -static PRIntervalTime pr_ticks = 0; -static PRUint32 pr_clock_granularity = 1; -static PRUint32 pr_previous = 0, pr_residual = 0; -static PRUint32 pr_ticks_per_second = 0; - -extern PRIntervalTime _PR_UNIX_GetInterval(void); -extern PRIntervalTime _PR_UNIX_TicksPerSecond(void); - -static void _MD_IrixIntervalInit(void) -{ - /* - * As much as I would like, the service available through this - * interface on R3000's (aka, IP12) just isn't going to make it. - * The register is only 24 bits wide, and rolls over at a verocious - * rate. - */ - PRUint32 one_tick = 0; - struct utsname utsinfo; - uname(&utsinfo); - if ((strncmp("IP12", utsinfo.machine, 4) != 0) - && ((mmem_fd = open("/dev/mmem", O_RDONLY)) != -1)) - { - int poffmask = getpagesize() - 1; - __psunsigned_t phys_addr, raddr, cycleval; - - phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval); - raddr = phys_addr & ~poffmask; - iotimer_addr = mmap( - 0, poffmask, PROT_READ, MAP_PRIVATE, mmem_fd, (__psint_t)raddr); - - clock_width = syssgi(SGI_CYCLECNTR_SIZE); - if (clock_width < 0) - { - /* - * We must be executing on a 6.0 or earlier system, since the - * SGI_CYCLECNTR_SIZE call is not supported. - * - * The only pre-6.1 platforms with 64-bit counters are - * IP19 and IP21 (Challenge, PowerChallenge, Onyx). - */ - if (!strncmp(utsinfo.machine, "IP19", 4) || - !strncmp(utsinfo.machine, "IP21", 4)) - clock_width = 64; - else - clock_width = 32; - } - - /* - * 'cycleval' is picoseconds / increment of the counter. - * I'm pushing for a tick to be 100 microseconds, 10^(-4). - * That leaves 10^(-8) left over, or 10^8 / cycleval. - * Did I do that right? - */ - - one_tick = 100000000UL / cycleval ; /* 100 microseconds */ - - while (0 != one_tick) - { - pr_clock_shift += 1; - one_tick = one_tick >> 1; - pr_clock_granularity = pr_clock_granularity << 1; - } - pr_clock_mask = pr_clock_granularity - 1; /* to make a mask out of it */ - pr_ticks_per_second = PR_PSEC_PER_SEC - / ((PRUint64)pr_clock_granularity * (PRUint64)cycleval); - - iotimer_addr = (void*) - ((__psunsigned_t)iotimer_addr + (phys_addr & poffmask)); - } - else - { - pr_ticks_per_second = _PR_UNIX_TicksPerSecond(); - } -} /* _MD_IrixIntervalInit */ - -PRIntervalTime _MD_IrixIntervalPerSec(void) -{ - return pr_ticks_per_second; -} - -PRIntervalTime _MD_IrixGetInterval(void) -{ - if (mmem_fd != -1) - { - if (64 == clock_width) - { - PRUint64 temp = *(PRUint64*)iotimer_addr; - pr_ticks = (PRIntervalTime)(temp >> pr_clock_shift); - } - else - { - PRIntervalTime ticks = pr_ticks; - PRUint32 now = *(PRUint32*)iotimer_addr, temp; - PRUint32 residual = pr_residual, previous = pr_previous; - - temp = now - previous + residual; - residual = temp & pr_clock_mask; - ticks += temp >> pr_clock_shift; - - pr_previous = now; - pr_residual = residual; - pr_ticks = ticks; - } - } - else - { - /* - * No fast access. Use the time of day clock. This isn't the - * right answer since this clock can get set back, tick at odd - * rates, and it's expensive to acqurie. - */ - pr_ticks = _PR_UNIX_GetInterval(); - } - return pr_ticks; -} /* _MD_IrixGetInterval */ - diff --git a/nsprpub/pr/src/md/unix/linux.c b/nsprpub/pr/src/md/unix/linux.c index 1b485a024..6bfc7a802 100644 --- a/nsprpub/pr/src/md/unix/linux.c +++ b/nsprpub/pr/src/md/unix/linux.c @@ -13,13 +13,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } @@ -43,13 +43,13 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - /* - * set the pointers to the stack-pointer and frame-pointer words in the - * context structure; this is for debugging use. - */ - thread->md.sp = _MD_GET_SP_PTR(thread); - thread->md.fp = _MD_GET_FP_PTR(thread); - return PR_SUCCESS; + /* + * set the pointers to the stack-pointer and frame-pointer words in the + * context structure; this is for debugging use. + */ + thread->md.sp = _MD_GET_SP_PTR(thread); + thread->md.fp = _MD_GET_FP_PTR(thread); + return PR_SUCCESS; } PRStatus @@ -64,7 +64,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -86,6 +86,6 @@ _MD_CREATE_THREAD( PRUint32 stackSize) { PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Linux."); - return PR_FAILURE; + return PR_FAILURE; } #endif /* ! _PR_PTHREADS */ diff --git a/nsprpub/pr/src/md/unix/nto.c b/nsprpub/pr/src/md/unix/nto.c index e41d665ca..8ab8b1eab 100644 --- a/nsprpub/pr/src/md/unix/nto.c +++ b/nsprpub/pr/src/md/unix/nto.c @@ -10,8 +10,8 @@ /* Fake this out */ int socketpair (int foo, int foo2, int foo3, int sv[2]) { - printf("error in socketpair\n"); - exit (-1); + printf("error in socketpair\n"); + exit (-1); } void _MD_EarlyInit(void) @@ -22,13 +22,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } diff --git a/nsprpub/pr/src/md/unix/os_Irix.s b/nsprpub/pr/src/md/unix/os_Irix.s deleted file mode 100644 index ab1cb0b30..000000000 --- a/nsprpub/pr/src/md/unix/os_Irix.s +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* - * Atomically add a new element to the top of the stack - * - * usage : PR_StackPush(listp, elementp); - * ----------------------- - */ - -#include "md/_irix.h" -#ifdef _PR_HAVE_ATOMIC_CAS - -#include <sys/asm.h> -#include <sys/regdef.h> - -LEAF(PR_StackPush) - -retry_push: -.set noreorder - lw v0,0(a0) - li t1,1 - beq v0,t1,retry_push - move t0,a1 - - ll v0,0(a0) - beq v0,t1,retry_push - nop - sc t1,0(a0) - beq t1,0,retry_push - nop - sw v0,0(a1) - sync - sw t0,0(a0) - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - jr ra - nop - -END(PR_StackPush) - -/* - * - * Atomically remove the element at the top of the stack - * - * usage : elemep = PR_StackPop(listp); - * - */ - -LEAF(PR_StackPop) -retry_pop: -.set noreorder - - - lw v0,0(a0) - li t1,1 - beq v0,0,done - nop - beq v0,t1,retry_pop - nop - - ll v0,0(a0) - beq v0,0,done - nop - beq v0,t1,retry_pop - nop - sc t1,0(a0) - beq t1,0,retry_pop - nop - lw t0,0(v0) - sw t0,0(a0) -done: - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - jr ra - nop - -END(PR_StackPop) - -#endif /* _PR_HAVE_ATOMIC_CAS */ diff --git a/nsprpub/pr/src/md/unix/osf1.c b/nsprpub/pr/src/md/unix/osf1.c deleted file mode 100644 index a9a1c67d0..000000000 --- a/nsprpub/pr/src/md/unix/osf1.c +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "primpl.h" - -void _MD_EarlyInit(void) -{ -} - -PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) -{ -#ifndef _PR_PTHREADS - if (isCurrent) { - (void) setjmp(CONTEXT(t)); - } - *np = sizeof(CONTEXT(t)) / sizeof(PRWord); - return (PRWord *) CONTEXT(t); -#else - *np = 0; - return NULL; -#endif -} - -#ifndef _PR_PTHREADS -void -_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) -{ - return; -} - -PRStatus -_MD_InitializeThread(PRThread *thread) -{ - return PR_SUCCESS; -} - -PRStatus -_MD_WAIT(PRThread *thread, PRIntervalTime ticks) -{ - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); - _PR_MD_SWITCH_CONTEXT(thread); - return PR_SUCCESS; -} - -PRStatus -_MD_WAKEUP_WAITER(PRThread *thread) -{ - if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); - } - return PR_SUCCESS; -} - -/* These functions should not be called for OSF1 */ -void -_MD_YIELD(void) -{ - PR_NOT_REACHED("_MD_YIELD should not be called for OSF1."); -} - -PRStatus -_MD_CREATE_THREAD( - PRThread *thread, - void (*start) (void *), - PRThreadPriority priority, - PRThreadScope scope, - PRThreadState state, - PRUint32 stackSize) -{ - PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for OSF1."); - return PR_FAILURE; -} -#endif /* ! _PR_PTHREADS */ diff --git a/nsprpub/pr/src/md/unix/pthreads_user.c b/nsprpub/pr/src/md/unix/pthreads_user.c index bb64b9f44..525c1576f 100644 --- a/nsprpub/pr/src/md/unix/pthreads_user.c +++ b/nsprpub/pr/src/md/unix/pthreads_user.c @@ -11,7 +11,7 @@ sigset_t ints_off; -pthread_mutex_t _pr_heapLock; +pthread_mutex_t _pr_heapLock; pthread_key_t current_thread_key; pthread_key_t current_cpu_key; pthread_key_t last_thread_key; @@ -23,55 +23,57 @@ PRInt32 _pr_md_pthreads = 1; void _MD_EarlyInit(void) { -extern PRInt32 _nspr_noclock; - - if (pthread_key_create(¤t_thread_key, NULL) != 0) { - perror("pthread_key_create failed"); - exit(1); - } - if (pthread_key_create(¤t_cpu_key, NULL) != 0) { - perror("pthread_key_create failed"); - exit(1); - } - if (pthread_key_create(&last_thread_key, NULL) != 0) { - perror("pthread_key_create failed"); - exit(1); - } - if (pthread_key_create(&intsoff_key, NULL) != 0) { - perror("pthread_key_create failed"); - exit(1); - } - - sigemptyset(&ints_off); - sigaddset(&ints_off, SIGALRM); - sigaddset(&ints_off, SIGIO); - sigaddset(&ints_off, SIGCLD); - - /* - * disable clock interrupts - */ - _nspr_noclock = 1; + extern PRInt32 _nspr_noclock; + + if (pthread_key_create(¤t_thread_key, NULL) != 0) { + perror("pthread_key_create failed"); + exit(1); + } + if (pthread_key_create(¤t_cpu_key, NULL) != 0) { + perror("pthread_key_create failed"); + exit(1); + } + if (pthread_key_create(&last_thread_key, NULL) != 0) { + perror("pthread_key_create failed"); + exit(1); + } + if (pthread_key_create(&intsoff_key, NULL) != 0) { + perror("pthread_key_create failed"); + exit(1); + } + + sigemptyset(&ints_off); + sigaddset(&ints_off, SIGALRM); + sigaddset(&ints_off, SIGIO); + sigaddset(&ints_off, SIGCLD); + + /* + * disable clock interrupts + */ + _nspr_noclock = 1; } void _MD_InitLocks() { - if (pthread_mutex_init(&_pr_heapLock, NULL) != 0) { - perror("pthread_mutex_init failed"); - exit(1); - } + if (pthread_mutex_init(&_pr_heapLock, NULL) != 0) { + perror("pthread_mutex_init failed"); + exit(1); + } } PR_IMPLEMENT(void) _MD_FREE_LOCK(struct _MDLock *lockp) { - PRIntn _is; - PRThread *me = _PR_MD_CURRENT_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(_is); - pthread_mutex_destroy(&lockp->mutex); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(_is); + PRIntn _is; + PRThread *me = _PR_MD_CURRENT_THREAD(); + + if (me && !_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(_is); + } + pthread_mutex_destroy(&lockp->mutex); + if (me && !_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(_is); + } } @@ -80,21 +82,23 @@ PR_IMPLEMENT(PRStatus) _MD_NEW_LOCK(struct _MDLock *lockp) { PRStatus rv; PRIntn is; - PRThread *me = _PR_MD_CURRENT_THREAD(); - - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); - rv = pthread_mutex_init(&lockp->mutex, NULL); - if (me && !_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - return (rv == 0) ? PR_SUCCESS : PR_FAILURE; + PRThread *me = _PR_MD_CURRENT_THREAD(); + + if (me && !_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(is); + } + rv = pthread_mutex_init(&lockp->mutex, NULL); + if (me && !_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } + return (rv == 0) ? PR_SUCCESS : PR_FAILURE; } PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); @@ -103,9 +107,9 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) PR_IMPLEMENT(void) _MD_SetPriority(_MDThread *thread, PRThreadPriority newPri) { - /* - * XXX - to be implemented - */ + /* + * XXX - to be implemented + */ return; } @@ -116,17 +120,17 @@ PR_IMPLEMENT(PRStatus) _MD_InitThread(struct PRThread *thread) if (thread->flags & _PR_GLOBAL_SCOPE) { thread->md.pthread = pthread_self(); #if 0 - /* - * set up SIGUSR1 handler; this is used to save state - * during PR_SuspendAll - */ - sigact.sa_handler = save_context_and_block; - sigact.sa_flags = SA_RESTART; - /* - * Must mask clock interrupts - */ - sigact.sa_mask = timer_set; - sigaction(SIGUSR1, &sigact, 0); + /* + * set up SIGUSR1 handler; this is used to save state + * during PR_SuspendAll + */ + sigact.sa_handler = save_context_and_block; + sigact.sa_flags = SA_RESTART; + /* + * Must mask clock interrupts + */ + sigact.sa_mask = timer_set; + sigaction(SIGUSR1, &sigact, 0); #endif } @@ -144,8 +148,8 @@ PR_IMPLEMENT(void) _MD_ExitThread(struct PRThread *thread) PR_IMPLEMENT(void) _MD_CleanThread(struct PRThread *thread) { if (thread->flags & _PR_GLOBAL_SCOPE) { - pthread_mutex_destroy(&thread->md.pthread_mutex); - pthread_cond_destroy(&thread->md.pthread_cond); + pthread_mutex_destroy(&thread->md.pthread_mutex); + pthread_cond_destroy(&thread->md.pthread_cond); } } @@ -154,16 +158,16 @@ PR_IMPLEMENT(void) _MD_SuspendThread(struct PRThread *thread) PRInt32 rv; PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) && - _PR_IS_GCABLE_THREAD(thread)); + _PR_IS_GCABLE_THREAD(thread)); #if 0 - thread->md.suspending_id = getpid(); - rv = kill(thread->md.id, SIGUSR1); - PR_ASSERT(rv == 0); - /* - * now, block the current thread/cpu until woken up by the suspended - * thread from it's SIGUSR1 signal handler - */ - blockproc(getpid()); + thread->md.suspending_id = getpid(); + rv = kill(thread->md.id, SIGUSR1); + PR_ASSERT(rv == 0); + /* + * now, block the current thread/cpu until woken up by the suspended + * thread from it's SIGUSR1 signal handler + */ + blockproc(getpid()); #endif } @@ -172,7 +176,7 @@ PR_IMPLEMENT(void) _MD_ResumeThread(struct PRThread *thread) PRInt32 rv; PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) && - _PR_IS_GCABLE_THREAD(thread)); + _PR_IS_GCABLE_THREAD(thread)); #if 0 rv = unblockproc(thread->md.id); #endif @@ -183,21 +187,21 @@ PR_IMPLEMENT(void) _MD_SuspendCPU(struct _PRCPU *thread) PRInt32 rv; #if 0 - cpu->md.suspending_id = getpid(); - rv = kill(cpu->md.id, SIGUSR1); - PR_ASSERT(rv == 0); - /* - * now, block the current thread/cpu until woken up by the suspended - * thread from it's SIGUSR1 signal handler - */ - blockproc(getpid()); + cpu->md.suspending_id = getpid(); + rv = kill(cpu->md.id, SIGUSR1); + PR_ASSERT(rv == 0); + /* + * now, block the current thread/cpu until woken up by the suspended + * thread from it's SIGUSR1 signal handler + */ + blockproc(getpid()); #endif } PR_IMPLEMENT(void) _MD_ResumeCPU(struct _PRCPU *thread) { #if 0 - unblockproc(cpu->md.id); + unblockproc(cpu->md.id); #endif } @@ -208,54 +212,55 @@ PR_IMPLEMENT(void) _MD_ResumeCPU(struct _PRCPU *thread) PR_IMPLEMENT(PRStatus) _pt_wait(PRThread *thread, PRIntervalTime timeout) { -int rv; -struct timeval now; -struct timespec tmo; -PRUint32 ticks = PR_TicksPerSecond(); - - - if (timeout != PR_INTERVAL_NO_TIMEOUT) { - tmo.tv_sec = timeout / ticks; - tmo.tv_nsec = timeout - (tmo.tv_sec * ticks); - tmo.tv_nsec = PR_IntervalToMicroseconds(PT_NANOPERMICRO * - tmo.tv_nsec); - - /* pthreads wants this in absolute time, off we go ... */ - (void)GETTIMEOFDAY(&now); - /* that one's usecs, this one's nsecs - grrrr! */ - tmo.tv_sec += now.tv_sec; - tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec); - tmo.tv_sec += tmo.tv_nsec / PT_BILLION; - tmo.tv_nsec %= PT_BILLION; - } - - pthread_mutex_lock(&thread->md.pthread_mutex); - thread->md.wait--; - if (thread->md.wait < 0) { - if (timeout != PR_INTERVAL_NO_TIMEOUT) { - rv = pthread_cond_timedwait(&thread->md.pthread_cond, - &thread->md.pthread_mutex, &tmo); + int rv; + struct timeval now; + struct timespec tmo; + PRUint32 ticks = PR_TicksPerSecond(); + + + if (timeout != PR_INTERVAL_NO_TIMEOUT) { + tmo.tv_sec = timeout / ticks; + tmo.tv_nsec = timeout - (tmo.tv_sec * ticks); + tmo.tv_nsec = PR_IntervalToMicroseconds(PT_NANOPERMICRO * + tmo.tv_nsec); + + /* pthreads wants this in absolute time, off we go ... */ + (void)GETTIMEOFDAY(&now); + /* that one's usecs, this one's nsecs - grrrr! */ + tmo.tv_sec += now.tv_sec; + tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec); + tmo.tv_sec += tmo.tv_nsec / PT_BILLION; + tmo.tv_nsec %= PT_BILLION; + } + + pthread_mutex_lock(&thread->md.pthread_mutex); + thread->md.wait--; + if (thread->md.wait < 0) { + if (timeout != PR_INTERVAL_NO_TIMEOUT) { + rv = pthread_cond_timedwait(&thread->md.pthread_cond, + &thread->md.pthread_mutex, &tmo); + } + else + rv = pthread_cond_wait(&thread->md.pthread_cond, + &thread->md.pthread_mutex); + if (rv != 0) { + thread->md.wait++; } - else - rv = pthread_cond_wait(&thread->md.pthread_cond, - &thread->md.pthread_mutex); - if (rv != 0) { - thread->md.wait++; - } - } else - rv = 0; - pthread_mutex_unlock(&thread->md.pthread_mutex); - - return (rv == 0) ? PR_SUCCESS : PR_FAILURE; + } else { + rv = 0; + } + pthread_mutex_unlock(&thread->md.pthread_mutex); + + return (rv == 0) ? PR_SUCCESS : PR_FAILURE; } PR_IMPLEMENT(PRStatus) _MD_wait(PRThread *thread, PRIntervalTime ticks) { if ( thread->flags & _PR_GLOBAL_SCOPE ) { - _MD_CHECK_FOR_EXIT(); + _MD_CHECK_FOR_EXIT(); if (_pt_wait(thread, ticks) == PR_FAILURE) { - _MD_CHECK_FOR_EXIT(); + _MD_CHECK_FOR_EXIT(); /* * wait timed out */ @@ -269,12 +274,12 @@ _MD_wait(PRThread *thread, PRIntervalTime ticks) thread->state = _PR_RUNNING; _PR_THREAD_UNLOCK(thread); } else { - _pt_wait(thread, PR_INTERVAL_NO_TIMEOUT); + _pt_wait(thread, PR_INTERVAL_NO_TIMEOUT); _PR_THREAD_UNLOCK(thread); } } } else { - _PR_MD_SWITCH_CONTEXT(thread); + _PR_MD_SWITCH_CONTEXT(thread); } return PR_SUCCESS; } @@ -286,38 +291,43 @@ _MD_WakeupWaiter(PRThread *thread) PRInt32 pid, rv; PRIntn is; - PR_ASSERT(_pr_md_idle_cpus >= 0); + PR_ASSERT(_pr_md_idle_cpus >= 0); if (thread == NULL) { - if (_pr_md_idle_cpus) - _MD_Wakeup_CPUs(); + if (_pr_md_idle_cpus) { + _MD_Wakeup_CPUs(); + } } else if (!_PR_IS_NATIVE_THREAD(thread)) { - /* - * If the thread is on my cpu's runq there is no need to - * wakeup any cpus - */ - if (!_PR_IS_NATIVE_THREAD(me)) { - if (me->cpu != thread->cpu) { - if (_pr_md_idle_cpus) - _MD_Wakeup_CPUs(); - } - } else { - if (_pr_md_idle_cpus) - _MD_Wakeup_CPUs(); - } + /* + * If the thread is on my cpu's runq there is no need to + * wakeup any cpus + */ + if (!_PR_IS_NATIVE_THREAD(me)) { + if (me->cpu != thread->cpu) { + if (_pr_md_idle_cpus) { + _MD_Wakeup_CPUs(); + } + } + } else { + if (_pr_md_idle_cpus) { + _MD_Wakeup_CPUs(); + } + } } else { - PR_ASSERT(_PR_IS_NATIVE_THREAD(thread)); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); - - pthread_mutex_lock(&thread->md.pthread_mutex); - thread->md.wait++; - rv = pthread_cond_signal(&thread->md.pthread_cond); - PR_ASSERT(rv == 0); - pthread_mutex_unlock(&thread->md.pthread_mutex); - - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); - } + PR_ASSERT(_PR_IS_NATIVE_THREAD(thread)); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(is); + } + + pthread_mutex_lock(&thread->md.pthread_mutex); + thread->md.wait++; + rv = pthread_cond_signal(&thread->md.pthread_cond); + PR_ASSERT(rv == 0); + pthread_mutex_unlock(&thread->md.pthread_mutex); + + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } + } return PR_SUCCESS; } @@ -339,51 +349,57 @@ _MD_CreateThread( { PRIntn is; int rv; - PRThread *me = _PR_MD_CURRENT_THREAD(); - pthread_attr_t attr; + PRThread *me = _PR_MD_CURRENT_THREAD(); + pthread_attr_t attr; - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(is); + } - if (pthread_mutex_init(&thread->md.pthread_mutex, NULL) != 0) { - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); + if (pthread_mutex_init(&thread->md.pthread_mutex, NULL) != 0) { + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } return PR_FAILURE; - } + } - if (pthread_cond_init(&thread->md.pthread_cond, NULL) != 0) { - pthread_mutex_destroy(&thread->md.pthread_mutex); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); + if (pthread_cond_init(&thread->md.pthread_cond, NULL) != 0) { + pthread_mutex_destroy(&thread->md.pthread_mutex); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } return PR_FAILURE; - } + } thread->flags |= _PR_GLOBAL_SCOPE; - pthread_attr_init(&attr); /* initialize attr with default attributes */ - if (pthread_attr_setstacksize(&attr, (size_t) stackSize) != 0) { - pthread_mutex_destroy(&thread->md.pthread_mutex); - pthread_cond_destroy(&thread->md.pthread_cond); - pthread_attr_destroy(&attr); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); + pthread_attr_init(&attr); /* initialize attr with default attributes */ + if (pthread_attr_setstacksize(&attr, (size_t) stackSize) != 0) { + pthread_mutex_destroy(&thread->md.pthread_mutex); + pthread_cond_destroy(&thread->md.pthread_cond); + pthread_attr_destroy(&attr); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } return PR_FAILURE; - } + } - thread->md.wait = 0; + thread->md.wait = 0; rv = pthread_create(&thread->md.pthread, &attr, start, (void *)thread); if (0 == rv) { _MD_ATOMIC_INCREMENT(&_pr_md_pthreads_created); _MD_ATOMIC_INCREMENT(&_pr_md_pthreads); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } return PR_SUCCESS; } else { - pthread_mutex_destroy(&thread->md.pthread_mutex); - pthread_cond_destroy(&thread->md.pthread_cond); - pthread_attr_destroy(&attr); + pthread_mutex_destroy(&thread->md.pthread_mutex); + pthread_cond_destroy(&thread->md.pthread_cond); + pthread_attr_destroy(&attr); _MD_ATOMIC_INCREMENT(&_pr_md_pthreads_failed); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_FAST_INTSON(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, rv); return PR_FAILURE; } @@ -396,12 +412,12 @@ _MD_InitRunningCPU(struct _PRCPU *cpu) _MD_unix_init_running_cpu(cpu); cpu->md.pthread = pthread_self(); - if (_pr_md_pipefd[0] >= 0) { - _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0]; + if (_pr_md_pipefd[0] >= 0) { + _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0]; #ifndef _PR_USE_POLL - FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu)); + FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu)); #endif - } + } } @@ -411,7 +427,7 @@ _MD_CleanupBeforeExit(void) #if 0 extern PRInt32 _pr_cpus_exit; - _pr_irix_exit_now = 1; + _pr_irix_exit_now = 1; if (_pr_numCPU > 1) { /* * Set a global flag, and wakeup all cpus which will notice the flag @@ -427,22 +443,22 @@ _MD_CleanupBeforeExit(void) /* * cause global threads on the recycle list to exit */ - _PR_DEADQ_LOCK; - if (_PR_NUM_DEADNATIVE != 0) { - PRThread *thread; - PRCList *ptr; + _PR_DEADQ_LOCK; + if (_PR_NUM_DEADNATIVE != 0) { + PRThread *thread; + PRCList *ptr; ptr = _PR_DEADNATIVEQ.next; while( ptr != &_PR_DEADNATIVEQ ) { - thread = _PR_THREAD_PTR(ptr); - _MD_CVAR_POST_SEM(thread); - ptr = ptr->next; - } - } - _PR_DEADQ_UNLOCK; - while(_PR_NUM_DEADNATIVE > 1) { - _PR_WAIT_SEM(_pr_irix_exit_sem); - _PR_DEC_DEADNATIVE; - } + thread = _PR_THREAD_PTR(ptr); + _MD_CVAR_POST_SEM(thread); + ptr = ptr->next; + } + } + _PR_DEADQ_UNLOCK; + while(_PR_NUM_DEADNATIVE > 1) { + _PR_WAIT_SEM(_pr_irix_exit_sem); + _PR_DEC_DEADNATIVE; + } #endif } diff --git a/nsprpub/pr/src/md/unix/qnx.c b/nsprpub/pr/src/md/unix/qnx.c index 259e29cdc..aef97a25a 100644 --- a/nsprpub/pr/src/md/unix/qnx.c +++ b/nsprpub/pr/src/md/unix/qnx.c @@ -14,7 +14,7 @@ void _MD_EarlyInit(void) PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); @@ -29,7 +29,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -44,7 +44,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } diff --git a/nsprpub/pr/src/md/unix/riscos.c b/nsprpub/pr/src/md/unix/riscos.c index 318903acb..a04118875 100644 --- a/nsprpub/pr/src/md/unix/riscos.c +++ b/nsprpub/pr/src/md/unix/riscos.c @@ -13,13 +13,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { #ifndef _PR_PTHREADS if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); #else - *np = 0; - return NULL; + *np = 0; + return NULL; #endif } @@ -40,13 +40,13 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - /* - * set the pointers to the stack-pointer and frame-pointer words in the - * context structure; this is for debugging use. - */ - thread->md.sp = _MD_GET_SP_PTR(thread); - thread->md.fp = _MD_GET_FP_PTR(thread); - return PR_SUCCESS; + /* + * set the pointers to the stack-pointer and frame-pointer words in the + * context structure; this is for debugging use. + */ + thread->md.sp = _MD_GET_SP_PTR(thread); + thread->md.fp = _MD_GET_FP_PTR(thread); + return PR_SUCCESS; } PRStatus @@ -61,7 +61,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -83,6 +83,6 @@ _MD_CREATE_THREAD( PRUint32 stackSize) { PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for RISC OS."); - return PR_FAILURE; + return PR_FAILURE; } #endif /* ! _PR_PTHREADS */ diff --git a/nsprpub/pr/src/md/unix/scoos.c b/nsprpub/pr/src/md/unix/scoos.c index b727a53ae..43b256d82 100644 --- a/nsprpub/pr/src/md/unix/scoos.c +++ b/nsprpub/pr/src/md/unix/scoos.c @@ -17,7 +17,7 @@ void _MD_EarlyInit(void) PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); @@ -26,7 +26,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) #ifdef ALARMS_BREAK_TCP /* I don't think they do */ PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen, - PRIntervalTime timeout) + PRIntervalTime timeout) { PRInt32 rv; @@ -36,7 +36,7 @@ PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen, } PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen, - PRIntervalTime timeout) + PRIntervalTime timeout) { PRInt32 rv; @@ -61,8 +61,9 @@ void _MD_INIT_ATOMIC(void) { /* Sigh. Sure wish SYSV semaphores weren't such a pain to use */ - if ((_uw_semf = tmpfile()) == NULL) + if ((_uw_semf = tmpfile()) == NULL) { PR_ASSERT(0); + } return; } @@ -109,7 +110,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -124,7 +125,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } diff --git a/nsprpub/pr/src/md/unix/solaris.c b/nsprpub/pr/src/md/unix/solaris.c index 4fe2043b1..383f49d04 100644 --- a/nsprpub/pr/src/md/unix/solaris.c +++ b/nsprpub/pr/src/md/unix/solaris.c @@ -25,8 +25,8 @@ PRIntervalTime _MD_Solaris_TicksPerSecond(void) PRIntervalTime _MD_Solaris_GetInterval(void) { union { - hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */ - PRInt64 pr64; + hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */ + PRInt64 pr64; } time; PRInt64 resolution; PRIntervalTime ticks; @@ -49,8 +49,8 @@ void _MD_EarlyInit(void) PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) { - *np = 0; - return NULL; + *np = 0; + return NULL; } #endif /* _PR_PTHREADS */ @@ -74,7 +74,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -88,7 +88,7 @@ _MD_WAIT(PRThread *thread, PRIntervalTime ticks) PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { - PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE))); + PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE))); return PR_SUCCESS; } @@ -109,14 +109,14 @@ _MD_CREATE_THREAD( PRUint32 stackSize) { PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Solaris"); - return(PR_FAILURE); + return(PR_FAILURE); } #ifdef USE_SETJMP PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); @@ -125,7 +125,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) { if (isCurrent) { - (void) getcontext(CONTEXT(t)); + (void) getcontext(CONTEXT(t)); } *np = NGREG; return (PRWord*) &t->md.context.uc_mcontext.gregs[0]; @@ -136,7 +136,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) #ifndef _PR_PTHREADS #if defined(i386) && defined(SOLARIS2_4) -/* +/* * Because clock_gettime() on Solaris/x86 2.4 always generates a * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(), * which is implemented using gettimeofday(). @@ -148,8 +148,8 @@ _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp) struct timeval tv; if (clock_id != CLOCK_REALTIME) { - errno = EINVAL; - return -1; + errno = EINVAL; + return -1; } gettimeofday(&tv, NULL); diff --git a/nsprpub/pr/src/md/unix/symbian.c b/nsprpub/pr/src/md/unix/symbian.c deleted file mode 100644 index c797d8687..000000000 --- a/nsprpub/pr/src/md/unix/symbian.c +++ /dev/null @@ -1,16 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "primpl.h" - -void _MD_EarlyInit(void) -{ -} - -PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) -{ - *np = 0; - return NULL; -} diff --git a/nsprpub/pr/src/md/unix/unix.c b/nsprpub/pr/src/md/unix/unix.c index 7c90b5075..a8862a4ce 100644 --- a/nsprpub/pr/src/md/unix/unix.c +++ b/nsprpub/pr/src/md/unix/unix.c @@ -41,7 +41,7 @@ #if defined(HAVE_SOCKLEN_T) \ || (defined(__GLIBC__) && __GLIBC__ >= 2) #define _PRSockLen_t socklen_t -#elif defined(IRIX) || defined(HPUX) || defined(OSF1) || defined(SOLARIS) \ +#elif defined(HPUX) || defined(SOLARIS) \ || defined(AIX4_1) || defined(LINUX) \ || defined(BSDI) || defined(SCO) \ || defined(DARWIN) \ @@ -49,7 +49,7 @@ #define _PRSockLen_t int #elif (defined(AIX) && !defined(AIX4_1)) || defined(FREEBSD) \ || defined(NETBSD) || defined(OPENBSD) || defined(UNIXWARE) \ - || defined(DGUX) || defined(NTO) || defined(RISCOS) + || defined(NTO) || defined(RISCOS) #define _PRSockLen_t size_t #else #error "Cannot determine architecture" @@ -59,7 +59,7 @@ ** Global lock variable used to bracket calls into rusty libraries that ** aren't thread safe (like libc, libX, etc). */ -static PRLock *_pr_rename_lock = NULL; +static PRLock *_pr_unix_rename_lock = NULL; static PRMonitor *_pr_Xfe_mon = NULL; static PRInt64 minus_one; @@ -84,10 +84,6 @@ static sigset_t empty_set; */ int _nspr_noclock = 1; -#ifdef IRIX -extern PRInt32 _nspr_terminate_on_error; -#endif - /* * There is an assertion in this code that NSPR's definition of PRIOVec * is bit compatible with UNIX' definition of a struct iovec. This is @@ -98,13 +94,15 @@ extern PRInt32 _nspr_terminate_on_error; int _pr_md_pipefd[2] = { -1, -1 }; static char _pr_md_pipebuf[PIPE_BUF]; static PRInt32 local_io_wait(PRInt32 osfd, PRInt32 wait_flag, - PRIntervalTime timeout); + PRIntervalTime timeout); _PRInterruptTable _pr_interruptTable[] = { - { - "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt, }, - { - 0 } + { + "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt, + }, + { + 0 + } }; void _MD_unix_init_running_cpu(_PRCPU *cpu) @@ -116,7 +114,7 @@ void _MD_unix_init_running_cpu(_PRCPU *cpu) PRStatus _MD_open_dir(_MDDir *d, const char *name) { -int err; + int err; d->d = opendir(name); if (!d->d) { @@ -129,13 +127,13 @@ int err; PRInt32 _MD_close_dir(_MDDir *d) { -int rv = 0, err; + int rv = 0, err; if (d->d) { rv = closedir(d->d); if (rv == -1) { - err = _MD_ERRNO(); - _PR_MD_MAP_CLOSEDIR_ERROR(err); + err = _MD_ERRNO(); + _PR_MD_MAP_CLOSEDIR_ERROR(err); } } return rv; @@ -143,8 +141,8 @@ int rv = 0, err; char * _MD_read_dir(_MDDir *d, PRIntn flags) { -struct dirent *de; -int err; + struct dirent *de; + int err; for (;;) { /* @@ -157,16 +155,19 @@ int err; err = _MD_ERRNO(); _PR_MD_MAP_READDIR_ERROR(err); return 0; - } + } if ((flags & PR_SKIP_DOT) && - (de->d_name[0] == '.') && (de->d_name[1] == 0)) + (de->d_name[0] == '.') && (de->d_name[1] == 0)) { continue; + } if ((flags & PR_SKIP_DOT_DOT) && (de->d_name[0] == '.') && (de->d_name[1] == '.') && - (de->d_name[2] == 0)) + (de->d_name[2] == 0)) { continue; - if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.')) + } + if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.')) { continue; + } break; } return de->d_name; @@ -174,7 +175,7 @@ int err; PRInt32 _MD_delete(const char *name) { -PRInt32 rv, err; + PRInt32 rv, err; #ifdef UNIXWARE sigset_t set, oset; #endif @@ -188,8 +189,8 @@ PRInt32 rv, err; sigprocmask(SIG_SETMASK, &oset, NULL); #endif if (rv == -1) { - err = _MD_ERRNO(); - _PR_MD_MAP_UNLINK_ERROR(err); + err = _MD_ERRNO(); + _PR_MD_MAP_UNLINK_ERROR(err); } return(rv); } @@ -204,10 +205,12 @@ PRInt32 _MD_rename(const char *from, const char *to) ** of an existing file. Holding a lock across these two function ** and the open function is known to be a bad idea, but .... */ - if (NULL != _pr_rename_lock) - PR_Lock(_pr_rename_lock); - if (0 == access(to, F_OK)) + if (NULL != _pr_unix_rename_lock) { + PR_Lock(_pr_unix_rename_lock); + } + if (0 == access(to, F_OK)) { PR_SetError(PR_FILE_EXISTS_ERROR, 0); + } else { rv = rename(from, to); @@ -216,15 +219,16 @@ PRInt32 _MD_rename(const char *from, const char *to) _PR_MD_MAP_RENAME_ERROR(err); } } - if (NULL != _pr_rename_lock) - PR_Unlock(_pr_rename_lock); + if (NULL != _pr_unix_rename_lock) { + PR_Unlock(_pr_unix_rename_lock); + } return rv; } PRInt32 _MD_access(const char *name, PRAccessHow how) { -PRInt32 rv, err; -int amode; + PRInt32 rv, err; + int amode; switch (how) { case PR_ACCESS_WRITE_OK: @@ -254,46 +258,48 @@ done: PRInt32 _MD_mkdir(const char *name, PRIntn mode) { -int rv, err; + int rv, err; /* ** This lock is used to enforce rename semantics as described ** in PR_Rename. Look there for more fun details. */ - if (NULL !=_pr_rename_lock) - PR_Lock(_pr_rename_lock); + if (NULL !=_pr_unix_rename_lock) { + PR_Lock(_pr_unix_rename_lock); + } rv = mkdir(name, mode); if (rv < 0) { err = _MD_ERRNO(); _PR_MD_MAP_MKDIR_ERROR(err); } - if (NULL !=_pr_rename_lock) - PR_Unlock(_pr_rename_lock); + if (NULL !=_pr_unix_rename_lock) { + PR_Unlock(_pr_unix_rename_lock); + } return rv; } PRInt32 _MD_rmdir(const char *name) { -int rv, err; + int rv, err; rv = rmdir(name); if (rv == -1) { - err = _MD_ERRNO(); - _PR_MD_MAP_RMDIR_ERROR(err); + err = _MD_ERRNO(); + _PR_MD_MAP_RMDIR_ERROR(err); } return rv; } PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount) { -PRThread *me = _PR_MD_CURRENT_THREAD(); -PRInt32 rv, err; + PRThread *me = _PR_MD_CURRENT_THREAD(); + PRInt32 rv, err; #ifndef _PR_USE_POLL -fd_set rd; + fd_set rd; #else -struct pollfd pfd; + struct pollfd pfd; #endif /* _PR_USE_POLL */ -PRInt32 osfd = fd->secret->md.osfd; + PRInt32 osfd = fd->secret->md.osfd; #ifndef _PR_USE_POLL FD_ZERO(&rd); @@ -310,17 +316,18 @@ PRInt32 osfd = fd->secret->md.osfd; } if (!_PR_IS_NATIVE_THREAD(me)) { if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, - PR_INTERVAL_NO_TIMEOUT)) < 0) - goto done; + PR_INTERVAL_NO_TIMEOUT)) < 0) { + goto done; + } } else { #ifndef _PR_USE_POLL while ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, NULL)) - == -1 && (err = _MD_ERRNO()) == EINTR) { + == -1 && (err = _MD_ERRNO()) == EINTR) { /* retry _MD_SELECT() if it is interrupted */ } #else /* _PR_USE_POLL */ while ((rv = _MD_POLL(&pfd, 1, -1)) - == -1 && (err = _MD_ERRNO()) == EINTR) { + == -1 && (err = _MD_ERRNO()) == EINTR) { /* retry _MD_POLL() if it is interrupted */ } #endif /* _PR_USE_POLL */ @@ -328,9 +335,10 @@ PRInt32 osfd = fd->secret->md.osfd; break; } } - if (_PR_PENDING_INTERRUPT(me)) + if (_PR_PENDING_INTERRUPT(me)) { break; - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -350,14 +358,14 @@ done: PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount) { -PRThread *me = _PR_MD_CURRENT_THREAD(); -PRInt32 rv, err; + PRThread *me = _PR_MD_CURRENT_THREAD(); + PRInt32 rv, err; #ifndef _PR_USE_POLL -fd_set wd; + fd_set wd; #else -struct pollfd pfd; + struct pollfd pfd; #endif /* _PR_USE_POLL */ -PRInt32 osfd = fd->secret->md.osfd; + PRInt32 osfd = fd->secret->md.osfd; #ifndef _PR_USE_POLL FD_ZERO(&wd); @@ -374,17 +382,18 @@ PRInt32 osfd = fd->secret->md.osfd; } if (!_PR_IS_NATIVE_THREAD(me)) { if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, - PR_INTERVAL_NO_TIMEOUT)) < 0) + PR_INTERVAL_NO_TIMEOUT)) < 0) { goto done; + } } else { #ifndef _PR_USE_POLL while ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, NULL)) - == -1 && (err = _MD_ERRNO()) == EINTR) { + == -1 && (err = _MD_ERRNO()) == EINTR) { /* retry _MD_SELECT() if it is interrupted */ } #else /* _PR_USE_POLL */ while ((rv = _MD_POLL(&pfd, 1, -1)) - == -1 && (err = _MD_ERRNO()) == EINTR) { + == -1 && (err = _MD_ERRNO()) == EINTR) { /* retry _MD_POLL() if it is interrupted */ } #endif /* _PR_USE_POLL */ @@ -392,9 +401,10 @@ PRInt32 osfd = fd->secret->md.osfd; break; } } - if (_PR_PENDING_INTERRUPT(me)) + if (_PR_PENDING_INTERRUPT(me)) { break; - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -414,7 +424,7 @@ done: PRInt32 _MD_fsync(PRFileDesc *fd) { -PRInt32 rv, err; + PRInt32 rv, err; rv = fsync(fd->secret->md.osfd); if (rv == -1) { @@ -426,7 +436,7 @@ PRInt32 rv, err; PRInt32 _MD_close(PRInt32 osfd) { -PRInt32 rv, err; + PRInt32 rv, err; rv = close(osfd); if (rv == -1) { @@ -484,7 +494,7 @@ PRInt64 _MD_socketavailable64(PRFileDesc *fd) #ifndef _PR_USE_POLL static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, - PRIntervalTime timeout) + PRIntervalTime timeout) { PRInt32 rv = -1; struct timeval tv; @@ -508,10 +518,12 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, FD_ZERO(&rd_wr); do { FD_SET(osfd, &rd_wr); - if (fd_type == READ_FD) + if (fd_type == READ_FD) { rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv); - else + } + else { rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv); + } if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) { _PR_MD_MAP_SELECT_ERROR(syserror); break; @@ -543,14 +555,16 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, tv.tv_usec = 0; } else { tv.tv_usec = PR_IntervalToMicroseconds( - remaining - - PR_SecondsToInterval(tv.tv_sec)); + remaining - + PR_SecondsToInterval(tv.tv_sec)); } FD_SET(osfd, &rd_wr); - if (fd_type == READ_FD) + if (fd_type == READ_FD) { rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv); - else + } + else { rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv); + } /* * we don't consider EINTR a real error */ @@ -579,7 +593,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, now += remaining; } else { now += PR_SecondsToInterval(tv.tv_sec) - + PR_MicrosecondsToInterval(tv.tv_usec); + + PR_MicrosecondsToInterval(tv.tv_usec); } } else { now = PR_IntervalNow(); @@ -602,7 +616,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, #else /* _PR_USE_POLL */ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, - PRIntervalTime timeout) + PRIntervalTime timeout) { PRInt32 rv = -1; int msecs; @@ -634,11 +648,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, _PR_MD_MAP_POLL_ERROR(syserror); break; } - /* - * If POLLERR is set, don't process it; retry the operation - */ + /* + * If POLLERR is set, don't process it; retry the operation + */ if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) { - rv = -1; + rv = -1; _PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents); break; } @@ -686,11 +700,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type, rv = -1; break; } - /* - * If POLLERR is set, don't process it; retry the operation - */ + /* + * If POLLERR is set, don't process it; retry the operation + */ if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) { - rv = -1; + rv = -1; _PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents); break; } @@ -739,11 +753,13 @@ static PRInt32 local_io_wait( PRInt32 rv; PR_LOG(_pr_io_lm, PR_LOG_MIN, - ("waiting to %s on osfd=%d", - (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write", - osfd)); + ("waiting to %s on osfd=%d", + (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write", + osfd)); - if (timeout == PR_INTERVAL_NO_WAIT) return 0; + if (timeout == PR_INTERVAL_NO_WAIT) { + return 0; + } pd.osfd = osfd; pd.in_flags = wait_flag; @@ -760,17 +776,17 @@ static PRInt32 local_io_wait( PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, - PRInt32 flags, PRIntervalTime timeout) + PRInt32 flags, PRIntervalTime timeout) { PRInt32 osfd = fd->secret->md.osfd; PRInt32 rv, err; PRThread *me = _PR_MD_CURRENT_THREAD(); -/* - * Many OS's (Solaris, Unixware) have a broken recv which won't read - * from socketpairs. As long as we don't use flags on socketpairs, this - * is a decent fix. - mikep - */ + /* + * Many OS's (Solaris, Unixware) have a broken recv which won't read + * from socketpairs. As long as we don't use flags on socketpairs, this + * is a decent fix. - mikep + */ #if defined(UNIXWARE) || defined(SOLARIS) while ((rv = read(osfd,buf,amount)) == -1) { #else @@ -782,13 +798,15 @@ PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, break; } if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0) - goto done; + if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0) { + goto done; + } } else { - if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) + if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) { goto done; + } } - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -802,29 +820,31 @@ done: } PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount, - PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, - PRIntervalTime timeout) + PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, + PRIntervalTime timeout) { PRInt32 osfd = fd->secret->md.osfd; PRInt32 rv, err; PRThread *me = _PR_MD_CURRENT_THREAD(); while ((*addrlen = PR_NETADDR_SIZE(addr)), - ((rv = recvfrom(osfd, buf, amount, flags, - (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) { + ((rv = recvfrom(osfd, buf, amount, flags, + (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) { err = _MD_ERRNO(); if ((err == EAGAIN) || (err == EWOULDBLOCK)) { if (fd->secret->nonblocking) { break; } if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) + if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) { goto done; + } } else { - if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) + if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) { goto done; + } } - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -846,13 +866,13 @@ done: } PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount, - PRInt32 flags, PRIntervalTime timeout) + PRInt32 flags, PRIntervalTime timeout) { PRInt32 osfd = fd->secret->md.osfd; PRInt32 rv, err; PRThread *me = _PR_MD_CURRENT_THREAD(); #if defined(SOLARIS) - PRInt32 tmp_amount = amount; + PRInt32 tmp_amount = amount; #endif /* @@ -872,48 +892,50 @@ PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount, break; } if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) + if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) { goto done; + } } else { - if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) + if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) { goto done; + } } - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { #if defined(SOLARIS) - /* - * The write system call has been reported to return the ERANGE - * error on occasion. Try to write in smaller chunks to workaround - * this bug. - */ - if (err == ERANGE) { - if (tmp_amount > 1) { - tmp_amount = tmp_amount/2; /* half the bytes */ - continue; - } - } + /* + * The write system call has been reported to return the ERANGE + * error on occasion. Try to write in smaller chunks to workaround + * this bug. + */ + if (err == ERANGE) { + if (tmp_amount > 1) { + tmp_amount = tmp_amount/2; /* half the bytes */ + continue; + } + } #endif break; } } - /* - * optimization; if bytes sent is less than "amount" call - * select before returning. This is because it is likely that - * the next send() call will return EWOULDBLOCK. - */ + /* + * optimization; if bytes sent is less than "amount" call + * select before returning. This is because it is likely that + * the next send() call will return EWOULDBLOCK. + */ if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount) - && (timeout != PR_INTERVAL_NO_WAIT)) { + && (timeout != PR_INTERVAL_NO_WAIT)) { if (_PR_IS_NATIVE_THREAD(me)) { - if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) { - rv = -1; - goto done; - } + if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) { + rv = -1; + goto done; + } } else { - if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) { - rv = -1; - goto done; - } + if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) { + rv = -1; + goto done; + } } } if (rv < 0) { @@ -938,10 +960,10 @@ PRInt32 _MD_sendto( ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family; while ((rv = sendto(osfd, buf, amount, flags, - (struct sockaddr *) &addrCopy, addrlen)) == -1) { + (struct sockaddr *) &addrCopy, addrlen)) == -1) { #else while ((rv = sendto(osfd, buf, amount, flags, - (struct sockaddr *) addr, addrlen)) == -1) { + (struct sockaddr *) addr, addrlen)) == -1) { #endif err = _MD_ERRNO(); if ((err == EAGAIN) || (err == EWOULDBLOCK)) { @@ -949,13 +971,15 @@ PRInt32 _MD_sendto( break; } if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) - goto done; + if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) { + goto done; + } } else { - if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) + if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) { goto done; + } } - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -997,13 +1021,15 @@ PRInt32 _MD_writev( break; } if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) - goto done; + if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) { + goto done; + } } else { - if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) + if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) { goto done; + } } - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -1015,17 +1041,17 @@ PRInt32 _MD_writev( * the next writev() call will return EWOULDBLOCK. */ if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount) - && (timeout != PR_INTERVAL_NO_WAIT)) { + && (timeout != PR_INTERVAL_NO_WAIT)) { if (_PR_IS_NATIVE_THREAD(me)) { if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) { - rv = -1; + rv = -1; goto done; - } + } } else { - if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) { - rv = -1; - goto done; - } + if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) { + rv = -1; + goto done; + } } } if (rv < 0) { @@ -1036,27 +1062,29 @@ done: } PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, - PRUint32 *addrlen, PRIntervalTime timeout) + PRUint32 *addrlen, PRIntervalTime timeout) { PRInt32 osfd = fd->secret->md.osfd; PRInt32 rv, err; PRThread *me = _PR_MD_CURRENT_THREAD(); while ((rv = accept(osfd, (struct sockaddr *) addr, - (_PRSockLen_t *)addrlen)) == -1) { + (_PRSockLen_t *)addrlen)) == -1) { err = _MD_ERRNO(); if ((err == EAGAIN) || (err == EWOULDBLOCK) || (err == ECONNABORTED)) { if (fd->secret->nonblocking) { break; } if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) - goto done; + if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) { + goto done; + } } else { - if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) + if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) { goto done; + } } - } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){ + } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) { continue; } else { break; @@ -1084,10 +1112,6 @@ PRInt32 _MD_connect( PRInt32 rv, err; PRThread *me = _PR_MD_CURRENT_THREAD(); PRInt32 osfd = fd->secret->md.osfd; -#ifdef IRIX -extern PRInt32 _MD_irix_connect( - PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout); -#endif #ifdef _PR_HAVE_SOCKADDR_LEN PRNetAddr addrCopy; @@ -1109,15 +1133,11 @@ extern PRInt32 _MD_irix_connect( */ retry: -#ifdef IRIX - if ((rv = _MD_irix_connect(osfd, addr, addrlen, timeout)) == -1) { -#else #ifdef _PR_HAVE_SOCKADDR_LEN if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1) { #else if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1) { #endif -#endif err = _MD_ERRNO(); if (err == EINTR) { @@ -1132,8 +1152,9 @@ retry: if (!fd->secret->nonblocking && (err == EINPROGRESS)) { if (!_PR_IS_NATIVE_THREAD(me)) { - if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) + if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) { return -1; + } } else { /* * socket_io_wait() may return -1 or 1. @@ -1210,7 +1231,7 @@ PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how) } PRInt32 _MD_socketpair(int af, int type, int flags, - PRInt32 *osfd) + PRInt32 *osfd) { PRInt32 rv, err; @@ -1223,12 +1244,12 @@ PRInt32 _MD_socketpair(int af, int type, int flags, } PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr, - PRUint32 *addrlen) + PRUint32 *addrlen) { PRInt32 rv, err; rv = getsockname(fd->secret->md.osfd, - (struct sockaddr *) addr, (_PRSockLen_t *)addrlen); + (struct sockaddr *) addr, (_PRSockLen_t *)addrlen); #ifdef _PR_HAVE_SOCKADDR_LEN if (rv == 0) { /* ignore the sa_len field of struct sockaddr */ @@ -1245,12 +1266,12 @@ PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr, } PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr, - PRUint32 *addrlen) + PRUint32 *addrlen) { PRInt32 rv, err; rv = getpeername(fd->secret->md.osfd, - (struct sockaddr *) addr, (_PRSockLen_t *)addrlen); + (struct sockaddr *) addr, (_PRSockLen_t *)addrlen); #ifdef _PR_HAVE_SOCKADDR_LEN if (rv == 0) { /* ignore the sa_len field of struct sockaddr */ @@ -1279,8 +1300,8 @@ PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level, return rv==0?PR_SUCCESS:PR_FAILURE; } -PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, - PRInt32 optname, const char* optval, PRInt32 optlen) +PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, + PRInt32 optname, const char* optval, PRInt32 optlen) { PRInt32 rv, err; @@ -1354,7 +1375,7 @@ static void FindBadFDs(void) if (fcntl(osfd, F_GETFL, 0) == -1) { /* Found a bad descriptor, remove it from the fd_sets. */ PR_LOG(_pr_io_lm, PR_LOG_MAX, - ("file descriptor %d is bad", osfd)); + ("file descriptor %d is bad", osfd)); pds->out_flags = _PR_UNIX_POLL_NVAL; notify = PR_TRUE; } @@ -1369,26 +1390,29 @@ static void FindBadFDs(void) pq->on_ioq = PR_FALSE; /* - * Decrement the count of descriptors for each desciptor/event - * because this I/O request is being removed from the - * ioq - */ + * Decrement the count of descriptors for each desciptor/event + * because this I/O request is being removed from the + * ioq + */ pds = pq->pds; for (; pds < epds; pds++) { PRInt32 osfd = pds->osfd; PRInt16 in_flags = pds->in_flags; PR_ASSERT(osfd >= 0 || in_flags == 0); if (in_flags & _PR_UNIX_POLL_READ) { - if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu)); + } } if (in_flags & _PR_UNIX_POLL_WRITE) { - if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu)); + } } if (in_flags & _PR_UNIX_POLL_EXCEPT) { - if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu)); + } } } @@ -1399,36 +1423,39 @@ static void FindBadFDs(void) _PR_DEL_SLEEPQ(pq->thr, PR_TRUE); _PR_SLEEPQ_UNLOCK(pq->thr->cpu); - if (pq->thr->flags & _PR_SUSPENDING) { - /* - * set thread state to SUSPENDED; - * a Resume operation on the thread - * will move it to the runQ - */ - pq->thr->state = _PR_SUSPENDED; - _PR_MISCQ_LOCK(pq->thr->cpu); - _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu); - _PR_MISCQ_UNLOCK(pq->thr->cpu); - } else { - pri = pq->thr->priority; - pq->thr->state = _PR_RUNNABLE; - - _PR_RUNQ_LOCK(cpu); - _PR_ADD_RUNQ(pq->thr, cpu, pri); - _PR_RUNQ_UNLOCK(cpu); - } + if (pq->thr->flags & _PR_SUSPENDING) { + /* + * set thread state to SUSPENDED; + * a Resume operation on the thread + * will move it to the runQ + */ + pq->thr->state = _PR_SUSPENDED; + _PR_MISCQ_LOCK(pq->thr->cpu); + _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu); + _PR_MISCQ_UNLOCK(pq->thr->cpu); + } else { + pri = pq->thr->priority; + pq->thr->state = _PR_RUNNABLE; + + _PR_RUNQ_LOCK(cpu); + _PR_ADD_RUNQ(pq->thr, cpu, pri); + _PR_RUNQ_UNLOCK(cpu); + } } _PR_THREAD_UNLOCK(pq->thr); } else { - if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) + if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) { _PR_IOQ_TIMEOUT(me->cpu) = pq->timeout; - if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) + } + if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) { _PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd; + } } } if (_PR_IS_NATIVE_THREAD_SUPPORTED()) { - if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) + if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) { _PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0]; + } } } #endif /* !defined(_PR_USE_POLL) */ @@ -1466,9 +1493,6 @@ void _MD_PauseCPU(PRIntervalTime ticks) PRCList *q; PRUint32 min_timeout; sigset_t oldset; -#ifdef IRIX -extern sigset_t ints_off; -#endif PR_ASSERT(_PR_MD_GET_INTSOFF() != 0); @@ -1487,24 +1511,15 @@ extern sigset_t ints_off; */ if (_PR_IS_NATIVE_THREAD_SUPPORTED()) { npollfds++; -#ifdef IRIX - /* - * On Irix, a second pipe is used to cause the primordial cpu to - * wakeup and exit, when the process is exiting because of a call - * to exit/PR_ProcessExit. - */ - if (me->cpu->id == 0) { - npollfds++; - } -#endif - } + } /* * if the cpu's pollfd array is not big enough, release it and allocate a new one */ if (npollfds > _PR_IOQ_POLLFDS_SIZE(me->cpu)) { - if (_PR_IOQ_POLLFDS(me->cpu) != NULL) + if (_PR_IOQ_POLLFDS(me->cpu) != NULL) { PR_DELETE(_PR_IOQ_POLLFDS(me->cpu)); + } pollfds_size = PR_MAX(_PR_IOQ_MIN_POLLFDS_SIZE(me->cpu), npollfds); pollfds = (struct pollfd *) PR_MALLOC(pollfds_size * sizeof(struct pollfd)); _PR_IOQ_POLLFDS(me->cpu) = pollfds; @@ -1522,16 +1537,6 @@ extern sigset_t ints_off; pollfdPtr->fd = _pr_md_pipefd[0]; pollfdPtr->events = POLLIN; pollfdPtr++; -#ifdef IRIX - /* - * On Irix, the second element is the exit pipe - */ - if (me->cpu->id == 0) { - pollfdPtr->fd = _pr_irix_primoridal_cpu_fd[0]; - pollfdPtr->events = POLLIN; - pollfdPtr++; - } -#endif } min_timeout = PR_INTERVAL_NO_TIMEOUT; @@ -1545,9 +1550,9 @@ extern sigset_t ints_off; } for (; pds < epds; pds++, pollfdPtr++) { /* - * Assert that the pollfdPtr pointer does not go - * beyond the end of the pollfds array - */ + * Assert that the pollfdPtr pointer does not go + * beyond the end of the pollfds array + */ PR_ASSERT(pollfdPtr < pollfds + npollfds); pollfdPtr->fd = pds->osfd; /* direct copy of poll flags */ @@ -1589,17 +1594,19 @@ extern sigset_t ints_off; } #ifdef _PR_USE_POLL - if (min_timeout == PR_INTERVAL_NO_TIMEOUT) + if (min_timeout == PR_INTERVAL_NO_TIMEOUT) { timeout = -1; - else + } + else { timeout = PR_IntervalToMilliseconds(min_timeout); + } #else if (min_timeout == PR_INTERVAL_NO_TIMEOUT) { tvp = NULL; } else { timeout.tv_sec = PR_IntervalToSeconds(min_timeout); timeout.tv_usec = PR_IntervalToMicroseconds(min_timeout) - % PR_USEC_PER_SEC; + % PR_USEC_PER_SEC; tvp = &timeout; } #endif /* _PR_USE_POLL */ @@ -1615,22 +1622,10 @@ extern sigset_t ints_off; * are enabled. Otherwise, when the select/poll calls are interrupted, the * timer value starts ticking from zero again when the system call is restarted. */ -#ifdef IRIX - /* - * SIGCHLD signal is used on Irix to detect he termination of an - * sproc by SIGSEGV, SIGBUS or SIGABRT signals when - * _nspr_terminate_on_error is set. - */ - if ((!_nspr_noclock) || (_nspr_terminate_on_error)) -#else - if (!_nspr_noclock) -#endif /* IRIX */ -#ifdef IRIX - sigprocmask(SIG_BLOCK, &ints_off, &oldset); -#else - PR_ASSERT(sigismember(&timer_set, SIGALRM)); + if (!_nspr_noclock) { + PR_ASSERT(sigismember(&timer_set, SIGALRM)); + } sigprocmask(SIG_BLOCK, &timer_set, &oldset); -#endif /* IRIX */ #endif /* !_PR_NO_CLOCK_TIMER */ #ifndef _PR_USE_POLL @@ -1641,19 +1636,14 @@ extern sigset_t ints_off; #endif /* !_PR_USE_POLL */ #ifndef _PR_NO_CLOCK_TIMER -#ifdef IRIX - if ((!_nspr_noclock) || (_nspr_terminate_on_error)) -#else - if (!_nspr_noclock) -#endif /* IRIX */ - sigprocmask(SIG_SETMASK, &oldset, 0); + if (!_nspr_noclock) { + sigprocmask(SIG_SETMASK, &oldset, 0); + } #endif /* !_PR_NO_CLOCK_TIMER */ _MD_CHECK_FOR_EXIT(); -#ifdef IRIX - _PR_MD_primordial_cpu(); -#endif + _PR_MD_primordial_cpu(); _PR_MD_IOQ_LOCK(); /* @@ -1664,45 +1654,21 @@ extern sigset_t ints_off; pollfdPtr = pollfds; if (_PR_IS_NATIVE_THREAD_SUPPORTED()) { /* - * Assert that the pipe is the first element in the - * pollfds array. - */ + * Assert that the pipe is the first element in the + * pollfds array. + */ PR_ASSERT(pollfds[0].fd == _pr_md_pipefd[0]); if ((pollfds[0].revents & POLLIN) && (nfd == 1)) { /* - * woken up by another thread; read all the data - * in the pipe to empty the pipe - */ + * woken up by another thread; read all the data + * in the pipe to empty the pipe + */ while ((rv = read(_pr_md_pipefd[0], _pr_md_pipebuf, - PIPE_BUF)) == PIPE_BUF){ + PIPE_BUF)) == PIPE_BUF) { } PR_ASSERT((rv > 0) || ((rv == -1) && (errno == EAGAIN))); } pollfdPtr++; -#ifdef IRIX - /* - * On Irix, check to see if the primordial cpu needs to exit - * to cause the process to terminate - */ - if (me->cpu->id == 0) { - PR_ASSERT(pollfds[1].fd == _pr_irix_primoridal_cpu_fd[0]); - if (pollfdPtr->revents & POLLIN) { - if (_pr_irix_process_exit) { - /* - * process exit due to a call to PR_ProcessExit - */ - prctl(PR_SETEXITSIG, SIGKILL); - _exit(_pr_irix_process_exit_code); - } else { - while ((rv = read(_pr_irix_primoridal_cpu_fd[0], - _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) { - } - PR_ASSERT(rv > 0); - } - } - pollfdPtr++; - } -#endif } for (q = _PR_IOQ(me->cpu).next; q != &_PR_IOQ(me->cpu); q = q->next) { PRPollQueue *pq = _PR_POLLQUEUE_PTR(q); @@ -1744,26 +1710,27 @@ extern sigset_t ints_off; _PR_DEL_SLEEPQ(pq->thr, PR_TRUE); _PR_SLEEPQ_UNLOCK(pq->thr->cpu); - if (pq->thr->flags & _PR_SUSPENDING) { - /* - * set thread state to SUSPENDED; - * a Resume operation on the thread - * will move it to the runQ - */ - pq->thr->state = _PR_SUSPENDED; - _PR_MISCQ_LOCK(pq->thr->cpu); - _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu); - _PR_MISCQ_UNLOCK(pq->thr->cpu); - } else { - pri = pq->thr->priority; - pq->thr->state = _PR_RUNNABLE; - - _PR_RUNQ_LOCK(cpu); - _PR_ADD_RUNQ(pq->thr, cpu, pri); - _PR_RUNQ_UNLOCK(cpu); - if (_pr_md_idle_cpus > 1) - _PR_MD_WAKEUP_WAITER(thred); - } + if (pq->thr->flags & _PR_SUSPENDING) { + /* + * set thread state to SUSPENDED; + * a Resume operation on the thread + * will move it to the runQ + */ + pq->thr->state = _PR_SUSPENDED; + _PR_MISCQ_LOCK(pq->thr->cpu); + _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu); + _PR_MISCQ_UNLOCK(pq->thr->cpu); + } else { + pri = pq->thr->priority; + pq->thr->state = _PR_RUNNABLE; + + _PR_RUNQ_LOCK(cpu); + _PR_ADD_RUNQ(pq->thr, cpu, pri); + _PR_RUNQ_UNLOCK(cpu); + if (_pr_md_idle_cpus > 1) { + _PR_MD_WAKEUP_WAITER(thred); + } + } } _PR_THREAD_UNLOCK(thred); _PR_IOQ_OSFD_CNT(me->cpu) -= pq->npds; @@ -1827,16 +1794,19 @@ extern sigset_t ints_off; PRInt16 in_flags = pds->in_flags; PR_ASSERT(osfd >= 0 || in_flags == 0); if (in_flags & _PR_UNIX_POLL_READ) { - if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu)); + } } if (in_flags & _PR_UNIX_POLL_WRITE) { - if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu)); + } } if (in_flags & _PR_UNIX_POLL_EXCEPT) { - if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu)); + } } } @@ -1845,7 +1815,7 @@ extern sigset_t ints_off; * after being added to the run queue, do not dereference * pq */ - thred = pq->thr; + thred = pq->thr; _PR_THREAD_LOCK(thred); if (pq->thr->flags & (_PR_ON_PAUSEQ|_PR_ON_SLEEPQ)) { _PRCPU *cpu = thred->cpu; @@ -1853,79 +1823,62 @@ extern sigset_t ints_off; _PR_DEL_SLEEPQ(pq->thr, PR_TRUE); _PR_SLEEPQ_UNLOCK(pq->thr->cpu); - if (pq->thr->flags & _PR_SUSPENDING) { - /* - * set thread state to SUSPENDED; - * a Resume operation on the thread - * will move it to the runQ - */ - pq->thr->state = _PR_SUSPENDED; - _PR_MISCQ_LOCK(pq->thr->cpu); - _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu); - _PR_MISCQ_UNLOCK(pq->thr->cpu); - } else { - pri = pq->thr->priority; - pq->thr->state = _PR_RUNNABLE; - - pq->thr->cpu = cpu; - _PR_RUNQ_LOCK(cpu); - _PR_ADD_RUNQ(pq->thr, cpu, pri); - _PR_RUNQ_UNLOCK(cpu); - if (_pr_md_idle_cpus > 1) - _PR_MD_WAKEUP_WAITER(thred); - } + if (pq->thr->flags & _PR_SUSPENDING) { + /* + * set thread state to SUSPENDED; + * a Resume operation on the thread + * will move it to the runQ + */ + pq->thr->state = _PR_SUSPENDED; + _PR_MISCQ_LOCK(pq->thr->cpu); + _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu); + _PR_MISCQ_UNLOCK(pq->thr->cpu); + } else { + pri = pq->thr->priority; + pq->thr->state = _PR_RUNNABLE; + + pq->thr->cpu = cpu; + _PR_RUNQ_LOCK(cpu); + _PR_ADD_RUNQ(pq->thr, cpu, pri); + _PR_RUNQ_UNLOCK(cpu); + if (_pr_md_idle_cpus > 1) { + _PR_MD_WAKEUP_WAITER(thred); + } + } } _PR_THREAD_UNLOCK(thred); } else { - if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) + if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) { _PR_IOQ_TIMEOUT(me->cpu) = pq->timeout; - if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) + } + if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) { _PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd; + } } } if (_PR_IS_NATIVE_THREAD_SUPPORTED()) { if ((FD_ISSET(_pr_md_pipefd[0], rp)) && (nfd == 1)) { /* - * woken up by another thread; read all the data - * in the pipe to empty the pipe - */ + * woken up by another thread; read all the data + * in the pipe to empty the pipe + */ while ((rv = - read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF)) - == PIPE_BUF){ + read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF)) + == PIPE_BUF) { } PR_ASSERT((rv > 0) || - ((rv == -1) && (errno == EAGAIN))); + ((rv == -1) && (errno == EAGAIN))); } - if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) + if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) { _PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0]; -#ifdef IRIX - if ((me->cpu->id == 0) && - (FD_ISSET(_pr_irix_primoridal_cpu_fd[0], rp))) { - if (_pr_irix_process_exit) { - /* - * process exit due to a call to PR_ProcessExit - */ - prctl(PR_SETEXITSIG, SIGKILL); - _exit(_pr_irix_process_exit_code); - } else { - while ((rv = read(_pr_irix_primoridal_cpu_fd[0], - _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) { - } - PR_ASSERT(rv > 0); - } - } - if (me->cpu->id == 0) { - if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_irix_primoridal_cpu_fd[0]) - _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0]; - } -#endif + } } } else if (nfd < 0) { if (errno == EBADF) { FindBadFDs(); } else { PR_LOG(_pr_io_lm, PR_LOG_MAX, ("select() failed with errno %d", - errno)); + errno)); } } else { PR_ASSERT(nfd == 0); @@ -1947,14 +1900,17 @@ extern sigset_t ints_off; pq_max_osfd = pds->osfd; } } - if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) + if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) { _PR_IOQ_TIMEOUT(me->cpu) = pq->timeout; - if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) + } + if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) { _PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd; + } } if (_PR_IS_NATIVE_THREAD_SUPPORTED()) { - if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) + if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) { _PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0]; + } } } #endif /* _PR_USE_POLL */ @@ -1973,11 +1929,11 @@ void _MD_Wakeup_CPUs() * pipe full, read all data in pipe to empty it */ while ((rv = - read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF)) - == PIPE_BUF) { + read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF)) + == PIPE_BUF) { } PR_ASSERT((rv > 0) || - ((rv == -1) && (errno == EAGAIN))); + ((rv == -1) && (errno == EAGAIN))); rv = write(_pr_md_pipefd[1], &data, 1); } } @@ -2041,10 +1997,10 @@ static void ClockInterruptHandler() } #else /* _PR_NO_PREEMPT */ /* - ** Re-enable unix interrupts (so that we can use - ** setjmp/longjmp for context switching without having to - ** worry about the signal state) - */ + ** Re-enable unix interrupts (so that we can use + ** setjmp/longjmp for context switching without having to + ** worry about the signal state) + */ sigprocmask(SIG_SETMASK, &empty_set, 0); PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock caused context switch")); @@ -2056,8 +2012,9 @@ static void ClockInterruptHandler() _PR_ADD_RUNQ(me, cpu, pri); _PR_RUNQ_UNLOCK(cpu); _PR_THREAD_UNLOCK(me); - } else + } else { me->state = _PR_RUNNABLE; + } _MD_SWITCH_CONTEXT(me); PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock back from context switch")); #endif /* _PR_NO_PREEMPT */ @@ -2096,10 +2053,12 @@ void _MD_StartInterrupts() char *eval; if ((eval = getenv("NSPR_NOCLOCK")) != NULL) { - if (atoi(eval) == 0) + if (atoi(eval) == 0) { _nspr_noclock = 0; - else + } + else { _nspr_noclock = 1; + } } #ifndef _PR_NO_CLOCK_TIMER @@ -2135,10 +2094,10 @@ void _MD_EnableClockInterrupts() #endif /* HPUX9 */ PR_ASSERT(_pr_numCPU == 1); - itval.it_interval.tv_sec = 0; - itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC; - itval.it_value = itval.it_interval; - setitimer(ITIMER_REAL, &itval, 0); + itval.it_interval.tv_sec = 0; + itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC; + itval.it_value = itval.it_interval; + setitimer(ITIMER_REAL, &itval, 0); } void _MD_DisableClockInterrupts() @@ -2147,10 +2106,10 @@ void _MD_DisableClockInterrupts() extern PRUintn _pr_numCPU; PR_ASSERT(_pr_numCPU == 1); - itval.it_interval.tv_sec = 0; - itval.it_interval.tv_usec = 0; - itval.it_value = itval.it_interval; - setitimer(ITIMER_REAL, &itval, 0); + itval.it_interval.tv_sec = 0; + itval.it_interval.tv_usec = 0; + itval.it_value = itval.it_interval; + setitimer(ITIMER_REAL, &itval, 0); } void _MD_BlockClockInterrupts() @@ -2181,7 +2140,7 @@ void _MD_MakeNonblock(PRFileDesc *fd) */ fcntl(osfd, F_SETFL, flags | O_NONBLOCK); - } +} PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode) { @@ -2196,12 +2155,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode) osflags = O_RDONLY; } - if (flags & PR_EXCL) + if (flags & PR_EXCL) { osflags |= O_EXCL; - if (flags & PR_APPEND) + } + if (flags & PR_APPEND) { osflags |= O_APPEND; - if (flags & PR_TRUNCATE) + } + if (flags & PR_TRUNCATE) { osflags |= O_TRUNC; + } if (flags & PR_SYNC) { #if defined(O_SYNC) osflags |= O_SYNC; @@ -2219,8 +2181,9 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode) if (flags & PR_CREATE_FILE) { osflags |= O_CREAT; - if (NULL !=_pr_rename_lock) - PR_Lock(_pr_rename_lock); + if (NULL !=_pr_unix_rename_lock) { + PR_Lock(_pr_unix_rename_lock); + } } #if defined(ANDROID) @@ -2234,14 +2197,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode) _PR_MD_MAP_OPEN_ERROR(err); } - if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock)) - PR_Unlock(_pr_rename_lock); + if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock)) { + PR_Unlock(_pr_unix_rename_lock); + } return rv; } PRIntervalTime intr_timeout_ticks; -#if defined(SOLARIS) || defined(IRIX) +#if defined(SOLARIS) static void sigsegvhandler() { fprintf(stderr,"Received SIGSEGV\n"); fflush(stderr); @@ -2259,7 +2223,7 @@ static void sigbushandler() { fflush(stderr); pause(); } -#endif /* SOLARIS, IRIX */ +#endif /* SOLARIS */ #endif /* !defined(_PR_PTHREADS) */ @@ -2271,7 +2235,7 @@ void _MD_query_fd_inheritable(PRFileDesc *fd) flags = fcntl(fd->secret->md.osfd, F_GETFD, 0); PR_ASSERT(-1 != flags); fd->secret->inheritable = (flags & FD_CLOEXEC) ? - _PR_TRI_FALSE : _PR_TRI_TRUE; + _PR_TRI_FALSE : _PR_TRI_TRUE; } PROffset32 _MD_lseek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence) @@ -2537,12 +2501,15 @@ static int _MD_convert_stat_to_fileinfo( const struct stat *sb, PRFileInfo *info) { - if (S_IFREG & sb->st_mode) + if (S_IFREG & sb->st_mode) { info->type = PR_FILE_FILE; - else if (S_IFDIR & sb->st_mode) + } + else if (S_IFDIR & sb->st_mode) { info->type = PR_FILE_DIRECTORY; - else + } + else { info->type = PR_FILE_OTHER; + } #if defined(_PR_HAVE_LARGE_OFF_T) if (0x7fffffffL < sb->st_size) @@ -2561,12 +2528,15 @@ static int _MD_convert_stat64_to_fileinfo64( const _MDStat64 *sb, PRFileInfo64 *info) { - if (S_IFREG & sb->st_mode) + if (S_IFREG & sb->st_mode) { info->type = PR_FILE_FILE; - else if (S_IFDIR & sb->st_mode) + } + else if (S_IFDIR & sb->st_mode) { info->type = PR_FILE_DIRECTORY; - else + } + else { info->type = PR_FILE_OTHER; + } LL_I2L(info->size, sb->st_size); @@ -2580,10 +2550,12 @@ PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info) struct stat sb; rv = stat(fn, &sb); - if (rv < 0) + if (rv < 0) { _PR_MD_MAP_STAT_ERROR(_MD_ERRNO()); - else if (NULL != info) + } + else if (NULL != info) { rv = _MD_convert_stat_to_fileinfo(&sb, info); + } return rv; } @@ -2591,10 +2563,12 @@ PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info) { _MDStat64 sb; PRInt32 rv = _md_iovector._stat64(fn, &sb); - if (rv < 0) + if (rv < 0) { _PR_MD_MAP_STAT_ERROR(_MD_ERRNO()); - else if (NULL != info) + } + else if (NULL != info) { rv = _MD_convert_stat64_to_fileinfo64(&sb, info); + } return rv; } @@ -2602,10 +2576,12 @@ PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info) { struct stat sb; PRInt32 rv = fstat(fd->secret->md.osfd, &sb); - if (rv < 0) + if (rv < 0) { _PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO()); - else if (NULL != info) + } + else if (NULL != info) { rv = _MD_convert_stat_to_fileinfo(&sb, info); + } return rv; } @@ -2613,10 +2589,12 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info) { _MDStat64 sb; PRInt32 rv = _md_iovector._fstat64(fd->secret->md.osfd, &sb); - if (rv < 0) + if (rv < 0) { _PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO()); - else if (NULL != info) + } + else if (NULL != info) { rv = _MD_convert_stat64_to_fileinfo64(&sb, info); + } return rv; } @@ -2626,11 +2604,7 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info) * initialized by _PR_MD_FINAL_INIT. This means the log file cannot be a * large file on some platforms. */ -#ifdef SYMBIAN -struct _MD_IOVector _md_iovector; /* Will crash if NSPR_LOG_FILE is set. */ -#else struct _MD_IOVector _md_iovector = { open }; -#endif /* ** These implementations are to emulate large file routines on systems that @@ -2700,7 +2674,9 @@ static PROffset64 _MD_Unix_lseek64(PRIntn osfd, PROffset64 offset, PRIntn whence LL_L2I(off, offset); LL_I2L(rv, lseek(osfd, off, whence)); } - else errno = EFBIG; /* we can't go there */ + else { + errno = EFBIG; /* we can't go there */ + } return rv; } /* _MD_Unix_lseek64 */ @@ -2735,28 +2711,6 @@ mmap64(void *addr, size_t len, int prot, int flags, int fd, loff_t offset) } #endif -#if defined(OSF1) && defined(__GNUC__) - -/* - * On OSF1 V5.0A, <sys/stat.h> defines stat and fstat as - * macros when compiled under gcc, so it is rather tricky to - * take the addresses of the real functions the macros expend - * to. A simple solution is to define forwarder functions - * and take the addresses of the forwarder functions instead. - */ - -static int stat_forwarder(const char *path, struct stat *buffer) -{ - return stat(path, buffer); -} - -static int fstat_forwarder(int filedes, struct stat *buffer) -{ - return fstat(filedes, buffer); -} - -#endif - static void _PR_InitIOV(void) { #if defined(SOLARIS2_5) @@ -2789,7 +2743,7 @@ static void _PR_InitIOV(void) _md_iovector._stat64 = stat; _md_iovector._lseek64 = _MD_Unix_lseek64; #elif defined(_PR_HAVE_OFF64_T) -#if defined(IRIX5_3) || (defined(ANDROID) && __ANDROID_API__ < 21) +#if (defined(ANDROID) && __ANDROID_API__ < 21) /* * Android < 21 doesn't have open64. We pass the O_LARGEFILE flag to open * in _MD_open. @@ -2811,13 +2765,8 @@ static void _PR_InitIOV(void) #elif defined(_PR_HAVE_LARGE_OFF_T) _md_iovector._open64 = open; _md_iovector._mmap64 = mmap; -#if defined(OSF1) && defined(__GNUC__) - _md_iovector._fstat64 = fstat_forwarder; - _md_iovector._stat64 = stat_forwarder; -#else _md_iovector._fstat64 = fstat; _md_iovector._stat64 = stat; -#endif _md_iovector._lseek64 = lseek; #else #error "I don't know yet" @@ -2837,9 +2786,9 @@ void _PR_UnixInit(void) sigaddset(&timer_set, SIGALRM); sigemptyset(&empty_set); intr_timeout_ticks = - PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS); + PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS); -#if defined(SOLARIS) || defined(IRIX) +#if defined(SOLARIS) if (getenv("NSPR_SIGSEGV_HANDLE")) { sigact.sa_handler = sigsegvhandler; @@ -2871,8 +2820,8 @@ void _PR_UnixInit(void) rv = sigaction(SIGPIPE, &sigact, 0); PR_ASSERT(0 == rv); - _pr_rename_lock = PR_NewLock(); - PR_ASSERT(NULL != _pr_rename_lock); + _pr_unix_rename_lock = PR_NewLock(); + PR_ASSERT(NULL != _pr_unix_rename_lock); _pr_Xfe_mon = PR_NewMonitor(); PR_ASSERT(NULL != _pr_Xfe_mon); @@ -2881,9 +2830,9 @@ void _PR_UnixInit(void) void _PR_UnixCleanup(void) { - if (_pr_rename_lock) { - PR_DestroyLock(_pr_rename_lock); - _pr_rename_lock = NULL; + if (_pr_unix_rename_lock) { + PR_DestroyLock(_pr_unix_rename_lock); + _pr_unix_rename_lock = NULL; } if (_pr_Xfe_mon) { PR_DestroyMonitor(_pr_Xfe_mon); @@ -2917,7 +2866,7 @@ void _MD_InitSegs(void) return; } #endif - _pr_zero_fd = open("/dev/zero",O_RDWR , 0); + _pr_zero_fd = open("/dev/zero",O_RDWR, 0); /* Prevent the fd from being inherited by child processes */ fcntl(_pr_zero_fd, F_SETFD, FD_CLOEXEC); _pr_md_lock = PR_NewLock(); @@ -2956,8 +2905,8 @@ from_heap: prot |= PROT_EXEC; #endif rv = mmap((vaddr != 0) ? vaddr : lastaddr, size, prot, - _MD_MMAP_FLAGS, - _pr_zero_fd, 0); + _MD_MMAP_FLAGS, + _pr_zero_fd, 0); if (rv == (void*)-1) { goto from_heap; } @@ -2973,10 +2922,12 @@ exit: void _MD_FreeSegment(PRSegment *seg) { - if (seg->flags & _PR_SEG_VM) + if (seg->flags & _PR_SEG_VM) { (void) munmap(seg->vaddr, seg->size); - else + } + else { PR_DELETE(seg->vaddr); + } } #endif /* _PR_PTHREADS */ @@ -3123,7 +3074,7 @@ PRInt32 _PR_WaitForMultipleFDs( } _PR_IOQ_OSFD_CNT(me->cpu) += pdcnt; - + _PR_SLEEPQ_LOCK(me->cpu); _PR_ADD_SLEEPQ(me, timeout); me->state = _PR_IO_WAIT; @@ -3139,7 +3090,7 @@ PRInt32 _PR_WaitForMultipleFDs( me->io_suspended = PR_FALSE; /* - * This thread should run on the same cpu on which it was blocked; when + * This thread should run on the same cpu on which it was blocked; when * the IO request times out the fd sets and fd counts for the * cpu are updated below. */ @@ -3163,16 +3114,19 @@ PRInt32 _PR_WaitForMultipleFDs( PRInt16 in_flags = unixpd->in_flags; if (in_flags & _PR_UNIX_POLL_READ) { - if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu)); + } } if (in_flags & _PR_UNIX_POLL_WRITE) { - if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu)); + } } if (in_flags & _PR_UNIX_POLL_EXCEPT) { - if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) + if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) { FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu)); + } } } #endif /* _PR_USE_POLL */ @@ -3220,12 +3174,12 @@ void _PR_Unblock_IO_Wait(PRThread *thr) { int pri = thr->priority; _PRCPU *cpu = thr->cpu; - + /* * GLOBAL threads wakeup periodically to check for interrupt */ if (_PR_IS_NATIVE_THREAD(thr)) { - _PR_THREAD_UNLOCK(thr); + _PR_THREAD_UNLOCK(thr); return; } @@ -3267,7 +3221,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd) if (strcmp(superblock.f_basetype, "ttcpip") == 0) { /* Using the Tiny Stack! */ rv = getpeername(osfd, (struct sockaddr *) &addr, - (_PRSockLen_t *) &addrlen); + (_PRSockLen_t *) &addrlen); if (rv == -1) { int errno_copy = errno; /* make a copy so I don't * accidentally reset */ @@ -3306,7 +3260,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd) _PRSockLen_t optlen = sizeof(err); if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, - (char *) &err, &optlen) == -1) { + (char *) &err, &optlen) == -1) { return errno; } else { return err; @@ -3325,16 +3279,16 @@ int _MD_unix_get_nonblocking_connect_error(int osfd) rv = getmsg(osfd, NULL, NULL, &flags); PR_ASSERT(-1 == rv || 0 == rv); if (-1 == rv && errno != EAGAIN && errno != EWOULDBLOCK) { - return errno; + return errno; } return 0; /* no error */ #else - int err; - _PRSockLen_t optlen = sizeof(err); - if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) { - return errno; - } - return err; + int err; + _PRSockLen_t optlen = sizeof(err); + if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) { + return errno; + } + return err; #endif } @@ -3390,8 +3344,9 @@ _MD_LockFile(PRInt32 f) arg.l_start = 0; arg.l_len = 0; /* until EOF */ rv = fcntl(f, F_SETLKW, &arg); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3407,8 +3362,9 @@ _MD_TLockFile(PRInt32 f) arg.l_start = 0; arg.l_len = 0; /* until EOF */ rv = fcntl(f, F_SETLK, &arg); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3424,8 +3380,9 @@ _MD_UnlockFile(PRInt32 f) arg.l_start = 0; arg.l_len = 0; /* until EOF */ rv = fcntl(f, F_SETLK, &arg); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3439,8 +3396,9 @@ _MD_LockFile(PRInt32 f) { PRInt32 rv; rv = flock(f, LOCK_EX); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3450,8 +3408,9 @@ _MD_TLockFile(PRInt32 f) { PRInt32 rv; rv = flock(f, LOCK_EX|LOCK_NB); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3461,8 +3420,9 @@ _MD_UnlockFile(PRInt32 f) { PRInt32 rv; rv = flock(f, LOCK_UN); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3473,8 +3433,9 @@ _MD_LockFile(PRInt32 f) { PRInt32 rv; rv = lockf(f, F_LOCK, 0); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3484,8 +3445,9 @@ _MD_TLockFile(PRInt32 f) { PRInt32 rv; rv = lockf(f, F_TLOCK, 0); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3495,8 +3457,9 @@ _MD_UnlockFile(PRInt32 f) { PRInt32 rv; rv = lockf(f, F_ULOCK, 0); - if (rv == 0) + if (rv == 0) { return PR_SUCCESS; + } _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO()); return PR_FAILURE; } @@ -3516,20 +3479,23 @@ PRStatus _MD_gethostname(char *name, PRUint32 namelen) PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen) { - struct utsname info; + struct utsname info; - PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE)); + PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE)); - if (uname(&info) == -1) { - _PR_MD_MAP_DEFAULT_ERROR(errno); - return PR_FAILURE; - } - if (PR_SI_SYSNAME == cmd) - (void)PR_snprintf(name, namelen, info.sysname); - else if (PR_SI_RELEASE == cmd) - (void)PR_snprintf(name, namelen, info.release); - else - return PR_FAILURE; + if (uname(&info) == -1) { + _PR_MD_MAP_DEFAULT_ERROR(errno); + return PR_FAILURE; + } + if (PR_SI_SYSNAME == cmd) { + (void)PR_snprintf(name, namelen, info.sysname); + } + else if (PR_SI_RELEASE == cmd) { + (void)PR_snprintf(name, namelen, info.release); + } + else { + return PR_FAILURE; + } return PR_SUCCESS; } @@ -3569,12 +3535,15 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size) } if (fmap->prot == PR_PROT_READONLY) { fmap->md.prot = PROT_READ; -#ifdef OSF1V4_MAP_PRIVATE_BUG +#if defined(DARWIN) || defined(ANDROID) /* - * Use MAP_SHARED to work around a bug in OSF1 V4.0D - * (QAR 70220 in the OSF_QAR database) that results in - * corrupted data in the memory-mapped region. This - * bug is fixed in V5.0. + * This is needed on OS X because its implementation of + * POSIX shared memory returns an error for MAP_PRIVATE, even + * when the mapping is read-only. + * + * And this is needed on Android, because mapping ashmem with + * MAP_PRIVATE creates a mapping of zeroed memory instead of + * the shm contents. */ fmap->md.flags = MAP_SHARED; #else @@ -3601,8 +3570,8 @@ void * _MD_MemMap( LL_L2I(off, offset); if ((addr = mmap(0, len, fmap->md.prot, fmap->md.flags, - fmap->fd->secret->md.osfd, off)) == (void *) -1) { - _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO()); + fmap->fd->secret->md.osfd, off)) == (void *) -1) { + _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO()); addr = NULL; } return addr; @@ -3623,7 +3592,7 @@ PRStatus _MD_CloseFileMap(PRFileMap *fmap) PRStatus rc = PR_Close( fmap->fd ); if ( PR_FAILURE == rc ) { PR_LOG( _pr_io_lm, PR_LOG_DEBUG, - ("_MD_CloseFileMap(): error closing anonymnous file map osfd")); + ("_MD_CloseFileMap(): error closing anonymnous file map osfd")); return PR_FAILURE; } } diff --git a/nsprpub/pr/src/md/unix/unix_errors.c b/nsprpub/pr/src/md/unix/unix_errors.c index bcea0993f..1d8765969 100644 --- a/nsprpub/pr/src/md/unix/unix_errors.c +++ b/nsprpub/pr/src/md/unix/unix_errors.c @@ -29,9 +29,9 @@ void _MD_unix_map_default_error(int err) case EAGAIN: prError = PR_WOULD_BLOCK_ERROR; break; - /* - * On QNX and Neutrino, EALREADY is defined as EBUSY. - */ + /* + * On QNX and Neutrino, EALREADY is defined as EBUSY. + */ #if EALREADY != EBUSY case EALREADY: prError = PR_ALREADY_INITIATED_ERROR; @@ -127,9 +127,9 @@ void _MD_unix_map_default_error(int err) case ENFILE: prError = PR_SYS_DESC_TABLE_FULL_ERROR; break; - /* - * On SCO OpenServer 5, ENOBUFS is defined as ENOSR. - */ + /* + * On SCO OpenServer 5, ENOBUFS is defined as ENOSR. + */ #if defined(ENOBUFS) && (ENOBUFS != ENOSR) case ENOBUFS: prError = PR_INSUFFICIENT_RESOURCES_ERROR; @@ -144,7 +144,7 @@ void _MD_unix_map_default_error(int err) case ENOLCK: prError = PR_FILE_IS_LOCKED_ERROR; break; -#ifdef ENOLINK +#ifdef ENOLINK case ENOLINK: prError = PR_REMOTE_FILE_ERROR; break; @@ -362,9 +362,9 @@ void _MD_unix_map_rmdir_error(int err) PRErrorCode prError; switch (err) { - /* - * On AIX 4.3, ENOTEMPTY is defined as EEXIST. - */ + /* + * On AIX 4.3, ENOTEMPTY is defined as EEXIST. + */ #if ENOTEMPTY != EEXIST case ENOTEMPTY: prError = PR_DIRECTORY_NOT_EMPTY_ERROR; @@ -530,8 +530,8 @@ void _MD_unix_map_connect_error(int err) switch (err) { #if defined(UNIXWARE) /* - * On some platforms, if we connect to a port on the local host - * (the loopback address) that no process is listening on, we get + * On some platforms, if we connect to a port on the local host + * (the loopback address) that no process is listening on, we get * EIO instead of ECONNREFUSED. */ case EIO: @@ -738,14 +738,18 @@ void _MD_unix_map_poll_error(int err) void _MD_unix_map_poll_revents_error(int err) { - if (err & POLLNVAL) + if (err & POLLNVAL) { PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF); - else if (err & POLLHUP) + } + else if (err & POLLHUP) { PR_SetError(PR_CONNECT_RESET_ERROR, EPIPE); - else if (err & POLLERR) + } + else if (err & POLLERR) { PR_SetError(PR_IO_ERROR, EIO); - else + } + else { PR_SetError(PR_UNKNOWN_ERROR, err); + } } #endif /* _PR_POLL_AVAILABLE || _PR_NEED_FAKE_POLL */ diff --git a/nsprpub/pr/src/md/unix/unixware.c b/nsprpub/pr/src/md/unix/unixware.c index 638af5f2e..d6958558b 100644 --- a/nsprpub/pr/src/md/unix/unixware.c +++ b/nsprpub/pr/src/md/unix/unixware.c @@ -20,7 +20,7 @@ void _MD_EarlyInit(void) PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { if (isCurrent) { - (void) setjmp(CONTEXT(t)); + (void) setjmp(CONTEXT(t)); } *np = sizeof(CONTEXT(t)) / sizeof(PRWord); return (PRWord *) CONTEXT(t); @@ -29,7 +29,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) #ifdef ALARMS_BREAK_TCP /* I don't think they do */ PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, - PRIntervalTime timeout) + PRIntervalTime timeout) { PRInt32 rv; @@ -39,7 +39,7 @@ PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, } PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen, - PRIntervalTime timeout) + PRIntervalTime timeout) { PRInt32 rv; @@ -64,8 +64,9 @@ void _MD_INIT_ATOMIC(void) { /* Sigh. Sure wish SYSV semaphores weren't such a pain to use */ - if ((_uw_semf = tmpfile()) == NULL) + if ((_uw_semf = tmpfile()) == NULL) { PR_ASSERT(0); + } return; } @@ -112,7 +113,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) PRStatus _MD_InitializeThread(PRThread *thread) { - return PR_SUCCESS; + return PR_SUCCESS; } PRStatus @@ -127,7 +128,7 @@ PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { if (thread) { - PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); } return PR_SUCCESS; } @@ -230,30 +231,31 @@ void _MD_EarlyInit(void) sigaddset(&set, SIGALRM); } -PRStatus _MD_CREATE_THREAD(PRThread *thread, - void (*start)(void *), - PRThreadPriority priority, - PRThreadScope scope, - PRThreadState state, - PRUint32 stackSize) +PRStatus _MD_CREATE_THREAD(PRThread *thread, + void (*start)(void *), + PRThreadPriority priority, + PRThreadScope scope, + PRThreadState state, + PRUint32 stackSize) { - long flags; - + long flags; + /* mask out SIGALRM for native thread creation */ - thr_sigsetmask(SIG_BLOCK, &set, &oldset); + thr_sigsetmask(SIG_BLOCK, &set, &oldset); - flags = (state == PR_JOINABLE_THREAD ? THR_SUSPENDED/*|THR_NEW_LWP*/ - : THR_SUSPENDED|THR_DETACHED/*|THR_NEW_LWP*/); - if (_PR_IS_GCABLE_THREAD(thread) || - (scope == PR_GLOBAL_BOUND_THREAD)) - flags |= THR_BOUND; + flags = (state == PR_JOINABLE_THREAD ? THR_SUSPENDED/*|THR_NEW_LWP*/ + : THR_SUSPENDED|THR_DETACHED/*|THR_NEW_LWP*/); + if (_PR_IS_GCABLE_THREAD(thread) || + (scope == PR_GLOBAL_BOUND_THREAD)) { + flags |= THR_BOUND; + } if (thr_create(NULL, thread->stack->stackSize, - (void *(*)(void *)) start, (void *) thread, - flags, - &thread->md.handle)) { - thr_sigsetmask(SIG_SETMASK, &oldset, NULL); - return PR_FAILURE; + (void *(*)(void *)) start, (void *) thread, + flags, + &thread->md.handle)) { + thr_sigsetmask(SIG_SETMASK, &oldset, NULL); + return PR_FAILURE; } @@ -262,34 +264,34 @@ PRStatus _MD_CREATE_THREAD(PRThread *thread, * its register state is initialized properly for GC */ thread->md.lwpid = -1; - thr_sigsetmask(SIG_SETMASK, &oldset, NULL); + thr_sigsetmask(SIG_SETMASK, &oldset, NULL); _MD_NEW_SEM(&thread->md.waiter_sem, 0); - if ((scope == PR_GLOBAL_THREAD) || (scope == PR_GLOBAL_BOUND_THREAD)) { - thread->flags |= _PR_GLOBAL_SCOPE; + if ((scope == PR_GLOBAL_THREAD) || (scope == PR_GLOBAL_BOUND_THREAD)) { + thread->flags |= _PR_GLOBAL_SCOPE; } - /* - ** Set the thread priority. This will also place the thread on + /* + ** Set the thread priority. This will also place the thread on ** the runQ. ** ** Force PR_SetThreadPriority to set the priority by ** setting thread->priority to 100. */ { - int pri; - pri = thread->priority; - thread->priority = 100; - PR_SetThreadPriority( thread, pri ); - - PR_LOG(_pr_thread_lm, PR_LOG_MIN, - ("(0X%x)[Start]: on to runq at priority %d", - thread, thread->priority)); + int pri; + pri = thread->priority; + thread->priority = 100; + PR_SetThreadPriority( thread, pri ); + + PR_LOG(_pr_thread_lm, PR_LOG_MIN, + ("(0X%x)[Start]: on to runq at priority %d", + thread, thread->priority)); } /* Activate the thread */ if (thr_continue( thread->md.handle ) ) { - return PR_FAILURE; + return PR_FAILURE; } return PR_SUCCESS; } @@ -301,7 +303,7 @@ void _MD_cleanup_thread(PRThread *thread) hdl = thread->md.handle; - /* + /* ** First, suspend the thread (unless it's the active one) ** Because we suspend it first, we don't have to use LOCK_SCHEDULER to ** prevent both of us modifying the thread structure at the same time. @@ -310,17 +312,17 @@ void _MD_cleanup_thread(PRThread *thread) thr_suspend(hdl); } PR_LOG(_pr_thread_lm, PR_LOG_MIN, - ("(0X%x)[DestroyThread]\n", thread)); + ("(0X%x)[DestroyThread]\n", thread)); _MD_DESTROY_SEM(&thread->md.waiter_sem); } void _MD_SET_PRIORITY(_MDThread *md_thread, PRUintn newPri) { - if(thr_setprio((thread_t)md_thread->handle, newPri)) { - PR_LOG(_pr_thread_lm, PR_LOG_MIN, - ("_PR_SetThreadPriority: can't set thread priority\n")); - } + if(thr_setprio((thread_t)md_thread->handle, newPri)) { + PR_LOG(_pr_thread_lm, PR_LOG_MIN, + ("_PR_SetThreadPriority: can't set thread priority\n")); + } } void _MD_WAIT_CV( @@ -373,18 +375,18 @@ PRThread *_pr_current_thread_tls() PRStatus _MD_WAIT(PRThread *thread, PRIntervalTime ticks) { - _MD_WAIT_SEM(&thread->md.waiter_sem); - return PR_SUCCESS; + _MD_WAIT_SEM(&thread->md.waiter_sem); + return PR_SUCCESS; } PRStatus _MD_WAKEUP_WAITER(PRThread *thread) { - if (thread == NULL) { - return PR_SUCCESS; - } - _MD_POST_SEM(&thread->md.waiter_sem); - return PR_SUCCESS; + if (thread == NULL) { + return PR_SUCCESS; + } + _MD_POST_SEM(&thread->md.waiter_sem); + return PR_SUCCESS; } _PRCPU *_pr_current_cpu_tls() @@ -412,39 +414,40 @@ void _MD_INIT_IO (void) PRStatus _MD_InitializeThread(PRThread *thread) { - if (!_PR_IS_NATIVE_THREAD(thread)) + if (!_PR_IS_NATIVE_THREAD(thread)) { return; - /* prime the sp; substract 4 so we don't hit the assert that - * curr sp > base_stack - */ + } + /* prime the sp; substract 4 so we don't hit the assert that + * curr sp > base_stack + */ thread->md.sp = (uint_t) thread->stack->allocBase - sizeof(long); thread->md.lwpid = _lwp_self(); thread->md.handle = THR_SELF(); - /* all threads on Solaris are global threads from NSPR's perspective - * since all of them are mapped to Solaris threads. - */ + /* all threads on Solaris are global threads from NSPR's perspective + * since all of them are mapped to Solaris threads. + */ thread->flags |= _PR_GLOBAL_SCOPE; - /* For primordial/attached thread, we don't create an underlying native thread. - * So, _MD_CREATE_THREAD() does not get called. We need to do initialization - * like allocating thread's synchronization variables and set the underlying - * native thread's priority. - */ - if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) { - _MD_NEW_SEM(&thread->md.waiter_sem, 0); - _MD_SET_PRIORITY(&(thread->md), thread->priority); - } - return PR_SUCCESS; -} - -static sigset_t old_mask; /* store away original gc thread sigmask */ -static int gcprio; /* store away original gc thread priority */ -static lwpid_t *all_lwps=NULL; /* list of lwps that we suspended */ + /* For primordial/attached thread, we don't create an underlying native thread. + * So, _MD_CREATE_THREAD() does not get called. We need to do initialization + * like allocating thread's synchronization variables and set the underlying + * native thread's priority. + */ + if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) { + _MD_NEW_SEM(&thread->md.waiter_sem, 0); + _MD_SET_PRIORITY(&(thread->md), thread->priority); + } + return PR_SUCCESS; +} + +static sigset_t old_mask; /* store away original gc thread sigmask */ +static int gcprio; /* store away original gc thread priority */ +static lwpid_t *all_lwps=NULL; /* list of lwps that we suspended */ static int num_lwps ; static int suspendAllOn = 0; -#define VALID_SP(sp, bottom, top) \ +#define VALID_SP(sp, bottom, top) \ (((uint_t)(sp)) > ((uint_t)(bottom)) && ((uint_t)(sp)) < ((uint_t)(top))) void unixware_preempt_off() @@ -456,7 +459,7 @@ void unixware_preempt_off() void unixware_preempt_on() { - sigprocmask (SIG_SETMASK, &old_mask, NULL); + sigprocmask (SIG_SETMASK, &old_mask, NULL); } void _MD_Begin_SuspendAll() @@ -466,7 +469,7 @@ void _MD_Begin_SuspendAll() PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin_SuspendAll\n")); /* run at highest prio so I cannot be preempted */ thr_getprio(thr_self(), &gcprio); - thr_setprio(thr_self(), 0x7fffffff); + thr_setprio(thr_self(), 0x7fffffff); suspendAllOn = 1; } @@ -484,55 +487,60 @@ void _MD_End_ResumeAll() void _MD_Suspend(PRThread *thr) { - int lwp_fd, result; - int lwp_main_proc_fd = 0; + int lwp_fd, result; + int lwp_main_proc_fd = 0; thr_suspend(thr->md.handle); - if (!_PR_IS_GCABLE_THREAD(thr)) - return; + if (!_PR_IS_GCABLE_THREAD(thr)) { + return; + } /* XXX Primordial thread can't be bound to an lwp, hence there is no * way we can assume that we can get the lwp status for primordial * thread reliably. Hence we skip this for primordial thread, hoping - * that the SP is saved during lock and cond. wait. + * that the SP is saved during lock and cond. wait. * XXX - Again this is concern only for java interpreter, not for the * server, 'cause primordial thread in the server does not do java work */ - if (thr->flags & _PR_PRIMORDIAL) - return; + if (thr->flags & _PR_PRIMORDIAL) { + return; + } /* if the thread is not started yet then don't do anything */ - if (!suspendAllOn || thr->md.lwpid == -1) - return; + if (!suspendAllOn || thr->md.lwpid == -1) { + return; + } } void _MD_Resume(PRThread *thr) { - if (!_PR_IS_GCABLE_THREAD(thr) || !suspendAllOn){ - /*XXX When the suspendAllOn is set, we will be trying to do lwp_suspend - * during that time we can't call any thread lib or libc calls. Hence - * make sure that no resume is requested for Non gcable thread - * during suspendAllOn */ - PR_ASSERT(!suspendAllOn); - thr_continue(thr->md.handle); - return; - } - if (thr->md.lwpid == -1) - return; - - if ( _lwp_continue(thr->md.lwpid) < 0) { - PR_ASSERT(0); /* ARGH, we are hosed! */ - } + if (!_PR_IS_GCABLE_THREAD(thr) || !suspendAllOn) { + /*XXX When the suspendAllOn is set, we will be trying to do lwp_suspend + * during that time we can't call any thread lib or libc calls. Hence + * make sure that no resume is requested for Non gcable thread + * during suspendAllOn */ + PR_ASSERT(!suspendAllOn); + thr_continue(thr->md.handle); + return; + } + if (thr->md.lwpid == -1) { + return; + } + + if ( _lwp_continue(thr->md.lwpid) < 0) { + PR_ASSERT(0); /* ARGH, we are hosed! */ + } } PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) { if (isCurrent) { - (void) getcontext(CONTEXT(t)); /* XXX tune me: set md_IRIX.c */ + (void) getcontext(CONTEXT(t)); /* XXX tune me: set md_IRIX.c */ } *np = NGREG; - if (t->md.lwpid == -1) - memset(&t->md.context.uc_mcontext.gregs[0], 0, NGREG * sizeof(PRWord)); + if (t->md.lwpid == -1) { + memset(&t->md.context.uc_mcontext.gregs[0], 0, NGREG * sizeof(PRWord)); + } return (PRWord*) &t->md.context.uc_mcontext.gregs[0]; } @@ -540,7 +548,7 @@ int _pr_unixware_clock_gettime (struct timespec *tp) { struct timeval tv; - + gettimeofday(&tv, NULL); tp->tv_sec = tv.tv_sec; tp->tv_nsec = tv.tv_usec * 1000; diff --git a/nsprpub/pr/src/md/unix/uxpoll.c b/nsprpub/pr/src/md/unix/uxpoll.c index 8a618ed80..d01121cbf 100644 --- a/nsprpub/pr/src/md/unix/uxpoll.c +++ b/nsprpub/pr/src/md/unix/uxpoll.c @@ -52,19 +52,19 @@ static PRInt32 NativeThreadPoll( if (pds[index].in_flags & PR_POLL_READ) { in_flags_read = (pds[index].fd->methods->poll)( - pds[index].fd, - pds[index].in_flags & ~PR_POLL_WRITE, - &out_flags_read); + pds[index].fd, + pds[index].in_flags & ~PR_POLL_WRITE, + &out_flags_read); } if (pds[index].in_flags & PR_POLL_WRITE) { in_flags_write = (pds[index].fd->methods->poll)( - pds[index].fd, - pds[index].in_flags & ~PR_POLL_READ, - &out_flags_write); + pds[index].fd, + pds[index].in_flags & ~PR_POLL_READ, + &out_flags_write); } if ((0 != (in_flags_read & out_flags_read)) - || (0 != (in_flags_write & out_flags_write))) + || (0 != (in_flags_write & out_flags_write))) { /* this one is ready right now */ if (0 == ready) @@ -91,7 +91,7 @@ static PRInt32 NativeThreadPoll( bottom = PR_GetIdentitiesLayer(pds[index].fd, PR_NSPR_IO_LAYER); PR_ASSERT(NULL != bottom); /* what to do about that? */ if ((NULL != bottom) - && (_PR_FILEDESC_OPEN == bottom->secret->state)) + && (_PR_FILEDESC_OPEN == bottom->secret->state)) { if (0 == ready) { @@ -121,8 +121,9 @@ static PRInt32 NativeThreadPoll( _PR_POLL_WRITE_SYS_WRITE; syspoll[index].events |= POLLOUT; } - if (pds[index].in_flags & PR_POLL_EXCEPT) + if (pds[index].in_flags & PR_POLL_EXCEPT) { syspoll[index].events |= POLLPRI; + } } } else @@ -168,12 +169,18 @@ retry: if (EINTR == oserror) { - if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry; - else if (timeout == PR_INTERVAL_NO_WAIT) ready = 0; + if (timeout == PR_INTERVAL_NO_TIMEOUT) { + goto retry; + } + else if (timeout == PR_INTERVAL_NO_WAIT) { + ready = 0; + } else { elapsed = (PRIntervalTime)(PR_IntervalNow() - start); - if (elapsed > timeout) ready = 0; /* timed out */ + if (elapsed > timeout) { + ready = 0; /* timed out */ + } else { remaining = timeout - elapsed; @@ -182,7 +189,9 @@ retry: } } } - else _PR_MD_MAP_POLL_ERROR(oserror); + else { + _PR_MD_MAP_POLL_ERROR(oserror); + } } else if (ready > 0) { @@ -203,12 +212,12 @@ retry: if (syspoll[index].revents & POLLIN) { if (pds[index].out_flags - & _PR_POLL_READ_SYS_READ) + & _PR_POLL_READ_SYS_READ) { out_flags |= PR_POLL_READ; } if (pds[index].out_flags - & _PR_POLL_WRITE_SYS_READ) + & _PR_POLL_WRITE_SYS_READ) { out_flags |= PR_POLL_WRITE; } @@ -216,24 +225,28 @@ retry: if (syspoll[index].revents & POLLOUT) { if (pds[index].out_flags - & _PR_POLL_READ_SYS_WRITE) + & _PR_POLL_READ_SYS_WRITE) { out_flags |= PR_POLL_READ; } if (pds[index].out_flags - & _PR_POLL_WRITE_SYS_WRITE) + & _PR_POLL_WRITE_SYS_WRITE) { out_flags |= PR_POLL_WRITE; } } - if (syspoll[index].revents & POLLPRI) + if (syspoll[index].revents & POLLPRI) { out_flags |= PR_POLL_EXCEPT; - if (syspoll[index].revents & POLLERR) + } + if (syspoll[index].revents & POLLERR) { out_flags |= PR_POLL_ERR; - if (syspoll[index].revents & POLLNVAL) + } + if (syspoll[index].revents & POLLNVAL) { out_flags |= PR_POLL_NVAL; - if (syspoll[index].revents & POLLHUP) + } + if (syspoll[index].revents & POLLHUP) { out_flags |= PR_POLL_HUP; + } } } pds[index].out_flags = out_flags; @@ -277,15 +290,15 @@ static PRInt32 NativeThreadSelect( if (pd->in_flags & PR_POLL_READ) { in_flags_read = (pd->fd->methods->poll)( - pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); + pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); } if (pd->in_flags & PR_POLL_WRITE) { in_flags_write = (pd->fd->methods->poll)( - pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); + pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); } if ((0 != (in_flags_read & out_flags_read)) - || (0 != (in_flags_write & out_flags_write))) + || (0 != (in_flags_write & out_flags_write))) { /* this one's ready right now */ if (0 == ready) @@ -313,12 +326,14 @@ static PRInt32 NativeThreadSelect( bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER); PR_ASSERT(NULL != bottom); /* what to do about that? */ if ((NULL != bottom) - && (_PR_FILEDESC_OPEN == bottom->secret->state)) + && (_PR_FILEDESC_OPEN == bottom->secret->state)) { if (0 == ready) { PRInt32 osfd = bottom->secret->md.osfd; - if (osfd > maxfd) maxfd = osfd; + if (osfd > maxfd) { + maxfd = osfd; + } if (in_flags_read & PR_POLL_READ) { pd->out_flags |= _PR_POLL_READ_SYS_READ; @@ -339,7 +354,9 @@ static PRInt32 NativeThreadSelect( pd->out_flags |= _PR_POLL_WRITE_SYS_WRITE; FD_SET(osfd, &wt); } - if (pd->in_flags & PR_POLL_EXCEPT) FD_SET(osfd, &ex); + if (pd->in_flags & PR_POLL_EXCEPT) { + FD_SET(osfd, &ex); + } } } else @@ -363,7 +380,9 @@ static PRInt32 NativeThreadSelect( } } - if (0 != ready) return ready; /* no need to block */ + if (0 != ready) { + return ready; /* no need to block */ + } remaining = timeout; start = PR_IntervalNow(); @@ -381,11 +400,15 @@ retry: if (ready == -1 && errno == EINTR) { - if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry; + if (timeout == PR_INTERVAL_NO_TIMEOUT) { + goto retry; + } else { elapsed = (PRIntervalTime) (PR_IntervalNow() - start); - if (elapsed > timeout) ready = 0; /* timed out */ + if (elapsed > timeout) { + ready = 0; /* timed out */ + } else { remaining = timeout - elapsed; @@ -415,22 +438,30 @@ retry: if (FD_ISSET(osfd, &rd)) { - if (pd->out_flags & _PR_POLL_READ_SYS_READ) + if (pd->out_flags & _PR_POLL_READ_SYS_READ) { out_flags |= PR_POLL_READ; - if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) + } + if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) { out_flags |= PR_POLL_WRITE; - } + } + } if (FD_ISSET(osfd, &wt)) { - if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) + if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) { out_flags |= PR_POLL_READ; - if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) + } + if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) { out_flags |= PR_POLL_WRITE; - } - if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT; + } + } + if (FD_ISSET(osfd, &ex)) { + out_flags |= PR_POLL_EXCEPT; + } } pd->out_flags = out_flags; - if (out_flags) ready++; + if (out_flags) { + ready++; + } } PR_ASSERT(ready > 0); } @@ -456,7 +487,9 @@ retry: } PR_ASSERT(ready > 0); } - else _PR_MD_MAP_SELECT_ERROR(err); + else { + _PR_MD_MAP_SELECT_ERROR(err); + } } return ready; @@ -484,7 +517,7 @@ static PRInt32 LocalThreads( */ unixpd = unixpds = (_PRUnixPollDesc*) - PR_MALLOC(npds * sizeof(_PRUnixPollDesc)); + PR_MALLOC(npds * sizeof(_PRUnixPollDesc)); if (NULL == unixpds) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); @@ -503,15 +536,15 @@ static PRInt32 LocalThreads( if (pd->in_flags & PR_POLL_READ) { in_flags_read = (pd->fd->methods->poll)( - pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); + pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); } if (pd->in_flags & PR_POLL_WRITE) { in_flags_write = (pd->fd->methods->poll)( - pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); + pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); } if ((0 != (in_flags_read & out_flags_read)) - || (0 != (in_flags_write & out_flags_write))) + || (0 != (in_flags_write & out_flags_write))) { /* this one's ready right now */ if (0 == ready) @@ -537,7 +570,7 @@ static PRInt32 LocalThreads( bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER); PR_ASSERT(NULL != bottom); /* what to do about that? */ if ((NULL != bottom) - && (_PR_FILEDESC_OPEN == bottom->secret->state)) + && (_PR_FILEDESC_OPEN == bottom->secret->state)) { if (0 == ready) { @@ -614,26 +647,34 @@ static PRInt32 LocalThreads( { if (unixpd->out_flags & _PR_UNIX_POLL_READ) { - if (pd->out_flags & _PR_POLL_READ_SYS_READ) + if (pd->out_flags & _PR_POLL_READ_SYS_READ) { out_flags |= PR_POLL_READ; - if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) + } + if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) { out_flags |= PR_POLL_WRITE; + } } if (unixpd->out_flags & _PR_UNIX_POLL_WRITE) { - if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) + if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) { out_flags |= PR_POLL_READ; - if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) + } + if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) { out_flags |= PR_POLL_WRITE; + } } - if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT) + if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT) { out_flags |= PR_POLL_EXCEPT; - if (unixpd->out_flags & _PR_UNIX_POLL_ERR) + } + if (unixpd->out_flags & _PR_UNIX_POLL_ERR) { out_flags |= PR_POLL_ERR; - if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) + } + if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) { out_flags |= PR_POLL_NVAL; - if (unixpd->out_flags & _PR_UNIX_POLL_HUP) + } + if (unixpd->out_flags & _PR_UNIX_POLL_HUP) { out_flags |= PR_POLL_HUP; + } } unixpd++; } @@ -662,15 +703,20 @@ PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0); return -1; } - if (0 == npds) PR_Sleep(timeout); - else if (_PR_IS_NATIVE_THREAD(me)) + if (0 == npds) { + PR_Sleep(timeout); + } + else if (_PR_IS_NATIVE_THREAD(me)) { rv = NativeThreads(pds, npds, timeout); - else rv = LocalThreads(pds, npds, timeout); + } + else { + rv = LocalThreads(pds, npds, timeout); + } return rv; } /* _MD_pr_poll */ -#endif /* defined(_PR_PTHREADS) */ +#endif /* defined(_PR_PTHREADS) */ /* uxpoll.c */ diff --git a/nsprpub/pr/src/md/unix/uxproces.c b/nsprpub/pr/src/md/unix/uxproces.c index 18f23fde8..4216c0442 100644 --- a/nsprpub/pr/src/md/unix/uxproces.c +++ b/nsprpub/pr/src/md/unix/uxproces.c @@ -55,11 +55,10 @@ typedef struct pr_PidRecord { } pr_PidRecord; /* - * Irix sprocs and LinuxThreads are actually a kind of processes + * LinuxThreads are actually a kind of processes * that can share the virtual address space and file descriptors. */ -#if (defined(IRIX) && !defined(_PR_PTHREADS)) \ - || ((defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)) \ +#if ((defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)) \ && defined(_PR_PTHREADS)) #define _PR_SHARE_CLONES #endif @@ -74,8 +73,8 @@ typedef struct pr_PidRecord { */ #if defined(_PR_GLOBAL_THREADS_ONLY) \ - || (defined(_PR_PTHREADS) \ - && !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__)) + || (defined(_PR_PTHREADS) \ + && !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__)) #define _PR_NATIVE_THREADS #endif @@ -192,7 +191,7 @@ ForkAndExec( #ifdef AIX process->md.pid = (*pr_wp.forkptr)(); -#elif defined(NTO) || defined(SYMBIAN) +#elif defined(NTO) /* * fork() & exec() does not work in a multithreaded process. * Use spawn() instead. @@ -204,38 +203,39 @@ ForkAndExec( if (attr->stdinFd && attr->stdinFd->secret->md.osfd != 0) { fd_map[0] = dup(attr->stdinFd->secret->md.osfd); flags = fcntl(fd_map[0], F_GETFL, 0); - if (flags & O_NONBLOCK) + if (flags & O_NONBLOCK) { fcntl(fd_map[0], F_SETFL, flags & ~O_NONBLOCK); + } } if (attr->stdoutFd && attr->stdoutFd->secret->md.osfd != 1) { fd_map[1] = dup(attr->stdoutFd->secret->md.osfd); flags = fcntl(fd_map[1], F_GETFL, 0); - if (flags & O_NONBLOCK) + if (flags & O_NONBLOCK) { fcntl(fd_map[1], F_SETFL, flags & ~O_NONBLOCK); + } } if (attr->stderrFd && attr->stderrFd->secret->md.osfd != 2) { fd_map[2] = dup(attr->stderrFd->secret->md.osfd); flags = fcntl(fd_map[2], F_GETFL, 0); - if (flags & O_NONBLOCK) + if (flags & O_NONBLOCK) { fcntl(fd_map[2], F_SETFL, flags & ~O_NONBLOCK); + } } PR_ASSERT(attr->currentDirectory == NULL); /* not implemented */ } -#ifdef SYMBIAN - /* In Symbian OS, we use posix_spawn instead of fork() and exec() */ - posix_spawn(&(process->md.pid), path, NULL, NULL, argv, childEnvp); -#else process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp); -#endif - if (fd_map[0] != 0) + if (fd_map[0] != 0) { close(fd_map[0]); - if (fd_map[1] != 1) + } + if (fd_map[1] != 1) { close(fd_map[1]); - if (fd_map[2] != 2) + } + if (fd_map[2] != 2) { close(fd_map[2]); + } } #else process->md.pid = fork(); @@ -249,20 +249,20 @@ ForkAndExec( return NULL; } if (0 == process->md.pid) { /* the child process */ - /* - * If the child process needs to exit, it must call _exit(). - * Do not call exit(), because exit() will flush and close - * the standard I/O file descriptors, and hence corrupt - * the parent process's standard I/O data structures. - */ - -#if !defined(NTO) && !defined(SYMBIAN) + /* + * If the child process needs to exit, it must call _exit(). + * Do not call exit(), because exit() will flush and close + * the standard I/O file descriptors, and hence corrupt + * the parent process's standard I/O data structures. + */ + +#if !defined(NTO) if (attr) { /* the osfd's to redirect stdin, stdout, and stderr to */ int in_osfd = -1, out_osfd = -1, err_osfd = -1; if (attr->stdinFd - && attr->stdinFd->secret->md.osfd != 0) { + && attr->stdinFd->secret->md.osfd != 0) { in_osfd = attr->stdinFd->secret->md.osfd; if (dup2(in_osfd, 0) != 0) { _exit(1); /* failed */ @@ -273,7 +273,7 @@ ForkAndExec( } } if (attr->stdoutFd - && attr->stdoutFd->secret->md.osfd != 1) { + && attr->stdoutFd->secret->md.osfd != 1) { out_osfd = attr->stdoutFd->secret->md.osfd; if (dup2(out_osfd, 1) != 1) { _exit(1); /* failed */ @@ -284,7 +284,7 @@ ForkAndExec( } } if (attr->stderrFd - && attr->stderrFd->secret->md.osfd != 2) { + && attr->stderrFd->secret->md.osfd != 2) { err_osfd = attr->stderrFd->secret->md.osfd; if (dup2(err_osfd, 2) != 2) { _exit(1); /* failed */ @@ -301,7 +301,7 @@ ForkAndExec( close(out_osfd); } if (err_osfd != -1 && err_osfd != in_osfd - && err_osfd != out_osfd) { + && err_osfd != out_osfd) { close(err_osfd); } if (attr->currentDirectory) { @@ -363,13 +363,13 @@ _MD_CreateUnixProcess( int rv; if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) { - return NULL; + return NULL; } op = PR_NEW(struct pr_CreateProcOp); if (NULL == op) { - PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); - return NULL; + PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); + return NULL; } op->path = path; op->argv = argv; @@ -378,19 +378,19 @@ _MD_CreateUnixProcess( op->done = PR_FALSE; op->doneCV = PR_NewCondVar(pr_wp.ml); if (NULL == op->doneCV) { - PR_DELETE(op); - return NULL; + PR_DELETE(op); + return NULL; } PR_Lock(pr_wp.ml); /* add to the tail of op queue */ op->next = NULL; if (pr_wp.opTail) { - pr_wp.opTail->next = op; - pr_wp.opTail = op; + pr_wp.opTail->next = op; + pr_wp.opTail = op; } else { - PR_ASSERT(NULL == pr_wp.opHead); - pr_wp.opHead = pr_wp.opTail = op; + PR_ASSERT(NULL == pr_wp.opHead); + pr_wp.opHead = pr_wp.opTail = op; } /* wake up the daemon thread */ @@ -399,13 +399,13 @@ _MD_CreateUnixProcess( } while (-1 == rv && EINTR == errno); while (op->done == PR_FALSE) { - PR_WaitCondVar(op->doneCV, PR_INTERVAL_NO_TIMEOUT); + PR_WaitCondVar(op->doneCV, PR_INTERVAL_NO_TIMEOUT); } PR_Unlock(pr_wp.ml); PR_DestroyCondVar(op->doneCV); proc = op->process; if (!proc) { - PR_SetError(op->prerror, op->oserror); + PR_SetError(op->prerror, op->oserror); } PR_DELETE(op); return proc; @@ -421,7 +421,7 @@ _MD_CreateUnixProcess( const PRProcessAttr *attr) { if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) { - return NULL; + return NULL; } return ForkAndExec(path, argv, envp, attr); } /* _MD_CreateUnixProcess */ @@ -445,10 +445,10 @@ FindPidTable(pid_t pid) pRec = pr_wp.pidTable[keyHash]; while (pRec) { - if (pRec->pid == pid) { - break; - } - pRec = pRec->next; + if (pRec->pid == pid) { + break; + } + pRec = pRec->next; } return pRec; } @@ -468,21 +468,21 @@ DeletePidTable(pr_PidRecord *pRec) int keyHash = (int) (pRec->pid & PID_HASH_MASK); if (pr_wp.pidTable[keyHash] == pRec) { - pr_wp.pidTable[keyHash] = pRec->next; + pr_wp.pidTable[keyHash] = pRec->next; } else { - pr_PidRecord *pred, *cur; /* predecessor and current */ - - pred = pr_wp.pidTable[keyHash]; - cur = pred->next; - while (cur) { - if (cur == pRec) { - pred->next = cur->next; - break; + pr_PidRecord *pred, *cur; /* predecessor and current */ + + pred = pr_wp.pidTable[keyHash]; + cur = pred->next; + while (cur) { + if (cur == pRec) { + pred->next = cur->next; + break; } - pred = cur; - cur = cur->next; + pred = cur; + cur = cur->next; } - PR_ASSERT(cur != NULL); + PR_ASSERT(cur != NULL); } } @@ -498,10 +498,10 @@ ExtractExitStatus(int rawExitStatus) PR_ASSERT(!WIFCONTINUED(rawExitStatus)); #endif if (WIFEXITED(rawExitStatus)) { - return WEXITSTATUS(rawExitStatus); + return WEXITSTATUS(rawExitStatus); } - PR_ASSERT(WIFSIGNALED(rawExitStatus)); - return _PR_SIGNALED_EXITSTATUS; + PR_ASSERT(WIFSIGNALED(rawExitStatus)); + return _PR_SIGNALED_EXITSTATUS; } static void @@ -553,16 +553,16 @@ static void WaitPidDaemonThread(void *unused) } PR_Unlock(pr_wp.ml); - while (1) { - do { - pid = waitpid((pid_t) -1, &status, 0); - } while ((pid_t) -1 == pid && EINTR == errno); + while (1) { + do { + pid = waitpid((pid_t) -1, &status, 0); + } while ((pid_t) -1 == pid && EINTR == errno); /* * waitpid() cannot return 0 because we did not invoke it * with the WNOHANG option. - */ - PR_ASSERT(0 != pid); + */ + PR_ASSERT(0 != pid); /* * The only possible error code is ECHILD. But if we do @@ -570,18 +570,18 @@ static void WaitPidDaemonThread(void *unused) * when there is a child process to wait for. */ PR_ASSERT((pid_t) -1 != pid); - if ((pid_t) -1 == pid) { + if ((pid_t) -1 == pid) { break; } - PR_Lock(pr_wp.ml); + PR_Lock(pr_wp.ml); ProcessReapedChildInternal(pid, status); pr_wp.numProcs--; while (0 == pr_wp.numProcs) { PR_WaitCondVar(pr_wp.cv, PR_INTERVAL_NO_TIMEOUT); } - PR_Unlock(pr_wp.ml); - } + PR_Unlock(pr_wp.ml); + } } } @@ -616,48 +616,50 @@ static void WaitPidDaemonThread(void *unused) if (pr_waitpid_daemon_exit) { return; } - PR_Lock(pr_wp.ml); + PR_Lock(pr_wp.ml); #endif - + do { rv = read(pr_wp.pipefd[0], buf, sizeof(buf)); } while (sizeof(buf) == rv || (-1 == rv && EINTR == errno)); #ifdef _PR_SHARE_CLONES - while ((op = pr_wp.opHead) != NULL) { - PR_Unlock(pr_wp.ml); - op->process = ForkAndExec(op->path, op->argv, - op->envp, op->attr); - if (NULL == op->process) { - op->prerror = PR_GetError(); - op->oserror = PR_GetOSError(); - } - PR_Lock(pr_wp.ml); - pr_wp.opHead = op->next; - if (NULL == pr_wp.opHead) { - pr_wp.opTail = NULL; - } - op->done = PR_TRUE; - PR_NotifyCondVar(op->doneCV); - } - PR_Unlock(pr_wp.ml); + while ((op = pr_wp.opHead) != NULL) { + PR_Unlock(pr_wp.ml); + op->process = ForkAndExec(op->path, op->argv, + op->envp, op->attr); + if (NULL == op->process) { + op->prerror = PR_GetError(); + op->oserror = PR_GetOSError(); + } + PR_Lock(pr_wp.ml); + pr_wp.opHead = op->next; + if (NULL == pr_wp.opHead) { + pr_wp.opTail = NULL; + } + op->done = PR_TRUE; + PR_NotifyCondVar(op->doneCV); + } + PR_Unlock(pr_wp.ml); #endif - while (1) { - do { - pid = waitpid((pid_t) -1, &status, WNOHANG); - } while ((pid_t) -1 == pid && EINTR == errno); - if (0 == pid) break; - if ((pid_t) -1 == pid) { - /* must be because we have no child processes */ - PR_ASSERT(ECHILD == errno); - break; + while (1) { + do { + pid = waitpid((pid_t) -1, &status, WNOHANG); + } while ((pid_t) -1 == pid && EINTR == errno); + if (0 == pid) { + break; + } + if ((pid_t) -1 == pid) { + /* must be because we have no child processes */ + PR_ASSERT(ECHILD == errno); + break; } - PR_Lock(pr_wp.ml); + PR_Lock(pr_wp.ml); ProcessReapedChildInternal(pid, status); - PR_Unlock(pr_wp.ml); - } + PR_Unlock(pr_wp.ml); + } } } @@ -740,13 +742,13 @@ static PRStatus _MD_InitProcesses(void) #endif /* !_PR_NATIVE_THREADS */ pr_wp.thread = PR_CreateThread(PR_SYSTEM_THREAD, - WaitPidDaemonThread, NULL, PR_PRIORITY_NORMAL, + WaitPidDaemonThread, NULL, PR_PRIORITY_NORMAL, #ifdef _PR_SHARE_CLONES - PR_GLOBAL_THREAD, + PR_GLOBAL_THREAD, #else - PR_LOCAL_THREAD, + PR_LOCAL_THREAD, #endif - PR_JOINABLE_THREAD, 0); + PR_JOINABLE_THREAD, 0); PR_ASSERT(NULL != pr_wp.thread); pr_wp.pidTable = (pr_PidRecord**)PR_CALLOC(NBUCKETS * sizeof(pr_PidRecord *)); @@ -762,26 +764,26 @@ PRStatus _MD_DetachUnixProcess(PRProcess *process) PR_Lock(pr_wp.ml); pRec = FindPidTable(process->md.pid); if (NULL == pRec) { - pRec = PR_NEW(pr_PidRecord); - if (NULL == pRec) { - PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); - retVal = PR_FAILURE; - goto done; - } - pRec->pid = process->md.pid; - pRec->state = _PR_PID_DETACHED; - pRec->reapedCV = NULL; - InsertPidTable(pRec); + pRec = PR_NEW(pr_PidRecord); + if (NULL == pRec) { + PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); + retVal = PR_FAILURE; + goto done; + } + pRec->pid = process->md.pid; + pRec->state = _PR_PID_DETACHED; + pRec->reapedCV = NULL; + InsertPidTable(pRec); } else { - PR_ASSERT(_PR_PID_REAPED == pRec->state); - if (_PR_PID_REAPED != pRec->state) { - PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); - retVal = PR_FAILURE; - } else { - DeletePidTable(pRec); - PR_ASSERT(NULL == pRec->reapedCV); - PR_DELETE(pRec); - } + PR_ASSERT(_PR_PID_REAPED == pRec->state); + if (_PR_PID_REAPED != pRec->state) { + PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); + retVal = PR_FAILURE; + } else { + DeletePidTable(pRec); + PR_ASSERT(NULL == pRec->reapedCV); + PR_DELETE(pRec); + } } PR_DELETE(process); @@ -801,47 +803,47 @@ PRStatus _MD_WaitUnixProcess( PR_Lock(pr_wp.ml); pRec = FindPidTable(process->md.pid); if (NULL == pRec) { - pRec = PR_NEW(pr_PidRecord); - if (NULL == pRec) { - PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); - retVal = PR_FAILURE; - goto done; - } - pRec->pid = process->md.pid; - pRec->state = _PR_PID_WAITING; - pRec->reapedCV = PR_NewCondVar(pr_wp.ml); - if (NULL == pRec->reapedCV) { - PR_DELETE(pRec); - retVal = PR_FAILURE; - goto done; - } - InsertPidTable(pRec); - while (!interrupted && _PR_PID_REAPED != pRec->state) { - if (PR_WaitCondVar(pRec->reapedCV, - PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE - && PR_GetError() == PR_PENDING_INTERRUPT_ERROR) { - interrupted = PR_TRUE; + pRec = PR_NEW(pr_PidRecord); + if (NULL == pRec) { + PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); + retVal = PR_FAILURE; + goto done; + } + pRec->pid = process->md.pid; + pRec->state = _PR_PID_WAITING; + pRec->reapedCV = PR_NewCondVar(pr_wp.ml); + if (NULL == pRec->reapedCV) { + PR_DELETE(pRec); + retVal = PR_FAILURE; + goto done; + } + InsertPidTable(pRec); + while (!interrupted && _PR_PID_REAPED != pRec->state) { + if (PR_WaitCondVar(pRec->reapedCV, + PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE + && PR_GetError() == PR_PENDING_INTERRUPT_ERROR) { + interrupted = PR_TRUE; } - } - if (_PR_PID_REAPED == pRec->state) { + } + if (_PR_PID_REAPED == pRec->state) { if (exitCode) { *exitCode = pRec->exitStatus; } - } else { - PR_ASSERT(interrupted); - retVal = PR_FAILURE; - } - DeletePidTable(pRec); - PR_DestroyCondVar(pRec->reapedCV); - PR_DELETE(pRec); + } else { + PR_ASSERT(interrupted); + retVal = PR_FAILURE; + } + DeletePidTable(pRec); + PR_DestroyCondVar(pRec->reapedCV); + PR_DELETE(pRec); } else { - PR_ASSERT(_PR_PID_REAPED == pRec->state); - PR_ASSERT(NULL == pRec->reapedCV); - DeletePidTable(pRec); + PR_ASSERT(_PR_PID_REAPED == pRec->state); + PR_ASSERT(NULL == pRec->reapedCV); + DeletePidTable(pRec); if (exitCode) { *exitCode = pRec->exitStatus; } - PR_DELETE(pRec); + PR_DELETE(pRec); } PR_DELETE(process); @@ -855,27 +857,21 @@ PRStatus _MD_KillUnixProcess(PRProcess *process) PRErrorCode prerror; PRInt32 oserror; -#ifdef SYMBIAN - /* In Symbian OS, we can not kill other process with Open C */ - PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, oserror); - return PR_FAILURE; -#else if (kill(process->md.pid, SIGKILL) == 0) { - return PR_SUCCESS; + return PR_SUCCESS; } oserror = errno; switch (oserror) { case EPERM: - prerror = PR_NO_ACCESS_RIGHTS_ERROR; - break; + prerror = PR_NO_ACCESS_RIGHTS_ERROR; + break; case ESRCH: - prerror = PR_INVALID_ARGUMENT_ERROR; - break; + prerror = PR_INVALID_ARGUMENT_ERROR; + break; default: - prerror = PR_UNKNOWN_ERROR; - break; + prerror = PR_UNKNOWN_ERROR; + break; } PR_SetError(prerror, oserror); return PR_FAILURE; -#endif } /* _MD_KillUnixProcess */ diff --git a/nsprpub/pr/src/md/unix/uxrng.c b/nsprpub/pr/src/md/unix/uxrng.c index da2f7e9fe..479859000 100644 --- a/nsprpub/pr/src/md/unix/uxrng.c +++ b/nsprpub/pr/src/md/unix/uxrng.c @@ -20,7 +20,7 @@ GetHighResClock(void *buf, size_t maxbytes) hrtime_t t; t = gethrtime(); if (t) { - return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t)); + return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t)); } return 0; } @@ -54,28 +54,6 @@ GetHighResClock(void *buf, size_t maxbytes) } #endif -#elif defined(OSF1) - -#include <c_asm.h> - -/* - * Use the "get the cycle counter" instruction on the alpha. - * The low 32 bits completely turn over in less than a minute. - * The high 32 bits are some non-counter gunk that changes sometimes. - */ -static size_t -GetHighResClock(void *buf, size_t maxbytes) -{ - unsigned long t; - -#ifdef __GNUC__ - __asm__("rpcc %0" : "=r" (t)); -#else - t = asm("rpcc %v0"); -#endif - return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t)); -} - #elif defined(AIX) static size_t @@ -86,7 +64,7 @@ GetHighResClock(void *buf, size_t maxbytes) #elif (defined(LINUX) || defined(FREEBSD) || defined(__FreeBSD_kernel__) \ || defined(NETBSD) || defined(__NetBSD_kernel__) || defined(OPENBSD) \ - || defined(SYMBIAN) || defined(__GNU__)) + || defined(__GNU__)) #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -122,91 +100,8 @@ static size_t GetDevURandom( void *buf, size_t size ) static size_t GetHighResClock(void *buf, size_t maxbytes) -{ - return(GetDevURandom( buf, maxbytes )); -} - -#elif defined(IRIX) -#include <fcntl.h> -#undef PRIVATE -#include <sys/mman.h> -#include <sys/syssgi.h> -#include <sys/immu.h> -#include <sys/systeminfo.h> -#include <sys/utsname.h> - -static size_t GetHighResClock(void *buf, size_t maxbuf) { - unsigned phys_addr, raddr, cycleval; - static volatile unsigned *iotimer_addr = NULL; - static int tries = 0; - static int cntr_size; - int mfd; - unsigned s0[2]; - -#ifndef SGI_CYCLECNTR_SIZE -#define SGI_CYCLECNTR_SIZE 165 /* Size user needs to use to read CC */ -#endif - - if (iotimer_addr == NULL) { - if (tries++ > 1) { - /* Don't keep trying if it didn't work */ - return 0; - } - - /* - ** For SGI machines we can use the cycle counter, if it has one, - ** to generate some truly random numbers - */ - phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval); - if (phys_addr) { - int pgsz = getpagesize(); - int pgoffmask = pgsz - 1; - - raddr = phys_addr & ~pgoffmask; - mfd = open("/dev/mmem", O_RDONLY); - if (mfd < 0) { - return 0; - } - iotimer_addr = (unsigned *) - mmap(0, pgoffmask, PROT_READ, MAP_PRIVATE, mfd, (int)raddr); - if (iotimer_addr == (unsigned*)-1) { - close(mfd); - iotimer_addr = NULL; - return 0; - } - iotimer_addr = (unsigned*) - ((__psint_t)iotimer_addr | (phys_addr & pgoffmask)); - /* - * The file 'mfd' is purposefully not closed. - */ - cntr_size = syssgi(SGI_CYCLECNTR_SIZE); - if (cntr_size < 0) { - struct utsname utsinfo; - - /* - * We must be executing on a 6.0 or earlier system, since the - * SGI_CYCLECNTR_SIZE call is not supported. - * - * The only pre-6.1 platforms with 64-bit counters are - * IP19 and IP21 (Challenge, PowerChallenge, Onyx). - */ - uname(&utsinfo); - if (!strncmp(utsinfo.machine, "IP19", 4) || - !strncmp(utsinfo.machine, "IP21", 4)) - cntr_size = 64; - else - cntr_size = 32; - } - cntr_size /= 8; /* Convert from bits to bytes */ - } - } - - s0[0] = *iotimer_addr; - if (cntr_size > 4) - s0[1] = *(iotimer_addr + 1); - memcpy(buf, (char *)&s0[0], cntr_size); - return _pr_CopyLowBits(buf, maxbuf, &s0, cntr_size); + return(GetDevURandom( buf, maxbytes )); } #elif defined(SCO) || defined(UNIXWARE) || defined(BSDI) || defined(NTO) \ diff --git a/nsprpub/pr/src/md/unix/uxshm.c b/nsprpub/pr/src/md/unix/uxshm.c index 54e68191c..29a6030f4 100644 --- a/nsprpub/pr/src/md/unix/uxshm.c +++ b/nsprpub/pr/src/md/unix/uxshm.c @@ -14,7 +14,7 @@ #include <prshm.h> #include <prerr.h> #include <prmem.h> -#include "primpl.h" +#include "primpl.h" #include <fcntl.h> extern PRLogModuleInfo *_pr_shm_lm; @@ -36,7 +36,7 @@ extern PRLogModuleInfo *_pr_shm_lm; #define _MD_CLOSE_SHARED_MEMORY _MD_CloseSharedMemory #define _MD_DELETE_SHARED_MEMORY _MD_DeleteSharedMemory -extern PRSharedMemory * _MD_OpenSharedMemory( +extern PRSharedMemory * _MD_OpenSharedMemory( const char *name, PRSize size, PRIntn flags, @@ -52,16 +52,16 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( PR_FAILURE == rc ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return( NULL ); } shm = PR_NEWZAP( PRSharedMemory ); - if ( NULL == shm ) + if ( NULL == shm ) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); return( NULL ); } @@ -69,7 +69,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( NULL == shm->ipcname ) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); PR_DELETE( shm ); return( NULL ); } @@ -89,7 +89,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( PR_FREEIF( shm->ipcname ); PR_DELETE( shm ); return( NULL ); - } + } if ( close(osfd) == -1 ) { _PR_MD_MAP_CLOSE_ERROR( errno ); PR_FREEIF( shm->ipcname ); @@ -104,8 +104,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory( { rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname)); PR_FREEIF( shm->ipcname ); PR_DELETE( shm ); return( NULL ); @@ -119,19 +119,19 @@ extern PRSharedMemory * _MD_OpenSharedMemory( } if ((errno == EEXIST) && (flags & PR_SHM_EXCL)) { PR_SetError( PR_FILE_EXISTS_ERROR, errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno)); PR_FREEIF(shm->ipcname); PR_DELETE(shm); return(NULL); } - } + } shm->id = shmget( key, shm->size, shm->mode ); if ( -1 == shm->id ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno)); PR_FREEIF(shm->ipcname); PR_DELETE(shm); return(NULL); @@ -153,14 +153,14 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags ) if ( (void*)-1 == addr ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d", - shm->ipcname, PR_GetOSError() )); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d", + shm->ipcname, PR_GetOSError() )); addr = NULL; } return addr; -} +} extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) { @@ -174,12 +174,12 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) { rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname )); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname )); } return rc; -} +} extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ) { @@ -189,7 +189,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ) PR_DELETE(shm); return PR_SUCCESS; -} +} extern PRStatus _MD_DeleteSharedMemory( const char *name ) { @@ -202,19 +202,19 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm ); if ( PR_FAILURE == rc ) { - PR_SetError( PR_UNKNOWN_ERROR , errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + PR_SetError( PR_UNKNOWN_ERROR, errno ); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return(PR_FAILURE); } - /* create the file first */ + /* create the file first */ { int osfd = open( ipcname, (O_RDWR | O_CREAT), 0666 ); if ( -1 == osfd ) { _PR_MD_MAP_OPEN_ERROR( errno ); return( PR_FAILURE ); - } + } if ( close(osfd) == -1 ) { _PR_MD_MAP_CLOSE_ERROR( errno ); return( PR_FAILURE ); @@ -227,20 +227,15 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) { rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname)); } -#ifdef SYMBIAN - /* In Symbian OS the system imposed minimum is 1 byte, instead of ZERO */ - id = shmget( key, 1, 0 ); -#else id = shmget( key, 0, 0 ); -#endif if ( -1 == id ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno)); return(PR_FAILURE); } @@ -248,16 +243,16 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) if ( -1 == urc ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname )); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname )); return(PR_FAILURE); } urc = unlink( ipcname ); if ( -1 == urc ) { _PR_MD_MAP_UNLINK_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname )); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname )); return(PR_FAILURE); } @@ -280,7 +275,7 @@ struct _MDSharedMemory { int handle; }; -extern PRSharedMemory * _MD_OpenSharedMemory( +extern PRSharedMemory * _MD_OpenSharedMemory( const char *name, PRSize size, PRIntn flags, @@ -295,17 +290,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory( rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm ); if ( PR_FAILURE == rc ) { - PR_SetError( PR_UNKNOWN_ERROR , errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + PR_SetError( PR_UNKNOWN_ERROR, errno ); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return( NULL ); } shm = PR_NEWZAP( PRSharedMemory ); - if ( NULL == shm ) + if ( NULL == shm ) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); return( NULL ); } @@ -313,13 +308,13 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( NULL == shm->ipcname ) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); return( NULL ); } /* copy args to struct */ strcpy( shm->ipcname, ipcname ); - shm->size = size; + shm->size = size; shm->mode = mode; shm->flags = flags; shm->ident = _PR_SHM_IDENT; @@ -329,9 +324,10 @@ extern PRSharedMemory * _MD_OpenSharedMemory( */ if ( flags & PR_SHM_CREATE ) { int oflag = (O_CREAT | O_RDWR); - - if ( flags & PR_SHM_EXCL ) + + if ( flags & PR_SHM_EXCL ) { oflag |= O_EXCL; + } shm->id = shm_open( shm->ipcname, oflag, shm->mode ); } else { shm->id = shm_open( shm->ipcname, O_RDWR, shm->mode ); @@ -339,9 +335,9 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( -1 == shm->id ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d", - shm->ipcname, PR_GetOSError())); + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d", + shm->ipcname, PR_GetOSError())); PR_DELETE( shm->ipcname ); PR_DELETE( shm ); return(NULL); @@ -350,8 +346,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory( end = ftruncate( shm->id, shm->size ); if ( -1 == end ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", + PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", PR_GetOSError())); PR_DELETE( shm->ipcname ); PR_DELETE( shm ); @@ -368,24 +364,25 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags ) PR_ASSERT( shm->ident == _PR_SHM_IDENT ); - if ( PR_SHM_READONLY == flags) + if ( PR_SHM_READONLY == flags) { prot ^= PROT_WRITE; + } addr = mmap( (void*)0, shm->size, prot, MAP_SHARED, shm->id, 0 ); if ((void*)-1 == addr ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", - shm->ipcname, PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", + shm->ipcname, PR_GetOSError())); addr = NULL; } else { - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr)); } - + return addr; -} +} extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) { @@ -399,30 +396,30 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) { rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", - shm->ipcname, PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", + shm->ipcname, PR_GetOSError())); } return rc; -} +} extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ) { int urc; - + PR_ASSERT( shm->ident == _PR_SHM_IDENT ); urc = close( shm->id ); if ( -1 == urc ) { _PR_MD_MAP_CLOSE_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError())); return(PR_FAILURE); } PR_DELETE( shm->ipcname ); PR_DELETE( shm ); return PR_SUCCESS; -} +} extern PRStatus _MD_DeleteSharedMemory( const char *name ) { @@ -433,9 +430,9 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm ); if ( PR_FAILURE == rc ) { - PR_SetError( PR_UNKNOWN_ERROR , errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + PR_SetError( PR_UNKNOWN_ERROR, errno ); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return rc; } @@ -443,12 +440,12 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) if ( -1 == urc ) { rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d", - ipcname, PR_GetOSError())); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d", + ipcname, PR_GetOSError())); } else { - PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): %s, success", ipcname)); + PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, + ("_MD_DeleteSharedMemory(): %s, success", ipcname)); } return rc; @@ -464,7 +461,7 @@ extern PRLogModuleInfo *_pr_shma_lm; #include <unistd.h> -extern PRFileMap* _md_OpenAnonFileMap( +extern PRFileMap* _md_OpenAnonFileMap( const char *dirName, PRSize size, PRFileMapProtect prot @@ -488,100 +485,90 @@ extern PRFileMap* _md_OpenAnonFileMap( ** make maxTries number of attempts at uniqueness in the filename */ for ( incr = 0; incr < maxTries ; incr++ ) { -#if defined(SYMBIAN) -#define NSPR_AFM_FILENAME "%s\\NSPR-AFM-%d-%p.%d" -#else #define NSPR_AFM_FILENAME "%s/.NSPR-AFM-%d-%p.%d" -#endif genName = PR_smprintf( NSPR_AFM_FILENAME, - dirName, (int) pid, tid, incr ); + dirName, (int) pid, tid, incr ); if ( NULL == genName ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename")); + ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename")); goto Finished; } /* create the file */ osfd = open(genName, (O_CREAT | O_EXCL | O_RDWR), mode); if (-1 == osfd) { - if (EEXIST == errno) { + if (EEXIST == errno) { + PR_smprintf_free(genName); + continue; /* name exists, try again */ + } + _PR_MD_MAP_OPEN_ERROR(errno); + PR_LOG( + _pr_shma_lm, + PR_LOG_DEBUG, + ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d", + genName, + PR_GetOSError())); PR_smprintf_free(genName); - continue; /* name exists, try again */ - } - _PR_MD_MAP_OPEN_ERROR(errno); - PR_LOG( - _pr_shma_lm, - PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d", - genName, - PR_GetOSError())); - PR_smprintf_free(genName); - goto Finished; + goto Finished; } break; /* name generation and open successful, break; */ } /* end for() */ if (incr == maxTries) { - PR_ASSERT(-1 == osfd); - PR_ASSERT(EEXIST == errno); - _PR_MD_MAP_OPEN_ERROR(errno); - goto Finished; + PR_ASSERT(-1 == osfd); + PR_ASSERT(EEXIST == errno); + _PR_MD_MAP_OPEN_ERROR(errno); + goto Finished; } urc = unlink( genName ); -#if defined(SYMBIAN) && defined(__WINS__) - /* If it is being used by the system or another process, Symbian OS - * Emulator(WINS) considers this an error. */ - if ( -1 == urc && EACCES != errno ) { -#else if ( -1 == urc ) { -#endif _PR_MD_MAP_UNLINK_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno)); + ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno)); PR_smprintf_free( genName ); close( osfd ); - goto Finished; + goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): unlink(): %s", genName )); + ("_md_OpenAnonFileMap(): unlink(): %s", genName )); PR_smprintf_free( genName ); fd = PR_ImportFile( osfd ); if ( NULL == fd ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_ImportFile(): failed")); - goto Finished; + ("_md_OpenAnonFileMap(): PR_ImportFile(): failed")); + goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): fd: %p", fd )); + ("_md_OpenAnonFileMap(): fd: %p", fd )); urc = ftruncate( fd->secret->md.osfd, size ); if ( -1 == urc ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno)); + ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno)); PR_Close( fd ); - goto Finished; + goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size )); + ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size )); LL_UI2L(size64, size); /* PRSize (size_t) is unsigned */ fm = PR_CreateFileMap( fd, size64, prot ); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("PR_OpenAnonFileMap(): failed")); + ("PR_OpenAnonFileMap(): failed")); PR_Close( fd ); - goto Finished; + goto Finished; } fm->md.isAnonFM = PR_TRUE; /* set fd close */ PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm )); + ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm )); -Finished: +Finished: return(fm); } /* end md_OpenAnonFileMap() */ @@ -598,10 +585,10 @@ extern PRStatus _md_ExportFileMapAsString( { PRIntn written; PRIntn prot = (PRIntn)fm->prot; - + written = PR_snprintf( buf, bufSize, "%ld:%d", - fm->fd->secret->md.osfd, prot ); - + fm->fd->secret->md.osfd, prot ); + return((written == -1)? PR_FAILURE : PR_SUCCESS); } /* end _md_ExportFileMapAsString() */ @@ -623,21 +610,21 @@ extern PRFileMap * _md_ImportFileMapFromString( fd = PR_ImportFile( osfd ); if ( NULL == fd ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_ImportFile() failed")); + ("_md_ImportFileMapFromString(): PR_ImportFile() failed")); goto Finished; } rc = PR_GetOpenFileInfo64( fd, &info ); if ( PR_FAILURE == rc ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed")); + ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed")); goto Finished; } fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot ); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed")); + ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed")); } Finished: diff --git a/nsprpub/pr/src/md/unix/uxwrap.c b/nsprpub/pr/src/md/unix/uxwrap.c index 3f8e149ef..d6f6d0621 100644 --- a/nsprpub/pr/src/md/unix/uxwrap.c +++ b/nsprpub/pr/src/md/unix/uxwrap.c @@ -18,30 +18,25 @@ /* Do not wrap select() and poll(). */ #else /* defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) */ /* The include files for select() */ -#ifdef IRIX -#include <unistd.h> -#include <bstring.h> -#endif - #include <string.h> #include <sys/types.h> #include <sys/time.h> -#define ZAP_SET(_to, _width) \ - PR_BEGIN_MACRO \ - memset(_to, 0, \ - ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \ - * sizeof(int) \ - ); \ +#define ZAP_SET(_to, _width) \ + PR_BEGIN_MACRO \ + memset(_to, 0, \ + ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \ + * sizeof(int) \ + ); \ PR_END_MACRO /* see comments in ns/cmd/xfe/mozilla.c (look for "PR_XGetXtHackFD") */ static int _pr_xt_hack_fd = -1; - + int PR_XGetXtHackFD(void) { int fds[2]; - + if (_pr_xt_hack_fd == -1) { if (!pipe(fds)) { _pr_xt_hack_fd = fds[0]; @@ -54,7 +49,7 @@ static int (*_pr_xt_hack_okayToReleaseXLock)(void) = 0; void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void)) { - _pr_xt_hack_okayToReleaseXLock = fn; + _pr_xt_hack_okayToReleaseXLock = fn; } @@ -72,10 +67,10 @@ void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void)) int select(size_t width, int *rl, int *wl, int *el, const struct timeval *tv) #elif defined(AIX_RENAME_SELECT) int wrap_select(unsigned long width, void *rl, void *wl, void *el, - struct timeval *tv) + struct timeval *tv) #elif defined(_PR_SELECT_CONST_TIMEVAL) int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, - const struct timeval *tv) + const struct timeval *tv) #else int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) #endif @@ -108,10 +103,10 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) if (!_pr_initialized) { _PR_ImplicitInitialization(); } - + #ifndef _PR_LOCAL_THREADS_ONLY if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) { - return _MD_SELECT(width, rd, wr, ex, tv); + return _MD_SELECT(width, rd, wr, ex, tv); } #endif @@ -127,7 +122,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) * from the select() man pages. */ if (tv->tv_sec < 0 || tv->tv_sec > 100000000 - || tv->tv_usec < 0 || tv->tv_usec >= 1000000) { + || tv->tv_usec < 0 || tv->tv_usec >= 1000000) { errno = EINVAL; return -1; } @@ -187,31 +182,37 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) * see comments in mozilla/cmd/xfe/mozilla.c (look for * "PR_XGetXtHackFD") */ - { - int needToLockXAgain; - - needToLockXAgain = 0; - if (rd && (_pr_xt_hack_fd != -1) - && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked() - && (!_pr_xt_hack_okayToReleaseXLock - || _pr_xt_hack_okayToReleaseXLock())) { - PR_XUnlock(); - needToLockXAgain = 1; - } - - /* This is the potentially blocking step */ - retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout); - - if (needToLockXAgain) { - PR_XLock(); - } - } + { + int needToLockXAgain; + + needToLockXAgain = 0; + if (rd && (_pr_xt_hack_fd != -1) + && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked() + && (!_pr_xt_hack_okayToReleaseXLock + || _pr_xt_hack_okayToReleaseXLock())) { + PR_XUnlock(); + needToLockXAgain = 1; + } + + /* This is the potentially blocking step */ + retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout); + + if (needToLockXAgain) { + PR_XLock(); + } + } if (retVal > 0) { /* Compute select results */ - if (rd) ZAP_SET(rd, width); - if (wr) ZAP_SET(wr, width); - if (ex) ZAP_SET(ex, width); + if (rd) { + ZAP_SET(rd, width); + } + if (wr) { + ZAP_SET(wr, width); + } + if (ex) { + ZAP_SET(ex, width); + } /* * The return value can be either the number of ready file @@ -226,7 +227,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) { errno = EBADF; PR_LOG(_pr_io_lm, PR_LOG_ERROR, - ("select returns EBADF for %d", unixpd->osfd)); + ("select returns EBADF for %d", unixpd->osfd)); retVal = -1; break; } @@ -238,27 +239,25 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) * it has a hangup condition. */ if (rd && (unixpd->in_flags & _PR_UNIX_POLL_READ) - && (unixpd->out_flags & (_PR_UNIX_POLL_READ - | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) { + && (unixpd->out_flags & (_PR_UNIX_POLL_READ + | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) { FD_SET(unixpd->osfd, rd); nbits++; } if (wr && (unixpd->in_flags & _PR_UNIX_POLL_WRITE) - && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE - | _PR_UNIX_POLL_ERR))) { + && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE + | _PR_UNIX_POLL_ERR))) { FD_SET(unixpd->osfd, wr); nbits++; } if (ex && (unixpd->in_flags & _PR_UNIX_POLL_WRITE) - && (unixpd->out_flags & PR_POLL_EXCEPT)) { + && (unixpd->out_flags & PR_POLL_EXCEPT)) { FD_SET(unixpd->osfd, ex); nbits++; } PR_ASSERT(nbits > 0); -#if defined(HPUX) || defined(SOLARIS) || defined(OSF1) || defined(AIX) +#if defined(HPUX) || defined(SOLARIS) || defined(AIX) retVal += nbits; -#else /* IRIX */ - retVal += 1; #endif } } @@ -288,7 +287,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) *----------------------------------------------------------------------- * poll() -- * - * RETURN VALUES: + * RETURN VALUES: * -1: fails, errno indicates the error. * 0: timed out, the revents bitmasks are not set. * positive value: the number of file descriptors for which poll() @@ -303,7 +302,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) int wrap_poll(void *listptr, unsigned long nfds, long timeout) #elif (defined(AIX) && !defined(AIX_RENAME_SELECT)) int poll(void *listptr, unsigned long nfds, long timeout) -#elif defined(OSF1) || (defined(HPUX) && !defined(HPUX9)) +#elif defined(HPUX) && !defined(HPUX9) int poll(struct pollfd filedes[], unsigned int nfds, int timeout) #elif defined(HPUX9) int poll(struct pollfd filedes[], int nfds, int timeout) @@ -344,7 +343,7 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout) #ifndef _PR_LOCAL_THREADS_ONLY if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) { - return _MD_POLL(filedes, nfds, timeout); + return _MD_POLL(filedes, nfds, timeout); } #endif @@ -372,7 +371,7 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout) } unixpds = (_PRUnixPollDesc *) - PR_MALLOC(nfds * sizeof(_PRUnixPollDesc)); + PR_MALLOC(nfds * sizeof(_PRUnixPollDesc)); if (NULL == unixpds) { errno = EAGAIN; return -1; @@ -405,23 +404,23 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout) unixpd->in_flags = 0; if (pfd->events & (POLLIN #ifdef POLLRDNORM - | POLLRDNORM + | POLLRDNORM #endif - )) { + )) { unixpd->in_flags |= _PR_UNIX_POLL_READ; } if (pfd->events & (POLLOUT #ifdef POLLWRNORM - | POLLWRNORM + | POLLWRNORM #endif - )) { + )) { unixpd->in_flags |= _PR_UNIX_POLL_WRITE; } if (pfd->events & (POLLPRI #ifdef POLLRDBAND - | POLLRDBAND + | POLLRDBAND #endif - )) { + )) { unixpd->in_flags |= PR_POLL_EXCEPT; } #endif /* _PR_USE_POLL */ |