summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-10-24 20:38:27 -0400
committermidipix <writeonce@midipix.org>2016-11-10 23:35:52 -0500
commit9a46b6d0483006a8b6e25d2f33f393ec6f16808f (patch)
treee6b105a4d91271a9617194e6303049901838d2da
parent9b7081116d8da0807045911704449a65217211c3 (diff)
downloadperk-9a46b6d0483006a8b6e25d2f33f393ec6f16808f.tar.bz2
perk-9a46b6d0483006a8b6e25d2f33f393ec6f16808f.tar.xz
pe_map_raw_image(): added error trace support.
-rw-r--r--include/perk/perk.h2
-rw-r--r--src/driver/pe_unit_ctx.c2
-rw-r--r--src/logic/pe_map_raw_image.c18
3 files changed, 13 insertions, 9 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h
index be5c079..bb2a05b 100644
--- a/include/perk/perk.h
+++ b/include/perk/perk.h
@@ -188,7 +188,7 @@ perk_api int pe_output_export_symbols (const struct pe_image_meta *, const stru
perk_api int pe_output_import_libraries(const struct pe_image_meta *, const struct pe_common_ctx *, FILE *);
/* high-level api */
-perk_api int pe_map_raw_image (int fd, const char * path, int prot, struct pe_raw_image *);
+perk_api int pe_map_raw_image (const struct pe_driver_ctx *, int fd, const char * path, int prot, struct pe_raw_image *);
perk_api int pe_unmap_raw_image (struct pe_raw_image *);
perk_api int pe_get_image_meta (const struct pe_driver_ctx *, const struct pe_raw_image *, struct pe_image_meta **);
diff --git a/src/driver/pe_unit_ctx.c b/src/driver/pe_unit_ctx.c
index 2ea690e..5330659 100644
--- a/src/driver/pe_unit_ctx.c
+++ b/src/driver/pe_unit_ctx.c
@@ -43,7 +43,7 @@ int pe_get_unit_ctx(
? PROT_READ | PROT_WRITE
: PROT_READ;
- if (pe_map_raw_image(dctx->cctx->ioctx->fdin,path,prot,&ctx->map))
+ if (pe_map_raw_image(dctx,dctx->cctx->ioctx->fdin,path,prot,&ctx->map))
return pe_free_unit_ctx_impl(ctx,
PERK_SYSTEM_ERROR(dctx));
diff --git a/src/logic/pe_map_raw_image.c b/src/logic/pe_map_raw_image.c
index 0598d85..4c6ec92 100644
--- a/src/logic/pe_map_raw_image.c
+++ b/src/logic/pe_map_raw_image.c
@@ -13,12 +13,14 @@
#include <sys/stat.h>
#include <perk/perk.h>
+#include "perk_errinfo_impl.h"
int pe_map_raw_image(
- int fd,
- const char * path,
- int prot,
- struct pe_raw_image * map)
+ const struct pe_driver_ctx * dctx,
+ int fd,
+ const char * path,
+ int prot,
+ struct pe_raw_image * map)
{
struct stat st;
bool fnew;
@@ -28,13 +30,13 @@ int pe_map_raw_image(
fd = open(path,O_RDONLY | O_CLOEXEC);
if (fd < 0)
- return -1;
+ return PERK_SYSTEM_ERROR(dctx);
if ((ret = fstat(fd,&st) < 0) && fnew)
close(fd);
if (ret < 0)
- return -1;
+ return PERK_SYSTEM_ERROR(dctx);
map->size = st.st_size;
map->addr = mmap(0,map->size,prot,MAP_PRIVATE,fd,0);
@@ -42,7 +44,9 @@ int pe_map_raw_image(
if (fnew)
close(fd);
- return (map->addr == MAP_FAILED) ? -1 : 0;
+ return (map->addr == MAP_FAILED)
+ ? PERK_SYSTEM_ERROR(dctx)
+ : 0;
}
int pe_unmap_raw_image(struct pe_raw_image * map)