linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Paul E . McKenney" <paulmck@kernel.org>
Cc: Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, Willy Tarreau <w@1wt.eu>
Subject: [PATCH 04/42] tools/nolibc/types: split syscall-specific definitions into their own files
Date: Mon,  7 Feb 2022 17:23:16 +0100	[thread overview]
Message-ID: <20220207162354.14293-5-w@1wt.eu> (raw)
In-Reply-To: <20220207162354.14293-1-w@1wt.eu>

The macros and type definitions used by a number of syscalls were moved
to types.h where they will be easier to maintain. A few of them
are arch-specific and must not be moved there (e.g. O_*, sys_stat_struct).
A warning about them was placed at the top of the file.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 tools/include/nolibc/nolibc.h | 110 +---------------------------
 tools/include/nolibc/types.h  | 133 ++++++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+), 108 deletions(-)
 create mode 100644 tools/include/nolibc/types.h

diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 186a78c25326..3719959e6f57 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -94,7 +94,9 @@
 #include <linux/fs.h>
 #include <linux/loop.h>
 #include <linux/time.h>
+#include "types.h"
 
+/* Used by programs to avoid std includes */
 #define NOLIBC
 
 /* this way it will be removed if unused */
@@ -111,114 +113,6 @@ static int errno;
  */
 #define MAX_ERRNO 4095
 
