cloudabi_util.h revision 286359
148156Sjlemon/*- 257828Sjlemon * Copyright (c) 2015 Nuxi, https://nuxi.nl/ 348156Sjlemon * 448156Sjlemon * Redistribution and use in source and binary forms, with or without 548156Sjlemon * modification, are permitted provided that the following conditions 648156Sjlemon * are met: 748156Sjlemon * 1. Redistributions of source code must retain the above copyright 848156Sjlemon * notice, this list of conditions and the following disclaimer. 948156Sjlemon * 2. Redistributions in binary form must reproduce the above copyright 1048156Sjlemon * notice, this list of conditions and the following disclaimer in the 1148156Sjlemon * documentation and/or other materials provided with the distribution. 1248156Sjlemon * 1348156Sjlemon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1448156Sjlemon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1548156Sjlemon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1648156Sjlemon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1748156Sjlemon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1848156Sjlemon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1948156Sjlemon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2048156Sjlemon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2148156Sjlemon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2248156Sjlemon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2348156Sjlemon * SUCH DAMAGE. 2448156Sjlemon * 2548156Sjlemon * $FreeBSD: head/sys/compat/cloudabi/cloudabi_util.h 286359 2015-08-06 06:47:28Z ed $ 2650477Speter */ 2748156Sjlemon 2848156Sjlemon#ifndef _CLOUDABI_UTIL_H_ 2948156Sjlemon#define _CLOUDABI_UTIL_H_ 3048156Sjlemon 3148156Sjlemon#include <sys/socket.h> 3248156Sjlemon 3348156Sjlemon#include <compat/cloudabi/cloudabi_syscalldefs.h> 3457828Sjlemon 3548156Sjlemonstruct file; 36124471Smdoddstruct thread; 37124471Smdoddstruct timespec; 38124471Smdodd 39124471Smdodd/* Fetches the time value of a clock. */ 40124471Smdoddint cloudabi_clock_time_get(struct thread *, cloudabi_clockid_t, 41124471Smdodd cloudabi_timestamp_t *); 42124471Smdodd 43124471Smdodd/* Converts a FreeBSD errno to a CloudABI errno. */ 44124471Smdoddcloudabi_errno_t cloudabi_convert_errno(int); 45124471Smdodd 4657828Sjlemon/* Converts FreeBSD's struct sockaddr to CloudABI's cloudabi_sockaddr_t. */ 47124471Smdoddvoid cloudabi_convert_sockaddr(const struct sockaddr *, socklen_t, 48124471Smdodd cloudabi_sockaddr_t *); 4957828Sjlemon 5057828Sjlemon/* Converts a file descriptor to a CloudABI file descriptor type. */ 5157828Sjlemoncloudabi_filetype_t cloudabi_convert_filetype(const struct file *); 5257828Sjlemon 53124471Smdodd/* Converts CloudABI rights to a set of Capsicum capabilities. */ 54124471Smdoddint cloudabi_convert_rights(cloudabi_rights_t, cap_rights_t *); 55124471Smdodd 56124471Smdodd/* Removes rights that conflict with the file descriptor type. */ 57124471Smdoddvoid cloudabi_remove_conflicting_rights(cloudabi_filetype_t, 5848156Sjlemon cloudabi_rights_t *, cloudabi_rights_t *); 5948156Sjlemon 6057828Sjlemon/* Converts a struct timespec to a CloudABI timestamp. */ 6148156Sjlemonint cloudabi_convert_timespec(const struct timespec *, cloudabi_timestamp_t *); 62124471Smdodd 63124471Smdodd/* 6448156Sjlemon * Blocking futex functions. 6548156Sjlemon * 6657828Sjlemon * These functions are called by CloudABI's polling system calls to 6757828Sjlemon * sleep on a lock or condition variable. 68124471Smdodd */ 69124471Smdoddint cloudabi_futex_condvar_wait(struct thread *, cloudabi_condvar_t *, 70124471Smdodd cloudabi_mflags_t, cloudabi_lock_t *, cloudabi_mflags_t, cloudabi_clockid_t, 71124471Smdodd cloudabi_timestamp_t, cloudabi_timestamp_t); 7257828Sjlemonint cloudabi_futex_lock_rdlock(struct thread *, cloudabi_lock_t *, 7357828Sjlemon cloudabi_mflags_t, cloudabi_clockid_t, cloudabi_timestamp_t, 7457828Sjlemon cloudabi_timestamp_t); 7557828Sjlemonint cloudabi_futex_lock_wrlock(struct thread *, cloudabi_lock_t *, 76124471Smdodd cloudabi_mflags_t, cloudabi_clockid_t, cloudabi_timestamp_t, 77124471Smdodd cloudabi_timestamp_t); 78124471Smdodd 7957828Sjlemon#endif 8057828Sjlemon