mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
Kernel: Don't leak an FPU state buffer for every spawned thread
We were leaking 512 bytes of kmalloc memory for every new thread. This patch fixes that, and also makes sure to zero out the FPU state buffer after allocating it, and finally also makes the LogStream operator<< for Thread look a little bit nicer. :^)
This commit is contained in:
parent
517e78a7e2
commit
40beb4c5c0
|
@ -50,6 +50,7 @@ Thread::Thread(Process& process)
|
|||
dbgprintf("Thread{%p}: New thread TID=%u in %s(%u)\n", this, m_tid, process.name().characters(), process.pid());
|
||||
set_default_signal_dispositions();
|
||||
m_fpu_state = (FPUState*)kmalloc_aligned(sizeof(FPUState), 16);
|
||||
memset(m_fpu_state, 0, sizeof(FPUState));
|
||||
memset(&m_tss, 0, sizeof(m_tss));
|
||||
|
||||
// Only IF is set when a process boots.
|
||||
|
@ -564,7 +565,6 @@ Thread* Thread::clone(Process& process)
|
|||
auto* clone = new Thread(process);
|
||||
memcpy(clone->m_signal_action_data, m_signal_action_data, sizeof(m_signal_action_data));
|
||||
clone->m_signal_mask = m_signal_mask;
|
||||
clone->m_fpu_state = (FPUState*)kmalloc_aligned(sizeof(FPUState), 16);
|
||||
memcpy(clone->m_fpu_state, m_fpu_state, sizeof(FPUState));
|
||||
clone->m_has_used_fpu = m_has_used_fpu;
|
||||
clone->m_thread_specific_data = m_thread_specific_data;
|
||||
|
@ -658,3 +658,8 @@ void Thread::make_thread_specific_region(Badge<Process>)
|
|||
if (process().m_master_tls_size)
|
||||
memcpy(thread_local_storage, process().m_master_tls_region->vaddr().as_ptr(), process().m_master_tls_size);
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const Thread& value)
|
||||
{
|
||||
return stream << value.process().name() << "(" << value.pid() << ":" << value.tid() << ")";
|
||||
}
|
||||
|
|
|
@ -379,10 +379,7 @@ inline IterationDecision Thread::for_each_in_state(State state, Callback callbac
|
|||
return Scheduler::for_each_nonrunnable(new_callback);
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const Thread& value)
|
||||
{
|
||||
return stream << "Thread{" << &value << "}(" << value.pid() << ":" << value.tid() << ")";
|
||||
}
|
||||
const LogStream& operator<<(const LogStream&, const Thread&);
|
||||
|
||||
struct SchedulerData {
|
||||
typedef IntrusiveList<Thread, &Thread::m_runnable_list_node> ThreadList;
|
||||
|
|
Loading…
Reference in a new issue