1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:58:11 +00:00

UserspaceEmulator: Implement readlink syscall

This commit is contained in:
Ben Wiederhake 2020-12-07 00:16:28 +01:00 committed by Andreas Kling
parent 88b090a808
commit 809a8ee693
2 changed files with 25 additions and 0 deletions

View file

@ -404,6 +404,8 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
return virt$watch_file(arg1, arg2);
case SC_clock_nanosleep:
return virt$clock_nanosleep(arg1);
case SC_readlink:
return virt$readlink(arg1);
default:
reportln("\n=={}== \033[31;1mUnimplemented syscall: {}\033[0m, {:p}", getpid(), Syscall::to_string((Syscall::Function)function), function);
dump_backtrace();
@ -1527,4 +1529,26 @@ int Emulator::virt$clock_nanosleep(FlatPtr params_addr)
return rc;
}
int Emulator::virt$readlink(FlatPtr params_addr)
{
Syscall::SC_readlink_params params;
mmu().copy_from_vm(&params, params_addr, sizeof(params));
if (params.path.length > PATH_MAX) {
return -ENAMETOOLONG;
}
auto path = mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length);
char host_buffer[PATH_MAX] = {};
size_t host_buffer_size = min(sizeof(host_buffer), params.buffer.size);
Syscall::SC_readlink_params host_params;
host_params.path = { (const char*)path.data(), path.size() };
host_params.buffer = { host_buffer, host_buffer_size };
int rc = syscall(SC_readlink, &host_params);
if (rc < 0)
return rc;
mmu().copy_to_vm((FlatPtr)params.buffer.data, host_buffer, host_buffer_size);
return rc;
}
}