Compare commits
No commits in common. "3032415bc0f399e82b3e58072fc04b877ce54ad2" and "9e651314520776ee7d8597680fb923e0db3e4284" have entirely different histories.
3032415bc0
...
9e65131452
@ -71,14 +71,31 @@ 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)
|
Result<u64> Thread::push_mem_on_stack(const u8* mem, usize size)
|
||||||
{
|
{
|
||||||
return MemoryManager::push_mem_on_stack(mem, size, stack, regs.rsp);
|
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)
|
Result<u64> Thread::pop_mem_from_stack(u8* mem, usize size)
|
||||||
{
|
{
|
||||||
return MemoryManager::pop_mem_from_stack(mem, size, stack, regs.rsp);
|
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)
|
bool Thread::deliver_signal(int signo, Registers* current_regs)
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "fs/devices/BlockDevice.h"
|
#include "fs/devices/BlockDevice.h"
|
||||||
#include "fs/devices/DeviceRegistry.h"
|
#include "fs/devices/DeviceRegistry.h"
|
||||||
#include "lib/Mutex.h"
|
#include "lib/Mutex.h"
|
||||||
#include "thread/Thread.h"
|
|
||||||
#include <luna/Atomic.h>
|
#include <luna/Atomic.h>
|
||||||
#include <luna/SharedPtr.h>
|
#include <luna/SharedPtr.h>
|
||||||
#include <luna/StaticString.h>
|
#include <luna/StaticString.h>
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "thread/Thread.h"
|
||||||
#include <luna/CircularQueue.h>
|
#include <luna/CircularQueue.h>
|
||||||
#include <luna/Spinlock.h>
|
#include <luna/Spinlock.h>
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
class Thread;
|
|
||||||
|
|
||||||
class Mutex
|
class Mutex
|
||||||
{
|
{
|
||||||
|
@ -641,30 +641,4 @@ namespace MemoryManager
|
|||||||
{
|
{
|
||||||
return free_mem + used_mem + reserved_mem;
|
return free_mem + used_mem + reserved_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<u64> push_mem_on_stack(const u8* mem, usize size, const Stack& stack, u64& sp)
|
|
||||||
{
|
|
||||||
if ((sp - size) < stack.bottom()) return err(E2BIG);
|
|
||||||
|
|
||||||
if (!MemoryManager::validate_user_write((void*)(sp - size), size)) return err(EFAULT);
|
|
||||||
|
|
||||||
sp -= size;
|
|
||||||
|
|
||||||
memcpy((void*)sp, mem, size);
|
|
||||||
|
|
||||||
return sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<u64> pop_mem_from_stack(u8* mem, usize size, const Stack& stack, u64& sp)
|
|
||||||
{
|
|
||||||
if ((sp + size) > stack.top()) return err(E2BIG);
|
|
||||||
|
|
||||||
if (!MemoryManager::validate_user_read((void*)sp, size)) return err(EFAULT);
|
|
||||||
|
|
||||||
memcpy(mem, (void*)sp, size);
|
|
||||||
|
|
||||||
sp += size;
|
|
||||||
|
|
||||||
return sp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "arch/MMU.h"
|
#include "arch/MMU.h"
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
#include <luna/Stack.h>
|
|
||||||
#include <luna/String.h>
|
#include <luna/String.h>
|
||||||
#include <luna/Types.h>
|
#include <luna/Types.h>
|
||||||
|
|
||||||
@ -89,7 +88,4 @@ namespace MemoryManager
|
|||||||
usize used();
|
usize used();
|
||||||
usize reserved();
|
usize reserved();
|
||||||
usize total();
|
usize total();
|
||||||
|
|
||||||
Result<u64> push_mem_on_stack(const u8* mem, usize size, const Stack& stack, u64& sp);
|
|
||||||
Result<u64> pop_mem_from_stack(u8* mem, usize size, const Stack& stack, u64& sp);
|
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,7 @@ Result<u64> sys_timer_create(Registers*, SyscallArgs args)
|
|||||||
if (ksevp.sigev_signo <= 0 || ksevp.sigev_signo > NSIG) return err(EINVAL);
|
if (ksevp.sigev_signo <= 0 || ksevp.sigev_signo > NSIG) return err(EINVAL);
|
||||||
|
|
||||||
int id = TRY(current->allocate_timerid());
|
int id = TRY(current->allocate_timerid());
|
||||||
|
current->posix_timers[id] = Timer {};
|
||||||
|
|
||||||
Timer* timer = current->posix_timers[id].value_ptr();
|
Timer* timer = current->posix_timers[id].value_ptr();
|
||||||
timer->signo = ksevp.sigev_signo;
|
timer->signo = ksevp.sigev_signo;
|
||||||
|
@ -61,15 +61,10 @@ Result<FileDescriptor*> Thread::resolve_fd(int fd)
|
|||||||
|
|
||||||
Result<int> Thread::allocate_timerid()
|
Result<int> Thread::allocate_timerid()
|
||||||
{
|
{
|
||||||
ScopedMutexLock lock(posix_timer_mutex);
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_POSIX_TIMERS; i++)
|
for (int i = 0; i < MAX_POSIX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
if (!posix_timers[i].has_value())
|
// FIXME: Possible race condition, this should be used alongside a mutex.
|
||||||
{
|
if (!posix_timers[i].has_value()) { return i; }
|
||||||
posix_timers[i] = Timer {};
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err(EMFILE);
|
return err(EMFILE);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "arch/MMU.h"
|
#include "arch/MMU.h"
|
||||||
#include "fs/OpenFileDescription.h"
|
#include "fs/OpenFileDescription.h"
|
||||||
#include "fs/VFS.h"
|
#include "fs/VFS.h"
|
||||||
#include "lib/Mutex.h"
|
|
||||||
#include "memory/AddressSpace.h"
|
#include "memory/AddressSpace.h"
|
||||||
#include <bits/signal.h>
|
#include <bits/signal.h>
|
||||||
#include <luna/Bitset.h>
|
#include <luna/Bitset.h>
|
||||||
@ -110,7 +109,6 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
Clock profiling_clock;
|
Clock profiling_clock;
|
||||||
|
|
||||||
Option<Timer> posix_timers[MAX_POSIX_TIMERS];
|
Option<Timer> posix_timers[MAX_POSIX_TIMERS];
|
||||||
Mutex posix_timer_mutex;
|
|
||||||
|
|
||||||
Result<int> allocate_timerid();
|
Result<int> allocate_timerid();
|
||||||
Result<Timer*> resolve_timerid(int id);
|
Result<Timer*> resolve_timerid(int id);
|
||||||
|
@ -67,7 +67,15 @@ Result<OwnedPtr<ThreadImage>> ThreadImage::clone_from_thread(Thread* parent)
|
|||||||
|
|
||||||
Result<u64> ThreadImage::push_mem_on_stack(const u8* mem, usize size)
|
Result<u64> ThreadImage::push_mem_on_stack(const u8* mem, usize size)
|
||||||
{
|
{
|
||||||
return MemoryManager::push_mem_on_stack(mem, size, m_user_stack, m_sp);
|
if ((m_sp - size) < m_user_stack.bottom()) return err(E2BIG);
|
||||||
|
|
||||||
|
if (!MemoryManager::validate_user_write((void*)(m_sp - size), size)) return err(EFAULT);
|
||||||
|
|
||||||
|
m_sp -= size;
|
||||||
|
|
||||||
|
memcpy((void*)m_sp, mem, size);
|
||||||
|
|
||||||
|
return m_sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<u64> ThreadImage::push_string_vector_on_stack(const Vector<String>& vec)
|
Result<u64> ThreadImage::push_string_vector_on_stack(const Vector<String>& vec)
|
||||||
|
Loading…
Reference in New Issue
Block a user