From 3ed54889eb63b3d4ff16ea94193bfb7937c6a56b Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 27 Oct 2007 09:02:20 +0000 Subject: [PATCH] Added some more support for the iphone tools. --- mapping.h | 15 +++++++++------ minimal.h | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mapping.h b/mapping.h index 6882d03..3f4fc32 100644 --- a/mapping.h +++ b/mapping.h @@ -7,18 +7,21 @@ #include #include -void *Map(const char *path, size_t *size, bool ro) { +void *Map(const char *path, size_t offset, size_t size, size_t *psize, bool ro) { int fd; _syscall(fd = open(path, ro ? O_RDONLY : O_RDWR)); - struct stat stat; - _syscall(fstat(fd, &stat)); + if (size == _not(size_t)) { + struct stat stat; + _syscall(fstat(fd, &stat)); + size = stat.st_size; + } - if (size != NULL) - *size = stat.st_size; + if (psize != NULL) + *psize = size; void *base; - _syscall(base = mmap(0, stat.st_size, ro ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); + _syscall(base = mmap(NULL, size, ro ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)); _syscall(close(fd)); return base; diff --git a/minimal.h b/minimal.h index 9d3bd20..6e26870 100644 --- a/minimal.h +++ b/minimal.h @@ -1,6 +1,6 @@ #define _assert(expr) \ do if (!(expr)) { \ - fprintf(stderr, "_assert(%s)\n", #expr); \ + fprintf(stderr, "%s(%u): _assert(%u:%s)\n", __FILE__, __LINE__, errno, #expr); \ exit(1); \ } while (false) @@ -20,6 +20,9 @@ #define _trace() \ printf("_trace(%s:%u)\n", __FILE__, __LINE__) +#define _not(type) \ + ((type) ~ (type) 0) + #include #include #include -- 2.47.2