Skip to content

Commit

Permalink
Ensuring the HAL identification function gets access to the real mmap…
Browse files Browse the repository at this point in the history
… function, while others can rely on the syscall instead
  • Loading branch information
wberube committed May 24, 2024
1 parent d7f3b64 commit 9216437
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRC := $(shell find ./ -name '*.c')

divinus:
$(CC) $(SRC) -I src -rdynamic $(OPT) -o ../$@
$(CC) $(SRC) -I src -rdynamic -Wl,--wrap=mmap $(OPT) -o ../$@
5 changes: 4 additions & 1 deletion src/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ int __fgetc_unlocked(FILE *stream) { return fgetc(stream); }
double __log_finite(double x) { return log(x); }

void* mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) {
return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12);
return (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12);
}
void* __wrap_mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) {
return mmap(start, len, prot, flags, fd, off);
}
4 changes: 3 additions & 1 deletion src/hal/support.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "support.h"

extern __real_mmap();

void *isp_thread = NULL;
void *venc_thread = NULL;

Expand Down Expand Up @@ -32,7 +34,7 @@ bool hal_registry(unsigned int addr, unsigned int *data, hal_register_op op) {

volatile char *mapped_area;
if (offset != loaded_offset) {
mapped_area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset);
mapped_area = (void*)__real_mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset);
if (mapped_area == MAP_FAILED) {
fprintf(stderr, "hal_registry mmap error: %s (%d)\n",
strerror(errno), errno);
Expand Down

0 comments on commit 9216437

Please sign in to comment.