compel: add error constants

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@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Dmitry Safonov 2016-05-06 19:14:58 +03:00 committed by Andrei Vagin
parent efc30c0856
commit 89978b5b1d
6 changed files with 26 additions and 6 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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__ */