Commit c6527e56 authored by Florian Bezdeka's avatar Florian Bezdeka Committed by Jan Kiszka

y2038: Adding sem_timedwait64

Implementation is heavily inspired by the sem_timedwait syscall,
but expecting time64 based timespec / timeout.

We need two new syscall handlers:
  - The native one (COBALT_SYSCALL()) to get 32 bit kernels time64
    aware. This handler is added for 64 bit kernels as well, but not
    used. As we don't have separate syscall tables for this both
    worlds we have to add it.

 - The compat handler (COBALT_SYSCALL32emu()) for x32 or x86
   applications running on an x86_64 kernel. Otherwise the redirection
   to the compat / emulation syscalls is broken.
Signed-off-by: default avatarFlorian Bezdeka <florian.bezdeka@siemens.com>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent d47a4cdd
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _COBALT_KERNEL_TIME_H
#define _COBALT_KERNEL_TIME_H
#include <linux/time.h>
#include <linux/time64.h>
/**
* Read struct __kernel_timespec from userspace and convert to
* struct timespec64
*
* @param ts The destination, will be filled
* @param uts The source, provided by an application
* @return 0 on success, -EFAULT otherwise
*/
int cobalt_get_timespec64(struct timespec64 *ts,
const struct __kernel_timespec __user *uts);
#endif //_COBALT_KERNEL_TIME_H
......@@ -122,6 +122,7 @@
#define sc_cobalt_sendmmsg 99
#define sc_cobalt_clock_adjtime 100
#define sc_cobalt_thread_setschedprio 101
#define sc_cobalt_sem_timedwait64 102
#define __NR_COBALT_SYSCALLS 128 /* Power of 2 */
......
......@@ -13,6 +13,7 @@ xenomai-y := arith.o \
select.o \
synch.o \
thread.o \
time.o \
timer.o \
tree.o
......
......@@ -19,6 +19,7 @@
#include <stddef.h>
#include <linux/err.h>
#include <cobalt/kernel/time.h>
#include "internal.h"
#include "thread.h"
#include "clock.h"
......@@ -326,6 +327,18 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
return ret;
}
int __cobalt_sem_timedwait64(struct cobalt_sem_shadow __user *u_sem,
const struct __kernel_timespec __user *u_ts)
{
int ret = 1;
struct timespec64 ts64;
if (u_ts)
ret = cobalt_get_timespec64(&ts64, u_ts);
return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
}
static int sem_post(xnhandle_t handle)
{
struct cobalt_sem *sem;
......@@ -435,6 +448,13 @@ COBALT_SYSCALL(sem_timedwait, primary,
return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
}
COBALT_SYSCALL(sem_timedwait64, primary,
(struct cobalt_sem_shadow __user *u_sem,
const struct __kernel_timespec __user *u_ts))
{
return __cobalt_sem_timedwait64(u_sem, u_ts);
}
COBALT_SYSCALL(sem_trywait, primary,
(struct cobalt_sem_shadow __user *u_sem))
{
......
......@@ -66,6 +66,9 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
const struct timespec64 *ts);
int __cobalt_sem_timedwait64(struct cobalt_sem_shadow __user *u_sem,
const struct __kernel_timespec __user *u_ts);
int __cobalt_sem_destroy(xnhandle_t handle);
void cobalt_nsem_reclaim(struct cobalt_process *process);
......@@ -91,6 +94,10 @@ COBALT_SYSCALL_DECL(sem_timedwait,
(struct cobalt_sem_shadow __user *u_sem,
const struct __user_old_timespec __user *u_ts));
COBALT_SYSCALL_DECL(sem_timedwait64,
(struct cobalt_sem_shadow __user *u_sem,
const struct __kernel_timespec __user *u_ts));
COBALT_SYSCALL_DECL(sem_trywait,
(struct cobalt_sem_shadow __user *u_sem));
......
......@@ -135,6 +135,13 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
}
COBALT_SYSCALL32emu(sem_timedwait64, primary,
(struct cobalt_sem_shadow __user *u_sem,
const struct __kernel_timespec __user *u_ts))
{
return __cobalt_sem_timedwait64(u_sem, u_ts);
}
COBALT_SYSCALL32emu(clock_getres, current,
(clockid_t clock_id,
struct old_timespec32 __user *u_ts))
......
......@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
(struct cobalt_sem_shadow __user *u_sem,
const struct old_timespec32 __user *u_ts));
COBALT_SYSCALL32emu_DECL(sem_timedwait64,
(struct cobalt_sem_shadow __user *u_sem,
const struct __kernel_timespec __user *u_ts));
#endif /* !_COBALT_POSIX_SYSCALL32_H */
// SPDX-License-Identifier: GPL-2.0
#include <asm-generic/xenomai/syscall.h>
#include <cobalt/kernel/time.h>
#include <linux/compat.h>
int cobalt_get_timespec64(struct timespec64 *ts,
const struct __kernel_timespec __user *uts)
{
struct __kernel_timespec kts;
int ret;
ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
if (ret)
return -EFAULT;
ts->tv_sec = kts.tv_sec;
/* Zero out the padding in compat mode */
if (in_compat_syscall())
kts.tv_nsec &= 0xFFFFFFFFUL;
/* In 32-bit mode, this drops the padding */
ts->tv_nsec = kts.tv_nsec;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment