In fcntl va_arg is currently used even if the caller did not pass
any variadic arguments. This is undefined behaviour and does not
work with the Morello purecap ABI, so use a helper macro.
When the argument is missing, the result of the helper macro is
arbitrary as it will be ignored by the kernel, we just have to
ensure it does not cause a runtime crash.
LOAD_ARGS_6 (c0, c1, c2, c3, c4, c5) \
register __sysarg_t _x6 asm ("c6") = _x6tmp;
+# define FCNTL_VA_ARG(a, t) (a ? va_arg(a, t) : 0)
+
#endif /* __ASSEMBLER__ */
/* Disable pointer mangling for purecap ABI. */
# define __NR_fcntl64 __NR_fcntl
#endif
+#ifndef FCNTL_VA_ARG
+# define FCNTL_VA_ARG(a, t) va_arg(a, t)
+#endif
+
#ifndef FCNTL_ADJUST_CMD
# define FCNTL_ADJUST_CMD(__cmd) __cmd
#endif
void *arg;
va_start (ap, cmd);
- arg = va_arg (ap, void *);
+ arg = FCNTL_VA_ARG (ap, void *);
va_end (ap);
cmd = FCNTL_ADJUST_CMD (cmd);
# define __NR_fcntl64 __NR_fcntl
#endif
+#ifndef FCNTL_VA_ARG
+# define FCNTL_VA_ARG(a, t) va_arg(a, t)
+#endif
+
#ifndef FCNTL_ADJUST_CMD
# define FCNTL_ADJUST_CMD(__cmd) __cmd
#endif
void *arg;
va_start (ap, cmd);
- arg = va_arg (ap, void *);
+ arg = FCNTL_VA_ARG (ap, void *);
va_end (ap);
cmd = FCNTL_ADJUST_CMD (cmd);