summaryrefslogtreecommitdiff
path: root/src/fcntl
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-01-08 02:18:06 -0500
committerRich Felker <dalias@aerifal.cx>2014-01-08 02:18:06 -0500
commit131871a3d846369fd925d3f8edb692edbad77e4d (patch)
treebd22b296221578478c0b11afc80c6538f6550910 /src/fcntl
parent1d23b3c9136f606276142ec0037ff78fbb95e26d (diff)
downloadmusl-131871a3d846369fd925d3f8edb692edbad77e4d.tar.gz
in fcntl, avoid passing pointer arguments to syscalls as longs
really, fcntl should be changed to use the correct type corresponding to cmd when calling va_arg, and to carry the correct type through until making the syscall. however, this greatly increases binary size and does not seem to offer any benefits except formal correctness, so I'm holding off on that change for now. the minimal changes made in this patch are in preparation for addition of the x32 port, where the syscall macros need to know whether their arguments are pointers or integers in order to properly pass them to the 64-bit kernel.
Diffstat (limited to 'src/fcntl')
-rw-r--r--src/fcntl/fcntl.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/fcntl/fcntl.c b/src/fcntl/fcntl.c
index 4c34ba04..4a713fd4 100644
--- a/src/fcntl/fcntl.c
+++ b/src/fcntl/fcntl.c
@@ -13,11 +13,11 @@ int fcntl(int fd, int cmd, ...)
arg = va_arg(ap, long);
va_end(ap);
if (cmd == F_SETFL) arg |= O_LARGEFILE;
- if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, arg);
+ if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
if (cmd == F_GETOWN) {
struct f_owner_ex ex;
int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex);
- if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, arg);
+ if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg);
if (ret) return __syscall_ret(ret);
return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid;
}
@@ -37,5 +37,14 @@ int fcntl(int fd, int cmd, ...)
if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
return __syscall_ret(ret);
}
- return syscall(SYS_fcntl, fd, cmd, arg);
+ switch (cmd) {
+ case F_SETLK:
+ case F_SETLKW:
+ case F_GETLK:
+ case F_GETOWN_EX:
+ case F_SETOWN_EX:
+ return syscall(SYS_fcntl, fd, cmd, (void *)arg);
+ default:
+ return syscall(SYS_fcntl, fd, cmd, arg);
+ }
}