Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,20 @@ static long isProcMem(const char* path)
return 0;
}

static int isPathValid(const char* path)
{
if(!path)
return 0;
uintptr_t p = (uintptr_t)path;
for(size_t i = 0; i < 4096; ++i) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 4096 magic constant should be a MACRO constant instead

if(!(getProtection_fast(p + i) & PROT_READ))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not call getprotection if page didn't change, use a local cache.

return 0;
if(!path[i])
return 1;
}
return 0;
}

// buf may not end with NULL and prefix must end with NULL.
static int start_with(char *buf, ssize_t buflen, char *prefix)
{
Expand Down Expand Up @@ -2923,6 +2937,9 @@ EXPORT int32_t my_execv(x64emu_t* emu, const char* path, char* const argv[])

EXPORT int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], char* const envp[])
{
if(!isPathValid(path))
return execve(path, argv, envp);

int self = isProcSelf(path, "exe");
int x64 = FileIsX64ELF(path);
int x86 = my_context->box86path?FileIsX86ELF(path):0;
Expand Down
Loading