Skip to content

Commit

Permalink
timerfd: Move implementation from linux compat to sys/kern
Browse files Browse the repository at this point in the history
Move the timerfd impelemntation from linux compat code to sys/kern. Use
it to implement the new system calls for timerfd. Add a hook to kern_tc
to allow timerfd to know when the system time has stepped. Add kqueue
support to timerfd. Adjust a few names to be less Linux centric.

RelNotes: YES
Reviewed by: markj (on irc), imp, kib (with reservations), jhb (slack)
Differential Revision: https://reviews.freebsd.org/D38459
  • Loading branch information
jakesfreeland authored and bsdimp committed Aug 24, 2023
1 parent f8bc606 commit af93fea
Show file tree
Hide file tree
Showing 23 changed files with 999 additions and 425 deletions.
3 changes: 3 additions & 0 deletions lib/libc/sys/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ FBSD_1.7 {
kqueuex;
membarrier;
swapoff;
timerfd_create;
timerfd_gettime;
timerfd_settime;
};

FBSDprivate_1.0 {
Expand Down
1 change: 1 addition & 0 deletions sys/bsm/audit_kevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@
#define AUE_AIO_WRITEV 43267 /* FreeBSD-specific. */
#define AUE_AIO_READV 43268 /* FreeBSD-specific. */
#define AUE_FSPACECTL 43269 /* FreeBSD-specific. */
#define AUE_TIMERFD 43270 /* FreeBSD/Linux. */

/*
* Darwin BSM uses a number of AUE_O_* definitions, which are aliased to the
Expand Down
14 changes: 14 additions & 0 deletions sys/compat/freebsd32/freebsd32_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,16 @@ struct freebsd32_aio_writev_args {
struct freebsd32_aio_readv_args {
char aiocbp_l_[PADL_(struct aiocb32 *)]; struct aiocb32 * aiocbp; char aiocbp_r_[PADR_(struct aiocb32 *)];
};
struct freebsd32_timerfd_gettime_args {
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
char curr_value_l_[PADL_(struct itimerspec32 *)]; struct itimerspec32 * curr_value; char curr_value_r_[PADR_(struct itimerspec32 *)];
};
struct freebsd32_timerfd_settime_args {
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
char new_value_l_[PADL_(const struct itimerspec32 *)]; const struct itimerspec32 * new_value; char new_value_r_[PADR_(const struct itimerspec32 *)];
char old_value_l_[PADL_(struct itimerspec32 *)]; struct itimerspec32 * old_value; char old_value_r_[PADR_(struct itimerspec32 *)];
};
int freebsd32_wait4(struct thread *, struct freebsd32_wait4_args *);
int freebsd32_ptrace(struct thread *, struct freebsd32_ptrace_args *);
int freebsd32_recvmsg(struct thread *, struct freebsd32_recvmsg_args *);
Expand Down Expand Up @@ -799,6 +809,8 @@ int freebsd32_cpuset_setdomain(struct thread *, struct freebsd32_cpuset_setdomai
int freebsd32___sysctlbyname(struct thread *, struct freebsd32___sysctlbyname_args *);
int freebsd32_aio_writev(struct thread *, struct freebsd32_aio_writev_args *);
int freebsd32_aio_readv(struct thread *, struct freebsd32_aio_readv_args *);
int freebsd32_timerfd_gettime(struct thread *, struct freebsd32_timerfd_gettime_args *);
int freebsd32_timerfd_settime(struct thread *, struct freebsd32_timerfd_settime_args *);

#ifdef COMPAT_43

Expand Down Expand Up @@ -1292,6 +1304,8 @@ int freebsd11_freebsd32_fstatat(struct thread *, struct freebsd11_freebsd32_fsta
#define FREEBSD32_SYS_AUE_freebsd32___sysctlbyname AUE_SYSCTL
#define FREEBSD32_SYS_AUE_freebsd32_aio_writev AUE_AIO_WRITEV
#define FREEBSD32_SYS_AUE_freebsd32_aio_readv AUE_AIO_READV
#define FREEBSD32_SYS_AUE_freebsd32_timerfd_gettime AUE_TIMERFD
#define FREEBSD32_SYS_AUE_freebsd32_timerfd_settime AUE_TIMERFD

#undef PAD_
#undef PADL_
Expand Down
5 changes: 4 additions & 1 deletion sys/compat/freebsd32/freebsd32_syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,7 @@
#define FREEBSD32_SYS_swapoff 582
#define FREEBSD32_SYS_kqueuex 583
#define FREEBSD32_SYS_membarrier 584
#define FREEBSD32_SYS_MAXSYSCALL 585
#define FREEBSD32_SYS_timerfd_create 585
#define FREEBSD32_SYS_freebsd32_timerfd_gettime 586
#define FREEBSD32_SYS_freebsd32_timerfd_settime 587
#define FREEBSD32_SYS_MAXSYSCALL 588
3 changes: 3 additions & 0 deletions sys/compat/freebsd32/freebsd32_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,4 +590,7 @@ const char *freebsd32_syscallnames[] = {
"swapoff", /* 582 = swapoff */
"kqueuex", /* 583 = kqueuex */
"membarrier", /* 584 = membarrier */
"timerfd_create", /* 585 = timerfd_create */
"freebsd32_timerfd_gettime", /* 586 = freebsd32_timerfd_gettime */
"freebsd32_timerfd_settime", /* 587 = freebsd32_timerfd_settime */
};
3 changes: 3 additions & 0 deletions sys/compat/freebsd32/freebsd32_sysent.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(swapoff_args), .sy_call = (sy_call_t *)sys_swapoff, .sy_auevent = AUE_SWAPOFF, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 582 = swapoff */
{ .sy_narg = AS(kqueuex_args), .sy_call = (sy_call_t *)sys_kqueuex, .sy_auevent = AUE_KQUEUE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 583 = kqueuex */
{ .sy_narg = AS(membarrier_args), .sy_call = (sy_call_t *)sys_membarrier, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 584 = membarrier */
{ .sy_narg = AS(timerfd_create_args), .sy_call = (sy_call_t *)sys_timerfd_create, .sy_auevent = AUE_TIMERFD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 585 = timerfd_create */
{ .sy_narg = AS(freebsd32_timerfd_gettime_args), .sy_call = (sy_call_t *)freebsd32_timerfd_gettime, .sy_auevent = AUE_TIMERFD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 586 = freebsd32_timerfd_gettime */
{ .sy_narg = AS(freebsd32_timerfd_settime_args), .sy_call = (sy_call_t *)freebsd32_timerfd_settime, .sy_auevent = AUE_TIMERFD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 587 = freebsd32_timerfd_settime */
};
86 changes: 86 additions & 0 deletions sys/compat/freebsd32/freebsd32_systrace_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -3336,6 +3336,32 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 3;
break;
}
/* timerfd_create */
case 585: {
struct timerfd_create_args *p = params;
iarg[a++] = p->clockid; /* int */
iarg[a++] = p->flags; /* int */
*n_args = 2;
break;
}
/* freebsd32_timerfd_gettime */
case 586: {
struct freebsd32_timerfd_gettime_args *p = params;
iarg[a++] = p->fd; /* int */
uarg[a++] = (intptr_t)p->curr_value; /* struct itimerspec32 * */
*n_args = 2;
break;
}
/* freebsd32_timerfd_settime */
case 587: {
struct freebsd32_timerfd_settime_args *p = params;
iarg[a++] = p->fd; /* int */
iarg[a++] = p->flags; /* int */
uarg[a++] = (intptr_t)p->new_value; /* const struct itimerspec32 * */
uarg[a++] = (intptr_t)p->old_value; /* struct itimerspec32 * */
*n_args = 4;
break;
}
default:
*n_args = 0;
break;
Expand Down Expand Up @@ -9005,6 +9031,51 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
};
break;
/* timerfd_create */
case 585:
switch (ndx) {
case 0:
p = "int";
break;
case 1:
p = "int";
break;
default:
break;
};
break;
/* freebsd32_timerfd_gettime */
case 586:
switch (ndx) {
case 0:
p = "int";
break;
case 1:
p = "userland struct itimerspec32 *";
break;
default:
break;
};
break;
/* freebsd32_timerfd_settime */
case 587:
switch (ndx) {
case 0:
p = "int";
break;
case 1:
p = "int";
break;
case 2:
p = "userland const struct itimerspec32 *";
break;
case 3:
p = "userland struct itimerspec32 *";
break;
default:
break;
};
break;
default:
break;
};
Expand Down Expand Up @@ -10873,6 +10944,21 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
if (ndx == 0 || ndx == 1)
p = "int";
break;
/* timerfd_create */
case 585:
if (ndx == 0 || ndx == 1)
p = "int";
break;
/* freebsd32_timerfd_gettime */
case 586:
if (ndx == 0 || ndx == 1)
p = "int";
break;
/* freebsd32_timerfd_settime */
case 587:
if (ndx == 0 || ndx == 1)
p = "int";
break;
default:
break;
};
Expand Down
Loading

0 comments on commit af93fea

Please sign in to comment.