Compare commits
No commits in common. "77ebdda2e0499c4873175f71b94331b921e165a4" and "f45734c61d2c5dba8de71b9d76d58695ead080c8" have entirely different histories.
77ebdda2e0
...
f45734c61d
@ -562,7 +562,7 @@ namespace MemoryManager
|
||||
while (size--)
|
||||
{
|
||||
// Crossed a page boundary, gotta check the page tables again before touching any memory!!
|
||||
if ((user_ptr % ARCH_PAGE_SIZE) == 0)
|
||||
if (user_ptr % ARCH_PAGE_SIZE)
|
||||
{
|
||||
if (!validate_page_access(user_ptr, MMU::ReadWrite | MMU::User)) return false;
|
||||
}
|
||||
@ -590,7 +590,7 @@ namespace MemoryManager
|
||||
while (size--)
|
||||
{
|
||||
// Crossed a page boundary, gotta check the page tables again before touching any memory!!
|
||||
if ((user_ptr % ARCH_PAGE_SIZE) == 0)
|
||||
if (user_ptr % ARCH_PAGE_SIZE)
|
||||
{
|
||||
if (!validate_page_access(user_ptr, MMU::User)) return false;
|
||||
}
|
||||
|
@ -55,8 +55,7 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
|
||||
{
|
||||
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
||||
auto argv = TRY(copy_string_vector_from_userspace(args[1]));
|
||||
Vector<String> envp;
|
||||
if (args[2]) envp = TRY(copy_string_vector_from_userspace(args[2]));
|
||||
auto envp = TRY(copy_string_vector_from_userspace(args[2]));
|
||||
|
||||
if ((calculate_userspace_stack_size(argv) + calculate_userspace_stack_size(envp)) > MAX_ARGV_STACK_SIZE)
|
||||
return err(E2BIG);
|
||||
|
@ -59,37 +59,6 @@ namespace os
|
||||
*/
|
||||
static Result<void> exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path = true);
|
||||
|
||||
/**
|
||||
* @brief Spawn a new process from an executable file.
|
||||
*
|
||||
* @param path The new executable's path.
|
||||
* @param args The argument list to pass to the new process.
|
||||
* @param search_in_path Determines whether to search in the system binary directories if path is just a name.
|
||||
* @return Result<pid_t> An error, or the process ID of the new process.
|
||||
*/
|
||||
static Result<pid_t> spawn(StringView path, Slice<String> args, bool search_in_path = true);
|
||||
|
||||
/**
|
||||
* @brief Spawn a new process from an executable file.
|
||||
*
|
||||
* @param path The new executable's path.
|
||||
* @param args The argument list to pass to the new process.
|
||||
* @param search_in_path Determines whether to search in the system binary directories if path is just a name.
|
||||
* @return Result<pid_t> An error, or the process ID of the new process.
|
||||
*/
|
||||
static Result<pid_t> spawn(StringView path, Slice<StringView> args, bool search_in_path = true);
|
||||
|
||||
/**
|
||||
* @brief Spawn a new process from an executable file.
|
||||
*
|
||||
* @param path The new executable's path.
|
||||
* @param args The argument list to pass to the new process.
|
||||
* @param env The environment to pass to the new process, instead of the current environment.
|
||||
* @param search_in_path Determines whether to search in the system binary directories if path is just a name.
|
||||
* @return Result<pid_t> An error, or the process ID of the new process.
|
||||
*/
|
||||
static Result<pid_t> spawn(StringView path, Slice<String> args, Slice<String> env, bool search_in_path = true);
|
||||
|
||||
// To use as the child argument to wait() to wait for any child.
|
||||
static constexpr pid_t ANY_CHILD = -1;
|
||||
|
||||
|
@ -8,14 +8,11 @@
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <luna/DebugLog.h>
|
||||
#include <os/Process.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char** environ;
|
||||
|
||||
namespace os
|
||||
{
|
||||
Result<pid_t> Process::fork()
|
||||
@ -67,58 +64,6 @@ namespace os
|
||||
return err(errno);
|
||||
}
|
||||
|
||||
static Result<pid_t> do_spawn(const char* path, char** argv, char** envp, bool use_path)
|
||||
{
|
||||
pid_t child = fork();
|
||||
if (child < 0) return err(errno);
|
||||
if (child == 0)
|
||||
{
|
||||
if (use_path) execvpe(path, argv, envp);
|
||||
else
|
||||
execve(path, argv, envp);
|
||||
_exit(127);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
Result<pid_t> Process::spawn(StringView path, Slice<String> args, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
return do_spawn(path.chars(), const_cast<char**>(argv.data()), environ, search_in_path);
|
||||
}
|
||||
|
||||
Result<pid_t> Process::spawn(StringView path, Slice<StringView> args, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
for (const auto& arg : args)
|
||||
{
|
||||
TRY(argv.try_append(arg.chars()));
|
||||
dbgln("os::Process:spawn() adding new argument: %s", arg.chars());
|
||||
}
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
dbgln("os::Process:spawn() invoking do_spawn(): path=%s, argv=%p, envp=%p", path.chars(),
|
||||
const_cast<char**>(argv.data()), environ);
|
||||
|
||||
return do_spawn(path.chars(), const_cast<char**>(argv.data()), environ, search_in_path);
|
||||
}
|
||||
|
||||
Result<pid_t> Process::spawn(StringView path, Slice<String> args, Slice<String> env, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
Vector<const char*> envp;
|
||||
for (const auto& arg : env) { TRY(envp.try_append(arg.chars())); }
|
||||
TRY(envp.try_append(nullptr));
|
||||
|
||||
return do_spawn(path.chars(), const_cast<char**>(argv.data()), const_cast<char**>(envp.data()), search_in_path);
|
||||
}
|
||||
|
||||
Result<pid_t> Process::wait(pid_t child, int* status, int options)
|
||||
{
|
||||
long rc = syscall(SYS_waitpid, child, status, options);
|
||||
|
Loading…
Reference in New Issue
Block a user