2014-07-23 02:41:58 +04:00
|
|
|
/* $NetBSD: rumpuser_int.h,v 1.10 2014/07/22 22:41:58 justin Exp $ */
|
2008-10-03 01:37:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND 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.
|
|
|
|
*/
|
|
|
|
|
2010-05-18 18:58:41 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-01-08 01:50:08 +03:00
|
|
|
#include <rump/rumpuser.h>
|
|
|
|
|
2010-11-15 18:23:32 +03:00
|
|
|
#define seterror(value) do { if (error) *error = value;} while (/*CONSTCOND*/0)
|
|
|
|
|
2013-04-29 18:51:39 +04:00
|
|
|
extern struct rumpuser_hyperup rumpuser__hyp;
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rumpkern_unsched(int *nlocks, void *interlock)
|
|
|
|
{
|
|
|
|
|
|
|
|
rumpuser__hyp.hyp_backend_unschedule(0, nlocks, interlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rumpkern_sched(int nlocks, void *interlock)
|
|
|
|
{
|
|
|
|
|
|
|
|
rumpuser__hyp.hyp_backend_schedule(nlocks, interlock);
|
|
|
|
}
|
|
|
|
|
2008-10-09 05:19:06 +04:00
|
|
|
#define KLOCK_WRAP(a) \
|
|
|
|
do { \
|
|
|
|
int nlocks; \
|
2013-04-29 18:51:39 +04:00
|
|
|
rumpkern_unsched(&nlocks, NULL); \
|
2008-10-09 05:19:06 +04:00
|
|
|
a; \
|
2013-04-29 18:51:39 +04:00
|
|
|
rumpkern_sched(nlocks, NULL); \
|
2008-10-09 05:19:06 +04:00
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
2008-10-03 01:37:59 +04:00
|
|
|
#define DOCALL(rvtype, call) \
|
2010-03-22 12:39:02 +03:00
|
|
|
{ \
|
2008-10-03 01:37:59 +04:00
|
|
|
rvtype rv; \
|
|
|
|
rv = call; \
|
|
|
|
if (rv == -1) \
|
2010-11-15 18:23:32 +03:00
|
|
|
seterror(errno); \
|
2008-10-03 01:37:59 +04:00
|
|
|
else \
|
2010-11-15 18:23:32 +03:00
|
|
|
seterror(0); \
|
2010-03-22 12:39:02 +03:00
|
|
|
return rv; \
|
|
|
|
}
|
2008-10-09 05:19:06 +04:00
|
|
|
|
|
|
|
#define DOCALL_KLOCK(rvtype, call) \
|
2010-03-22 12:39:02 +03:00
|
|
|
{ \
|
2008-10-09 05:19:06 +04:00
|
|
|
rvtype rv; \
|
|
|
|
int nlocks; \
|
2013-04-29 18:51:39 +04:00
|
|
|
rumpkern_unsched(&nlocks, NULL); \
|
2008-10-09 05:19:06 +04:00
|
|
|
rv = call; \
|
2013-04-29 18:51:39 +04:00
|
|
|
rumpkern_sched(nlocks, NULL); \
|
2008-10-09 05:19:06 +04:00
|
|
|
if (rv == -1) \
|
2010-11-15 18:23:32 +03:00
|
|
|
seterror(errno); \
|
2008-10-09 05:19:06 +04:00
|
|
|
else \
|
2010-11-15 18:23:32 +03:00
|
|
|
seterror(0); \
|
2010-03-22 12:39:02 +03:00
|
|
|
return rv; \
|
|
|
|
}
|
2013-04-27 18:59:08 +04:00
|
|
|
|
|
|
|
void rumpuser__thrinit(void);
|
2013-04-29 16:56:03 +04:00
|
|
|
|
|
|
|
#define NOFAIL(a) do {if (!(a)) abort();} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#define NOFAIL_ERRNO(a) \
|
|
|
|
do { \
|
|
|
|
int fail_rv = (a); \
|
|
|
|
if (fail_rv) { \
|
|
|
|
printf("panic: rumpuser fatal failure %d (%s)\n", \
|
|
|
|
fail_rv, strerror(fail_rv)); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
} while (/*CONSTCOND*/0)
|
2013-04-30 16:39:20 +04:00
|
|
|
|
2014-02-20 05:24:49 +04:00
|
|
|
int rumpuser__sig_rump2host(int);
|
2013-04-30 16:39:20 +04:00
|
|
|
int rumpuser__errtrans(int);
|
|
|
|
#ifdef __NetBSD__
|
|
|
|
#define ET(_v_) return (_v_);
|
|
|
|
#else
|
|
|
|
#define ET(_v_) return (_v_) ? rumpuser__errtrans(_v_) : 0;
|
|
|
|
#endif
|
2014-07-23 02:41:58 +04:00
|
|
|
|
|
|
|
int rumpuser__random_init(void);
|