Home | History | Annotate | Line # | Download | only in librumpuser
      1 /*	$NetBSD: rumpuser_int.h,v 1.11 2022/04/19 20:32:17 rillig Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #include <stdlib.h>
     29 
     30 #include <rump/rumpuser.h>
     31 
     32 #define seterror(value) do { if (error) *error = value;} while (0)
     33 
     34 extern struct rumpuser_hyperup rumpuser__hyp;
     35 
     36 static inline void
     37 rumpkern_unsched(int *nlocks, void *interlock)
     38 {
     39 
     40 	rumpuser__hyp.hyp_backend_unschedule(0, nlocks, interlock);
     41 }
     42 
     43 static inline void
     44 rumpkern_sched(int nlocks, void *interlock)
     45 {
     46 
     47 	rumpuser__hyp.hyp_backend_schedule(nlocks, interlock);
     48 }
     49 
     50 #define KLOCK_WRAP(a)							\
     51 do {									\
     52 	int nlocks;							\
     53 	rumpkern_unsched(&nlocks, NULL);				\
     54 	a;								\
     55 	rumpkern_sched(nlocks, NULL);					\
     56 } while (0)
     57 
     58 #define DOCALL(rvtype, call)						\
     59 {									\
     60 	rvtype rv;							\
     61 	rv = call;							\
     62 	if (rv == -1)							\
     63 		seterror(errno);					\
     64 	else								\
     65 		seterror(0);						\
     66 	return rv;							\
     67 }
     68 
     69 #define DOCALL_KLOCK(rvtype, call)					\
     70 {									\
     71 	rvtype rv;							\
     72 	int nlocks;							\
     73 	rumpkern_unsched(&nlocks, NULL);				\
     74 	rv = call;							\
     75 	rumpkern_sched(nlocks, NULL);					\
     76 	if (rv == -1)							\
     77 		seterror(errno);					\
     78 	else								\
     79 		seterror(0);						\
     80 	return rv;							\
     81 }
     82 
     83 void rumpuser__thrinit(void);
     84 
     85 #define NOFAIL(a) do {if (!(a)) abort();} while (0)
     86 
     87 #define NOFAIL_ERRNO(a)							\
     88 do {									\
     89 	int fail_rv = (a);						\
     90 	if (fail_rv) {							\
     91 		printf("panic: rumpuser fatal failure %d (%s)\n",	\
     92 		    fail_rv, strerror(fail_rv));			\
     93 		abort();						\
     94 	}								\
     95 } while (0)
     96 
     97 int  rumpuser__sig_rump2host(int);
     98 int  rumpuser__errtrans(int);
     99 #ifdef __NetBSD__
    100 #define ET(_v_) return (_v_);
    101 #else
    102 #define ET(_v_) return (_v_) ? rumpuser__errtrans(_v_) : 0;
    103 #endif
    104 
    105 int rumpuser__random_init(void);
    106