Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
pt_reload: use mmap instead of malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed Apr 6, 2024
1 parent 11146ae commit d3a256e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions elfldr.c
Expand Up @@ -135,8 +135,9 @@ pt_reload(elfldr_ctx_t *ctx, Elf64_Phdr *phdr) {
void* data = 0;
int error = 0;

if(!(data=malloc(memsz))) {
klog_perror("malloc");
if(!(data=mmap(0, memsz, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0))) {
perror("mmap");
return -1;
}

Expand Down Expand Up @@ -185,7 +186,7 @@ pt_reload(elfldr_ctx_t *ctx, Elf64_Phdr *phdr) {
pt_munmap(ctx->pid, addr, memsz);
}

free(data);
munmap(data, memsz);
pt_close(ctx->pid, alias_fd);
pt_close(ctx->pid, shm_fd);

Expand Down

0 comments on commit d3a256e

Please sign in to comment.