Commit 89978b5b authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

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: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent efc30c08
#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;
}
#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;
}
#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;
}
#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;
}
......@@ -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;
}
#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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment