diff options
Diffstat (limited to 'libc/include/llvm-libc-macros')
71 files changed, 4689 insertions, 0 deletions
diff --git a/libc/include/llvm-libc-macros/EFIAPI-macros.h b/libc/include/llvm-libc-macros/EFIAPI-macros.h new file mode 100644 index 000000000000..cb854928d0ab --- /dev/null +++ b/libc/include/llvm-libc-macros/EFIAPI-macros.h @@ -0,0 +1,18 @@ +//===-- Definition of EFIAPI macro ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_EFIAPI_MACROS_H +#define LLVM_LIBC_MACROS_EFIAPI_MACROS_H + +#if defined(__x86_64__) && !defined(__ILP32__) +#define EFIAPI __attribute__((ms_abi)) +#else +#define EFIAPI +#endif + +#endif // LLVM_LIBC_MACROS_EFIAPI_MACROS_H diff --git a/libc/include/llvm-libc-macros/assert-macros.h b/libc/include/llvm-libc-macros/assert-macros.h new file mode 100644 index 000000000000..44e14543d856 --- /dev/null +++ b/libc/include/llvm-libc-macros/assert-macros.h @@ -0,0 +1,14 @@ +//===-- Definition of macros to be used with assert functions -------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __LLVM_LIBC_MACROS_ASSERT_MACROS_H +#define __LLVM_LIBC_MACROS_ASSERT_MACROS_H + +#define __STDC_VERSION_ASSERT_H__ 202311L + +#endif // __LLVM_LIBC_MACROS_ASSERT_MACROS_H diff --git a/libc/include/llvm-libc-macros/baremetal/time-macros.h b/libc/include/llvm-libc-macros/baremetal/time-macros.h new file mode 100644 index 000000000000..3537376c4bca --- /dev/null +++ b/libc/include/llvm-libc-macros/baremetal/time-macros.h @@ -0,0 +1,26 @@ +//===-- Definition of macros from time.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H +#define LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H + +#ifdef __CLK_TCK +#define CLOCKS_PER_SEC __CLK_TCK +#else +#if defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || \ + defined(__arm64__) || defined(_M_ARM64) +// This default implementation of this function shall use semihosting +// Semihosting measures time in centiseconds +// https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst#sys-clock-0x10 +#define CLOCKS_PER_SEC 100 +#else +#define CLOCKS_PER_SEC 1000000 +#endif +#endif + +#endif // LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/complex-macros.h b/libc/include/llvm-libc-macros/complex-macros.h new file mode 100644 index 000000000000..427c68d289e0 --- /dev/null +++ b/libc/include/llvm-libc-macros/complex-macros.h @@ -0,0 +1,24 @@ +//===-- Definition of macros to be used with complex functions ------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __LLVM_LIBC_MACROS_COMPLEX_MACROS_H +#define __LLVM_LIBC_MACROS_COMPLEX_MACROS_H + +#ifndef __STDC_NO_COMPLEX__ + +#define __STDC_VERSION_COMPLEX_H__ 202311L + +#define complex _Complex +#define _Complex_I ((_Complex float)1.0fi) +#define I _Complex_I + +// TODO: Add imaginary macros once GCC or Clang support _Imaginary builtin-type. + +#endif + +#endif // __LLVM_LIBC_MACROS_COMPLEX_MACROS_H diff --git a/libc/include/llvm-libc-macros/containerof-macro.h b/libc/include/llvm-libc-macros/containerof-macro.h new file mode 100644 index 000000000000..debf441bf845 --- /dev/null +++ b/libc/include/llvm-libc-macros/containerof-macro.h @@ -0,0 +1,20 @@ +//===-- Definition of the containerof macro -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H +#define LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H + +#include "offsetof-macro.h" + +#define __containerof(ptr, type, member) \ + ({ \ + const __typeof(((type *)0)->member) *__ptr = (ptr); \ + (type *)(void *)((const char *)__ptr - offsetof(type, member)); \ + }) + +#endif // LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H diff --git a/libc/include/llvm-libc-macros/dlfcn-macros.h b/libc/include/llvm-libc-macros/dlfcn-macros.h new file mode 100644 index 000000000000..dcd202b9ab43 --- /dev/null +++ b/libc/include/llvm-libc-macros/dlfcn-macros.h @@ -0,0 +1,23 @@ +//===-- Definition of macros from dlfcn.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_DLFCN_MACROS_H +#define LLVM_LIBC_MACROS_DLFCN_MACROS_H + +#define RTLD_LAZY 0x00001 +#define RTLD_NOW 0x00002 +#define RTLD_GLOBAL 0x00100 +#define RTLD_LOCAL 0 + +// Non-standard stuff here +#define RTLD_BINDING_MASK 0x3 +#define RTLD_NOLOAD 0x00004 +#define RTLD_DEEPBIND 0x00008 +#define RTLD_NODELETE 0x01000 + +#endif // LLVM_LIBC_MACROS_DLFCN_MACROS_H diff --git a/libc/include/llvm-libc-macros/elf-macros.h b/libc/include/llvm-libc-macros/elf-macros.h new file mode 100644 index 000000000000..fa4442abf0f5 --- /dev/null +++ b/libc/include/llvm-libc-macros/elf-macros.h @@ -0,0 +1,18 @@ +//===-- Definition of macros from elf.h -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_ELF_MACROS_H +#define LLVM_LIBC_MACROS_ELF_MACROS_H + +#if __has_include(<linux/elf.h>) +#include <linux/elf.h> +#else +#error "cannot use <sys/elf.h> without proper system headers." +#endif + +#endif // LLVM_LIBC_MACROS_ELF_MACROS_H diff --git a/libc/include/llvm-libc-macros/endian-macros.h b/libc/include/llvm-libc-macros/endian-macros.h new file mode 100644 index 000000000000..52d95dc01cd8 --- /dev/null +++ b/libc/include/llvm-libc-macros/endian-macros.h @@ -0,0 +1,50 @@ +//===-- Definition of macros from endian.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_ENDIAN_MACROS_H +#define LLVM_LIBC_MACROS_ENDIAN_MACROS_H + +#include "stdint-macros.h" + +#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#define BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#define BYTE_ORDER __BYTE_ORDER__ + +#if BYTE_ORDER == LITTLE_ENDIAN + +#define htobe16(x) __builtin_bswap16((x)) +#define htobe32(x) __builtin_bswap32((x)) +#define htobe64(x) __builtin_bswap64((x)) +#define htole16(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x) +#define htole32(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x) +#define htole64(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x) +#define be16toh(x) __builtin_bswap16((x)) +#define be32toh(x) __builtin_bswap32((x)) +#define be64toh(x) __builtin_bswap64((x)) +#define le16toh(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x) +#define le32toh(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x) +#define le64toh(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x) + +#else + +#define htobe16(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x) +#define htobe32(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x) +#define htobe64(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x) +#define htole16(x) __builtin_bswap16((x)) +#define htole32(x) __builtin_bswap32((x)) +#define htole64(x) __builtin_bswap64((x)) +#define be16toh(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x) +#define be32toh(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x) +#define be64toh(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x) +#define le16toh(x) __builtin_bswap16((x)) +#define le32toh(x) __builtin_bswap32((x)) +#define le64toh(x) __builtin_bswap64((x)) + +#endif + +#endif // LLVM_LIBC_MACROS_ENDIAN_MACROS_H diff --git a/libc/include/llvm-libc-macros/error-number-macros.h b/libc/include/llvm-libc-macros/error-number-macros.h new file mode 100644 index 000000000000..29bd54d07f2e --- /dev/null +++ b/libc/include/llvm-libc-macros/error-number-macros.h @@ -0,0 +1,8 @@ +#ifndef LLVM_LIBC_MACROS_ERROR_NUMBER_MACROS_H +#define LLVM_LIBC_MACROS_ERROR_NUMBER_MACROS_H + +#ifdef __linux__ +#include "linux/error-number-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_ERROR_NUMBER_MACROS_H diff --git a/libc/include/llvm-libc-macros/fcntl-macros.h b/libc/include/llvm-libc-macros/fcntl-macros.h new file mode 100644 index 000000000000..4bd03a7e3e2b --- /dev/null +++ b/libc/include/llvm-libc-macros/fcntl-macros.h @@ -0,0 +1,8 @@ +#ifndef LLVM_LIBC_MACROS_FCNTL_MACROS_H +#define LLVM_LIBC_MACROS_FCNTL_MACROS_H + +#ifdef __linux__ +#include "linux/fcntl-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_FCNTL_MACROS_H diff --git a/libc/include/llvm-libc-macros/features-macros.h b/libc/include/llvm-libc-macros/features-macros.h new file mode 100644 index 000000000000..f87ae4ad1240 --- /dev/null +++ b/libc/include/llvm-libc-macros/features-macros.h @@ -0,0 +1,12 @@ +//===-- Definition of macros from features.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_FEATURES_MACROS_H +#define LLVM_LIBC_MACROS_FEATURES_MACROS_H + +#endif // LLVM_LIBC_MACROS_FEATURES_MACROS_H diff --git a/libc/include/llvm-libc-macros/fenv-macros.h b/libc/include/llvm-libc-macros/fenv-macros.h new file mode 100644 index 000000000000..1826723f9349 --- /dev/null +++ b/libc/include/llvm-libc-macros/fenv-macros.h @@ -0,0 +1,28 @@ +//===-- Definition of macros from fenv.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_FENV_MACROS_H +#define LLVM_LIBC_MACROS_FENV_MACROS_H + +#define FE_DIVBYZERO 0x1 +#define FE_INEXACT 0x2 +#define FE_INVALID 0x4 +#define FE_OVERFLOW 0x8 +#define FE_UNDERFLOW 0x10 +#define __FE_DENORM 0x20 +#define FE_ALL_EXCEPT \ + (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +#define FE_DOWNWARD 0x400 +#define FE_TONEAREST 0 +#define FE_TOWARDZERO 0xC00 +#define FE_UPWARD 0x800 + +#define FE_DFL_ENV ((fenv_t *)-1) + +#endif // LLVM_LIBC_MACROS_FENV_MACROS_H diff --git a/libc/include/llvm-libc-macros/file-seek-macros.h b/libc/include/llvm-libc-macros/file-seek-macros.h new file mode 100644 index 000000000000..676cb7511407 --- /dev/null +++ b/libc/include/llvm-libc-macros/file-seek-macros.h @@ -0,0 +1,16 @@ +//===-- Definition of macros to be used with file seek functions ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_FILE_SEEK_MACROS_H +#define LLVM_LIBC_MACROS_FILE_SEEK_MACROS_H + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +#endif // LLVM_LIBC_MACROS_FILE_SEEK_MACROS_H diff --git a/libc/include/llvm-libc-macros/float-macros.h b/libc/include/llvm-libc-macros/float-macros.h new file mode 100644 index 000000000000..a25ef60a293d --- /dev/null +++ b/libc/include/llvm-libc-macros/float-macros.h @@ -0,0 +1,178 @@ +//===-- Definition of macros from float.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_FLOAT_MACROS_H +#define LLVM_LIBC_MACROS_FLOAT_MACROS_H + +#ifndef FLT_RADIX +#define FLT_RADIX __FLT_RADIX__ +#endif // FLT_RADIX + +#ifndef FLT_EVAL_METHOD +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +#endif // FLT_EVAL_METHOD + +#ifndef FLT_ROUNDS +#if __has_builtin(__builtin_flt_rounds) +#define FLT_ROUNDS __builtin_flt_rounds() +#else +#define FLT_ROUNDS 1 +#endif +#endif // FLT_ROUNDS + +#ifndef FLT_DECIMAL_DIG +#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__ +#endif // FLT_DECIMAL_DIG + +#ifndef DBL_DECIMAL_DIG +#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__ +#endif // DBL_DECIMAL_DIG + +#ifndef LDBL_DECIMAL_DIG +#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ +#endif // LDBL_DECIMAL_DIG + +#ifndef DECIMAL_DIG +#define DECIMAL_DIG __DECIMAL_DIG__ +#endif // DECIMAL_DIG + +#ifndef FLT_DIG +#define FLT_DIG __FLT_DIG__ +#endif // FLT_DIG + +#ifndef DBL_DIG +#define DBL_DIG __DBL_DIG__ +#endif // DBL_DIG + +#ifndef LDBL_DIG +#define LDBL_DIG __LDBL_DIG__ +#endif // LDBL_DIG + +#ifndef FLT_MANT_DIG +#define FLT_MANT_DIG __FLT_MANT_DIG__ +#endif // FLT_MANT_DIG + +#ifndef DBL_MANT_DIG +#define DBL_MANT_DIG __DBL_MANT_DIG__ +#endif // DBL_MANT_DIG + +#ifndef LDBL_MANT_DIG +#define LDBL_MANT_DIG __LDBL_MANT_DIG__ +#endif // LDBL_MANT_DIG + +#ifndef FLT_MIN +#define FLT_MIN __FLT_MIN__ +#endif // FLT_MIN + +#ifndef DBL_MIN +#define DBL_MIN __DBL_MIN__ +#endif // DBL_MIN + +#ifndef LDBL_MIN +#define LDBL_MIN __LDBL_MIN__ +#endif // LDBL_MIN + +#ifndef FLT_MAX +#define FLT_MAX __FLT_MAX__ +#endif // FLT_MAX + +#ifndef DBL_MAX +#define DBL_MAX __DBL_MAX__ +#endif // DBL_MAX + +#ifndef LDBL_MAX +#define LDBL_MAX __LDBL_MAX__ +#endif // LDBL_MAX + +#ifndef FLT_TRUE_MIN +#define FLT_TRUE_MIN __FLT_DENORM_MIN__ +#endif // FLT_TRUE_MIN + +#ifndef DBL_TRUE_MIN +#define DBL_TRUE_MIN __DBL_DENORM_MIN__ +#endif // DBL_TRUE_MIN + +#ifndef LDBL_TRUE_MIN +#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__ +#endif // LDBL_TRUE_MIN + +#ifndef FLT_EPSILON +#define FLT_EPSILON __FLT_EPSILON__ +#endif // FLT_EPSILON + +#ifndef DBL_EPSILON +#define DBL_EPSILON __DBL_EPSILON__ +#endif // DBL_EPSILON + +#ifndef LDBL_EPSILON +#define LDBL_EPSILON __LDBL_EPSILON__ +#endif // LDBL_EPSILON + +#ifndef FLT_MIN_EXP +#define FLT_MIN_EXP __FLT_MIN_EXP__ +#endif // FLT_MIN_EXP + +#ifndef DBL_MIN_EXP +#define DBL_MIN_EXP __DBL_MIN_EXP__ +#endif // DBL_MIN_EXP + +#ifndef LDBL_MIN_EXP +#define LDBL_MIN_EXP __LDBL_MIN_EXP__ +#endif // LDBL_MIN_EXP + +#ifndef FLT_MIN_10_EXP +#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ +#endif // FLT_MIN_10_EXP + +#ifndef DBL_MIN_10_EXP +#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ +#endif // DBL_MIN_10_EXP + +#ifndef LDBL_MIN_10_EXP +#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ +#endif // LDBL_MIN_10_EXP + +#ifndef FLT_MAX_EXP +#define FLT_MAX_EXP __FLT_MAX_EXP__ +#endif // FLT_MAX_EXP + +#ifndef DBL_MAX_EXP +#define DBL_MAX_EXP __DBL_MAX_EXP__ +#endif // DBL_MAX_EXP + +#ifndef LDBL_MAX_EXP +#define LDBL_MAX_EXP __LDBL_MAX_EXP__ +#endif // LDBL_MAX_EXP + +#ifndef FLT_MAX_10_EXP +#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ +#endif // FLT_MAX_10_EXP + +#ifndef DBL_MAX_10_EXP +#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ +#endif // DBL_MAX_10_EXP + +#ifndef LDBL_MAX_10_EXP +#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ +#endif // LDBL_MAX_10_EXP + +#ifndef FLT_HAS_SUBNORM +#define FLT_HAS_SUBNORM __FLT_HAS_DENORM__ +#endif // FLT_HAS_SUBNORM + +#ifndef DBL_HAS_SUBNORM +#define DBL_HAS_SUBNORM __DBL_HAS_DENORM__ +#endif // DBL_HAS_SUBNORM + +#ifndef LDBL_HAS_SUBNORM +#define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__ +#endif // LDBL_HAS_SUBNORM + +// TODO: Add FLT16 and FLT128 constants. + +#endif // LLVM_LIBC_MACROS_FLOAT_MACROS_H diff --git a/libc/include/llvm-libc-macros/float16-macros.h b/libc/include/llvm-libc-macros/float16-macros.h new file mode 100644 index 000000000000..229e3e62f2ae --- /dev/null +++ b/libc/include/llvm-libc-macros/float16-macros.h @@ -0,0 +1,27 @@ +//===-- Detection of _Float16 compiler builtin type -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_FLOAT16_MACROS_H +#define LLVM_LIBC_MACROS_FLOAT16_MACROS_H + +#include "../llvm-libc-types/float128.h" + +#if defined(__FLT16_MANT_DIG__) && \ + (!defined(__GNUC__) || __GNUC__ >= 13 || defined(__clang__)) && \ + !defined(__arm__) && !defined(_M_ARM) && !defined(__riscv) && \ + !defined(_WIN32) +#define LIBC_TYPES_HAS_FLOAT16 + +// TODO: This would no longer be required if HdrGen let us guard function +// declarations with multiple macros. +#ifdef LIBC_TYPES_HAS_FLOAT128 +#define LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128 +#endif // LIBC_TYPES_HAS_FLOAT128 +#endif + +#endif // LLVM_LIBC_MACROS_FLOAT16_MACROS_H diff --git a/libc/include/llvm-libc-macros/generic-error-number-macros.h b/libc/include/llvm-libc-macros/generic-error-number-macros.h new file mode 100644 index 000000000000..199a86217b34 --- /dev/null +++ b/libc/include/llvm-libc-macros/generic-error-number-macros.h @@ -0,0 +1,48 @@ +//===-- Definition of generic error number macros -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H +#define LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H + +#define EPERM 1 +#define ENOENT 2 +#define ESRCH 3 +#define EINTR 4 +#define EIO 5 +#define ENXIO 6 +#define E2BIG 7 +#define ENOEXEC 8 +#define EBADF 9 +#define ECHILD 10 +#define EAGAIN 11 +#define ENOMEM 12 +#define EACCES 13 +#define EFAULT 14 +#define ENOTBLK 15 +#define EBUSY 16 +#define EEXIST 17 +#define EXDEV 18 +#define ENODEV 19 +#define ENOTDIR 20 +#define EISDIR 21 +#define EINVAL 22 +#define ENFILE 23 +#define EMFILE 24 +#define ENOTTY 25 +#define ETXTBSY 26 +#define EFBIG 27 +#define ENOSPC 28 +#define ESPIPE 29 +#define EROFS 30 +#define EMLINK 31 +#define EPIPE 32 +#define EDOM 33 +#define ERANGE 34 +#define EILSEQ 84 + +#endif // LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H diff --git a/libc/include/llvm-libc-macros/gpu/signal-macros.h b/libc/include/llvm-libc-macros/gpu/signal-macros.h new file mode 100644 index 000000000000..f0d49ea34fe0 --- /dev/null +++ b/libc/include/llvm-libc-macros/gpu/signal-macros.h @@ -0,0 +1,28 @@ +//===-- Definition of GPU signal number macros ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H +#define LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H + +#define SIGINT 2 +#define SIGILL 4 +#define SIGABRT 6 +#define SIGFPE 8 +#define SIGSEGV 11 +#define SIGTERM 15 + +#define SIG_DFL ((void (*)(int))(0)) +#define SIG_IGN ((void (*)(int))(1)) +#define SIG_ERR ((void (*)(int))(-1)) + +// Max signal number +#define NSIG 64 + +#define __NSIGSET_WORDS NSIG + +#endif // LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H diff --git a/libc/include/llvm-libc-macros/gpu/time-macros.h b/libc/include/llvm-libc-macros/gpu/time-macros.h new file mode 100644 index 000000000000..7142a3e1b276 --- /dev/null +++ b/libc/include/llvm-libc-macros/gpu/time-macros.h @@ -0,0 +1,17 @@ +//===-- Definition of macros from time.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_GPU_TIME_MACROS_H +#define LLVM_LIBC_MACROS_GPU_TIME_MACROS_H + +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 + +#define CLOCKS_PER_SEC 1000000 + +#endif // LLVM_LIBC_MACROS_GPU_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/inttypes-macros.h b/libc/include/llvm-libc-macros/inttypes-macros.h new file mode 100644 index 000000000000..9b554670271e --- /dev/null +++ b/libc/include/llvm-libc-macros/inttypes-macros.h @@ -0,0 +1,420 @@ +//===-- Definition of macros from inttypes.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_MACROS_INTTYPES_MACROS_H +#define LLVM_LIBC_MACROS_INTTYPES_MACROS_H + +// fprintf/scanf format macros. +#define __STDC_VERSION_INTTYPES_H__ 202311L + +// clang provides these macros, so we don't need to define them. +#ifndef __clang__ +#if __UINTPTR_MAX__ == __UINT64_MAX__ +#define __PRI64 "l" +#define __PRIPTR "l" +#elif __UINTPTR_MAX__ == __UINT32_MAX__ +#define __PRI64 "ll" +#define __PRIPTR "" +#else +// CHERI achitecture for example, has 128-bit pointers that use special "P" +// format. +#error "Unsupported pointer format" +#endif +#define __INT8_FMTd__ "hhd" +#define __INT16_FMTd__ "hd" +#define __INT32_FMTd__ "d" +#define __INT64_FMTd__ __PRI64 "d" +#define __INT_LEAST8_FMTd__ "hhd" +#define __INT_LEAST16_FMTd__ "hd" +#define __INT_LEAST32_FMTd__ "d" +#define __INT_LEAST64_FMTd__ __PRI64 "d" +#define __INT_FAST8_FMTd__ "hhd" +#define __INT_FAST16_FMTd__ "hd" +#define __INT_FAST32_FMTd__ "d" +#define __INT_FAST64_FMTd__ __PRI64 "d" +#define __INTMAX_FMTd__ __PRI64 "d" +#define __INTPTR_FMTd__ __PRIPTR "d" + +#define __INT8_FMTi__ "hhi" +#define __INT16_FMTi__ "hi" +#define __INT32_FMTi__ "i" +#define __INT64_FMTi__ __PRI64 "i" +#define __INT_LEAST8_FMTi__ "hhi" +#define __INT_LEAST16_FMTi__ "hi" +#define __INT_LEAST32_FMTi__ "i" +#define __INT_LEAST64_FMTi__ __PRI64 "i" +#define __INT_FAST8_FMTi__ "hhi" +#define __INT_FAST16_FMTi__ "hi" +#define __INT_FAST32_FMTi__ "i" +#define __INT_FAST64_FMTi__ __PRI64 "i" +#define __INTMAX_FMTi__ __PRI64 "i" +#define __INTPTR_FMTi__ __PRIPTR "i" + +#define __UINT8_FMTo__ "hho" +#define __UINT16_FMTo__ "ho" +#define __UINT32_FMTo__ "o" +#define __UINT64_FMTo__ __PRI64 "o" +#define __UINT_LEAST8_FMTo__ "hho" +#define __UINT_LEAST16_FMTo__ "ho" +#define __UINT_LEAST32_FMTo__ "o" +#define __UINT_LEAST64_FMTo__ __PRI64 "o" +#define __UINT_FAST8_FMTo__ "hho" +#define __UINT_FAST16_FMTo__ "ho" +#define __UINT_FAST32_FMTo__ "o" +#define __UINT_FAST64_FMTo__ __PRI64 "o" +#define __UINTMAX_FMTo__ __PRI64 "o" +#define __UINTPTR_FMTo__ __PRIPTR "o" + +#define __UINT8_FMTu__ "hhu" +#define __UINT16_FMTu__ "hu" +#define __UINT32_FMTu__ "u" +#define __UINT64_FMTu__ __PRI64 "u" +#define __UINT_LEAST8_FMTu__ "hhu" +#define __UINT_LEAST16_FMTu__ "hu" +#define __UINT_LEAST32_FMTu__ "u" +#define __UINT_LEAST64_FMTu__ __PRI64 "u" +#define __UINT_FAST8_FMTu__ "hhu" +#define __UINT_FAST16_FMTu__ "hu" +#define __UINT_FAST32_FMTu__ "u" +#define __UINT_FAST64_FMTu__ __PRI64 "u" +#define __UINTMAX_FMTu__ __PRI64 "u" +#define __UINTPTR_FMTu__ __PRIPTR "u" + +#define __UINT8_FMTx__ "hhx" +#define __UINT16_FMTx__ "hx" +#define __UINT32_FMTx__ "x" +#define __UINT64_FMTx__ __PRI64 "x" +#define __UINT_LEAST8_FMTx__ "hhx" +#define __UINT_LEAST16_FMTx__ "hx" +#define __UINT_LEAST32_FMTx__ "x" +#define __UINT_LEAST64_FMTx__ __PRI64 "x" +#define __UINT_FAST8_FMTx__ "hhx" +#define __UINT_FAST16_FMTx__ "hx" +#define __UINT_FAST32_FMTx__ "x" +#define __UINT_FAST64_FMTx__ __PRI64 "x" +#define __UINTMAX_FMTx__ __PRI64 "x" +#define __UINTPTR_FMTx__ __PRIPTR "x" + +#define __UINT8_FMTX__ "hhX" +#define __UINT16_FMTX__ "hX" +#define __UINT32_FMTX__ "X" +#define __UINT64_FMTX__ __PRI64 "X" +#define __UINT_LEAST8_FMTX__ "hhX" +#define __UINT_LEAST16_FMTX__ "hX" +#define __UINT_LEAST32_FMTX__ "X" +#define __UINT_LEAST64_FMTX__ __PRI64 "X" +#define __UINT_FAST8_FMTX__ "hhX" +#define __UINT_FAST16_FMTX__ "hX" +#define __UINT_FAST32_FMTX__ "X" +#define __UINT_FAST64_FMTX__ __PRI64 "X" +#define __UINTMAX_FMTX__ __PRI64 "X" +#define __UINTPTR_FMTX__ __PRIPTR "X" +#endif + +// only recent clang provides these macros, so we need to check if they are +// available. +#ifndef __UINT8_FMTb__ +#define __UINT8_FMTb__ "hhb" +#endif +#ifndef __UINT16_FMTb__ +#define __UINT16_FMTb__ "hb" +#endif +#ifndef __UINT32_FMTb__ +#define __UINT32_FMTb__ "b" +#endif +#ifndef __UINT64_FMTb__ +#define __UINT64_FMTb__ __PRI64 "b" +#endif +#ifndef __UINT_LEAST8_FMTb__ +#define __UINT_LEAST8_FMTb__ "hhb" +#endif +#ifndef __UINT_LEAST16_FMTb__ +#define __UINT_LEAST16_FMTb__ "hb" +#endif +#ifndef __UINT_LEAST32_FMTb__ +#define __UINT_LEAST32_FMTb__ "b" +#endif +#ifndef __UINT_LEAST64_FMTb__ +#define __UINT_LEAST64_FMTb__ __PRI64 "b" +#endif +#ifndef __UINT_FAST8_FMTb__ +#define __UINT_FAST8_FMTb__ "hhb" +#endif +#ifndef __UINT_FAST16_FMTb__ +#define __UINT_FAST16_FMTb__ "hb" +#endif +#ifndef __UINT_FAST32_FMTb__ +#define __UINT_FAST32_FMTb__ "b" +#endif +#ifndef __UINT_FAST64_FMTb__ +#define __UINT_FAST64_FMTb__ __PRI64 "b" +#endif +#ifndef __UINTMAX_FMTb__ +#define __UINTMAX_FMTb__ __PRI64 "b" +#endif +#ifndef __UINTPTR_FMTb__ +#define __UINTPTR_FMTb__ __PRIPTR "b" +#endif + +#ifndef __UINT8_FMTB__ +#define __UINT8_FMTB__ "hhB" +#endif +#ifndef __UINT16_FMTB__ +#define __UINT16_FMTB__ "hB" +#endif +#ifndef __UINT32_FMTB__ +#define __UINT32_FMTB__ "B" +#endif +#ifndef __UINT64_FMTB__ +#define __UINT64_FMTB__ __PRI64 "B" +#endif +#ifndef __UINT_LEAST8_FMTB__ +#define __UINT_LEAST8_FMTB__ "hhB" +#endif +#ifndef __UINT_LEAST16_FMTB__ +#define __UINT_LEAST16_FMTB__ "hB" +#endif +#ifndef __UINT_LEAST32_FMTB__ +#define __UINT_LEAST32_FMTB__ "B" +#endif +#ifndef __UINT_LEAST64_FMTB__ +#define __UINT_LEAST64_FMTB__ __PRI64 "B" +#endif +#ifndef __UINT_FAST8_FMTB__ +#define __UINT_FAST8_FMTB__ "hhB" +#endif +#ifndef __UINT_FAST16_FMTB__ +#define __UINT_FAST16_FMTB__ "hB" +#endif +#ifndef __UINT_FAST32_FMTB__ +#define __UINT_FAST32_FMTB__ "B" +#endif +#ifndef __UINT_FAST64_FMTB__ +#define __UINT_FAST64_FMTB__ __PRI64 "B" +#endif +#ifndef __UINTMAX_FMTB__ +#define __UINTMAX_FMTB__ __PRI64 "B" +#endif +#ifndef __UINTPTR_FMTB__ +#define __UINTPTR_FMTB__ __PRIPTR "B" +#endif + +// The fprintf() macros for signed integers. +#define PRId8 __INT8_FMTd__ +#define PRId16 __INT16_FMTd__ +#define PRId32 __INT32_FMTd__ +#define PRId64 __INT64_FMTd__ +#define PRIdLEAST8 __INT_LEAST8_FMTd__ +#define PRIdLEAST16 __INT_LEAST16_FMTd__ +#define PRIdLEAST32 __INT_LEAST32_FMTd__ +#define PRIdLEAST64 __INT_LEAST64_FMTd__ +#define PRIdFAST8 __INT_FAST8_FMTd__ +#define PRIdFAST16 __INT_FAST16_FMTd__ +#define PRIdFAST32 __INT_FAST32_FMTd__ +#define PRIdFAST64 __INT_FAST64_FMTd__ +#define PRIdMAX __INTMAX_FMTd__ +#define PRIdPTR __INTPTR_FMTd__ + +#define PRIi8 __INT8_FMTi__ +#define PRIi16 __INT16_FMTi__ +#define PRIi32 __INT32_FMTi__ +#define PRIi64 __INT64_FMTi__ +#define PRIiLEAST8 __INT_LEAST8_FMTi__ +#define PRIiLEAST16 __INT_LEAST16_FMTi__ +#define PRIiLEAST32 __INT_LEAST32_FMTi__ +#define PRIiLEAST64 __INT_LEAST64_FMTi__ +#define PRIiFAST8 __INT_FAST8_FMTi__ +#define PRIiFAST16 __INT_FAST16_FMTi__ +#define PRIiFAST32 __INT_FAST32_FMTi__ +#define PRIiFAST64 __INT_FAST64_FMTi__ +#define PRIiMAX __INTMAX_FMTi__ +#define PRIiPTR __INTPTR_FMTi__ + +// The fprintf() macros for unsigned integers. +#define PRIo8 __UINT8_FMTo__ +#define PRIo16 __UINT16_FMTo__ +#define PRIo32 __UINT32_FMTo__ +#define PRIo64 __UINT64_FMTo__ +#define PRIoLEAST8 __UINT_LEAST8_FMTo__ +#define PRIoLEAST16 __UINT_LEAST16_FMTo__ +#define PRIoLEAST32 __UINT_LEAST32_FMTo__ +#define PRIoLEAST64 __UINT_LEAST64_FMTo__ +#define PRIoFAST8 __UINT_FAST8_FMTo__ +#define PRIoFAST16 __UINT_FAST16_FMTo__ +#define PRIoFAST32 __UINT_FAST32_FMTo__ +#define PRIoFAST64 __UINT_FAST64_FMTo__ +#define PRIoMAX __UINTMAX_FMTo__ +#define PRIoPTR __UINTPTR_FMTo__ + +#define PRIu8 __UINT8_FMTu__ +#define PRIu16 __UINT16_FMTu__ +#define PRIu32 __UINT32_FMTu__ +#define PRIu64 __UINT64_FMTu__ +#define PRIuLEAST8 __UINT_LEAST8_FMTu__ +#define PRIuLEAST16 __UINT_LEAST16_FMTu__ +#define PRIuLEAST32 __UINT_LEAST32_FMTu__ +#define PRIuLEAST64 __UINT_LEAST64_FMTu__ +#define PRIuFAST8 __UINT_FAST8_FMTu__ +#define PRIuFAST16 __UINT_FAST16_FMTu__ +#define PRIuFAST32 __UINT_FAST32_FMTu__ +#define PRIuFAST64 __UINT_FAST64_FMTu__ +#define PRIuMAX __UINTMAX_FMTu__ +#define PRIuPTR __UINTPTR_FMTu__ + +#define PRIx8 __UINT8_FMTx__ +#define PRIx16 __UINT16_FMTx__ +#define PRIx32 __UINT32_FMTx__ +#define PRIx64 __UINT64_FMTx__ +#define PRIxLEAST8 __UINT_LEAST8_FMTx__ +#define PRIxLEAST16 __UINT_LEAST16_FMTx__ +#define PRIxLEAST32 __UINT_LEAST32_FMTx__ +#define PRIxLEAST64 __UINT_LEAST64_FMTx__ +#define PRIxFAST8 __UINT_FAST8_FMTx__ +#define PRIxFAST16 __UINT_FAST16_FMTx__ +#define PRIxFAST32 __UINT_FAST32_FMTx__ +#define PRIxFAST64 __UINT_FAST64_FMTx__ +#define PRIxMAX __UINTMAX_FMTx__ +#define PRIxPTR __UINTPTR_FMTx__ + +#define PRIX8 __UINT8_FMTX__ +#define PRIX16 __UINT16_FMTX__ +#define PRIX32 __UINT32_FMTX__ +#define PRIX64 __UINT64_FMTX__ +#define PRIXLEAST8 __UINT_LEAST8_FMTX__ +#define PRIXLEAST16 __UINT_LEAST16_FMTX__ +#define PRIXLEAST32 __UINT_LEAST32_FMTX__ +#define PRIXLEAST64 __UINT_LEAST64_FMTX__ +#define PRIXFAST8 __UINT_FAST8_FMTX__ +#define PRIXFAST16 __UINT_FAST16_FMTX__ +#define PRIXFAST32 __UINT_FAST32_FMTX__ +#define PRIXFAST64 __UINT_FAST64_FMTX__ +#define PRIXMAX __UINTMAX_FMTX__ +#define PRIXPTR __UINTPTR_FMTX__ + +#define PRIb8 __UINT8_FMTb__ +#define PRIb16 __UINT16_FMTb__ +#define PRIb32 __UINT32_FMTb__ +#define PRIb64 __UINT64_FMTb__ +#define PRIbLEAST8 __UINT_LEAST8_FMTb__ +#define PRIbLEAST16 __UINT_LEAST16_FMTb__ +#define PRIbLEAST32 __UINT_LEAST32_FMTb__ +#define PRIbLEAST64 __UINT_LEAST64_FMTb__ +#define PRIbFAST8 __UINT_FAST8_FMTb__ +#define PRIbFAST16 __UINT_FAST16_FMTb__ +#define PRIbFAST32 __UINT_FAST32_FMTb__ +#define PRIbFAST64 __UINT_FAST64_FMTb__ +#define PRIbMAX __UINTMAX_FMTb__ +#define PRIbPTR __UINTPTR_FMTb__ + +#define PRIB8 __UINT8_FMTB__ +#define PRIB16 __UINT16_FMTB__ +#define PRIB32 __UINT32_FMTB__ +#define PRIB64 __UINT64_FMTB__ +#define PRIBLEAST8 __UINT_LEAST8_FMTB__ +#define PRIBLEAST16 __UINT_LEAST16_FMTB__ +#define PRIBLEAST32 __UINT_LEAST32_FMTB__ +#define PRIBLEAST64 __UINT_LEAST64_FMTB__ +#define PRIBFAST8 __UINT_FAST8_FMTB__ +#define PRIBFAST16 __UINT_FAST16_FMTB__ +#define PRIBFAST32 __UINT_FAST32_FMTB__ +#define PRIBFAST64 __UINT_FAST64_FMTB__ +#define PRIBMAX __UINTMAX_FMTB__ +#define PRIBPTR __UINTPTR_FMTB__ + +// The fscanf() macros for signed integers. +#define SCNd8 __INT8_FMTd__ +#define SCNd16 __INT16_FMTd__ +#define SCNd32 __INT32_FMTd__ +#define SCNd64 __INT64_FMTd__ +#define SCNdLEAST8 __INT_LEAST8_FMTd__ +#define SCNdLEAST16 __INT_LEAST16_FMTd__ +#define SCNdLEAST32 __INT_LEAST32_FMTd__ +#define SCNdLEAST64 __INT_LEAST64_FMTd__ +#define SCNdFAST8 __INT_FAST8_FMTd__ +#define SCNdFAST16 __INT_FAST16_FMTd__ +#define SCNdFAST32 __INT_FAST32_FMTd__ +#define SCNdFAST64 __INT_FAST64_FMTd__ +#define SCNdMAX __INTMAX_FMTd__ +#define SCNdPTR __INTPTR_FMTd__ + +#define SCNi8 __INT8_FMTi__ +#define SCNi16 __INT16_FMTi__ +#define SCNi32 __INT32_FMTi__ +#define SCNi64 __INT64_FMTi__ +#define SCNiLEAST8 __INT_LEAST8_FMTi__ +#define SCNiLEAST16 __INT_LEAST16_FMTi__ +#define SCNiLEAST32 __INT_LEAST32_FMTi__ +#define SCNiLEAST64 __INT_LEAST64_FMTi__ +#define SCNiFAST8 __INT_FAST8_FMTi__ +#define SCNiFAST16 __INT_FAST16_FMTi__ +#define SCNiFAST32 __INT_FAST32_FMTi__ +#define SCNiFAST64 __INT_FAST64_FMTi__ +#define SCNiMAX __INTMAX_FMTi__ +#define SCNiPTR __INTPTR_FMTi__ + +// The fscanf() macros for unsigned integers. +#define SCNo8 __UINT8_FMTo__ +#define SCNo16 __UINT16_FMTo__ +#define SCNo32 __UINT32_FMTo__ +#define SCNo64 __UINT64_FMTo__ +#define SCNoLEAST8 __UINT_LEAST8_FMTo__ +#define SCNoLEAST16 __UINT_LEAST16_FMTo__ +#define SCNoLEAST32 __UINT_LEAST32_FMTo__ +#define SCNoLEAST64 __UINT_LEAST64_FMTo__ +#define SCNoFAST8 __UINT_FAST8_FMTo__ +#define SCNoFAST16 __UINT_FAST16_FMTo__ +#define SCNoFAST32 __UINT_FAST32_FMTo__ +#define SCNoFAST64 __UINT_FAST64_FMTo__ +#define SCNoMAX __UINTMAX_FMTo__ +#define SCNoPTR __UINTPTR_FMTo__ + +#define SCNu8 __UINT8_FMTu__ +#define SCNu16 __UINT16_FMTu__ +#define SCNu32 __UINT32_FMTu__ +#define SCNu64 __UINT64_FMTu__ +#define SCNuLEAST8 __UINT_LEAST8_FMTu__ +#define SCNuLEAST16 __UINT_LEAST16_FMTu__ +#define SCNuLEAST32 __UINT_LEAST32_FMTu__ +#define SCNuLEAST64 __UINT_LEAST64_FMTu__ +#define SCNuFAST8 __UINT_FAST8_FMTu__ +#define SCNuFAST16 __UINT_FAST16_FMTu__ +#define SCNuFAST32 __UINT_FAST32_FMTu__ +#define SCNuFAST64 __UINT_FAST64_FMTu__ +#define SCNuMAX __UINTMAX_FMTu__ +#define SCNuPTR __UINTPTR_FMTu__ + +#define SCNx8 __UINT8_FMTx__ +#define SCNx16 __UINT16_FMTx__ +#define SCNx32 __UINT32_FMTx__ +#define SCNx64 __UINT64_FMTx__ +#define SCNxLEAST8 __UINT_LEAST8_FMTx__ +#define SCNxLEAST16 __UINT_LEAST16_FMTx__ +#define SCNxLEAST32 __UINT_LEAST32_FMTx__ +#define SCNxLEAST64 __UINT_LEAST64_FMTx__ +#define SCNxFAST8 __UINT_FAST8_FMTx__ +#define SCNxFAST16 __UINT_FAST16_FMTx__ +#define SCNxFAST32 __UINT_FAST32_FMTx__ +#define SCNxFAST64 __UINT_FAST64_FMTx__ +#define SCNxMAX __UINTMAX_FMTx__ +#define SCNxPTR __UINTPTR_FMTx__ + +#define SCNb8 __UINT8_FMTb__ +#define SCNb16 __UINT16_FMTb__ +#define SCNb32 __UINT32_FMTb__ +#define SCNb64 __UINT64_FMTb__ +#define SCNbLEAST8 __UINT_LEAST8_FMTb__ +#define SCNbLEAST16 __UINT_LEAST16_FMTb__ +#define SCNbLEAST32 __UINT_LEAST32_FMTb__ +#define SCNbLEAST64 __UINT_LEAST64_FMTb__ +#define SCNbFAST8 __UINT_FAST8_FMTb__ +#define SCNbFAST16 __UINT_FAST16_FMTb__ +#define SCNbFAST32 __UINT_FAST32_FMTb__ +#define SCNbFAST64 __UINT_FAST64_FMTb__ +#define SCNbMAX __UINTMAX_FMTb__ +#define SCNbPTR __UINTPTR_FMTb__ + +#endif // LLVM_LIBC_MACROS_INTTYPES_MACROS_H diff --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h new file mode 100644 index 000000000000..79bbbe401eb0 --- /dev/null +++ b/libc/include/llvm-libc-macros/limits-macros.h @@ -0,0 +1,246 @@ +//===-- Definition of macros from limits.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LIMITS_MACROS_H +#define LLVM_LIBC_MACROS_LIMITS_MACROS_H + +// Define all C23 macro constants of limits.h + +#ifndef CHAR_BIT +#ifdef __CHAR_BIT__ +#define CHAR_BIT __CHAR_BIT__ +#else +#define CHAR_BIT 8 +#endif // __CHAR_BIT__ +#endif // CHAR_BIT + +#ifndef MB_LEN_MAX +// Represents a single UTF-32 wide character in the default locale. +#define MB_LEN_MAX 4 +#endif // MB_LEN_MAX + +// *_WIDTH macros + +#ifndef CHAR_WIDTH +#define CHAR_WIDTH CHAR_BIT +#endif // CHAR_WIDTH + +#ifndef SCHAR_WIDTH +#define SCHAR_WIDTH CHAR_BIT +#endif // SCHAR_WIDTH + +#ifndef UCHAR_WIDTH +#define UCHAR_WIDTH CHAR_BIT +#endif // UCHAR_WIDTH + +#ifndef SHRT_WIDTH +#ifdef __SHRT_WIDTH__ +#define SHRT_WIDTH __SHRT_WIDTH__ +#else +#define SHRT_WIDTH 16 +#endif // __SHRT_WIDTH__ +#endif // SHRT_WIDTH + +#ifndef USHRT_WIDTH +#define USHRT_WIDTH SHRT_WIDTH +#endif // USHRT_WIDTH + +#ifndef INT_WIDTH +#ifdef __INT_WIDTH__ +#define INT_WIDTH __INT_WIDTH__ +#else +#define INT_WIDTH 32 +#endif // __INT_WIDTH__ +#endif // INT_WIDTH + +#ifndef UINT_WIDTH +#define UINT_WIDTH INT_WIDTH +#endif // UINT_WIDTH + +#ifndef LONG_WIDTH +#ifdef __LONG_WIDTH__ +#define LONG_WIDTH __LONG_WIDTH__ +#elif defined(__WORDSIZE) +#define LONG_WIDTH __WORDSIZE +#else +// Use __SIZEOF_LONG__ * CHAR_BIT as backup. This is needed for clang-13 or +// before. +#define LONG_WIDTH (__SIZEOF_LONG__ * CHAR_BIT) +#endif // __LONG_WIDTH__ +#endif // LONG_WIDTH + +#ifndef ULONG_WIDTH +#define ULONG_WIDTH LONG_WIDTH +#endif // ULONG_WIDTH + +#ifndef LLONG_WIDTH +#ifdef __LLONG_WIDTH__ +#define LLONG_WIDTH __LLONG_WIDTH__ +#else +#define LLONG_WIDTH 64 +#endif // __LLONG_WIDTH__ +#endif // LLONG_WIDTH + +#ifndef ULLONG_WIDTH +#define ULLONG_WIDTH LLONG_WIDTH +#endif // ULLONG_WIDTH + +#ifndef BOOL_WIDTH +#ifdef __BOOL_WIDTH__ +#define BOOL_WIDTH __BOOL_WIDTH__ +#else +#define BOOL_WIDTH 1 +#endif // __BOOL_WIDTH__ +#endif // BOOL_WIDTH + +// *_MAX macros + +#ifndef SCHAR_MAX +#ifdef __SCHAR_MAX__ +#define SCHAR_MAX __SCHAR_MAX__ +#else +#define SCHAR_MAX 0x7f +#endif // __SCHAR_MAX__ +#endif // SCHAR_MAX + +#ifndef UCHAR_MAX +#define UCHAR_MAX (SCHAR_MAX * 2 + 1) +#endif // UCHAR_MAX + +// Check if char is unsigned. +#if !defined(__CHAR_UNSIGNED__) && ('\xff' > 0) +#define __CHAR_UNSIGNED__ +#endif + +#ifndef CHAR_MAX +#ifdef __CHAR_UNSIGNED__ +#define CHAR_MAX UCHAR_MAX +#else +#define CHAR_MAX SCHAR_MAX +#endif // __CHAR_UNSIGNED__ +#endif // CHAR_MAX + +#ifndef SHRT_MAX +#ifdef __SHRT_MAX__ +#define SHRT_MAX __SHRT_MAX__ +#else +#define SHRT_MAX 0x7fff +#endif // __SHRT_MAX__ +#endif // SHRT_MAX + +#ifndef USHRT_MAX +#define USHRT_MAX (SHRT_MAX * 2U + 1U) +#endif // USHRT_MAX + +#ifndef INT_MAX +#ifdef __INT_MAX__ +#define INT_MAX __INT_MAX__ +#else +#define INT_MAX (0 ^ (1 << (INT_WIDTH - 1))) +#endif // __INT_MAX__ +#endif // INT_MAX + +#ifndef UINT_MAX +#define UINT_MAX (INT_MAX * 2U + 1U) +#endif // UINT_MAX + +#ifndef LONG_MAX +#ifdef __LONG_MAX__ +#define LONG_MAX __LONG_MAX__ +#else +#define LONG_MAX (0L ^ (1L << (LONG_WIDTH - 1))) +#endif // __LONG_MAX__ +#endif // LONG_MAX + +#ifndef ULONG_MAX +#define ULONG_MAX (LONG_MAX * 2UL + 1UL) +#endif // ULONG_MAX + +#ifndef LLONG_MAX +#ifdef __LONG_LONG_MAX__ +#define LLONG_MAX __LONG_LONG_MAX__ +#else +#define LLONG_MAX (0LL ^ (1LL << (LLONG_WIDTH - 1))) +#endif // __LONG_LONG_MAX__ +#endif // LLONG_MAX + +#ifndef ULLONG_MAX +#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) +#endif // ULLONG_MAX + +// *_MIN macros + +#ifndef SCHAR_MIN +#define SCHAR_MIN (-SCHAR_MAX - 1) +#endif // SCHAR_MIN + +#ifndef UCHAR_MIN +#define UCHAR_MIN 0 +#endif // UCHAR_MIN + +#ifndef CHAR_MIN +#ifdef __CHAR_UNSIGNED__ +#define CHAR_MIN UCHAR_MIN +#else +#define CHAR_MIN SCHAR_MIN +#endif // __CHAR_UNSIGNED__ +#endif // CHAR_MIN + +#ifndef SHRT_MIN +#define SHRT_MIN (-SHRT_MAX - 1) +#endif // SHRT_MIN + +#ifndef USHRT_MIN +#define USHRT_MIN 0U +#endif // USHRT_MIN + +#ifndef INT_MIN +#define INT_MIN (-INT_MAX - 1) +#endif // INT_MIN + +#ifndef UINT_MIN +#define UINT_MIN 0U +#endif // UINT_MIN + +#ifndef LONG_MIN +#define LONG_MIN (-LONG_MAX - 1L) +#endif // LONG_MIN + +#ifndef ULONG_MIN +#define ULONG_MIN 0UL +#endif // ULONG_MIN + +#ifndef LLONG_MIN +#define LLONG_MIN (-LLONG_MAX - 1LL) +#endif // LLONG_MIN + +#ifndef ULLONG_MIN +#define ULLONG_MIN 0ULL +#endif // ULLONG_MIN + +#ifndef _POSIX_MAX_CANON +#define _POSIX_MAX_CANON 255 +#endif + +#ifndef _POSIX_MAX_INPUT +#define _POSIX_MAX_INPUT 255 +#endif + +#ifndef _POSIX_NAME_MAX +#define _POSIX_PATH_MAX 256 +#endif + +#ifndef _POSIX_ARG_MAX +#define _POSIX_ARG_MAX 4096 +#endif + +#ifndef IOV_MAX +#define IOV_MAX 1024 +#endif // IOV_MAX + +#endif // LLVM_LIBC_MACROS_LIMITS_MACROS_H diff --git a/libc/include/llvm-libc-macros/link-macros.h b/libc/include/llvm-libc-macros/link-macros.h new file mode 100644 index 000000000000..89e7bb50aa55 --- /dev/null +++ b/libc/include/llvm-libc-macros/link-macros.h @@ -0,0 +1,20 @@ +//===-- Definition of macros to for extra dynamic linker functionality ----===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINK_MACROS_H +#define LLVM_LIBC_MACROS_LINK_MACROS_H + +#include "elf-macros.h" + +#ifdef __LP64__ +#define ElfW(type) Elf64_##type +#else +#define ElfW(type) Elf32_##type +#endif + +#endif diff --git a/libc/include/llvm-libc-macros/linux/error-number-macros.h b/libc/include/llvm-libc-macros/linux/error-number-macros.h new file mode 100644 index 000000000000..9a7304fa161a --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/error-number-macros.h @@ -0,0 +1,32 @@ +#ifndef LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H + +#ifndef ECANCELED +#define ECANCELED 125 +#endif // ECANCELED + +#ifndef EOWNERDEAD +#define EOWNERDEAD 130 +#endif // EOWNERDEAD + +#ifndef ENOTRECOVERABLE +#define ENOTRECOVERABLE 131 +#endif // ENOTRECOVERABLE + +#ifndef ERFKILL +#define ERFKILL 132 +#endif // ERFKILL + +#ifndef EHWPOISON +#define EHWPOISON 133 +#endif // EHWPOISON + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 95 +#endif + +#ifndef ENOTSUP +#define ENOTSUP EOPNOTSUPP +#endif + +#endif // LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/fcntl-macros.h b/libc/include/llvm-libc-macros/linux/fcntl-macros.h new file mode 100644 index 000000000000..aec8a0d2da0b --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/fcntl-macros.h @@ -0,0 +1,105 @@ +//===-- Definition of macros from fcntl.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_FCNTL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_FCNTL_MACROS_H + +// File creation flags +#define O_CLOEXEC 02000000 +#define O_CREAT 00000100 +#define O_PATH 010000000 + +#ifdef __aarch64__ +#define O_DIRECTORY 040000 +#else +#define O_DIRECTORY 00200000 +#endif + +#define O_EXCL 00000200 +#define O_NOCTTY 00000400 + +#ifdef __aarch64__ +#define O_NOFOLLOW 0100000 +#else +#define O_NOFOLLOW 00400000 +#endif + +#define O_TRUNC 00001000 +#define O_TMPFILE (020000000 | O_DIRECTORY) + +// File status flags +#define O_APPEND 00002000 +#define O_DSYNC 00010000 +#define O_NONBLOCK 00004000 +#define O_SYNC 04000000 | O_DSYNC + +// File access mode mask +#define O_ACCMODE 00000003 + +// File access mode flags +#define O_RDONLY 00000000 +#define O_RDWR 00000002 +#define O_WRONLY 00000001 + +// Special directory FD to indicate that the path argument to +// openat is relative to the current directory. +#define AT_FDCWD -100 + +// Special flag to the function unlinkat to indicate that it +// has to perform the equivalent of "rmdir" on the path argument. +#define AT_REMOVEDIR 0x200 + +// Special flag for functions like lstat to convey that symlinks +// should not be followed. +#define AT_SYMLINK_NOFOLLOW 0x100 + +// Allow empty relative pathname. +#define AT_EMPTY_PATH 0x1000 + +// Values of SYS_fcntl commands. +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 +#define F_GETLK 5 +#define F_SETLK 6 +#define F_SETLKW 7 +#define F_SETOWN 8 +#define F_GETOWN 9 +#define F_SETSIG 10 +#define F_GETSIG 11 +#define F_GETLK64 12 +#define F_SETLK64 13 +#define F_SETLKW64 14 +#define F_SETOWN_EX 15 +#define F_GETOWN_EX 16 + +// Open File Description Locks. +#define F_OFD_GETLK 36 +#define F_OFD_SETLK 37 +#define F_OFD_SETLKW 38 + +// Close on succesful +#define F_CLOEXEC 1 + +// Close on execute for fcntl. +#define FD_CLOEXEC 1 + +#define F_RDLCK 0 +#define F_WRLCK 1 +#define F_UNLCK 2 + +// For Large File Support +#if defined(_LARGEFILE64_SOURCE) +#define F_GETLK F_GETLK64 +#define F_SETLK F_SETLK64 +#define F_SETLKW F_SETLKW64 +#endif + +#endif // LLVM_LIBC_MACROS_LINUX_FCNTL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/poll-macros.h b/libc/include/llvm-libc-macros/linux/poll-macros.h new file mode 100644 index 000000000000..d6724c5ee321 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/poll-macros.h @@ -0,0 +1,65 @@ +//===-- Macros defined in poll.h header file ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H + +// From asm-generic/poll.h, redefined here to avoid redeclaring struct pollfd. +#ifndef POLLIN +#define POLLIN 0x0001 +#endif + +#ifndef POLLPRI +#define POLLPRI 0x0002 +#endif + +#ifndef POLLOUT +#define POLLOUT 0x0004 +#endif + +#ifndef POLLERR +#define POLLERR 0x0008 +#endif + +#ifndef POLLHUP +#define POLLHUP 0x0010 +#endif + +#ifndef POLLNVAL +#define POLLNVAL 0x0020 +#endif + +#ifndef POLLRDNORM +#define POLLRDNORM 0x0040 +#endif + +#ifndef POLLRDBAND +#define POLLRDBAND 0x0080 +#endif + +#ifndef POLLWRNORM +#define POLLWRNORM 0x0100 +#endif + +#ifndef POLLWRBAND +#define POLLWRBAND 0x0200 +#endif + +#ifndef POLLMSG +#define POLLMSG 0x0400 +#endif + +#ifndef POLLREMOVE +#define POLLREMOVE 0x1000 +#endif + +#ifndef POLLRDHUP +#define POLLRDHUP 0x2000 +#endif + +#endif // LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sched-macros.h b/libc/include/llvm-libc-macros/linux/sched-macros.h new file mode 100644 index 000000000000..597789bb4ce2 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sched-macros.h @@ -0,0 +1,37 @@ +//===-- Definition of macros from sched.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H + +// Definitions of SCHED_* macros must match was linux as at: +// https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/sched.h + +// Posix required +#define SCHED_OTHER 0 +#define SCHED_FIFO 1 +#define SCHED_RR 2 + +// Linux extentions +#define SCHED_BATCH 3 +#define SCHED_ISO 4 // Not yet implemented, reserved. +#define SCHED_IDLE 5 +#define SCHED_DEADLINE 6 + +#define CPU_SETSIZE __CPU_SETSIZE +#define NCPUBITS __NCPUBITS +#define CPU_COUNT_S(setsize, set) __sched_getcpucount(setsize, set) +#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t), set) +#define CPU_ZERO_S(setsize, set) __sched_setcpuzero(setsize, set) +#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t), set) +#define CPU_SET_S(cpu, setsize, set) __sched_setcpuset(cpu, setsize, set) +#define CPU_SET(cpu, setsize, set) CPU_SET_S(cpu, sizeof(cpt_set_t), set) +#define CPU_ISSET_S(cpu, setsize, set) __sched_getcpuisset(cpu, setsize, set) +#define CPU_ISSET(cpu, setsize, set) CPU_ISSET_S(cpu, sizeof(cpt_set_t), set) + +#endif // LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/signal-macros.h b/libc/include/llvm-libc-macros/linux/signal-macros.h new file mode 100644 index 000000000000..d220241a3820 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/signal-macros.h @@ -0,0 +1,101 @@ +//===-- Definition of Linux signal number macros --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SIGNAL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SIGNAL_MACROS_H + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGIOT 6 +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL SIGIO +#define SIGPWR 30 +#define SIGSYS 31 + +// Max signal number +#define NSIG 64 + +// SIGRTMIN is current set to the minimum usable from user mode programs. If +// the libc itself uses some of these signal numbers for private operations, +// then it has to be adjusted in future to reflect that. +#define SIGRTMIN 32 + +#define SIGRTMAX NSIG + +// The kernel sigset is stored as an array of long values. Each bit of this +// array corresponds to a signal, adjusted by 1. That is, bit 0 corresponds +// to signal number 1, bit 1 corresponds to signal number 2 and so on. The +// below macro denotes the size of that array (in number of long words and +// not bytes). +#define __NSIGSET_WORDS (NSIG / (sizeof(unsigned long) * 8)) + +#define SIG_BLOCK 0 // For blocking signals +#define SIG_UNBLOCK 1 // For unblocking signals +#define SIG_SETMASK 2 // For setting signal mask + +// Flag values to be used for setting sigaction.sa_flags. +#define SA_NOCLDSTOP 0x00000001 +#define SA_NOCLDWAIT 0x00000002 +#define SA_SIGINFO 0x00000004 +#define SA_RESTART 0x10000000 +#define SA_RESTORER 0x04000000 +#define SA_ONSTACK 0x08000000 + +// Signal stack flags +#define SS_ONSTACK 0x1 +#define SS_DISABLE 0x2 + +#if defined(__x86_64__) || defined(__i386__) || defined(__riscv) +#define MINSIGSTKSZ 2048 +#define SIGSTKSZ 8192 +#elif defined(__aarch64__) +#define MINSIGSTKSZ 5120 +#define SIGSTKSZ 16384 +#else +#error "Signal stack sizes not defined for your platform." +#endif + +#define SIG_DFL ((void (*)(int))0) +#define SIG_IGN ((void (*)(int))1) +#define SIG_ERR ((void (*)(int))(-1)) + +// SIGCHLD si_codes +#define CLD_EXITED 1 // child has exited +#define CLD_KILLED 2 // child was killed +#define CLD_DUMPED 3 // child terminated abnormally +#define CLD_TRAPPED 4 // traced child has trapped +#define CLD_STOPPED 5 // child has stopped +#define CLD_CONTINUED 6 // stopped child has continued + +#endif // LLVM_LIBC_MACROS_LINUX_SIGNAL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-epoll-macros.h b/libc/include/llvm-libc-macros/linux/sys-epoll-macros.h new file mode 100644 index 000000000000..f73d690908fd --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-epoll-macros.h @@ -0,0 +1,40 @@ +//===-- Macros defined in sys/epoll.h header file -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H + +#include "fcntl-macros.h" + +// These are also defined in <linux/eventpoll.h> but that also contains a +// different definition of the epoll_event struct that is different from the +// userspace version. + +#define EPOLL_CLOEXEC O_CLOEXEC + +#define EPOLL_CTL_ADD 1 +#define EPOLL_CTL_DEL 2 +#define EPOLL_CTL_MOD 3 + +#define EPOLLIN 0x1 +#define EPOLLPRI 0x2 +#define EPOLLOUT 0x4 +#define EPOLLERR 0x8 +#define EPOLLHUP 0x10 +#define EPOLLRDNORM 0x40 +#define EPOLLRDBAND 0x80 +#define EPOLLWRNORM 0x100 +#define EPOLLWRBAND 0x200 +#define EPOLLMSG 0x400 +#define EPOLLRDHUP 0x2000 +#define EPOLLEXCLUSIVE 0x10000000 +#define EPOLLWAKEUP 0x20000000 +#define EPOLLONESHOT 0x40000000 +#define EPOLLET 0x80000000 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h b/libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h new file mode 100644 index 000000000000..41226080084c --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h @@ -0,0 +1,20 @@ +//===-- Definition of macros from sys/ioctl.h -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_IOCTL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_IOCTL_MACROS_H + +// TODO (michaelrj): Finish defining these macros. +// Just defining this macro for the moment since it's all that we need right +// now. The other macros are mostly just constants, but there's some complexity +// around the definitions of macros like _IO, _IOR, _IOW, and _IOWR that I don't +// think is worth digging into right now. +#define TIOCGETD 0x5424 +#define FIONREAD 0x541B + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_IOCTL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-random-macros.h b/libc/include/llvm-libc-macros/linux/sys-random-macros.h new file mode 100644 index 000000000000..9261e87bdbf6 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-random-macros.h @@ -0,0 +1,17 @@ +//===-- Definition of macros from sys/random.h ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_RANDOM_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_RANDOM_MACROS_H + +// Getrandom flags +#define GRND_RANDOM 0x0001 +#define GRND_NONBLOCK 0x0002 +#define GRND_INSECURE 0x0004 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_RANDOM_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-resource-macros.h b/libc/include/llvm-libc-macros/linux/sys-resource-macros.h new file mode 100644 index 000000000000..c9d93c30c35a --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-resource-macros.h @@ -0,0 +1,31 @@ +//===-- Macros defined in sys/resource.h header file ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_RESOURCE_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_RESOURCE_MACROS_H + +#define RLIMIT_CPU 0 +#define RLIMIT_FSIZE 1 +#define RLIMIT_DATA 2 +#define RLIMIT_STACK 3 +#define RLIMIT_CORE 4 +#define RLIMIT_RSS 5 +#define RLIMIT_NPROC 6 +#define RLIMIT_NOFILE 7 +#define RLIMIT_MEMLOCK 8 +#define RLIMIT_AS 9 +#define RLIMIT_LOCKS 10 +#define RLIMIT_SIGPENDING 11 +#define RLIMIT_MSGQUEUE 12 +#define RLIMIT_NICE 13 +#define RLIMIT_RTPRIO 14 +#define RLIMIT_RTTIME 15 + +#define RLIM_INFINITY (~0UL) + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_RESOURCE_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-socket-macros.h b/libc/include/llvm-libc-macros/linux/sys-socket-macros.h new file mode 100644 index 000000000000..f335200a103b --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-socket-macros.h @@ -0,0 +1,28 @@ +//===-- Definition of macros from sys/socket.h ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_SOCKET_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_SOCKET_MACROS_H + +// IEEE Std 1003.1-2017 - basedefs/sys_socket.h.html +// Macro values come from the Linux syscall interface. + +#define AF_UNSPEC 0 // Unspecified +#define AF_UNIX 1 // Unix domain sockets +#define AF_LOCAL 1 // POSIX name for AF_UNIX +#define AF_INET 2 // Internet IPv4 Protocol +#define AF_INET6 10 // IP version 6 + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 +#define SOCK_RDM 4 +#define SOCK_SEQPACKET 5 +#define SOCK_PACKET 10 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_SOCKET_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-stat-macros.h b/libc/include/llvm-libc-macros/linux/sys-stat-macros.h new file mode 100644 index 000000000000..3013121d0f3c --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-stat-macros.h @@ -0,0 +1,48 @@ +//===-- Definition of macros from sys/stat.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H + +// Definitions from linux/stat.h +#define S_IFMT 0170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 + +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 + +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 + +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-time-macros.h b/libc/include/llvm-libc-macros/linux/sys-time-macros.h new file mode 100644 index 000000000000..e97819594adc --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-time-macros.h @@ -0,0 +1,53 @@ +//===-- Definition of macros from sys/time.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H + +// Add two timevals and put the result in timeval_ptr_result. If the resulting +// usec value is greater than 999,999 then the microseconds are turned into full +// seconds (1,000,000 is subtracted from usec and 1 is added to sec). +#define timeradd(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \ + (timeval_ptr_result)->tv_sec = \ + (timeval_ptr_a)->tv_sec + (timeval_ptr_b)->tv_sec + \ + (((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 ? 1 \ + : 0); \ + (timeval_ptr_result)->tv_usec = \ + (timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec - \ + (((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 \ + ? 1000000 \ + : 0); + +// Subtract two timevals and put the result in timeval_ptr_result. If the +// resulting usec value is less than 0 then 1,000,000 is added to usec and 1 is +// subtracted from sec. +#define timersub(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \ + (timeval_ptr_result)->tv_sec = \ + (timeval_ptr_a)->tv_sec - (timeval_ptr_b)->tv_sec - \ + (((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1 : 0); \ + (timeval_ptr_result)->tv_usec = \ + (timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec + \ + (((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1000000 \ + : 0); + +// Reset a timeval to the epoch. +#define timerclear(timeval_ptr) \ + (timeval_ptr)->tv_sec = 0; \ + (timeval_ptr)->tv_usec = 0; + +// Determine if a timeval is set to the epoch. +#define timerisset(timeval_ptr) \ + (timeval_ptr)->tv_sec != 0 || (timeval_ptr)->tv_usec != 0; + +// Compare two timevals using CMP. +#define timercmp(timeval_ptr_a, timeval_ptr_b, CMP) \ + (((timeval_ptr_a)->tv_sec == (timeval_ptr_b)->tv_sec) \ + ? ((timeval_ptr_a)->tv_usec CMP(timeval_ptr_b)->tv_usec) \ + : ((timeval_ptr_a)->tv_sec CMP(timeval_ptr_b)->tv_sec)) + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h new file mode 100644 index 000000000000..d01cfa71ba39 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h @@ -0,0 +1,27 @@ +//===-- Definition of macros from sys/wait.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H + +#include <linux/wait.h> + +#define WCOREDUMP(status) ((status) & WCOREFLAG) +#define WEXITSTATUS(status) (((status) & 0xff00) >> 8) +#define WIFCONTINUED(status) ((status) == 0xffff) +#define WIFEXITED(status) (WTERMSIG(status) == 0) +#define WIFSIGNALED(status) ((WTERMSIG(status) + 1) >= 2) +#define WIFSTOPPED(status) (WTERMSIG(status) == 0x7f) +#define WSTOPSIG(status) WEXITSTATUS(status) +#define WTERMSIG(status) ((status) & 0x7f) + +#define WCOREFLAG 0x80 +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | 0x7f) + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/termios-macros.h b/libc/include/llvm-libc-macros/linux/termios-macros.h new file mode 100644 index 000000000000..668cfe27abaa --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/termios-macros.h @@ -0,0 +1,167 @@ +//===-- Definition of macros from termios.h -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_TERMIOS_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_TERMIOS_MACROS_H + +// Below are generic definitions of symbolic bit-masks, modes etc. They serve +// most architectures including x86_64, aarch64 but have to be adjusted for few +// architectures MIPS. + +#define NCCS 32 + +// Bit-masks for the c_iflag field of struct termios. +#define IGNBRK 0000001 // Ignore break condition +#define BRKINT 0000002 // Signal interrupt on break +#define IGNPAR 0000004 // Ignore characters with parity errors +#define PARMRK 0000010 // Mark parity and framing errors +#define INPCK 0000020 // Enable input parity check +#define ISTRIP 0000040 // Strip 8th bit off characters +#define INLCR 0000100 // Map NL to CR on input +#define IGNCR 0000200 // Ignore CR +#define ICRNL 0000400 // Map CR to NL on input +#define IUCLC 0001000 // Map uppercase characters to lowercase on input +#define IXON 0002000 // Enable start/stop output control +#define IXANY 0004000 // Enable any character to restart output +#define IXOFF 0010000 // Enable start/stop input control +#define IMAXBEL 0020000 // Ring bell when input queue is full +#define IUTF8 0040000 // Input is UTF8 (not in POSIX) + +// Bit-masks for the c_oflag field of struct termios. +#define OPOST 0000001 // Post-process output +#define OLCUC 0000002 // Map lowercase characters to uppercase on output +#define ONLCR 0000004 // Map NL to CR-NL on output +#define OCRNL 0000010 // Map CR to NL on output +#define ONOCR 0000020 // No CR output at column 0 +#define ONLRET 0000040 // NL performs CR function +#define OFILL 0000100 // Use fill characters for delay +#define OFDEL 0000200 // Fill is DEL +#define NLDLY 0000400 // Select newline delays +#define NL0 0000000 // Newline type 0 +#define NL1 0000400 // Newline type 1 +#define CRDLY 0003000 // Select carriage-return delays +#define CR0 0000000 // Carriage-return delay type 0 +#define CR1 0001000 // Carriage-return delay type 1 +#define CR2 0002000 // Carriage-return delay type 2 +#define CR3 0003000 // Carriage-return delay type 3 +#define TABDLY 0014000 // Select horizontal-tab delays +#define TAB0 0000000 // Horizontal-tab delay type 0 +#define TAB1 0004000 // Horizontal-tab delay type 1 +#define TAB2 0010000 // Horizontal-tab delay type 2 +#define TAB3 0014000 // Expand tabs to spaces +#define BSDLY 0020000 // Select backspace delays +#define BS0 0000000 // Backspace-delay type 0 +#define BS1 0020000 // Backspace-delay type 1 +#define FFDLY 0100000 // Select form-feed delays +#define FF0 0000000 // Form-feed delay type 0 +#define FF1 0100000 // Form-feed delay type 1 +#define VTDLY 0040000 // Select vertical-tab delays +#define VT0 0000000 // Vertical-tab delay type 0 +#define VT1 0040000 // Vertical-tab delay type 1 +#define XTABS 0014000 + +// Symbolic subscripts for the c_cc array. +#define VINTR 0 +#define VQUIT 1 +#define VERASE 2 +#define VKILL 3 +#define VEOF 4 +#define VTIME 5 +#define VMIN 6 +#define VSWTC 7 +#define VSTART 8 +#define VSTOP 9 +#define VSUSP 10 +#define VEOL 11 +#define VREPRINT 12 +#define VDISCARD 13 +#define VWERASE 14 +#define VLNEXT 15 +#define VEOL2 16 + +// Baud rate related definitions +#define CBAUD 000000010017 // Baud speed mask +#define CBAUDX 000000010000 // Extra baud speed mask +#define CIBAUD 002003600000 +#define CMSPAR 010000000000 +#define CRTSCTS 020000000000 +// Baud rates with values representable by the speed_t type. +#define B0 0000000 // Implies hang-up +// A symbol B<NN+> below indicates a baud rate of <NN+>. +#define B50 0000001 +#define B75 0000002 +#define B110 0000003 +#define B134 0000004 +#define B150 0000005 +#define B200 0000006 +#define B300 0000007 +#define B600 0000010 +#define B1200 0000011 +#define B1800 0000012 +#define B2400 0000013 +#define B4800 0000014 +#define B9600 0000015 +#define B19200 0000016 +#define B38400 0000017 +// Extra baud rates +#define B57600 0010001 +#define B115200 0010002 +#define B230400 0010003 +#define B460800 0010004 +#define B500000 0010005 +#define B576000 0010006 +#define B921600 0010007 +#define B1000000 0010010 +#define B1152000 0010011 +#define B1500000 0010012 +#define B2000000 0010013 +#define B2500000 0010014 +#define B3000000 0010015 +#define B3500000 0010016 +#define B4000000 0010017 + +// Control mode bits for use in the c_cflag field of struct termios. +#define CSIZE 0000060 // Mask for character size bits +#define CS5 0000000 +#define CS6 0000020 +#define CS7 0000040 +#define CS8 0000060 +#define CSTOPB 0000100 // Send two bits, else one +#define CREAD 0000200 // Enable receiver +#define PARENB 0000400 // Parity enable +#define PARODD 0001000 // Odd parity, else even +#define HUPCL 0002000 // Hang up on last close +#define CLOCAL 0004000 // Ignore modem status lines + +// Local mode bits for use in the c_lflag field of struct termios. +#define ISIG 0000001 // Enable signals +#define ICANON 0000002 // Canonical input (erase and kill processing) +#define ECHO 0000010 // Enable echo +#define ECHOE 0000020 // Echo erase character as error-correcting backspace +#define ECHOK 0000040 // Echo KILL +#define ECHONL 0000100 // Echo NL +#define NOFLSH 0000200 // Disable flush after interrupt or quit +#define TOSTOP 0000400 // Send SIGTTOU for background output + +// Attribute selection +#define TCSANOW 0 // Change attributes immediately +#define TCSADRAIN 1 // Change attributes when output has drained +#define TCSAFLUSH 2 // Same as TCSADRAIN and flush pending Output + +// Symbolic constants for use with tcflush function. +#define TCIFLUSH 0 // Flush pending input +#define TCIOFLUSH 1 // Flush pending input and unstransmitted output +#define TCOFLUSH 2 // Flush unstransmitted output + +// Symbolic constantf for use with tcflow function. +#define TCOOFF 0 // Transmit a STOP character, intended to suspend input data +#define TCOON 1 // Transmit a START character, intended to restart input data +#define TCIOFF 2 // Suspend output +#define TCION 3 // Restart output + +#endif // LLVM_LIBC_MACROS_LINUX_TERMIOS_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/time-macros.h b/libc/include/llvm-libc-macros/linux/time-macros.h new file mode 100644 index 000000000000..407a1eb30eea --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/time-macros.h @@ -0,0 +1,26 @@ +//===-- Definition of macros from time.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_TIME_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_TIME_MACROS_H + +// clock type macros +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 +#define CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOCK_THREAD_CPUTIME_ID 3 +#define CLOCK_MONOTONIC_RAW 4 +#define CLOCK_REALTIME_COARSE 5 +#define CLOCK_MONOTONIC_COARSE 6 +#define CLOCK_BOOTTIME 7 +#define CLOCK_REALTIME_ALARM 8 +#define CLOCK_BOOTTIME_ALARM 9 + +#define CLOCKS_PER_SEC 1000000 + +#endif // LLVM_LIBC_MACROS_LINUX_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/unistd-macros.h b/libc/include/llvm-libc-macros/linux/unistd-macros.h new file mode 100644 index 000000000000..a4c8e3cd91f7 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/unistd-macros.h @@ -0,0 +1,57 @@ +//===-- Definition of macros from unistd.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_UNISTD_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_UNISTD_MACROS_H + +// Values for mode argument to the access(...) function. +#define F_OK 0 +#define X_OK 1 +#define W_OK 2 +#define R_OK 4 + +#define _SC_PAGESIZE 1 +#define _SC_PAGE_SIZE _SC_PAGESIZE + +#define _PC_FILESIZEBITS 0 +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_2_SYMLINKS 7 +#define _PC_ALLOC_SIZE_MIN 8 +#define _PC_REC_INCR_XFER_SIZE 9 +#define _PC_REC_MAX_XFER_SIZE 10 +#define _PC_REC_MIN_XFER_SIZE 11 +#define _PC_REC_XFER_ALIGN 12 +#define _PC_SYMLINK_MAX 13 +#define _PC_CHOWN_RESTRICTED 14 +#define _PC_NO_TRUNC 15 +#define _PC_VDISABLE 16 +#define _PC_ASYNC_IO 17 +#define _PC_PRIO_IO 18 +#define _PC_SYNC_IO 19 + +// TODO: Move these limit macros to a separate file +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_NO_TRUNC 1 +#define _POSIX_VDISABLE '\0' + +// Macro to set up the call to the __llvm_libc_syscall function +// This is to prevent the call from having fewer than 6 arguments, since six +// arguments are always passed to the syscall. Unnecessary arguments are +// ignored. +#define __syscall_helper(sysno, arg1, arg2, arg3, arg4, arg5, arg6, ...) \ + __llvm_libc_syscall((long)(sysno), (long)(arg1), (long)(arg2), (long)(arg3), \ + (long)(arg4), (long)(arg5), (long)(arg6)) +#define syscall(...) __syscall_helper(__VA_ARGS__, 0, 1, 2, 3, 4, 5, 6) + +#endif // LLVM_LIBC_MACROS_LINUX_UNISTD_MACROS_H diff --git a/libc/include/llvm-libc-macros/locale-macros.h b/libc/include/llvm-libc-macros/locale-macros.h new file mode 100644 index 000000000000..892f8b69f3a7 --- /dev/null +++ b/libc/include/llvm-libc-macros/locale-macros.h @@ -0,0 +1,32 @@ +//===-- Definition of macros from locale.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LOCALE_MACROS_H +#define LLVM_LIBC_MACROS_LOCALE_MACROS_H + +#include "../llvm-libc-types/locale_t.h" + +#define LC_CTYPE 0 +#define LC_NUMERIC 1 +#define LC_TIME 2 +#define LC_COLLATE 3 +#define LC_MONETARY 4 +#define LC_MESSAGES 5 +#define LC_ALL 6 + +#define LC_GLOBAL_LOCALE ((locale_t)(-1)) + +#define LC_CTYPE_MASK (1 << LC_CTYPE) +#define LC_NUMERIC_MASK (1 << LC_NUMERIC) +#define LC_TIME_MASK (1 << LC_TIME) +#define LC_COLLATE_MASK (1 << LC_COLLATE) +#define LC_MONETARY_MASK (1 << LC_MONETARY) +#define LC_MESSAGES_MASK (1 << LC_MESSAGES) +#define LC_ALL_MASK 0x7fffffff + +#endif // LLVM_LIBC_MACROS_LOCALE_MACROS_H diff --git a/libc/include/llvm-libc-macros/malloc-macros.h b/libc/include/llvm-libc-macros/malloc-macros.h new file mode 100644 index 000000000000..65eddfc5e86d --- /dev/null +++ b/libc/include/llvm-libc-macros/malloc-macros.h @@ -0,0 +1,17 @@ +//===-- Definition of macros to be used with malloc functions -------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_MALLOC_MACROS_H +#define LLVM_LIBC_MACROS_MALLOC_MACROS_H + +// Note: these values only make sense when Scudo is used as the memory +// allocator. +#define M_PURGE (-101) +#define M_PURGE_ALL (-104) + +#endif // LLVM_LIBC_MACROS_MALLOC_MACROS_H diff --git a/libc/include/llvm-libc-macros/math-function-macros.h b/libc/include/llvm-libc-macros/math-function-macros.h new file mode 100644 index 000000000000..21d09f1f5e1a --- /dev/null +++ b/libc/include/llvm-libc-macros/math-function-macros.h @@ -0,0 +1,37 @@ +//===-- Definition of function macros from math.h -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H +#define LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H + +#include "math-macros.h" + +#ifndef __cplusplus +#define issignaling(x) \ + _Generic((x), \ + float: issignalingf, \ + double: issignaling, \ + long double: issignalingl)(x) +#define iscanonical(x) \ + _Generic((x), \ + float: iscanonicalf, \ + double: iscanonical, \ + long double: iscanonicall)(x) +#endif + +#define isfinite(x) __builtin_isfinite(x) +#define isinf(x) __builtin_isinf(x) +#define isnan(x) __builtin_isnan(x) +#define signbit(x) __builtin_signbit(x) +#define iszero(x) (x == 0) +#define fpclassify(x) \ + __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x) +#define isnormal(x) __builtin_isnormal(x) +#define issubnormal(x) (fpclassify(x) == FP_SUBNORMAL) + +#endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h new file mode 100644 index 000000000000..2f05d7544666 --- /dev/null +++ b/libc/include/llvm-libc-macros/math-macros.h @@ -0,0 +1,53 @@ +//===-- Definition of macros from math.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_MATH_MACROS_H +#define LLVM_LIBC_MACROS_MATH_MACROS_H + +#include "limits-macros.h" + +#define FP_NAN 0 +#define FP_INFINITE 1 +#define FP_ZERO 2 +#define FP_SUBNORMAL 3 +#define FP_NORMAL 4 + +#define FP_INT_UPWARD 0 +#define FP_INT_DOWNWARD 1 +#define FP_INT_TOWARDZERO 2 +#define FP_INT_TONEARESTFROMZERO 3 +#define FP_INT_TONEAREST 4 + +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 + +#define HUGE_VAL __builtin_huge_val() +#define HUGE_VALF __builtin_huge_valf() +#define INFINITY __builtin_inff() +#define NAN __builtin_nanf("") + +#define FP_ILOGB0 (-INT_MAX - 1) +#define FP_LLOGB0 (-LONG_MAX - 1) + +#ifdef __FP_LOGBNAN_MIN +#define FP_ILOGBNAN (-INT_MAX - 1) +#define FP_LLOGBNAN (-LONG_MAX - 1) +#else +#define FP_ILOGBNAN INT_MAX +#define FP_LLOGBNAN LONG_MAX +#endif + +#if defined(__NVPTX__) || defined(__AMDGPU__) || defined(__FAST_MATH__) +#define math_errhandling 0 +#elif defined(__NO_MATH_ERRNO__) +#define math_errhandling (MATH_ERREXCEPT) +#else +#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) +#endif + +#endif // LLVM_LIBC_MACROS_MATH_MACROS_H diff --git a/libc/include/llvm-libc-macros/null-macro.h b/libc/include/llvm-libc-macros/null-macro.h new file mode 100644 index 000000000000..416d4e865fc5 --- /dev/null +++ b/libc/include/llvm-libc-macros/null-macro.h @@ -0,0 +1,15 @@ +//===-- Definition of the NULL macro --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_NULL_MACRO_H +#define LLVM_LIBC_MACROS_NULL_MACRO_H + +#define __need_NULL +#include <stddef.h> + +#endif // LLVM_LIBC_MACROS_NULL_MACRO_H diff --git a/libc/include/llvm-libc-macros/offsetof-macro.h b/libc/include/llvm-libc-macros/offsetof-macro.h new file mode 100644 index 000000000000..208c06b29cb6 --- /dev/null +++ b/libc/include/llvm-libc-macros/offsetof-macro.h @@ -0,0 +1,15 @@ +//===-- Definition of the offsetof macro ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_OFFSETOF_MACRO_H +#define LLVM_LIBC_MACROS_OFFSETOF_MACRO_H + +#define __need_offsetof +#include <stddef.h> + +#endif // LLVM_LIBC_MACROS_OFFSETOF_MACRO_H diff --git a/libc/include/llvm-libc-macros/poll-macros.h b/libc/include/llvm-libc-macros/poll-macros.h new file mode 100644 index 000000000000..52b59a978a21 --- /dev/null +++ b/libc/include/llvm-libc-macros/poll-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in poll.h header file ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_POLL_MACROS_H +#define LLVM_LIBC_MACROS_POLL_MACROS_H + +#ifdef __linux__ +#include "linux/poll-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_POLL_MACROS_H diff --git a/libc/include/llvm-libc-macros/pthread-macros.h b/libc/include/llvm-libc-macros/pthread-macros.h new file mode 100644 index 000000000000..fcc6ef925e3f --- /dev/null +++ b/libc/include/llvm-libc-macros/pthread-macros.h @@ -0,0 +1,65 @@ +//===-- Definition of pthread macros --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_PTHREAD_MACRO_H +#define LLVM_LIBC_MACROS_PTHREAD_MACRO_H + +#include "null-macro.h" + +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_CREATE_DETACHED 1 + +#define PTHREAD_MUTEX_NORMAL 0 +#define PTHREAD_MUTEX_ERRORCHECK 1 +#define PTHREAD_MUTEX_RECURSIVE 2 +#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL + +#define PTHREAD_MUTEX_STALLED 0 +#define PTHREAD_MUTEX_ROBUST 1 + +#define PTHREAD_ONCE_INIT {0} + +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 + +#ifdef __linux__ +#define PTHREAD_MUTEX_INITIALIZER \ + { \ + /* .__timed = */ 0, /* .__recursive = */ 0, \ + /* .__robust = */ 0, /* .__owner = */ NULL, \ + /* .__lock_count = */ 0, /* .__futex_word = */ {0}, \ + } +#else +#define PTHREAD_MUTEX_INITIALIZER \ + { \ + /* .__timed = */ 0, /* .__recursive = */ 0, \ + /* .__robust = */ 0, /* .__owner = */ NULL, \ + /* .__lock_count = */ 0, \ + } +#endif + +#define PTHREAD_RWLOCK_INITIALIZER \ + { \ + /* .__is_pshared = */ 0, \ + /* .__preference = */ 0, \ + /* .__state = */ 0, \ + /* .__write_tid = */ 0, \ + /* .__wait_queue_mutex = */ {0}, \ + /* .__pending_readers = */ {0}, \ + /* .__pending_writers = */ {0}, \ + /* .__reader_serialization = */ {0}, \ + /* .__writer_serialization = */ {0}, \ + } + +// glibc extensions +#define PTHREAD_STACK_MIN (1 << 14) // 16KB +#define PTHREAD_RWLOCK_PREFER_READER_NP 0 +#define PTHREAD_RWLOCK_PREFER_WRITER_NP 1 +#define PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 2 + +#endif // LLVM_LIBC_MACROS_PTHREAD_MACRO_H diff --git a/libc/include/llvm-libc-macros/sched-macros.h b/libc/include/llvm-libc-macros/sched-macros.h new file mode 100644 index 000000000000..0f643029816c --- /dev/null +++ b/libc/include/llvm-libc-macros/sched-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sched.h header file -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SCHED_MACROS_H +#define LLVM_LIBC_MACROS_SCHED_MACROS_H + +#ifdef __linux__ +#include "linux/sched-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SCHED_MACROS_H diff --git a/libc/include/llvm-libc-macros/signal-macros.h b/libc/include/llvm-libc-macros/signal-macros.h new file mode 100644 index 000000000000..fbe929a0fea2 --- /dev/null +++ b/libc/include/llvm-libc-macros/signal-macros.h @@ -0,0 +1,18 @@ +//===-- Definition of signal number macros --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SIGNAL_MACROS_H +#define LLVM_LIBC_MACROS_SIGNAL_MACROS_H + +#if defined(__linux__) +#include "linux/signal-macros.h" +#elif defined(__NVPTX__) || defined(__AMDGPU__) +#include "gpu/signal-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SIGNAL_MACROS_H diff --git a/libc/include/llvm-libc-macros/stdbit-macros.h b/libc/include/llvm-libc-macros/stdbit-macros.h new file mode 100644 index 000000000000..c5b2f0977834 --- /dev/null +++ b/libc/include/llvm-libc-macros/stdbit-macros.h @@ -0,0 +1,316 @@ +//===-- Definition of macros to be used with stdbit functions ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __LLVM_LIBC_MACROS_STDBIT_MACROS_H +#define __LLVM_LIBC_MACROS_STDBIT_MACROS_H + +#define __STDC_VERSION_STDBIT_H__ 202311L +#define __STDC_ENDIAN_LITTLE__ __ORDER_LITTLE_ENDIAN__ +#define __STDC_ENDIAN_BIG__ __ORDER_BIG_ENDIAN__ +#define __STDC_ENDIAN_NATIVE__ __BYTE_ORDER__ + +// TODO(https://github.com/llvm/llvm-project/issues/80509): support _BitInt(). +#ifdef __cplusplus +inline unsigned stdc_leading_zeros(unsigned char x) { + return stdc_leading_zeros_uc(x); +} +inline unsigned stdc_leading_zeros(unsigned short x) { + return stdc_leading_zeros_us(x); +} +inline unsigned stdc_leading_zeros(unsigned x) { + return stdc_leading_zeros_ui(x); +} +inline unsigned stdc_leading_zeros(unsigned long x) { + return stdc_leading_zeros_ul(x); +} +inline unsigned stdc_leading_zeros(unsigned long long x) { + return stdc_leading_zeros_ull(x); +} +inline unsigned stdc_leading_ones(unsigned char x) { + return stdc_leading_ones_uc(x); +} +inline unsigned stdc_leading_ones(unsigned short x) { + return stdc_leading_ones_us(x); +} +inline unsigned stdc_leading_ones(unsigned x) { + return stdc_leading_ones_ui(x); +} +inline unsigned stdc_leading_ones(unsigned long x) { + return stdc_leading_ones_ul(x); +} +inline unsigned stdc_leading_ones(unsigned long long x) { + return stdc_leading_ones_ull(x); +} +inline unsigned stdc_trailing_zeros(unsigned char x) { + return stdc_trailing_zeros_uc(x); +} +inline unsigned stdc_trailing_zeros(unsigned short x) { + return stdc_trailing_zeros_us(x); +} +inline unsigned stdc_trailing_zeros(unsigned x) { + return stdc_trailing_zeros_ui(x); +} +inline unsigned stdc_trailing_zeros(unsigned long x) { + return stdc_trailing_zeros_ul(x); +} +inline unsigned stdc_trailing_zeros(unsigned long long x) { + return stdc_trailing_zeros_ull(x); +} +inline unsigned stdc_trailing_ones(unsigned char x) { + return stdc_trailing_ones_uc(x); +} +inline unsigned stdc_trailing_ones(unsigned short x) { + return stdc_trailing_ones_us(x); +} +inline unsigned stdc_trailing_ones(unsigned x) { + return stdc_trailing_ones_ui(x); +} +inline unsigned stdc_trailing_ones(unsigned long x) { + return stdc_trailing_ones_ul(x); +} +inline unsigned stdc_trailing_ones(unsigned long long x) { + return stdc_trailing_ones_ull(x); +} +inline unsigned stdc_first_leading_zero(unsigned char x) { + return stdc_first_leading_zero_uc(x); +} +inline unsigned stdc_first_leading_zero(unsigned short x) { + return stdc_first_leading_zero_us(x); +} +inline unsigned stdc_first_leading_zero(unsigned x) { + return stdc_first_leading_zero_ui(x); +} +inline unsigned stdc_first_leading_zero(unsigned long x) { + return stdc_first_leading_zero_ul(x); +} +inline unsigned stdc_first_leading_zero(unsigned long long x) { + return stdc_first_leading_zero_ull(x); +} +inline unsigned stdc_first_leading_one(unsigned char x) { + return stdc_first_leading_one_uc(x); +} +inline unsigned stdc_first_leading_one(unsigned short x) { + return stdc_first_leading_one_us(x); +} +inline unsigned stdc_first_leading_one(unsigned x) { + return stdc_first_leading_one_ui(x); +} +inline unsigned stdc_first_leading_one(unsigned long x) { + return stdc_first_leading_one_ul(x); +} +inline unsigned stdc_first_leading_one(unsigned long long x) { + return stdc_first_leading_one_ull(x); +} +inline unsigned stdc_first_trailing_zero(unsigned char x) { + return stdc_first_trailing_zero_uc(x); +} +inline unsigned stdc_first_trailing_zero(unsigned short x) { + return stdc_first_trailing_zero_us(x); +} +inline unsigned stdc_first_trailing_zero(unsigned x) { + return stdc_first_trailing_zero_ui(x); +} +inline unsigned stdc_first_trailing_zero(unsigned long x) { + return stdc_first_trailing_zero_ul(x); +} +inline unsigned stdc_first_trailing_zero(unsigned long long x) { + return stdc_first_trailing_zero_ull(x); +} +inline unsigned stdc_first_trailing_one(unsigned char x) { + return stdc_first_trailing_one_uc(x); +} +inline unsigned stdc_first_trailing_one(unsigned short x) { + return stdc_first_trailing_one_us(x); +} +inline unsigned stdc_first_trailing_one(unsigned x) { + return stdc_first_trailing_one_ui(x); +} +inline unsigned stdc_first_trailing_one(unsigned long x) { + return stdc_first_trailing_one_ul(x); +} +inline unsigned stdc_first_trailing_one(unsigned long long x) { + return stdc_first_trailing_one_ull(x); +} +inline unsigned stdc_count_zeros(unsigned char x) { + return stdc_count_zeros_uc(x); +} +inline unsigned stdc_count_zeros(unsigned short x) { + return stdc_count_zeros_us(x); +} +inline unsigned stdc_count_zeros(unsigned x) { return stdc_count_zeros_ui(x); } +inline unsigned stdc_count_zeros(unsigned long x) { + return stdc_count_zeros_ul(x); +} +inline unsigned stdc_count_zeros(unsigned long long x) { + return stdc_count_zeros_ull(x); +} +inline unsigned stdc_count_ones(unsigned char x) { + return stdc_count_ones_uc(x); +} +inline unsigned stdc_count_ones(unsigned short x) { + return stdc_count_ones_us(x); +} +inline unsigned stdc_count_ones(unsigned x) { return stdc_count_ones_ui(x); } +inline unsigned stdc_count_ones(unsigned long x) { + return stdc_count_ones_ul(x); +} +inline unsigned stdc_count_ones(unsigned long long x) { + return stdc_count_ones_ull(x); +} +inline bool stdc_has_single_bit(unsigned char x) { + return stdc_has_single_bit_uc(x); +} +inline bool stdc_has_single_bit(unsigned short x) { + return stdc_has_single_bit_us(x); +} +inline bool stdc_has_single_bit(unsigned x) { + return stdc_has_single_bit_ui(x); +} +inline bool stdc_has_single_bit(unsigned long x) { + return stdc_has_single_bit_ul(x); +} +inline bool stdc_has_single_bit(unsigned long long x) { + return stdc_has_single_bit_ull(x); +} +inline unsigned stdc_bit_width(unsigned char x) { return stdc_bit_width_uc(x); } +inline unsigned stdc_bit_width(unsigned short x) { + return stdc_bit_width_us(x); +} +inline unsigned stdc_bit_width(unsigned x) { return stdc_bit_width_ui(x); } +inline unsigned stdc_bit_width(unsigned long x) { return stdc_bit_width_ul(x); } +inline unsigned stdc_bit_width(unsigned long long x) { + return stdc_bit_width_ull(x); +} +inline unsigned char stdc_bit_floor(unsigned char x) { + return stdc_bit_floor_uc(x); +} +inline unsigned short stdc_bit_floor(unsigned short x) { + return stdc_bit_floor_us(x); +} +inline unsigned stdc_bit_floor(unsigned x) { return stdc_bit_floor_ui(x); } +inline unsigned long stdc_bit_floor(unsigned long x) { + return stdc_bit_floor_ul(x); +} +inline unsigned long long stdc_bit_floor(unsigned long long x) { + return stdc_bit_floor_ull(x); +} +inline unsigned char stdc_bit_ceil(unsigned char x) { + return stdc_bit_ceil_uc(x); +} +inline unsigned short stdc_bit_ceil(unsigned short x) { + return stdc_bit_ceil_us(x); +} +inline unsigned stdc_bit_ceil(unsigned x) { return stdc_bit_ceil_ui(x); } +inline unsigned long stdc_bit_ceil(unsigned long x) { + return stdc_bit_ceil_ul(x); +} +inline unsigned long long stdc_bit_ceil(unsigned long long x) { + return stdc_bit_ceil_ull(x); +} +#else +#define stdc_leading_zeros(x) \ + _Generic((x), \ + unsigned char: stdc_leading_zeros_uc, \ + unsigned short: stdc_leading_zeros_us, \ + unsigned: stdc_leading_zeros_ui, \ + unsigned long: stdc_leading_zeros_ul, \ + unsigned long long: stdc_leading_zeros_ull)(x) +#define stdc_leading_ones(x) \ + _Generic((x), \ + unsigned char: stdc_leading_ones_uc, \ + unsigned short: stdc_leading_ones_us, \ + unsigned: stdc_leading_ones_ui, \ + unsigned long: stdc_leading_ones_ul, \ + unsigned long long: stdc_leading_ones_ull)(x) +#define stdc_trailing_zeros(x) \ + _Generic((x), \ + unsigned char: stdc_trailing_zeros_uc, \ + unsigned short: stdc_trailing_zeros_us, \ + unsigned: stdc_trailing_zeros_ui, \ + unsigned long: stdc_trailing_zeros_ul, \ + unsigned long long: stdc_trailing_zeros_ull)(x) +#define stdc_trailing_ones(x) \ + _Generic((x), \ + unsigned char: stdc_trailing_ones_uc, \ + unsigned short: stdc_trailing_ones_us, \ + unsigned: stdc_trailing_ones_ui, \ + unsigned long: stdc_trailing_ones_ul, \ + unsigned long long: stdc_trailing_ones_ull)(x) +#define stdc_first_leading_zero(x) \ + _Generic((x), \ + unsigned char: stdc_first_leading_zero_uc, \ + unsigned short: stdc_first_leading_zero_us, \ + unsigned: stdc_first_leading_zero_ui, \ + unsigned long: stdc_first_leading_zero_ul, \ + unsigned long long: stdc_first_leading_zero_ull)(x) +#define stdc_first_leading_one(x) \ + _Generic((x), \ + unsigned char: stdc_first_leading_one_uc, \ + unsigned short: stdc_first_leading_one_us, \ + unsigned: stdc_first_leading_one_ui, \ + unsigned long: stdc_first_leading_one_ul, \ + unsigned long long: stdc_first_leading_one_ull)(x) +#define stdc_first_trailing_zero(x) \ + _Generic((x), \ + unsigned char: stdc_first_trailing_zero_uc, \ + unsigned short: stdc_first_trailing_zero_us, \ + unsigned: stdc_first_trailing_zero_ui, \ + unsigned long: stdc_first_trailing_zero_ul, \ + unsigned long long: stdc_first_trailing_zero_ull)(x) +#define stdc_first_trailing_one(x) \ + _Generic((x), \ + unsigned char: stdc_first_trailing_one_uc, \ + unsigned short: stdc_first_trailing_one_us, \ + unsigned: stdc_first_trailing_one_ui, \ + unsigned long: stdc_first_trailing_one_ul, \ + unsigned long long: stdc_first_trailing_one_ull)(x) +#define stdc_count_zeros(x) \ + _Generic((x), \ + unsigned char: stdc_count_zeros_uc, \ + unsigned short: stdc_count_zeros_us, \ + unsigned: stdc_count_zeros_ui, \ + unsigned long: stdc_count_zeros_ul, \ + unsigned long long: stdc_count_zeros_ull)(x) +#define stdc_count_ones(x) \ + _Generic((x), \ + unsigned char: stdc_count_ones_uc, \ + unsigned short: stdc_count_ones_us, \ + unsigned: stdc_count_ones_ui, \ + unsigned long: stdc_count_ones_ul, \ + unsigned long long: stdc_count_ones_ull)(x) +#define stdc_has_single_bit(x) \ + _Generic((x), \ + unsigned char: stdc_has_single_bit_uc, \ + unsigned short: stdc_has_single_bit_us, \ + unsigned: stdc_has_single_bit_ui, \ + unsigned long: stdc_has_single_bit_ul, \ + unsigned long long: stdc_has_single_bit_ull)(x) +#define stdc_bit_width(x) \ + _Generic((x), \ + unsigned char: stdc_bit_width_uc, \ + unsigned short: stdc_bit_width_us, \ + unsigned: stdc_bit_width_ui, \ + unsigned long: stdc_bit_width_ul, \ + unsigned long long: stdc_bit_width_ull)(x) +#define stdc_bit_floor(x) \ + _Generic((x), \ + unsigned char: stdc_bit_floor_uc, \ + unsigned short: stdc_bit_floor_us, \ + unsigned: stdc_bit_floor_ui, \ + unsigned long: stdc_bit_floor_ul, \ + unsigned long long: stdc_bit_floor_ull)(x) +#define stdc_bit_ceil(x) \ + _Generic((x), \ + unsigned char: stdc_bit_ceil_uc, \ + unsigned short: stdc_bit_ceil_us, \ + unsigned: stdc_bit_ceil_ui, \ + unsigned long: stdc_bit_ceil_ul, \ + unsigned long long: stdc_bit_ceil_ull)(x) +#endif // __cplusplus + +#endif // __LLVM_LIBC_MACROS_STDBIT_MACROS_H diff --git a/libc/include/llvm-libc-macros/stdckdint-macros.h b/libc/include/llvm-libc-macros/stdckdint-macros.h new file mode 100644 index 000000000000..17e4ccdc2d5f --- /dev/null +++ b/libc/include/llvm-libc-macros/stdckdint-macros.h @@ -0,0 +1,27 @@ +//===-- Definition of macros for stdckdint.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_STDCKDINT_MACROS_H +#define LLVM_LIBC_MACROS_STDCKDINT_MACROS_H + +// We need to use __builtin_*_overflow from GCC/Clang to implement the overflow +// macros. Check __GNUC__ or __clang__ for availability of such builtins. +// Note that clang-cl defines __clang__ only and does not define __GNUC__ so we +// have to check for both. +#if defined(__GNUC__) || defined(__clang__) +// clang/gcc overlay may provides similar macros, we need to avoid redefining +// them. +#ifndef __STDC_VERSION_STDCKDINT_H__ +#define __STDC_VERSION_STDCKDINT_H__ 202311L + +#define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R)) +#define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R)) +#define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R)) +#endif // __STDC_VERSION_STDCKDINT_H__ +#endif // __GNUC__ +#endif // LLVM_LIBC_MACROS_STDCKDINT_MACROS_H diff --git a/libc/include/llvm-libc-macros/stdfix-macros.h b/libc/include/llvm-libc-macros/stdfix-macros.h new file mode 100644 index 000000000000..04097e14e974 --- /dev/null +++ b/libc/include/llvm-libc-macros/stdfix-macros.h @@ -0,0 +1,367 @@ +//===-- Definitions from stdfix.h -----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_STDFIX_MACROS_H +#define LLVM_LIBC_MACROS_STDFIX_MACROS_H + +#ifdef __FRACT_FBIT__ +// _Fract and _Accum types are available +#define LIBC_COMPILER_HAS_FIXED_POINT +#endif // __FRACT_FBIT__ + +#ifdef LIBC_COMPILER_HAS_FIXED_POINT + +#define fract _Fract +#define accum _Accum +#define sat _Sat + +// Default values: from ISO/IEC TR 18037:2008 standard - Annex A.3 - Typical +// desktop processor. + +#ifdef __SFRACT_FBIT__ +#define SFRACT_FBIT __SFRACT_FBIT__ +#else +#define SFRACT_FBIT 7 +#endif // SFRACT_FBIT + +#ifdef __SFRACT_MIN__ +#define SFRACT_MIN __SFRACT_MIN__ +#else +#define SFRACT_MIN (-0.5HR - 0.5HR) +#endif // SFRACT_MIN + +#ifdef __SFRACT_MAX__ +#define SFRACT_MAX __SFRACT_MAX__ +#else +#define SFRACT_MAX 0x1.FCp-1HR +#endif // SFRACT_MAX + +#ifdef __SFRACT_EPSILON__ +#define SFRACT_EPSILON __SFRACT_EPSILON__ +#else +#define SFRACT_EPSILON 0x1.0p-7HR +#endif // SFRACT_EPSILON + +#ifdef __USFRACT_FBIT__ +#define USFRACT_FBIT __USFRACT_FBIT__ +#else +#define USFRACT_FBIT 8 +#endif // USFRACT_FBIT + +#define USFRACT_MIN 0.0UHR + +#ifdef __USFRACT_MAX__ +#define USFRACT_MAX __USFRACT_MAX__ +#else +#define USFRACT_MAX 0x1.FEp-1UHR +#endif // USFRACT_MAX + +#ifdef __USFRACT_EPSILON__ +#define USFRACT_EPSILON __USFRACT_EPSILON__ +#else +#define USFRACT_EPSILON 0x1.0p-8UHR +#endif // USFRACT_EPSILON + +#ifdef __FRACT_FBIT__ +#define FRACT_FBIT __FRACT_FBIT__ +#else +#define FRACT_FBIT 15 +#endif // FRACT_FBIT + +#ifdef __FRACT_MIN__ +#define FRACT_MIN __FRACT_MIN__ +#else +#define FRACT_MIN (-0.5R - 0.5R) +#endif // FRACT_MIN + +#ifdef __FRACT_MAX__ +#define FRACT_MAX __FRACT_MAX__ +#else +#define FRACT_MAX 0x1.FFFCp-1R +#endif // FRACT_MAX + +#ifdef __FRACT_EPSILON__ +#define FRACT_EPSILON __FRACT_EPSILON__ +#else +#define FRACT_EPSILON 0x1.0p-15R +#endif // FRACT_EPSILON + +#ifdef __UFRACT_FBIT__ +#define UFRACT_FBIT __UFRACT_FBIT__ +#else +#define UFRACT_FBIT 16 +#endif // UFRACT_FBIT + +#define UFRACT_MIN 0.0UR + +#ifdef __UFRACT_MAX__ +#define UFRACT_MAX __UFRACT_MAX__ +#else +#define UFRACT_MAX 0x1.FFFEp-1UR +#endif // UFRACT_MAX + +#ifdef __UFRACT_EPSILON__ +#define UFRACT_EPSILON __UFRACT_EPSILON__ +#else +#define UFRACT_EPSILON 0x1.0p-16UR +#endif // UFRACT_EPSILON + +#ifdef __LFRACT_FBIT__ +#define LFRACT_FBIT __LFRACT_FBIT__ +#else +#define LFRACT_FBIT 31 +#endif // LFRACT_FBIT + +#ifdef __LFRACT_MIN__ +#define LFRACT_MIN __LFRACT_MIN__ +#else +#define LFRACT_MIN (-0.5LR - 0.5LR) +#endif // LFRACT_MIN + +#ifdef __LFRACT_MAX__ +#define LFRACT_MAX __LFRACT_MAX__ +#else +#define LFRACT_MAX 0x1.FFFFFFFCp-1LR +#endif // LFRACT_MAX + +#ifdef __LFRACT_EPSILON__ +#define LFRACT_EPSILON __LFRACT_EPSILON__ +#else +#define LFRACT_EPSILON 0x1.0p-31LR +#endif // LFRACT_EPSILON + +#ifdef __ULFRACT_FBIT__ +#define ULFRACT_FBIT __ULFRACT_FBIT__ +#else +#define ULFRACT_FBIT 32 +#endif // ULFRACT_FBIT + +#define ULFRACT_MIN 0.0ULR + +#ifdef __ULFRACT_MAX__ +#define ULFRACT_MAX __ULFRACT_MAX__ +#else +#define ULFRACT_MAX 0x1.FFFFFFFEp-1ULR +#endif // ULFRACT_MAX + +#ifdef __ULFRACT_EPSILON__ +#define ULFRACT_EPSILON __ULFRACT_EPSILON__ +#else +#define ULFRACT_EPSILON 0x1.0p-32ULR +#endif // ULFRACT_EPSILON + +#ifdef __SACCUM_FBIT__ +#define SACCUM_FBIT __SACCUM_FBIT__ +#else +#define SACCUM_FBIT 7 +#endif // SACCUM_FBIT + +#ifdef __SACCUM_IBIT__ +#define SACCUM_IBIT __SACCUM_IBIT__ +#else +#define SACCUM_IBIT 8 +#endif // SACCUM_IBIT + +#ifdef __SACCUM_MIN__ +#define SACCUM_MIN __SACCUM_MIN__ +#else +#define SACCUM_MIN (-0x1.0p+7HK - 0x1.0p+7HK) +#endif // SACCUM_MIN + +#ifdef __SACCUM_MAX__ +#define SACCUM_MAX __SACCUM_MAX__ +#else +#define SACCUM_MAX 0x1.FFFCp+7HK +#endif // SACCUM_MAX + +#ifdef __SACCUM_EPSILON__ +#define SACCUM_EPSILON __SACCUM_EPSILON__ +#else +#define SACCUM_EPSILON 0x1.0p-7HK +#endif // SACCUM_EPSILON + +#ifdef __USACCUM_FBIT__ +#define USACCUM_FBIT __USACCUM_FBIT__ +#else +#define USACCUM_FBIT 8 +#endif // USACCUM_FBIT + +#ifdef __USACCUM_IBIT__ +#define USACCUM_IBIT __USACCUM_IBIT__ +#else +#define USACCUM_IBIT 8 +#endif // USACCUM_IBIT + +#define USACCUM_MIN 0.0UHK + +#ifdef __USACCUM_MAX__ +#define USACCUM_MAX __USACCUM_MAX__ +#else +#define USACCUM_MAX 0x1.FFFEp+7UHK +#endif // USACCUM_MAX + +#ifdef __USACCUM_EPSILON__ +#define USACCUM_EPSILON __USACCUM_EPSILON__ +#else +#define USACCUM_EPSILON 0x1.0p-8UHK +#endif // USACCUM_EPSILON + +#ifdef __ACCUM_FBIT__ +#define ACCUM_FBIT __ACCUM_FBIT__ +#else +#define ACCUM_FBIT 15 +#endif // ACCUM_FBIT + +#ifdef __ACCUM_IBIT__ +#define ACCUM_IBIT __ACCUM_IBIT__ +#else +#define ACCUM_IBIT 16 +#endif // ACCUM_IBIT + +#ifdef __ACCUM_MIN__ +#define ACCUM_MIN __ACCUM_MIN__ +#else +#define ACCUM_MIN (-0x1.0p+15K - 0x1.0p+15K) +#endif // ACCUM_MIN + +#ifdef __ACCUM_MAX__ +#define ACCUM_MAX __ACCUM_MAX__ +#else +#define ACCUM_MAX 0x1.FFFFFFFCp+15K +#endif // ACCUM_MAX + +#ifdef __ACCUM_EPSILON__ +#define ACCUM_EPSILON __ACCUM_EPSILON__ +#else +#define ACCUM_EPSILON 0x1.0p-15K +#endif // ACCUM_EPSILON + +#ifdef __UACCUM_FBIT__ +#define UACCUM_FBIT __UACCUM_FBIT__ +#else +#define UACCUM_FBIT 16 +#endif // UACCUM_FBIT + +#ifdef __UACCUM_IBIT__ +#define UACCUM_IBIT __UACCUM_IBIT__ +#else +#define UACCUM_IBIT 16 +#endif // UACCUM_IBIT + +#define UACCUM_MIN 0.0UK + +#ifdef __UACCUM_MAX__ +#define UACCUM_MAX __UACCUM_MAX__ +#else +#define UACCUM_MAX 0x1.FFFFFFFEp+15UK +#endif // UACCUM_MAX + +#ifdef __UACCUM_EPSILON__ +#define UACCUM_EPSILON __UACCUM_EPSILON__ +#else +#define UACCUM_EPSILON 0x1.0p-16UK +#endif // UACCUM_EPSILON + +#ifdef __LACCUM_FBIT__ +#define LACCUM_FBIT __LACCUM_FBIT__ +#else +#define LACCUM_FBIT 31 +#endif // LACCUM_FBIT + +#ifdef __LACCUM_IBIT__ +#define LACCUM_IBIT __LACCUM_IBIT__ +#else +#define LACCUM_IBIT 32 +#endif // LACCUM_IBIT + +#ifdef __LACCUM_MIN__ +#define LACCUM_MIN __LACCUM_MIN__ +#else +#define LACCUM_MIN (-0x1.0p+31LK - 0x1.0p+31LK) +#endif // LACCUM_MIN + +#ifdef __LACCUM_MAX__ +#define LACCUM_MAX __LACCUM_MAX__ +#else +#define LACCUM_MAX 0x1.FFFFFFFFFFFFFFFCp+31LK +#endif // LACCUM_MAX + +#ifdef __LACCUM_EPSILON__ +#define LACCUM_EPSILON __LACCUM_EPSILON__ +#else +#define LACCUM_EPSILON 0x1.0p-31LK +#endif // LACCUM_EPSILON + +#ifdef __ULACCUM_FBIT__ +#define ULACCUM_FBIT __ULACCUM_FBIT__ +#else +#define ULACCUM_FBIT 32 +#endif // ULACCUM_FBIT + +#ifdef __ULACCUM_IBIT__ +#define ULACCUM_IBIT __ULACCUM_IBIT__ +#else +#define ULACCUM_IBIT 32 +#endif // ULACCUM_IBIT + +#define ULACCUM_MIN 0.0ULK + +#ifdef __ULACCUM_MAX__ +#define ULACCUM_MAX __ULACCUM_MAX__ +#else +#define ULACCUM_MAX 0x1.FFFFFFFFFFFFFFFEp+31ULK +#endif // ULACCUM_MAX + +#ifdef __ULACCUM_EPSILON__ +#define ULACCUM_EPSILON __ULACCUM_EPSILON__ +#else +#define ULACCUM_EPSILON 0x1.0p-32ULK +#endif // ULACCUM_EPSILON + +#define absfx(x) \ + _Generic((x), \ + fract: absr, \ + short fract: abshr, \ + long fract: abslr, \ + accum: absk, \ + short accum: abshk, \ + long accum: abslk)(x) + +#define countlsfx(x) \ + _Generic((x), \ + fract: countlsr, \ + short fract: countlshr, \ + long fract: countlslr, \ + accum: countlsk, \ + short accum: countlshk, \ + long accum: countlslk, \ + unsigned fract: countlsur, \ + unsigned short fract: countlsuhr, \ + unsigned long fract: countlsulr, \ + unsigned accum: countlsuk, \ + unsigned short accum: countlsuhk, \ + unsigned long accum: countlsulk)(x) + +#define roundfx(x, y) \ + _Generic((x), \ + fract: roundr, \ + short fract: roundhr, \ + long fract: roundlr, \ + accum: roundk, \ + short accum: roundhk, \ + long accum: roundlk, \ + unsigned fract: roundur, \ + unsigned short fract: rounduhr, \ + unsigned long fract: roundulr, \ + unsigned accum: rounduk, \ + unsigned short accum: rounduhk, \ + unsigned long accum: roundulk)(x, y) + +#endif // LIBC_COMPILER_HAS_FIXED_POINT + +#endif // LLVM_LIBC_MACROS_STDFIX_MACROS_H diff --git a/libc/include/llvm-libc-macros/stdint-macros.h b/libc/include/llvm-libc-macros/stdint-macros.h new file mode 100644 index 000000000000..1d5da2b783b6 --- /dev/null +++ b/libc/include/llvm-libc-macros/stdint-macros.h @@ -0,0 +1,878 @@ +//===-- Definition of macros from stdint.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_STDINT_MACROS_H +#define LLVM_LIBC_MACROS_STDINT_MACROS_H + +// These definitions are copied directly from the clang implementation located +// at 'clang/lib/Headers/stdint.h'. We provide it here again for compatibility. + +/* C99 7.18.1.1 Exact-width integer types. + * C99 7.18.1.2 Minimum-width integer types. + * C99 7.18.1.3 Fastest minimum-width integer types. + * + * The standard requires that exact-width type be defined for 8-, 16-, 32-, and + * 64-bit types if they are implemented. Other exact width types are optional. + * This implementation defines an exact-width types for every integer width + * that is represented in the standard integer types. + * + * The standard also requires minimum-width types be defined for 8-, 16-, 32-, + * and 64-bit widths regardless of whether there are corresponding exact-width + * types. + * + * To accommodate targets that are missing types that are exactly 8, 16, 32, or + * 64 bits wide, this implementation takes an approach of cascading + * redefinitions, redefining __int_leastN_t to successively smaller exact-width + * types. It is therefore important that the types are defined in order of + * descending widths. + * + * We currently assume that the minimum-width types and the fastest + * minimum-width types are the same. This is allowed by the standard, but is + * suboptimal. + * + * In violation of the standard, some targets do not implement a type that is + * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit). + * To accommodate these targets, a required minimum-width type is only + * defined if there exists an exact-width type of equal or greater width. + */ + +#ifdef __INT64_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/ +typedef __INT64_TYPE__ int64_t; +#endif /* __int8_t_defined */ +typedef __UINT64_TYPE__ uint64_t; +#undef __int_least64_t +#define __int_least64_t int64_t +#undef __uint_least64_t +#define __uint_least64_t uint64_t +#undef __int_least32_t +#define __int_least32_t int64_t +#undef __uint_least32_t +#define __uint_least32_t uint64_t +#undef __int_least16_t +#define __int_least16_t int64_t +#undef __uint_least16_t +#define __uint_least16_t uint64_t +#undef __int_least8_t +#define __int_least8_t int64_t +#undef __uint_least8_t +#define __uint_least8_t uint64_t +#endif /* __INT64_TYPE__ */ + +#ifdef __int_least64_t +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; +typedef __int_least64_t int_fast64_t; +typedef __uint_least64_t uint_fast64_t; +#endif /* __int_least64_t */ + +#ifdef __INT56_TYPE__ +typedef __INT56_TYPE__ int56_t; +typedef __UINT56_TYPE__ uint56_t; +typedef int56_t int_least56_t; +typedef uint56_t uint_least56_t; +typedef int56_t int_fast56_t; +typedef uint56_t uint_fast56_t; +#undef __int_least32_t +#define __int_least32_t int56_t +#undef __uint_least32_t +#define __uint_least32_t uint56_t +#undef __int_least16_t +#define __int_least16_t int56_t +#undef __uint_least16_t +#define __uint_least16_t uint56_t +#undef __int_least8_t +#define __int_least8_t int56_t +#undef __uint_least8_t +#define __uint_least8_t uint56_t +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +typedef __INT48_TYPE__ int48_t; +typedef __UINT48_TYPE__ uint48_t; +typedef int48_t int_least48_t; +typedef uint48_t uint_least48_t; +typedef int48_t int_fast48_t; +typedef uint48_t uint_fast48_t; +#undef __int_least32_t +#define __int_least32_t int48_t +#undef __uint_least32_t +#define __uint_least32_t uint48_t +#undef __int_least16_t +#define __int_least16_t int48_t +#undef __uint_least16_t +#define __uint_least16_t uint48_t +#undef __int_least8_t +#define __int_least8_t int48_t +#undef __uint_least8_t +#define __uint_least8_t uint48_t +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +typedef __INT40_TYPE__ int40_t; +typedef __UINT40_TYPE__ uint40_t; +typedef int40_t int_least40_t; +typedef uint40_t uint_least40_t; +typedef int40_t int_fast40_t; +typedef uint40_t uint_fast40_t; +#undef __int_least32_t +#define __int_least32_t int40_t +#undef __uint_least32_t +#define __uint_least32_t uint40_t +#undef __int_least16_t +#define __int_least16_t int40_t +#undef __uint_least16_t +#define __uint_least16_t uint40_t +#undef __int_least8_t +#define __int_least8_t int40_t +#undef __uint_least8_t +#define __uint_least8_t uint40_t +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ + +#ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/ +typedef __INT32_TYPE__ int32_t; +#endif /* __int8_t_defined */ + +#ifndef __uint32_t_defined /* more glibc compatibility */ +#define __uint32_t_defined +typedef __UINT32_TYPE__ uint32_t; +#endif /* __uint32_t_defined */ + +#undef __int_least32_t +#define __int_least32_t int32_t +#undef __uint_least32_t +#define __uint_least32_t uint32_t +#undef __int_least16_t +#define __int_least16_t int32_t +#undef __uint_least16_t +#define __uint_least16_t uint32_t +#undef __int_least8_t +#define __int_least8_t int32_t +#undef __uint_least8_t +#define __uint_least8_t uint32_t +#endif /* __INT32_TYPE__ */ + +#ifdef __int_least32_t +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least32_t int_fast32_t; +typedef __uint_least32_t uint_fast32_t; +#endif /* __int_least32_t */ + +#ifdef __INT24_TYPE__ +typedef __INT24_TYPE__ int24_t; +typedef __UINT24_TYPE__ uint24_t; +typedef int24_t int_least24_t; +typedef uint24_t uint_least24_t; +typedef int24_t int_fast24_t; +typedef uint24_t uint_fast24_t; +#undef __int_least16_t +#define __int_least16_t int24_t +#undef __uint_least16_t +#define __uint_least16_t uint24_t +#undef __int_least8_t +#define __int_least8_t int24_t +#undef __uint_least8_t +#define __uint_least8_t uint24_t +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/ +typedef __INT16_TYPE__ int16_t; +#endif /* __int8_t_defined */ +typedef __UINT16_TYPE__ uint16_t; +#undef __int_least16_t +#define __int_least16_t int16_t +#undef __uint_least16_t +#define __uint_least16_t uint16_t +#undef __int_least8_t +#define __int_least8_t int16_t +#undef __uint_least8_t +#define __uint_least8_t uint16_t +#endif /* __INT16_TYPE__ */ + +#ifdef __int_least16_t +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least16_t int_fast16_t; +typedef __uint_least16_t uint_fast16_t; +#endif /* __int_least16_t */ + +#ifdef __INT8_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/ +typedef __INT8_TYPE__ int8_t; +#endif /* __int8_t_defined */ +typedef __UINT8_TYPE__ uint8_t; +#undef __int_least8_t +#define __int_least8_t int8_t +#undef __uint_least8_t +#define __uint_least8_t uint8_t +#endif /* __INT8_TYPE__ */ + +#ifdef __int_least8_t +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least8_t int_fast8_t; +typedef __uint_least8_t uint_fast8_t; +#endif /* __int_least8_t */ + +/* prevent glibc sys/types.h from defining conflicting types */ +#ifndef __int8_t_defined +#define __int8_t_defined +#endif /* __int8_t_defined */ + +/* C99 7.18.1.4 Integer types capable of holding object pointers. + */ +#define __stdint_join3(a, b, c) a##b##c + +#ifndef _INTPTR_T +#ifndef __intptr_t_defined +typedef __INTPTR_TYPE__ intptr_t; +#define __intptr_t_defined +#define _INTPTR_T +#endif +#endif + +#ifndef _UINTPTR_T +typedef __UINTPTR_TYPE__ uintptr_t; +#define _UINTPTR_T +#endif + +/* C99 7.18.1.5 Greatest-width integer types. + */ +typedef __INTMAX_TYPE__ intmax_t; +typedef __UINTMAX_TYPE__ uintmax_t; + +/* C99 7.18.4 Macros for minimum-width integer constants. + * + * The standard requires that integer constant macros be defined for all the + * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width + * types are required, the corresponding integer constant macros are defined + * here. This implementation also defines minimum-width types for every other + * integer width that the target implements, so corresponding macros are + * defined below, too. + * + * These macros are defined using the same successive-shrinking approach as + * the type definitions above. It is likewise important that macros are defined + * in order of decending width. + * + * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the + * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). + */ + +#define __int_c_join(a, b) a##b +#define __int_c(v, suffix) __int_c_join(v, suffix) +#define __uint_c(v, suffix) __int_c_join(v##U, suffix) + +#ifdef __INT64_TYPE__ +#undef __int64_c_suffix +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT64_C_SUFFIX__ +#define __int64_c_suffix __INT64_C_SUFFIX__ +#define __int32_c_suffix __INT64_C_SUFFIX__ +#define __int16_c_suffix __INT64_C_SUFFIX__ +#define __int8_c_suffix __INT64_C_SUFFIX__ +#endif /* __INT64_C_SUFFIX__ */ +#endif /* __INT64_TYPE__ */ + +#ifdef __int_least64_t +#ifdef __int64_c_suffix +#define INT64_C(v) __int_c(v, __int64_c_suffix) +#define UINT64_C(v) __uint_c(v, __int64_c_suffix) +#else +#define INT64_C(v) v +#define UINT64_C(v) v##U +#endif /* __int64_c_suffix */ +#endif /* __int_least64_t */ + +#ifdef __INT56_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT56_C_SUFFIX__ +#define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__) +#define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__) +#define __int32_c_suffix __INT56_C_SUFFIX__ +#define __int16_c_suffix __INT56_C_SUFFIX__ +#define __int8_c_suffix __INT56_C_SUFFIX__ +#else +#define INT56_C(v) v +#define UINT56_C(v) v##U +#endif /* __INT56_C_SUFFIX__ */ +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT48_C_SUFFIX__ +#define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__) +#define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__) +#define __int32_c_suffix __INT48_C_SUFFIX__ +#define __int16_c_suffix __INT48_C_SUFFIX__ +#define __int8_c_suffix __INT48_C_SUFFIX__ +#else +#define INT48_C(v) v +#define UINT48_C(v) v##U +#endif /* __INT48_C_SUFFIX__ */ +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT40_C_SUFFIX__ +#define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__) +#define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__) +#define __int32_c_suffix __INT40_C_SUFFIX__ +#define __int16_c_suffix __INT40_C_SUFFIX__ +#define __int8_c_suffix __INT40_C_SUFFIX__ +#else +#define INT40_C(v) v +#define UINT40_C(v) v##U +#endif /* __INT40_C_SUFFIX__ */ +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT32_C_SUFFIX__ +#define __int32_c_suffix __INT32_C_SUFFIX__ +#define __int16_c_suffix __INT32_C_SUFFIX__ +#define __int8_c_suffix __INT32_C_SUFFIX__ +#endif /* __INT32_C_SUFFIX__ */ +#endif /* __INT32_TYPE__ */ + +#ifdef __int_least32_t +#ifdef __int32_c_suffix +#define INT32_C(v) __int_c(v, __int32_c_suffix) +#define UINT32_C(v) __uint_c(v, __int32_c_suffix) +#else +#define INT32_C(v) v +#define UINT32_C(v) v##U +#endif /* __int32_c_suffix */ +#endif /* __int_least32_t */ + +#ifdef __INT24_TYPE__ +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT24_C_SUFFIX__ +#define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__) +#define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__) +#define __int16_c_suffix __INT24_C_SUFFIX__ +#define __int8_c_suffix __INT24_C_SUFFIX__ +#else +#define INT24_C(v) v +#define UINT24_C(v) v##U +#endif /* __INT24_C_SUFFIX__ */ +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#undef __int16_c_suffix +#undef __int8_c_suffix +#ifdef __INT16_C_SUFFIX__ +#define __int16_c_suffix __INT16_C_SUFFIX__ +#define __int8_c_suffix __INT16_C_SUFFIX__ +#endif /* __INT16_C_SUFFIX__ */ +#endif /* __INT16_TYPE__ */ + +#ifdef __int_least16_t +#ifdef __int16_c_suffix +#define INT16_C(v) __int_c(v, __int16_c_suffix) +#define UINT16_C(v) __uint_c(v, __int16_c_suffix) +#else +#define INT16_C(v) v +#define UINT16_C(v) v##U +#endif /* __int16_c_suffix */ +#endif /* __int_least16_t */ + +#ifdef __INT8_TYPE__ +#undef __int8_c_suffix +#ifdef __INT8_C_SUFFIX__ +#define __int8_c_suffix __INT8_C_SUFFIX__ +#endif /* __INT8_C_SUFFIX__ */ +#endif /* __INT8_TYPE__ */ + +#ifdef __int_least8_t +#ifdef __int8_c_suffix +#define INT8_C(v) __int_c(v, __int8_c_suffix) +#define UINT8_C(v) __uint_c(v, __int8_c_suffix) +#else +#define INT8_C(v) v +#define UINT8_C(v) v##U +#endif /* __int8_c_suffix */ +#endif /* __int_least8_t */ + +/* C99 7.18.2.1 Limits of exact-width integer types. + * C99 7.18.2.2 Limits of minimum-width integer types. + * C99 7.18.2.3 Limits of fastest minimum-width integer types. + * + * The presence of limit macros are completely optional in C99. This + * implementation defines limits for all of the types (exact- and + * minimum-width) that it defines above, using the limits of the minimum-width + * type for any types that do not have exact-width representations. + * + * As in the type definitions, this section takes an approach of + * successive-shrinking to determine which limits to use for the standard (8, + * 16, 32, 64) bit widths when they don't have exact representations. It is + * therefore important that the definitions be kept in order of decending + * widths. + * + * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the + * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). + */ + +#ifdef __INT64_TYPE__ +#define INT64_MAX INT64_C(9223372036854775807) +#define INT64_MIN (-INT64_C(9223372036854775807) - 1) +#define UINT64_MAX UINT64_C(18446744073709551615) + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT64_WIDTH 64 +#define INT64_WIDTH UINT64_WIDTH + +#define __UINT_LEAST64_WIDTH UINT64_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT64_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT64_WIDTH +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT64_MAX +#endif /* __STDC_VERSION__ */ + +#define __INT_LEAST64_MIN INT64_MIN +#define __INT_LEAST64_MAX INT64_MAX +#define __UINT_LEAST64_MAX UINT64_MAX +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT64_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT64_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT64_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT64_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT64_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT64_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT64_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT64_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT64_MAX +#endif /* __INT64_TYPE__ */ + +#ifdef __INT_LEAST64_MIN +#define INT_LEAST64_MIN __INT_LEAST64_MIN +#define INT_LEAST64_MAX __INT_LEAST64_MAX +#define UINT_LEAST64_MAX __UINT_LEAST64_MAX +#define INT_FAST64_MIN __INT_LEAST64_MIN +#define INT_FAST64_MAX __INT_LEAST64_MAX +#define UINT_FAST64_MAX __UINT_LEAST64_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH +#define INT_LEAST64_WIDTH UINT_LEAST64_WIDTH +#define UINT_FAST64_WIDTH __UINT_LEAST64_WIDTH +#define INT_FAST64_WIDTH UINT_FAST64_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST64_MIN */ + +#ifdef __INT56_TYPE__ +#define INT56_MAX INT56_C(36028797018963967) +#define INT56_MIN (-INT56_C(36028797018963967) - 1) +#define UINT56_MAX UINT56_C(72057594037927935) +#define INT_LEAST56_MIN INT56_MIN +#define INT_LEAST56_MAX INT56_MAX +#define UINT_LEAST56_MAX UINT56_MAX +#define INT_FAST56_MIN INT56_MIN +#define INT_FAST56_MAX INT56_MAX +#define UINT_FAST56_MAX UINT56_MAX + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT56_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT56_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT56_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT56_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT56_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT56_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT56_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT56_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT56_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT56_WIDTH 56 +#define INT56_WIDTH UINT56_WIDTH +#define UINT_LEAST56_WIDTH UINT56_WIDTH +#define INT_LEAST56_WIDTH UINT_LEAST56_WIDTH +#define UINT_FAST56_WIDTH UINT56_WIDTH +#define INT_FAST56_WIDTH UINT_FAST56_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT56_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT56_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT56_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +#define INT48_MAX INT48_C(140737488355327) +#define INT48_MIN (-INT48_C(140737488355327) - 1) +#define UINT48_MAX UINT48_C(281474976710655) +#define INT_LEAST48_MIN INT48_MIN +#define INT_LEAST48_MAX INT48_MAX +#define UINT_LEAST48_MAX UINT48_MAX +#define INT_FAST48_MIN INT48_MIN +#define INT_FAST48_MAX INT48_MAX +#define UINT_FAST48_MAX UINT48_MAX + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT48_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT48_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT48_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT48_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT48_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT48_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT48_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT48_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT48_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT48_WIDTH 48 +#define INT48_WIDTH UINT48_WIDTH +#define UINT_LEAST48_WIDTH UINT48_WIDTH +#define INT_LEAST48_WIDTH UINT_LEAST48_WIDTH +#define UINT_FAST48_WIDTH UINT48_WIDTH +#define INT_FAST48_WIDTH UINT_FAST48_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT48_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT48_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT48_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +#define INT40_MAX INT40_C(549755813887) +#define INT40_MIN (-INT40_C(549755813887) - 1) +#define UINT40_MAX UINT40_C(1099511627775) +#define INT_LEAST40_MIN INT40_MIN +#define INT_LEAST40_MAX INT40_MAX +#define UINT_LEAST40_MAX UINT40_MAX +#define INT_FAST40_MIN INT40_MIN +#define INT_FAST40_MAX INT40_MAX +#define UINT_FAST40_MAX UINT40_MAX + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT40_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT40_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT40_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT40_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT40_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT40_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT40_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT40_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT40_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT40_WIDTH 40 +#define INT40_WIDTH UINT40_WIDTH +#define UINT_LEAST40_WIDTH UINT40_WIDTH +#define INT_LEAST40_WIDTH UINT_LEAST40_WIDTH +#define UINT_FAST40_WIDTH UINT40_WIDTH +#define INT_FAST40_WIDTH UINT_FAST40_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT40_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT40_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT40_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ +#define INT32_MAX INT32_C(2147483647) +#define INT32_MIN (-INT32_C(2147483647) - 1) +#define UINT32_MAX UINT32_C(4294967295) + +#undef __INT_LEAST32_MIN +#define __INT_LEAST32_MIN INT32_MIN +#undef __INT_LEAST32_MAX +#define __INT_LEAST32_MAX INT32_MAX +#undef __UINT_LEAST32_MAX +#define __UINT_LEAST32_MAX UINT32_MAX +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT32_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT32_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT32_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT32_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT32_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT32_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT32_WIDTH 32 +#define INT32_WIDTH UINT32_WIDTH +#undef __UINT_LEAST32_WIDTH +#define __UINT_LEAST32_WIDTH UINT32_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT32_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT32_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT32_TYPE__ */ + +#ifdef __INT_LEAST32_MIN +#define INT_LEAST32_MIN __INT_LEAST32_MIN +#define INT_LEAST32_MAX __INT_LEAST32_MAX +#define UINT_LEAST32_MAX __UINT_LEAST32_MAX +#define INT_FAST32_MIN __INT_LEAST32_MIN +#define INT_FAST32_MAX __INT_LEAST32_MAX +#define UINT_FAST32_MAX __UINT_LEAST32_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH +#define INT_LEAST32_WIDTH UINT_LEAST32_WIDTH +#define UINT_FAST32_WIDTH __UINT_LEAST32_WIDTH +#define INT_FAST32_WIDTH UINT_FAST32_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST32_MIN */ + +#ifdef __INT24_TYPE__ +#define INT24_MAX INT24_C(8388607) +#define INT24_MIN (-INT24_C(8388607) - 1) +#define UINT24_MAX UINT24_C(16777215) +#define INT_LEAST24_MIN INT24_MIN +#define INT_LEAST24_MAX INT24_MAX +#define UINT_LEAST24_MAX UINT24_MAX +#define INT_FAST24_MIN INT24_MIN +#define INT_FAST24_MAX INT24_MAX +#define UINT_FAST24_MAX UINT24_MAX + +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT24_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT24_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT24_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT24_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT24_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT24_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT24_WIDTH 24 +#define INT24_WIDTH UINT24_WIDTH +#define UINT_LEAST24_WIDTH UINT24_WIDTH +#define INT_LEAST24_WIDTH UINT_LEAST24_WIDTH +#define UINT_FAST24_WIDTH UINT24_WIDTH +#define INT_FAST24_WIDTH UINT_FAST24_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT24_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT24_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#define INT16_MAX INT16_C(32767) +#define INT16_MIN (-INT16_C(32767) - 1) +#define UINT16_MAX UINT16_C(65535) + +#undef __INT_LEAST16_MIN +#define __INT_LEAST16_MIN INT16_MIN +#undef __INT_LEAST16_MAX +#define __INT_LEAST16_MAX INT16_MAX +#undef __UINT_LEAST16_MAX +#define __UINT_LEAST16_MAX UINT16_MAX +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT16_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT16_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT16_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT16_WIDTH 16 +#define INT16_WIDTH UINT16_WIDTH +#undef __UINT_LEAST16_WIDTH +#define __UINT_LEAST16_WIDTH UINT16_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT16_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT16_TYPE__ */ + +#ifdef __INT_LEAST16_MIN +#define INT_LEAST16_MIN __INT_LEAST16_MIN +#define INT_LEAST16_MAX __INT_LEAST16_MAX +#define UINT_LEAST16_MAX __UINT_LEAST16_MAX +#define INT_FAST16_MIN __INT_LEAST16_MIN +#define INT_FAST16_MAX __INT_LEAST16_MAX +#define UINT_FAST16_MAX __UINT_LEAST16_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH +#define INT_LEAST16_WIDTH UINT_LEAST16_WIDTH +#define UINT_FAST16_WIDTH __UINT_LEAST16_WIDTH +#define INT_FAST16_WIDTH UINT_FAST16_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST16_MIN */ + +#ifdef __INT8_TYPE__ +#define INT8_MAX INT8_C(127) +#define INT8_MIN (-INT8_C(127) - 1) +#define UINT8_MAX UINT8_C(255) + +#undef __INT_LEAST8_MIN +#define __INT_LEAST8_MIN INT8_MIN +#undef __INT_LEAST8_MAX +#define __INT_LEAST8_MAX INT8_MAX +#undef __UINT_LEAST8_MAX +#define __UINT_LEAST8_MAX UINT8_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT8_WIDTH 8 +#define INT8_WIDTH UINT8_WIDTH +#undef __UINT_LEAST8_WIDTH +#define __UINT_LEAST8_WIDTH UINT8_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT8_TYPE__ */ + +#ifdef __INT_LEAST8_MIN +#define INT_LEAST8_MIN __INT_LEAST8_MIN +#define INT_LEAST8_MAX __INT_LEAST8_MAX +#define UINT_LEAST8_MAX __UINT_LEAST8_MAX +#define INT_FAST8_MIN __INT_LEAST8_MIN +#define INT_FAST8_MAX __INT_LEAST8_MAX +#define UINT_FAST8_MAX __UINT_LEAST8_MAX + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH +#define INT_LEAST8_WIDTH UINT_LEAST8_WIDTH +#define UINT_FAST8_WIDTH __UINT_LEAST8_WIDTH +#define INT_FAST8_WIDTH UINT_FAST8_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST8_MIN */ + +/* Some utility macros */ +#define __INTN_MIN(n) __stdint_join3(INT, n, _MIN) +#define __INTN_MAX(n) __stdint_join3(INT, n, _MAX) +#define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX) +#define __INTN_C(n, v) __stdint_join3(INT, n, _C(v)) +#define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v)) + +/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */ +/* C99 7.18.3 Limits of other integer types. */ + +#define INTPTR_MIN (-__INTPTR_MAX__ - 1) +#define INTPTR_MAX __INTPTR_MAX__ +#define UINTPTR_MAX __UINTPTR_MAX__ +#define PTRDIFF_MIN (-__PTRDIFF_MAX__ - 1) +#define PTRDIFF_MAX __PTRDIFF_MAX__ +#define SIZE_MAX __SIZE_MAX__ + +/* C23 7.22.2.4 Width of integer types capable of holding object pointers. */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +/* NB: The C standard requires that these be the same value, but the compiler + exposes separate internal width macros. */ +#define INTPTR_WIDTH __INTPTR_WIDTH__ +#define UINTPTR_WIDTH __UINTPTR_WIDTH__ +#endif + +/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__ + * is enabled. */ +#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 +#define RSIZE_MAX (SIZE_MAX >> 1) +#endif + +/* C99 7.18.2.5 Limits of greatest-width integer types. */ +#define INTMAX_MIN (-__INTMAX_MAX__ - 1) +#define INTMAX_MAX __INTMAX_MAX__ +#define UINTMAX_MAX __UINTMAX_MAX__ + +/* C23 7.22.2.5 Width of greatest-width integer types. */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +/* NB: The C standard requires that these be the same value, but the compiler + exposes separate internal width macros. */ +#define INTMAX_WIDTH __INTMAX_WIDTH__ +#define UINTMAX_WIDTH __UINTMAX_WIDTH__ +#endif + +/* C99 7.18.3 Limits of other integer types. */ +#define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__) +#define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__) +#ifdef __WINT_UNSIGNED__ +#define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0) +#define WINT_MAX __UINTN_MAX(__WINT_WIDTH__) +#else +#define WINT_MIN __INTN_MIN(__WINT_WIDTH__) +#define WINT_MAX __INTN_MAX(__WINT_WIDTH__) +#endif + +#ifndef WCHAR_MAX +#define WCHAR_MAX __WCHAR_MAX__ +#endif +#ifndef WCHAR_MIN +#if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__) +#define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__) +#else +#define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0) +#endif +#endif + +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__) +#define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__) + +/* C23 7.22.3.x Width of other integer types. */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__ +#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__ +#define SIZE_WIDTH __SIZE_WIDTH__ +#define WCHAR_WIDTH __WCHAR_WIDTH__ +#define WINT_WIDTH __WINT_WIDTH__ +#endif +#endif // LLVM_LIBC_MACROS_STDINT_MACROS_H diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h new file mode 100644 index 000000000000..96f0e6933ade --- /dev/null +++ b/libc/include/llvm-libc-macros/stdio-macros.h @@ -0,0 +1,58 @@ +//===-- Macros defined in stdio.h header file -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_STDIO_MACROS_H +#define LLVM_LIBC_MACROS_STDIO_MACROS_H + +#include "../llvm-libc-types/FILE.h" + +#ifdef __cplusplus +extern "C" FILE *stdin; +extern "C" FILE *stdout; +extern "C" FILE *stderr; +#else +extern FILE *stdin; +extern FILE *stdout; +extern FILE *stderr; +#endif + +#ifndef stdin +#define stdin stdin +#endif + +#ifndef stdout +#define stdout stdout +#endif + +#ifndef stderr +#define stderr stderr +#endif + +#ifndef EOF +#define EOF (-1) +#endif + +#define BUFSIZ 1024 + +#define _IONBF 2 +#define _IOLBF 1 +#define _IOFBF 0 + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#endif // LLVM_LIBC_MACROS_STDIO_MACROS_H diff --git a/libc/include/llvm-libc-macros/stdlib-macros.h b/libc/include/llvm-libc-macros/stdlib-macros.h new file mode 100644 index 000000000000..2565c76be3c5 --- /dev/null +++ b/libc/include/llvm-libc-macros/stdlib-macros.h @@ -0,0 +1,27 @@ +//===-- Definition of macros to be used with stdlib functions ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_STDLIB_MACROS_H +#define LLVM_LIBC_MACROS_STDLIB_MACROS_H + +#ifndef NULL +#define __need_NULL +#include <stddef.h> +#endif // NULL + +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 + +#ifndef MB_CUR_MAX +// We only support the "C" locale right now, so this is a constant byte. +#define MB_CUR_MAX 1 +#endif // MB_CUR_MAX + +#define RAND_MAX 2147483647 + +#endif // LLVM_LIBC_MACROS_STDLIB_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-auxv-macros.h b/libc/include/llvm-libc-macros/sys-auxv-macros.h new file mode 100644 index 000000000000..2dcaa2f1a8ee --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-auxv-macros.h @@ -0,0 +1,43 @@ +//===-- Macros defined in sys/auxv.h header file --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_AUXV_MACROS_H +#define LLVM_LIBC_MACROS_SYS_AUXV_MACROS_H + +// Macros defining the aux vector indexes. +#define AT_NULL 0 +#define AT_IGNORE 1 +#define AT_EXECFD 2 +#define AT_PHDR 3 +#define AT_PHENT 4 +#define AT_PHNUM 5 +#define AT_PAGESZ 6 +#define AT_BASE 7 +#define AT_FLAGS 8 +#define AT_ENTRY 9 +#define AT_NOTELF 10 +#define AT_UID 11 +#define AT_EUID 12 +#define AT_GID 13 +#define AT_EGID 14 +#define AT_PLATFORM 15 +#define AT_HWCAP 16 +#define AT_CLKTCK 17 + +#define AT_SECURE 23 +#define AT_BASE_PLATFORM 24 +#define AT_RANDOM 25 +#define AT_HWCAP2 26 + +#define AT_EXECFN 31 + +#ifndef AT_MINSIGSTKSZ +#define AT_MINSIGSTKSZ 51 +#endif + +#endif // LLVM_LIBC_MACROS_SYS_AUXV_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-epoll-macros.h b/libc/include/llvm-libc-macros/sys-epoll-macros.h new file mode 100644 index 000000000000..8212df252b8e --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-epoll-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/epoll.h header file -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H +#define LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H + +#ifdef __linux__ +#include "linux/sys-epoll-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-ioctl-macros.h b/libc/include/llvm-libc-macros/sys-ioctl-macros.h new file mode 100644 index 000000000000..4a5f9651231f --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-ioctl-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/ioctl.h header file -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_IOCTL_MACROS_H +#define LLVM_LIBC_MACROS_SYS_IOCTL_MACROS_H + +#ifdef __linux__ +#include "linux/sys-ioctl-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_IOCTL_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-mman-macros.h b/libc/include/llvm-libc-macros/sys-mman-macros.h new file mode 100644 index 000000000000..a6dc6d96b5b7 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-mman-macros.h @@ -0,0 +1,48 @@ +//===-- Macros defined in sys/mman.h header file --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H +#define LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H + +// Use definitions from <linux/mman.h> to dispatch arch-specific flag values. +// For example, MCL_CURRENT/MCL_FUTURE/MCL_ONFAULT are different on different +// architectures. +#if __has_include(<linux/mman.h>) +#include <linux/mman.h> +#else +#error "cannot use <sys/mman.h> without proper system headers." +#endif + +// Some posix standard flags may not be defined in system headers. +// Posix mmap flags. +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +// Posix memory advise flags. (posix_madvise) +#ifndef POSIX_MADV_NORMAL +#define POSIX_MADV_NORMAL MADV_NORMAL +#endif + +#ifndef POSIX_MADV_SEQUENTIAL +#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL +#endif + +#ifndef POSIX_MADV_RANDOM +#define POSIX_MADV_RANDOM MADV_RANDOM +#endif + +#ifndef POSIX_MADV_WILLNEED +#define POSIX_MADV_WILLNEED MADV_WILLNEED +#endif + +#ifndef POSIX_MADV_DONTNEED +#define POSIX_MADV_DONTNEED MADV_DONTNEED +#endif + +#endif // LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-queue-macros.h b/libc/include/llvm-libc-macros/sys-queue-macros.h new file mode 100644 index 000000000000..21e80f42a91d --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-queue-macros.h @@ -0,0 +1,262 @@ +//===-- Macros defined in sys/queue.h header file -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_QUEUE_MACROS_H +#define LLVM_LIBC_MACROS_SYS_QUEUE_MACROS_H + +#include "containerof-macro.h" +#include "null-macro.h" + +#ifdef __cplusplus +#define QUEUE_TYPEOF(type) type +#else +#define QUEUE_TYPEOF(type) struct type +#endif + +// Singly-linked list definitions. + +#define SLIST_HEAD(name, type) \ + struct name { \ + struct type *slh_first; \ + } + +#define SLIST_CLASS_HEAD(name, type) \ + struct name { \ + class type *slh_first; \ + } + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ + struct { \ + struct type *next; \ + } + +#define SLIST_CLASS_ENTRY(type) \ + struct { \ + class type *next; \ + } + +// Singly-linked list access methods. + +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_NEXT(elem, field) ((elem)->field.next) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST(head); (var); (var) = SLIST_NEXT(var, field)) + +#define SLIST_FOREACH_FROM(var, head, field) \ + if (!(var)) \ + (var) = SLIST_FIRST(head); \ + for (; (var); (var) = SLIST_NEXT(var, field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST(head); \ + (var) && ((tvar) = SLIST_NEXT(var, field), 1); (var) = (tvar)) + +#define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + if (!(var)) \ + (var) = SLIST_FIRST(head); \ + for (; (var) && ((tvar) = SLIST_NEXT(var, field), 1); (var) = (tvar)) + +// Singly-linked list functions. + +#define SLIST_CONCAT(head1, head2, type, field) \ + do { \ + if (SLIST_EMPTY(head1)) { \ + if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \ + SLIST_INIT(head2); \ + } else if (!SLIST_EMPTY(head2)) { \ + QUEUE_TYPEOF(type) *cur = SLIST_FIRST(head1); \ + while (SLIST_NEXT(cur, field) != NULL) \ + cur = SLIST_NEXT(cur, field); \ + SLIST_NEXT(cur, field) = SLIST_FIRST(head2); \ + SLIST_INIT(head2); \ + } \ + } while (0) + +#define SLIST_INIT(head) \ + do { \ + SLIST_FIRST(head) = NULL; \ + } while (0) + +#define SLIST_INSERT_AFTER(slistelem, elem, field) \ + do { \ + SLIST_NEXT(elem, field) = SLIST_NEXT(slistelem, field); \ + SLIST_NEXT(slistelem, field) = (elem); \ + } while (0) + +#define SLIST_INSERT_HEAD(head, elem, field) \ + do { \ + SLIST_NEXT(elem, field) = SLIST_FIRST(head); \ + SLIST_FIRST(head) = (elem); \ + } while (0) + +#define SLIST_REMOVE(head, elem, type, field) \ + do { \ + if (SLIST_FIRST(head) == (elem)) { \ + SLIST_REMOVE_HEAD(head, field); \ + } else { \ + QUEUE_TYPEOF(type) *cur = SLIST_FIRST(head); \ + while (SLIST_NEXT(cur, field) != (elem)) \ + cur = SLIST_NEXT(cur, field); \ + SLIST_REMOVE_AFTER(cur, field); \ + } \ + } while (0) + +#define SLIST_REMOVE_AFTER(elem, field) \ + do { \ + SLIST_NEXT(elem, field) = SLIST_NEXT(SLIST_NEXT(elem, field), field); \ + } while (0) + +#define SLIST_REMOVE_HEAD(head, field) \ + do { \ + SLIST_FIRST(head) = SLIST_NEXT(SLIST_FIRST(head), field); \ + } while (0) + +#define SLIST_SWAP(head1, head2, type) \ + do { \ + QUEUE_TYPEOF(type) *first = SLIST_FIRST(head1); \ + SLIST_FIRST(head1) = SLIST_FIRST(head2); \ + SLIST_FIRST(head2) = first; \ + } while (0) + +// Singly-linked tail queue definitions. + +#define STAILQ_HEAD(name, type) \ + struct name { \ + struct type *stqh_first; \ + struct type **stqh_last; \ + } + +#define STAILQ_CLASS_HEAD(name, type) \ + struct name { \ + class type *stqh_first; \ + class type **stqh_last; \ + } + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ + struct { \ + struct type *next; \ + } + +#define STAILQ_CLASS_ENTRY(type) \ + struct { \ + class type *next; \ + } + +// Singly-linked tail queue access methods. + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) +#define STAILQ_FIRST(head) ((head)->stqh_first) +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY(head) \ + ? NULL \ + : __containerof((head)->stqh_last, QUEUE_TYPEOF(type), field.next)) +#define STAILQ_NEXT(elem, field) ((elem)->field.next) + +#define STAILQ_FOREACH(var, head, field) \ + for ((var) = STAILQ_FIRST(head); (var); (var) = STAILQ_NEXT(var, field)) + +#define STAILQ_FOREACH_FROM(var, head, field) \ + if (!(var)) \ + (var) = STAILQ_FIRST(head); \ + for (; (var); (var) = STAILQ_NEXT(var, field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST(head); \ + (var) && ((tvar) = STAILQ_NEXT(var, field), 1); (var) = (tvar)) + +#define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + if (!(var)) \ + (var) = STAILQ_FIRST(head); \ + for (; (var) && ((tvar) = STAILQ_NEXT(var, field), 1); (var) = (tvar)) + +// Singly-linked tail queue functions. + +#define STAILQ_CONCAT(head1, head2, type, field) \ + do { \ + if (!STAILQ_EMPTY(head2)) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT(head2); \ + } \ + } while (0) + +#define STAILQ_INIT(head) \ + do { \ + STAILQ_FIRST(head) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST(head); \ + } while (0) + +#define STAILQ_INSERT_AFTER(head, listelem, elem, field) \ + do { \ + if ((STAILQ_NEXT(elem, field) = STAILQ_NEXT(listelem, field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT(elem, field); \ + STAILQ_NEXT(listelem, field) = (elem); \ + } while (0) + +#define STAILQ_INSERT_HEAD(head, elem, field) \ + do { \ + if ((STAILQ_NEXT(elem, field) = STAILQ_FIRST(head)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT(elem, field); \ + STAILQ_FIRST(head) = (elem); \ + } while (0) + +#define STAILQ_INSERT_TAIL(head, elem, field) \ + do { \ + STAILQ_NEXT(elem, field) = NULL; \ + *(head)->stqh_last = (elem); \ + (head)->stqh_last = &STAILQ_NEXT(elem, field); \ + } while (0) + +#define STAILQ_REMOVE(head, elem, type, field) \ + do { \ + if (STAILQ_FIRST(head) == (elem)) { \ + STAILQ_REMOVE_HEAD(head, field); \ + } else { \ + QUEUE_TYPEOF(type) *cur = STAILQ_FIRST(head); \ + while (STAILQ_NEXT(cur, field) != (elem)) \ + cur = STAILQ_NEXT(cur, field); \ + STAILQ_REMOVE_AFTER(head, cur, field); \ + } \ + } while (0) + +#define STAILQ_REMOVE_AFTER(head, elem, field) \ + do { \ + if ((STAILQ_NEXT(elem, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elem, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT(elem, field); \ + } while (0) + +#define STAILQ_REMOVE_HEAD(head, field) \ + do { \ + if ((STAILQ_FIRST(head) = STAILQ_NEXT(STAILQ_FIRST(head), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST(head); \ + } while (0) + +#define STAILQ_SWAP(head1, head2, type) \ + do { \ + QUEUE_TYPEOF(type) *first = STAILQ_FIRST(head1); \ + QUEUE_TYPEOF(type) **last = (head1)->stqh_last; \ + STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_FIRST(head2) = first; \ + (head2)->stqh_last = last; \ + if (STAILQ_EMPTY(head1)) \ + (head1)->stqh_last = &STAILQ_FIRST(head1); \ + if (STAILQ_EMPTY(head2)) \ + (head2)->stqh_last = &STAILQ_FIRST(head2); \ + } while (0) + +#endif // LLVM_LIBC_MACROS_SYS_QUEUE_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-random-macros.h b/libc/include/llvm-libc-macros/sys-random-macros.h new file mode 100644 index 000000000000..9b1a8edb4f79 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-random-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/random.h header file ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_RANDOM_MACROS_H +#define LLVM_LIBC_MACROS_SYS_RANDOM_MACROS_H + +#ifdef __linux__ +#include "linux/sys-random-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_RANDOM_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-resource-macros.h b/libc/include/llvm-libc-macros/sys-resource-macros.h new file mode 100644 index 000000000000..1ce01cdd1e83 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-resource-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/resource.h header file ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_RESOURCE_MACROS_H +#define LLVM_LIBC_MACROS_SYS_RESOURCE_MACROS_H + +#ifdef __linux__ +#include "linux/sys-resource-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_RESOURCE_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-select-macros.h b/libc/include/llvm-libc-macros/sys-select-macros.h new file mode 100644 index 000000000000..d54e5300d12e --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-select-macros.h @@ -0,0 +1,35 @@ +//===-- Macros defined in sys/select.h header file ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_SELECT_MACROS_H +#define LLVM_LIBC_MACROS_SYS_SELECT_MACROS_H + +#define FD_SETSIZE 1024 +#define __FD_SET_WORD_TYPE unsigned long +#define __FD_SET_WORD_SIZE (sizeof(__FD_SET_WORD_TYPE) * 8) +#define __FD_SET_ARRAYSIZE (FD_SETSIZE / __FD_SET_WORD_SIZE) + +#define FD_ZERO(set) \ + do { \ + unsigned i; \ + for (i = 0; i < __FD_SET_ARRAYSIZE; ++i) \ + (set)->__set[i] = 0; \ + } while (0) + +#define __FD_WORD(fd) ((fd) / __FD_SET_WORD_SIZE) +#define __FD_MASK(fd) \ + ((__FD_SET_WORD_TYPE)1) << ((__FD_SET_WORD_TYPE)((fd) % __FD_SET_WORD_SIZE)) + +#define FD_CLR(fd, set) (void)((set)->__set[__FD_WORD(fd)] &= ~__FD_MASK(fd)) + +#define FD_SET(fd, set) (void)((set)->__set[__FD_WORD(fd)] |= __FD_MASK(fd)) + +#define FD_ISSET(fd, set) \ + (int)(((set)->__set[__FD_WORD(fd)] & __FD_MASK(fd)) != 0) + +#endif // LLVM_LIBC_MACROS_SYS_SELECT_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-socket-macros.h b/libc/include/llvm-libc-macros/sys-socket-macros.h new file mode 100644 index 000000000000..6b1d28070b43 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-socket-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/socket.h header file ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_SOCKET_MACROS_H +#define LLVM_LIBC_MACROS_SYS_SOCKET_MACROS_H + +#ifdef __linux__ +#include "linux/sys-socket-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_SOCKET_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-stat-macros.h b/libc/include/llvm-libc-macros/sys-stat-macros.h new file mode 100644 index 000000000000..c47c9612705e --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-stat-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/stat.h header file --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_STAT_MACROS_H +#define LLVM_LIBC_MACROS_SYS_STAT_MACROS_H + +#ifdef __linux__ +#include "linux/sys-stat-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_STAT_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-time-macros.h b/libc/include/llvm-libc-macros/sys-time-macros.h new file mode 100644 index 000000000000..36d7d5adafc9 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-time-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/time.h header file --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_TIME_MACROS_H +#define LLVM_LIBC_MACROS_SYS_TIME_MACROS_H + +#ifdef __linux__ +#include "linux/sys-time-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-wait-macros.h b/libc/include/llvm-libc-macros/sys-wait-macros.h new file mode 100644 index 000000000000..c418a7930b69 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-wait-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/wait.h header file --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_WAIT_MACROS_H +#define LLVM_LIBC_MACROS_SYS_WAIT_MACROS_H + +#ifdef __linux__ +#include "linux/sys-wait-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_WAIT_MACROS_H diff --git a/libc/include/llvm-libc-macros/sysexits-macros.h b/libc/include/llvm-libc-macros/sysexits-macros.h new file mode 100644 index 000000000000..52f838788632 --- /dev/null +++ b/libc/include/llvm-libc-macros/sysexits-macros.h @@ -0,0 +1,29 @@ +//===-- Macros defined in sysexits.h header file --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef SYSEXITS_MACROS_H +#define SYSEXITS_MACROS_H + +#define EX_OK 0 // Successful termination +#define EX_USAGE 64 // Command line usage error +#define EX_DATAERR 65 // Data format error +#define EX_NOINPUT 66 // Cannot open input +#define EX_NOUSER 67 // Addressee unknown +#define EX_NOHOST 68 // Host name unknown +#define EX_UNAVAILABLE 69 // Service unavailable +#define EX_SOFTWARE 70 // Internal software error +#define EX_OSERR 71 // Operating system error +#define EX_OSFILE 72 // System file error +#define EX_CANTCREAT 73 // Cannot create (user) output file +#define EX_IOERR 74 // Input/output error +#define EX_TEMPFAIL 75 // Temporary failure, try again +#define EX_PROTOCOL 76 // Remote protocol error +#define EX_NOPERM 77 // Permission denied +#define EX_CONFIG 78 // Configuration error + +#endif // SYSEXITS_MACROS_H diff --git a/libc/include/llvm-libc-macros/termios-macros.h b/libc/include/llvm-libc-macros/termios-macros.h new file mode 100644 index 000000000000..1067e8a57474 --- /dev/null +++ b/libc/include/llvm-libc-macros/termios-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in termios.h header file ---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_TERMIOS_MACROS_H +#define LLVM_LIBC_MACROS_TERMIOS_MACROS_H + +#ifdef __linux__ +#include "linux/termios-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_TERMIOS_MACROS_H diff --git a/libc/include/llvm-libc-macros/time-macros.h b/libc/include/llvm-libc-macros/time-macros.h new file mode 100644 index 000000000000..30e0a310a548 --- /dev/null +++ b/libc/include/llvm-libc-macros/time-macros.h @@ -0,0 +1,21 @@ +#ifndef LLVM_LIBC_MACROS_TIME_MACROS_H +#define LLVM_LIBC_MACROS_TIME_MACROS_H + +#if defined(__AMDGPU__) || defined(__NVPTX__) +#include "gpu/time-macros.h" +#elif defined(__linux__) +#include "linux/time-macros.h" +#elif defined(__ELF__) +#include "baremetal/time-macros.h" +#else +#define CLOCKS_PER_SEC 1000000 +#endif + +#define CLK_TCK CLOCKS_PER_SEC + +#define TIME_UTC 1 +#define TIME_MONOTONIC 2 +#define TIME_ACTIVE 3 +#define TIME_THREAD_ACTIVE 4 + +#endif // LLVM_LIBC_MACROS_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/unistd-macros.h b/libc/include/llvm-libc-macros/unistd-macros.h new file mode 100644 index 000000000000..e09dada04a19 --- /dev/null +++ b/libc/include/llvm-libc-macros/unistd-macros.h @@ -0,0 +1,12 @@ +#ifndef LLVM_LIBC_MACROS_UNISTD_MACROS_H +#define LLVM_LIBC_MACROS_UNISTD_MACROS_H + +#ifdef __linux__ +#include "linux/unistd-macros.h" +#endif + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +#endif // LLVM_LIBC_MACROS_UNISTD_MACROS_H diff --git a/libc/include/llvm-libc-macros/wchar-macros.h b/libc/include/llvm-libc-macros/wchar-macros.h new file mode 100644 index 000000000000..2a0cabd6133a --- /dev/null +++ b/libc/include/llvm-libc-macros/wchar-macros.h @@ -0,0 +1,18 @@ +//===-- Macros defined in wchar.h header file -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_WCHAR_MACROS_H +#define LLVM_LIBC_MACROS_WCHAR_MACROS_H + +#include "../llvm-libc-types/wint_t.h" + +#ifndef WEOF +#define WEOF ((wint_t)(0xffffffffu)) +#endif + +#endif // LLVM_LIBC_MACROS_WCHAR_MACROS_H diff --git a/libc/include/llvm-libc-macros/windows/time-macros-ext.h b/libc/include/llvm-libc-macros/windows/time-macros-ext.h new file mode 100644 index 000000000000..71d914b45187 --- /dev/null +++ b/libc/include/llvm-libc-macros/windows/time-macros-ext.h @@ -0,0 +1,17 @@ +//===-- Windows Time Macros Extension -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_WINDOWS_TIME_MACROS_EXT_H +#define LLVM_LIBC_MACROS_WINDOWS_TIME_MACROS_EXT_H + +#define CLOCK_MONOTONIC 0 +#define CLOCK_REALTIME 1 +#define CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOCK_THREAD_CPUTIME_ID 3 + +#endif // LLVM_LIBC_MACROS_WINDOWS_TIME_MACROS_EXT_H |
