summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-14 15:36:26 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-14 19:58:11 +0200
commit740140a661df037087f2efc0d2adb47472726c3b (patch)
treef32c165319f3552e7232d35705eac16538d3f3fc /Kernel
parent5c3440c5db431ff2f61c2fbecb7c0a2f509d9b16 (diff)
downloadserenity-740140a661df037087f2efc0d2adb47472726c3b.zip
Kernel+LibC: Share definitions in fcntl.h and sys/types.h
This patch begins the work of sharing types and macros between Kernel and LibC instead of duplicating them via the kludge in UnixTypes.h. The basic idea is that the Kernel vends various POSIX headers via Kernel/API/POSIX/ and LibC simply #include's them to get the macros.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/API/POSIX/fcntl.h60
-rw-r--r--Kernel/API/POSIX/sys/types.h101
-rw-r--r--Kernel/UnixTypes.h34
3 files changed, 162 insertions, 33 deletions
diff --git a/Kernel/API/POSIX/fcntl.h b/Kernel/API/POSIX/fcntl.h
new file mode 100644
index 0000000000..b28cefb678
--- /dev/null
+++ b/Kernel/API/POSIX/fcntl.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <Kernel/API/POSIX/sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define F_DUPFD 0
+#define F_GETFD 1
+#define F_SETFD 2
+#define F_GETFL 3
+#define F_SETFL 4
+#define F_ISTTY 5
+#define F_GETLK 6
+#define F_SETLK 7
+#define F_SETLKW 8
+
+#define FD_CLOEXEC 1
+
+#define O_RDONLY (1 << 0)
+#define O_WRONLY (1 << 1)
+#define O_RDWR (O_RDONLY | O_WRONLY)
+#define O_ACCMODE (O_RDONLY | O_WRONLY)
+#define O_EXEC (1 << 2)
+#define O_CREAT (1 << 3)
+#define O_EXCL (1 << 4)
+#define O_NOCTTY (1 << 5)
+#define O_TRUNC (1 << 6)
+#define O_APPEND (1 << 7)
+#define O_NONBLOCK (1 << 8)
+#define O_DIRECTORY (1 << 9)
+#define O_NOFOLLOW (1 << 10)
+#define O_CLOEXEC (1 << 11)
+#define O_DIRECT (1 << 12)
+
+#define F_RDLCK ((short)0)
+#define F_WRLCK ((short)1)
+#define F_UNLCK ((short)2)
+
+#define AT_FDCWD -100
+#define AT_SYMLINK_NOFOLLOW 0x100
+
+struct flock {
+ short l_type;
+ short l_whence;
+ off_t l_start;
+ off_t l_len;
+ pid_t l_pid;
+};
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/Kernel/API/POSIX/sys/types.h b/Kernel/API/POSIX/sys/types.h
new file mode 100644
index 0000000000..3029e0a101
--- /dev/null
+++ b/Kernel/API/POSIX/sys/types.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#ifndef KERNEL
+# include <sys/cdefs.h>
+# include <sys/types.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* There is no __SSIZE_TYPE__ but we can trick the preprocessor into defining it for us anyway! */
+#define unsigned signed
+typedef __SIZE_TYPE__ ssize_t;
+#undef unsigned
+
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
+
+typedef uint32_t uid_t;
+typedef uint32_t gid_t;
+
+typedef int __pid_t;
+#define pid_t __pid_t
+
+typedef char* caddr_t;
+
+typedef int id_t;
+
+typedef uint64_t ino_t;
+typedef int64_t off_t;
+
+typedef uint32_t blkcnt_t;
+typedef uint32_t blksize_t;
+typedef uint32_t dev_t;
+typedef uint16_t mode_t;
+typedef uint32_t nlink_t;
+
+typedef int64_t time_t;
+typedef uint32_t useconds_t;
+typedef int32_t suseconds_t;
+typedef uint32_t clock_t;
+
+typedef uint64_t fsblkcnt_t;
+typedef uint64_t fsfilcnt_t;
+
+#define __socklen_t_defined
+#define __socklen_t uint32_t
+typedef __socklen_t socklen_t;
+
+struct utimbuf {
+ time_t actime;
+ time_t modtime;
+};
+
+typedef int pthread_t;
+typedef int pthread_key_t;
+typedef uint32_t pthread_once_t;
+
+typedef struct __pthread_mutex_t {
+ uint32_t lock;
+ pthread_t owner;
+ int level;
+ int type;
+} pthread_mutex_t;
+
+typedef void* pthread_attr_t;
+typedef struct __pthread_mutexattr_t {
+ int type;
+} pthread_mutexattr_t;
+
+typedef struct __pthread_cond_t {
+ pthread_mutex_t* mutex;
+ uint32_t value;
+ int clockid; // clockid_t
+} pthread_cond_t;
+
+typedef uint64_t pthread_rwlock_t;
+typedef void* pthread_rwlockattr_t;
+typedef struct __pthread_spinlock_t {
+ int m_lock;
+} pthread_spinlock_t;
+typedef struct __pthread_condattr_t {
+ int clockid; // clockid_t
+} pthread_condattr_t;
+
+inline dev_t makedev(unsigned major, unsigned minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
+inline unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
+inline unsigned int minor(dev_t dev) { return (dev & 0xffu) | ((dev >> 12u) & 0xfff00u); }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/Kernel/UnixTypes.h b/Kernel/UnixTypes.h
index 1edee66b9e..a71b9ec5dc 100644
--- a/Kernel/UnixTypes.h
+++ b/Kernel/UnixTypes.h
@@ -8,22 +8,7 @@
#include <AK/DistinctNumeric.h>
#include <AK/Types.h>
-
-#define O_RDONLY (1 << 0)
-#define O_WRONLY (1 << 1)
-#define O_RDWR (O_RDONLY | O_WRONLY)
-#define O_ACCMODE (O_RDONLY | O_WRONLY)
-#define O_EXEC (1 << 2)
-#define O_CREAT (1 << 3)
-#define O_EXCL (1 << 4)
-#define O_NOCTTY (1 << 5)
-#define O_TRUNC (1 << 6)
-#define O_APPEND (1 << 7)
-#define O_NONBLOCK (1 << 8)
-#define O_DIRECTORY (1 << 9)
-#define O_NOFOLLOW (1 << 10)
-#define O_CLOEXEC (1 << 11)
-#define O_DIRECT (1 << 12)
+#include <Kernel/API/POSIX/fcntl.h>
// Kernel internal options.
#define O_NOFOLLOW_NOERROR (1 << 29)
@@ -426,11 +411,6 @@ struct sigaction {
typedef i64 off_t;
typedef i64 time_t;
-struct utimbuf {
- time_t actime;
- time_t modtime;
-};
-
typedef u32 blksize_t;
typedef u32 blkcnt_t;
@@ -770,15 +750,3 @@ struct statvfs {
unsigned long f_flag;
unsigned long f_namemax;
};
-
-#define F_RDLCK ((short)0)
-#define F_WRLCK ((short)1)
-#define F_UNLCK ((short)2)
-
-struct flock {
- short l_type;
- short l_whence;
- off_t l_start;
- off_t l_len;
- pid_t l_pid;
-};