libc+kernel: Add alarm() and getpagesize()
This commit is contained in:
parent
ec3c1132d2
commit
52064e0317
@ -44,6 +44,7 @@ set(SOURCES
|
||||
src/sys/signal.cpp
|
||||
src/sys/socket.cpp
|
||||
src/sys/poll.cpp
|
||||
src/sys/alarm.cpp
|
||||
src/fs/VFS.cpp
|
||||
src/fs/Pipe.cpp
|
||||
src/fs/Mount.cpp
|
||||
|
15
kernel/src/sys/alarm.cpp
Normal file
15
kernel/src/sys/alarm.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "sys/Syscall.h"
|
||||
#include "thread/Scheduler.h"
|
||||
|
||||
Result<u64> sys_alarm(Registers*, SyscallArgs args)
|
||||
{
|
||||
unsigned int seconds = (unsigned int)args[0];
|
||||
|
||||
auto* current = Scheduler::current();
|
||||
|
||||
u64 time_left = current->alarm_ticks_left;
|
||||
|
||||
current->alarm_ticks_left = seconds * 1000;
|
||||
|
||||
return time_left * 1000;
|
||||
}
|
@ -282,6 +282,8 @@ namespace Scheduler
|
||||
{
|
||||
if (thread->sleep_ticks_left == 0 || --thread->sleep_ticks_left == 0) thread->wake_up();
|
||||
}
|
||||
|
||||
if (thread->alarm_ticks_left && --thread->alarm_ticks_left == 0) thread->send_signal(SIGALRM);
|
||||
}
|
||||
|
||||
if (!g_current->ticks_left) switch_task(regs);
|
||||
|
@ -87,6 +87,7 @@ struct Thread : public LinkedListNode<Thread>
|
||||
|
||||
u64 ticks_left;
|
||||
u64 sleep_ticks_left;
|
||||
u64 alarm_ticks_left { 0 };
|
||||
|
||||
Stack stack;
|
||||
Stack kernel_stack;
|
||||
|
@ -190,6 +190,12 @@ extern "C"
|
||||
/* Truncate a file to a specific length. */
|
||||
int ftruncate(int fd, size_t size);
|
||||
|
||||
/* Return the system page size. */
|
||||
int getpagesize(void);
|
||||
|
||||
/* Schedule an alarm signal. */
|
||||
unsigned int alarm(unsigned int seconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/utsname.h>
|
||||
@ -510,4 +511,14 @@ extern "C"
|
||||
long rc = syscall(SYS_ftruncate, fd, size);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int getpagesize(void)
|
||||
{
|
||||
return PAGE_SIZE;
|
||||
}
|
||||
|
||||
unsigned int alarm(unsigned int seconds)
|
||||
{
|
||||
return (unsigned int)syscall(SYS_alarm, seconds);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user