From: Andrew Cooper Date: Wed, 9 Aug 2017 15:09:30 +0000 (+0100) Subject: Implement xtf_get_domid() for tests which need to know their own domid X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=35746a16fe73ec044c1766b157be54baa6e9b0bd;p=people%2Fandrewcoop%2Fxen-test-framework.git Implement xtf_get_domid() for tests which need to know their own domid Signed-off-by: Andrew Cooper --- diff --git a/common/lib.c b/common/lib.c index 0da6653..43142ce 100644 --- a/common/lib.c +++ b/common/lib.c @@ -1,6 +1,15 @@ #include #include #include +#include + +#ifndef isdigit +/* Avoid pulling in all of ctypes just for this. */ +static int isdigit(int c) +{ + return c >= '0' && c <= '9'; +} +#endif void __noreturn panic(const char *fmt, ...) { @@ -34,6 +43,26 @@ int xtf_probe_sysctl_interface_version(void) return -1; } +int xtf_get_domid(void) +{ + const char *str = xenstore_read("domid"); + unsigned int domid = 0; + + if ( !str || !isdigit(*str) ) + return -1; + + while ( isdigit(*str) ) + { + domid = domid * 10 + (*str - '0'); + str++; + } + + if ( domid >= DOMID_FIRST_RESERVED ) + return -1; + + return domid; +} + /* * Local variables: * mode: C diff --git a/include/xen/xen.h b/include/xen/xen.h index 413b045..85aaba8 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -66,6 +66,7 @@ typedef uint16_t domid_t; #endif +#define DOMID_FIRST_RESERVED (0x7ff0U) #define DOMID_SELF (0x7ff0U) /* Commands to HYPERVISOR_console_io */ diff --git a/include/xtf/lib.h b/include/xtf/lib.h index a392fb4..d792a8d 100644 --- a/include/xtf/lib.h +++ b/include/xtf/lib.h @@ -90,6 +90,12 @@ static inline void exec_user_void(void (*fn)(void)) */ int xtf_probe_sysctl_interface_version(void); +/** + * Obtain the current domid. + * @returns domid, or -1 on failure. + */ +int xtf_get_domid(void); + #endif /* XTF_LIB_H */ /*