lkl: follow up fixes after 4.17 merge

This fix includes removing obsolte syscall usage from LKL based on the
following commit introduced at 4.17 kernel.

Fixes: 8a1ab3155c ("UAPI: (Scripted) Disintegrate include/asm-generic")

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
This commit is contained in:
Hajime Tazaki
2018-10-31 15:02:51 +09:00
parent 4ff4382c0d
commit 780bdc7a66
3 changed files with 292 additions and 14 deletions

View File

@@ -50,12 +50,40 @@ typedef __s64 s64;
#undef __NR_name_to_handle_at
#undef __NR_open_by_handle_at
/* deprecated system calls */
#undef __NR_epoll_create
#undef __NR_epoll_wait
#undef __NR_access
#undef __NR_chmod
#undef __NR_chown
#undef __NR_lchown
#undef __NR_open
#undef __NR_creat
#undef __NR_readlink
#undef __NR_pipe
#undef __NR_mknod
#undef __NR_mkdir
#undef __NR_rmdir
#undef __NR_unlink
#undef __NR_symlink
#undef __NR_link
#undef __NR_rename
#undef __NR_getdents
#undef __NR_select
#undef __NR_poll
#undef __NR_dup2
#undef __NR_futimesat
#undef __NR_utimes
#undef __NR_ustat
#undef __NR_eventfd
#undef __NR_bdflush
#undef __NR_send
#undef __NR_recv
#undef __NR_umount
#define __NR_umount __NR_umount2
#ifdef CONFIG_64BIT
#define __NR_newstat __NR3264_stat
#define __NR_newlstat __NR3264_lstat
#define __NR_newfstat __NR3264_fstat
#define __NR_newfstatat __NR3264_fstatat
#endif

View File

