Kernel: Add basic nanosleep, only millisecond percision

This commit is contained in:
Bananymous 2023-09-04 12:58:25 +03:00
parent f1d4d5f995
commit 044378cfa3
5 changed files with 17 additions and 0 deletions

View File

@ -68,6 +68,7 @@ namespace Kernel
BAN::ErrorOr<long> sys_wait(pid_t pid, int* stat_loc, int options); BAN::ErrorOr<long> sys_wait(pid_t pid, int* stat_loc, int options);
BAN::ErrorOr<long> sys_sleep(int seconds); BAN::ErrorOr<long> sys_sleep(int seconds);
BAN::ErrorOr<long> sys_nanosleep(const timespec* rqtp, timespec* rmtp);
BAN::ErrorOr<long> sys_setenvp(char** envp); BAN::ErrorOr<long> sys_setenvp(char** envp);

View File

@ -529,6 +529,13 @@ namespace Kernel
return 0; return 0;
} }
BAN::ErrorOr<long> Process::sys_nanosleep(const timespec* rqtp, timespec* rmtp)
{
(void)rmtp;
SystemTimer::get().sleep(rqtp->tv_sec * 1000 + BAN::Math::div_round_up<uint64_t>(rqtp->tv_nsec, 1'000'000));
return 0;
}
BAN::ErrorOr<long> Process::sys_setenvp(char** envp) BAN::ErrorOr<long> Process::sys_setenvp(char** envp)
{ {
LockGuard _(m_lock); LockGuard _(m_lock);

View File

@ -182,6 +182,9 @@ namespace Kernel
case SYS_FCNTL: case SYS_FCNTL:
ret = Process::current().sys_fcntl((int)arg1, (int)arg2, (int)arg3); ret = Process::current().sys_fcntl((int)arg1, (int)arg2, (int)arg3);
break; break;
case SYS_NANOSLEEP:
ret = Process::current().sys_nanosleep((const timespec*)arg1, (timespec*)arg2);
break;
default: default:
dwarnln("Unknown syscall {}", syscall); dwarnln("Unknown syscall {}", syscall);
break; break;

View File

@ -51,6 +51,7 @@ __BEGIN_DECLS
#define SYS_GET_PGID 44 #define SYS_GET_PGID 44
#define SYS_SET_PGID 45 #define SYS_SET_PGID 45
#define SYS_FCNTL 46 #define SYS_FCNTL 46
#define SYS_NANOSLEEP 47
__END_DECLS __END_DECLS

View File

@ -6,3 +6,8 @@ int clock_gettime(clockid_t clock_id, struct timespec* tp)
{ {
return syscall(SYS_CLOCK_GETTIME, clock_id, tp); return syscall(SYS_CLOCK_GETTIME, clock_id, tp);
} }
int nanosleep(const struct timespec* rqtp, struct timespec* rmtp)
{
return syscall(SYS_NANOSLEEP, rqtp, rmtp);
}