Skip to content

Commit

Permalink
[LibOS] Move Linux ABI headers to a separate directory (part 1)
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Kowalczyk <mkow@invisiblethingslab.com>
  • Loading branch information
mkow committed Apr 16, 2023
1 parent 08038f8 commit 751b6c2
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 160 deletions.
15 changes: 0 additions & 15 deletions libos/include/arch/x86_64/libos_types_arch.h

This file was deleted.

17 changes: 17 additions & 0 deletions libos/include/arch/x86_64/linux_abi/signals_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 Intel Corporation
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
#pragma once

/* Types and structures used by various Linux ABIs (e.g. syscalls). */
/* These need to be binary-identical with the ones used by Linux. */

#define SIGS_CNT 64
#define SIGRTMIN 32

typedef struct {
unsigned long __val[SIGS_CNT / (8 * sizeof(unsigned long))];
} __sigset_t;

#define RED_ZONE_SIZE 128
2 changes: 1 addition & 1 deletion libos/include/libos_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ long libos_syscall_prlimit64(pid_t pid, int resource, const struct __kernel_rlim
long libos_syscall_sendmmsg(int fd, struct mmsghdr* msg, unsigned int vlen, unsigned int flags);
long libos_syscall_eventfd2(unsigned int count, int flags);
long libos_syscall_eventfd(unsigned int count);
long libos_syscall_getcpu(unsigned* cpu, unsigned* node, struct getcpu_cache* unused);
long libos_syscall_getcpu(unsigned* cpu, unsigned* node, void* unused_cache);
long libos_syscall_getrandom(char* buf, size_t count, unsigned int flags);
long libos_syscall_mlock2(unsigned long start, size_t len, int flags);
long libos_syscall_sysinfo(struct sysinfo* info);
Expand Down
147 changes: 8 additions & 139 deletions libos/include/libos_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,155 +5,24 @@
#include <stddef.h>
#include <stdint.h>

#include <asm/errno.h>
#include <asm/poll.h>
#include <asm/posix_types.h>
#include <asm/siginfo.h>
#include <asm/signal.h>
#include <asm/stat.h>
#include <asm/statfs.h>
#include <linux/aio_abi.h>
#include <linux/eventpoll.h>
#include <linux/futex.h>
#include <linux/kernel.h>
#include <linux/msg.h>
#include <linux/perf_event.h>
#include <linux/sem.h>
#include <linux/times.h>
#include <linux/timex.h>
#include <linux/types.h>
#include <linux/utime.h>
#include <linux/utsname.h>
#include <linux/version.h>

#include "elf.h"
#include "libos_types_arch.h"
#include "linux_socket.h"
#include "pal.h"

// TODO: remove from here and include only where they are used.
#include "linux_abi/types.h"
#include "linux_abi/fs.h"
#include "linux_abi/limits.h"
#include "linux_abi/sched.h"
#include "linux_abi/signals.h"
#include "linux_abi/time.h"

typedef unsigned long int nfds_t;
typedef unsigned long int nlink_t;

typedef __kernel_uid_t uid_t;
typedef __kernel_gid_t gid_t;
typedef __kernel_pid_t pid_t;
typedef __kernel_mode_t mode_t;
typedef __kernel_off_t off_t;
typedef __kernel_loff_t loff_t;
typedef __kernel_time_t time_t;
typedef __kernel_old_dev_t dev_t;
typedef __kernel_ino_t ino_t;
typedef __kernel_clockid_t clockid_t;
typedef __kernel_fd_set fd_set;

/* linux/time.h */
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
struct __kernel_timespec {
__kernel_time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
#endif

struct __kernel_timeval {
__kernel_time_t tv_sec; /* seconds */
__kernel_suseconds_t tv_usec; /* microsecond */
};

struct __kernel_itimerval {
struct __kernel_timeval it_interval; /* time interval */
struct __kernel_timeval it_value; /* current value */
};

struct __kernel_timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};

/* /arch/x86/include/asm/posix_types_64.h */
typedef unsigned int __kernel_uid_t;

struct __kernel_sched_param {
int __sched_priority;
};

struct __kernel_sigaction {
__sighandler_t k_sa_handler;
unsigned long sa_flags;
void (*sa_restorer)(void);
__sigset_t sa_mask;
};

/* linux/rlimit.h */
struct __kernel_rusage {
struct __kernel_timeval ru_utime; /* user time used */
struct __kernel_timeval ru_stime; /* system time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary " */
};

struct __kernel_rlimit {
unsigned long rlim_cur, rlim_max;
};

struct __kernel_rlimit64 {
uint64_t rlim_cur, rlim_max;
};

struct getcpu_cache {
unsigned long blob[128 / sizeof(long)];
};

#undef __CPU_SETSIZE
#undef __NCPUBITS

#define LINUX_DT_UNKNOWN 0
#define LINUX_DT_FIFO 1
#define LINUX_DT_CHR 2
#define LINUX_DT_DIR 4
#define LINUX_DT_BLK 6
#define LINUX_DT_REG 8
#define LINUX_DT_LNK 10
#define LINUX_DT_SOCK 12
#define LINUX_DT_WHT 14

struct linux_dirent64 {
uint64_t d_ino; /* Inode number */
uint64_t d_off; /* Offset to next linux_dirent */
unsigned short int d_reclen; /* Length of this linux_dirent */
unsigned char d_type;
char d_name[]; /* File name (null-terminated) */
};

struct linux_dirent {
unsigned long d_ino; /* Inode number */
unsigned long d_off; /* Offset to next linux_dirent */
unsigned short int d_reclen; /* Length of this linux_dirent */
char d_name[]; /* File name (null-terminated) */
};

struct linux_dirent_tail {
char pad;
unsigned char d_type;
};

struct linux_file_handle {
unsigned int handle_bytes;
int handle_type;
unsigned char f_handle[0];
};

typedef Elf64_auxv_t elf_auxv_t;

/* typedef for LibOS internal types */
Expand Down
40 changes: 40 additions & 0 deletions libos/include/linux_abi/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 Intel Corporation
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
#pragma once

/* Types and structures used by various Linux ABIs (e.g. syscalls). */
/* These need to be binary-identical with the ones used by Linux. */

#include <stdint.h>

struct linux_dirent64 {
uint64_t d_ino; /* Inode number */
uint64_t d_off; /* Offset to next linux_dirent */
unsigned short int d_reclen; /* Length of this linux_dirent */
unsigned char d_type;
char d_name[]; /* File name (null-terminated) */
};

struct linux_dirent {
unsigned long d_ino; /* Inode number */
unsigned long d_off; /* Offset to next linux_dirent */
unsigned short int d_reclen; /* Length of this linux_dirent */
char d_name[]; /* File name (null-terminated) */
};

struct linux_dirent_tail {
char pad;
unsigned char d_type;
};

#define LINUX_DT_UNKNOWN 0
#define LINUX_DT_FIFO 1
#define LINUX_DT_CHR 2
#define LINUX_DT_DIR 4
#define LINUX_DT_BLK 6
#define LINUX_DT_REG 8
#define LINUX_DT_LNK 10
#define LINUX_DT_SOCK 12
#define LINUX_DT_WHT 14
39 changes: 39 additions & 0 deletions libos/include/linux_abi/limits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 Intel Corporation
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
#pragma once

/* Types and structures used by various Linux ABIs (e.g. syscalls). */
/* These need to be binary-identical with the ones used by Linux. */

#include <stdint.h>

#include "linux_abi/time.h"

struct __kernel_rusage {
struct __kernel_timeval ru_utime; /* user time used */
struct __kernel_timeval ru_stime; /* system time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary " */
};

struct __kernel_rlimit {
unsigned long rlim_cur, rlim_max;
};

struct __kernel_rlimit64 {
uint64_t rlim_cur, rlim_max;
};
12 changes: 12 additions & 0 deletions libos/include/linux_abi/sched.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 Intel Corporation
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
#pragma once

/* Types and structures used by various Linux ABIs (e.g. syscalls). */
/* These need to be binary-identical with the ones used by Linux. */

struct __kernel_sched_param {
int __sched_priority;
};
21 changes: 21 additions & 0 deletions libos/include/linux_abi/signals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 Intel Corporation
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
#pragma once

/* Types and structures used by various Linux ABIs (e.g. syscalls). */
/* These need to be binary-identical with the ones used by Linux. */

// TODO: remove all of these includes and make this header libc-independent.
#include <asm/siginfo.h>
#include <asm/signal.h>

#include "linux_abi/signals_arch.h"

struct __kernel_sigaction {
__sighandler_t k_sa_handler;
unsigned long sa_flags;
void (*sa_restorer)(void);
__sigset_t sa_mask;
};
37 changes: 37 additions & 0 deletions libos/include/linux_abi/time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 Intel Corporation
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
#pragma once

/* Types and structures used by various Linux ABIs (e.g. syscalls). */
/* These need to be binary-identical with the ones used by Linux. */

// TODO: remove all of these includes and make this header libc-independent.
#include <linux/times.h>
#include <linux/timex.h>
#include <linux/utime.h>

typedef __kernel_time_t time_t;

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
struct __kernel_timespec {
__kernel_time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
#endif

struct __kernel_timeval {
__kernel_time_t tv_sec; /* seconds */
__kernel_suseconds_t tv_usec; /* microsecond */
};

struct __kernel_itimerval {
struct __kernel_timeval it_interval; /* time interval */
struct __kernel_timeval it_value; /* current value */
};

struct __kernel_timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
Loading

0 comments on commit 751b6c2

Please sign in to comment.