summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/MemoryManager.cpp2
-rw-r--r--Kernel/Process.cpp11
-rw-r--r--Userland/cat.cpp1
-rw-r--r--Userland/sh.cpp34
4 files changed, 24 insertions, 24 deletions
diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp
index 500f57bfb1..4e7c0421f0 100644
--- a/Kernel/MemoryManager.cpp
+++ b/Kernel/MemoryManager.cpp
@@ -152,8 +152,6 @@ auto MemoryManager::ensurePTE(PageDirectory* page_directory, LinearAddress laddr
laddr.get(),
page_table);
#endif
- if (page_table.get() == 0x71d000)
- ASSERT(page_directory == m_kernel_page_directory);
page_directory->physical_addresses[page_directory_index] = page_table;
pde.setPageTableBase(page_table.get());
pde.setUserAllowed(true);
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index c4ef53777f..f0985cf59b 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -346,8 +346,7 @@ int Process::sys$execve(const char* filename, const char** argv, const char** en
new_page_directory = reinterpret_cast<PageDirectory*>(kmalloc_page_aligned(sizeof(PageDirectory)));
MM.populate_page_directory(*new_page_directory);
m_page_directory = new_page_directory;
-
- ProcessPagingScope pagingScope(*this);
+ MM.enter_process_paging_scope(*this);
space.hookableAlloc = [&] (const String& name, size_t size) {
if (!size)
return (void*)nullptr;
@@ -357,11 +356,12 @@ int Process::sys$execve(const char* filename, const char** argv, const char** en
};
bool success = space.loadELF(move(elfData));
if (!success) {
- MM.release_page_directory(*new_page_directory);
m_page_directory = old_page_directory;
+ MM.enter_process_paging_scope(*this);
+ MM.release_page_directory(*new_page_directory);
m_regions = move(old_regions);
m_subregions = move(old_subregions);
- kprintf("Failure loading ELF %s\n", path.characters());
+ kprintf("sys$execve: Failure loading %s\n", path.characters());
return -ENOEXEC;
}
@@ -378,8 +378,9 @@ int Process::sys$execve(const char* filename, const char** argv, const char** en
entry_eip = (dword)space.symbolPtr("_start");
if (!entry_eip) {
- MM.release_page_directory(*new_page_directory);
m_page_directory = old_page_directory;
+ MM.enter_process_paging_scope(*this);
+ MM.release_page_directory(*new_page_directory);
m_regions = move(old_regions);
m_subregions = move(old_subregions);
return -ENOEXEC;
diff --git a/Userland/cat.cpp b/Userland/cat.cpp
index 134e7a2db4..b127bf2cc9 100644
--- a/Userland/cat.cpp
+++ b/Userland/cat.cpp
@@ -5,7 +5,6 @@
int main(int argc, char** argv)
{
- setpgid(0, 0);
if (argc != 2) {
printf("usage: cat <file>\n");
return 1;
diff --git a/Userland/sh.cpp b/Userland/sh.cpp
index 6c83c806e4..8df8ae9c58 100644
--- a/Userland/sh.cpp
+++ b/Userland/sh.cpp
@@ -142,16 +142,15 @@ static bool handle_builtin(int argc, const char** argv, int& retval)
return false;
}
-static int try_spawn(const char* path, const char** argv)
+static int try_exec(const char* path, const char** argv)
{
- int ret = spawn(path, argv);
- if (ret >= 0)
- return ret;
+ int ret = execve(path, argv, nullptr);
+ assert(ret < 0);
const char* search_path = "/bin";
char pathbuf[128];
sprintf(pathbuf, "%s/%s", search_path, argv[0]);
- ret = spawn(pathbuf, argv);
+ ret = execve(pathbuf, argv, nullptr);
if (ret == -1)
return -1;
return ret;
@@ -181,21 +180,24 @@ static int runcmd(char* cmd)
return 0;
}
- int ret = try_spawn(argv[0], argv);
- if (ret < 0) {
- printf("spawn failed: %s (%s)\n", cmd, strerror(errno));
- return 1;
+ pid_t child = fork();
+ if (!child) {
+ setpgid(0, 0);
+ tcsetpgrp(0, getpid());
+ int ret = try_exec(argv[0], argv);
+ if (ret < 0) {
+ printf("exec failed: %s (%s)\n", cmd, strerror(errno));
+ exit(1);
+ }
+ // We should never get here!
+ assert(false);
}
- // FIXME: This is racy, since spawn has already started the new process.
- // Once I have fork()+exec(), pgrp setup can be done in the child before exec()ing.
- tcsetpgrp(0, ret);
-
- // FIXME: waitpid should give us the spawned process's exit status
int wstatus = 0;
- waitpid(ret, &wstatus, 0);
+ waitpid(child, &wstatus, 0);
- // FIXME: Racy as mentioned above. Rework once we have fork()+exec().
+ // FIXME: Should I really have to tcsetpgrp() after my child has exited?
+ // Is the terminal controlling pgrp really still the PGID of the dead process?
tcsetpgrp(0, getpid());
if (WIFEXITED(wstatus)) {