Compare commits
No commits in common. "cde467ee465cd821a71f068bfd89a6f6100d0175" and "15199a2366fa5db61f2b320bc8f53a420a314577" have entirely different histories.
cde467ee46
...
15199a2366
@ -30,7 +30,6 @@ luna_app(uname.cpp uname)
|
|||||||
luna_app(base64.cpp base64)
|
luna_app(base64.cpp base64)
|
||||||
luna_app(login.cpp login)
|
luna_app(login.cpp login)
|
||||||
luna_app(ipc-test.cpp ipc-test)
|
luna_app(ipc-test.cpp ipc-test)
|
||||||
luna_app(signal-test.cpp signal-test)
|
|
||||||
luna_app(mount.cpp mount)
|
luna_app(mount.cpp mount)
|
||||||
luna_app(umount.cpp umount)
|
luna_app(umount.cpp umount)
|
||||||
luna_app(ps.cpp ps)
|
luna_app(ps.cpp ps)
|
||||||
|
@ -328,14 +328,7 @@ int main()
|
|||||||
{
|
{
|
||||||
if (service.pid.has_value() && service.pid.value() == child)
|
if (service.pid.has_value() && service.pid.value() == child)
|
||||||
{
|
{
|
||||||
if (WIFEXITED(status))
|
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
||||||
{
|
|
||||||
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
do_log("[init] service %s was terminated by signal %d\n", service.name.chars(), WTERMSIG(status));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (service.restart)
|
if (service.restart)
|
||||||
{
|
{
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void handler(int)
|
|
||||||
{
|
|
||||||
puts("I'm a signal handler");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
struct sigaction sa;
|
|
||||||
sa.sa_handler = handler;
|
|
||||||
sigaction(SIGABRT, &sa, NULL);
|
|
||||||
|
|
||||||
raise(SIGABRT);
|
|
||||||
|
|
||||||
puts("I'm outside the signal handler!");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -40,7 +40,6 @@ set(SOURCES
|
|||||||
src/sys/uname.cpp
|
src/sys/uname.cpp
|
||||||
src/sys/mount.cpp
|
src/sys/mount.cpp
|
||||||
src/sys/resource.cpp
|
src/sys/resource.cpp
|
||||||
src/sys/signal.cpp
|
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/Pipe.cpp
|
src/fs/Pipe.cpp
|
||||||
src/fs/Mount.cpp
|
src/fs/Mount.cpp
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
#include "thread/Thread.h"
|
#include "thread/Thread.h"
|
||||||
#include "Log.h"
|
|
||||||
#include "memory/MemoryManager.h"
|
|
||||||
#include <luna/Alignment.h>
|
|
||||||
#include <luna/CString.h>
|
#include <luna/CString.h>
|
||||||
#include <luna/Check.h>
|
|
||||||
|
|
||||||
bool is_in_kernel(Registers* regs)
|
bool is_in_kernel(Registers* regs)
|
||||||
{
|
{
|
||||||
@ -35,11 +31,6 @@ void Thread::set_return(u64 ret)
|
|||||||
regs.rax = ret;
|
regs.rax = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 Thread::return_register()
|
|
||||||
{
|
|
||||||
return regs.rax;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thread::init_regs_kernel()
|
void Thread::init_regs_kernel()
|
||||||
{
|
{
|
||||||
memset(®s, 0, sizeof(Registers));
|
memset(®s, 0, sizeof(Registers));
|
||||||
@ -70,87 +61,3 @@ void switch_context(Thread* old_thread, Thread* new_thread, Registers* regs)
|
|||||||
|
|
||||||
memcpy(regs, &new_thread->regs, sizeof(Registers));
|
memcpy(regs, &new_thread->regs, sizeof(Registers));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Move this function to a common location (also used in ThreadImage)
|
|
||||||
Result<u64> Thread::push_mem_on_stack(const u8* mem, usize size)
|
|
||||||
{
|
|
||||||
if ((regs.rsp - size) < stack.bottom()) return err(E2BIG);
|
|
||||||
|
|
||||||
if (!MemoryManager::validate_user_write((void*)(regs.rsp - size), size)) return err(EFAULT);
|
|
||||||
|
|
||||||
regs.rsp -= size;
|
|
||||||
|
|
||||||
memcpy((void*)regs.rsp, mem, size);
|
|
||||||
|
|
||||||
return regs.rsp;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<u64> Thread::pop_mem_from_stack(u8* mem, usize size)
|
|
||||||
{
|
|
||||||
if ((regs.rsp + size) > stack.top()) return err(E2BIG);
|
|
||||||
|
|
||||||
if (!MemoryManager::validate_user_read((void*)regs.rsp, size)) return err(EFAULT);
|
|
||||||
|
|
||||||
memcpy(mem, (void*)regs.rsp, size);
|
|
||||||
|
|
||||||
regs.rsp += size;
|
|
||||||
|
|
||||||
return regs.rsp;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Thread::deliver_signal(int signo, Registers* current_regs)
|
|
||||||
{
|
|
||||||
auto handler = signal_handlers[signo - 1];
|
|
||||||
check(handler.sa_handler != SIG_IGN);
|
|
||||||
check(handler.sa_handler != SIG_DFL);
|
|
||||||
|
|
||||||
memcpy(®s, current_regs, sizeof(regs));
|
|
||||||
|
|
||||||
kinfoln("signal: delivering signal %d for thread %ld, ip=%p, sp=%p, handler=%p, sigreturn=%p", signo, id,
|
|
||||||
(void*)regs.rip, (void*)regs.rsp, (void*)handler.sa_handler, (void*)handler.__sa_sigreturn);
|
|
||||||
|
|
||||||
regs.rsp -= 128; // Skip the red zone
|
|
||||||
|
|
||||||
if (push_mem_on_stack((u8*)current_regs, sizeof(*current_regs)).has_error()) return false;
|
|
||||||
if (push_mem_on_stack((u8*)&signal_mask, sizeof(signal_mask)).has_error()) return false;
|
|
||||||
|
|
||||||
u64 rsp = regs.rsp;
|
|
||||||
|
|
||||||
regs.rsp = align_down<16>(regs.rsp);
|
|
||||||
if (push_mem_on_stack((u8*)&rsp, sizeof(u64)).has_error()) return false;
|
|
||||||
if (push_mem_on_stack((u8*)&handler.__sa_sigreturn, sizeof(void*)).has_error()) return false;
|
|
||||||
|
|
||||||
// FIXME: Do not add the current signal to the signal mask if SA_NODEFER is set.
|
|
||||||
signal_mask = handler.sa_mask | (1 << (signo - 1));
|
|
||||||
|
|
||||||
rsp = regs.rsp;
|
|
||||||
|
|
||||||
init_regs_user();
|
|
||||||
regs.rsp = rsp;
|
|
||||||
regs.rip = (u64)handler.sa_handler;
|
|
||||||
regs.rdi = signo;
|
|
||||||
|
|
||||||
memcpy(current_regs, ®s, sizeof(regs));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thread::sigreturn(Registers* current_regs)
|
|
||||||
{
|
|
||||||
memcpy(®s, current_regs, sizeof(regs));
|
|
||||||
|
|
||||||
u64 rsp;
|
|
||||||
pop_mem_from_stack((u8*)&rsp, sizeof(rsp));
|
|
||||||
regs.rsp = rsp;
|
|
||||||
pop_mem_from_stack((u8*)&signal_mask, sizeof(signal_mask));
|
|
||||||
pop_mem_from_stack((u8*)current_regs, sizeof(*current_regs));
|
|
||||||
memcpy(®s, current_regs, sizeof(regs));
|
|
||||||
regs.cs = 0x18 | 3;
|
|
||||||
regs.ss = 0x20 | 3;
|
|
||||||
// FIXME: Using this, a program can craft a special RFLAGS that gives them a higher IOPL or other stuff. Find out
|
|
||||||
// exactly what bits to block from modifying.
|
|
||||||
|
|
||||||
kinfoln("sigreturn: restored program state, sp=%p, ip=%p", (void*)regs.rsp, (void*)regs.rip);
|
|
||||||
|
|
||||||
memcpy(current_regs, ®s, sizeof(regs));
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "sys/Syscall.h"
|
#include "sys/Syscall.h"
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
#include <luna/SystemError.h>
|
#include <luna/SystemError.h>
|
||||||
|
|
||||||
syscall_func_t syscalls[] = {
|
syscall_func_t syscalls[] = {
|
||||||
@ -14,9 +13,6 @@ i64 invoke_syscall(Registers* regs, SyscallArgs args, u64 syscall)
|
|||||||
if (syscall >= Syscalls::__count) { return -ENOSYS; }
|
if (syscall >= Syscalls::__count) { return -ENOSYS; }
|
||||||
|
|
||||||
auto rc = syscalls[syscall](regs, args);
|
auto rc = syscalls[syscall](regs, args);
|
||||||
|
|
||||||
Scheduler::current()->process_pending_signals(regs);
|
|
||||||
|
|
||||||
if (rc.has_error()) return -rc.error();
|
if (rc.has_error()) return -rc.error();
|
||||||
return (i64)rc.value();
|
return (i64)rc.value();
|
||||||
}
|
}
|
||||||
|
@ -112,11 +112,6 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
|
|||||||
|
|
||||||
memcpy(regs, ¤t->regs, sizeof(*regs));
|
memcpy(regs, ¤t->regs, sizeof(*regs));
|
||||||
|
|
||||||
for (int i = 0; i < NSIG; i++)
|
|
||||||
{
|
|
||||||
current->signal_handlers[i] = { .sa_handler = SIG_DFL, .sa_mask = 0, .sa_flags = 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
kinfoln("exec: thread %lu was replaced with %s", current->id, path.chars());
|
kinfoln("exec: thread %lu was replaced with %s", current->id, path.chars());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -156,13 +151,6 @@ Result<u64> sys_fork(Registers* regs, SyscallArgs)
|
|||||||
|
|
||||||
memcpy(&thread->regs, regs, sizeof(*regs));
|
memcpy(&thread->regs, regs, sizeof(*regs));
|
||||||
|
|
||||||
for (int i = 0; i < NSIG; i++)
|
|
||||||
{
|
|
||||||
auto sighandler = current->signal_handlers[i].sa_handler;
|
|
||||||
thread->signal_handlers[i] = { .sa_handler = sighandler, .sa_mask = 0, .sa_flags = 0 };
|
|
||||||
}
|
|
||||||
thread->signal_mask = current->signal_mask;
|
|
||||||
|
|
||||||
thread->set_return(0);
|
thread->set_return(0);
|
||||||
|
|
||||||
Scheduler::add_thread(thread);
|
Scheduler::add_thread(thread);
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
#include "Log.h"
|
|
||||||
#include "memory/MemoryManager.h"
|
|
||||||
#include "sys/Syscall.h"
|
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
|
|
||||||
Result<u64> sys_sigreturn(Registers* regs, SyscallArgs)
|
|
||||||
{
|
|
||||||
auto* current = Scheduler::current();
|
|
||||||
|
|
||||||
current->sigreturn(regs);
|
|
||||||
|
|
||||||
// Since we could be returning to anywhere in the program, we don't want to be changing the return value register
|
|
||||||
// (RAX on x86_64). But our syscall framework doesn't allow that, so we just set it to its current value.
|
|
||||||
return current->return_register();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<u64> sys_sigaction(Registers*, SyscallArgs args)
|
|
||||||
{
|
|
||||||
auto* current = Scheduler::current();
|
|
||||||
|
|
||||||
int signo = (int)args[0];
|
|
||||||
const struct sigaction* act = (const struct sigaction*)args[1];
|
|
||||||
struct sigaction* oldact = (struct sigaction*)args[2];
|
|
||||||
void* sigreturn = (void*)args[3];
|
|
||||||
|
|
||||||
if (signo > NSIG) return err(EINVAL);
|
|
||||||
if (signo <= 0) return err(EINVAL);
|
|
||||||
|
|
||||||
if (oldact)
|
|
||||||
{
|
|
||||||
if (!MemoryManager::copy_to_user_typed(oldact, ¤t->signal_handlers[signo - 1])) return err(EFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (act)
|
|
||||||
{
|
|
||||||
struct sigaction kact;
|
|
||||||
if (!MemoryManager::copy_from_user_typed(act, &kact)) return err(EFAULT);
|
|
||||||
kact.__sa_sigreturn = sigreturn;
|
|
||||||
|
|
||||||
kinfoln("sigaction: installing signal handler for signo=%d: handler=%p, sigreturn=%p", signo,
|
|
||||||
(void*)kact.sa_handler, sigreturn);
|
|
||||||
|
|
||||||
current->signal_handlers[signo - 1] = kact;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<u64> sys_kill(Registers*, SyscallArgs args)
|
|
||||||
{
|
|
||||||
auto* current = Scheduler::current();
|
|
||||||
|
|
||||||
pid_t pid = (pid_t)args[0];
|
|
||||||
int signo = (int)args[1];
|
|
||||||
|
|
||||||
// FIXME: Support this case.
|
|
||||||
if (pid <= 0) return err(ENOTSUP);
|
|
||||||
|
|
||||||
auto* target = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
|
||||||
if (current->auth.euid != 0 && current->auth.euid != target->auth.euid && current->auth.egid != target->auth.egid)
|
|
||||||
return err(EPERM);
|
|
||||||
if (target->is_kernel) return 0;
|
|
||||||
if (signo == 0) return 0;
|
|
||||||
|
|
||||||
target->send_signal(signo);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -155,11 +155,6 @@ namespace Scheduler
|
|||||||
image->apply(thread);
|
image->apply(thread);
|
||||||
thread->set_arguments(args.size(), argv, env.size(), envp);
|
thread->set_arguments(args.size(), argv, env.size(), envp);
|
||||||
|
|
||||||
for (int i = 0; i < NSIG; i++)
|
|
||||||
{
|
|
||||||
thread->signal_handlers[i] = { .sa_handler = SIG_DFL, .sa_mask = 0, .sa_flags = 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
kinfoln("Created userspace thread: id %lu with ip %#.16lx and sp %#.16lx (ksp %#lx)", thread->id, thread->ip(),
|
kinfoln("Created userspace thread: id %lu with ip %#.16lx and sp %#.16lx (ksp %#lx)", thread->id, thread->ip(),
|
||||||
thread->sp(), thread->kernel_stack.top());
|
thread->sp(), thread->kernel_stack.top());
|
||||||
|
|
||||||
@ -264,7 +259,6 @@ namespace Scheduler
|
|||||||
Thread* old_thread = g_current;
|
Thread* old_thread = g_current;
|
||||||
Thread* new_thread = pick_task();
|
Thread* new_thread = pick_task();
|
||||||
generic_switch_context(old_thread, new_thread, regs);
|
generic_switch_context(old_thread, new_thread, regs);
|
||||||
if (!is_in_kernel(regs)) new_thread->process_pending_signals(regs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke(Registers* regs)
|
void invoke(Registers* regs)
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
#include "thread/Thread.h"
|
#include "thread/Thread.h"
|
||||||
#include "Log.h"
|
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
#include <bits/atfile.h>
|
#include <bits/atfile.h>
|
||||||
#include <bits/open-flags.h>
|
#include <bits/open-flags.h>
|
||||||
#include <bits/waitpid.h>
|
|
||||||
#include <luna/Alloc.h>
|
#include <luna/Alloc.h>
|
||||||
#include <luna/Atomic.h>
|
#include <luna/Atomic.h>
|
||||||
#include <luna/PathParser.h>
|
#include <luna/PathParser.h>
|
||||||
@ -71,7 +69,7 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
|||||||
return VFS::resolve_path(path.chars(), this->auth, descriptor->inode, follow_last_symlink);
|
return VFS::resolve_path(path.chars(), this->auth, descriptor->inode, follow_last_symlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void Thread::exit_and_signal_parent(int _status)
|
[[noreturn]] void Thread::exit_and_signal_parent(u8 _status)
|
||||||
{
|
{
|
||||||
if (this->id == 1) fail("the init process exited");
|
if (this->id == 1) fail("the init process exited");
|
||||||
if (is_kernel) state = ThreadState::Dying;
|
if (is_kernel) state = ThreadState::Dying;
|
||||||
@ -99,66 +97,6 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
|||||||
unreachable();
|
unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DefaultSignalAction
|
|
||||||
{
|
|
||||||
Ignore,
|
|
||||||
Terminate,
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr DefaultSignalAction default_actions[] = {
|
|
||||||
DefaultSignalAction::Terminate // SIGABRT
|
|
||||||
};
|
|
||||||
|
|
||||||
void Thread::process_pending_signals(Registers* current_regs)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < NSIG; i++)
|
|
||||||
{
|
|
||||||
if (signal_mask & (1 << i)) continue;
|
|
||||||
if (pending_signals & (1 << i))
|
|
||||||
{
|
|
||||||
int signo = i + 1;
|
|
||||||
pending_signals &= ~(1 << i);
|
|
||||||
kinfoln("signal: executing signal %d for thread %ld", signo, id);
|
|
||||||
auto handler = signal_handlers[i];
|
|
||||||
if (handler.sa_handler == SIG_IGN)
|
|
||||||
{
|
|
||||||
kinfoln("signal: ignoring signal (handler=SIG_IGN)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (handler.sa_handler == SIG_DFL)
|
|
||||||
{
|
|
||||||
default_signal:
|
|
||||||
if (id == 1)
|
|
||||||
{
|
|
||||||
kwarnln("signal: init got a signal it has no handler for, ignoring");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
kinfoln("signal: using default behavior (handler=SIG_DFL)");
|
|
||||||
|
|
||||||
auto action = default_actions[i];
|
|
||||||
switch (action)
|
|
||||||
{
|
|
||||||
case DefaultSignalAction::Ignore: return;
|
|
||||||
// FIXME: Add signal exit codes.
|
|
||||||
case DefaultSignalAction::Terminate: exit_and_signal_parent(signo | _SIGBIT);
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If we fail to deliver the signal (usually because there's not enough space on the stack), execute the
|
|
||||||
// default action.
|
|
||||||
if (!deliver_signal(signo, current_regs)) goto default_signal;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thread::send_signal(int signo)
|
|
||||||
{
|
|
||||||
check(signo > 0 && signo <= NSIG);
|
|
||||||
pending_signals |= 1 << (signo - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileDescriptor::should_append()
|
bool FileDescriptor::should_append()
|
||||||
{
|
{
|
||||||
return flags & O_APPEND;
|
return flags & O_APPEND;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "arch/MMU.h"
|
#include "arch/MMU.h"
|
||||||
#include "fs/VFS.h"
|
#include "fs/VFS.h"
|
||||||
#include "memory/AddressSpace.h"
|
#include "memory/AddressSpace.h"
|
||||||
#include <bits/signal.h>
|
|
||||||
#include <luna/LinkedList.h>
|
#include <luna/LinkedList.h>
|
||||||
#include <luna/OwnedPtr.h>
|
#include <luna/OwnedPtr.h>
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
@ -80,18 +79,13 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
bool follow_last_symlink,
|
bool follow_last_symlink,
|
||||||
SharedPtr<VFS::Inode>* parent_inode = nullptr);
|
SharedPtr<VFS::Inode>* parent_inode = nullptr);
|
||||||
|
|
||||||
struct sigaction signal_handlers[NSIG];
|
|
||||||
sigset_t signal_mask { 0 };
|
|
||||||
|
|
||||||
int pending_signals { 0 };
|
|
||||||
|
|
||||||
FPData fp_data;
|
FPData fp_data;
|
||||||
|
|
||||||
ThreadState state = ThreadState::Runnable;
|
ThreadState state = ThreadState::Runnable;
|
||||||
|
|
||||||
bool is_kernel { true };
|
bool is_kernel { true };
|
||||||
|
|
||||||
int status { 0 };
|
u8 status { 0 };
|
||||||
|
|
||||||
mode_t umask { 0 };
|
mode_t umask { 0 };
|
||||||
|
|
||||||
@ -110,7 +104,7 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
|
|
||||||
PageDirectory* active_directory { nullptr };
|
PageDirectory* active_directory { nullptr };
|
||||||
|
|
||||||
[[noreturn]] void exit_and_signal_parent(int status);
|
[[noreturn]] void exit_and_signal_parent(u8 status);
|
||||||
|
|
||||||
bool is_idle()
|
bool is_idle()
|
||||||
{
|
{
|
||||||
@ -134,17 +128,6 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
u64 sp();
|
u64 sp();
|
||||||
|
|
||||||
void set_return(u64 ret);
|
void set_return(u64 ret);
|
||||||
u64 return_register();
|
|
||||||
|
|
||||||
void process_pending_signals(Registers* current_regs);
|
|
||||||
|
|
||||||
bool deliver_signal(int signo, Registers* current_regs);
|
|
||||||
void sigreturn(Registers* current_regs);
|
|
||||||
|
|
||||||
Result<u64> push_mem_on_stack(const u8* mem, usize size);
|
|
||||||
Result<u64> pop_mem_from_stack(u8* mem, usize size);
|
|
||||||
|
|
||||||
void send_signal(int signo);
|
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,6 @@ set(SOURCES
|
|||||||
src/grp.cpp
|
src/grp.cpp
|
||||||
src/locale.cpp
|
src/locale.cpp
|
||||||
src/scanf.cpp
|
src/scanf.cpp
|
||||||
src/signal.cpp
|
|
||||||
src/sys/stat.cpp
|
src/sys/stat.cpp
|
||||||
src/sys/mman.cpp
|
src/sys/mman.cpp
|
||||||
src/sys/wait.cpp
|
src/sys/wait.cpp
|
||||||
@ -37,7 +36,6 @@ if(${LUNA_ARCH} STREQUAL "x86_64")
|
|||||||
${SOURCES}
|
${SOURCES}
|
||||||
src/arch/x86_64/syscall.S
|
src/arch/x86_64/syscall.S
|
||||||
src/arch/x86_64/setjmp.S
|
src/arch/x86_64/setjmp.S
|
||||||
src/arch/x86_64/sigreturn.S
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/* bits/signal.h: Signal-related definitions. */
|
|
||||||
|
|
||||||
#ifndef _BITS_SIGNAL_H
|
|
||||||
#define _BITS_SIGNAL_H
|
|
||||||
|
|
||||||
typedef void (*__simple_sighandler_t)(int);
|
|
||||||
|
|
||||||
#define SIG_IGN (__simple_sighandler_t)(-1)
|
|
||||||
#define SIG_DFL (__simple_sighandler_t)(-2)
|
|
||||||
|
|
||||||
typedef int sigset_t;
|
|
||||||
|
|
||||||
struct sigaction
|
|
||||||
{
|
|
||||||
__simple_sighandler_t sa_handler;
|
|
||||||
sigset_t sa_mask;
|
|
||||||
int sa_flags;
|
|
||||||
void* __sa_sigreturn = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum __signals
|
|
||||||
{
|
|
||||||
SIGABRT = 1,
|
|
||||||
__NSIG,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define NSIG (__NSIG - 1)
|
|
||||||
|
|
||||||
#endif
|
|
@ -3,8 +3,6 @@
|
|||||||
#ifndef _BITS_WAITPID_H
|
#ifndef _BITS_WAITPID_H
|
||||||
#define _BITS_WAITPID_H
|
#define _BITS_WAITPID_H
|
||||||
|
|
||||||
#define _SIGBIT 0x100
|
|
||||||
|
|
||||||
#define WNOHANG 1
|
#define WNOHANG 1
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,30 +3,6 @@
|
|||||||
#ifndef _SIGNAL_H
|
#ifndef _SIGNAL_H
|
||||||
#define _SIGNAL_H
|
#define _SIGNAL_H
|
||||||
|
|
||||||
#include <bits/signal.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef int sig_atomic_t;
|
typedef int sig_atomic_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma GCC push_options
|
|
||||||
#pragma GCC diagnostic ignored "-Wshadow"
|
|
||||||
/* Examine/change the current thread's signal disposition for a specific signal. */
|
|
||||||
int sigaction(int signo, const struct sigaction* act, struct sigaction* oldact);
|
|
||||||
#pragma GCC pop_options
|
|
||||||
|
|
||||||
/* Send a signal to a specific process. */
|
|
||||||
int kill(pid_t pid, int signo);
|
|
||||||
|
|
||||||
/* Send a signal to the current thread. */
|
|
||||||
int raise(int signo);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,10 +6,8 @@
|
|||||||
#include <bits/waitpid.h>
|
#include <bits/waitpid.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define WIFEXITED(ret) (((ret)&_SIGBIT) == 0)
|
#define WIFEXITED(ret) ((ret) | 0)
|
||||||
#define WEXITSTATUS(ret) ((ret)&0xff)
|
#define WEXITSTATUS(ret) ((ret)&0xff)
|
||||||
#define WIFSIGNALED(ret) (((ret)&_SIGBIT) == _SIGBIT)
|
|
||||||
#define WTERMSIG(ret) ((ret)&0xff)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
.global sigreturn
|
|
||||||
sigreturn:
|
|
||||||
mov $47, %rax
|
|
||||||
int $66
|
|
||||||
ud2
|
|
@ -1,26 +0,0 @@
|
|||||||
#include <bits/errno-return.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
extern "C" void sigreturn();
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
int sigaction(int signo, const struct sigaction* act, struct sigaction* oldact)
|
|
||||||
{
|
|
||||||
long rc = syscall(SYS_sigaction, signo, act, oldact, sigreturn);
|
|
||||||
__errno_return(rc, int);
|
|
||||||
}
|
|
||||||
|
|
||||||
int kill(pid_t pid, int signo)
|
|
||||||
{
|
|
||||||
long rc = syscall(SYS_kill, pid, signo);
|
|
||||||
__errno_return(rc, int);
|
|
||||||
}
|
|
||||||
|
|
||||||
int raise(int signo)
|
|
||||||
{
|
|
||||||
return kill(getpid(), signo);
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,7 @@
|
|||||||
_e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(fchmodat) _e(fchownat) _e(ioctl) \
|
_e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(fchmodat) _e(fchownat) _e(ioctl) \
|
||||||
_e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname) _e(sethostname) _e(dup2) _e(pipe) _e(mount) \
|
_e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname) _e(sethostname) _e(dup2) _e(pipe) _e(mount) \
|
||||||
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
||||||
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill)
|
_e(pivot_root)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user