Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce vfcntl() #2194

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/libsys/Symbol.sys.map
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ FBSD_1.7 {
};

FBSD_1.8 {
kcmp;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to upstream this whitespace cleanup but turns out that file does not exist in FreeBSD.

kcmp;
vfcntl;
};

FBSDprivate_1.0 {
Expand Down
3 changes: 3 additions & 0 deletions lib/libsys/fcntl.2
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
.In fcntl.h
.Ft int
.Fn fcntl "int fd" "int cmd" "..."
.In stdarg.h
.Ft int
.Fn vfcntl "int fd" "int cmd" "va_list ap"
.Sh DESCRIPTION
The
.Fn fcntl
Expand Down
69 changes: 36 additions & 33 deletions lib/libsys/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,27 @@
* CHERI CHANGES END
*/

#include <fcntl.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/syscall.h>

#include <fcntl.h>
#include <stdarg.h>

#include "libc_private.h"

#pragma weak fcntl
int
fcntl(int fd, int cmd, ...)
typedef int (*fcntl_func)(int, int, intptr_t);

static int
call_fcntl(fcntl_func fn, int fd, int cmd, va_list ap)
{
va_list args;
intptr_t arg;

va_start(args, cmd);
switch (cmd) {
case F_GETLK:
case F_SETLK:
case F_SETLKW:
case F_KINFO:
arg = va_arg(args, intptr_t);
arg = va_arg(ap, intptr_t);
break;

case F_GETFD:
Expand All @@ -74,13 +75,34 @@ fcntl(int fd, int cmd, ...)
break;

default:
arg = va_arg(args, int);
arg = va_arg(ap, int);
break;
}

return (fn(fd, cmd, arg));
}

#pragma weak fcntl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/fcntl/vfcntl/?

int
vfcntl(int fd, int cmd, va_list ap)
{
fcntl_func fn = (fcntl_func)*__libsys_interposing_slot(INTERPOS_fcntl);

return (call_fcntl(fn, fd, cmd, ap));
}

#pragma weak fcntl
int
fcntl(int fd, int cmd, ...)
{
va_list args;
int result;

va_start(args, cmd);
result = vfcntl(fd, cmd, args);
va_end(args);

return (((int (*)(int, int, intptr_t))
*(__libc_interposing_slot(INTERPOS_fcntl)))(fd, cmd, arg));
return (result);
}

#ifdef __CHERI_PURE_CAPABILITY__
Expand All @@ -90,31 +112,12 @@ int
_fcntl(int fd, int cmd, ...)
{
va_list args;
intptr_t arg;
int result;

va_start(args, cmd);
switch (cmd) {
case F_GETLK:
case F_SETLK:
case F_SETLKW:
case F_KINFO:
arg = va_arg(args, intptr_t);
break;

case F_GETFD:
case F_GETFL:
case F_GETOWN:
case F_GET_SEALS:
case F_ISUNIONSTACK:
arg = 0;
break;

default:
arg = va_arg(args, int);
break;
}
result = call_fcntl(__sys_fcntl, fd, cmd, args);
va_end(args);

return (__sys_fcntl(fd, cmd, arg));
return (result);
}
#endif
1 change: 1 addition & 0 deletions sys/sys/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,10 @@
int creat(const char *, mode_t);
int fcntl(int, int, ...);
#if __BSD_VISIBLE
int vfcntl(int, int, __va_list);
int flock(int, int);
int fspacectl(int, int, const struct spacectl_range *, int,
struct spacectl_range *);

Check failure on line 382 in sys/sys/fcntl.h

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
#endif
#if __POSIX_VISIBLE >= 200809
int openat(int, const char *, int, ...);
Expand Down
Loading