mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 04:37:40 +00:00
Kernel: Use Userspace<T> for the execve syscall
This commit is contained in:
parent
025a2a3c5b
commit
0f42463eab
5 changed files with 8 additions and 8 deletions
|
@ -957,7 +957,7 @@ int Emulator::virt$execve(FlatPtr params_addr)
|
||||||
auto copy_string_list = [this](auto& output_vector, auto& string_list) {
|
auto copy_string_list = [this](auto& output_vector, auto& string_list) {
|
||||||
for (size_t i = 0; i < string_list.length; ++i) {
|
for (size_t i = 0; i < string_list.length; ++i) {
|
||||||
Syscall::StringArgument string;
|
Syscall::StringArgument string;
|
||||||
mmu().copy_from_vm(&string, (FlatPtr)&string_list.strings[i], sizeof(string));
|
mmu().copy_from_vm(&string, (FlatPtr)&string_list.strings.ptr()[i], sizeof(string));
|
||||||
output_vector.append(String::copy(mmu().copy_buffer_from_vm((FlatPtr)string.characters, string.length)));
|
output_vector.append(String::copy(mmu().copy_buffer_from_vm((FlatPtr)string.characters, string.length)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -241,7 +241,7 @@ struct ImmutableBufferArgument {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StringListArgument {
|
struct StringListArgument {
|
||||||
StringArgument* strings { nullptr };
|
Userspace<StringArgument*> strings { };
|
||||||
size_t length { 0 };
|
size_t length { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ public:
|
||||||
int sys$ttyname(int fd, Userspace<char*>, size_t);
|
int sys$ttyname(int fd, Userspace<char*>, size_t);
|
||||||
int sys$ptsname(int fd, Userspace<char*>, size_t);
|
int sys$ptsname(int fd, Userspace<char*>, size_t);
|
||||||
pid_t sys$fork(RegisterState&);
|
pid_t sys$fork(RegisterState&);
|
||||||
int sys$execve(const Syscall::SC_execve_params*);
|
int sys$execve(Userspace<const Syscall::SC_execve_params*>);
|
||||||
int sys$dup(int oldfd);
|
int sys$dup(int oldfd);
|
||||||
int sys$dup2(int oldfd, int newfd);
|
int sys$dup2(int oldfd, int newfd);
|
||||||
int sys$sigaction(int signum, const sigaction* act, sigaction* old_act);
|
int sys$sigaction(int signum, const sigaction* act, sigaction* old_act);
|
||||||
|
|
|
@ -544,7 +544,7 @@ int Process::exec(String path, Vector<String> arguments, Vector<String> environm
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$execve(const Syscall::SC_execve_params* user_params)
|
int Process::sys$execve(Userspace<const Syscall::SC_execve_params*> user_params)
|
||||||
{
|
{
|
||||||
REQUIRE_PROMISE(exec);
|
REQUIRE_PROMISE(exec);
|
||||||
|
|
||||||
|
@ -568,14 +568,14 @@ int Process::sys$execve(const Syscall::SC_execve_params* user_params)
|
||||||
path = path_arg.value();
|
path = path_arg.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto copy_user_strings = [&](const auto& list, auto& output) {
|
auto copy_user_strings = [this](const auto& list, auto& output) {
|
||||||
if (!list.length)
|
if (!list.length)
|
||||||
return true;
|
return true;
|
||||||
if (!validate_read_typed(list.strings, list.length))
|
if (!validate_read_typed(list.strings, list.length))
|
||||||
return false;
|
return false;
|
||||||
Vector<Syscall::StringArgument, 32> strings;
|
Vector<Syscall::StringArgument, 32> strings;
|
||||||
strings.resize(list.length);
|
strings.resize(list.length);
|
||||||
copy_from_user(strings.data(), list.strings, list.length * sizeof(Syscall::StringArgument));
|
copy_from_user(strings.data(), list.strings.unsafe_userspace_ptr(), list.length * sizeof(Syscall::StringArgument));
|
||||||
for (size_t i = 0; i < list.length; ++i) {
|
for (size_t i = 0; i < list.length; ++i) {
|
||||||
auto string = validate_and_copy_string_from_user(strings[i]);
|
auto string = validate_and_copy_string_from_user(strings[i]);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
|
|
|
@ -94,8 +94,8 @@ int execve(const char* filename, char* const argv[], char* const envp[])
|
||||||
auto copy_strings = [&](auto& vec, size_t count, auto& output) {
|
auto copy_strings = [&](auto& vec, size_t count, auto& output) {
|
||||||
output.length = count;
|
output.length = count;
|
||||||
for (size_t i = 0; vec[i]; ++i) {
|
for (size_t i = 0; vec[i]; ++i) {
|
||||||
output.strings[i].characters = vec[i];
|
output.strings.ptr()[i].characters = vec[i];
|
||||||
output.strings[i].length = strlen(vec[i]);
|
output.strings.ptr()[i].length = strlen(vec[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue