[CRIU] [RFC 3/4] compel: add error constants
Dmitry Safonov
dsafonov at virtuozzo.com
Fri May 6 09:14:58 PDT 2016
For tests, we need to know if elf file parsing was interrupted
in a proper place (and thus meaningful error numbers).
Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
compel/arch/aarch64/handle-elf.c | 3 ++-
compel/arch/arm/handle-elf.c | 3 ++-
compel/arch/ppc64/handle-elf.c | 3 ++-
compel/arch/x86/handle-elf.c | 3 ++-
compel/handle-elf.c | 10 ++++++++--
compel/include/uapi/piegen-err.h | 10 ++++++++++
6 files changed, 26 insertions(+), 6 deletions(-)
create mode 100644 compel/include/uapi/piegen-err.h
diff --git a/compel/arch/aarch64/handle-elf.c b/compel/arch/aarch64/handle-elf.c
index 82c282b5f85d..bbd4bf1b0369 100644
--- a/compel/arch/aarch64/handle-elf.c
+++ b/compel/arch/aarch64/handle-elf.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "piegen.h"
+#include "uapi/piegen-err.h"
#include "handle-elf.h"
int handle_binary(void *mem, size_t size)
@@ -16,5 +17,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_aarch64(mem, size);
pr_err("Unsupported Elf format detected\n");
- return -1;
+ return -E_NOT_ELF;
}
diff --git a/compel/arch/arm/handle-elf.c b/compel/arch/arm/handle-elf.c
index 580ed0e4fa15..2692439c71c7 100644
--- a/compel/arch/arm/handle-elf.c
+++ b/compel/arch/arm/handle-elf.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "piegen.h"
+#include "uapi/piegen-err.h"
#include "handle-elf.h"
int handle_binary(void *mem, size_t size)
@@ -9,5 +10,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_arm(mem, size);
pr_err("Unsupported Elf format detected\n");
- return -1;
+ return -E_NOT_ELF;
}
diff --git a/compel/arch/ppc64/handle-elf.c b/compel/arch/ppc64/handle-elf.c
index 9433ef135345..049e3fba0e66 100644
--- a/compel/arch/ppc64/handle-elf.c
+++ b/compel/arch/ppc64/handle-elf.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "piegen.h"
+#include "uapi/piegen-err.h"
#include "handle-elf.h"
int handle_binary(void *mem, size_t size)
@@ -16,5 +17,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_ppc64(mem, size);
pr_err("Unsupported Elf format detected\n");
- return -1;
+ return -E_NOT_ELF;
}
diff --git a/compel/arch/x86/handle-elf.c b/compel/arch/x86/handle-elf.c
index 5a142c9ef601..9edb94262f70 100644
--- a/compel/arch/x86/handle-elf.c
+++ b/compel/arch/x86/handle-elf.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "piegen.h"
+#include "uapi/piegen-err.h"
#include "handle-elf.h"
int handle_binary(void *mem, size_t size)
@@ -11,5 +12,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_x86_64(mem, size);
pr_err("Unsupported Elf format detected\n");
- return -1;
+ return -E_NOT_ELF;
}
diff --git a/compel/handle-elf.c b/compel/handle-elf.c
index 2e8d33c0fbf7..eabff7c4f067 100644
--- a/compel/handle-elf.c
+++ b/compel/handle-elf.c
@@ -13,6 +13,7 @@
#include "asm-generic/int.h"
+#include "uapi/piegen-err.h"
#include "piegen.h"
#include "handle-elf.h"
@@ -142,6 +143,7 @@ int __handle_elf(void *mem, size_t size)
#ifdef ELF_PPC64
s64 toc_offset = 0;
#endif
+ int ret = -E_UNKNOWN;
pr_debug("Header\n");
pr_debug("------------\n");
@@ -150,18 +152,22 @@ int __handle_elf(void *mem, size_t size)
if (!is_header_supported(hdr)) {
pr_err("Unsupported header detected\n");
+ ret = -E_NOT_ELF;
goto err;
}
sec_hdrs = malloc(sizeof(*sec_hdrs) * hdr->e_shnum);
if (!sec_hdrs) {
pr_err("No memory for section headers\n");
+ ret = -E_NOMEM;
goto err;
}
secstrings = get_strings_section(hdr, (uintptr_t)mem, size);
- if (!secstrings)
+ if (!secstrings) {
+ ret = -E_NO_STR_SEC;
goto err;
+ }
pr_debug("Sections\n");
pr_debug("------------\n");
@@ -563,5 +569,5 @@ int __handle_elf(void *mem, size_t size)
return 0;
err:
free(sec_hdrs);
- return -1;
+ return ret;
}
diff --git a/compel/include/uapi/piegen-err.h b/compel/include/uapi/piegen-err.h
new file mode 100644
index 000000000000..f8a2349a1d26
--- /dev/null
+++ b/compel/include/uapi/piegen-err.h
@@ -0,0 +1,10 @@
+#ifndef __PIEGEN_ERR_H__
+#define __PIEGEN_ERR_H__
+
+/* Error numbers for piegen. Success is 0, so errors should differ. */
+#define E_UNKNOWN 1
+#define E_NOMEM 2
+#define E_NOT_ELF 3
+#define E_NO_STR_SEC 4
+
+#endif /* __PIEGEN_ERR_H__ */
--
2.8.0
More information about the CRIU
mailing list