-/* for poll() */
-struct pollfd {
-	int fd;
-	short int events;
-	short int revents;
-};
-
-/* for getdents64() */
-struct linux_dirent64 {
-	uint64_t       d_ino;
-	int64_t        d_off;
-	unsigned short d_reclen;
-	unsigned char  d_type;
-	char           d_name[];
-};
-
-/* commonly an fd_set represents 256 FDs */
-#define FD_SETSIZE 256
-typedef struct { uint32_t fd32[FD_SETSIZE/32]; } fd_set;
-
-/* needed by wait4() */
-struct rusage {
-	struct timeval ru_utime;
-	struct timeval ru_stime;
-	long   ru_maxrss;
-	long   ru_ixrss;
-	long   ru_idrss;
-	long   ru_isrss;
-	long   ru_minflt;
-	long   ru_majflt;
-	long   ru_nswap;
-	long   ru_inblock;
-	long   ru_oublock;
-	long   ru_msgsnd;
-	long   ru_msgrcv;
-	long   ru_nsignals;
-	long   ru_nvcsw;
-	long   ru_nivcsw;
-};
-
-/* stat flags (WARNING, octal here) */
-#define S_IFDIR       0040000
-#define S_IFCHR       0020000
-#define S_IFBLK       0060000
-#define S_IFREG       0100000
-#define S_IFIFO       0010000
-#define S_IFLNK       0120000
-#define S_IFSOCK      0140000
-#define S_IFMT        0170000
-
-#define S_ISDIR(mode)  (((mode) & S_IFDIR) == S_IFDIR)
-#define S_ISCHR(mode)  (((mode) & S_IFCHR) == S_IFCHR)
-#define S_ISBLK(mode)  (((mode) & S_IFBLK) == S_IFBLK)
-#define S_ISREG(mode)  (((mode) & S_IFREG) == S_IFREG)
-#define S_ISFIFO(mode) (((mode) & S_IFIFO) == S_IFIFO)
-#define S_ISLNK(mode)  (((mode) & S_IFLNK) == S_IFLNK)
-#define S_ISSOCK(mode) (((mode) & S_IFSOCK) == S_IFSOCK)
-
-#define DT_UNKNOWN 0
-#define DT_FIFO    1
-#define DT_CHR     2
-#define DT_DIR     4
-#define DT_BLK     6
-#define DT_REG     8
-#define DT_LNK    10
-#define DT_SOCK   12
-
-/* all the *at functions */
-#ifndef AT_FDCWD
-#define AT_FDCWD             -100
-#endif
-
-/* lseek */
-#define SEEK_SET        0
-#define SEEK_CUR        1
-#define SEEK_END        2
-
-/* reboot */
-#define LINUX_REBOOT_MAGIC1         0xfee1dead
-#define LINUX_REBOOT_MAGIC2         0x28121969
-#define LINUX_REBOOT_CMD_HALT       0xcdef0123
-#define LINUX_REBOOT_CMD_POWER_OFF  0x4321fedc
-#define LINUX_REBOOT_CMD_RESTART    0x01234567
-#define LINUX_REBOOT_CMD_SW_SUSPEND 0xd000fce2
-
-
-/* The format of the struct as returned by the libc to the application, which
- * significantly differs from the format returned by the stat() syscall flavours.
- */
-struct stat {
-	dev_t     st_dev;     /* ID of device containing file */
-	ino_t     st_ino;     /* inode number */
-	mode_t    st_mode;    /* protection */
-	nlink_t   st_nlink;   /* number of hard links */
-	uid_t     st_uid;     /* user ID of owner */
-	gid_t     st_gid;     /* group ID of owner */
-	dev_t     st_rdev;    /* device ID (if special file) */
-	off_t     st_size;    /* total size, in bytes */
-	blksize_t st_blksize; /* blocksize for file system I/O */
-	blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
-	time_t    st_atime;   /* time of last access */
-	time_t    st_mtime;   /* time of last modification */
-	time_t    st_ctime;   /* time of last status change */
-};
-
-#define WEXITSTATUS(status)   (((status) & 0xff00) >> 8)
-#define WIFEXITED(status)     (((status) & 0x7f) == 0)
-
 /* Below comes the architecture-specific code. For each architecture, we have
  * the syscall declarations and the _start code definition. This is the only
  * global part. On all architectures the kernel puts everything in the stack
diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h
new file mode 100644
index 000000000000..2f09abaf95f1
--- /dev/null
+++ b/tools/include/nolibc/types.h
@@ -0,0 +1,133 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * Special types used by various syscalls for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_TYPES_H
+#define _NOLIBC_TYPES_H
+
+#include "std.h"
+#include <linux/time.h>
+
+
+/* Only the generic macros and types may be defined here. The arch-specific
+ * ones such as the O_RDONLY and related macros used by fcntl() and open(), or
+ * the layout of sys_stat_struct must not be defined here.
+ */
+
+/* stat flags (WARNING, octal here) */
+#define S_IFDIR        0040000
+#define S_IFCHR        0020000
+#define S_IFBLK        0060000
+#define S_IFREG        0100000
+#define S_IFIFO        0010000
+#define S_IFLNK        0120000
+#define S_IFSOCK       0140000
+#define S_IFMT         0170000
+
+#define S_ISDIR(mode)  (((mode) & S_IFDIR)  == S_IFDIR)
+#define S_ISCHR(mode)  (((mode) & S_IFCHR)  == S_IFCHR)
+#define S_ISBLK(mode)  (((mode) & S_IFBLK)  == S_IFBLK)
+#define S_ISREG(mode)  (((mode) & S_IFREG)  == S_IFREG)
+#define S_ISFIFO(mode) (((mode) & S_IFIFO)  == S_IFIFO)
+#define S_ISLNK(mode)  (((mode) & S_IFLNK)  == S_IFLNK)
+#define S_ISSOCK(mode) (((mode) & S_IFSOCK) == S_IFSOCK)
+
+/* dirent types */
+#define DT_UNKNOWN     0x0
+#define DT_FIFO        0x1
+#define DT_CHR         0x2
+#define DT_DIR         0x4
+#define DT_BLK         0x6
+#define DT_REG         0x8
+#define DT_LNK         0xa
+#define DT_SOCK        0xc
+
+/* commonly an fd_set represents 256 FDs */
+#define FD_SETSIZE     256
+
+/* Special FD used by all the *at functions */
+#ifndef AT_FDCWD
+#define AT_FDCWD       (-100)
+#endif
+
+/* whence values for lseek() */
+#define SEEK_SET       0
+#define SEEK_CUR       1
+#define SEEK_END       2
+
+/* cmd for reboot() */
+#define LINUX_REBOOT_MAGIC1         0xfee1dead
+#define LINUX_REBOOT_MAGIC2         0x28121969
+#define LINUX_REBOOT_CMD_HALT       0xcdef0123
+#define LINUX_REBOOT_CMD_POWER_OFF  0x4321fedc
+#define LINUX_REBOOT_CMD_RESTART    0x01234567
+#define LINUX_REBOOT_CMD_SW_SUSPEND 0xd000fce2
+
+/* Macros used on waitpid()'s return status */
+#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
+#define WIFEXITED(status)   (((status) & 0x7f) == 0)
+
+
+/* for select() */
+typedef struct {
+	uint32_t fd32[FD_SETSIZE / 32];
+} fd_set;
+
+/* for poll() */
+struct pollfd {
+	int fd;
+	short int events;
+	short int revents;
+};
+
+/* for getdents64() */
+struct linux_dirent64 {
+	uint64_t       d_ino;
+	int64_t        d_off;
+	unsigned short d_reclen;
+	unsigned char  d_type;
+	char           d_name[];
+};
+
+/* needed by wait4() */
+struct rusage {
+	struct timeval ru_utime;
+	struct timeval ru_stime;
+	long   ru_maxrss;
+	long   ru_ixrss;
+	long   ru_idrss;
+	long   ru_isrss;
+	long   ru_minflt;
+	long   ru_majflt;
+	long   ru_nswap;
+	long   ru_inblock;
+	long   ru_oublock;
+	long   ru_msgsnd;
+	long   ru_msgrcv;
+	long   ru_nsignals;
+	long   ru_nvcsw;
+	long   ru_nivcsw;
+};
+
+/* The format of the struct as returned by the libc to the application, which
+ * significantly differs from the format returned by the stat() syscall flavours.
+ */
+struct stat {
+	dev_t     st_dev;     /* ID of device containing file */
+	ino_t     st_ino;     /* inode number */
+	mode_t    st_mode;    /* protection */
+	nlink_t   st_nlink;   /* number of hard links */
+	uid_t     st_uid;     /* user ID of owner */
+	gid_t     st_gid;     /* group ID of owner */
+	dev_t     st_rdev;    /* device ID (if special file) */
+	off_t     st_size;    /* total size, in bytes */
+	blksize_t st_blksize; /* blocksize for file system I/O */
+	blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
+	time_t    st_atime;   /* time of last access */
+	time_t    st_mtime;   /* time of last modification */
+	time_t    st_ctime;   /* time of last status change */
+};
+
+#endif /* _NOLIBC_TYPES_H */
-- 
2.35.1


  parent reply	other threads:[~2022-02-07 16:45 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 16:23 [PATCH 00/42] nolibc: update to resync with out-of-tree project Willy Tarreau
2022-02-07 16:23 ` [PATCH 01/42] tools/nolibc: use pselect6 on RISCV Willy Tarreau
2022-02-07 16:23 ` [PATCH 02/42] tools/nolibc: guard the main file against multiple inclusion Willy Tarreau
2022-02-07 16:23 ` [PATCH 03/42] tools/nolibc/std: move the standard type definitions to std.h Willy Tarreau
2022-02-07 16:23 ` Willy Tarreau [this message]
2022-02-07 16:23 ` [PATCH 05/42] tools/nolibc/arch: split arch-specific code into individual files Willy Tarreau
2022-02-07 16:23 ` [PATCH 06/42] tools/nolibc/sys: split the syscall definitions into their own file Willy Tarreau
2022-02-07 16:23 ` [PATCH 07/42] tools/nolibc/stdlib: extract the stdlib-specific functions to " Willy Tarreau
2022-02-07 16:23 ` [PATCH 08/42] tools/nolibc/string: split the string functions into string.h Willy Tarreau
2022-02-07 16:23 ` [PATCH 09/42] tools/nolibc/ctype: split the is* functions to ctype.h Willy Tarreau
2022-02-07 16:23 ` [PATCH 10/42] tools/nolibc/ctype: add the missing is* functions Willy Tarreau
2022-02-07 16:23 ` [PATCH 11/42] tools/nolibc/types: move the FD_* functions to macros in types.h Willy Tarreau
2022-02-07 17:05   ` David Laight
2022-02-08  5:14     ` Willy Tarreau
2022-02-13  8:52   ` [PATCH v2 " Willy Tarreau
2022-02-07 16:23 ` [PATCH 12/42] tools/nolibc/types: make FD_SETSIZE configurable Willy Tarreau
2022-02-13  8:53   ` [PATCH v2 " Willy Tarreau
2022-02-14 20:17     ` Paul E. McKenney
2022-02-07 16:23 ` [PATCH 13/42] tools/nolibc/types: move makedev to types.h and make it a macro Willy Tarreau
2022-02-07 16:23 ` [PATCH 14/42] tools/nolibc/stdlib: move ltoa() to stdlib.h Willy Tarreau
2022-02-07 16:23 ` [PATCH 15/42] tools/nolibc/stdlib: replace the ltoa() function with more efficient ones Willy Tarreau
2022-02-07 16:23 ` [PATCH 16/42] tools/nolibc/stdlib: add i64toa() and u64toa() Willy Tarreau
2022-02-07 16:23 ` [PATCH 17/42] tools/nolibc/stdlib: add utoh() and u64toh() Willy Tarreau
2022-02-07 16:23 ` [PATCH 18/42] tools/nolibc/stdio: add a minimal set of stdio functions Willy Tarreau
2022-02-07 16:23 ` [PATCH 19/42] tools/nolibc/stdio: add stdin/stdout/stderr and fget*/fput* functions Willy Tarreau
2022-02-07 16:23 ` [PATCH 20/42] tools/nolibc/stdio: add fwrite() to stdio Willy Tarreau
2022-02-07 16:23 ` [PATCH 21/42] tools/nolibc/stdio: add a minimal [vf]printf() implementation Willy Tarreau
2022-02-07 16:23 ` [PATCH 22/42] tools/nolibc/types: define EXIT_SUCCESS and EXIT_FAILURE Willy Tarreau
2022-02-07 16:23 ` [PATCH 23/42] tools/nolibc/stdio: add perror() to report the errno value Willy Tarreau
2022-02-07 16:23 ` [PATCH 24/42] tools/nolibc/sys: make open() take a vararg on the 3rd argument Willy Tarreau
2022-02-07 16:23 ` [PATCH 25/42] tools/nolibc/stdlib: avoid a 64-bit shift in u64toh_r() Willy Tarreau
2022-02-07 16:23 ` [PATCH 26/42] tools/nolibc/stdlib: make raise() use the lower level syscalls only Willy Tarreau
2022-02-07 16:23 ` [PATCH 27/42] tools/nolibc/sys: make getpgrp(), getpid(), gettid() not set errno Willy Tarreau
2022-02-07 16:23 ` [PATCH 28/42] tools/nolibc/string: use unidirectional variants for memcpy() Willy Tarreau
2022-02-07 16:23 ` [PATCH 29/42] tools/nolibc/string: slightly simplify memmove() Willy Tarreau
2022-02-07 16:23 ` [PATCH 30/42] tools/nolibc/string: add strncpy() and strlcpy() Willy Tarreau
2022-02-07 16:23 ` [PATCH 31/42] tools/nolibc/string: add tiny versions of strncat() and strlcat() Willy Tarreau
2022-02-07 16:23 ` [PATCH 32/42] tools/nolibc: move exported functions to their own section Willy Tarreau
2022-02-07 16:23 ` [PATCH 33/42] tools/nolibc/arch: mark the _start symbol as weak Willy Tarreau
2022-02-07 16:23 ` [PATCH 34/42] tools/nolibc/types: define PATH_MAX and MAXPATHLEN Willy Tarreau
2022-02-07 16:23 ` [PATCH 35/42] tools/nolibc/string: export memset() and memmove() Willy Tarreau
2022-02-07 16:23 ` [PATCH 36/42] tools/nolibc/errno: extract errno.h from sys.h Willy Tarreau
2022-02-07 16:23 ` [PATCH 37/42] tools/nolibc/unistd: extract msleep(), sleep(), tcsetpgrp() to unistd.h Willy Tarreau
2022-02-07 16:23 ` [PATCH 38/42] tools/nolibc/unistd: add usleep() Willy Tarreau
2022-02-07 16:23 ` [PATCH 39/42] tools/nolibc/signal: move raise() to signal.h Willy Tarreau
2022-02-07 16:23 ` [PATCH 40/42] tools/nolibc/time: create time.h with time() Willy Tarreau
2022-02-07 16:23 ` [PATCH 41/42] tools/nolibc: also mention how to build by just setting the include path Willy Tarreau
2022-02-07 16:23 ` [PATCH 42/42] tools/nolibc/stdlib: implement abort() Willy Tarreau
2022-02-08  0:00 ` [PATCH 00/42] nolibc: update to resync with out-of-tree project Paul E. McKenney
2022-02-08  4:41   ` Willy Tarreau
2022-02-08  5:10     ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220207162354.14293-5-w@1wt.eu \
    --to=w@1wt.eu \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).