1212#include < stdlib.h>
1313#include < string.h>
1414#include < sys/ioctl.h>
15+ #include < sys/resource.h>
1516#include < sys/stat.h>
1617#include < zinnia/syscall.hpp>
1718
@@ -47,6 +48,13 @@ int Sysdeps<ClockGetres>::operator()(int clock, time_t *secs, long *nanos) {
4748 return 0 ;
4849}
4950
51+ int Sysdeps<ClockSet>::operator ()(int clock, time_t secs, long nanos) {
52+ struct timespec ts;
53+ ts.tv_sec = secs;
54+ ts.tv_nsec = nanos;
55+ return zinnia_syscall (SYSCALL_CLOCK_SET , clock, (size_t )&ts).error ;
56+ }
57+
5058int Sysdeps<Flock>::operator ()(int fd, int options) {
5159 auto r = zinnia_syscall (SYSCALL_FLOCK , fd, options);
5260 return r.error ;
@@ -165,6 +173,14 @@ int Sysdeps<Ftruncate>::operator()(int fd, size_t size) {
165173 return zinnia_syscall (SYSCALL_FTRUNCATE , fd, size).error ;
166174}
167175
176+ int Sysdeps<Truncate>::operator ()(const char *path, off_t length) {
177+ return zinnia_syscall (SYSCALL_TRUNCATE , (size_t )path, length).error ;
178+ }
179+
180+ int Sysdeps<Fadvise>::operator ()(int fd, off_t offset, off_t length, int advice) {
181+ return zinnia_syscall (SYSCALL_FADVISE , fd, offset, length, advice).error ;
182+ }
183+
168184int Sysdeps<Fallocate>::operator ()(int fd, off_t offset, size_t size) {
169185 return zinnia_syscall (SYSCALL_FALLOCATE , fd, offset, size).error ;
170186}
@@ -351,6 +367,10 @@ int Sysdeps<Execve>::operator()(const char *path, char *const argv[], char *cons
351367 return zinnia_syscall (SYSCALL_EXECVE , (size_t )path, (size_t )argv, (size_t )envp).error ;
352368}
353369
370+ int Sysdeps<Fexecve>::operator ()(int fd, char *const argv[], char *const envp[]) {
371+ return zinnia_syscall (SYSCALL_FEXECVE , fd, (size_t )argv, (size_t )envp).error ;
372+ }
373+
354374int Sysdeps<Pselect>::operator ()(
355375 int num_fds,
356376 fd_set *read_set,
@@ -588,6 +608,27 @@ int Sysdeps<Tcsetattr>::operator()(int fd, int optional_action, const struct ter
588608 return sysdep<Ioctl>(fd, req, (void *)attr, &ret);
589609}
590610
611+ int Sysdeps<Tcsendbreak>::operator ()(int fd, int ) {
612+ // Like Linux, we ignore the duration and always send a break of the default length.
613+ int ret;
614+ return sysdep<Ioctl>(fd, TCSBRK , (void *)0 , &ret);
615+ }
616+
617+ int Sysdeps<Tcdrain>::operator ()(int fd) {
618+ int ret;
619+ return sysdep<Ioctl>(fd, TCSBRK , (void *)1 , &ret);
620+ }
621+
622+ int Sysdeps<Tcflow>::operator ()(int fd, int action) {
623+ int ret;
624+ return sysdep<Ioctl>(fd, TCXONC , (void *)(uintptr_t )action, &ret);
625+ }
626+
627+ int Sysdeps<Tcflush>::operator ()(int fd, int queue) {
628+ int ret;
629+ return sysdep<Ioctl>(fd, TCFLSH , (void *)(uintptr_t )queue, &ret);
630+ }
631+
591632int Sysdeps<Tcgetwinsize>::operator ()(int fd, struct winsize *winsz) {
592633 int result;
593634 return sysdep<Ioctl>(fd, TIOCGWINSZ , winsz, &result);
@@ -621,7 +662,7 @@ int Sysdeps<Poll>::operator()(struct pollfd *fds, nfds_t count, int timeout, int
621662 ts.tv_sec = timeout / 1000 ;
622663 ts.tv_nsec = (timeout % 1000 ) * 1000000 ;
623664
624- return sysdep<Ppoll>(fds, count, timeout != -1 ? &ts : NULL , NULL , num_events);
665+ return sysdep<Ppoll>(fds, count, timeout != -1 ? &ts : nullptr , nullptr , num_events);
625666}
626667
627668int Sysdeps<Ioctl>::operator ()(int fd, unsigned long request, void *arg, int *result) {
@@ -669,6 +710,27 @@ int Sysdeps<Kill>::operator()(pid_t pid, int signal) {
669710 return zinnia_syscall (SYSCALL_KILL , pid, signal).error ;
670711}
671712
713+ int Sysdeps<Sigqueue>::operator ()(pid_t pid, int sig, const union sigval val) {
714+ return zinnia_syscall (SYSCALL_SIGQUEUE , pid, sig, (size_t )val.sival_ptr ).error ;
715+ }
716+
717+ int Sysdeps<Nice>::operator ()(int inc, int *new_nice) {
718+ auto r = zinnia_syscall (SYSCALL_GETPRIORITY , PRIO_PROCESS , 0 );
719+ if (r.error )
720+ return r.error ;
721+
722+ int target = (int )r.value + inc;
723+ if (int e = zinnia_syscall (SYSCALL_SETPRIORITY , PRIO_PROCESS , 0 , target).error )
724+ return e;
725+
726+ auto updated = zinnia_syscall (SYSCALL_GETPRIORITY , PRIO_PROCESS , 0 );
727+ if (updated.error )
728+ return updated.error ;
729+
730+ *new_nice = (int )updated.value ;
731+ return 0 ;
732+ }
733+
672734int Sysdeps<GetHostname>::operator ()(char *buffer, size_t bufsize) {
673735 struct utsname name;
674736 int i = sysdep<Uname>(&name);
@@ -764,6 +826,18 @@ int Sysdeps<TimerSettime>::operator()(
764826 return zinnia_syscall (SYSCALL_TIMER_SET , (size_t )t, flags, (size_t )val, (size_t )old).error ;
765827}
766828
829+ int Sysdeps<TimerGettime>::operator ()(timer_t t, struct itimerspec *val) {
830+ return zinnia_syscall (SYSCALL_TIMER_GET , (size_t )t, (size_t )val).error ;
831+ }
832+
833+ int Sysdeps<TimerGetoverrun>::operator ()(timer_t t, int *out) {
834+ auto r = zinnia_syscall (SYSCALL_TIMER_GETOVERRUN , (size_t )t);
835+ if (r.error )
836+ return r.error ;
837+ *out = (int )r.value ;
838+ return 0 ;
839+ }
840+
767841int Sysdeps<TimerDelete>::operator ()(timer_t t) {
768842 return zinnia_syscall (SYSCALL_TIMER_DELETE , (size_t )t).error ;
769843}
@@ -799,7 +873,7 @@ int Sysdeps<SetRegid>::operator()(gid_t rgid, gid_t egid) {
799873
800874int Sysdeps<Unlockpt>::operator ()(int fd) {
801875 int unlock = 0 ;
802- if (int e = sysdep<Ioctl>(fd, TIOCSPTLCK , &unlock, NULL ); e)
876+ if (int e = sysdep<Ioctl>(fd, TIOCSPTLCK , &unlock, nullptr ); e)
803877 return e;
804878 return 0 ;
805879}
@@ -820,7 +894,7 @@ int Sysdeps<Waitid>::operator()(idtype_t idtype, id_t id, siginfo_t *info, int o
820894
821895int Sysdeps<Ptsname>::operator ()(int fd, char *buffer, size_t length) {
822896 int index;
823- if (int e = sysdep<Ioctl>(fd, TIOCGPTN , &index, NULL ); e)
897+ if (int e = sysdep<Ioctl>(fd, TIOCGPTN , &index, nullptr ); e)
824898 return e;
825899 if ((size_t )snprintf (buffer, length, " /dev/pts/%d" , index) >= length) {
826900 return ERANGE ;
@@ -838,7 +912,7 @@ int Sysdeps<IfIndextoname>::operator()(unsigned int index, char *name) {
838912 struct ifreq ifr;
839913 ifr.ifr_ifindex = index;
840914
841- int ret = sysdep<Ioctl>(fd, SIOCGIFNAME , &ifr, NULL );
915+ int ret = sysdep<Ioctl>(fd, SIOCGIFNAME , &ifr, nullptr );
842916 close (fd);
843917
844918 if (ret) {
@@ -862,7 +936,7 @@ int Sysdeps<IfNametoindex>::operator()(const char *name, unsigned int *ret) {
862936 struct ifreq ifr;
863937 strncpy (ifr.ifr_name , name, sizeof ifr.ifr_name );
864938
865- r = sysdep<Ioctl>(fd, SIOCGIFINDEX , &ifr, NULL );
939+ r = sysdep<Ioctl>(fd, SIOCGIFINDEX , &ifr, nullptr );
866940 close (fd);
867941
868942 if (r) {
@@ -913,7 +987,7 @@ int Sysdeps<Sysconf>::operator()(int num, long *ret) {
913987}
914988
915989int Sysdeps<Pause>::operator ()() {
916- return sysdep<Ppoll>(NULL , 0 , NULL , NULL , NULL );
990+ return sysdep<Ppoll>(nullptr , 0 , nullptr , nullptr , nullptr );
917991}
918992
919993} // namespace mlibc
0 commit comments