Skip to content

Commit

Permalink
Kernel/LibC: Implement posix syscall clock_getres()
Browse files Browse the repository at this point in the history
  • Loading branch information
zzSunil authored and awesomekling committed Jul 25, 2022
1 parent a031b7a commit ca74443
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Kernel/API/Syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum class NeedsBigProcessLock {
S(chown, NeedsBigProcessLock::No) \
S(clock_gettime, NeedsBigProcessLock::No) \
S(clock_nanosleep, NeedsBigProcessLock::No) \
S(clock_getres, NeedsBigProcessLock::No) \
S(clock_settime, NeedsBigProcessLock::No) \
S(close, NeedsBigProcessLock::No) \
S(connect, NeedsBigProcessLock::No) \
Expand Down Expand Up @@ -259,6 +260,11 @@ struct SC_clock_nanosleep_params {
struct timespec* remaining_sleep;
};

struct SC_clock_getres_params {
int clock_id;
struct timespec* result;
};

struct SC_accept4_params {
sockaddr* addr;
socklen_t* addrlen;
Expand Down
1 change: 1 addition & 0 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class Process final
ErrorOr<FlatPtr> sys$clock_gettime(clockid_t, Userspace<timespec*>);
ErrorOr<FlatPtr> sys$clock_settime(clockid_t, Userspace<timespec const*>);
ErrorOr<FlatPtr> sys$clock_nanosleep(Userspace<Syscall::SC_clock_nanosleep_params const*>);
ErrorOr<FlatPtr> sys$clock_getres(Userspace<Syscall::SC_clock_getres_params const*>);
ErrorOr<FlatPtr> sys$gethostname(Userspace<char*>, size_t);
ErrorOr<FlatPtr> sys$sethostname(Userspace<char const*>, size_t);
ErrorOr<FlatPtr> sys$uname(Userspace<utsname*>);
Expand Down
17 changes: 17 additions & 0 deletions Kernel/Syscalls/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ ErrorOr<FlatPtr> Process::sys$clock_nanosleep(Userspace<Syscall::SC_clock_nanosl
return 0;
}

ErrorOr<FlatPtr> Process::sys$clock_getres(Userspace<Syscall::SC_clock_getres_params const*> user_params)
{
VERIFY_NO_PROCESS_BIG_LOCK(this);
auto params = TRY(copy_typed_from_user(user_params));
timespec ts {};
switch (params.clock_id) {
case CLOCK_REALTIME:
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / _SC_CLK_TCK;
TRY(copy_to_user(params.result, &ts));
break;
default:
return EINVAL;
}
return 0;
}

ErrorOr<FlatPtr> Process::sys$adjtime(Userspace<timeval const*> user_delta, Userspace<timeval*> user_old_delta)
{
VERIFY_NO_PROCESS_BIG_LOCK(this);
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibC/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ int nanosleep(const struct timespec* requested_sleep, struct timespec* remaining
return clock_nanosleep(CLOCK_REALTIME, 0, requested_sleep, remaining_sleep);
}

int clock_getres(clockid_t, struct timespec*)
int clock_getres(clockid_t clock_id, struct timespec* result)
{
dbgln("FIXME: Implement clock_getres()");
auto rc = -ENOSYS;
Syscall::SC_clock_getres_params params { clock_id, result };
int rc = syscall(SC_clock_getres, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}

Expand Down

0 comments on commit ca74443

Please sign in to comment.