LibC: Implement getrlimit

This commit is contained in:
Bananymous 2024-12-02 03:54:11 +02:00
parent d2b503910f
commit 6346e288ad
3 changed files with 49 additions and 5 deletions

View File

@ -30,6 +30,9 @@ namespace Kernel
Terminated,
};
static constexpr size_t kernel_stack_size { PAGE_SIZE * 8 };
static constexpr size_t userspace_stack_size { PAGE_SIZE * 128 };
public:
static BAN::ErrorOr<Thread*> create_kernel(entry_t, void*, Process*);
static BAN::ErrorOr<Thread*> create_userspace(Process*, PageTable&);
@ -103,8 +106,6 @@ namespace Kernel
// {kernel,userspace}_stack has to be destroyed before page table
BAN::UniqPtr<PageTable> m_keep_alive_page_table;
static constexpr size_t m_kernel_stack_size { PAGE_SIZE * 8 };
static constexpr size_t m_userspace_stack_size { PAGE_SIZE * 128 };
BAN::UniqPtr<VirtualRange> m_kernel_stack;
BAN::UniqPtr<VirtualRange> m_userspace_stack;
const pid_t m_tid { 0 };

View File

@ -64,7 +64,7 @@ namespace Kernel
PageTable::kernel(),
KERNEL_OFFSET,
~(uintptr_t)0,
m_kernel_stack_size,
kernel_stack_size,
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
true
));
@ -104,7 +104,7 @@ namespace Kernel
thread->m_kernel_stack = TRY(VirtualRange::create_to_vaddr_range(
page_table,
0x300000, KERNEL_OFFSET,
m_kernel_stack_size,
kernel_stack_size,
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
true
));
@ -112,7 +112,7 @@ namespace Kernel
thread->m_userspace_stack = TRY(VirtualRange::create_to_vaddr_range(
page_table,
0x300000, KERNEL_OFFSET,
m_userspace_stack_size,
userspace_stack_size,
PageTable::Flags::UserSupervisor | PageTable::Flags::ReadWrite | PageTable::Flags::Present,
true
));

View File

@ -1,7 +1,50 @@
#include <BAN/Assert.h>
#include <BAN/Limits.h>
#include <kernel/Thread.h>
#include <errno.h>
#include <limits.h>
#include <sys/resource.h>
int getrlimit(int resource, struct rlimit* rlp)
{
switch (resource)
{
case RLIMIT_CORE:
rlp->rlim_cur = 0;
rlp->rlim_max = 0;
return 0;
case RLIMIT_CPU:
rlp->rlim_cur = BAN::numeric_limits<rlim_t>::max();
rlp->rlim_max = BAN::numeric_limits<rlim_t>::max();
return 0;
case RLIMIT_DATA:
rlp->rlim_cur = BAN::numeric_limits<rlim_t>::max();
rlp->rlim_max = BAN::numeric_limits<rlim_t>::max();
return 0;
case RLIMIT_FSIZE:
rlp->rlim_cur = BAN::numeric_limits<rlim_t>::max();
rlp->rlim_max = BAN::numeric_limits<rlim_t>::max();
return 0;
case RLIMIT_NOFILE:
rlp->rlim_cur = OPEN_MAX;
rlp->rlim_max = OPEN_MAX;
return 0;
case RLIMIT_STACK:
rlp->rlim_cur = Kernel::Thread::userspace_stack_size;
rlp->rlim_max = Kernel::Thread::userspace_stack_size;
return 0;
case RLIMIT_AS:
rlp->rlim_cur = BAN::numeric_limits<rlim_t>::max();
rlp->rlim_max = BAN::numeric_limits<rlim_t>::max();
return 0;
}
errno = EINVAL;
return -1;
}
int getrusage(int who, struct rusage* r_usage)
{
if (who != RUSAGE_CHILDREN && who != RUSAGE_SELF)