1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-22 13:17:40 +00:00

Kernel: Abstract Processor::assume_context flags using InterruptsState

The details of the specific interrupt bits that must be turned on are
irrelevant to the sys$execve implementation. Abstract it away to the
Processor implementations using the InterruptsState enum.
This commit is contained in:
Idan Horowitz 2023-04-02 03:26:57 +03:00 committed by Andrew Kaster
parent 6ad8f4bb11
commit a349570a04
5 changed files with 9 additions and 13 deletions

View file

@ -255,10 +255,10 @@ void Processor::switch_context(Thread*& from_thread, Thread*& to_thread)
dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context <-- from {} {} to {} {}", VirtualAddress(from_thread), *from_thread, VirtualAddress(to_thread), *to_thread); dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context <-- from {} {} to {} {}", VirtualAddress(from_thread), *from_thread, VirtualAddress(to_thread), *to_thread);
} }
void Processor::assume_context(Thread& thread, FlatPtr flags) void Processor::assume_context(Thread& thread, InterruptsState new_interrupts_state)
{ {
(void)thread; (void)thread;
(void)flags; (void)new_interrupts_state;
TODO_AARCH64(); TODO_AARCH64();
} }

View file

@ -25,6 +25,7 @@ class PageDirectory;
class Thread; class Thread;
class Processor; class Processor;
struct TrapFrame; struct TrapFrame;
enum class InterruptsState;
// FIXME This needs to go behind some sort of platform abstraction // FIXME This needs to go behind some sort of platform abstraction
// it is used between Thread and Processor. // it is used between Thread and Processor.
@ -270,7 +271,7 @@ public:
[[noreturn]] void initialize_context_switching(Thread& initial_thread); [[noreturn]] void initialize_context_switching(Thread& initial_thread);
NEVER_INLINE void switch_context(Thread*& from_thread, Thread*& to_thread); NEVER_INLINE void switch_context(Thread*& from_thread, Thread*& to_thread);
[[noreturn]] static void assume_context(Thread& thread, FlatPtr flags); [[noreturn]] static void assume_context(Thread& thread, InterruptsState new_interrupts_state);
FlatPtr init_context(Thread& thread, bool leave_crit); FlatPtr init_context(Thread& thread, bool leave_crit);
static ErrorOr<Vector<FlatPtr, 32>> capture_stack_trace(Thread& thread, size_t max_frames = 0); static ErrorOr<Vector<FlatPtr, 32>> capture_stack_trace(Thread& thread, size_t max_frames = 0);

View file

@ -1569,7 +1569,7 @@ extern "C" FlatPtr do_init_context(Thread* thread, u32 flags)
return Processor::current().init_context(*thread, true); return Processor::current().init_context(*thread, true);
} }
void Processor::assume_context(Thread& thread, FlatPtr flags) void Processor::assume_context(Thread& thread, InterruptsState new_interrupts_state)
{ {
dbgln_if(CONTEXT_SWITCH_DEBUG, "Assume context for thread {} {}", VirtualAddress(&thread), thread); dbgln_if(CONTEXT_SWITCH_DEBUG, "Assume context for thread {} {}", VirtualAddress(&thread), thread);
@ -1579,6 +1579,7 @@ void Processor::assume_context(Thread& thread, FlatPtr flags)
// and then the scheduler lock // and then the scheduler lock
VERIFY(Processor::in_critical() == 2); VERIFY(Processor::in_critical() == 2);
u32 flags = 2 | (new_interrupts_state == InterruptsState::Enabled ? 0x200 : 0);
do_assume_context(&thread, flags); do_assume_context(&thread, flags);
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();

View file

@ -55,6 +55,7 @@ struct [[gnu::aligned(64), gnu::packed]] FPUState
u8 ext_save_area[256]; u8 ext_save_area[256];
}; };
enum class InterruptsState;
class Processor; class Processor;
// Note: We only support 64 processors at most at the moment, // Note: We only support 64 processors at most at the moment,
// so allocate 64 slots of inline capacity in the container. // so allocate 64 slots of inline capacity in the container.
@ -414,7 +415,7 @@ public:
[[noreturn]] void initialize_context_switching(Thread& initial_thread); [[noreturn]] void initialize_context_switching(Thread& initial_thread);
NEVER_INLINE void switch_context(Thread*& from_thread, Thread*& to_thread); NEVER_INLINE void switch_context(Thread*& from_thread, Thread*& to_thread);
[[noreturn]] static void assume_context(Thread& thread, FlatPtr flags); [[noreturn]] static void assume_context(Thread& thread, InterruptsState new_interrupts_state);
FlatPtr init_context(Thread& thread, bool leave_crit); FlatPtr init_context(Thread& thread, bool leave_crit);
static ErrorOr<Vector<FlatPtr, 32>> capture_stack_trace(Thread& thread, size_t max_frames = 0); static ErrorOr<Vector<FlatPtr, 32>> capture_stack_trace(Thread& thread, size_t max_frames = 0);

View file

@ -980,15 +980,8 @@ ErrorOr<FlatPtr> Process::sys$execve(Userspace<Syscall::SC_execve_params const*>
VERIFY(Processor::in_critical() == 1); VERIFY(Processor::in_critical() == 1);
g_scheduler_lock.lock(); g_scheduler_lock.lock();
current_thread->set_state(Thread::State::Running); current_thread->set_state(Thread::State::Running);
#if ARCH(X86_64) Processor::assume_context(*current_thread, previous_interrupts_state);
FlatPtr prev_flags = previous_interrupts_state == InterruptsState::Enabled ? 0x200 : 0;
Processor::assume_context(*current_thread, prev_flags);
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
#elif ARCH(AARCH64)
TODO_AARCH64();
#else
# error Unknown architecture
#endif
} }
// NOTE: This code path is taken in the non-syscall case, i.e when the kernel spawns // NOTE: This code path is taken in the non-syscall case, i.e when the kernel spawns