Compare commits
No commits in common. "b6fb5f3dfe5b682112f916366ee71b4c378bb04d" and "355dd6c32b775af09d9c4a2170b32cbc32de9d6b" have entirely different histories.
b6fb5f3dfe
...
355dd6c32b
@ -3,7 +3,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static char** split_command_into_argv(const char* cmd)
|
static char** split_command_into_argv(const char* cmd)
|
||||||
@ -95,6 +94,7 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waitpid(child, NULL, 0) < 0) perror("waitpid");
|
// Don't have sched_yield() or waitpid() yet...
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@ set(SOURCES
|
|||||||
src/sys/id.cpp
|
src/sys/id.cpp
|
||||||
src/sys/mkdir.cpp
|
src/sys/mkdir.cpp
|
||||||
src/sys/mknod.cpp
|
src/sys/mknod.cpp
|
||||||
src/sys/waitpid.cpp
|
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/tmpfs/FileSystem.cpp
|
src/fs/tmpfs/FileSystem.cpp
|
||||||
src/fs/devices/DeviceRegistry.cpp
|
src/fs/devices/DeviceRegistry.cpp
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
#include "sys/Syscall.h"
|
#include "sys/Syscall.h"
|
||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
|
|
||||||
Result<u64> sys_exit(Registers*, SyscallArgs args)
|
Result<u64> sys_exit(Registers*, SyscallArgs)
|
||||||
{
|
{
|
||||||
u8 status = (u8)args[0];
|
kernel_exit();
|
||||||
|
|
||||||
Thread* current = Scheduler::current();
|
|
||||||
|
|
||||||
current->status = status;
|
|
||||||
current->state = ThreadState::Exited;
|
|
||||||
|
|
||||||
kernel_yield();
|
|
||||||
unreachable();
|
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
#include "memory/MemoryManager.h"
|
|
||||||
#include "sys/Syscall.h"
|
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
#include <bits/waitpid.h>
|
|
||||||
|
|
||||||
Result<u64> sys_waitpid(Registers*, SyscallArgs args)
|
|
||||||
{
|
|
||||||
pid_t pid = (pid_t)args[0];
|
|
||||||
int* status_ptr = (int*)args[1];
|
|
||||||
int options = (int)args[2];
|
|
||||||
|
|
||||||
Thread* thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
|
||||||
|
|
||||||
while (thread->state != ThreadState::Exited)
|
|
||||||
{
|
|
||||||
if (options & WNOHANG) return err(EAGAIN);
|
|
||||||
kernel_sleep(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = (int)thread->status;
|
|
||||||
|
|
||||||
thread->state = ThreadState::Dying;
|
|
||||||
|
|
||||||
if (status_ptr)
|
|
||||||
if (!MemoryManager::copy_to_user_typed(status_ptr, &status)) return err(EFAULT);
|
|
||||||
|
|
||||||
return (u64)pid;
|
|
||||||
}
|
|
@ -253,17 +253,6 @@ namespace Scheduler
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Option<Thread*> find_by_pid(pid_t pid)
|
|
||||||
{
|
|
||||||
Option<Thread*> result;
|
|
||||||
|
|
||||||
g_threads.for_each([&](Thread* thread) {
|
|
||||||
if (thread->id == (u64)pid && thread->state != ThreadState::Dying) result = thread;
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kernel_sleep(u64 ms)
|
void kernel_sleep(u64 ms)
|
||||||
|
@ -26,8 +26,6 @@ namespace Scheduler
|
|||||||
void invoke(Registers* regs);
|
void invoke(Registers* regs);
|
||||||
|
|
||||||
LinkedList<Thread> check_for_dying_threads();
|
LinkedList<Thread> check_for_dying_threads();
|
||||||
|
|
||||||
Option<Thread*> find_by_pid(pid_t pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void kernel_yield();
|
extern "C" void kernel_yield();
|
||||||
|
@ -19,7 +19,6 @@ enum class ThreadState
|
|||||||
Idle,
|
Idle,
|
||||||
Runnable,
|
Runnable,
|
||||||
Sleeping,
|
Sleeping,
|
||||||
Exited,
|
|
||||||
Dying
|
Dying
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,8 +64,6 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
|
|
||||||
bool is_kernel { true };
|
bool is_kernel { true };
|
||||||
|
|
||||||
u8 status { 0 };
|
|
||||||
|
|
||||||
PageDirectory* directory;
|
PageDirectory* directory;
|
||||||
|
|
||||||
bool is_idle()
|
bool is_idle()
|
||||||
|
@ -15,7 +15,6 @@ set(SOURCES
|
|||||||
src/init.cpp
|
src/init.cpp
|
||||||
src/sys/stat.cpp
|
src/sys/stat.cpp
|
||||||
src/sys/mman.cpp
|
src/sys/mman.cpp
|
||||||
src/sys/wait.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${LUNA_ARCH} STREQUAL "x86_64")
|
if(${LUNA_ARCH} STREQUAL "x86_64")
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
/* bits/waitpid.h: Constants for waitpid(). */
|
|
||||||
|
|
||||||
#ifndef _BITS_WAITPID_H
|
|
||||||
#define _BITS_WAITPID_H
|
|
||||||
|
|
||||||
#define WNOHANG 1
|
|
||||||
|
|
||||||
#endif
|
|
@ -95,10 +95,10 @@ extern "C"
|
|||||||
void srand(int);
|
void srand(int);
|
||||||
|
|
||||||
/* Exit the program normally, performing any registered cleanup actions. */
|
/* Exit the program normally, performing any registered cleanup actions. */
|
||||||
__noreturn void exit(int status);
|
__noreturn void exit(int);
|
||||||
|
|
||||||
/* Exit the program abnormally, without performing any registered cleanup actions. */
|
/* Exit the program abnormally, without performing any registered cleanup actions. */
|
||||||
__noreturn void _Exit(int status);
|
__noreturn void _Exit(int);
|
||||||
|
|
||||||
int system(const char*);
|
int system(const char*);
|
||||||
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
/* sys/wait.h: Functions for waiting. */
|
|
||||||
|
|
||||||
#ifndef _SYS_WAIT_H
|
|
||||||
#define _SYS_WAIT_H
|
|
||||||
|
|
||||||
#include <bits/waitpid.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Wait for a child process to exit. */
|
|
||||||
pid_t waitpid(pid_t pid, int* status, int options);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -94,13 +94,13 @@ extern "C"
|
|||||||
|
|
||||||
__noreturn void abort()
|
__noreturn void abort()
|
||||||
{
|
{
|
||||||
syscall(SYS_exit, 255);
|
syscall(SYS_exit);
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
__noreturn void _Exit(int status)
|
__noreturn void _Exit(int)
|
||||||
{
|
{
|
||||||
syscall(SYS_exit, status);
|
syscall(SYS_exit);
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#include <bits/errno-return.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
pid_t waitpid(pid_t pid, int* status, int options)
|
|
||||||
{
|
|
||||||
long rc = syscall(SYS_waitpid, pid, status, options);
|
|
||||||
__errno_return(rc, pid_t);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#define enumerate_syscalls(_e) \
|
#define enumerate_syscalls(_e) \
|
||||||
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
|
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
|
||||||
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid)
|
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user