diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-14 18:10:13 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-14 19:28:34 +0100 |
| commit | 872cf03f26c2801ae6c3008ce5fa0d7856f5f85d (patch) | |
| tree | 94809812b71ee286eb5b74c70e4d08fc4c8dc057 | |
| parent | ec769a83bde09c76bd6ad9ee7f391036dba5cd97 (diff) | |
libc: implement err/warn functions
200 files changed, 423 insertions, 202 deletions
@@ -11,3 +11,5 @@ menu "General Setup" help Enable this option to include debugging symbols and additional debug information in the build. endmenu + +source "bin/Kconfig" @@ -1,5 +1,7 @@ obj-y += clear/ obj-y += echo/ obj-y += false/ +obj-y += free/ obj-y += gzip/ +obj-y += sync/ obj-y += true/ diff --git a/bin/Kconfig b/bin/Kconfig new file mode 100644 index 00000000..0dcab22e --- /dev/null +++ b/bin/Kconfig @@ -0,0 +1,46 @@ +# bin/Kconfig + +menu "Binary Utilities Configuration" +config BIN_CLEAR + bool "clear" + default y + help + Enable the 'clear' command to clear the terminal screen. + +config BIN_ECHO + bool "echo" + default y + help + Enable the 'echo' command to display a line of text. + +config BIN_FALSE + bool "false" + default y + help + Enable the 'false' command which returns a non-zero exit status. + +config BIN_FREE + bool "free" + default y + help + Enable the 'free' command to display memory usage. + +config BIN_GZIP + bool "gzip" + default n + help + Enable the 'gzip' command to compress files using the gzip algorithm. + +config BIN_SYNC + bool "sync" + default y + help + Enable the 'sync' command to flush filesystem buffers. + +config BIN_TRUE + bool "true" + default y + help + Enable the 'true' command which returns a zero exit status. + +endmenu diff --git a/bin/clear/clear b/bin/clear/clear Binary files differnew file mode 100755 index 00000000..27b775a0 --- /dev/null +++ b/bin/clear/clear diff --git a/bin/clear/clear.c b/bin/clear/clear.c index 9c371ea7..c5a7a7c0 100644 --- a/bin/clear/clear.c +++ b/bin/clear/clear.c @@ -1,14 +1,7 @@ -#include <sys/cdefs.h> #include <unistd.h> -int main(int argc, char **__unused argv) +void _start(void) { - if (argc) { - write(STDOUT_FILENO, "usage: clear\n", 13); - return 0; - } - write(STDOUT_FILENO, "\033[H\033[2J", 7); - - return 0; + _exit(0); } diff --git a/bin/echo/Kbuild b/bin/echo/Kbuild index 919423fd..00d6ecdd 100644 --- a/bin/echo/Kbuild +++ b/bin/echo/Kbuild @@ -1,5 +1,3 @@ bin-y := echo - -libs-y += $(srctree)/lib/libc/libc.a - obj-y += echo.o +libs-y += $(srctree)/lib/libc/libc.a diff --git a/bin/echo/echo b/bin/echo/echo Binary files differnew file mode 100755 index 00000000..95ff666c --- /dev/null +++ b/bin/echo/echo diff --git a/bin/echo/echo.c b/bin/echo/echo.c index b5ceee1c..ee932898 100644 --- a/bin/echo/echo.c +++ b/bin/echo/echo.c @@ -1,30 +1,35 @@ +#include <alloca.h> // for alloca +#include <err.h> // for errx #include <string.h> // for strlen #include <sys/uio.h> // for iovec, writev #include <unistd.h> // for STDOUT_FILENO int main(int argc, char **argv) { + struct iovec *iov; + int n_iov; + if (argc <= 1) return 0; - struct iovec iov[2 * argc - 2]; - int iovcnt = 0; + iov = alloca(sizeof(struct iovec) * (int)(2 * argc)); + n_iov = 0; for (int i = 1; i < argc; i++) { - iov[iovcnt].iov_base = argv[i]; - iov[iovcnt].iov_len = strlen(argv[i]); - iovcnt++; + iov[n_iov].iov_base = argv[i]; + iov[n_iov++].iov_len = strlen(argv[i]); if (i < argc - 1) { - iov[iovcnt].iov_base = " "; - iov[iovcnt].iov_len = 1; - iovcnt++; + iov[n_iov].iov_base = " "; + iov[n_iov++].iov_len = 1; } } - iov[iovcnt].iov_base = "\n"; - iov[iovcnt].iov_len = 1; - iovcnt++; + iov[n_iov].iov_base = "\n"; + iov[n_iov++].iov_len = 1; + + if (writev(STDOUT_FILENO, iov, n_iov) < 0) + err(1, "writev"); - return writev(STDOUT_FILENO, iov, iovcnt) < 0 ? 1 : 0; + return 0; } diff --git a/bin/false/false b/bin/false/false Binary files differnew file mode 100755 index 00000000..627a3e2d --- /dev/null +++ b/bin/false/false diff --git a/bin/free/Kbuild b/bin/free/Kbuild new file mode 100644 index 00000000..08613953 --- /dev/null +++ b/bin/free/Kbuild @@ -0,0 +1,4 @@ +bin-y := free +obj-y += free.o +libs-y += $(srctree)/lib/libc/libc.a + diff --git a/bin/free/free b/bin/free/free Binary files differnew file mode 100755 index 00000000..31c93e2f --- /dev/null +++ b/bin/free/free diff --git a/bin/free/free.c b/bin/free/free.c new file mode 100644 index 00000000..b42ad99a --- /dev/null +++ b/bin/free/free.c @@ -0,0 +1,64 @@ +#include <stdio.h> +#include <sys/sysinfo.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + int opt; + struct sysinfo info; + unsigned int shift; + + while ((opt = getopt(argc, argv, "hmtbs")) != -1) { + switch (opt) { + case 'b': /* bytes */ + shift = 0; + break; + case 'k': /* kibibytes */ + shift = 10; + break; + case 'm': /* mebibytes */ + shift = 20; + break; + case 'g': /* gibibytes */ + shift = 30; + break; + default: + goto usage; + } + } + + if (sysinfo(&info) < 0) + perror("sysinfo"); + + printf(" %13s%13s%13s%13s%13s\n", "total", "used", "free", "shared", + "buffers"); + + printf("Mem: %13llu%13llu%13llu%13llu%13llu\n", + (unsigned long long)((info.totalram * info.mem_unit) >> shift), + (unsigned long long)(((info.totalram - info.freeram) * + info.mem_unit) >> + shift), + (unsigned long long)((info.freeram * info.mem_unit) >> shift), + (unsigned long long)((info.sharedram * info.mem_unit) >> shift), + (unsigned long long)((info.bufferram * info.mem_unit) >> shift)); + + printf("-/+ buffers/cache:%13llu%13llu\n", + (unsigned long long)(((info.totalram - info.freeram - + info.bufferram) * + info.mem_unit) >> + shift), + (unsigned long long)(((info.freeram + info.bufferram) * + info.mem_unit) >> + shift)); + printf("Swap:%13llu%13llu%13llu\n", + (unsigned long long)((info.totalswap * info.mem_unit) >> shift), + (unsigned long long)(((info.totalswap - info.freeswap) * + info.mem_unit) >> + shift), + (unsigned long long)((info.freeswap * info.mem_unit) >> shift)); + + return 0; +usage: + write(STDOUT_FILENO, "usage: free [-hmtbs]\n", 21); + return 0; +} diff --git a/bin/sync/Kbuild b/bin/sync/Kbuild new file mode 100644 index 00000000..14337916 --- /dev/null +++ b/bin/sync/Kbuild @@ -0,0 +1,3 @@ +bin-y := sync + +obj-y += arch/ diff --git a/bin/sync/arch/Kbuild b/bin/sync/arch/Kbuild new file mode 100644 index 00000000..ad3a7486 --- /dev/null +++ b/bin/sync/arch/Kbuild @@ -0,0 +1 @@ +obj-y += $(ARCH)/ diff --git a/bin/sync/arch/x86_64/Kbuild b/bin/sync/arch/x86_64/Kbuild new file mode 100644 index 00000000..7da95e2c --- /dev/null +++ b/bin/sync/arch/x86_64/Kbuild @@ -0,0 +1 @@ +obj-y += sync.o diff --git a/bin/sync/arch/x86_64/sync.s b/bin/sync/arch/x86_64/sync.s new file mode 100644 index 00000000..f1fc7ffc --- /dev/null +++ b/bin/sync/arch/x86_64/sync.s @@ -0,0 +1,5 @@ +.globl _start + +_start: + mov 162, %rax + syscall diff --git a/bin/sync/sync b/bin/sync/sync Binary files differnew file mode 100755 index 00000000..95965cdc --- /dev/null +++ b/bin/sync/sync diff --git a/bin/true/true b/bin/true/true Binary files differnew file mode 100755 index 00000000..8f690cd7 --- /dev/null +++ b/bin/true/true diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..25133bb0 --- /dev/null +++ b/dockerfile @@ -0,0 +1,3 @@ +FROM alpine:latest +RUN apk add --no-cache e2fsprogs util-linux cpio make xz e2fsprogs-extra sfdisk losetup kpartx jq dosfstools mtools +WORKDIR /openlinux diff --git a/include/arch/x86_64/drm/drm.h b/include/arch/x86_64/drm/drm.h index a928f61f..ebd6ebb5 100644 --- a/include/arch/x86_64/drm/drm.h +++ b/include/arch/x86_64/drm/drm.h @@ -253,7 +253,7 @@ enum drm_stat_type { _DRM_STAT_DMA, /**< DMA */ _DRM_STAT_SPECIAL, /**< Special DMA (e.g., priority or polled) */ _DRM_STAT_MISSED /**< Missed DMA opportunity */ - /* Add to the *END* of the list */ + /* Add to the *END* of the list */ }; /* diff --git a/include/arch/x86_64/drm/i915_drm.h b/include/arch/x86_64/drm/i915_drm.h index e0403cb6..68f08e16 100644 --- a/include/arch/x86_64/drm/i915_drm.h +++ b/include/arch/x86_64/drm/i915_drm.h @@ -2115,10 +2115,10 @@ struct drm_i915_gem_context_param { #define I915_CONTEXT_MAX_USER_PRIORITY 1023 /* inclusive */ #define I915_CONTEXT_DEFAULT_PRIORITY 0 #define I915_CONTEXT_MIN_USER_PRIORITY -1023 /* inclusive */ - /* - * When using the following param, value should be a pointer to - * drm_i915_gem_context_param_sseu. - */ + /* + * When using the following param, value should be a pointer to + * drm_i915_gem_context_param_sseu. + */ #define I915_CONTEXT_PARAM_SSEU 0x7 /* diff --git a/include/arch/x86_64/linux/can/isotp.h b/include/arch/x86_64/linux/can/isotp.h index d986173d..3d72f3d3 100644 --- a/include/arch/x86_64/linux/can/isotp.h +++ b/include/arch/x86_64/linux/can/isotp.h @@ -85,7 +85,7 @@ struct can_isotp_options { /* __u8 value : content on rx path */ __u8 rx_ext_address; /* set address for extended addressing */ - /* __u8 value : extended address (rx) */ + /* __u8 value : extended address (rx) */ }; struct can_isotp_fc_options { diff --git a/include/arch/x86_64/linux/hdlcdrv.h b/include/arch/x86_64/linux/hdlcdrv.h index 784d1dcf..0d3f0ba7 100644 --- a/include/arch/x86_64/linux/hdlcdrv.h +++ b/include/arch/x86_64/linux/hdlcdrv.h @@ -29,7 +29,7 @@ struct hdlcdrv_channel_params { int slottime; /* the slottime in 10ms; usually 10 = 100ms */ int ppersist; /* the p-persistence 0..255 */ int fulldup; /* some driver do not support full duplex, setting */ - /* this just makes them send even if DCD is on */ + /* this just makes them send even if DCD is on */ }; struct hdlcdrv_old_channel_state { diff --git a/include/arch/x86_64/linux/scc.h b/include/arch/x86_64/linux/scc.h index ce9c783b..ac19e3ef 100644 --- a/include/arch/x86_64/linux/scc.h +++ b/include/arch/x86_64/linux/scc.h @@ -87,7 +87,7 @@ enum CLOCK_sources { CLK_DIVIDER, /* Rx = DPLL, Tx = divider (fullduplex with */ /* modems without clock regeneration */ CLK_BRG /* experimental fullduplex mode with DPLL/BRG for */ - /* MODEMs without clock recovery */ + /* MODEMs without clock recovery */ }; /* Tx state */ diff --git a/include/complex.h b/include/complex.h index e8cec9cc..ced87a8f 100644 --- a/include/complex.h +++ b/include/complex.h @@ -1,7 +1,6 @@ #ifndef __COMPLEX_H #define __COMPLEX_H -#include <complex.h> #define complex _Complex #define _Complex_I (__extension__(0.0f + 1.0fi)) #define imaginary _Imaginary diff --git a/include/err.h b/include/err.h index f08005f7..3e670fb8 100644 --- a/include/err.h +++ b/include/err.h @@ -2,16 +2,15 @@ #define __ERR_H #include <stdarg.h> +#include <sys/cdefs.h> -_Noreturn void err(int eval, const char *fmt, ...); -_Noreturn void errx(int eval, const char *fmt, ...); +__dead void err(int eval, const char *fmt, ...); +__dead void errx(int eval, const char *fmt, ...); +__dead void verr(int eval, const char *fmt, va_list args); +__dead void verrx(int eval, const char *fmt, va_list args); void warn(const char *fmt, ...); void warnx(const char *fmt, ...); - -_Noreturn void verr(int eval, const char *fmt, va_list args); -_Noreturn void verrx(int eval, const char *fmt, va_list args); - void vwarn(const char *fmt, va_list args); void vwarnx(const char *fmt, va_list args); diff --git a/include/execinfo.h b/include/execinfo.h new file mode 100644 index 00000000..08ff6557 --- /dev/null +++ b/include/execinfo.h @@ -0,0 +1,14 @@ +#ifndef __EXECINFO_H +#define __EXECINFO_H + +#include <sys/cdefs.h> + +__BEGIN_DECLS + +int backtrace(void *, int); +char **backtrace_symbols(void *const, int size); +void backtrace_symbols_fd(void *const, int, int); + +__END_DECLS + +#endif diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index 4c86d599..70ace705 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -1,8 +1,13 @@ #ifndef __SYS_CDEFS_H #define __SYS_CDEFS_H +#ifdef __cplusplus #define __BEGIN_DECLS extern "C" { #define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif #define __dead __attribute__((__noreturn__)) #define __used __attribute__((__used__)) diff --git a/include/sys/reboot.h b/include/sys/reboot.h new file mode 100644 index 00000000..d6499d10 --- /dev/null +++ b/include/sys/reboot.h @@ -0,0 +1,14 @@ +#ifndef __SYS_REBOOT_H +#define __SYS_REBOOT_H + +#define RB_AUTOBOOT 0x01234567 +#define RB_HALT_SYSTEM 0xCDEF0123 +#define RB_ENABLE_CAD 0x89ABCDEF +#define RB_DISABLE_CAD 0x00000000 +#define RB_POWRT_OFF 0x4321FEDC +#define RB_SW_SUSPEND 0xD000FCE2 +#define RB_KEXEC 0x45584543 + +int reboot(int); + +#endif diff --git a/lib/libc/Kbuild b/lib/libc/Kbuild index 638e79cc..55ec6422 100644 --- a/lib/libc/Kbuild +++ b/lib/libc/Kbuild @@ -9,8 +9,10 @@ obj-y += ctype/ obj-y += devctl/ obj-y += dirent/ obj-y += endian/ +obj-y += err/ obj-y += errno/ obj-y += fcntl/ +obj-y += fenv/ obj-y += grp/ obj-y += inttypes/ obj-y += libgen/ diff --git a/lib/libc/arch/x86_64/crt0.c b/lib/libc/arch/x86_64/crt0.c index 53ae222d..a278c525 100644 --- a/lib/libc/arch/x86_64/crt0.c +++ b/lib/libc/arch/x86_64/crt0.c @@ -10,6 +10,7 @@ extern int main(int, char *[]); char **environ; +char *__progname; struct __attribute__((packed)) auxv_t { uintptr_t a_type; @@ -29,6 +30,7 @@ __attribute__((used)) void __libc_start(uintptr_t *sp) argc = (int)(*sp); argv = (char **)(++sp); + __progname = argv[0]; sp += argc; environ = (char **)(++sp); diff --git a/lib/libc/devctl/posix_devctl.c b/lib/libc/devctl/posix_devctl.c index 1b9db522..7403ec53 100644 --- a/lib/libc/devctl/posix_devctl.c +++ b/lib/libc/devctl/posix_devctl.c @@ -1,9 +1,8 @@ - -#include <devctl.h> // for posix_devctl, size_t -#include <errno.h> // for errno -#include <libc.h> // for __unused +#include <devctl.h> // for posix_devctl, size_t +#include <errno.h> // for errno +#include <libc.h> // for __unused #include <stddef.h> #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/dirent/readdir_r.c b/lib/libc/dirent/readdir_r.c index d2ca9809..c7bffdea 100644 --- a/lib/libc/dirent/readdir_r.c +++ b/lib/libc/dirent/readdir_r.c @@ -1,6 +1,6 @@ /* Maintainer: <contact@bellrise.net> */ -#include "stdio.h" // for off_t +#include "sys/types.h" // for off_t #include <__dirent.h> // for linux_dirent64 #include <dirent.h> // for dirent, ssize_t, DIR, readdir_r diff --git a/lib/libc/err/Kbuild b/lib/libc/err/Kbuild new file mode 100644 index 00000000..e60623f5 --- /dev/null +++ b/lib/libc/err/Kbuild @@ -0,0 +1,8 @@ +obj-y += err.o +obj-y += errx.o +obj-y += verr.o +obj-y += verrx.o +obj-y += vwarn.o +obj-y += vwarnx.o +obj-y += warn.o +obj-y += warnx.o diff --git a/lib/libc/err/err.c b/lib/libc/err/err.c new file mode 100644 index 00000000..5b1b2b02 --- /dev/null +++ b/lib/libc/err/err.c @@ -0,0 +1,10 @@ +#include <err.h> +#include <stdarg.h> + +__dead void err(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verr(eval, fmt, ap); + va_end(ap); +} diff --git a/lib/libc/err/errx.c b/lib/libc/err/errx.c new file mode 100644 index 00000000..0afe999e --- /dev/null +++ b/lib/libc/err/errx.c @@ -0,0 +1,10 @@ +#include <err.h> +#include <stdarg.h> + +__dead void errx(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verrx(eval, fmt, ap); + va_end(ap); +} diff --git a/lib/libc/err/verr.c b/lib/libc/err/verr.c new file mode 100644 index 00000000..d769c15c --- /dev/null +++ b/lib/libc/err/verr.c @@ -0,0 +1,9 @@ +#include <err.h> +#include <stdarg.h> +#include <stdlib.h> + +__dead void verr(int eval, const char *fmt, va_list args) +{ + vwarn(fmt, args); + exit(eval); +} diff --git a/lib/libc/err/verrx.c b/lib/libc/err/verrx.c new file mode 100644 index 00000000..d769c15c --- /dev/null +++ b/lib/libc/err/verrx.c @@ -0,0 +1,9 @@ +#include <err.h> +#include <stdarg.h> +#include <stdlib.h> + +__dead void verr(int eval, const char *fmt, va_list args) +{ + vwarn(fmt, args); + exit(eval); +} diff --git a/lib/libc/err/vwarn.c b/lib/libc/err/vwarn.c new file mode 100644 index 00000000..2f485d93 --- /dev/null +++ b/lib/libc/err/vwarn.c @@ -0,0 +1,16 @@ +#include <stdarg.h> +#include <stdio.h> + +extern char *__progname; + +void vwarn(const char *fmt, va_list args) +{ + fprintf(stderr, "%s: ", __progname); + + if (fmt != NULL) { + vfprintf(stderr, fmt, args); + fprintf(stderr, ": "); + } + + perror(NULL); +} diff --git a/lib/libc/err/vwarnx.c b/lib/libc/err/vwarnx.c new file mode 100644 index 00000000..2f485d93 --- /dev/null +++ b/lib/libc/err/vwarnx.c @@ -0,0 +1,16 @@ +#include <stdarg.h> +#include <stdio.h> + +extern char *__progname; + +void vwarn(const char *fmt, va_list args) +{ + fprintf(stderr, "%s: ", __progname); + + if (fmt != NULL) { + vfprintf(stderr, fmt, args); + fprintf(stderr, ": "); + } + + perror(NULL); +} diff --git a/lib/libc/err/warn.c b/lib/libc/err/warn.c new file mode 100644 index 00000000..4f12995a --- /dev/null +++ b/lib/libc/err/warn.c @@ -0,0 +1,10 @@ +#include <err.h> +#include <stdarg.h> + +void warn(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); +} diff --git a/lib/libc/err/warnx.c b/lib/libc/err/warnx.c new file mode 100644 index 00000000..fa0e6fda --- /dev/null +++ b/lib/libc/err/warnx.c @@ -0,0 +1,10 @@ +#include <err.h> +#include <stdarg.h> + +void warnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); +} diff --git a/lib/libc/fcntl/creat.c b/lib/libc/fcntl/creat.c index 4b84ecae..436b343c 100644 --- a/lib/libc/fcntl/creat.c +++ b/lib/libc/fcntl/creat.c @@ -1,6 +1,5 @@ - #include <fcntl.h> // for creat #include <sys/types.h> // for mode_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/fcntl/fcntl.c b/lib/libc/fcntl/fcntl.c index b3ca012f..ca1f682d 100644 --- a/lib/libc/fcntl/fcntl.c +++ b/lib/libc/fcntl/fcntl.c @@ -1,4 +1,4 @@ -#include "errno.h" // for EINVAL +#include "errno.h" // for EINVAL #include <fcntl.h> // for F_DUPFD_CLOEXEC, FD_CLOEXEC, F_SETFD, F_D... #include <stdarg.h> // for va_arg, va_end, va_list, va_start diff --git a/lib/libc/fcntl/open.c b/lib/libc/fcntl/open.c index ab59e3c7..3e19aaf2 100644 --- a/lib/libc/fcntl/open.c +++ b/lib/libc/fcntl/open.c @@ -1,6 +1,5 @@ - #include <fcntl.h> // for FD_CLOEXEC, F_SETFD, O_CLOEXEC, O_CREAT #include <stdarg.h> // for va_arg, va_end, va_list, va_start #include <sys/types.h> // for mode_t diff --git a/lib/libc/fcntl/openat.c b/lib/libc/fcntl/openat.c index d99693dc..e178e226 100644 --- a/lib/libc/fcntl/openat.c +++ b/lib/libc/fcntl/openat.c @@ -1,6 +1,5 @@ - #include <fcntl.h> // for O_CREAT, openat #include <stdarg.h> // for va_arg, va_end, va_list, va_start #include <sys/types.h> // for mode_t diff --git a/lib/libc/fcntl/posix_fadvise.c b/lib/libc/fcntl/posix_fadvise.c index 51018a27..74954461 100644 --- a/lib/libc/fcntl/posix_fadvise.c +++ b/lib/libc/fcntl/posix_fadvise.c @@ -1,6 +1,5 @@ - #include <fcntl.h> // for posix_fadvise #include <sys/types.h> // for off_t #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/fcntl/posix_fallocate.c b/lib/libc/fcntl/posix_fallocate.c index c4a05fcc..f1d1e5ba 100644 --- a/lib/libc/fcntl/posix_fallocate.c +++ b/lib/libc/fcntl/posix_fallocate.c @@ -1,6 +1,5 @@ - #include <fcntl.h> // for posix_fallocate #include <sys/types.h> // for off_t #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/fenv/Kbuild b/lib/libc/fenv/Kbuild new file mode 100644 index 00000000..f20c5a3f --- /dev/null +++ b/lib/libc/fenv/Kbuild @@ -0,0 +1 @@ +obj-y += fesetround.o diff --git a/lib/libc/fenv/fesetround.c b/lib/libc/fenv/fesetround.c new file mode 100644 index 00000000..0c7c6bfe --- /dev/null +++ b/lib/libc/fenv/fesetround.c @@ -0,0 +1,8 @@ +#include <fenv.h> + +int __fesetround(int); + +int fesetround(int round) +{ + return __fesetround(round); +} diff --git a/lib/libc/mman/mlock.c b/lib/libc/mman/mlock.c index a8b029c6..c27ab5e4 100644 --- a/lib/libc/mman/mlock.c +++ b/lib/libc/mman/mlock.c @@ -1,6 +1,5 @@ - #include <stddef.h> // for size_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/mman/mlockall.c b/lib/libc/mman/mlockall.c index 9adb6b9e..74665680 100644 --- a/lib/libc/mman/mlockall.c +++ b/lib/libc/mman/mlockall.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int mlockall(int flags) diff --git a/lib/libc/mman/mmap.c b/lib/libc/mman/mmap.c index f5e09265..d43ed686 100644 --- a/lib/libc/mman/mmap.c +++ b/lib/libc/mman/mmap.c @@ -1,6 +1,5 @@ - #include <stddef.h> // for size_t #include <syscall.h> // for __syscall_6, syscall diff --git a/lib/libc/mman/mprotect.c b/lib/libc/mman/mprotect.c index 068d7e68..bc97ae4a 100644 --- a/lib/libc/mman/mprotect.c +++ b/lib/libc/mman/mprotect.c @@ -1,6 +1,5 @@ - #include <stddef.h> // for size_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/mman/msync.c b/lib/libc/mman/msync.c index 6cf3688b..3d1a1170 100644 --- a/lib/libc/mman/msync.c +++ b/lib/libc/mman/msync.c @@ -1,6 +1,5 @@ - #include <stddef.h> // for size_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/mman/munlock.c b/lib/libc/mman/munlock.c index 4e1901ef..9f7706fb 100644 --- a/lib/libc/mman/munlock.c +++ b/lib/libc/mman/munlock.c @@ -1,6 +1,5 @@ - #include <stddef.h> // for size_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/mman/munlockall.c b/lib/libc/mman/munlockall.c index cdeb5253..32ff016a 100644 --- a/lib/libc/mman/munlockall.c +++ b/lib/libc/mman/munlockall.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall int munlockall(void) diff --git a/lib/libc/mman/munmap.c b/lib/libc/mman/munmap.c index 7a4fe5fc..eb22c058 100644 --- a/lib/libc/mman/munmap.c +++ b/lib/libc/mman/munmap.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/mman.h> // for munmap, size_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/mman/posix_madvise.c b/lib/libc/mman/posix_madvise.c index 6e9243ca..427f95f2 100644 --- a/lib/libc/mman/posix_madvise.c +++ b/lib/libc/mman/posix_madvise.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/mman.h> // for posix_madvise, size_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/msg/msgctl.c b/lib/libc/msg/msgctl.c index a71bb9d9..1be164c6 100644 --- a/lib/libc/msg/msgctl.c +++ b/lib/libc/msg/msgctl.c @@ -1,6 +1,5 @@ - #include <sys/msg.h> // for msgctl #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/poll/poll.c b/lib/libc/poll/poll.c index 4601b9b3..60c79a16 100644 --- a/lib/libc/poll/poll.c +++ b/lib/libc/poll/poll.c @@ -1,6 +1,5 @@ - #include <poll.h> // for nfds_t, poll, pollfd #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/poll/ppoll.c b/lib/libc/poll/ppoll.c index da23d412..902ae5c5 100644 --- a/lib/libc/poll/ppoll.c +++ b/lib/libc/poll/ppoll.c @@ -1,6 +1,5 @@ - #include <poll.h> // for nfds_t, pollfd, ppoll #include <signal.h> // for sigset_t #include <syscall.h> // for __syscall_5, syscall diff --git a/lib/libc/select/pselect.c b/lib/libc/select/pselect.c index 0f434533..7ac84ad5 100644 --- a/lib/libc/select/pselect.c +++ b/lib/libc/select/pselect.c @@ -1,6 +1,5 @@ - #include <stdint.h> // for uintptr_t #include <sys/select.h> // for fd_set, pselect, sigset_t #include <syscall.h> // for __syscall_6, syscall, syscall_arg_t diff --git a/lib/libc/select/select.c b/lib/libc/select/select.c index 786724a8..9a0480c9 100644 --- a/lib/libc/select/select.c +++ b/lib/libc/select/select.c @@ -1,7 +1,6 @@ #define __BITS_SELECT_H_ #include "bits/select.h" // for fd_set, timeval (ptr only) - #include <sys/select.h> // for select #include <syscall.h> // for __syscall_6, syscall, syscall_arg_t diff --git a/lib/libc/sem/semctl.c b/lib/libc/sem/semctl.c index 14f6698d..7b047b62 100644 --- a/lib/libc/sem/semctl.c +++ b/lib/libc/sem/semctl.c @@ -1,6 +1,5 @@ - #include <stdarg.h> // for va_arg, va_end, va_list, va_start #include <stddef.h> // for NULL #include <sys/ipc.h> // for IPC_SET, IPC_STAT diff --git a/lib/libc/sem/semget.c b/lib/libc/sem/semget.c index d9652179..41901a0b 100644 --- a/lib/libc/sem/semget.c +++ b/lib/libc/sem/semget.c @@ -1,6 +1,5 @@ - #include <sys/sem.h> // for semget #include <sys/types.h> // for key_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/sem/semop.c b/lib/libc/sem/semop.c index 054c6a86..2e965784 100644 --- a/lib/libc/sem/semop.c +++ b/lib/libc/sem/semop.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/sem.h> // for semop, size_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/signal/kill.c b/lib/libc/signal/kill.c index 84d729f3..3e87b419 100644 --- a/lib/libc/signal/kill.c +++ b/lib/libc/signal/kill.c @@ -1,6 +1,5 @@ - #include <signal.h> // for kill #include <sys/types.h> // for pid_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/signal/pthread_kill.c b/lib/libc/signal/pthread_kill.c index 2c0bb40b..f5a2a991 100644 --- a/lib/libc/signal/pthread_kill.c +++ b/lib/libc/signal/pthread_kill.c @@ -1,4 +1,4 @@ -#include "errno.h" // for EINVAL +#include "errno.h" // for EINVAL #include <__thread.h> // for __thread_self #include <asm-generic/signal.h> // for _NSIG diff --git a/lib/libc/signal/sigaction.c b/lib/libc/signal/sigaction.c index 93e8aab2..95f485d3 100644 --- a/lib/libc/signal/sigaction.c +++ b/lib/libc/signal/sigaction.c @@ -1,6 +1,5 @@ - #include <signal.h> // for sigaction, sigset_t #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/signal/sigpending.c b/lib/libc/signal/sigpending.c index 90414b1e..88cfb234 100644 --- a/lib/libc/signal/sigpending.c +++ b/lib/libc/signal/sigpending.c @@ -1,6 +1,5 @@ - #include <signal.h> // for sigpending, sigset_t #include <syscall.h> // for __syscall_1, syscall diff --git a/lib/libc/signal/sigprocmask.c b/lib/libc/signal/sigprocmask.c index 4f766ec3..c4a3cdb0 100644 --- a/lib/libc/signal/sigprocmask.c +++ b/lib/libc/signal/sigprocmask.c @@ -1,6 +1,5 @@ - #include <signal.h> // for sigset_t, sigprocmask #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/signal/sigsuspend.c b/lib/libc/signal/sigsuspend.c index 214d7c39..a7de0c02 100644 --- a/lib/libc/signal/sigsuspend.c +++ b/lib/libc/signal/sigsuspend.c @@ -1,6 +1,5 @@ - #include <signal.h> // for sigset_t, sigsuspend #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/signal/sigtimedwait.c b/lib/libc/signal/sigtimedwait.c index 5445d1d7..e33743d9 100644 --- a/lib/libc/signal/sigtimedwait.c +++ b/lib/libc/signal/sigtimedwait.c @@ -1,6 +1,5 @@ - #include <signal.h> // for siginfo_t, sigset_t, sigtimedwait #include <syscall.h> // for __syscall_4, syscall #include <time.h> diff --git a/lib/libc/socket/accept.c b/lib/libc/socket/accept.c index d720b2e9..af897d3c 100644 --- a/lib/libc/socket/accept.c +++ b/lib/libc/socket/accept.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for accept, socklen_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/accept4.c b/lib/libc/socket/accept4.c index ff5cbc06..80b05488 100644 --- a/lib/libc/socket/accept4.c +++ b/lib/libc/socket/accept4.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for accept4, socklen_t #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/socket/bind.c b/lib/libc/socket/bind.c index e605cfda..50c1f7ac 100644 --- a/lib/libc/socket/bind.c +++ b/lib/libc/socket/bind.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for bind, socklen_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/connect.c b/lib/libc/socket/connect.c index e9f0795a..dabe5135 100644 --- a/lib/libc/socket/connect.c +++ b/lib/libc/socket/connect.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for connect, socklen_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/getpeername.c b/lib/libc/socket/getpeername.c index d8edb334..ed5361b0 100644 --- a/lib/libc/socket/getpeername.c +++ b/lib/libc/socket/getpeername.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for getpeername, socklen_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/getsockname.c b/lib/libc/socket/getsockname.c index 3cb898fa..3da117cc 100644 --- a/lib/libc/socket/getsockname.c +++ b/lib/libc/socket/getsockname.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for getsockname, socklen_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/getsockopt.c b/lib/libc/socket/getsockopt.c index 6c5694e8..c2c5f0eb 100644 --- a/lib/libc/socket/getsockopt.c +++ b/lib/libc/socket/getsockopt.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for getsockopt, socklen_t #include <syscall.h> // for __syscall_5, syscall diff --git a/lib/libc/socket/listen.c b/lib/libc/socket/listen.c index 62fdb9b4..474bdeca 100644 --- a/lib/libc/socket/listen.c +++ b/lib/libc/socket/listen.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for listen #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/socket/recv.c b/lib/libc/socket/recv.c index a7ed4998..7c9f48e0 100644 --- a/lib/libc/socket/recv.c +++ b/lib/libc/socket/recv.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/socket.h> // for recv #include <sys/types.h> // for size_t, ssize_t diff --git a/lib/libc/socket/recvfrom.c b/lib/libc/socket/recvfrom.c index 1afb088d..d8aff7e1 100644 --- a/lib/libc/socket/recvfrom.c +++ b/lib/libc/socket/recvfrom.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/socket.h> // for recvfrom, socklen_t #include <sys/types.h> // for size_t, ssize_t diff --git a/lib/libc/socket/recvmsg.c b/lib/libc/socket/recvmsg.c index a4b2cc13..3413d170 100644 --- a/lib/libc/socket/recvmsg.c +++ b/lib/libc/socket/recvmsg.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for recvmsg #include <sys/types.h> // for ssize_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/send.c b/lib/libc/socket/send.c index 45de1514..ec38c200 100644 --- a/lib/libc/socket/send.c +++ b/lib/libc/socket/send.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/socket.h> // for send #include <sys/types.h> // for size_t, ssize_t diff --git a/lib/libc/socket/sendmsg.c b/lib/libc/socket/sendmsg.c index 11814d19..393d29c2 100644 --- a/lib/libc/socket/sendmsg.c +++ b/lib/libc/socket/sendmsg.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for sendmsg #include <sys/types.h> // for ssize_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/sendto.c b/lib/libc/socket/sendto.c index a9403917..6dc4cc66 100644 --- a/lib/libc/socket/sendto.c +++ b/lib/libc/socket/sendto.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <sys/socket.h> // for sendto, socklen_t #include <sys/types.h> // for size_t, ssize_t diff --git a/lib/libc/socket/setsockopt.c b/lib/libc/socket/setsockopt.c index c9ae6f88..1a2531a6 100644 --- a/lib/libc/socket/setsockopt.c +++ b/lib/libc/socket/setsockopt.c @@ -1,6 +1,5 @@ - #include <sys/socket.h> // for setsockopt, socklen_t #include <syscall.h> // for __syscall_5, syscall diff --git a/lib/libc/socket/shutdown.c b/lib/libc/socket/shutdown.c index b667204e..fd14c70f 100644 --- a/lib/libc/socket/shutdown.c +++ b/lib/libc/socket/shutdown.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int shutdown(int socket, int how) diff --git a/lib/libc/socket/sockatmark.c b/lib/libc/socket/sockatmark.c index 92045454..cf6ab896 100644 --- a/lib/libc/socket/sockatmark.c +++ b/lib/libc/socket/sockatmark.c @@ -1,6 +1,5 @@ - #include <asm-generic/sockios.h> // for SIOCATMARK #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/socket/socket.c b/lib/libc/socket/socket.c index 2c300be6..a18acaa3 100644 --- a/lib/libc/socket/socket.c +++ b/lib/libc/socket/socket.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall int socket(int domain, int type, int protocol) diff --git a/lib/libc/socket/socketpair.c b/lib/libc/socket/socketpair.c index 30749d3a..24d93b58 100644 --- a/lib/libc/socket/socketpair.c +++ b/lib/libc/socket/socketpair.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_4, syscall int socketpair(int domain, int type, int protocol, int socket_vector[2]) diff --git a/lib/libc/stat/chmod.c b/lib/libc/stat/chmod.c index 005869ba..061fc87e 100644 --- a/lib/libc/stat/chmod.c +++ b/lib/libc/stat/chmod.c @@ -1,6 +1,5 @@ - #include <sys/stat.h> // for chmod #include <sys/types.h> // for mode_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/stat/fchmod.c b/lib/libc/stat/fchmod.c index 89ad637a..84d8ef50 100644 --- a/lib/libc/stat/fchmod.c +++ b/lib/libc/stat/fchmod.c @@ -1,6 +1,5 @@ - #include <sys/stat.h> // for fchmod #include <sys/types.h> // for mode_t #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/stat/fchmodat.c b/lib/libc/stat/fchmodat.c index 7bf834b1..ae5e882f 100644 --- a/lib/libc/stat/fchmodat.c +++ b/lib/libc/stat/fchmodat.c @@ -1,6 +1,5 @@ - #include <sys/stat.h> // for fchmodat #include <sys/types.h> // for mode_t #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/stat/fstatat.c b/lib/libc/stat/fstatat.c index 08519fe3..746848b7 100644 --- a/lib/libc/stat/fstatat.c +++ b/lib/libc/stat/fstatat.c @@ -3,7 +3,6 @@ #define __BITS_STAT_H_ - #include <bits/stat.h> // for stat #include <syscall.h> // for __syscall_5, syscall diff --git a/lib/libc/stat/mkdirat.c b/lib/libc/stat/mkdirat.c index dc075bb2..03b2c070 100644 --- a/lib/libc/stat/mkdirat.c +++ b/lib/libc/stat/mkdirat.c @@ -1,6 +1,5 @@ - #include <sys/stat.h> // for mkdirat #include <sys/types.h> // for mode_t #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/stat/mknod.c b/lib/libc/stat/mknod.c index e76e232b..4da1139e 100644 --- a/lib/libc/stat/mknod.c +++ b/lib/libc/stat/mknod.c @@ -1,6 +1,5 @@ - #include <fcntl.h> // for AT_FDCWD #include <sys/stat.h> // for mknod #include <sys/types.h> // for dev_t, mode_t diff --git a/lib/libc/stat/mknodat.c b/lib/libc/stat/mknodat.c index d19253e6..928b1208 100644 --- a/lib/libc/stat/mknodat.c +++ b/lib/libc/stat/mknodat.c @@ -1,6 +1,5 @@ - #include <sys/stat.h> // for mknodat #include <sys/types.h> // for dev_t, mode_t #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/stat/umask.c b/lib/libc/stat/umask.c index e33ec9f4..3eea89e8 100644 --- a/lib/libc/stat/umask.c +++ b/lib/libc/stat/umask.c @@ -1,6 +1,5 @@ - #include <sys/stat.h> // for umask #include <sys/types.h> // for mode_t #include <syscall.h> // for __syscall_1, syscall diff --git a/lib/libc/stat/utimensat.c b/lib/libc/stat/utimensat.c index 984c1921..aba18657 100644 --- a/lib/libc/stat/utimensat.c +++ b/lib/libc/stat/utimensat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_4, syscall #include <time.h> // for timespec diff --git a/lib/libc/statvfs/fstatvfs.c b/lib/libc/statvfs/fstatvfs.c index e228de83..bf630015 100644 --- a/lib/libc/statvfs/fstatvfs.c +++ b/lib/libc/statvfs/fstatvfs.c @@ -1,6 +1,5 @@ - #include <__statvfs.h> // for __statvfs #include <asm-generic/statfs.h> // for statfs #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/statvfs/statvfs.c b/lib/libc/statvfs/statvfs.c index 8316b169..c350b02d 100644 --- a/lib/libc/statvfs/statvfs.c +++ b/lib/libc/statvfs/statvfs.c @@ -1,6 +1,5 @@ - #include <__statvfs.h> // for __statvfs #include <asm-generic/statfs.h> // for statfs #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index ad314038..02e14a42 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -8,19 +8,21 @@ void perror(const char *s) { + char *errstr; struct iovec iov[4]; - char *errstr = strerror(errno); - if (s != NULL && *s != '\0') { iov[0].iov_base = (void *)s; iov[0].iov_len = strlen(s); + iov[1].iov_base = ": "; iov[1].iov_len = 2; } + errstr = strerror(errno); iov[s != NULL && *s != '\0' ? 2 : 0].iov_base = errstr; iov[s != NULL && *s != '\0' ? 2 : 0].iov_len = strlen(errstr); + iov[s != NULL && *s != '\0' ? 3 : 1].iov_base = "\n"; iov[s != NULL && *s != '\0' ? 3 : 1].iov_len = 1; diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c index 9afd47b4..8cb9c298 100644 --- a/lib/libc/stdio/remove.c +++ b/lib/libc/stdio/remove.c @@ -1,4 +1,4 @@ -#include "errno.h" // for EISDIR, errno +#include "errno.h" // for EISDIR, errno #include <fcntl.h> // for AT_FDCWD, AT_REMOVEDIR #include <stdio.h> // for remove diff --git a/lib/libc/stdio/rename.c b/lib/libc/stdio/rename.c index 52426ab0..17f09df5 100644 --- a/lib/libc/stdio/rename.c +++ b/lib/libc/stdio/rename.c @@ -1,6 +1,5 @@ - #include <stdio.h> // for rename #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/stdio/renameat.c b/lib/libc/stdio/renameat.c index c7e9a683..b82323ef 100644 --- a/lib/libc/stdio/renameat.c +++ b/lib/libc/stdio/renameat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_4, syscall int renameat(int oldfd, const char *old, int newfd, const char *new) diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 126c1193..06609046 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -1,13 +1,40 @@ -#include <ctype.h> // for isdigit -#include <errno.h> // for EINVAL, errno -#include <math.h> // for frexp, isinf, isnan -#include <stdarg.h> // for va_arg -#include <stddef.h> // for NULL, ptrdiff_t +#include <ctype.h> // for isdigit +#include <errno.h> // for EINVAL, errno +#include <math.h> // for isinf, isnan +#include <stdarg.h> // for va_arg +#include <stddef.h> // for NULL, ptrdiff_t +#include <stdint.h> #include <stdint.h> // for uintptr_t, intmax_t, uintmax_t #include <stdio.h> // for fwrite, fputc, vfprintf, FILE, va_list #include <string.h> // for memmove, strlcpy, strlen #include <sys/types.h> // for size_t, ssize_t +static double __frexp(double x, int *e) +{ + union { + double d; + uint64_t i; + } y = { x }; + uint64_t ee = y.i >> 52 & 0x7ff; + + if (!ee) { + if (x) { + x = __frexp(x * 0x1p64, e); + *e -= 64; + } else + *e = 0; + return x; + } + if (ee == 0x7ff) { + return x; + } + + *e = (int)ee - 0x3fe; + y.i &= 0x800fffffffffffffull; + y.i |= 0x3fe0000000000000ull; + return y.d; +} + extern char *dtoa(double, int mode, int ndigits, int *decpt, int *sign, char **rve); extern void freedtoa(char *s); @@ -615,7 +642,7 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } int exp; - double mant = frexp(val, &exp); + double mant = __frexp(val, &exp); mant *= 2.0; exp--; diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index 99001570..466329d1 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -1,6 +1,7 @@ + #include <__thread.h> // for __thread_self #include <atomic.h> // for LIBC_LOCK -#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous) +#include <libc.h> // for libc, libc::(anonymous) #include <signal.h> // for SIGABRT, sigaction, SIGKILL, SIG_DFL #include <stdlib.h> // for abort #include <syscall.h> // for __syscall, __syscall_2, __syscall_4 diff --git a/lib/libc/stdlib/free.c b/lib/libc/stdlib/free.c index e08b0170..ab656633 100644 --- a/lib/libc/stdlib/free.c +++ b/lib/libc/stdlib/free.c @@ -1,5 +1,5 @@ #include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK -#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous) +#include <libc.h> // for libc, libc::(anonymous) #include <malloc.h> // for page, page::(anonymous), __malloc_pvec, LARGE_... #include <stddef.h> // for NULL #include <stdint.h> // for uintptr_t diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index 17975574..41517e2f 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -1,5 +1,5 @@ #include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK -#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous), libc +#include <libc.h> // for libc, libc::(anonymous), weak_reference #include <stddef.h> // for NULL #include <stdlib.h> // for getenv, secure_getenv diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 344c9623..556fcbd1 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -2,7 +2,7 @@ #include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK #include <features.h> // for __weak -#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous) +#include <libc.h> // for libc, libc::(anonymous) #include <malloc.h> // for page, page::(anonymous), class, global_size_c... #include <stdatomic.h> // for atomic_flag_clear #include <stdint.h> // for uint32_t, uint8_t, uintptr_t diff --git a/lib/libc/stdlib/realloc.c b/lib/libc/stdlib/realloc.c index 4722ac5e..dca8cac2 100644 --- a/lib/libc/stdlib/realloc.c +++ b/lib/libc/stdlib/realloc.c @@ -2,7 +2,7 @@ #include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK #include <errno.h> // for EINVAL, errno -#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous), libc +#include <libc.h> // for libc, libc::(anonymous) #include <malloc.h> // for page, page::(anonymous), __malloc_pvec #include <stdint.h> // for uintptr_t #include <stdlib.h> // for free, malloc, realloc diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c index 004a29bd..3dfe3d22 100644 --- a/lib/libc/stdlib/setenv.c +++ b/lib/libc/stdlib/setenv.c @@ -1,7 +1,7 @@ #include "stddef.h" // for NULL #include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK -#include <libc.h> // for (anonymous), libc, (anonymous struct)::(anonymous) +#include <libc.h> // for libc, libc::(anonymous), libc::LIBC_ENVP_TOUCHED #include <stdlib.h> // for malloc, realloc, setenv #include <string.h> // for strlen, size_t, memcpy, strcpy, strchr, strncmp diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index c0a73146..2d3ea611 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -104,6 +104,12 @@ char *strerror(int errnum) [EKEYREJECTED] = "Key was rejected by service", }; + if (errnum < 0 || (size_t)errnum >= sizeof(table) / sizeof(table[0]) || + !table[errnum]) { + errno = EINVAL; + return NULL; + } + return table[errnum]; } diff --git a/lib/libc/sys/Kbuild b/lib/libc/sys/Kbuild index eedb3527..1bf1dcba 100644 --- a/lib/libc/sys/Kbuild +++ b/lib/libc/sys/Kbuild @@ -1,4 +1,6 @@ obj-y += ioctl.o obj-y += mount.o +obj-y += reboot.o +obj-y += sysinfo.o obj-y += umount.o obj-y += umount2.o diff --git a/lib/libc/sys/ioctl.c b/lib/libc/sys/ioctl.c index 0b9c3b82..9a164ffb 100644 --- a/lib/libc/sys/ioctl.c +++ b/lib/libc/sys/ioctl.c @@ -1,6 +1,5 @@ - #include <stdarg.h> // for va_arg, va_end, va_list, va_start #include <syscall.h> // for __syscall_3, syscall diff --git a/lib/libc/sys/mount.c b/lib/libc/sys/mount.c index 67f2d9af..75532cdf 100644 --- a/lib/libc/sys/mount.c +++ b/lib/libc/sys/mount.c @@ -1,3 +1,4 @@ + #include <sys/mount.h> // for mount #include <syscall.h> // for __syscall_5, syscall diff --git a/lib/libc/sys/reboot.c b/lib/libc/sys/reboot.c new file mode 100644 index 00000000..03b99cdb --- /dev/null +++ b/lib/libc/sys/reboot.c @@ -0,0 +1,8 @@ +#include <linux/reboot.h> +#include <sys/reboot.h> +#include <syscall.h> + +int reboot(int op) +{ + return syscall(reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, op); +} diff --git a/lib/libc/sys/umount.c b/lib/libc/sys/umount.c index ed2b2edc..10db7885 100644 --- a/lib/libc/sys/umount.c +++ b/lib/libc/sys/umount.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int umount(const char *target) diff --git a/lib/libc/sys/umount2.c b/lib/libc/sys/umount2.c index 17ff73aa..88543450 100644 --- a/lib/libc/sys/umount2.c +++ b/lib/libc/sys/umount2.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int umount2(const char *target, int flags) diff --git a/lib/libc/time/clock_getcpuclockid.c b/lib/libc/time/clock_getcpuclockid.c index a0f10b8a..18309dba 100644 --- a/lib/libc/time/clock_getcpuclockid.c +++ b/lib/libc/time/clock_getcpuclockid.c @@ -1,3 +1,4 @@ + #include <syscall.h> // for __syscall_2, syscall #include <time.h> // for clockid_t, clock_getcpuclockid, pid_t diff --git a/lib/libc/uio/readv.c b/lib/libc/uio/readv.c index 97e94f7d..dd96eed7 100644 --- a/lib/libc/uio/readv.c +++ b/lib/libc/uio/readv.c @@ -2,7 +2,7 @@ #include <errno.h> // for errno, EAGAIN, EINTR, EINVAL #include <string.h> // for memcpy -#include <sys/types.h> // for ssize_t, size_t +#include <sys/types.h> // for ssize_t #include <syscall.h> // for __syscall_3, syscall ssize_t readv(int fd, const struct iovec *iov, int iovcnt) diff --git a/lib/libc/uio/writev.c b/lib/libc/uio/writev.c index 63089f3b..a642111a 100644 --- a/lib/libc/uio/writev.c +++ b/lib/libc/uio/writev.c @@ -4,7 +4,6 @@ #include <sys/types.h> // for ssize_t, size_t #include <syscall.h> // for __syscall_3, syscall - #include <linux/uio.h> // for iovec, UIO_MAXIOV ssize_t writev(int fd, const struct iovec *iov, int iovcnt) diff --git a/lib/libc/unistd/_Fork.c b/lib/libc/unistd/_Fork.c index 9286adfd..a91f21bf 100644 --- a/lib/libc/unistd/_Fork.c +++ b/lib/libc/unistd/_Fork.c @@ -1,6 +1,5 @@ - #include <signal.h> // for SIGCHLD #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for _Fork, pid_t diff --git a/lib/libc/unistd/_exit.c b/lib/libc/unistd/_exit.c index 9d356ef2..9ca98613 100644 --- a/lib/libc/unistd/_exit.c +++ b/lib/libc/unistd/_exit.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall, __syscall_1 void _exit(int status) diff --git a/lib/libc/unistd/access.c b/lib/libc/unistd/access.c index 7ae7e4c1..9c5522b9 100644 --- a/lib/libc/unistd/access.c +++ b/lib/libc/unistd/access.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int access(const char *path, int amode) diff --git a/lib/libc/unistd/alarm.c b/lib/libc/unistd/alarm.c index 7dffd08a..ac77693d 100644 --- a/lib/libc/unistd/alarm.c +++ b/lib/libc/unistd/alarm.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall unsigned alarm(unsigned seconds) diff --git a/lib/libc/unistd/chdir.c b/lib/libc/unistd/chdir.c index 502b4c07..b60d1e70 100644 --- a/lib/libc/unistd/chdir.c +++ b/lib/libc/unistd/chdir.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int chdir(const char *path) diff --git a/lib/libc/unistd/chown.c b/lib/libc/unistd/chown.c index 02693a92..4471d53c 100644 --- a/lib/libc/unistd/chown.c +++ b/lib/libc/unistd/chown.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for chown, gid_t, uid_t diff --git a/lib/libc/unistd/close.c b/lib/libc/unistd/close.c index f2b079a6..6769a2ac 100644 --- a/lib/libc/unistd/close.c +++ b/lib/libc/unistd/close.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int close(int fildes) diff --git a/lib/libc/unistd/dup.c b/lib/libc/unistd/dup.c index 73fb1a6e..9ab81350 100644 --- a/lib/libc/unistd/dup.c +++ b/lib/libc/unistd/dup.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int dup(int fildes) diff --git a/lib/libc/unistd/dup2.c b/lib/libc/unistd/dup2.c index 414086ed..d2c47d09 100644 --- a/lib/libc/unistd/dup2.c +++ b/lib/libc/unistd/dup2.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int dup2(int fildes, int fildes2) diff --git a/lib/libc/unistd/dup3.c b/lib/libc/unistd/dup3.c index 65cf5749..261f18f3 100644 --- a/lib/libc/unistd/dup3.c +++ b/lib/libc/unistd/dup3.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall int dup3(int fildes, int fildes2, int flag) diff --git a/lib/libc/unistd/execv.c b/lib/libc/unistd/execv.c index a35a6aa4..af044a55 100644 --- a/lib/libc/unistd/execv.c +++ b/lib/libc/unistd/execv.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for execv diff --git a/lib/libc/unistd/execve.c b/lib/libc/unistd/execve.c index ec83fe92..7cfbe896 100644 --- a/lib/libc/unistd/execve.c +++ b/lib/libc/unistd/execve.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall int execve(const char *file, char *const argv[], char *const envp[]) diff --git a/lib/libc/unistd/faccessat.c b/lib/libc/unistd/faccessat.c index d5757785..f1d0a2b3 100644 --- a/lib/libc/unistd/faccessat.c +++ b/lib/libc/unistd/faccessat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_4, syscall int faccessat(int fd, const char *path, int amode, int flag) diff --git a/lib/libc/unistd/fchdir.c b/lib/libc/unistd/fchdir.c index fd392fb3..f0ffc555 100644 --- a/lib/libc/unistd/fchdir.c +++ b/lib/libc/unistd/fchdir.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int fchdir(int fildes) diff --git a/lib/libc/unistd/fchown.c b/lib/libc/unistd/fchown.c index 03f0ca76..6b110320 100644 --- a/lib/libc/unistd/fchown.c +++ b/lib/libc/unistd/fchown.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for fchown, gid_t, uid_t diff --git a/lib/libc/unistd/fchownat.c b/lib/libc/unistd/fchownat.c index f774d7d0..67d1246f 100644 --- a/lib/libc/unistd/fchownat.c +++ b/lib/libc/unistd/fchownat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_5, syscall #include <unistd.h> // for fchownat, gid_t, uid_t diff --git a/lib/libc/unistd/fdatasync.c b/lib/libc/unistd/fdatasync.c index 592cae02..d971ce7e 100644 --- a/lib/libc/unistd/fdatasync.c +++ b/lib/libc/unistd/fdatasync.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int fdatasync(int fildes) diff --git a/lib/libc/unistd/fsync.c b/lib/libc/unistd/fsync.c index e33afbd0..bece4f2a 100644 --- a/lib/libc/unistd/fsync.c +++ b/lib/libc/unistd/fsync.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int fsync(int fildes) diff --git a/lib/libc/unistd/ftruncate.c b/lib/libc/unistd/ftruncate.c index 3300a3a4..3273edee 100644 --- a/lib/libc/unistd/ftruncate.c +++ b/lib/libc/unistd/ftruncate.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for ftruncate, off_t diff --git a/lib/libc/unistd/getcwd.c b/lib/libc/unistd/getcwd.c index 61f6e872..c21a7c8b 100644 --- a/lib/libc/unistd/getcwd.c +++ b/lib/libc/unistd/getcwd.c @@ -1,3 +1,4 @@ + #include <stddef.h> #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for getcwd, size_t diff --git a/lib/libc/unistd/getegid.c b/lib/libc/unistd/getegid.c index e59cc2a4..061fe5c0 100644 --- a/lib/libc/unistd/getegid.c +++ b/lib/libc/unistd/getegid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for getegid, gid_t diff --git a/lib/libc/unistd/geteuid.c b/lib/libc/unistd/geteuid.c index 1044ac94..cd6e017a 100644 --- a/lib/libc/unistd/geteuid.c +++ b/lib/libc/unistd/geteuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for geteuid, gid_t diff --git a/lib/libc/unistd/getgid.c b/lib/libc/unistd/getgid.c index ffc5e9d2..3023bdc9 100644 --- a/lib/libc/unistd/getgid.c +++ b/lib/libc/unistd/getgid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for getgid, gid_t diff --git a/lib/libc/unistd/getgroups.c b/lib/libc/unistd/getgroups.c index 3eee06f4..2082bf75 100644 --- a/lib/libc/unistd/getgroups.c +++ b/lib/libc/unistd/getgroups.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for getgroups, gid_t diff --git a/lib/libc/unistd/getpgid.c b/lib/libc/unistd/getpgid.c index 11913277..cca8d274 100644 --- a/lib/libc/unistd/getpgid.c +++ b/lib/libc/unistd/getpgid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall #include <unistd.h> // for pid_t, getpgid diff --git a/lib/libc/unistd/getpid.c b/lib/libc/unistd/getpid.c index 72ac0c6b..966ecbbd 100644 --- a/lib/libc/unistd/getpid.c +++ b/lib/libc/unistd/getpid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for getpid, pid_t diff --git a/lib/libc/unistd/getppid.c b/lib/libc/unistd/getppid.c index 86c7209c..d365d532 100644 --- a/lib/libc/unistd/getppid.c +++ b/lib/libc/unistd/getppid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for getppid, pid_t diff --git a/lib/libc/unistd/getresgid.c b/lib/libc/unistd/getresgid.c index bfecfbb2..95d1ba17 100644 --- a/lib/libc/unistd/getresgid.c +++ b/lib/libc/unistd/getresgid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for gid_t, getresgid diff --git a/lib/libc/unistd/getresuid.c b/lib/libc/unistd/getresuid.c index 12dd7e20..4950b2e7 100644 --- a/lib/libc/unistd/getresuid.c +++ b/lib/libc/unistd/getresuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for uid_t, getresuid diff --git a/lib/libc/unistd/getsid.c b/lib/libc/unistd/getsid.c index c3bbbfd5..bc473180 100644 --- a/lib/libc/unistd/getsid.c +++ b/lib/libc/unistd/getsid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall #include <unistd.h> // for pid_t, getsid diff --git a/lib/libc/unistd/getuid.c b/lib/libc/unistd/getuid.c index 1013a8cc..ed552743 100644 --- a/lib/libc/unistd/getuid.c +++ b/lib/libc/unistd/getuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for getuid, uid_t diff --git a/lib/libc/unistd/isatty.c b/lib/libc/unistd/isatty.c index 46a952e4..589a8f65 100644 --- a/lib/libc/unistd/isatty.c +++ b/lib/libc/unistd/isatty.c @@ -1,3 +1,4 @@ + #include <asm-generic/ioctls.h> // for TIOCGWINSZ #include <syscall.h> // for __syscall_3, syscall #include <termios.h> // for winsize diff --git a/lib/libc/unistd/lchown.c b/lib/libc/unistd/lchown.c index 0812f26f..fcc9a726 100644 --- a/lib/libc/unistd/lchown.c +++ b/lib/libc/unistd/lchown.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for gid_t, lchown, uid_t diff --git a/lib/libc/unistd/link.c b/lib/libc/unistd/link.c index a0a070ff..96a6de18 100644 --- a/lib/libc/unistd/link.c +++ b/lib/libc/unistd/link.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for link diff --git a/lib/libc/unistd/linkat.c b/lib/libc/unistd/linkat.c index f96987b3..6751bec6 100644 --- a/lib/libc/unistd/linkat.c +++ b/lib/libc/unistd/linkat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_5, syscall #include <unistd.h> // for linkat diff --git a/lib/libc/unistd/lseek.c b/lib/libc/unistd/lseek.c index 39fab991..f2e81b8c 100644 --- a/lib/libc/unistd/lseek.c +++ b/lib/libc/unistd/lseek.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for off_t, lseek diff --git a/lib/libc/unistd/pause.c b/lib/libc/unistd/pause.c index cda0feaf..031829e3 100644 --- a/lib/libc/unistd/pause.c +++ b/lib/libc/unistd/pause.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall int pause(void) diff --git a/lib/libc/unistd/pipe.c b/lib/libc/unistd/pipe.c index a0d55b86..06966093 100644 --- a/lib/libc/unistd/pipe.c +++ b/lib/libc/unistd/pipe.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int pipe(int fildes[2]) diff --git a/lib/libc/unistd/pipe2.c b/lib/libc/unistd/pipe2.c index eb91ff29..7252a244 100644 --- a/lib/libc/unistd/pipe2.c +++ b/lib/libc/unistd/pipe2.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int pipe2(int fildes[2], int flag) diff --git a/lib/libc/unistd/posix_close.c b/lib/libc/unistd/posix_close.c index d77d4114..189f7db9 100644 --- a/lib/libc/unistd/posix_close.c +++ b/lib/libc/unistd/posix_close.c @@ -1,6 +1,5 @@ - #include <libc.h> // for __unused #include <syscall.h> // for __syscall_1, syscall diff --git a/lib/libc/unistd/read.c b/lib/libc/unistd/read.c index 0a524f51..80b3f0d2 100644 --- a/lib/libc/unistd/read.c +++ b/lib/libc/unistd/read.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for read, size_t, ssize_t diff --git a/lib/libc/unistd/readlink.c b/lib/libc/unistd/readlink.c index 05001f06..880d93fd 100644 --- a/lib/libc/unistd/readlink.c +++ b/lib/libc/unistd/readlink.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for readlink, size_t, ssize_t diff --git a/lib/libc/unistd/readlinkat.c b/lib/libc/unistd/readlinkat.c index 59e99d2d..b4fbcb39 100644 --- a/lib/libc/unistd/readlinkat.c +++ b/lib/libc/unistd/readlinkat.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <syscall.h> // for __syscall_4, syscall #include <unistd.h> // for readlinkat, size_t, ssize_t diff --git a/lib/libc/unistd/rmdir.c b/lib/libc/unistd/rmdir.c index 26afb14b..f319ab98 100644 --- a/lib/libc/unistd/rmdir.c +++ b/lib/libc/unistd/rmdir.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int rmdir(const char *path) diff --git a/lib/libc/unistd/setegid.c b/lib/libc/unistd/setegid.c index c5159de7..676a7990 100644 --- a/lib/libc/unistd/setegid.c +++ b/lib/libc/unistd/setegid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for gid_t, setegid diff --git a/lib/libc/unistd/seteuid.c b/lib/libc/unistd/seteuid.c index 41aea3ad..d0b76f35 100644 --- a/lib/libc/unistd/seteuid.c +++ b/lib/libc/unistd/seteuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for seteuid, uid_t diff --git a/lib/libc/unistd/setgid.c b/lib/libc/unistd/setgid.c index 0d465480..ba2fcfce 100644 --- a/lib/libc/unistd/setgid.c +++ b/lib/libc/unistd/setgid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall #include <unistd.h> // for gid_t, setgid diff --git a/lib/libc/unistd/setpgid.c b/lib/libc/unistd/setpgid.c index aa7bc2b2..4b1df056 100644 --- a/lib/libc/unistd/setpgid.c +++ b/lib/libc/unistd/setpgid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for pid_t, setpgid diff --git a/lib/libc/unistd/setregid.c b/lib/libc/unistd/setregid.c index c66d9c85..7185a454 100644 --- a/lib/libc/unistd/setregid.c +++ b/lib/libc/unistd/setregid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for gid_t, setregid diff --git a/lib/libc/unistd/setresgid.c b/lib/libc/unistd/setresgid.c index fb0451bb..eca009b0 100644 --- a/lib/libc/unistd/setresgid.c +++ b/lib/libc/unistd/setresgid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for gid_t, setresgid diff --git a/lib/libc/unistd/setresuid.c b/lib/libc/unistd/setresuid.c index 4460022d..447418c9 100644 --- a/lib/libc/unistd/setresuid.c +++ b/lib/libc/unistd/setresuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for uid_t, setresuid diff --git a/lib/libc/unistd/setreuid.c b/lib/libc/unistd/setreuid.c index 122e1b1f..587645b4 100644 --- a/lib/libc/unistd/setreuid.c +++ b/lib/libc/unistd/setreuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for uid_t, setreuid diff --git a/lib/libc/unistd/setsid.c b/lib/libc/unistd/setsid.c index cffe8bf3..fa44d8ae 100644 --- a/lib/libc/unistd/setsid.c +++ b/lib/libc/unistd/setsid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall #include <unistd.h> // for pid_t, setsid diff --git a/lib/libc/unistd/setuid.c b/lib/libc/unistd/setuid.c index 050cb62a..cb6ab14a 100644 --- a/lib/libc/unistd/setuid.c +++ b/lib/libc/unistd/setuid.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall #include <unistd.h> // for setuid, uid_t diff --git a/lib/libc/unistd/symlink.c b/lib/libc/unistd/symlink.c index 28b1722f..d847b6f1 100644 --- a/lib/libc/unistd/symlink.c +++ b/lib/libc/unistd/symlink.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall int symlink(const char *path1, const char *path2) diff --git a/lib/libc/unistd/symlinkat.c b/lib/libc/unistd/symlinkat.c index 8a64387b..7a7e05a8 100644 --- a/lib/libc/unistd/symlinkat.c +++ b/lib/libc/unistd/symlinkat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall int symlinkat(const char *path1, int fd, const char *path2) diff --git a/lib/libc/unistd/sync.c b/lib/libc/unistd/sync.c index e0b3aec6..efecd378 100644 --- a/lib/libc/unistd/sync.c +++ b/lib/libc/unistd/sync.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_0, syscall void sync(void) diff --git a/lib/libc/unistd/truncate.c b/lib/libc/unistd/truncate.c index e318fd4c..972f3717 100644 --- a/lib/libc/unistd/truncate.c +++ b/lib/libc/unistd/truncate.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_2, syscall #include <unistd.h> // for off_t, truncate diff --git a/lib/libc/unistd/unlink.c b/lib/libc/unistd/unlink.c index 639f89d2..0ca8298e 100644 --- a/lib/libc/unistd/unlink.c +++ b/lib/libc/unistd/unlink.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_1, syscall int unlink(const char *path) diff --git a/lib/libc/unistd/unlinkat.c b/lib/libc/unistd/unlinkat.c index ef01e323..fdfddf8a 100644 --- a/lib/libc/unistd/unlinkat.c +++ b/lib/libc/unistd/unlinkat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_3, syscall int unlinkat(int fd, const char *path, int flag) diff --git a/lib/libc/unistd/write.c b/lib/libc/unistd/write.c index ad037ad6..85dfaff2 100644 --- a/lib/libc/unistd/write.c +++ b/lib/libc/unistd/write.c @@ -1,6 +1,5 @@ - #include <stddef.h> #include <syscall.h> // for __syscall_3, syscall #include <unistd.h> // for size_t, ssize_t, write diff --git a/lib/libc/utsname/uname.c b/lib/libc/utsname/uname.c index e88142ab..a65193dd 100644 --- a/lib/libc/utsname/uname.c +++ b/lib/libc/utsname/uname.c @@ -1,6 +1,5 @@ - #include <sys/utsname.h> // for uname #include <syscall.h> // for __syscall_1, syscall diff --git a/lib/libc/wait/wait.c b/lib/libc/wait/wait.c index 52765008..8f703600 100644 --- a/lib/libc/wait/wait.c +++ b/lib/libc/wait/wait.c @@ -1,4 +1,4 @@ -#include "sys/types.h" // for pid_t +#include "signal.h" // for pid_t #include <sys/wait.h> // for wait #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libc/wait/waitid.c b/lib/libc/wait/waitid.c index f0f6bf0a..2e9c431a 100644 --- a/lib/libc/wait/waitid.c +++ b/lib/libc/wait/waitid.c @@ -1,6 +1,5 @@ - #include <signal.h> // for siginfo_t #include <sys/types.h> // for id_t #include <sys/wait.h> // for idtype_t, waitid diff --git a/lib/libc/wait/waitpid.c b/lib/libc/wait/waitpid.c index 3512104b..de1d0bb2 100644 --- a/lib/libc/wait/waitpid.c +++ b/lib/libc/wait/waitpid.c @@ -1,4 +1,4 @@ -#include "sys/types.h" // for pid_t +#include "signal.h" // for pid_t #include <sys/wait.h> // for waitpid #include <syscall.h> // for __syscall_4, syscall diff --git a/lib/libm/fmaf.c b/lib/libm/fmaf.c index b940283d..fb7508a3 100644 --- a/lib/libm/fmaf.c +++ b/lib/libm/fmaf.c @@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#include "bits/fenv.h" // for FE_INEXACT, FE_UNDERFLOW, FE_TONEAREST #include <fenv.h> // for feraiseexcept, fetestexcept, feclearexcept #include <math.h> // for fmaf diff --git a/lib/libm/fmal.c b/lib/libm/fmal.c index 8dd0ac61..11097f0e 100644 --- a/lib/libm/fmal.c +++ b/lib/libm/fmal.c @@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#include "bits/fenv.h" // for FE_INEXACT, FE_UNDERFLOW, FE_DOWNWARD, FE_TON... #include "libm.h" // for ldshape, ldshape::(anonymous) #include <float.h> // for LDBL_MANT_DIG, LDBL_MAX_EXP, LDBL_MIN diff --git a/lib/libm/llrintl.c b/lib/libm/llrintl.c index 99e38781..a075dcc7 100644 --- a/lib/libm/llrintl.c +++ b/lib/libm/llrintl.c @@ -1,5 +1,7 @@ +#include "bits/fenv.h" // for FE_INEXACT + #include <fenv.h> // for feclearexcept, fetestexcept #include <float.h> // for LDBL_MANT_DIG, LDBL_MAX_EXP #include <limits.h> // for LLONG_MAX, LLONG_MIN diff --git a/lib/libm/lrintl.c b/lib/libm/lrintl.c index fc82d8a8..22d99823 100644 --- a/lib/libm/lrintl.c +++ b/lib/libm/lrintl.c @@ -1,5 +1,7 @@ +#include "bits/fenv.h" // for FE_INEXACT + #include <fenv.h> // for feclearexcept, fetestexcept #include <float.h> // for LDBL_MANT_DIG, LDBL_MAX_EXP #include <limits.h> // for LONG_MAX, LONG_MIN diff --git a/lib/libm/nearbyint.c b/lib/libm/nearbyint.c index d075eac6..3e3317a9 100644 --- a/lib/libm/nearbyint.c +++ b/lib/libm/nearbyint.c @@ -1,5 +1,7 @@ +#include "bits/fenv.h" // for FE_INEXACT + #include <fenv.h> // for feclearexcept, fetestexcept #include <math.h> // for nearbyint, rint diff --git a/lib/libm/nearbyintf.c b/lib/libm/nearbyintf.c index a180ae22..224af0f6 100644 --- a/lib/libm/nearbyintf.c +++ b/lib/libm/nearbyintf.c @@ -1,5 +1,7 @@ +#include "bits/fenv.h" // for FE_INEXACT + #include <fenv.h> // for feclearexcept, fetestexcept #include <math.h> // for nearbyintf, rintf diff --git a/lib/libm/nearbyintl.c b/lib/libm/nearbyintl.c index fc19d84b..df48af53 100644 --- a/lib/libm/nearbyintl.c +++ b/lib/libm/nearbyintl.c @@ -1,5 +1,7 @@ +#include "bits/fenv.h" // for FE_INEXACT + #include <float.h> // for LDBL_MANT_DIG, LDBL_MAX_EXP #include <math.h> // for nearbyintl, rintl diff --git a/lib/libm/tanf.c b/lib/libm/tanf.c index ef808637..f005908f 100644 --- a/lib/libm/tanf.c +++ b/lib/libm/tanf.c @@ -16,7 +16,7 @@ #include "libm.h" // for __tandf, __rem_pio2f, FORCE_EVAL, GET_FLOAT_WORD -#include <math.h> // for M_PI_2, tanf +#include <math.h> // for M_PI_2, tanf, NAN #include <stdint.h> // for uint32_t /* Small multiples of pi/2 rounded to double precision. */ diff --git a/lib/libm/tanl.c b/lib/libm/tanl.c index 22657cce..7fb0e269 100644 --- a/lib/libm/tanl.c +++ b/lib/libm/tanl.c @@ -1,7 +1,7 @@ #include "libm.h" // for ldshape, ldshape::(anonymous), __tanl, __rem_pio2l #include <float.h> // for LDBL_MANT_DIG, LDBL_MAX_EXP -#include <math.h> // for tanl, M_PI_4 +#include <math.h> // for tanl, M_PI_4, NAN #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 long double tanl(long double x) @@ -55,6 +55,10 @@ ifdef M obj = $(M)/ endif +KCONFIG_CONFIG ?= .config + +-include ${KCONFIG_CONFIG} + # CFLAGS KBUILD_CFLAGS := -x c @@ -62,6 +66,7 @@ KBUILD_CFLAGS := -x c KBUILD_CFLAGS += -Wall -Wextra KBUILD_CFLAGS += -nostdinc KBUILD_CFLAGS += -target $(ARCH)-linux-eabi +KBUILD_CFLAGS += -ffreestanding KBUILD_CFLAGS += -I$(srctree)/include KBUILD_CFLAGS += -I$(srctree)/include/arch/$(ARCH) @@ -86,28 +91,32 @@ ifeq ($(CONFIG_WERROR),y) KBUILD_CFLAGS += -Werror endif +KBUILD_LDFLAGS := +KBUILD_ASFLAGS := ifeq ($(CONFIG_DEBUG),y) KBUILD_CFLAGS += -g -Og -fno-omit-frame-pointer -endif +else +KBUILD_CFLAGS += -O2 -fdata-sections -ffunction-sections +KBUILD_CFLAGS += -fno-unwind-tables -fomit-frame-pointer -KBUILD_ASFLAGS := +KBUILD_LDFLAGS += --gc-sections +KBUILD_LDFLAGS += --build-id=none +KBUILD_LDFLAGS += --as-needed +KBUILD_LDFLAGS += --strip-all +KBUILD_LDFLAGS += -z relro -z now -z noexecstack +KBUILD_LDFLAGS += --no-undefined +KBUILD_LDFLAGS += --icf=all + +KBUILD_ASFLAGS += +endif # Assembly does not need -nostdinc; clang warns it is unused. KBUILD_ASFLAGS += -target $(ARCH)-linux-eabi KBUILD_ASFLAGS += -I$(srctree)/include KBUILD_ASFLAGS += -I$(srctree)/include/arch/$(ARCH) -# LDFLAGS -KBUILD_LDFLAGS := - -KBUILD_LDFLAGS += --gc-sections -KBUILD_LDFLAGS += --build-id=none -KBUILD_LDFLAGS += --as-needed - PHONY := -KCONFIG_CONFIG ?= .config - export Q srctree MAKEFLAGS KCONFIG_CONFIG \ KBUILD_CFLAGS KBUILD_ASFLAGS KBUILD_LDFLAGS @@ -123,6 +132,13 @@ distclean: clean $(Q)$(MAKE) -C scripts/kconfig clean $(Q)rm -f compile_commands.json +info: + echo "CC: $(CC)" + echo "ARCH: $(ARCH)" + echo "CFLAGS: $(KBUILD_CFLAGS)" + echo "LDFLAGS: $(KBUILD_LDFLAGS)" + echo "ASFLAGS: $(KBUILD_ASFLAGS)" + $(KCONFIG_CONFIG): @echo >&2 '***' @echo >&2 '*** Configuration file "$@" not found!' |
