Xen Test Framework
lib.c
Go to the documentation of this file.
1 #include <xtf/framework.h>
2 #include <xtf/lib.h>
3 #include <xtf/traps.h>
4 #include <xtf/hypercall.h>
5 #include <xtf/xenstore.h>
6 
7 #ifndef isdigit
8 /* Avoid pulling in all of ctypes just for this. */
9 static int isdigit(int c)
10 {
11  return c >= '0' && c <= '9';
12 }
13 #endif
14 
15 void __noreturn panic(const char *fmt, ...)
16 {
17  va_list args;
18 
19  printk("******************************\n");
20 
21  printk("PANIC: ");
22  va_start(args, fmt);
23  vprintk(fmt, args);
24  va_end(args);
25 
26  printk("******************************\n");
27 
30 }
31 
33 {
34  int i;
35  xen_sysctl_t op = { .cmd = 0 };
36 
37  for ( i = 0; i < 128; i++ )
38  {
39  op.interface_version = i;
40  if ( hypercall_sysctl(&op) != -EACCES )
41  return i;
42  }
43 
44  return -1;
45 }
46 
47 int xtf_get_domid(void)
48 {
49  int rc = xenstore_init();
50 
51  if ( rc )
52  return -1;
53 
54  const char *str = xenstore_read("domid");
55  unsigned int domid = 0;
56 
57  if ( !str || !isdigit(*str) )
58  return -1;
59 
60  while ( isdigit(*str) )
61  {
62  domid = domid * 10 + (*str - '0');
63  str++;
64  }
65 
66  if ( domid >= DOMID_FIRST_RESERVED )
67  return -1;
68 
69  return domid;
70 }
71 
72 /*
73  * Local variables:
74  * mode: C
75  * c-file-style: "BSD"
76  * c-basic-offset: 4
77  * tab-width: 4
78  * indent-tabs-mode: nil
79  * End:
80  */
uint32_t interface_version
Definition: sysctl.h:193
domid_t domid
Definition: memory.h:23
void arch_crash_hard(void)
Definition: traps.c:142
#define __noreturn
Definition: compiler.h:10
#define SHUTDOWN_crash
Definition: sched.h:29
uint32_t cmd
Definition: sysctl.h:191
Interfaces used by common code, needing to be implemented by arch/environment specific code...
#define EACCES
Definition: errno.h:27
void panic(const char *fmt,...)
Definition: lib.c:15
void printk(const char *fmt,...)
Definition: console.c:134
#define va_end(v)
Definition: stdarg.h:11
int xtf_get_domid(void)
Obtain the current domid.
Definition: lib.c:47
static long hypercall_shutdown(unsigned int reason)
Definition: hypercall.h:201
#define va_start(v, l)
Definition: stdarg.h:10
int xenstore_init(void)
Initialise XTF ready for xenstore communication.
Definition: xenbus.c:109
static unsigned int str(void)
Definition: lib.h:366
void vprintk(const char *fmt, va_list args)
Definition: console.c:119
int xtf_probe_sysctl_interface_version(void)
Probe for the SYSCTL_INTERFACE_VERSION in use by the hypervisor.
Definition: lib.c:32
#define DOMID_FIRST_RESERVED
Definition: xen.h:69
const char * xenstore_read(const char *path)
Issue a XS_READ operation for key, waiting synchronously for the reply.
Definition: xenbus.c:115
static long hypercall_sysctl(xen_sysctl_t *arg)
Definition: hypercall.h:182
__builtin_va_list va_list
Definition: stdarg.h:9
static int isdigit(int c)
Definition: lib.c:9
Xenstore driver.