X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fsunos-os.c;h=eb84223b9eb01afbaef21c410ba66b4b8a726fb2;hb=bf40ae88bc289fd765a33861cc4bc0853ed483ba;hp=4389564d6be9117bbec3fab4db05b780a5f22eac;hpb=f2c8e80369a67f5b7e4e47725bed257b3c41de62;p=sbcl.git diff --git a/src/runtime/sunos-os.c b/src/runtime/sunos-os.c index 4389564..eb84223 100644 --- a/src/runtime/sunos-os.c +++ b/src/runtime/sunos-os.c @@ -26,6 +26,12 @@ #include "gencgc-internal.h" #endif +#ifdef LISP_FEATURE_SB_WTIMER +# include +# include +# include +#endif + os_vm_size_t os_vm_page_size=0; void @@ -51,7 +57,13 @@ os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len) if (addr == MAP_FAILED) { perror("mmap"); - lose ("Error in mmap(..)\n"); + /* While it is generally hard to recover from out-of-memory + * situations, we require callers to decide on the right course + * of action here. Consider thread creation: Failure to mmap + * here is common if users have started too many threads, and + * often we can recover from that and treat it as an ordinary + * error. */ + return 0; } return addr; @@ -138,6 +150,11 @@ sigsegv_handler(int signal, siginfo_t *info, os_context_t *context) { void* fault_addr = (void*)info->si_addr; +#ifdef LISP_FEATURE_SB_SAFEPOINT + if (handle_safepoint_violation(context, fault_addr)) + return; +#endif + if (!gencgc_handle_wp_violation(fault_addr)) if(!handle_guard_page_triggered(context, fault_addr)) lisp_memory_fault_error(context, fault_addr); @@ -164,9 +181,17 @@ os_install_interrupt_handlers() undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT, sigsegv_handler); + /* OAOOM c.f. linux-os.c. + * Should we have a reusable function gc_install_interrupt_handlers? */ #ifdef LISP_FEATURE_SB_THREAD +# ifdef LISP_FEATURE_SB_SAFEPOINT +# ifdef LISP_FEATURE_SB_THRUPTION + undoably_install_low_level_interrupt_handler(SIGPIPE, thruption_handler); +# endif +# else undoably_install_low_level_interrupt_handler(SIG_STOP_FOR_GC, sig_stop_for_gc_handler); +# endif #endif } @@ -181,3 +206,98 @@ os_get_runtime_executable_path(int external) return copied_string(path); } +#ifdef LISP_FEATURE_SB_WTIMER +/* + * Waitable timer implementation for the safepoint-based (SIGALRM-free) + * timer facility using SunOS completion ports. + */ + +struct os_wtimer { + int port; + int timer; +}; + +struct os_wtimer * +os_create_wtimer() +{ + int port = port_create(); + if (port == -1) { + perror("port_create"); + lose("os_create_wtimer"); + } + + port_notify_t pn; + pn.portnfy_port = port; + pn.portnfy_user = 0; + + struct sigevent ev; + memset(&ev, 0, sizeof(ev)); + ev.sigev_notify = SIGEV_PORT; + ev.sigev_value.sival_ptr = &pn; + + timer_t timer; + if (timer_create(CLOCK_HIGHRES, &ev, &timer) == -1 + && (errno != EPERM || timer_create(CLOCK_REALTIME, &ev, &timer) == -1)) + { + perror("timer_create"); + lose("os_create_wtimer"); + } + + struct os_wtimer *wt = malloc(sizeof(struct os_wtimer)); + if (!wt) + lose("os_create_wtimer: malloc"); + + wt->port = port; + wt->timer = timer; + return wt; +} + +int +os_wait_for_wtimer(struct os_wtimer *wt) +{ + port_event_t pe; + if (port_get(wt->port, &pe, 0) == -1) { + if (errno == EINTR) + return 1; + perror("port_get"); + lose("os_wtimer_listen failed"); + } + return 0; +} + +void +os_close_wtimer(struct os_wtimer *wt) +{ + if (close(wt->port) == -1) { + perror("close"); + lose("os_close_wtimer"); + } + if (timer_delete(wt->timer) == -1) { + perror("timer_delete"); + lose("os_close_wtimer"); + } + free(wt); +} + +void +os_set_wtimer(struct os_wtimer *wt, int sec, int nsec) +{ + struct itimerspec spec; + spec.it_value.tv_sec = sec; + spec.it_value.tv_nsec = nsec; + spec.it_interval.tv_sec = 0; + spec.it_interval.tv_nsec = 0; + if (timer_settime(wt->timer, 0, &spec, 0) == -1) { + int x = errno; + perror("timer_settime"); + if (x != EINVAL) + lose("os_set_wtimer"); + } +} + +void +os_cancel_wtimer(struct os_wtimer *wt) +{ + os_set_wtimer(wt, 0, 0); +} +#endif