ssize_t write(int fd, const void *buf, size_t count) { if(fd == -1) return -EBADF; if(!buf) return -EFAULT; if(!count) return 0; return (ssize_t)SYSCALL3(SYSCALL_WRITE, fd, buf, count); }
int ioctl(int fd, int req, int *argp) { int ret; SYSCALL3(SYS_IOCTL, fd, req, argp, ret); return ret; }
int ioctl(int fd, unsigned long request, ...) { va_list args; va_start(args, request); void *arg = va_arg(args, void *); va_end(args); return (int)SYSCALL3(SYS_Ioctl, fd, request, arg); }
ssize_t read(int fd, void *buf, size_t count) { ssize_t ret; if(fd == -1) return -EBADF; if(!buf) return -EFAULT; if(!count) return 0; ret = (size_t)SYSCALL3(SYSCALL_READ, fd, buf, count); return ret; }
//------------------------------------------------------------------------------ // Wait //------------------------------------------------------------------------------ int tbthread_cond_wait(tbthread_cond_t *cond, tbthread_mutex_t *mutex) { tb_futex_lock(&cond->lock); int st = 0; if(!cond->mutex) cond->mutex = mutex; if(cond->mutex != mutex) { st = -EINVAL; goto error; } st = tbthread_mutex_unlock(mutex); if(st) goto error; ++cond->waiters; int bseq = cond->broadcast_seq; int futex = cond->futex; tb_futex_unlock(&cond->lock); while(1) { st = SYSCALL3(__NR_futex, &cond->futex, FUTEX_WAIT, futex); if(st == -EINTR) continue; tb_futex_lock(&cond->lock); if(cond->signal_num) { --cond->signal_num; goto exit; } if(bseq != cond->broadcast_seq) goto exit; tb_futex_unlock(&cond->lock); } error: if(!cond->waiters) cond->mutex = 0; tb_futex_unlock(&cond->lock); return st; exit: --cond->waiters; if(!cond->waiters) cond->mutex = 0; tb_futex_unlock(&cond->lock); tbthread_mutex_lock(mutex); return st; }
//------------------------------------------------------------------------------ // Signal //------------------------------------------------------------------------------ int tbthread_cond_signal(tbthread_cond_t *cond) { tb_futex_lock(&cond->lock); if(cond->waiters == cond->signal_num) goto exit; ++cond->futex; ++cond->signal_num; SYSCALL3(__NR_futex, &cond->futex, FUTEX_WAKE, 1); exit: tb_futex_unlock(&cond->lock); return 0; }
//------------------------------------------------------------------------------ // Broadcast //------------------------------------------------------------------------------ int tbthread_cond_broadcast(tbthread_cond_t *cond) { tb_futex_lock(&cond->lock); if(!cond->waiters) goto exit; ++cond->futex; ++cond->broadcast_seq; SYSCALL3(__NR_futex, &cond->futex, FUTEX_WAKE, INT_MAX); exit: tb_futex_unlock(&cond->lock); return 0; }
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include <_ansi.h> #include <_syslist.h> #include <errno.h> #undef errno extern int errno; #include "warning.h" #include "syscall.h" int _DEFUN (_open, (file, flags, mode), char *file _AND int flags _AND int mode) { int ret; ret = SYSCALL3(__NR_open, file, flags, mode); if (ret < 0) { errno = -ret; ret = -1; } return ret; }
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include <_ansi.h> #include <_syslist.h> #include <errno.h> #undef errno extern int errno; #include "warning.h" #include "syscall.h" int _DEFUN (_lseek, (file, ptr, dir), int file _AND int ptr _AND int dir) { int ret; ret = SYSCALL3(__NR_lseek, file, ptr, dir); if (ret < 0) { errno = -ret; ret = -1; } return ret; }
// open call close s64 Open(char* path, s64 flag, s64 mode) { SYSCALL3(SYS_OPEN, path, flag, mode); }