LibC: Implement getrlimit
This commit is contained in:
parent
d2b503910f
commit
6346e288ad
|
@ -30,6 +30,9 @@ namespace Kernel
|
||||||
Terminated,
|
Terminated,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr size_t kernel_stack_size { PAGE_SIZE * 8 };
|
||||||
|
static constexpr size_t userspace_stack_size { PAGE_SIZE * 128 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<Thread*> create_kernel(entry_t, void*, Process*);
|
static BAN::ErrorOr<Thread*> create_kernel(entry_t, void*, Process*);
|
||||||
static BAN::ErrorOr<Thread*> create_userspace(Process*, PageTable&);
|
static BAN::ErrorOr<Thread*> create_userspace(Process*, PageTable&);
|
||||||
|
@ -103,8 +106,6 @@ namespace Kernel
|
||||||
// {kernel,userspace}_stack has to be destroyed before page table
|
// {kernel,userspace}_stack has to be destroyed before page table
|
||||||
BAN::UniqPtr<PageTable> m_keep_alive_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_kernel_stack;
|
||||||
BAN::UniqPtr<VirtualRange> m_userspace_stack;
|
BAN::UniqPtr<VirtualRange> m_userspace_stack;
|
||||||
const pid_t m_tid { 0 };
|
const pid_t m_tid { 0 };
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace Kernel
|
||||||
PageTable::kernel(),
|
PageTable::kernel(),
|
||||||
KERNEL_OFFSET,
|
KERNEL_OFFSET,
|
||||||
~(uintptr_t)0,
|
~(uintptr_t)0,
|
||||||
m_kernel_stack_size,
|
kernel_stack_size,
|
||||||
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
|
@ -104,7 +104,7 @@ namespace Kernel
|
||||||
thread->m_kernel_stack = TRY(VirtualRange::create_to_vaddr_range(
|
thread->m_kernel_stack = TRY(VirtualRange::create_to_vaddr_range(
|
||||||
page_table,
|
page_table,
|
||||||
0x300000, KERNEL_OFFSET,
|
0x300000, KERNEL_OFFSET,
|
||||||
m_kernel_stack_size,
|
kernel_stack_size,
|
||||||
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
|
@ -112,7 +112,7 @@ namespace Kernel
|
||||||
thread->m_userspace_stack = TRY(VirtualRange::create_to_vaddr_range(
|
thread->m_userspace_stack = TRY(VirtualRange::create_to_vaddr_range(
|
||||||
page_table,
|
page_table,
|
||||||
0x300000, KERNEL_OFFSET,
|
0x300000, KERNEL_OFFSET,
|
||||||
m_userspace_stack_size,
|
userspace_stack_size,
|
||||||
PageTable::Flags::UserSupervisor | PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
PageTable::Flags::UserSupervisor | PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
|
|
|
@ -1,7 +1,50 @@
|
||||||
#include <BAN/Assert.h>
|
#include <BAN/Assert.h>
|
||||||
|
#include <BAN/Limits.h>
|
||||||
|
|
||||||
|
#include <kernel/Thread.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <sys/resource.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)
|
int getrusage(int who, struct rusage* r_usage)
|
||||||
{
|
{
|
||||||
if (who != RUSAGE_CHILDREN && who != RUSAGE_SELF)
|
if (who != RUSAGE_CHILDREN && who != RUSAGE_SELF)
|
||||||
|
|
Loading…
Reference in New Issue