@@ -37,10 +37,9 @@ extern "C" {
#endif
#if __LKL__BITS_PER_LONG == 64
#define lkl_sys_stat lkl_sys_newstat
#define lkl_sys_lstat lkl_sys_newlstat
#define lkl_sys_fstatat lkl_sys_newfstatat
#define lkl_sys_fstat lkl_sys_newfstat
#else
#define lkl_stat lkl_stat64
#define lkl_sys_stat lkl_sys_stat64
@@ -66,6 +65,17 @@ static inline int lkl_sys_fstatfs(unsigned int fd, struct lkl_statfs *buf)
#endif
static inline int lkl_sys_stat(const char *path, struct lkl_stat *buf)
{
return lkl_sys_fstatat(LKL_AT_FDCWD, path, buf, 0);
}
static inline int lkl_sys_lstat(const char *path, struct lkl_stat *buf)
{
return lkl_sys_fstatat(LKL_AT_FDCWD, path, buf,
LKL_AT_SYMLINK_NOFOLLOW);
}
#ifdef __lkl__NR_llseek
/**
* lkl_sys_lseek - wrapper for lkl_sys_llseek
@@ -89,6 +99,227 @@ static inline void *lkl_sys_mmap(void *addr, size_t length, int prot, int flags,
#define lkl_sys_mmap2 lkl_sys_mmap_pgoff
#ifdef __lkl__NR_openat
/**
* lkl_sys_open - wrapper for lkl_sys_openat
*/
static inline long lkl_sys_open(const char *file, int flags, int mode)
{
return lkl_sys_openat(LKL_AT_FDCWD, file, flags, mode);
}
/**
* lkl_sys_creat - wrapper for lkl_sys_openat
*/
static inline long lkl_sys_creat(const char *file, int mode)
{
return lkl_sys_openat(LKL_AT_FDCWD, file,
LKL_O_CREAT|LKL_O_WRONLY|LKL_O_TRUNC, mode);
}
#endif
#ifdef __lkl__NR_faccessat
/**
* lkl_sys_access - wrapper for lkl_sys_faccessat
*/
static inline long lkl_sys_access(const char *file, int mode)
{
return lkl_sys_faccessat(LKL_AT_FDCWD, file, mode);
}
#endif
#ifdef __lkl__NR_fchownat
/**
* lkl_sys_chown - wrapper for lkl_sys_fchownat
*/
static inline long lkl_sys_chown(const char *path, lkl_uid_t uid, lkl_gid_t gid)
{
return lkl_sys_fchownat(LKL_AT_FDCWD, path, uid, gid, 0);
}
#endif
#ifdef __lkl__NR_fchmodat
/**
* lkl_sys_chmod - wrapper for lkl_sys_fchmodat
*/
static inline long lkl_sys_chmod(const char *path, mode_t mode)
{
return lkl_sys_fchmodat(LKL_AT_FDCWD, path, mode);
}
#endif
#ifdef __lkl__NR_linkat
/**
* lkl_sys_link - wrapper for lkl_sys_linkat
*/
static inline long lkl_sys_link(const char *existing, const char *new)
{
return lkl_sys_linkat(LKL_AT_FDCWD, existing, LKL_AT_FDCWD, new, 0);
}
#endif
#ifdef __lkl__NR_unlinkat
/**
* lkl_sys_unlink - wrapper for lkl_sys_unlinkat
*/
static inline long lkl_sys_unlink(const char *path)
{
return lkl_sys_unlinkat(LKL_AT_FDCWD, path, 0);
}
#endif
#ifdef __lkl__NR_symlinkat
/**
* lkl_sys_symlink - wrapper for lkl_sys_symlinkat
*/
static inline long lkl_sys_symlink(const char *existing, const char *new)
{
return lkl_sys_symlinkat(existing, LKL_AT_FDCWD, new);
}
#endif
#ifdef __lkl__NR_readlinkat
/**
* lkl_sys_readlink - wrapper for lkl_sys_readlinkat
*/
static inline long lkl_sys_readlink(const char *path, char *buf, size_t bufsize)
{
return lkl_sys_readlinkat(LKL_AT_FDCWD, path, buf, bufsize);
}
#endif
#ifdef __lkl__NR_renameat
/**
* lkl_sys_rename - wrapper for lkl_sys_renameat
*/
static inline long lkl_sys_rename(const char *old, const char *new)
{
return lkl_sys_renameat(LKL_AT_FDCWD, old, LKL_AT_FDCWD, new);
}
#endif
#ifdef __lkl__NR_mkdirat
/**
* lkl_sys_mkdir - wrapper for lkl_sys_mkdirat
*/
static inline long lkl_sys_mkdir(const char *path, mode_t mode)
{
return lkl_sys_mkdirat(LKL_AT_FDCWD, path, mode);
}
#endif
#ifdef __lkl__NR_unlinkat
/**
* lkl_sys_rmdir - wrapper for lkl_sys_unlinkrat
*/
static inline long lkl_sys_rmdir(const char *path)
{
return lkl_sys_unlinkat(LKL_AT_FDCWD, path, LKL_AT_REMOVEDIR);
}
#endif
#ifdef __lkl__NR_mknodat
/**
* lkl_sys_mknod - wrapper for lkl_sys_mknodat
*/
static inline long lkl_sys_mknod(const char *path, mode_t mode, dev_t dev)
{
return lkl_sys_mknodat(LKL_AT_FDCWD, path, mode, dev);
}
#endif
#ifdef __lkl__NR_pipe2
/**
* lkl_sys_pipe - wrapper for lkl_sys_pipe2
*/
static inline long lkl_sys_pipe(int fd[2])
{
return lkl_sys_pipe2(fd, 0);
}
#endif
#ifdef __lkl__NR_sendto
/**
* lkl_sys_send - wrapper for lkl_sys_sendto
*/
static inline long lkl_sys_send(int fd, void *buf, size_t len, int flags)
{
return lkl_sys_sendto(fd, buf, len, flags, 0, 0);
}
#endif
#ifdef __lkl__NR_recvfrom
/**
* lkl_sys_recv - wrapper for lkl_sys_recvfrom
*/
static inline long lkl_sys_recv(int fd, void *buf, size_t len, int flags)
{
return lkl_sys_recvfrom(fd, buf, len, flags, 0, 0);
}
#endif
#ifdef __lkl__NR_pselect6
/**
* lkl_sys_select - wrapper for lkl_sys_pselect
*/
static inline long lkl_sys_select(int n, lkl_fd_set *rfds, lkl_fd_set *wfds,
lkl_fd_set *efds, struct lkl_timeval *tv)
{
long data[2] = { 0, _LKL_NSIG/8 };
struct lkl_timespec ts;
lkl_time_t extra_secs;
const lkl_time_t max_time = ((1ULL<<8)*sizeof(time_t)-1)-1;
if (tv) {
if (tv->tv_sec < 0 || tv->tv_usec < 0)
return -LKL_EINVAL;
extra_secs = tv->tv_usec / 1000000;
ts.tv_nsec = tv->tv_usec % 1000000 * 1000;
ts.tv_sec = extra_secs > max_time - tv->tv_sec ?
max_time : tv->tv_sec + extra_secs;
}
return lkl_sys_pselect6(n, rfds, wfds, efds, tv ? &ts : 0, data);
}
#endif
#ifdef __lkl__NR_ppoll
/**
* lkl_sys_poll - wrapper for lkl_sys_ppoll
*/
static inline long lkl_sys_poll(struct lkl_pollfd *fds, int n, int timeout)
{
return lkl_sys_ppoll(fds, n, timeout >= 0 ?
&((struct lkl_timespec){ .tv_sec = timeout/1000,
.tv_nsec = timeout%1000*1000000 }) : 0,
0, _LKL_NSIG/8);
}
#endif
#ifdef __lkl__NR_epoll_create1
/**
* lkl_sys_epoll_create - wrapper for lkl_sys_epoll_create1
*/
static inline long lkl_sys_epoll_create(int size)
{
return lkl_sys_epoll_create1(0);
}
#endif
#ifdef __lkl__NR_epoll_pwait
/**
* lkl_sys_epoll_wait - wrapper for lkl_sys_epoll_pwait
*/
static inline long lkl_sys_epoll_wait(int fd, struct lkl_epoll_event *ev,
int cnt, int to)
{
return lkl_sys_epoll_pwait(fd, ev, cnt, to, 0, _LKL_NSIG/8);
}
#endif
/**
* lkl_strerror - returns a string describing the given error code
*

View File

@@ -154,14 +154,11 @@ HOOK_FD_CALL(accept)
HOOK_FD_CALL(write)
HOOK_FD_CALL(writev)
HOOK_FD_CALL(sendto)
HOOK_FD_CALL(send)
HOOK_FD_CALL(read)
HOOK_FD_CALL(readv)
HOOK_FD_CALL(recvfrom)
HOOK_FD_CALL(recv)
HOOK_FD_CALL(splice)
HOOK_FD_CALL(vmsplice)
HOOK_CALL_USE_HOST_BEFORE_START(pipe);
HOOK_CALL_USE_HOST_BEFORE_START(accept4);
HOOK_CALL_USE_HOST_BEFORE_START(pipe2);
@@ -264,7 +261,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
if (hostfds)
return host_poll(fds, nfds, timeout);
return lkl_call(__lkl__NR_poll, 3, fds, nfds, timeout);
return lkl_sys_poll((struct lkl_pollfd *)fds, nfds, timeout);
}
int __poll(struct pollfd *, nfds_t, int) __attribute__((alias("poll")));
@@ -304,7 +301,8 @@ int select(int nfds, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
if (hostfds)
return host_select(nfds, r, w, e, t);
return lkl_call(__lkl__NR_select, 5, nfds, r, w, e, t);
return lkl_sys_select(nfds, (lkl_fd_set *)r, (lkl_fd_set *)w,
(lkl_fd_set *)e, (struct lkl_timeval *)t);
}
HOST_CALL(close);
@@ -341,7 +339,7 @@ int epoll_create(int size)
if (!lkl_running)
return host_fd;
dual_fds[host_fd] = lkl_call(__lkl__NR_epoll_create, 1, size);
dual_fds[host_fd] = lkl_sys_epoll_create(size);
/* always returns the host fd */
return host_fd;
@@ -363,7 +361,7 @@ int epoll_create1(int flags)
if (!lkl_running)
return host_fd;
dual_fds[host_fd] = lkl_call(__lkl__NR_epoll_create1, 1, flags);
dual_fds[host_fd] = lkl_sys_epoll_create1(flags);
/* always returns the host fd */
return host_fd;
@@ -421,7 +419,7 @@ int epoll_wait(int epfd, struct epoll_event *events,
void *trv_val;
int i, ret, ret_lkl, ret_host;
ret = lkl_call(__lkl__NR_pipe, 1, l_pipe);
ret = lkl_sys_pipe(l_pipe);
if (ret == -1) {
fprintf(stderr, "lkl pipe error(errno=%d)\n", errno);
return -1;
@@ -471,8 +469,9 @@ int epoll_wait(int epfd, struct epoll_event *events,
earg.pipefd = l_pipe[1];
pthread_create(&thread, NULL, host_epollwait, &earg);
ret_lkl = lkl_call(__lkl__NR_epoll_wait, 4, dual_fds[epfd], l_events,
maxevents, timeout);
ret_lkl = lkl_sys_epoll_wait(dual_fds[epfd],
(struct lkl_epoll_event *)l_events,
maxevents, timeout);
if (ret_lkl == -1) {
fprintf(stderr,
"lkl_%s_wait error(epfd=%d:%d, fd=%d, err=%d)\n",
@@ -596,3 +595,23 @@ int stat(const char *pathname, struct stat *buf)
return host___xstat64(0, pathname, buf);
}
#endif
ssize_t send(int fd, const void *buf, size_t len, int flags)
{
return sendto(fd, buf, len, flags, 0, 0);
}
ssize_t recv(int fd, void *buf, size_t len, int flags)
{
return recvfrom(fd, buf, len, flags, 0, 0);
}
extern int pipe2(int fd[2], int flag);
int pipe(int fd[2])
{
if (!lkl_running)
return host_calls[__lkl__NR_pipe2]((long)fd, 0, 0, 0, 0, 0);
return pipe2(fd, 0);
}