[PATCH 06/17] Add halt() and some error codes

Andrew Jones
2014-01-21T16:22:35Z

Define a halt function that can be implemented by the test framework
for use on error paths before exit() works. Also add some error codes
that can be passed to halt() in case the serial isn't working either.
Then, on register inspection of the halted guest we may be able to
quickly determine the problem without having to find the halt()
call-site. The error codes may of course also be used with exit().

Signed-off-by: Andrew Jones <drjones@redhat.com>

---
v2:
- keep the error numbers more consistent with the standard numbers
---
lib/errno.h | 22 ++++++++++++++++++++++
lib/libcflat.h | 2 ++
2 files changed, 24 insertions(+)
create mode 100644 lib/errno.h

diff --git a/lib/errno.h b/lib/errno.h
new file mode 100644
index 0000000000000..f60845cdc61f6
--- /dev/null
+++ b/lib/errno.h
@@ -0,0 +1,22 @@
+#ifndef _ERRNO_H_
+#define _ERRNO_H_
+/*
+ * Define some error codes for the test framework's use. qemu
+ * exits with ((code << 1) | 1) when this framework calls
+ * exit(code), so we reserve codes 64 to 126. 127 is left
+ * for exit(-1).
+ *
+ * (Ab)use the standard E* names for syntax highlighting...
+ * The errno descriptions in [] are for non-standard semantics.
+ */
+#define EINTR (64 + 4) /* [unhandled exception] */
+#define EIO (64 + 5) /* I/O error */
+#define ENXIO (64 + 6) /* No such device or address [no serial] */
+#define ENOEXEC (64 + 8) /* Exec format error [bad flat file] */
+#define ENOMEM (64 + 12) /* Out of memory */
+#define ENODEV (64 + 19) /* No such device */
+#define EINVAL (64 + 22) /* Invalid argument */
+#define ENOSPC (64 + 28) /* No space left on device */
+#define ERANGE (64 + 34) /* Math result not representable
+ [divide by zero] */
+#endif
diff --git a/lib/libcflat.h b/lib/libcflat.h
index 140c172e77d54..a1be635ab4ee9 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -37,6 +37,7 @@ typedef _Bool bool;
#define true 1
#define false 0

+extern void halt(int code);
extern void exit(int code);

extern unsigned long strlen(const char *buf);
@@ -57,4 +58,5 @@ extern long atol(const char *ptr);
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)

#define NULL ((void *)0UL)
+#include "errno.h"
#endif
--
1.8.1.4