From bd5969fc876a10b18613302db7087ef3c40f18e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:00 -0500 Subject: lib: Add mlibc Signed-off-by: Ian Moffett --- .../options/linux/include/bits/linux/cpu_set.h | 49 ++++++++++++++++++ .../options/linux/include/bits/linux/linux_sched.h | 59 ++++++++++++++++++++++ .../linux/include/bits/linux/linux_unistd.h | 21 ++++++++ 3 files changed, 129 insertions(+) create mode 100644 lib/mlibc/options/linux/include/bits/linux/cpu_set.h create mode 100644 lib/mlibc/options/linux/include/bits/linux/linux_sched.h create mode 100644 lib/mlibc/options/linux/include/bits/linux/linux_unistd.h (limited to 'lib/mlibc/options/linux/include/bits') diff --git a/lib/mlibc/options/linux/include/bits/linux/cpu_set.h b/lib/mlibc/options/linux/include/bits/linux/cpu_set.h new file mode 100644 index 0000000..f3c753e --- /dev/null +++ b/lib/mlibc/options/linux/include/bits/linux/cpu_set.h @@ -0,0 +1,49 @@ +#ifndef _LINUX_CPU_SET_H +#define _LINUX_CPU_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +#ifndef __MLIBC_ABI_ONLY + +cpu_set_t *__mlibc_cpu_alloc(int num_cpus); +size_t __mlibc_cpu_alloc_size(int num_cpus); + +void __mlibc_cpu_zero(const size_t setsize, cpu_set_t *set); +void __mlibc_cpu_set(const int cpu, const size_t setsize, cpu_set_t *set); +void __mlibc_cpu_clear(const int cpu, const size_t setsize, cpu_set_t *set); +int __mlibc_cpu_isset(const int cpu, const size_t setsize, const cpu_set_t *set); +int __mlibc_cpu_count(const size_t setsize, const cpu_set_t *set); + +#define CPU_ALLOC_SIZE(n) __mlibc_cpu_alloc_size((n)) +#define CPU_ALLOC(n) __mlibc_cpu_alloc((n)) +#define CPU_FREE(set) free((set)) + +#define CPU_ZERO_S(setsize, set) __mlibc_cpu_zero((setsize), (set)) +#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t), set) + +#define CPU_SET_S(cpu, setsize, set) __mlibc_cpu_set((cpu), (setsize), (set)) +#define CPU_SET(cpu, set) CPU_SET_S(cpu, sizeof(cpu_set_t), set) + +#define CPU_CLR_S(cpu, setsize, set) __mlibc_cpu_clear((cpu), (setsize), (set)) +#define CPU_CLR(cpu, set) CPU_CLR_S(cpu, sizeof(cpu_set_t), set) + +#define CPU_ISSET_S(cpu, setsize, set) __mlibc_cpu_isset((cpu), (setsize), (set)) +#define CPU_ISSET(cpu, set) CPU_ISSET_S(cpu, sizeof(cpu_set_t), set) + +#define CPU_COUNT_S(setsize, set) __mlibc_cpu_count((setsize), (set)) +#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t), set) + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif /* _LINUX_CPU_SET_H */ diff --git a/lib/mlibc/options/linux/include/bits/linux/linux_sched.h b/lib/mlibc/options/linux/include/bits/linux/linux_sched.h new file mode 100644 index 0000000..6a1209a --- /dev/null +++ b/lib/mlibc/options/linux/include/bits/linux/linux_sched.h @@ -0,0 +1,59 @@ + +#ifndef _LINUX_SCHED_H +#define _LINUX_SCHED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define CLONE_VM 0x00000100 +#define CLONE_FS 0x00000200 +#define CLONE_FILES 0x00000400 +#define CLONE_SIGHAND 0x00000800 +#define CLONE_PTRACE 0x00002000 +#define CLONE_VFORK 0x00004000 +#define CLONE_PARENT 0x00008000 +#define CLONE_THREAD 0x00010000 +#define CLONE_NEWNS 0x00020000 +#define CLONE_SYSVSEM 0x00040000 +#define CLONE_SETTLS 0x00080000 +#define CLONE_PARENT_SETTID 0x00100000 +#define CLONE_CHILD_CLEARTID 0x00200000 +#define CLONE_DETACHED 0x00400000 +#define CLONE_UNTRACED 0x00800000 +#define CLONE_CHILD_SETTID 0x01000000 +#define CLONE_NEWCGROUP 0x02000000 +#define CLONE_NEWUTS 0x04000000 +#define CLONE_NEWIPC 0x08000000 +#define CLONE_NEWUSER 0x10000000 +#define CLONE_NEWPID 0x20000000 +#define CLONE_NEWNET 0x40000000 +#define CLONE_IO 0x80000000 + +#ifndef __MLIBC_ABI_ONLY + +int sched_getscheduler(pid_t pid); +int sched_setaffinity(pid_t pid, size_t cpusetsize, const cpu_set_t *mask); +int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask); + +int unshare(int flags); +int clone(int (*)(void *), void *, int, void *, ...); + +/* Glibc extension */ +int sched_getcpu(void); + +#if defined(_GNU_SOURCE) +int setns(int fd, int nstype); +#endif /* _GNU_SOURCE */ + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif /* _LINUX_SCHED_H */ diff --git a/lib/mlibc/options/linux/include/bits/linux/linux_unistd.h b/lib/mlibc/options/linux/include/bits/linux/linux_unistd.h new file mode 100644 index 0000000..77534ba --- /dev/null +++ b/lib/mlibc/options/linux/include/bits/linux/linux_unistd.h @@ -0,0 +1,21 @@ +#ifndef _LINUX_UNISTD_H +#define _LINUX_UNISTD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +int dup3(int fd, int newfd, int flags); +int vhangup(void); +int getdtablesize(void); +int syncfs(int fd); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _LINUX_UNISTD_H -- cgit v1.2.3