Skip to content
Closed
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
2 changes: 1 addition & 1 deletion arch/lkl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif

LDFLAGS_vmlinux += -r
LKL_ENTRY_POINTS := lkl_start_kernel lkl_sys_halt lkl_syscall lkl_trigger_irq \
lkl_get_free_irq lkl_put_irq
lkl_get_free_irq lkl_put_irq lkl_get_host_ops

core-y += arch/lkl/kernel/

Expand Down
2 changes: 2 additions & 0 deletions arch/lkl/include/uapi/asm/host_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* is provided here for convenience to be implemented by the host library.
*
* @print - optional operation that receives console messages
* @seterrno - called to set errno for applications in thread local storage.
*
* @panic - called during a kernel panic
*
Expand Down Expand Up @@ -39,6 +40,7 @@ struct lkl_host_operations {
const char *virtio_devices;

void (*print)(const char *str, int len);
void (*seterrno)(int);
void (*panic)(void);

void* (*sem_alloc)(int count);
Expand Down
58 changes: 47 additions & 11 deletions arch/lkl/include/uapi/asm/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ typedef __s64 s64;

#include <linux/kdev_t.h>
#include <asm/irq.h>
#include <asm/host_ops.h>

/* Define data structures used in system calls that are not defined in UAPI
* headers */
Expand Down Expand Up @@ -137,6 +138,16 @@ struct ustat {

long lkl_syscall(long no, long *params);
long lkl_sys_halt(void);
struct lkl_host_operations *lkl_get_host_ops(void);

static inline void lkl_host_seterrno(int error)
{
struct lkl_host_operations *host_ops;

host_ops = lkl_get_host_ops();
if (host_ops && host_ops->seterrno)
host_ops->seterrno(error);
}

#define __MAP0(m,...)
#define __MAP1(m,t,a) m(t,a)
Expand All @@ -150,19 +161,44 @@ long lkl_sys_halt(void);
#define __SC_LONG(t, a) (long)a
#define __SC_DECL(t, a) t a

#define LKL_SYSCALL0(name) \
static inline long lkl_sys_##name(void) \
{ \
long params[6]; \
return lkl_syscall(__lkl__NR_##name, params); \
#define LKL_SYSCALL0(name) \
static inline long lkl_sys_##name(void) \
{ \
long params[6]; \
return lkl_syscall(__lkl__NR_##name, params); \
}; \
static inline \
long lkl_sys_wrapper_##name(void) \
{ \
int ret; \
long params[6]; \
ret = lkl_syscall(__lkl__NR_##name, params); \
if (ret < 0) { \
lkl_host_seterrno(ret); \
ret = -1; \
} \
return ret; \
}

#define LKL_SYSCALLx(x, name, ...) \
static inline \
long lkl_sys_##name(__MAP(x, __SC_DECL, __VA_ARGS__)) \
{ \
long params[6] = { __MAP(x, __SC_LONG, __VA_ARGS__) }; \
return lkl_syscall(__lkl__NR_##name, params); \

#define LKL_SYSCALLx(x, name, ...) \
static inline \
long lkl_sys_##name(__MAP(x, __SC_DECL, __VA_ARGS__)) \
{ \
long params[6] = { __MAP(x, __SC_LONG, __VA_ARGS__) }; \
return lkl_syscall(__lkl__NR_##name, params); \
} \
static inline \
long lkl_sys_wrapper_##name(__MAP(x, __SC_DECL, __VA_ARGS__)) \
{ \
int ret; \
long params[6] = { __MAP(x, __SC_LONG, __VA_ARGS__) }; \
ret = lkl_syscall(__lkl__NR_##name, params); \
if (ret < 0) { \
lkl_host_seterrno(ret); \
ret = -1; \
} \
return ret; \
}

#define SYSCALL_DEFINE0(name, ...) LKL_SYSCALL0(name)
Expand Down
5 changes: 5 additions & 0 deletions arch/lkl/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,
return ret;
}

struct lkl_host_operations *lkl_get_host_ops(void)
{
return lkl_ops;
}

void machine_halt(void)
{
halt = true;
Expand Down
7 changes: 7 additions & 0 deletions tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ static void print(const char *str, int len)
ret = write(STDOUT_FILENO, str, len);
}

static void seterrno(int error)
{
/* LKL to Linux translation (assuming posix-host is Linux */
errno = -error;
}

struct pthread_sem {
pthread_mutex_t lock;
int count;
Expand Down Expand Up @@ -156,6 +162,7 @@ struct lkl_host_operations lkl_host_ops = {
.ioremap = lkl_ioremap,
.iomem_access = lkl_iomem_access,
.virtio_devices = lkl_virtio_devs,
.seterrno = seterrno
};

int fd_get_capacity(union lkl_disk_backstore bs, unsigned long long *res)
Expand Down