]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Implement xtf_get_domid() for tests which need to know their own domid
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 9 Aug 2017 15:09:30 +0000 (16:09 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 9 Aug 2017 15:37:25 +0000 (16:37 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/lib.c
include/xen/xen.h
include/xtf/lib.h

index 0da6653bf64ed9ceebf03f4f7efcde8743e5ccc5..43142ce7cf7644a7111c2a7c5038507b930cd327 100644 (file)
@@ -1,6 +1,15 @@
 #include <xtf/lib.h>
 #include <xtf/traps.h>
 #include <xtf/hypercall.h>
+#include <xtf/xenstore.h>
+
+#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
index 413b045b1328be1183a30bdd59c3da8b71c4ad17..85aaba8cacf06ca76807a7ab805635936c39cc7b 100644 (file)
@@ -66,6 +66,7 @@
 typedef uint16_t domid_t;
 #endif
 
+#define DOMID_FIRST_RESERVED (0x7ff0U)
 #define DOMID_SELF (0x7ff0U)
 
 /* Commands to HYPERVISOR_console_io */
index a392fb48a9dee1d42c147d2a8ab010d854308b5b..d792a8d853fd3b7eccb9b3c1019d595cc185e8be 100644 (file)
@@ -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 */
 
 /*