michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nspr_solaris_defs_h___ michael@0: #define nspr_solaris_defs_h___ michael@0: michael@0: /* michael@0: * Internal configuration macros michael@0: */ michael@0: michael@0: #define PR_LINKER_ARCH "solaris" michael@0: #define _PR_SI_SYSNAME "SOLARIS" michael@0: #ifdef sparc michael@0: #define _PR_SI_ARCHITECTURE "sparc" michael@0: #elif defined(__x86_64) michael@0: #define _PR_SI_ARCHITECTURE "x86-64" michael@0: #elif defined(i386) michael@0: #define _PR_SI_ARCHITECTURE "x86" michael@0: #else michael@0: #error unknown processor michael@0: #endif michael@0: #define PR_DLL_SUFFIX ".so" michael@0: michael@0: #define _PR_VMBASE 0x30000000 michael@0: #define _PR_STACK_VMBASE 0x50000000 michael@0: #define _MD_DEFAULT_STACK_SIZE (2*65536L) michael@0: #define _MD_MMAP_FLAGS MAP_SHARED michael@0: michael@0: #undef HAVE_STACK_GROWING_UP michael@0: michael@0: #ifndef HAVE_WEAK_IO_SYMBOLS michael@0: #define HAVE_WEAK_IO_SYMBOLS michael@0: #endif michael@0: michael@0: #undef HAVE_WEAK_MALLOC_SYMBOLS michael@0: #define HAVE_DLL michael@0: #define USE_DLFCN michael@0: #define NEED_STRFTIME_LOCK michael@0: michael@0: /* michael@0: * Intel x86 has atomic instructions. michael@0: * michael@0: * Sparc v8 does not have instructions to efficiently implement michael@0: * atomic increment/decrement operations. We use the default michael@0: * atomic routine implementation in pratom.c. michael@0: * michael@0: * 64-bit Solaris requires sparc v9, which has atomic instructions. michael@0: */ michael@0: #if defined(i386) || defined(IS_64) michael@0: #define _PR_HAVE_ATOMIC_OPS michael@0: #endif michael@0: michael@0: #define _PR_POLL_AVAILABLE michael@0: #define _PR_USE_POLL michael@0: #define _PR_STAT_HAS_ST_ATIM michael@0: #ifdef SOLARIS2_5 michael@0: #define _PR_HAVE_SYSV_SEMAPHORES michael@0: #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY michael@0: #else michael@0: #define _PR_HAVE_POSIX_SEMAPHORES michael@0: #define PR_HAVE_POSIX_NAMED_SHARED_MEMORY michael@0: #endif michael@0: #define _PR_HAVE_GETIPNODEBYNAME michael@0: #define _PR_HAVE_GETIPNODEBYADDR michael@0: #define _PR_HAVE_GETADDRINFO michael@0: #define _PR_INET6_PROBE michael@0: #define _PR_ACCEPT_INHERIT_NONBLOCK michael@0: #ifdef _PR_INET6 michael@0: #define _PR_HAVE_INET_NTOP michael@0: #else michael@0: #define AF_INET6 26 michael@0: struct addrinfo { michael@0: int ai_flags; michael@0: int ai_family; michael@0: int ai_socktype; michael@0: int ai_protocol; michael@0: size_t ai_addrlen; michael@0: char *ai_canonname; michael@0: struct sockaddr *ai_addr; michael@0: struct addrinfo *ai_next; michael@0: }; michael@0: #define AI_CANONNAME 0x0010 michael@0: #define AI_V4MAPPED 0x0001 michael@0: #define AI_ALL 0x0002 michael@0: #define AI_ADDRCONFIG 0x0004 michael@0: #define _PR_HAVE_MD_SOCKADDR_IN6 michael@0: /* isomorphic to struct in6_addr on Solaris 8 */ michael@0: struct _md_in6_addr { michael@0: union { michael@0: PRUint8 _S6_u8[16]; michael@0: PRUint32 _S6_u32[4]; michael@0: PRUint32 __S6_align; michael@0: } _S6_un; michael@0: }; michael@0: /* isomorphic to struct sockaddr_in6 on Solaris 8 */ michael@0: struct _md_sockaddr_in6 { michael@0: PRUint16 sin6_family; michael@0: PRUint16 sin6_port; michael@0: PRUint32 sin6_flowinfo; michael@0: struct _md_in6_addr sin6_addr; michael@0: PRUint32 sin6_scope_id; michael@0: PRUint32 __sin6_src_id; michael@0: }; michael@0: #endif michael@0: #if defined(_PR_PTHREADS) michael@0: #define _PR_HAVE_GETHOST_R michael@0: #define _PR_HAVE_GETHOST_R_POINTER michael@0: #endif michael@0: michael@0: #include "prinrval.h" michael@0: #define _MD_INTERVAL_INIT() michael@0: NSPR_API(PRIntervalTime) _MD_Solaris_GetInterval(void); michael@0: #define _MD_GET_INTERVAL _MD_Solaris_GetInterval michael@0: NSPR_API(PRIntervalTime) _MD_Solaris_TicksPerSecond(void); michael@0: #define _MD_INTERVAL_PER_SEC _MD_Solaris_TicksPerSecond michael@0: michael@0: #if defined(_PR_HAVE_ATOMIC_OPS) michael@0: /* michael@0: ** Atomic Operations michael@0: */ michael@0: #define _MD_INIT_ATOMIC() michael@0: michael@0: NSPR_API(PRInt32) _MD_AtomicIncrement(PRInt32 *val); michael@0: #define _MD_ATOMIC_INCREMENT _MD_AtomicIncrement michael@0: michael@0: NSPR_API(PRInt32) _MD_AtomicAdd(PRInt32 *ptr, PRInt32 val); michael@0: #define _MD_ATOMIC_ADD _MD_AtomicAdd michael@0: michael@0: NSPR_API(PRInt32) _MD_AtomicDecrement(PRInt32 *val); michael@0: #define _MD_ATOMIC_DECREMENT _MD_AtomicDecrement michael@0: michael@0: NSPR_API(PRInt32) _MD_AtomicSet(PRInt32 *val, PRInt32 newval); michael@0: #define _MD_ATOMIC_SET _MD_AtomicSet michael@0: #endif /* _PR_HAVE_ATOMIC_OPS */ michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: michael@0: NSPR_API(void) _MD_EarlyInit(void); michael@0: michael@0: #define _MD_EARLY_INIT _MD_EarlyInit michael@0: #define _MD_FINAL_INIT _PR_UnixInit michael@0: michael@0: #else /* _PR_PTHREADS */ michael@0: michael@0: /* michael@0: * _PR_LOCAL_THREADS_ONLY implementation on Solaris michael@0: */ michael@0: michael@0: #include "prthread.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: /* michael@0: ** Initialization Related definitions michael@0: */ michael@0: michael@0: NSPR_API(void) _MD_EarlyInit(void); michael@0: NSPR_API(void) _MD_SolarisInit(); michael@0: #define _MD_EARLY_INIT _MD_EarlyInit michael@0: #define _MD_FINAL_INIT _MD_SolarisInit michael@0: #define _MD_INIT_THREAD _MD_InitializeThread michael@0: michael@0: #ifdef USE_SETJMP michael@0: michael@0: #include michael@0: michael@0: #define _PR_CONTEXT_TYPE jmp_buf michael@0: michael@0: #ifdef sparc michael@0: #define _MD_GET_SP(_t) (_t)->md.context[2] michael@0: #else michael@0: #define _MD_GET_SP(_t) (_t)->md.context[4] michael@0: #endif michael@0: michael@0: #define PR_NUM_GCREGS _JBLEN michael@0: #define CONTEXT(_thread) (_thread)->md.context michael@0: michael@0: #else /* ! USE_SETJMP */ michael@0: michael@0: #ifdef sparc michael@0: #define _PR_CONTEXT_TYPE ucontext_t michael@0: #define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[REG_SP] michael@0: /* michael@0: ** Sparc's use register windows. the _MD_GetRegisters for the sparc's michael@0: ** doesn't actually store anything into the argument buffer; instead the michael@0: ** register windows are homed to the stack. I assume that the stack michael@0: ** always has room for the registers to spill to... michael@0: */ michael@0: #define PR_NUM_GCREGS 0 michael@0: #else michael@0: #define _PR_CONTEXT_TYPE unsigned int edi; sigset_t oldMask, blockMask; ucontext_t michael@0: #define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[USP] michael@0: #define PR_NUM_GCREGS _JBLEN michael@0: #endif michael@0: michael@0: #define CONTEXT(_thread) (&(_thread)->md.context) michael@0: michael@0: #endif /* ! USE_SETJMP */ michael@0: michael@0: #include michael@0: /* michael@0: * Because clock_gettime() on Solaris/x86 always generates a michael@0: * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(), michael@0: * which is implemented using gettimeofday(). michael@0: */ michael@0: #ifdef i386 michael@0: #define GETTIME(tt) _pr_solx86_clock_gettime(CLOCK_REALTIME, (tt)) michael@0: #else michael@0: #define GETTIME(tt) clock_gettime(CLOCK_REALTIME, (tt)) michael@0: #endif /* i386 */ michael@0: michael@0: #define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno; michael@0: #define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode; michael@0: michael@0: #ifdef sparc michael@0: michael@0: #ifdef USE_SETJMP michael@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ michael@0: PR_BEGIN_MACRO \ michael@0: int *context = (_thread)->md.context; \ michael@0: *status = PR_TRUE; \ michael@0: (void) setjmp(context); \ michael@0: (_thread)->md.context[1] = (int) ((_sp) - 64); \ michael@0: (_thread)->md.context[2] = (int) _main; \ michael@0: (_thread)->md.context[3] = (int) _main + 4; \ michael@0: _thread->no_sched = 0; \ michael@0: PR_END_MACRO michael@0: michael@0: #define _MD_SWITCH_CONTEXT(_thread) \ michael@0: if (!setjmp(CONTEXT(_thread))) { \ michael@0: _MD_SAVE_ERRNO(_thread) \ michael@0: _MD_SET_LAST_THREAD(_thread); \ michael@0: _MD_SET_CURRENT_THREAD(_thread); \ michael@0: _PR_Schedule(); \ michael@0: } michael@0: michael@0: #define _MD_RESTORE_CONTEXT(_newThread) \ michael@0: { \ michael@0: _MD_RESTORE_ERRNO(_newThread) \ michael@0: _MD_SET_CURRENT_THREAD(_newThread); \ michael@0: longjmp(CONTEXT(_newThread), 1); \ michael@0: } michael@0: michael@0: #else michael@0: /* michael@0: ** Initialize the thread context preparing it to execute _main. michael@0: */ michael@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ michael@0: PR_BEGIN_MACRO \ michael@0: ucontext_t *uc = CONTEXT(_thread); \ michael@0: *status = PR_TRUE; \ michael@0: getcontext(uc); \ michael@0: uc->uc_stack.ss_sp = (char *) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \ michael@0: uc->uc_stack.ss_size = _thread->stack->stackSize; \ michael@0: uc->uc_stack.ss_flags = 0; /* ? */ \ michael@0: uc->uc_mcontext.gregs[REG_SP] = (unsigned int) uc->uc_stack.ss_sp; \ michael@0: uc->uc_mcontext.gregs[REG_PC] = (unsigned int) _main; \ michael@0: uc->uc_mcontext.gregs[REG_nPC] = (unsigned int) ((char*)_main)+4; \ michael@0: uc->uc_flags = UC_ALL; \ michael@0: _thread->no_sched = 0; \ michael@0: PR_END_MACRO michael@0: michael@0: /* michael@0: ** Switch away from the current thread context by saving its state and michael@0: ** calling the thread scheduler. Reload cpu when we come back from the michael@0: ** context switch because it might have changed. michael@0: */ michael@0: #define _MD_SWITCH_CONTEXT(_thread) \ michael@0: PR_BEGIN_MACRO \ michael@0: if (!getcontext(CONTEXT(_thread))) { \ michael@0: _MD_SAVE_ERRNO(_thread); \ michael@0: _MD_SET_LAST_THREAD(_thread); \ michael@0: _PR_Schedule(); \ michael@0: } \ michael@0: PR_END_MACRO michael@0: michael@0: /* michael@0: ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or michael@0: ** initialized by _MD_INIT_CONTEXT. michael@0: */ michael@0: #define _MD_RESTORE_CONTEXT(_newThread) \ michael@0: PR_BEGIN_MACRO \ michael@0: ucontext_t *uc = CONTEXT(_newThread); \ michael@0: uc->uc_mcontext.gregs[11] = 1; \ michael@0: _MD_RESTORE_ERRNO(_newThread); \ michael@0: _MD_SET_CURRENT_THREAD(_newThread); \ michael@0: setcontext(uc); \ michael@0: PR_END_MACRO michael@0: #endif michael@0: michael@0: #else /* x86 solaris */ michael@0: michael@0: #ifdef USE_SETJMP michael@0: michael@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ michael@0: PR_BEGIN_MACRO \ michael@0: *status = PR_TRUE; \ michael@0: if (setjmp(CONTEXT(_thread))) _main(); \ michael@0: _MD_GET_SP(_thread) = (int) ((_sp) - 64); \ michael@0: PR_END_MACRO michael@0: michael@0: #define _MD_SWITCH_CONTEXT(_thread) \ michael@0: if (!setjmp(CONTEXT(_thread))) { \ michael@0: _MD_SAVE_ERRNO(_thread) \ michael@0: _PR_Schedule(); \ michael@0: } michael@0: michael@0: #define _MD_RESTORE_CONTEXT(_newThread) \ michael@0: { \ michael@0: _MD_RESTORE_ERRNO(_newThread) \ michael@0: _MD_SET_CURRENT_THREAD(_newThread); \ michael@0: longjmp(CONTEXT(_newThread), 1); \ michael@0: } michael@0: michael@0: #else /* USE_SETJMP */ michael@0: michael@0: #define WINDOWSIZE 0 michael@0: michael@0: int getedi(void); michael@0: void setedi(int); michael@0: michael@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ michael@0: PR_BEGIN_MACRO \ michael@0: ucontext_t *uc = CONTEXT(_thread); \ michael@0: *status = PR_TRUE; \ michael@0: getcontext(uc); \ michael@0: /* Force sp to be double aligned! */ \ michael@0: uc->uc_mcontext.gregs[USP] = (int) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \ michael@0: uc->uc_mcontext.gregs[PC] = (int) _main; \ michael@0: (_thread)->no_sched = 0; \ michael@0: PR_END_MACRO michael@0: michael@0: /* getcontext() may return 1, contrary to what the man page says */ michael@0: #define _MD_SWITCH_CONTEXT(_thread) \ michael@0: PR_BEGIN_MACRO \ michael@0: ucontext_t *uc = CONTEXT(_thread); \ michael@0: PR_ASSERT(_thread->no_sched); \ michael@0: sigfillset(&((_thread)->md.blockMask)); \ michael@0: sigprocmask(SIG_BLOCK, &((_thread)->md.blockMask), \ michael@0: &((_thread)->md.oldMask)); \ michael@0: (_thread)->md.edi = getedi(); \ michael@0: if (! getcontext(uc)) { \ michael@0: sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \ michael@0: uc->uc_mcontext.gregs[EDI] = (_thread)->md.edi; \ michael@0: _MD_SAVE_ERRNO(_thread) \ michael@0: _MD_SET_LAST_THREAD(_thread); \ michael@0: _PR_Schedule(); \ michael@0: } else { \ michael@0: sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \ michael@0: setedi((_thread)->md.edi); \ michael@0: PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \ michael@0: _MD_LAST_THREAD()->no_sched = 0; \ michael@0: } \ michael@0: PR_END_MACRO michael@0: michael@0: /* michael@0: ** Restore a thread context, saved by _PR_SWITCH_CONTEXT michael@0: */ michael@0: #define _MD_RESTORE_CONTEXT(_newthread) \ michael@0: PR_BEGIN_MACRO \ michael@0: ucontext_t *uc = CONTEXT(_newthread); \ michael@0: uc->uc_mcontext.gregs[EAX] = 1; \ michael@0: _MD_RESTORE_ERRNO(_newthread) \ michael@0: _MD_SET_CURRENT_THREAD(_newthread); \ michael@0: (_newthread)->no_sched = 1; \ michael@0: setcontext(uc); \ michael@0: PR_END_MACRO michael@0: #endif /* USE_SETJMP */ michael@0: michael@0: #endif /* sparc */ michael@0: michael@0: struct _MDLock { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: struct _MDCVar { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: struct _MDSemaphore { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: struct _MDThread { michael@0: _PR_CONTEXT_TYPE context; michael@0: int errcode; michael@0: int id; michael@0: }; michael@0: michael@0: struct _MDThreadStack { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: struct _MDSegment { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: /* michael@0: * md-specific cpu structure field michael@0: */ michael@0: #define _PR_MD_MAX_OSFD FD_SETSIZE michael@0: michael@0: struct _MDCPU_Unix { michael@0: PRCList ioQ; michael@0: PRUint32 ioq_timeout; michael@0: PRInt32 ioq_max_osfd; michael@0: PRInt32 ioq_osfd_cnt; michael@0: #ifndef _PR_USE_POLL michael@0: fd_set fd_read_set, fd_write_set, fd_exception_set; michael@0: PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], michael@0: fd_exception_cnt[_PR_MD_MAX_OSFD]; michael@0: #else michael@0: struct pollfd *ioq_pollfds; michael@0: int ioq_pollfds_size; michael@0: #endif /* _PR_USE_POLL */ michael@0: }; michael@0: michael@0: #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) michael@0: #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) michael@0: #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) michael@0: #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) michael@0: #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) michael@0: #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) michael@0: #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) michael@0: #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) michael@0: #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) michael@0: #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) michael@0: #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) michael@0: #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) michael@0: #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) michael@0: michael@0: #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 michael@0: michael@0: struct _MDCPU { michael@0: struct _MDCPU_Unix md_unix; michael@0: }; michael@0: michael@0: #define _MD_INIT_LOCKS() michael@0: #define _MD_NEW_LOCK(lock) PR_SUCCESS michael@0: #define _MD_FREE_LOCK(lock) michael@0: #define _MD_LOCK(lock) michael@0: #define _MD_UNLOCK(lock) michael@0: #define _MD_INIT_IO() michael@0: #define _MD_IOQ_LOCK() michael@0: #define _MD_IOQ_UNLOCK() michael@0: michael@0: #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) michael@0: #define _MD_INIT_THREAD _MD_InitializeThread michael@0: #define _MD_EXIT_THREAD(thread) michael@0: #define _MD_SUSPEND_THREAD(thread) michael@0: #define _MD_RESUME_THREAD(thread) michael@0: #define _MD_CLEAN_THREAD(_thread) michael@0: michael@0: extern PRStatus _MD_WAIT(struct PRThread *, PRIntervalTime timeout); michael@0: extern PRStatus _MD_WAKEUP_WAITER(struct PRThread *); michael@0: extern void _MD_YIELD(void); michael@0: extern PRStatus _MD_InitializeThread(PRThread *thread); michael@0: extern void _MD_SET_PRIORITY(struct _MDThread *thread, michael@0: PRThreadPriority newPri); michael@0: extern PRStatus _MD_CREATE_THREAD(PRThread *thread, void (*start) (void *), michael@0: PRThreadPriority priority, PRThreadScope scope, PRThreadState state, michael@0: PRUint32 stackSize); michael@0: michael@0: /* The following defines the unwrapped versions of select() and poll(). */ michael@0: extern int _select(int nfds, fd_set *readfds, fd_set *writefds, michael@0: fd_set *exceptfds, struct timeval *timeout); michael@0: #define _MD_SELECT _select michael@0: michael@0: #include michael@0: #include michael@0: #define _MD_POLL _poll michael@0: extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout); michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /* michael@0: ** Missing function prototypes michael@0: */ michael@0: extern int gethostname (char *name, int namelen); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* _PR_PTHREADS */ michael@0: michael@0: extern void _MD_solaris_map_sendfile_error(int err); michael@0: michael@0: #endif /* nspr_solaris_defs_h___ */ michael@0: