mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Kernel: Conditionally acquire the big lock based on syscall metadata
This commit is contained in:
parent
bb1fa019de
commit
120b9bc05b
Notes:
sideshowbarker
2024-07-18 08:42:51 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/120b9bc05bb Pull-request: https://github.com/SerenityOS/serenity/pull/8864 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/gunnarbeutner ✅ Reviewed-by: https://github.com/tomuta ✅
@ -108,8 +108,26 @@ KResultOr<FlatPtr> handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, F
|
||||
auto& process = current_thread->process();
|
||||
current_thread->did_syscall();
|
||||
|
||||
if (function >= Function::__Count) {
|
||||
dbgln("Unknown syscall {} requested ({:08x}, {:08x}, {:08x})", function, arg1, arg2, arg3);
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
const auto syscall_metadata = s_syscall_table[function];
|
||||
if (syscall_metadata.handler == nullptr) {
|
||||
dbgln("Null syscall {} requested, you probably need to rebuild this program!", function);
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
MutexLocker mutex_locker;
|
||||
const auto needs_big_lock = syscall_metadata.needs_lock == NeedsBigProcessLock::Yes;
|
||||
if (needs_big_lock) {
|
||||
mutex_locker.attach_and_lock(process.big_lock());
|
||||
};
|
||||
|
||||
if (function == SC_exit || function == SC_exit_thread) {
|
||||
// These syscalls need special handling since they never return to the caller.
|
||||
// In these cases the process big lock will get released on the exit of the thread.
|
||||
|
||||
if (auto* tracer = process.tracer(); tracer && tracer->is_tracing_syscalls()) {
|
||||
regs.set_return_reg(0);
|
||||
@ -129,23 +147,16 @@ KResultOr<FlatPtr> handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, F
|
||||
}
|
||||
}
|
||||
|
||||
KResultOr<FlatPtr> result { FlatPtr(nullptr) };
|
||||
if (function == SC_fork || function == SC_sigreturn) {
|
||||
// These syscalls want the RegisterState& rather than individual parameters.
|
||||
auto handler = (HandlerWithRegisterState)s_syscall_table[function].handler;
|
||||
return (process.*(handler))(regs);
|
||||
auto handler = (HandlerWithRegisterState)syscall_metadata.handler;
|
||||
result = (process.*(handler))(regs);
|
||||
} else {
|
||||
result = (process.*(syscall_metadata.handler))(arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
if (function >= Function::__Count) {
|
||||
dbgln("Unknown syscall {} requested ({:08x}, {:08x}, {:08x})", function, arg1, arg2, arg3);
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
if (s_syscall_table[function].handler == nullptr) {
|
||||
dbgln("Null syscall {} requested, you probably need to rebuild this program!", function);
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
return (process.*(s_syscall_table[function].handler))(arg1, arg2, arg3);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -204,18 +215,14 @@ NEVER_INLINE void syscall_handler(TrapFrame* trap)
|
||||
FlatPtr arg3;
|
||||
regs.capture_syscall_params(function, arg1, arg2, arg3);
|
||||
|
||||
process.big_lock().lock();
|
||||
|
||||
|
||||
auto result = Syscall::handle(regs, function, arg1, arg2, arg3);
|
||||
|
||||
if (result.is_error()) {
|
||||
regs.set_return_reg(result.error());
|
||||
} else {
|
||||
regs.set_return_reg(result.value());
|
||||
}
|
||||
|
||||
process.big_lock().unlock();
|
||||
|
||||
if (auto tracer = process.tracer(); tracer && tracer->is_tracing_syscalls()) {
|
||||
tracer->set_trace_syscalls(false);
|
||||
process.tracer_trap(*current_thread, regs); // this triggers SIGTRAP and stops the thread!
|
||||
|
Loading…
Reference in New Issue
Block a user