github.com/akaros/go-akaros@v0.0.0-20181004170632-85005d477eab/src/runtime/parlib/gcc_akaros.c (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include <futex.h> 6 #include <pthread.h> 7 #include <sys/syscall.h> 8 #include "gcc_akaros.h" 9 10 // Akaros syscalls 11 typedef void (*gcc_call_t)(void *arg); 12 const gcc_call_t gcc_syscall = (gcc_call_t)ros_syscall_sync; 13 14 // Akaros style futexes 15 static void __gcc_futex(void *__arg) 16 { 17 // For now, akaros futexes don't support uaddr2 or val3, so we 18 // just 0 them out. 19 gcc_futex_arg_t *a = (gcc_futex_arg_t*)__arg; 20 a->uaddr2 = NULL; 21 a->val3 = 0; 22 // Also, the minimum timout is 1us, so up it to that if it's too small 23 if(a->timeout != NULL) { 24 if(a->timeout->tv_sec == 0) 25 if(a->timeout->tv_nsec < 1000L) 26 a->timeout->tv_nsec = 1000L; 27 } 28 a->retval = futex(a->uaddr, a->op, a->val, a->timeout, a->uaddr2, a->val3); 29 } 30 const gcc_call_t gcc_futex = __gcc_futex; 31 32 // Akaros style pthread yields 33 static void __gcc_myield(void *__arg) 34 { 35 // We should never pass an argument here 36 assert(__arg == NULL); 37 pthread_yield(); 38 } 39 const gcc_call_t gcc_myield = __gcc_myield; 40 41 // Akaros style sigactions 42 static void __gcc_sigaction(void *__arg) 43 { 44 gcc_sigaction_arg_t *a = (gcc_sigaction_arg_t*)__arg; 45 a->ret = sigaction(a->sig, (struct sigaction*)a->act, (struct sigaction*)a->oact); 46 } 47 const gcc_call_t gcc_sigaction = __gcc_sigaction; 48 49 static void __gcc_sigaltstack(void *__arg) 50 { 51 gcc_sigaltstack_arg_t *a = (gcc_sigaltstack_arg_t*)__arg; 52 sigaltstack((struct sigaltstack * __restrict__)a, (struct sigaltstack * __restrict__) NULL); 53 } 54 const gcc_call_t gcc_sigaltstack = __gcc_sigaltstack; 55 56 // Akaros sigprocmask 57 static void __gcc_sigprocmask(void *__arg) 58 { 59 gcc_sigprocmask_arg_t *a = (gcc_sigprocmask_arg_t*)__arg; 60 a->retval = pthread_sigmask(a->how, a->set, a->oset); 61 } 62 const gcc_call_t gcc_sigprocmask = __gcc_sigprocmask; 63 64 // enable_profalarm() and disable_profalarm() 65 static void __gcc_enable_profalarm(void *__arg) 66 { 67 enable_profalarm(*((uint64_t*)__arg)); 68 } 69 const gcc_call_t gcc_enable_profalarm = __gcc_enable_profalarm; 70 71 static void __gcc_disable_profalarm(void *__arg) 72 { 73 disable_profalarm(); 74 } 75 const gcc_call_t gcc_disable_profalarm = __gcc_disable_profalarm;