diff options
Diffstat (limited to 'libc/include')
221 files changed, 8337 insertions, 0 deletions
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h new file mode 100644 index 000000000000..c6fd33a55532 --- /dev/null +++ b/libc/include/__llvm-libc-common.h @@ -0,0 +1,98 @@ +//===-- Common definitions for LLVM-libc public header files --------------===// +// +// 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_COMMON_H +#define _LLVM_LIBC_COMMON_H + +#define __LLVM_LIBC__ 1 + +#ifdef __cplusplus + +#undef __BEGIN_C_DECLS +#define __BEGIN_C_DECLS extern "C" { + +#undef __END_C_DECLS +#define __END_C_DECLS } + +// Standard C++ doesn't have C99 restrict but GNU C++ has it with __ spelling. +#undef __restrict +#ifndef __GNUC__ +#define __restrict +#endif + +#undef _Noreturn +#define _Noreturn [[noreturn]] + +#undef _Alignas +#define _Alignas alignas + +#undef _Static_assert +#define _Static_assert static_assert + +#undef _Alignof +#define _Alignof alignof + +#undef _Thread_local +#define _Thread_local thread_local + +#undef __NOEXCEPT +#if __cplusplus >= 201103L +#define __NOEXCEPT noexcept +#else +#define __NOEXCEPT throw() +#endif + +// This macro serves as a generic cast implementation for use in both C and C++, +// similar to `__BIONIC_CAST` in Android. +#undef __LLVM_LIBC_CAST +#define __LLVM_LIBC_CAST(cast, type, value) (cast<type>(value)) + +#else // not __cplusplus + +#undef __BEGIN_C_DECLS +#define __BEGIN_C_DECLS + +#undef __END_C_DECLS +#define __END_C_DECLS + +#undef __restrict +#if __STDC_VERSION__ >= 199901L +// C99 and above support the restrict keyword. +#define __restrict restrict +#elif !defined(__GNUC__) +// GNU-compatible compilers accept the __ spelling in all modes. +// Otherwise, omit the qualifier for pure C89 compatibility. +#define __restrict +#endif + +#undef _Noreturn +#if __STDC_VERSION__ >= 201112L +// In C11 and later, _Noreturn is a keyword. +#elif defined(__GNUC__) +// GNU-compatible compilers have an equivalent attribute. +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + +#undef __NOEXCEPT +#ifdef __GNUC__ +#define __NOEXCEPT __attribute__((__nothrow__)) +#else +#define __NOEXCEPT +#endif + +#undef _Returns_twice +#define _Returns_twice __attribute__((returns_twice)) + +#undef __LLVM_LIBC_CAST +#define __LLVM_LIBC_CAST(cast, type, value) ((type)(value)) + +#endif // __cplusplus + +#endif // _LLVM_LIBC_COMMON_H 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 diff --git a/libc/include/llvm-libc-types/ACTION.h b/libc/include/llvm-libc-types/ACTION.h new file mode 100644 index 000000000000..1ddce208df1c --- /dev/null +++ b/libc/include/llvm-libc-types/ACTION.h @@ -0,0 +1,14 @@ +//===-- Definition of ACTION 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_TYPES_ACTION_H +#define LLVM_LIBC_TYPES_ACTION_H + +typedef enum { FIND, ENTER } ACTION; + +#endif // LLVM_LIBC_TYPES_ACTION_H diff --git a/libc/include/llvm-libc-types/DIR.h b/libc/include/llvm-libc-types/DIR.h new file mode 100644 index 000000000000..855446db6f53 --- /dev/null +++ b/libc/include/llvm-libc-types/DIR.h @@ -0,0 +1,14 @@ +//===-- Definition of the type DIR ----------------------------------------===// +// +// 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_TYPES_DIR_H +#define LLVM_LIBC_TYPES_DIR_H + +typedef struct DIR DIR; + +#endif // LLVM_LIBC_TYPES_DIR_H diff --git a/libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h b/libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h new file mode 100644 index 000000000000..90f23969678f --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h @@ -0,0 +1,19 @@ +//===-- Definition of EFI_ALLOCATE_TYPE 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_TYPES_EFI_ALLOCATE_TYPE_H +#define LLVM_LIBC_TYPES_EFI_ALLOCATE_TYPE_H + +typedef enum { + AllocateAnyPages, + AllocateMaxAddress, + AllocateAddress, + MaxAllocateType +} EFI_ALLOCATE_TYPE; + +#endif // LLVM_LIBC_TYPES_EFI_ALLOCATE_TYPE_H diff --git a/libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h b/libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h new file mode 100644 index 000000000000..8b7a6aadd7a2 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h @@ -0,0 +1,250 @@ +//===-- Definition of EFI_BOOT_SERVICES 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_TYPES_EFI_BOOT_SERVICES_H +#define LLVM_LIBC_TYPES_EFI_BOOT_SERVICES_H + +#include "../llvm-libc-macros/EFIAPI-macros.h" +#include "EFI_ALLOCATE_TYPE.h" +#include "EFI_DEVICE_PATH_PROTOCOL.h" +#include "EFI_EVENT.h" +#include "EFI_GUID.h" +#include "EFI_INTERFACE_TYPE.h" +#include "EFI_LOCATE_SEARCH_TYPE.h" +#include "EFI_MEMORY_DESCRIPTOR.h" +#include "EFI_MEMORY_TYPE.h" +#include "EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h" +#include "EFI_PHYSICAL_ADDRESS.h" +#include "EFI_STATUS.h" +#include "EFI_TABLE_HEADER.h" +#include "EFI_TIMER_DELAY.h" +#include "EFI_TPL.h" +#include "char16_t.h" +#include "size_t.h" + +#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42 +#define EFI_BOOT_SERVICES_REVISION EFI_SPECIFICATION_VERSION + +typedef EFI_TPL(EFIAPI *EFI_RAISE_TPL)(EFI_TPL NewTpl); +typedef void(EFIAPI *EFI_RESTORE_TPL)(EFI_TPL OldTpl); + +typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type, + EFI_MEMORY_TYPE MemoryType, + size_t Pages, + EFI_PHYSICAL_ADDRESS *Memory); +typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(EFI_PHYSICAL_ADDRESS Memory, + size_t Pages); +typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(size_t *MemoryMapSize, + EFI_MEMORY_DESCRIPTOR *MemoryMap, + size_t *MapKey, + size_t *DescriptorSize, + uint32_t *DescriptorVersion); + +typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType, + size_t Size, void **Buffer); +typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer); + +typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context); + +typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, EFI_TPL NotifyTpl, + EFI_EVENT_NOTIFY NotifyFunction, + void *NotifyContext, + EFI_EVENT *Event); +typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type, + uint64_t TriggerTime); +typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(size_t NumberOfEvents, + EFI_EVENT *Event, size_t *Index); +typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event); +typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event); +typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event); + +typedef EFI_STATUS(EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE)( + EFI_HANDLE *Handle, EFI_GUID *Protocol, EFI_INTERFACE_TYPE InterfaceType, + void *Interface); +typedef EFI_STATUS(EFIAPI *EFI_REINSTALL_PROTOCOL_INTERFACE)( + EFI_HANDLE Handle, EFI_GUID *Protocol, void *OldInterface, + void *NewInterface); +typedef EFI_STATUS(EFIAPI *EFI_UNINSTALL_PROTOCOL_INTERFACE)(EFI_HANDLE Handle, + EFI_GUID *Protocol, + void *Interface); + +typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle, + EFI_GUID *Protocol, + void **Interface); +typedef EFI_STATUS(EFIAPI *EFI_REGISTER_PROTOCOL_NOTIFY)(EFI_GUID *Protocol, + EFI_EVENT Event, + void **Registration); + +typedef EFI_STATUS(EFIAPI *EFI_LOCATE_HANDLE)(EFI_LOCATE_SEARCH_TYPE SearchType, + EFI_GUID *Protocol, + void *SearchKey, + size_t *BufferSize, + EFI_HANDLE *Buffer); +typedef EFI_STATUS(EFIAPI *EFI_LOCATE_DEVICE_PATH)( + EFI_GUID *Protocol, EFI_DEVICE_PATH_PROTOCOL **DevicePath, + EFI_HANDLE *Device); + +typedef EFI_STATUS(EFIAPI *EFI_INSTALL_CONFIGURATION_TABLE)(EFI_GUID *Guid, + void *Table); +typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle); +typedef EFI_STATUS(EFIAPI *EFI_IMAGE_START)(EFI_HANDLE ImageHandle, + size_t *ExitDataSize, + char16_t **ExitData); + +typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle, + EFI_STATUS ExitStatus, size_t ExitDataSize, + char16_t *ExitData); +typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle, + size_t MapKey); +typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *Count); +typedef EFI_STATUS(EFIAPI *EFI_STALL)(size_t Microseconds); +typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(size_t Timeout, + uint64_t WatchdogCode, + size_t DataSize, + char16_t *WatchdogData); + +typedef EFI_STATUS(EFIAPI *EFI_CONNECT_CONTROLLER)( + EFI_HANDLE ControllerHandle, EFI_HANDLE *DriverImageHandle, + EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, bool Recursive); + +typedef EFI_STATUS(EFIAPI *EFI_DISCONNECT_CONTROLLER)( + EFI_HANDLE ControllerHandle, EFI_HANDLE DriverImageHandle, + EFI_HANDLE ChildHandle); + +typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL)( + EFI_HANDLE Handle, EFI_GUID *Protocol, void **Interface, + EFI_HANDLE AgentHandle, EFI_HANDLE ControllerHandle, uint32_t Attributes); + +typedef EFI_STATUS(EFIAPI *EFI_CLOSE_PROTOCOL)(EFI_HANDLE Handle, + EFI_GUID *Protocol, + EFI_HANDLE AgentHandle, + EFI_HANDLE ControllerHandle); + +typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION)( + EFI_HANDLE Handle, EFI_GUID *Protocol, + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, size_t *EntryCount); + +typedef EFI_STATUS(EFIAPI *EFI_PROTOCOLS_PER_HANDLE)( + EFI_HANDLE Handle, EFI_GUID ***ProtocolBuffer, size_t *ProtocolBufferCount); + +typedef EFI_STATUS(EFIAPI *EFI_LOCATE_HANDLE_BUFFER)( + EFI_LOCATE_SEARCH_TYPE SearchType, EFI_GUID *Protocol, void *SearchKey, + size_t *NoHandles, EFI_HANDLE **Buffer); + +typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol, + void *Registration, + void **Interface); + +typedef EFI_STATUS(EFIAPI *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)( + EFI_HANDLE Handle, ...); +typedef EFI_STATUS(EFIAPI *EFI_CALCULATE_CRC32)(void *Data, size_t DataSize, + uint32_t *Crc32); + +typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source, + size_t Length); +typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, size_t Size, uint8_t Value); + +typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)( + uint32_t Type, EFI_TPL NotifyTpl, EFI_EVENT_NOTIFY NotifyFunction, + const void *NotifyContext, const EFI_GUID *EventGroup, EFI_EVENT *Event); + +typedef struct { + EFI_TABLE_HEADER Hdr; + + // + // Task Priority Services + // + EFI_RAISE_TPL RaiseTPL; // EFI 1.0+ + EFI_RESTORE_TPL RestoreTPL; // EFI 1.0+ + + // + // Memory Services + // + EFI_ALLOCATE_PAGES AllocatePages; // EFI 1.0+ + EFI_FREE_PAGES FreePages; // EFI 1.0+ + EFI_GET_MEMORY_MAP GetMemoryMap; // EFI 1.0+ + EFI_ALLOCATE_POOL AllocatePool; // EFI 1.0+ + EFI_FREE_POOL FreePool; // EFI 1.0+ + + // + // Event & Timer Services + // + EFI_CREATE_EVENT CreateEvent; // EFI 1.0+ + EFI_SET_TIMER SetTimer; // EFI 1.0+ + EFI_WAIT_FOR_EVENT WaitForEvent; // EFI 1.0+ + EFI_SIGNAL_EVENT SignalEvent; // EFI 1.0+ + EFI_CLOSE_EVENT CloseEvent; // EFI 1.0+ + EFI_CHECK_EVENT CheckEvent; // EFI 1.0+ + + // + // Protocol Handler Services + // + EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface; // EFI 1.0+ + EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface; // EFI 1.0+ + EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface; // EFI 1.0+ + EFI_HANDLE_PROTOCOL HandleProtocol; // EFI 1.0+ + void *Reserved; // EFI 1.0+ + EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify; // EFI 1.0+ + EFI_LOCATE_HANDLE LocateHandle; // EFI 1.+ + EFI_LOCATE_DEVICE_PATH LocateDevicePath; // EFI 1.0+ + EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable; // EFI 1.0+ + + // + // Image Services + // + EFI_IMAGE_UNLOAD LoadImage; // EFI 1.0+ + EFI_IMAGE_START StartImage; // EFI 1.0+ + EFI_EXIT Exit; // EFI 1.0+ + EFI_IMAGE_UNLOAD UnloadImage; // EFI 1.0+ + EFI_EXIT_BOOT_SERVICES ExitBootServices; // EFI 1.0+ + + // + // Miscellaneous Services + // + EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount; // EFI 1.0+ + EFI_STALL Stall; // EFI 1.0+ + EFI_SET_WATCHDOG_TIMER SetWatchdogTimer; // EFI 1.0+ + + // + // DriverSupport Services + // + EFI_CONNECT_CONTROLLER ConnectController; // EFI 1.1 + EFI_DISCONNECT_CONTROLLER DisconnectController; // EFI 1.1+ + + // + // Open and Close Protocol Services + // + EFI_OPEN_PROTOCOL OpenProtocol; // EFI 1.1+ + EFI_CLOSE_PROTOCOL CloseProtocol; // EFI 1.1+ + EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation; // EFI 1.1+ + + // + // Library Services + // + EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle; // EFI 1.1+ + EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer; // EFI 1.1+ + EFI_LOCATE_PROTOCOL LocateProtocol; // EFI 1.1+ + EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES + InstallMultipleProtocolInterfaces; // EFI 1.1+ + EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES + UninstallMultipleProtocolInterfaces; // EFI 1.1+* + + // + // 32-bit CRC Services + // + EFI_CALCULATE_CRC32 CalculateCrc32; // EFI 1.1+ + + // + // Miscellaneous Services + // + EFI_COPY_MEM CopyMem; // EFI 1.1+ + EFI_SET_MEM SetMem; // EFI 1.1+ + EFI_CREATE_EVENT_EX CreateEventEx; // UEFI 2.0+ +} EFI_BOOT_SERVICES; + +#endif // LLVM_LIBC_TYPES_EFI_BOOT_SERVICES_H diff --git a/libc/include/llvm-libc-types/EFI_CAPSULE.h b/libc/include/llvm-libc-types/EFI_CAPSULE.h new file mode 100644 index 000000000000..c7440c9b03b7 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_CAPSULE.h @@ -0,0 +1,26 @@ +//===-- Definition of EFI_CAPSULE 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_TYPES_EFI_CAPSULE_H +#define LLVM_LIBC_TYPES_EFI_CAPSULE_H + +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_GUID.h" + +typedef struct { + EFI_GUID CapsuleGuid; + uint32_t HeaderSize; + uint32_t Flags; + uint32_t CapsuleImageSize; +} EFI_CAPSULE_HEADER; + +#define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000 +#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000 +#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 + +#endif // LLVM_LIBC_TYPES_EFI_CAPSULE_H diff --git a/libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h b/libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h new file mode 100644 index 000000000000..56cd3e4fbb58 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h @@ -0,0 +1,19 @@ +//===-- Definition of EFI_CONFIGURATION_TABLE 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_TYPES_EFI_CONFIGURATION_TABLE_H +#define LLVM_LIBC_TYPES_EFI_CONFIGURATION_TABLE_H + +#include "EFI_GUID.h" + +typedef struct { + EFI_GUID VendorGuid; + void *VendorTable; +} EFI_CONFIGURATION_TABLE; + +#endif // LLVM_LIBC_TYPES_EFI_CONFIGURATION_TABLE_H diff --git a/libc/include/llvm-libc-types/EFI_DEVICE_PATH_PROTOCOL.h b/libc/include/llvm-libc-types/EFI_DEVICE_PATH_PROTOCOL.h new file mode 100644 index 000000000000..f6a0b2e1f45c --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_DEVICE_PATH_PROTOCOL.h @@ -0,0 +1,23 @@ +//===-- Definition of EFI_DEVICE_PATH_PROTOCOL 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_TYPES_EFI_DEVICE_PATH_PROTOCOL_H +#define LLVM_LIBC_TYPES_EFI_DEVICE_PATH_PROTOCOL_H + +#include "../llvm-libc-macros/stdint-macros.h" + +#define EFI_DEVICE_PATH_PROTOCOL_GUID \ + {0x09576e91, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} + +typedef struct _EFI_DEVICE_PATH_PROTOCOL { + uint8_t Type; + uint8_t SubType; + uint8_t Length[2]; +} EFI_DEVICE_PATH_PROTOCOL; + +#endif // LLVM_LIBC_TYPES_EFI_DEVICE_PATH_PROTOCOL_H diff --git a/libc/include/llvm-libc-types/EFI_EVENT.h b/libc/include/llvm-libc-types/EFI_EVENT.h new file mode 100644 index 000000000000..938856b8e791 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_EVENT.h @@ -0,0 +1,21 @@ +//===-- Definition of EFI_EVENT 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_TYPES_EFI_EVENT_H +#define LLVM_LIBC_TYPES_EFI_EVENT_H + +typedef void *EFI_EVENT; + +#define EVT_TIMER 0x80000000 +#define EVT_RUNTIME 0x40000000 +#define EVT_NOTIFY_WAIT 0x00000100 +#define EVT_NOTIFY_SIGNAL 0x00000200 +#define EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201 +#define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202 + +#endif // LLVM_LIBC_TYPES_EFI_EVENT_H diff --git a/libc/include/llvm-libc-types/EFI_GUID.h b/libc/include/llvm-libc-types/EFI_GUID.h new file mode 100644 index 000000000000..b3530008384d --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_GUID.h @@ -0,0 +1,21 @@ +//===-- Definition of EFI_GUID 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_TYPES_EFI_GUID_H +#define LLVM_LIBC_TYPES_EFI_GUID_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef struct { + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[8]; +} EFI_GUID; + +#endif // LLVM_LIBC_TYPES_EFI_GUID_H diff --git a/libc/include/llvm-libc-types/EFI_HANDLE.h b/libc/include/llvm-libc-types/EFI_HANDLE.h new file mode 100644 index 000000000000..d4376dd24753 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_HANDLE.h @@ -0,0 +1,14 @@ +//===-- Definition of EFI_HANDLE 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_TYPES_EFI_HANDLE_H +#define LLVM_LIBC_TYPES_EFI_HANDLE_H + +typedef void *EFI_HANDLE; + +#endif // LLVM_LIBC_TYPES_EFI_HANDLE_H diff --git a/libc/include/llvm-libc-types/EFI_INTERFACE_TYPE.h b/libc/include/llvm-libc-types/EFI_INTERFACE_TYPE.h new file mode 100644 index 000000000000..d463c5381b3f --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_INTERFACE_TYPE.h @@ -0,0 +1,16 @@ +//===-- Definition of EFI_INTERFACE_TYPE 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_TYPES_EFI_INTERFACE_TYPE_H +#define LLVM_LIBC_TYPES_EFI_INTERFACE_TYPE_H + +typedef enum { + EFI_NATIVE_INTERFACE, +} EFI_INTERFACE_TYPE; + +#endif // LLVM_LIBC_TYPES_EFI_INTERFACE_TYPE_H diff --git a/libc/include/llvm-libc-types/EFI_LOCATE_SEARCH_TYPE.h b/libc/include/llvm-libc-types/EFI_LOCATE_SEARCH_TYPE.h new file mode 100644 index 000000000000..3a8fd7bc3e77 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_LOCATE_SEARCH_TYPE.h @@ -0,0 +1,18 @@ +//===-- Definition of EFI_LOCATE_SEARCH_TYPE 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_TYPES_EFI_LOCATE_SEARCH_TYPE_H +#define LLVM_LIBC_TYPES_EFI_LOCATE_SEARCH_TYPE_H + +typedef enum { + AllHandles, + ByRegisterNotify, + ByProtocol, +} EFI_LOCATE_SEARCH_TYPE; + +#endif // LLVM_LIBC_TYPES_EFI_LOCATE_SEARCH_TYPE_H diff --git a/libc/include/llvm-libc-types/EFI_MEMORY_DESCRIPTOR.h b/libc/include/llvm-libc-types/EFI_MEMORY_DESCRIPTOR.h new file mode 100644 index 000000000000..72d0579aef76 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_MEMORY_DESCRIPTOR.h @@ -0,0 +1,43 @@ +//===-- Definition of EFI_MEMORY_DESCRIPTOR 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_TYPES_EFI_MEMORY_DESCRIPTOR_H +#define LLVM_LIBC_TYPES_EFI_MEMORY_DESCRIPTOR_H + +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_PHYSICAL_ADDRESS.h" +#include "EFI_VIRTUAL_ADDRESS.h" + +#define EFI_MEMORY_DESCRIPTOR_VERSION 1 + +#define EFI_MEMORY_UC 0x0000000000000001 +#define EFI_MEMORY_WC 0x0000000000000002 +#define EFI_MEMORY_WT 0x0000000000000004 +#define EFI_MEMORY_WB 0x0000000000000008 +#define EFI_MEMORY_UCE 0x0000000000000010 +#define EFI_MEMORY_WP 0x0000000000001000 +#define EFI_MEMORY_RP 0x0000000000002000 +#define EFI_MEMORY_XP 0x0000000000004000 +#define EFI_MEMORY_NV 0x0000000000008000 +#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000 +#define EFI_MEMORY_RO 0x0000000000020000 +#define EFI_MEMORY_SP 0x0000000000040000 +#define EFI_MEMORY_CPU_CRYPTO 0x0000000000080000 +#define EFI_MEMORY_RUNTIME 0x8000000000000000 +#define EFI_MEMORY_ISA_VALID 0x4000000000000000 +#define EFI_MEMORY_ISA_MASK 0x0FFFF00000000000 + +typedef struct { + uint32_t Type; + EFI_PHYSICAL_ADDRESS PhysicalStart; + EFI_VIRTUAL_ADDRESS VirtualStart; + uint64_t NumberOfPages; + uint64_t Attribute; +} EFI_MEMORY_DESCRIPTOR; + +#endif // LLVM_LIBC_TYPES_EFI_MEMORY_DESCRIPTOR_H diff --git a/libc/include/llvm-libc-types/EFI_MEMORY_TYPE.h b/libc/include/llvm-libc-types/EFI_MEMORY_TYPE.h new file mode 100644 index 000000000000..c8921cda2c38 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_MEMORY_TYPE.h @@ -0,0 +1,32 @@ +//===-- Definition of EFI_MEMORY_TYPE 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_TYPES_EFI_MEMORY_TYPE_H +#define LLVM_LIBC_TYPES_EFI_MEMORY_TYPE_H + +typedef enum { + EfiReservedMemoryType, + EfiLoaderCode, + EfiLoaderData, + EfiBootServicesCode, + EfiBootServicesData, + EfiRuntimeServicesCode, + EfiRuntimeServicesData, + EfiConventionalMemory, + EfiUnusableMemory, + EfiACPIReclaimMemory, + EfiACPIMemoryNVS, + EfiMemoryMappedIO, + EfiMemoryMappedIOPortSpace, + EfiPalCode, + EfiPersistentMemory, + EfiUnacceptedMemoryType, + EfiMaxMemoryType +} EFI_MEMORY_TYPE; + +#endif // LLVM_LIBC_TYPES_EFI_MEMORY_TYPE_H diff --git a/libc/include/llvm-libc-types/EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h b/libc/include/llvm-libc-types/EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h new file mode 100644 index 000000000000..de0c59c139ef --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h @@ -0,0 +1,22 @@ +//===-- Definition of EFI_OPEN_PROTOCOL_INFORMATION_ENTRY 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_TYPES_EFI_OPEN_PROTOCOL_INFORMATION_ENTRY_H +#define LLVM_LIBC_TYPES_EFI_OPEN_PROTOCOL_INFORMATION_ENTRY_H + +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_HANDLE.h" + +typedef struct { + EFI_HANDLE AgentHandle; + EFI_HANDLE ControllerHandle; + uint32_t Attributes; + uint32_t OpenCount; +} EFI_OPEN_PROTOCOL_INFORMATION_ENTRY; + +#endif // LLVM_LIBC_TYPES_EFI_OPEN_PROTOCOL_INFORMATION_ENTRY_H diff --git a/libc/include/llvm-libc-types/EFI_PHYSICAL_ADDRESS.h b/libc/include/llvm-libc-types/EFI_PHYSICAL_ADDRESS.h new file mode 100644 index 000000000000..8880ee66c0f8 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_PHYSICAL_ADDRESS.h @@ -0,0 +1,16 @@ +//===-- Definition of EFI_PHYSICAL_ADDRESS 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_TYPES_EFI_PHYSICAL_ADDRESS_H +#define LLVM_LIBC_TYPES_EFI_PHYSICAL_ADDRESS_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef uint64_t EFI_PHYSICAL_ADDRESS; + +#endif // LLVM_LIBC_TYPES_EFI_PHYSICAL_ADDRESS_H diff --git a/libc/include/llvm-libc-types/EFI_RUNTIME_SERVICES.h b/libc/include/llvm-libc-types/EFI_RUNTIME_SERVICES.h new file mode 100644 index 000000000000..8913118b0844 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_RUNTIME_SERVICES.h @@ -0,0 +1,137 @@ +//===-- Definition of EFI_RUNTIME_SERVICES 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_TYPES_EFI_RUNTIME_SERVICES_H +#define LLVM_LIBC_TYPES_EFI_RUNTIME_SERVICES_H + +#include "../llvm-libc-macros/EFIAPI-macros.h" +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_CAPSULE.h" +#include "EFI_MEMORY_DESCRIPTOR.h" +#include "EFI_PHYSICAL_ADDRESS.h" +#include "EFI_STATUS.h" +#include "EFI_TABLE_HEADER.h" +#include "EFI_TIME.h" +#include "char16_t.h" +#include "size_t.h" + +#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552 +#define EFI_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_VERSION + +#define EFI_VARIABLE_NON_VOLATILE 0x00000001 +#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 +#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 +#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008 +// This attribute is identified by the mnemonic 'HR' elsewhere +// in this specification. +#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010 +// NOTE: EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated +// and should be considered reserved. +#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020 +#define EFI_VARIABLE_APPEND_WRITE 0x00000040 +#define EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS 0x00000080 + +typedef enum { + EfiResetCold, + EfiResetWarm, + EfiResetShutdown, + EfiResetPlatformSpecific, +} EFI_RESET_TYPE; + +#define EFI_VARIABLE_AUTHENTICATION_3_CERT_ID_SHA256 1 + +typedef struct { + uint8_t Type; + uint32_t IdSize; + // Value is defined as: + // uint8_t Id[IdSize]; +} EFI_VARIABLE_AUTHENTICATION_3_CERT_ID; + +typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(EFI_TIME *Time, + EFI_TIME_CAPABILITIES *Capabilities); +typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(EFI_TIME *Time); +typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(bool *Enabled, bool *Pending, + EFI_TIME *Time); +typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(bool *Enabled, EFI_TIME *Time); + +typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)( + size_t MemoryMapSize, size_t DescriptorSize, uint32_t DescriptorVersion, + EFI_MEMORY_DESCRIPTOR *VirtualMap); +typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(size_t DebugDisposition, + void **Address); + +typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(char16_t *VariableName, + EFI_GUID *VendorGuid, + uint32_t *Attributes, + size_t *DataSize, void *Data); +typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(size_t *VariableNameSize, + char16_t *VariableName, + EFI_GUID *VendorGuid); +typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(char16_t *VariableName, + EFI_GUID *VendorGuid, + uint32_t Attributes, + size_t DataSize, void *Data); + +typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT)(uint32_t *HighCount); +typedef void(EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE ResetType, + EFI_STATUS ResetStatus, size_t DataSize, + void *ResetData); + +typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)( + EFI_CAPSULE_HEADER **CapsuleHeaderArray, size_t CapsuleCount, + EFI_PHYSICAL_ADDRESS ScatterGatherList); +typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)( + EFI_CAPSULE_HEADER **CapsuleHeaderArray, size_t CapsuleCount, + uint64_t *MaximumCapsuleSize, EFI_RESET_TYPE ResetType); + +typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)( + uint32_t Attributes, uint64_t *MaximumVariableStorageSize, + uint64_t *RemainingVariableStorageSize, uint64_t *MaximumVariableSize); + +typedef struct { + EFI_TABLE_HEADER Hdr; + + /// + /// Time Services + EFI_GET_TIME GetTime; + EFI_SET_TIME SetTime; + EFI_GET_WAKEUP_TIME GetWakeupTime; + EFI_SET_WAKEUP_TIME SetWakeupTime; + + // + // Virtual Memory Services + // + EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap; + EFI_CONVERT_POINTER ConvertPointer; + + // + // Variable Services + // + EFI_GET_VARIABLE GetVariable; + EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName; + EFI_SET_VARIABLE SetVariable; + + // + // Miscellaneous Services + // + EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount; + EFI_RESET_SYSTEM ResetSystem; + + // + // UEFI 2.0 Capsule Services + // + EFI_UPDATE_CAPSULE UpdateCapsule; + EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities; + + // + // Miscellaneous UEFI 2.0 Service + // + EFI_QUERY_VARIABLE_INFO QueryVariableInfo; +} EFI_RUNTIME_SERVICES; + +#endif // LLVM_LIBC_TYPES_EFI_RUNTIME_SERVICES_H diff --git a/libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_INPUT_PROTOCOL.h b/libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_INPUT_PROTOCOL.h new file mode 100644 index 000000000000..a6dc0952b631 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_INPUT_PROTOCOL.h @@ -0,0 +1,39 @@ +//===-- Definition of EFI_SIMPLE_TEXT_INPUT_PROTOCOL 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_TYPES_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_H +#define LLVM_LIBC_TYPES_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_H + +#include "../llvm-libc-macros/EFIAPI-macros.h" +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_EVENT.h" +#include "EFI_STATUS.h" +#include "char16_t.h" + +#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ + {0x387477c1, 0x69c7, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} + +typedef struct { + uint16_t ScanCode; + char16_t UnicodeChar; +} EFI_INPUT_KEY; + +struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL; + +typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)( + struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, bool ExtendedVerification); +typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)( + struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, EFI_INPUT_KEY *Key); + +typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL { + EFI_INPUT_RESET Reset; + EFI_INPUT_READ_KEY ReadKeyStroke; + EFI_EVENT WaitForKey; +} EFI_SIMPLE_TEXT_INPUT_PROTOCOL; + +#endif // LLVM_LIBC_TYPES_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_H diff --git a/libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.h b/libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.h new file mode 100644 index 000000000000..b5014c46a072 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.h @@ -0,0 +1,64 @@ +//===-- Definition of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL 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_TYPES_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_H +#define LLVM_LIBC_TYPES_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_H + +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_STATUS.h" +#include "size_t.h" + +#define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \ + {0x387477c2, 0x69c7, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} + +struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL; + +typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool ExtendedVerification); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, const char16_t *String); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, const char16_t *String); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, size_t ModeNumber, + size_t *Columns, size_t *Rows); + +typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_MODE)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, size_t ModeNumber); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, size_t Attribute); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, size_t Column, size_t Row); +typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)( + struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool Visible); + +typedef struct { + int32_t MaxMode; + int32_t Mode; + int32_t Attribute; + int32_t CursorColumn; + int32_t CursorRow; + bool CursorVisible; +} SIMPLE_TEXT_OUTPUT_MODE; + +typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL { + EFI_TEXT_RESET Reset; + EFI_TEXT_STRING OutputString; + EFI_TEXT_TEST_STRING TestString; + EFI_TEXT_QUERY_MODE QueryMode; + EFI_TEXT_SET_MODE SetMode; + EFI_TEXT_SET_ATTRIBUTE SetAttribute; + EFI_TEXT_CLEAR_SCREEN ClearScreen; + EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition; + EFI_TEXT_ENABLE_CURSOR EnableCursor; + SIMPLE_TEXT_OUTPUT_MODE *Mode; +} EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL; + +#endif // LLVM_LIBC_TYPES_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_H diff --git a/libc/include/llvm-libc-types/EFI_STATUS.h b/libc/include/llvm-libc-types/EFI_STATUS.h new file mode 100644 index 000000000000..bb9542bed8ef --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_STATUS.h @@ -0,0 +1,60 @@ +//===-- Definition of EFI_STATUS 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_TYPES_EFI_STATUS_H +#define LLVM_LIBC_TYPES_EFI_STATUS_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef uintptr_t EFI_STATUS; + +#define EFI_SUCCESS 0 + +#define EFI_LOAD_ERROR 1 +#define EFI_INVALID_PARAMETER 2 +#define EFI_UNSUPPORTED 3 +#define EFI_BAD_BUFFER_SIZE 4 +#define EFI_BUFFER_TOO_SMALL 5 +#define EFI_NOT_READY 6 +#define EFI_DEVICE_ERROR 7 +#define EFI_WRITE_PROTECTED 8 +#define EFI_OUT_OF_RESOURCES 9 +#define EFI_VOLUME_CORRUPTED 10 +#define EFI_VOLUME_FULL 11 +#define EFI_NO_MEDIA 12 +#define EFI_MEDIA_CHANGED 13 +#define EFI_NOT_FOUND 14 +#define EFI_ACCESS_DENIED 15 +#define EFI_NO_RESPONSE 16 +#define EFI_NO_MAPPING 17 +#define EFI_TIMEOUT 18 +#define EFI_NOT_STARTED 19 +#define EFI_ALREADY_STARTED 20 +#define EFI_ABORTED 21 +#define EFI_ICMP_ERROR 22 +#define EFI_TFTP_ERROR 23 +#define EFI_PROTOCOL_ERROR 24 +#define EFI_INCOMPATIBLE_VERSION 25 +#define EFI_SECURITY_VIOLATION 26 +#define EFI_CRC_ERROR 27 +#define EFI_END_OF_MEDIA 28 +#define EFI_END_OF_FILE 31 +#define EFI_INVALID_LANGUAGE 32 +#define EFI_COMPROMISED_DATA 33 +#define EFI_IP_ADDRESS_CONFLICT 34 +#define EFI_HTTP_ERROR 35 + +#define EFI_WARN_UNKNOWN_GLYPH 1 +#define EFI_WARN_DELETE_FAILURE 2 +#define EFI_WARN_WRITE_FAILURE 3 +#define EFI_WARN_BUFFER_TOO_SMALL 4 +#define EFI_WARN_STALE_DATA 5 +#define EFI_WARN_FILE_SYSTEM 6 +#define EFI_WARN_RESET_REQUIRED 7 + +#endif // LLVM_LIBC_TYPES_EFI_STATUS_H diff --git a/libc/include/llvm-libc-types/EFI_SYSTEM_TABLE.h b/libc/include/llvm-libc-types/EFI_SYSTEM_TABLE.h new file mode 100644 index 000000000000..290067ad862e --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_SYSTEM_TABLE.h @@ -0,0 +1,65 @@ +//===-- Definition of EFI_SYSTEM_TABLE 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_TYPES_EFI_SYSTEM_TABLE_H +#define LLVM_LIBC_TYPES_EFI_SYSTEM_TABLE_H + +#include "../llvm-libc-macros/stdint-macros.h" +#include "EFI_BOOT_SERVICES.h" +#include "EFI_CONFIGURATION_TABLE.h" +#include "EFI_HANDLE.h" +#include "EFI_RUNTIME_SERVICES.h" +#include "EFI_SIMPLE_TEXT_INPUT_PROTOCOL.h" +#include "EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.h" +#include "EFI_STATUS.h" +#include "EFI_TABLE_HEADER.h" + +#include "char16_t.h" +#include "size_t.h" + +#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249 +#define EFI_2_100_SYSTEM_TABLE_REVISION ((2 << 16) | (100)) +#define EFI_2_90_SYSTEM_TABLE_REVISION ((2 << 16) | (90)) +#define EFI_2_80_SYSTEM_TABLE_REVISION ((2 << 16) | (80)) +#define EFI_2_70_SYSTEM_TABLE_REVISION ((2 << 16) | (70)) +#define EFI_2_60_SYSTEM_TABLE_REVISION ((2 << 16) | (60)) +#define EFI_2_50_SYSTEM_TABLE_REVISION ((2 << 16) | (50)) +#define EFI_2_40_SYSTEM_TABLE_REVISION ((2 << 16) | (40)) +#define EFI_2_31_SYSTEM_TABLE_REVISION ((2 << 16) | (31)) +#define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30)) +#define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20)) +#define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10)) +#define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00)) +#define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10)) +#define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02)) +#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION +#define EFI_SYSTEM_TABLE_REVISION EFI_2_100_SYSTEM_TABLE_REVISION + +typedef struct { + EFI_TABLE_HEADER Hdr; + + char16_t *FirmwareVendor; + uint32_t FirmwareRevision; + + EFI_HANDLE ConsoleInHandle; + EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn; + + EFI_HANDLE ConsoleOutHandle; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; + + EFI_HANDLE StandardErrorHandle; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr; + + EFI_RUNTIME_SERVICES *RuntimeServices; + EFI_BOOT_SERVICES *BootServices; + + size_t NumberOfTableEntries; + EFI_CONFIGURATION_TABLE *ConfigurationTable; +} EFI_SYSTEM_TABLE; + +#endif // LLVM_LIBC_TYPES_EFI_SYSTEM_TABLE_H diff --git a/libc/include/llvm-libc-types/EFI_TABLE_HEADER.h b/libc/include/llvm-libc-types/EFI_TABLE_HEADER.h new file mode 100644 index 000000000000..293968ecc4d1 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_TABLE_HEADER.h @@ -0,0 +1,22 @@ +//===-- Definition of EFI_TABLE_HEADER 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_TYPES_EFI_TABLE_HEADER_H +#define LLVM_LIBC_TYPES_EFI_TABLE_HEADER_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef struct { + uint64_t Signature; + uint32_t Revision; + uint32_t HeaderSize; + uint32_t CRC32; + uint32_t Reserved; +} EFI_TABLE_HEADER; + +#endif // LLVM_LIBC_TYPES_EFI_TABLE_HEADER_H diff --git a/libc/include/llvm-libc-types/EFI_TIME.h b/libc/include/llvm-libc-types/EFI_TIME.h new file mode 100644 index 000000000000..b0e38b987d44 --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_TIME.h @@ -0,0 +1,37 @@ +//===-- Definition of EFI_TIME 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_TYPES_EFI_TIME_H +#define LLVM_LIBC_TYPES_EFI_TIME_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef struct { + uint16_t Year; // 1900 - 9999 + uint8_t Month; // 1 - 12 + uint8_t Day; // 1 - 31 + uint8_t Hour; // 0 - 23 + uint8_t Minute; // 0 - 59 + uint8_t Second; // 0 - 59 + uint8_t Pad1; + uint32_t Nanosecond; // 0 - 999,999,999 + int16_t TimeZone; // --1440 to 1440 or 2047 +} EFI_TIME; + +#define EFI_TIME_ADJUST_DAYLIGHT 0x01 +#define EFI_TIME_IN_DAYLIGHT 0x02 + +#define EFI_UNSPECIFIED_TIMEZONE 0x07FF + +typedef struct { + uint32_t Resolution; + uint32_t Accuracy; + bool SetsToZero; +} EFI_TIME_CAPABILITIES; + +#endif // LLVM_LIBC_TYPES_EFI_TIME_H diff --git a/libc/include/llvm-libc-types/EFI_TIMER_DELAY.h b/libc/include/llvm-libc-types/EFI_TIMER_DELAY.h new file mode 100644 index 000000000000..2a6872c69c8b --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_TIMER_DELAY.h @@ -0,0 +1,18 @@ +//===-- Definition of EFI_TIMER_DELAY 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_TYPES_EFI_TIMER_DELAY_H +#define LLVM_LIBC_TYPES_EFI_TIMER_DELAY_H + +typedef enum { + TimerCancel, + TimerPeriodic, + TimerRelative, +} EFI_TIMER_DELAY; + +#endif // LLVM_LIBC_TYPES_EFI_TIMER_DELAY_H diff --git a/libc/include/llvm-libc-types/EFI_TPL.h b/libc/include/llvm-libc-types/EFI_TPL.h new file mode 100644 index 000000000000..8361ccfacd6f --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_TPL.h @@ -0,0 +1,21 @@ +//===-- Definition of EFI_TPL 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_TYPES_EFI_TPL_H +#define LLVM_LIBC_TYPES_EFI_TPL_H + +#include "size_t.h" + +typedef size_t EFI_TPL; + +#define TPL_APPLICATION 4 +#define TPL_CALLBACK 8 +#define TPL_NOTIFY 16 +#define TPL_HIGH_LEVEL 31 + +#endif // LLVM_LIBC_TYPES_EFI_TPL_H diff --git a/libc/include/llvm-libc-types/EFI_VIRTUAL_ADDRESS.h b/libc/include/llvm-libc-types/EFI_VIRTUAL_ADDRESS.h new file mode 100644 index 000000000000..46cbec734dad --- /dev/null +++ b/libc/include/llvm-libc-types/EFI_VIRTUAL_ADDRESS.h @@ -0,0 +1,16 @@ +//===-- Definition of EFI_VIRTUAL_ADDRESS 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_TYPES_EFI_VIRTUAL_ADDRESS_H +#define LLVM_LIBC_TYPES_EFI_VIRTUAL_ADDRESS_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef uint64_t EFI_VIRTUAL_ADDRESS; + +#endif // LLVM_LIBC_TYPES_EFI_VIRTUAL_ADDRESS_H diff --git a/libc/include/llvm-libc-types/ENTRY.h b/libc/include/llvm-libc-types/ENTRY.h new file mode 100644 index 000000000000..b007c8edba2f --- /dev/null +++ b/libc/include/llvm-libc-types/ENTRY.h @@ -0,0 +1,17 @@ +//===-- Definition of ENTRY 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_TYPES_ENTRY_H +#define LLVM_LIBC_TYPES_ENTRY_H + +typedef struct entry { + char *key; + void *data; +} ENTRY; + +#endif // LLVM_LIBC_TYPES_ENTRY_H diff --git a/libc/include/llvm-libc-types/FILE.h b/libc/include/llvm-libc-types/FILE.h new file mode 100644 index 000000000000..f1d2e4f726c7 --- /dev/null +++ b/libc/include/llvm-libc-types/FILE.h @@ -0,0 +1,14 @@ +//===-- Definition of the type 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_TYPES_FILE_H +#define LLVM_LIBC_TYPES_FILE_H + +typedef struct FILE FILE; + +#endif // LLVM_LIBC_TYPES_FILE_H diff --git a/libc/include/llvm-libc-types/VISIT.h b/libc/include/llvm-libc-types/VISIT.h new file mode 100644 index 000000000000..0a7ff6e50d46 --- /dev/null +++ b/libc/include/llvm-libc-types/VISIT.h @@ -0,0 +1,14 @@ +//===-- Definition of VISIT 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_TYPES_VISIT_H +#define LLVM_LIBC_TYPES_VISIT_H + +typedef enum { preorder, postorder, endorder, leaf } VISIT; + +#endif // LLVM_LIBC_TYPES_VISIT_H diff --git a/libc/include/llvm-libc-types/__atexithandler_t.h b/libc/include/llvm-libc-types/__atexithandler_t.h new file mode 100644 index 000000000000..01aed676c2a7 --- /dev/null +++ b/libc/include/llvm-libc-types/__atexithandler_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __atexithandler_t ------------------------------===// +// +// 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_TYPES___ATEXITHANDLER_T_H +#define LLVM_LIBC_TYPES___ATEXITHANDLER_T_H + +typedef void (*__atexithandler_t)(void); + +#endif // LLVM_LIBC_TYPES___ATEXITHANDLER_T_H diff --git a/libc/include/llvm-libc-types/__atfork_callback_t.h b/libc/include/llvm-libc-types/__atfork_callback_t.h new file mode 100644 index 000000000000..ae2d0ca39d53 --- /dev/null +++ b/libc/include/llvm-libc-types/__atfork_callback_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __atfork_callback_t ----------------------------===// +// +// 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_TYPES___ATFORK_CALLBACK_T_H +#define LLVM_LIBC_TYPES___ATFORK_CALLBACK_T_H + +typedef void (*__atfork_callback_t)(void); + +#endif // LLVM_LIBC_TYPES___ATFORK_CALLBACK_T_H diff --git a/libc/include/llvm-libc-types/__call_once_func_t.h b/libc/include/llvm-libc-types/__call_once_func_t.h new file mode 100644 index 000000000000..6d278da4f1d3 --- /dev/null +++ b/libc/include/llvm-libc-types/__call_once_func_t.h @@ -0,0 +1,14 @@ +//===-- Definition of __call_once_func_t 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_TYPES___CALL_ONCE_FUNC_T_H +#define LLVM_LIBC_TYPES___CALL_ONCE_FUNC_T_H + +typedef void (*__call_once_func_t)(void); + +#endif // LLVM_LIBC_TYPES___CALL_ONCE_FUNC_T_H diff --git a/libc/include/llvm-libc-types/__dl_iterate_phdr_callback_t.h b/libc/include/llvm-libc-types/__dl_iterate_phdr_callback_t.h new file mode 100644 index 000000000000..52078daf7d3c --- /dev/null +++ b/libc/include/llvm-libc-types/__dl_iterate_phdr_callback_t.h @@ -0,0 +1,19 @@ +//===-- Definition of type __dl_iterate_phdr_callback_t ------------------===// +// +// 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_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H +#define LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H + +#include "size_t.h" + +struct dl_phdr_info; + +typedef int (*__dl_iterate_phdr_callback_t)(struct dl_phdr_info *, size_t, + void *); + +#endif // LLVM_LIBC_TYPES___DL_ITERATE_PHDR_CALLBACK_T_H diff --git a/libc/include/llvm-libc-types/__exec_argv_t.h b/libc/include/llvm-libc-types/__exec_argv_t.h new file mode 100644 index 000000000000..4eff583768af --- /dev/null +++ b/libc/include/llvm-libc-types/__exec_argv_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __exec_argv_t ----------------------------------===// +// +// 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_TYPES___EXEC_ARGV_T_H +#define LLVM_LIBC_TYPES___EXEC_ARGV_T_H + +typedef char *const __exec_argv_t[]; + +#endif // LLVM_LIBC_TYPES___EXEC_ARGV_T_H diff --git a/libc/include/llvm-libc-types/__exec_envp_t.h b/libc/include/llvm-libc-types/__exec_envp_t.h new file mode 100644 index 000000000000..89e02754c4e4 --- /dev/null +++ b/libc/include/llvm-libc-types/__exec_envp_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __exec_envp_t ----------------------------------===// +// +// 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_TYPES___EXEC_ENVP_T_H +#define LLVM_LIBC_TYPES___EXEC_ENVP_T_H + +typedef char *const __exec_envp_t[]; + +#endif // LLVM_LIBC_TYPES___EXEC_ENVP_T_H diff --git a/libc/include/llvm-libc-types/__futex_word.h b/libc/include/llvm-libc-types/__futex_word.h new file mode 100644 index 000000000000..04023c7e2d5f --- /dev/null +++ b/libc/include/llvm-libc-types/__futex_word.h @@ -0,0 +1,20 @@ +//===-- Definition of type which can represent a futex word ---------------===// +// +// 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_TYPES___FUTEX_WORD_H +#define LLVM_LIBC_TYPES___FUTEX_WORD_H + +typedef struct { + // Futex word should be aligned appropriately to allow target atomic + // instructions. This declaration mimics the internal setup. + _Alignas(sizeof(__UINT32_TYPE__) > _Alignof(__UINT32_TYPE__) + ? sizeof(__UINT32_TYPE__) + : _Alignof(__UINT32_TYPE__)) __UINT32_TYPE__ __word; +} __futex_word; + +#endif // LLVM_LIBC_TYPES___FUTEX_WORD_H diff --git a/libc/include/llvm-libc-types/__getoptargv_t.h b/libc/include/llvm-libc-types/__getoptargv_t.h new file mode 100644 index 000000000000..c26b9e9fa619 --- /dev/null +++ b/libc/include/llvm-libc-types/__getoptargv_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __getoptargv_t ---------------------------------===// +// +// 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_TYPES___GETOPTARGV_T_H +#define LLVM_LIBC_TYPES___GETOPTARGV_T_H + +typedef char *const __getoptargv_t[]; + +#endif // LLVM_LIBC_TYPES___GETOPTARGV_T_H diff --git a/libc/include/llvm-libc-types/__mutex_type.h b/libc/include/llvm-libc-types/__mutex_type.h new file mode 100644 index 000000000000..835561626149 --- /dev/null +++ b/libc/include/llvm-libc-types/__mutex_type.h @@ -0,0 +1,29 @@ +//===-- Definition of a common mutex 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_TYPES___MUTEX_TYPE_H +#define LLVM_LIBC_TYPES___MUTEX_TYPE_H + +#include "__futex_word.h" + +typedef struct { + unsigned char __timed; + unsigned char __recursive; + unsigned char __robust; + + void *__owner; + unsigned long long __lock_count; + +#ifdef __linux__ + __futex_word __ftxw; +#else +#error "Mutex type not defined for the target platform." +#endif +} __mutex_type; + +#endif // LLVM_LIBC_TYPES___MUTEX_TYPE_H diff --git a/libc/include/llvm-libc-types/__pthread_once_func_t.h b/libc/include/llvm-libc-types/__pthread_once_func_t.h new file mode 100644 index 000000000000..7575029f08c2 --- /dev/null +++ b/libc/include/llvm-libc-types/__pthread_once_func_t.h @@ -0,0 +1,14 @@ +//===-- Definition of __pthread_once_func_t 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_TYPES___PTHREAD_ONCE_FUNC_T_H +#define LLVM_LIBC_TYPES___PTHREAD_ONCE_FUNC_T_H + +typedef void (*__pthread_once_func_t)(void); + +#endif // LLVM_LIBC_TYPES___PTHREAD_ONCE_FUNC_T_H diff --git a/libc/include/llvm-libc-types/__pthread_start_t.h b/libc/include/llvm-libc-types/__pthread_start_t.h new file mode 100644 index 000000000000..6b7ae40b1b77 --- /dev/null +++ b/libc/include/llvm-libc-types/__pthread_start_t.h @@ -0,0 +1,14 @@ +//===-- Definition of __pthread_start_t 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_TYPES___PTHREAD_START_T_H +#define LLVM_LIBC_TYPES___PTHREAD_START_T_H + +typedef void *(*__pthread_start_t)(void *); + +#endif // LLVM_LIBC_TYPES___PTHREAD_START_T_H diff --git a/libc/include/llvm-libc-types/__pthread_tss_dtor_t.h b/libc/include/llvm-libc-types/__pthread_tss_dtor_t.h new file mode 100644 index 000000000000..c67b6045936d --- /dev/null +++ b/libc/include/llvm-libc-types/__pthread_tss_dtor_t.h @@ -0,0 +1,14 @@ +//===-- Definition of the type __pthread_tss_dtor_t -----------------------===// +// +// 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_TYPES___PTHREAD_TSS_DTOR_T_H +#define LLVM_LIBC_TYPES___PTHREAD_TSS_DTOR_T_H + +typedef void (*__pthread_tss_dtor_t)(void *); + +#endif // LLVM_LIBC_TYPES___PTHREAD_TSS_DTOR_T_H diff --git a/libc/include/llvm-libc-types/__qsortcompare_t.h b/libc/include/llvm-libc-types/__qsortcompare_t.h new file mode 100644 index 000000000000..48fc9ccb4409 --- /dev/null +++ b/libc/include/llvm-libc-types/__qsortcompare_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __qsortcompare_t -------------------------------===// +// +// 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_TYPES___QSORTCOMPARE_T_H +#define LLVM_LIBC_TYPES___QSORTCOMPARE_T_H + +typedef int (*__qsortcompare_t)(const void *, const void *); + +#endif // LLVM_LIBC_TYPES___QSORTCOMPARE_T_H diff --git a/libc/include/llvm-libc-types/__qsortrcompare_t.h b/libc/include/llvm-libc-types/__qsortrcompare_t.h new file mode 100644 index 000000000000..f6b058864359 --- /dev/null +++ b/libc/include/llvm-libc-types/__qsortrcompare_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __qsortrcompare_t ------------------------------===// +// +// 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_TYPES___QSORTRCOMPARE_T_H +#define LLVM_LIBC_TYPES___QSORTRCOMPARE_T_H + +typedef int (*__qsortrcompare_t)(const void *, const void *, void *); + +#endif // LLVM_LIBC_TYPES___QSORTRCOMPARE_T_H diff --git a/libc/include/llvm-libc-types/__search_compare_t.h b/libc/include/llvm-libc-types/__search_compare_t.h new file mode 100644 index 000000000000..7033fef49b49 --- /dev/null +++ b/libc/include/llvm-libc-types/__search_compare_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type __search_compare_t -----------------------------===// +// +// 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_TYPES___SEARCH_COMPARE_T_H +#define LLVM_LIBC_TYPES___SEARCH_COMPARE_T_H + +typedef int (*__search_compare_t)(const void *, const void *); + +#endif // LLVM_LIBC_TYPES___SEARCH_COMPARE_T_H diff --git a/libc/include/llvm-libc-types/__thread_type.h b/libc/include/llvm-libc-types/__thread_type.h new file mode 100644 index 000000000000..645573f544a9 --- /dev/null +++ b/libc/include/llvm-libc-types/__thread_type.h @@ -0,0 +1,16 @@ +//===-- Definition of thrd_t 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_TYPES___THREAD_TYPE_H +#define LLVM_LIBC_TYPES___THREAD_TYPE_H + +typedef struct { + void *__attrib; +} __thread_type; + +#endif // LLVM_LIBC_TYPES___THREAD_TYPE_H diff --git a/libc/include/llvm-libc-types/blkcnt_t.h b/libc/include/llvm-libc-types/blkcnt_t.h new file mode 100644 index 000000000000..9dea8f033d6d --- /dev/null +++ b/libc/include/llvm-libc-types/blkcnt_t.h @@ -0,0 +1,14 @@ +//===-- Definition of blkcnt_t 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_TYPES_BLKCNT_T_H +#define LLVM_LIBC_TYPES_BLKCNT_T_H + +typedef __INTPTR_TYPE__ blkcnt_t; + +#endif // LLVM_LIBC_TYPES_BLKCNT_T_H diff --git a/libc/include/llvm-libc-types/blksize_t.h b/libc/include/llvm-libc-types/blksize_t.h new file mode 100644 index 000000000000..7caa9705cca3 --- /dev/null +++ b/libc/include/llvm-libc-types/blksize_t.h @@ -0,0 +1,14 @@ +//===-- Definition of blksize_t 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_TYPES_BLKSIZE_T_H +#define LLVM_LIBC_TYPES_BLKSIZE_T_H + +typedef __INTPTR_TYPE__ blksize_t; + +#endif // LLVM_LIBC_TYPES_BLKSIZE_T_H diff --git a/libc/include/llvm-libc-types/cc_t.h b/libc/include/llvm-libc-types/cc_t.h new file mode 100644 index 000000000000..40d99ad22da2 --- /dev/null +++ b/libc/include/llvm-libc-types/cc_t.h @@ -0,0 +1,14 @@ +//===-- Definition of cc_t 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_TYPES_CC_T_H +#define LLVM_LIBC_TYPES_CC_T_H + +typedef unsigned char cc_t; + +#endif // LLVM_LIBC_TYPES_CC_T_H diff --git a/libc/include/llvm-libc-types/cfloat128.h b/libc/include/llvm-libc-types/cfloat128.h new file mode 100644 index 000000000000..83fad8791013 --- /dev/null +++ b/libc/include/llvm-libc-types/cfloat128.h @@ -0,0 +1,44 @@ +//===-- Definition of cfloat128 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_TYPES_CFLOAT128_H +#define LLVM_LIBC_TYPES_CFLOAT128_H + +#include "../llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG + +// Currently, the complex variant of C23 `_Float128` type is only defined as a +// built-in type in GCC 7 or later, for C and in GCC 13 or later, for C++. For +// clang, the complex variant of `__float128` is defined instead, and only on +// x86-64 targets for clang 11 or later. +// +// TODO: Update the complex variant of C23 `_Float128` type detection again when +// clang supports it. +#ifdef __clang__ +#if (__clang_major__ >= 11) && \ + (defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)) +// Use _Complex __float128 type. clang uses __SIZEOF_FLOAT128__ or __FLOAT128__ +// macro to notify the availability of __float128 type: +// https://reviews.llvm.org/D15120 +#define LIBC_TYPES_HAS_CFLOAT128 +typedef _Complex __float128 cfloat128; +#endif +#elif defined(__GNUC__) +#if (defined(__STDC_IEC_60559_COMPLEX__) || defined(__SIZEOF_FLOAT128__)) && \ + (__GNUC__ >= 13 || (!defined(__cplusplus))) +#define LIBC_TYPES_HAS_CFLOAT128 +typedef _Complex _Float128 cfloat128; +#endif +#endif + +#if !defined(LIBC_TYPES_HAS_CFLOAT128) && (LDBL_MANT_DIG == 113) +#define LIBC_TYPES_HAS_CFLOAT128 +#define LIBC_TYPES_CFLOAT128_IS_COMPLEX_LONG_DOUBLE +typedef _Complex long double cfloat128; +#endif + +#endif // LLVM_LIBC_TYPES_CFLOAT128_H diff --git a/libc/include/llvm-libc-types/cfloat16.h b/libc/include/llvm-libc-types/cfloat16.h new file mode 100644 index 000000000000..2d4cef756272 --- /dev/null +++ b/libc/include/llvm-libc-types/cfloat16.h @@ -0,0 +1,21 @@ +//===-- Definition of cfloat16 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_TYPES_CFLOAT16_H +#define LLVM_LIBC_TYPES_CFLOAT16_H + +#if defined(__FLT16_MANT_DIG__) && \ + (!defined(__GNUC__) || __GNUC__ >= 13 || \ + (defined(__clang__) && __clang_major__ >= 14)) && \ + !defined(__arm__) && !defined(_M_ARM) && !defined(__riscv) && \ + !defined(_WIN32) +#define LIBC_TYPES_HAS_CFLOAT16 +typedef _Complex _Float16 cfloat16; +#endif + +#endif // LLVM_LIBC_TYPES_CFLOAT16_H diff --git a/libc/include/llvm-libc-types/char16_t.h b/libc/include/llvm-libc-types/char16_t.h new file mode 100644 index 000000000000..1f5847ae771b --- /dev/null +++ b/libc/include/llvm-libc-types/char16_t.h @@ -0,0 +1,17 @@ +//===-- Definition of char16_t 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_TYPES_CHAR16_T_H +#define LLVM_LIBC_TYPES_CHAR16_T_H + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#include "../llvm-libc-macros/stdint-macros.h" +typedef uint_least16_t char16_t; +#endif + +#endif // LLVM_LIBC_TYPES_CHAR16_T_H diff --git a/libc/include/llvm-libc-types/char32_t.h b/libc/include/llvm-libc-types/char32_t.h new file mode 100644 index 000000000000..20b72dc5d67e --- /dev/null +++ b/libc/include/llvm-libc-types/char32_t.h @@ -0,0 +1,17 @@ +//===-- Definition of char32_t 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_TYPES_CHAR32_T_H +#define LLVM_LIBC_TYPES_CHAR32_T_H + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#include "../llvm-libc-macros/stdint-macros.h" +typedef uint_least32_t char32_t; +#endif + +#endif // LLVM_LIBC_TYPES_CHAR32_T_H diff --git a/libc/include/llvm-libc-types/char8_t.h b/libc/include/llvm-libc-types/char8_t.h new file mode 100644 index 000000000000..a343be77d810 --- /dev/null +++ b/libc/include/llvm-libc-types/char8_t.h @@ -0,0 +1,16 @@ +//===-- Definition of char8_t 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_TYPES_CHAR8_T_H +#define LLVM_LIBC_TYPES_CHAR8_T_H + +#if !(defined(__cplusplus) && defined(__cpp_char8_t)) +typedef unsigned char char8_t; +#endif + +#endif // LLVM_LIBC_TYPES_CHAR8_T_H diff --git a/libc/include/llvm-libc-types/clock_t.h b/libc/include/llvm-libc-types/clock_t.h new file mode 100644 index 000000000000..8759ee999fb5 --- /dev/null +++ b/libc/include/llvm-libc-types/clock_t.h @@ -0,0 +1,14 @@ +//===-- Definition of clock_t 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_TYPES_CLOCK_T_H +#define LLVM_LIBC_TYPES_CLOCK_T_H + +typedef long clock_t; + +#endif // LLVM_LIBC_TYPES_CLOCK_T_H diff --git a/libc/include/llvm-libc-types/clockid_t.h b/libc/include/llvm-libc-types/clockid_t.h new file mode 100644 index 000000000000..4b059599502c --- /dev/null +++ b/libc/include/llvm-libc-types/clockid_t.h @@ -0,0 +1,14 @@ +//===-- Definition of the type clockid_t ----------------------------------===// +// +// 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_TYPES_CLOCKID_T_H +#define LLVM_LIBC_TYPES_CLOCKID_T_H + +typedef int clockid_t; + +#endif // LLVM_LIBC_TYPES_CLOCKID_T_H diff --git a/libc/include/llvm-libc-types/cnd_t.h b/libc/include/llvm-libc-types/cnd_t.h new file mode 100644 index 000000000000..77ec58352f07 --- /dev/null +++ b/libc/include/llvm-libc-types/cnd_t.h @@ -0,0 +1,20 @@ +//===-- Definition of cnd_t 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_TYPES_CND_T_H +#define LLVM_LIBC_TYPES_CND_T_H + +#include "__futex_word.h" + +typedef struct { + void *__qfront; + void *__qback; + __futex_word __qmtx; +} cnd_t; + +#endif // LLVM_LIBC_TYPES_CND_T_H diff --git a/libc/include/llvm-libc-types/cookie_io_functions_t.h b/libc/include/llvm-libc-types/cookie_io_functions_t.h new file mode 100644 index 000000000000..d1eea8ff3b5d --- /dev/null +++ b/libc/include/llvm-libc-types/cookie_io_functions_t.h @@ -0,0 +1,28 @@ +//===-- Definition of type cookie_io_functions_t --------------------------===// +// +// 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_TYPES_COOKIE_IO_FUNCTIONS_T_H +#define LLVM_LIBC_TYPES_COOKIE_IO_FUNCTIONS_T_H + +#include "off64_t.h" +#include "size_t.h" +#include "ssize_t.h" + +typedef ssize_t cookie_read_function_t(void *, char *, size_t); +typedef ssize_t cookie_write_function_t(void *, const char *, size_t); +typedef int cookie_seek_function_t(void *, off64_t *, int); +typedef int cookie_close_function_t(void *); + +typedef struct { + cookie_read_function_t *read; + cookie_write_function_t *write; + cookie_seek_function_t *seek; + cookie_close_function_t *close; +} cookie_io_functions_t; + +#endif // LLVM_LIBC_TYPES_COOKIE_IO_FUNCTIONS_T_H diff --git a/libc/include/llvm-libc-types/cpu_set_t.h b/libc/include/llvm-libc-types/cpu_set_t.h new file mode 100644 index 000000000000..8c6859de5f1d --- /dev/null +++ b/libc/include/llvm-libc-types/cpu_set_t.h @@ -0,0 +1,21 @@ +//===-- Definition of a cpu_set_t 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_TYPES_CPU_SET_T_H +#define LLVM_LIBC_TYPES_CPU_SET_T_H + +#define __CPU_SETSIZE 1024 +#define __NCPUBITS (8 * sizeof(unsigned long)) + +typedef struct { + // If a processor with more than 1024 CPUs is to be supported in future, + // we need to adjust the size of this array. + unsigned long __mask[128 / sizeof(unsigned long)]; +} cpu_set_t; + +#endif // LLVM_LIBC_TYPES_CPU_SET_T_H diff --git a/libc/include/llvm-libc-types/dev_t.h b/libc/include/llvm-libc-types/dev_t.h new file mode 100644 index 000000000000..3181e3415f2e --- /dev/null +++ b/libc/include/llvm-libc-types/dev_t.h @@ -0,0 +1,14 @@ +//===-- Definition of dev_t 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_TYPES_DEV_T_H +#define LLVM_LIBC_TYPES_DEV_T_H + +typedef __UINT64_TYPE__ dev_t; + +#endif // LLVM_LIBC_TYPES_DEV_T_H diff --git a/libc/include/llvm-libc-types/div_t.h b/libc/include/llvm-libc-types/div_t.h new file mode 100644 index 000000000000..450603d69f35 --- /dev/null +++ b/libc/include/llvm-libc-types/div_t.h @@ -0,0 +1,17 @@ +//===-- Definition of type div_t ------------------------------------------===// +// +// 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_TYPES_DIV_T_H +#define LLVM_LIBC_TYPES_DIV_T_H + +typedef struct { + int quot; + int rem; +} div_t; + +#endif // LLVM_LIBC_TYPES_DIV_T_H diff --git a/libc/include/llvm-libc-types/double_t.h b/libc/include/llvm-libc-types/double_t.h new file mode 100644 index 000000000000..c4ad08afddfa --- /dev/null +++ b/libc/include/llvm-libc-types/double_t.h @@ -0,0 +1,24 @@ +//===-- Definition of double_t 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_TYPES_DOUBLE_T_H +#define LLVM_LIBC_TYPES_DOUBLE_T_H + +#if !defined(__FLT_EVAL_METHOD__) || __FLT_EVAL_METHOD__ == 0 +#define __LLVM_LIBC_DOUBLE_T double +#elif __FLT_EVAL_METHOD__ == 1 +#define __LLVM_LIBC_DOUBLE_T double +#elif __FLT_EVAL_METHOD__ == 2 +#define __LLVM_LIBC_DOUBLE_T long double +#else +#error "Unsupported __FLT_EVAL_METHOD__ value." +#endif + +typedef __LLVM_LIBC_DOUBLE_T double_t; + +#endif // LLVM_LIBC_TYPES_DOUBLE_T_H diff --git a/libc/include/llvm-libc-types/fd_set.h b/libc/include/llvm-libc-types/fd_set.h new file mode 100644 index 000000000000..52b716185566 --- /dev/null +++ b/libc/include/llvm-libc-types/fd_set.h @@ -0,0 +1,18 @@ +//===-- Definition of fd_set 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_TYPES_FD_SET_H +#define LLVM_LIBC_TYPES_FD_SET_H + +#include "../llvm-libc-macros/sys-select-macros.h" // __FD_SET_WORD_TYPE, __FD_SET_ARRAYSIZE + +typedef struct { + __FD_SET_WORD_TYPE __set[__FD_SET_ARRAYSIZE]; +} fd_set; + +#endif // LLVM_LIBC_TYPES_FD_SET_H diff --git a/libc/include/llvm-libc-types/fenv_t.h b/libc/include/llvm-libc-types/fenv_t.h new file mode 100644 index 000000000000..c83f23894c0c --- /dev/null +++ b/libc/include/llvm-libc-types/fenv_t.h @@ -0,0 +1,36 @@ +//===-- Definition of type fenv_t -----------------------------------------===// +// +// 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_TYPES_FENV_T_H +#define LLVM_LIBC_TYPES_FENV_T_H + +#ifdef __aarch64__ +typedef struct { + unsigned char __control_word[4]; + unsigned char __status_word[4]; +} fenv_t; +#elif defined(__x86_64__) +typedef struct { + unsigned char __x86_status[28]; + unsigned char __mxcsr[4]; +} fenv_t; +#elif defined(__arm__) || defined(_M_ARM) +typedef struct { + unsigned int __fpscr; +} fenv_t; +#elif defined(__riscv) +typedef unsigned int fenv_t; +#elif defined(__AMDGPU__) || defined(__NVPTX__) +typedef struct { + unsigned int __fpc; +} fenv_t; +#else +#error "fenv_t not defined for your platform" +#endif + +#endif // LLVM_LIBC_TYPES_FENV_T_H diff --git a/libc/include/llvm-libc-types/fexcept_t.h b/libc/include/llvm-libc-types/fexcept_t.h new file mode 100644 index 000000000000..5aa09fbbaffc --- /dev/null +++ b/libc/include/llvm-libc-types/fexcept_t.h @@ -0,0 +1,18 @@ +//===-- Definition of fexcept_t 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_TYPES_FEXCEPT_T_H +#define LLVM_LIBC_TYPES_FEXCEPT_T_H + +#if defined(__x86_64__) || defined(__i386__) +typedef unsigned short int fexcept_t; +#else +typedef unsigned int fexcept_t; +#endif + +#endif // LLVM_LIBC_TYPES_FEXCEPT_T_H diff --git a/libc/include/llvm-libc-types/float128.h b/libc/include/llvm-libc-types/float128.h new file mode 100644 index 000000000000..82ebb79f1f58 --- /dev/null +++ b/libc/include/llvm-libc-types/float128.h @@ -0,0 +1,36 @@ +//===-- Definition of float128 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_TYPES_FLOAT128_H +#define LLVM_LIBC_TYPES_FLOAT128_H + +#include "../llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG + +// Currently, C23 `_Float128` type is only defined as a built-in type in GCC 7 +// or later, and only for C. For C++, or for clang, `__float128` is defined +// instead, and only on x86-64 targets. +// +// TODO: Update C23 `_Float128` type detection again when clang supports it. +// https://github.com/llvm/llvm-project/issues/80195 +#if defined(__STDC_IEC_60559_BFP__) && !defined(__clang__) && \ + !defined(__cplusplus) +#define LIBC_TYPES_HAS_FLOAT128 +typedef _Float128 float128; +#elif defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__) +// Use __float128 type. gcc and clang sometime use __SIZEOF_FLOAT128__ to +// notify the availability of __float128. +// clang also uses __FLOAT128__ macro to notify the availability of __float128 +// type: https://reviews.llvm.org/D15120 +#define LIBC_TYPES_HAS_FLOAT128 +typedef __float128 float128; +#elif (LDBL_MANT_DIG == 113) +#define LIBC_TYPES_HAS_FLOAT128 +typedef long double float128; +#endif + +#endif // LLVM_LIBC_TYPES_FLOAT128_H diff --git a/libc/include/llvm-libc-types/float_t.h b/libc/include/llvm-libc-types/float_t.h new file mode 100644 index 000000000000..5027249c30d3 --- /dev/null +++ b/libc/include/llvm-libc-types/float_t.h @@ -0,0 +1,24 @@ +//===-- Definition of float_t 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_TYPES_FLOAT_T_H +#define LLVM_LIBC_TYPES_FLOAT_T_H + +#if !defined(__FLT_EVAL_METHOD__) || __FLT_EVAL_METHOD__ == 0 +#define __LLVM_LIBC_FLOAT_T float +#elif __FLT_EVAL_METHOD__ == 1 +#define __LLVM_LIBC_FLOAT_T double +#elif __FLT_EVAL_METHOD__ == 2 +#define __LLVM_LIBC_FLOAT_T long double +#else +#error "Unsupported __FLT_EVAL_METHOD__ value." +#endif + +typedef __LLVM_LIBC_FLOAT_T float_t; + +#endif // LLVM_LIBC_TYPES_FLOAT_T_H diff --git a/libc/include/llvm-libc-types/fsblkcnt_t.h b/libc/include/llvm-libc-types/fsblkcnt_t.h new file mode 100644 index 000000000000..8c7d3307278c --- /dev/null +++ b/libc/include/llvm-libc-types/fsblkcnt_t.h @@ -0,0 +1,14 @@ +//===-- Definition of fsblkcnt_t 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_TYPES_FSBLKCNT_T_H +#define LLVM_LIBC_TYPES_FSBLKCNT_T_H + +typedef __UINT64_TYPE__ fsblkcnt_t; + +#endif // LLVM_LIBC_TYPES_FSBLKCNT_T_H diff --git a/libc/include/llvm-libc-types/fsfilcnt_t.h b/libc/include/llvm-libc-types/fsfilcnt_t.h new file mode 100644 index 000000000000..12697830e92e --- /dev/null +++ b/libc/include/llvm-libc-types/fsfilcnt_t.h @@ -0,0 +1,14 @@ +//===-- Definition of fsfilcnt_t 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_TYPES_FSFILCNT_T_H +#define LLVM_LIBC_TYPES_FSFILCNT_T_H + +typedef __UINT64_TYPE__ fsfilcnt_t; + +#endif // LLVM_LIBC_TYPES_FSFILCNT_T_H diff --git a/libc/include/llvm-libc-types/gid_t.h b/libc/include/llvm-libc-types/gid_t.h new file mode 100644 index 000000000000..cfe36ce9906b --- /dev/null +++ b/libc/include/llvm-libc-types/gid_t.h @@ -0,0 +1,14 @@ +//===-- Definition of gid_t 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_TYPES_GID_T_H +#define LLVM_LIBC_TYPES_GID_T_H + +typedef __UINT32_TYPE__ gid_t; + +#endif // LLVM_LIBC_TYPES_GID_T_H diff --git a/libc/include/llvm-libc-types/imaxdiv_t.h b/libc/include/llvm-libc-types/imaxdiv_t.h new file mode 100644 index 000000000000..5062b643065a --- /dev/null +++ b/libc/include/llvm-libc-types/imaxdiv_t.h @@ -0,0 +1,17 @@ +//===-- Definition of type imaxdiv_t --------------------------------------===// +// +// 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_TYPES_IMAXDIV_T_H__ +#define __LLVM_LIBC_TYPES_IMAXDIV_T_H__ + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +#endif // __LLVM_LIBC_TYPES_IMAXDIV_T_H__ diff --git a/libc/include/llvm-libc-types/ino_t.h b/libc/include/llvm-libc-types/ino_t.h new file mode 100644 index 000000000000..148bd67f98fe --- /dev/null +++ b/libc/include/llvm-libc-types/ino_t.h @@ -0,0 +1,14 @@ +//===-- Definition of ino_t 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_TYPES_INO_T_H +#define LLVM_LIBC_TYPES_INO_T_H + +typedef __UINTPTR_TYPE__ ino_t; + +#endif // LLVM_LIBC_TYPES_INO_T_H diff --git a/libc/include/llvm-libc-types/jmp_buf.h b/libc/include/llvm-libc-types/jmp_buf.h new file mode 100644 index 000000000000..8a7d2839e21d --- /dev/null +++ b/libc/include/llvm-libc-types/jmp_buf.h @@ -0,0 +1,84 @@ +//===-- Definition of type jmp_buf ----------------------------------------===// +// +// 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_TYPES_JMP_BUF_H +#define LLVM_LIBC_TYPES_JMP_BUF_H + +// TODO: implement sigjmp_buf related functions for other architectures +// Issue: https://github.com/llvm/llvm-project/issues/136358 +#if defined(__linux__) +#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ + defined(__arm__) || defined(__riscv) +#define __LIBC_HAS_SIGJMP_BUF +#endif +#endif + +#if defined(__LIBC_HAS_SIGJMP_BUF) +#include "sigset_t.h" +#endif + +typedef struct { +#ifdef __x86_64__ + __UINT64_TYPE__ rbx; + __UINT64_TYPE__ rbp; + __UINT64_TYPE__ r12; + __UINT64_TYPE__ r13; + __UINT64_TYPE__ r14; + __UINT64_TYPE__ r15; + __UINTPTR_TYPE__ rsp; + __UINTPTR_TYPE__ rip; +#elif defined(__i386__) + long ebx; + long esi; + long edi; + long ebp; + long esp; + long eip; +#elif defined(__riscv) + /* Program counter. */ + long int __pc; + /* Callee-saved registers. */ + long int __regs[12]; + /* Stack pointer. */ + long int __sp; + /* Callee-saved floating point registers. */ +#if __riscv_float_abi_double + double __fpregs[12]; +#elif defined(__riscv_float_abi_single) +#error "__jmp_buf not available for your target architecture." +#endif +#elif defined(__arm__) + // r4, r5, r6, r7, r8, r9, r10, r11, r12, lr + long opaque[10]; +#elif defined(__aarch64__) + long opaque[14]; // x19-x29, lr, sp, optional x18 +#if __ARM_FP + long fopaque[8]; // d8-d15 +#endif +#else +#error "__jmp_buf not available for your target architecture." +#endif +#if defined(__LIBC_HAS_SIGJMP_BUF) + // return address + void *sig_retaddr; + // extra register buffer to avoid indefinite stack growth in sigsetjmp + void *sig_extra; + // signal masks + sigset_t sigmask; +#endif +} __jmp_buf; + +typedef __jmp_buf jmp_buf[1]; + +#if defined(__LIBC_HAS_SIGJMP_BUF) +typedef __jmp_buf sigjmp_buf[1]; +#endif + +#undef __LIBC_HAS_SIGJMP_BUF + +#endif // LLVM_LIBC_TYPES_JMP_BUF_H diff --git a/libc/include/llvm-libc-types/ldiv_t.h b/libc/include/llvm-libc-types/ldiv_t.h new file mode 100644 index 000000000000..5c64ec10d918 --- /dev/null +++ b/libc/include/llvm-libc-types/ldiv_t.h @@ -0,0 +1,17 @@ +//===-- Definition of type ldiv_t -----------------------------------------===// +// +// 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_TYPES_LDIV_T_H +#define LLVM_LIBC_TYPES_LDIV_T_H + +typedef struct { + long quot; + long rem; +} ldiv_t; + +#endif // LLVM_LIBC_TYPES_LDIV_T_H diff --git a/libc/include/llvm-libc-types/lldiv_t.h b/libc/include/llvm-libc-types/lldiv_t.h new file mode 100644 index 000000000000..5b8dcbef9470 --- /dev/null +++ b/libc/include/llvm-libc-types/lldiv_t.h @@ -0,0 +1,17 @@ +//===-- Definition of type lldiv_t ----------------------------------------===// +// +// 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_TYPES_LLDIV_T_H +#define LLVM_LIBC_TYPES_LLDIV_T_H + +typedef struct { + long long quot; + long long rem; +} lldiv_t; + +#endif // LLVM_LIBC_TYPES_LLDIV_T_H diff --git a/libc/include/llvm-libc-types/locale_t.h b/libc/include/llvm-libc-types/locale_t.h new file mode 100644 index 000000000000..6d783001acf9 --- /dev/null +++ b/libc/include/llvm-libc-types/locale_t.h @@ -0,0 +1,22 @@ +//===-- Definition of type locale_t ---------------------------------------===// +// +// 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_TYPES_LOCALE_T_H +#define LLVM_LIBC_TYPES_LOCALE_T_H + +#define NUM_LOCALE_CATEGORIES 6 + +struct __locale_data; + +struct __locale_t { + struct __locale_data *data[NUM_LOCALE_CATEGORIES]; +}; + +typedef struct __locale_t *locale_t; + +#endif // LLVM_LIBC_TYPES_LOCALE_T_H diff --git a/libc/include/llvm-libc-types/mbstate_t.h b/libc/include/llvm-libc-types/mbstate_t.h new file mode 100644 index 000000000000..009fe57da50e --- /dev/null +++ b/libc/include/llvm-libc-types/mbstate_t.h @@ -0,0 +1,20 @@ +//===-- Definition of mbstate_t 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_TYPES_MBSTATE_T_H +#define LLVM_LIBC_TYPES_MBSTATE_T_H + +#include "../llvm-libc-macros/stdint-macros.h" + +typedef struct { + uint32_t __field1; + uint8_t __field2; + uint8_t __field3; +} mbstate_t; + +#endif // LLVM_LIBC_TYPES_MBSTATE_T_H diff --git a/libc/include/llvm-libc-types/mode_t.h b/libc/include/llvm-libc-types/mode_t.h new file mode 100644 index 000000000000..fe09060d9a6e --- /dev/null +++ b/libc/include/llvm-libc-types/mode_t.h @@ -0,0 +1,14 @@ +//===-- Definition of mode_t 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_TYPES_MODE_T_H +#define LLVM_LIBC_TYPES_MODE_T_H + +typedef unsigned mode_t; + +#endif // LLVM_LIBC_TYPES_MODE_T_H diff --git a/libc/include/llvm-libc-types/mtx_t.h b/libc/include/llvm-libc-types/mtx_t.h new file mode 100644 index 000000000000..56e41bdf89bc --- /dev/null +++ b/libc/include/llvm-libc-types/mtx_t.h @@ -0,0 +1,16 @@ +//===-- Definition of mtx_t 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_TYPES_MTX_T_H +#define LLVM_LIBC_TYPES_MTX_T_H + +#include "__mutex_type.h" + +typedef __mutex_type mtx_t; + +#endif // LLVM_LIBC_TYPES_MTX_T_H diff --git a/libc/include/llvm-libc-types/nfds_t.h b/libc/include/llvm-libc-types/nfds_t.h new file mode 100644 index 000000000000..c0abccee8a7d --- /dev/null +++ b/libc/include/llvm-libc-types/nfds_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type nfds_t -----------------------------------------===// +// +// 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_TYPES_NFDS_T_H +#define LLVM_LIBC_TYPES_NFDS_T_H + +typedef unsigned int nfds_t; + +#endif // LLVM_LIBC_TYPES_NFDS_T_H diff --git a/libc/include/llvm-libc-types/nlink_t.h b/libc/include/llvm-libc-types/nlink_t.h new file mode 100644 index 000000000000..7e0016a9af95 --- /dev/null +++ b/libc/include/llvm-libc-types/nlink_t.h @@ -0,0 +1,14 @@ +//===-- Definition of nlink_t 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_TYPES_NLINK_T_H +#define LLVM_LIBC_TYPES_NLINK_T_H + +typedef __UINTPTR_TYPE__ nlink_t; + +#endif // LLVM_LIBC_TYPES_NLINK_T_H diff --git a/libc/include/llvm-libc-types/off64_t.h b/libc/include/llvm-libc-types/off64_t.h new file mode 100644 index 000000000000..669698a8c05f --- /dev/null +++ b/libc/include/llvm-libc-types/off64_t.h @@ -0,0 +1,14 @@ +//===-- Definition of off64_t 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_TYPES_OFF64_T_H +#define LLVM_LIBC_TYPES_OFF64_T_H + +typedef __INT64_TYPE__ off64_t; + +#endif // LLVM_LIBC_TYPES_OFF64_T_H diff --git a/libc/include/llvm-libc-types/off_t.h b/libc/include/llvm-libc-types/off_t.h new file mode 100644 index 000000000000..63224b6831d5 --- /dev/null +++ b/libc/include/llvm-libc-types/off_t.h @@ -0,0 +1,14 @@ +//===-- Definition of off_t 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_TYPES_OFF_T_H +#define LLVM_LIBC_TYPES_OFF_T_H + +typedef __INT64_TYPE__ off_t; + +#endif // LLVM_LIBC_TYPES_OFF_T_H diff --git a/libc/include/llvm-libc-types/once_flag.h b/libc/include/llvm-libc-types/once_flag.h new file mode 100644 index 000000000000..b3b7e0de988c --- /dev/null +++ b/libc/include/llvm-libc-types/once_flag.h @@ -0,0 +1,20 @@ +//===-- Definition of once_flag 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_TYPES_ONCE_FLAG_H +#define LLVM_LIBC_TYPES_ONCE_FLAG_H + +#include "__futex_word.h" + +#ifdef __linux__ +typedef __futex_word once_flag; +#else +#error "Once flag type not defined for the target platform." +#endif + +#endif // LLVM_LIBC_TYPES_ONCE_FLAG_H diff --git a/libc/include/llvm-libc-types/pid_t.h b/libc/include/llvm-libc-types/pid_t.h new file mode 100644 index 000000000000..0397bd249032 --- /dev/null +++ b/libc/include/llvm-libc-types/pid_t.h @@ -0,0 +1,14 @@ +//===-- Definition of pid_t 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_TYPES_PID_T_H +#define LLVM_LIBC_TYPES_PID_T_H + +typedef __INT32_TYPE__ pid_t; + +#endif // LLVM_LIBC_TYPES_PID_T_H diff --git a/libc/include/llvm-libc-types/posix_spawn_file_actions_t.h b/libc/include/llvm-libc-types/posix_spawn_file_actions_t.h new file mode 100644 index 000000000000..3062da3a54b5 --- /dev/null +++ b/libc/include/llvm-libc-types/posix_spawn_file_actions_t.h @@ -0,0 +1,17 @@ +//===-- Definition of type posix_spawn_file_actions_t ---------------------===// +// +// 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_TYPES_POSIX_SPAWN_FILE_ACTIONS_T_H +#define LLVM_LIBC_TYPES_POSIX_SPAWN_FILE_ACTIONS_T_H + +typedef struct { + void *__front; + void *__back; +} posix_spawn_file_actions_t; + +#endif // LLVM_LIBC_TYPES_POSIX_SPAWN_FILE_ACTIONS_T_H diff --git a/libc/include/llvm-libc-types/posix_spawnattr_t.h b/libc/include/llvm-libc-types/posix_spawnattr_t.h new file mode 100644 index 000000000000..47cadc7cdda1 --- /dev/null +++ b/libc/include/llvm-libc-types/posix_spawnattr_t.h @@ -0,0 +1,16 @@ +//===-- Definition of type posix_spawn_file_actions_t ---------------------===// +// +// 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_TYPES_POSIX_SPAWNATTR_T_H +#define LLVM_LIBC_TYPES_POSIX_SPAWNATTR_T_H + +typedef struct { + // This data structure will be populated as required. +} posix_spawnattr_t; + +#endif // LLVM_LIBC_TYPES_POSIX_SPAWNATTR_T_H diff --git a/libc/include/llvm-libc-types/pthread_attr_t.h b/libc/include/llvm-libc-types/pthread_attr_t.h new file mode 100644 index 000000000000..e686ac91a6fe --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_attr_t.h @@ -0,0 +1,21 @@ +//===-- Definition of pthread_attr_t 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_TYPES_PTHREAD_ATTR_T_H +#define LLVM_LIBC_TYPES_PTHREAD_ATTR_T_H + +#include "size_t.h" + +typedef struct { + int __detachstate; + void *__stack; + size_t __stacksize; + size_t __guardsize; +} pthread_attr_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_ATTR_T_H diff --git a/libc/include/llvm-libc-types/pthread_condattr_t.h b/libc/include/llvm-libc-types/pthread_condattr_t.h new file mode 100644 index 000000000000..b91fc2950aa3 --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_condattr_t.h @@ -0,0 +1,18 @@ +//===-- Definition of pthread_condattr_t 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_TYPES_PTHREAD_CONDATTR_T_H +#define LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H + +#include "clockid_t.h" + +typedef struct { + clockid_t clock; + int pshared; +} pthread_condattr_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H diff --git a/libc/include/llvm-libc-types/pthread_key_t.h b/libc/include/llvm-libc-types/pthread_key_t.h new file mode 100644 index 000000000000..e73c7e26c17c --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_key_t.h @@ -0,0 +1,14 @@ +//===-- Definition of the type pthread_key_t ------------------------------===// +// +// 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_TYPES_PTHREAD_KEY_T_H +#define LLVM_LIBC_TYPES_PTHREAD_KEY_T_H + +typedef unsigned int pthread_key_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_KEY_T_H diff --git a/libc/include/llvm-libc-types/pthread_mutex_t.h b/libc/include/llvm-libc-types/pthread_mutex_t.h new file mode 100644 index 000000000000..1535cba65835 --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_mutex_t.h @@ -0,0 +1,16 @@ +//===-- Definition of pthread_mutex_t 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_TYPES_PTHREAD_MUTEX_T_H +#define LLVM_LIBC_TYPES_PTHREAD_MUTEX_T_H + +#include "__mutex_type.h" + +typedef __mutex_type pthread_mutex_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_MUTEX_T_H diff --git a/libc/include/llvm-libc-types/pthread_mutexattr_t.h b/libc/include/llvm-libc-types/pthread_mutexattr_t.h new file mode 100644 index 000000000000..8f159a61420c --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_mutexattr_t.h @@ -0,0 +1,16 @@ +//===-- Definition of pthread_mutexattr_t 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_TYPES_PTHREAD_MUTEXATTR_T_H +#define LLVM_LIBC_TYPES_PTHREAD_MUTEXATTR_T_H + +// pthread_mutexattr_t is a collection bit mapped flags. The mapping is internal +// detail of the libc implementation. +typedef unsigned int pthread_mutexattr_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_MUTEXATTR_T_H diff --git a/libc/include/llvm-libc-types/pthread_once_t.h b/libc/include/llvm-libc-types/pthread_once_t.h new file mode 100644 index 000000000000..12a81502baaf --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_once_t.h @@ -0,0 +1,20 @@ +//===-- Definition of pthread_once_t 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_TYPES_PTHREAD_ONCE_T_H +#define LLVM_LIBC_TYPES_PTHREAD_ONCE_T_H + +#include "__futex_word.h" + +#ifdef __linux__ +typedef __futex_word pthread_once_t; +#else +#error "Once flag type not defined for the target platform." +#endif + +#endif // LLVM_LIBC_TYPES_PTHREAD_ONCE_T_H diff --git a/libc/include/llvm-libc-types/pthread_rwlock_t.h b/libc/include/llvm-libc-types/pthread_rwlock_t.h new file mode 100644 index 000000000000..4a7c6c75250a --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_rwlock_t.h @@ -0,0 +1,26 @@ +//===-- Definition of pthread_mutex_t 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_TYPES_PTHREAD_RWLOCK_T_H +#define LLVM_LIBC_TYPES_PTHREAD_RWLOCK_T_H + +#include "__futex_word.h" +#include "pid_t.h" +typedef struct { + unsigned __is_pshared : 1; + unsigned __preference : 1; + int __state; + pid_t __writer_tid; + __futex_word __wait_queue_mutex; + __futex_word __pending_readers; + __futex_word __pending_writers; + __futex_word __reader_serialization; + __futex_word __writer_serialization; +} pthread_rwlock_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_RWLOCK_T_H diff --git a/libc/include/llvm-libc-types/pthread_rwlockattr_t.h b/libc/include/llvm-libc-types/pthread_rwlockattr_t.h new file mode 100644 index 000000000000..397c8440402a --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_rwlockattr_t.h @@ -0,0 +1,16 @@ +//===-- Definition of pthread_rwlockattr_t 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_TYPES_PTHREAD_RWLOCKATTR_T_H +#define LLVM_LIBC_TYPES_PTHREAD_RWLOCKATTR_T_H + +typedef struct { + int pshared; + int pref; +} pthread_rwlockattr_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_RWLOCKATTR_T_H diff --git a/libc/include/llvm-libc-types/pthread_spinlock_t.h b/libc/include/llvm-libc-types/pthread_spinlock_t.h new file mode 100644 index 000000000000..afb4fe91edd2 --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_spinlock_t.h @@ -0,0 +1,17 @@ +//===-- Definition of pthread_spinlock_t 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_TYPES_PTHREAD_SPINLOCK_T_H +#define LLVM_LIBC_TYPES_PTHREAD_SPINLOCK_T_H +#include "pid_t.h" +typedef struct { + unsigned char __lockword; + pid_t __owner; +} pthread_spinlock_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_SPINLOCK_T_H diff --git a/libc/include/llvm-libc-types/pthread_t.h b/libc/include/llvm-libc-types/pthread_t.h new file mode 100644 index 000000000000..f64887b25225 --- /dev/null +++ b/libc/include/llvm-libc-types/pthread_t.h @@ -0,0 +1,16 @@ +//===-- Definition of pthread_t 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_TYPES_PTHREAD_T_H +#define LLVM_LIBC_TYPES_PTHREAD_T_H + +#include "__thread_type.h" + +typedef __thread_type pthread_t; + +#endif // LLVM_LIBC_TYPES_PTHREAD_T_H diff --git a/libc/include/llvm-libc-types/rlim_t.h b/libc/include/llvm-libc-types/rlim_t.h new file mode 100644 index 000000000000..016ec7bdc5b1 --- /dev/null +++ b/libc/include/llvm-libc-types/rlim_t.h @@ -0,0 +1,14 @@ +//===-- Definition of type rlim_t -----------------------------------------===// +// +// 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_TYPES_RLIM_T_H +#define LLVM_LIBC_TYPES_RLIM_T_H + +typedef __UINT64_TYPE__ rlim_t; + +#endif // LLVM_LIBC_TYPES_RLIM_T_H diff --git a/libc/include/llvm-libc-types/sa_family_t.h b/libc/include/llvm-libc-types/sa_family_t.h new file mode 100644 index 000000000000..0a010b678ddb --- /dev/null +++ b/libc/include/llvm-libc-types/sa_family_t.h @@ -0,0 +1,19 @@ +//===-- Definition of sa_family_t 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_TYPES_SA_FAMILY_T_H +#define LLVM_LIBC_TYPES_SA_FAMILY_T_H + +// The posix standard only says of sa_family_t that it must be unsigned. The +// linux man page for "address_families" lists approximately 32 different +// address families, meaning that a short 16 bit number will have plenty of +// space for all of them. + +typedef unsigned short sa_family_t; + +#endif // LLVM_LIBC_TYPES_SA_FAMILY_T_H diff --git a/libc/include/llvm-libc-types/sig_atomic_t.h b/libc/include/llvm-libc-types/sig_atomic_t.h new file mode 100644 index 000000000000..2ef375806791 --- /dev/null +++ b/libc/include/llvm-libc-types/sig_atomic_t.h @@ -0,0 +1,14 @@ +//===-- Definition of sig_atomic_t 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_TYPES_SIG_ATOMIC_T_H +#define LLVM_LIBC_TYPES_SIG_ATOMIC_T_H + +typedef int sig_atomic_t; + +#endif // LLVM_LIBC_TYPES_SIG_ATOMIC_T_H diff --git a/libc/include/llvm-libc-types/sighandler_t.h b/libc/include/llvm-libc-types/sighandler_t.h new file mode 100644 index 000000000000..f39ab0468520 --- /dev/null +++ b/libc/include/llvm-libc-types/sighandler_t.h @@ -0,0 +1,17 @@ +//===-- Definition of sighandler_t ----------------------------------------===// +// +// 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_TYPES_SIGHANDLER_T_H +#define LLVM_LIBC_TYPES_SIGHANDLER_T_H + +#ifdef __linux__ +// For compatibility with glibc. +typedef void (*sighandler_t)(int); +#endif + +#endif // LLVM_LIBC_TYPES_SIGHANDLER_T_H diff --git a/libc/include/llvm-libc-types/siginfo_t.h b/libc/include/llvm-libc-types/siginfo_t.h new file mode 100644 index 000000000000..20fdd461bb6d --- /dev/null +++ b/libc/include/llvm-libc-types/siginfo_t.h @@ -0,0 +1,109 @@ +//===-- Definition of siginfo_t 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_TYPES_SIGINFO_T_H +#define LLVM_LIBC_TYPES_SIGINFO_T_H + +#include "clock_t.h" +#include "pid_t.h" +#include "uid_t.h" +#include "union_sigval.h" + +#define SI_MAX_SIZE 128 + +typedef struct { + int si_signo; /* Signal number. */ + int si_errno; /* If non-zero, an errno value associated with + this signal, as defined in <errno.h>. */ + int si_code; /* Signal code. */ + union { + int _si_pad[SI_MAX_SIZE / sizeof(int)]; + + /* kill() */ + struct { + pid_t si_pid; /* sender's pid */ + uid_t si_uid; /* sender's uid */ + } _kill; + + /* POSIX.1b timers */ + struct { + int si_tid; /* timer id */ + int _overrun; /* overrun count */ + union sigval si_sigval; /* same as below */ + } _timer; + + /* POSIX.1b signals */ + struct { + pid_t si_pid; /* sender's pid */ + uid_t si_uid; /* sender's uid */ + union sigval si_sigval; + } _rt; + + /* SIGCHLD */ + struct { + pid_t si_pid; /* which child */ + uid_t si_uid; /* sender's uid */ + int si_status; /* exit code */ + clock_t si_utime; + clock_t si_stime; + } _sigchld; + + /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ + struct { + void *si_addr; /* faulting insn/memory ref. */ + short int si_addr_lsb; /* Valid LSB of the reported address. */ + union { + /* used when si_code=SEGV_BNDERR */ + struct { + void *_lower; + void *_upper; + } _addr_bnd; + /* used when si_code=SEGV_PKUERR */ + __UINT32_TYPE__ _pkey; + } _bounds; + } _sigfault; + + /* SIGPOLL */ + struct { + long int si_band; /* POLL_IN, POLL_OUT, POLL_MSG */ + int si_fd; + } _sigpoll; + + /* SIGSYS */ + struct { + void *_call_addr; /* calling user insn */ + int _syscall; /* triggering system call number */ + unsigned int _arch; /* AUDIT_ARCH_* of syscall */ + } _sigsys; + } _sifields; +} siginfo_t; + +#undef SI_MAX_SIZE + +#define si_pid _sifields._kill.si_pid +#define si_uid _sifields._kill.si_uid +#define si_timerid _sifields._timer.si_tid +#define si_overrun _sifields._timer.si_overrun +#define si_status _sifields._sigchld.si_status +#define si_utime _sifields._sigchld.si_utime +#define si_stime _sifields._sigchld.si_stime +#define si_value _sifields._rt.si_sigval +#define si_int _sifields._rt.si_sigval.sival_int +#define si_ptr _sifields._rt.si_sigval.sival_ptr +#define si_addr _sifields._sigfault.si_addr +#define si_addr_lsb _sifields._sigfault.si_addr_lsb +#define si_lower _sifields._sigfault._bounds._addr_bnd._lower +#define si_upper _sifields._sigfault._bounds._addr_bnd._upper +#define si_pkey _sifields._sigfault._bounds._pkey +#define si_band _sifields._sigpoll.si_band +#define si_fd _sifields._sigpoll.si_fd +#define si_call_addr _sifields._sigsys._call_addr +#define si_syscall _sifields._sigsys._syscall +#define si_arch _sifields._sigsys._arch + +#endif // LLVM_LIBC_TYPES_SIGINFO_T_H diff --git a/libc/include/llvm-libc-types/sigset_t.h b/libc/include/llvm-libc-types/sigset_t.h new file mode 100644 index 000000000000..8c4d3b49533d --- /dev/null +++ b/libc/include/llvm-libc-types/sigset_t.h @@ -0,0 +1,20 @@ +//===-- Definition of sigset_t 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_TYPES_SIGSET_T_H +#define LLVM_LIBC_TYPES_SIGSET_T_H + +#include "../llvm-libc-macros/signal-macros.h" // __NSIGSET_WORDS + +// This definition can be adjusted/specialized for different targets and +// platforms as necessary. This definition works for Linux on most targets. +typedef struct { + unsigned long __signals[__NSIGSET_WORDS]; +} sigset_t; + +#endif // LLVM_LIBC_TYPES_SIGSET_T_H diff --git a/libc/include/llvm-libc-types/size_t.h b/libc/include/llvm-libc-types/size_t.h new file mode 100644 index 000000000000..26ae68abe0ee --- /dev/null +++ b/libc/include/llvm-libc-types/size_t.h @@ -0,0 +1,14 @@ +//===-- Definition of size_t types ----------------------------------------===// +// +// 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_TYPES_SIZE_T_H +#define LLVM_LIBC_TYPES_SIZE_T_H + +typedef __SIZE_TYPE__ size_t; + +#endif // LLVM_LIBC_TYPES_SIZE_T_H diff --git a/libc/include/llvm-libc-types/socklen_t.h b/libc/include/llvm-libc-types/socklen_t.h new file mode 100644 index 000000000000..5357747f5b83 --- /dev/null +++ b/libc/include/llvm-libc-types/socklen_t.h @@ -0,0 +1,18 @@ +//===-- Definition of socklen_t 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_TYPES_SOCKLEN_T_H +#define LLVM_LIBC_TYPES_SOCKLEN_T_H + +// The posix standard only says of socklen_t that it must be an integer type of +// width of at least 32 bits. The long type is defined as being at least 32 +// bits, so an unsigned long should be fine. + +typedef unsigned long socklen_t; + +#endif // LLVM_LIBC_TYPES_SOCKLEN_T_H diff --git a/libc/include/llvm-libc-types/speed_t.h b/libc/include/llvm-libc-types/speed_t.h new file mode 100644 index 000000000000..9875d3b82a69 --- /dev/null +++ b/libc/include/llvm-libc-types/speed_t.h @@ -0,0 +1,14 @@ +//===-- Definition of speed_t 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_TYPES_SPEED_T_H +#define LLVM_LIBC_TYPES_SPEED_T_H + +typedef unsigned int speed_t; + +#endif // LLVM_LIBC_TYPES_SPEED_T_H diff --git a/libc/include/llvm-libc-types/ssize_t.h b/libc/include/llvm-libc-types/ssize_t.h new file mode 100644 index 000000000000..8f579e2749ba --- /dev/null +++ b/libc/include/llvm-libc-types/ssize_t.h @@ -0,0 +1,14 @@ +//===-- Definition of ssize_t 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_TYPES_SSIZE_T_H +#define LLVM_LIBC_TYPES_SSIZE_T_H + +typedef __PTRDIFF_TYPE__ ssize_t; + +#endif // LLVM_LIBC_TYPES_SSIZE_T_H diff --git a/libc/include/llvm-libc-types/stack_t.h b/libc/include/llvm-libc-types/stack_t.h new file mode 100644 index 000000000000..92d030587168 --- /dev/null +++ b/libc/include/llvm-libc-types/stack_t.h @@ -0,0 +1,22 @@ +//===-- Definition of stack_t 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_TYPES_STACK_T_H +#define LLVM_LIBC_TYPES_STACK_T_H + +#include "size_t.h" + +typedef struct { + // The order of the fields declared here should match the kernel definition + // of stack_t in order for the SYS_sigaltstack syscall to work correctly. + void *ss_sp; + int ss_flags; + size_t ss_size; +} stack_t; + +#endif // LLVM_LIBC_TYPES_STACK_T_H diff --git a/libc/include/llvm-libc-types/stdfix-types.h b/libc/include/llvm-libc-types/stdfix-types.h new file mode 100644 index 000000000000..542d45ea97e9 --- /dev/null +++ b/libc/include/llvm-libc-types/stdfix-types.h @@ -0,0 +1,25 @@ +//===-- Definition of stdfix integer types --------------------------------===// +// +// 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_TYPES_STDFIX_TYPES_H +#define LLVM_LIBC_TYPES_STDFIX_TYPES_H + +typedef signed char int_hr_t; +typedef signed short int int_r_t; +typedef signed int int_lr_t; +typedef signed short int_hk_t; +typedef signed int int_k_t; +typedef signed long long int_lk_t; +typedef unsigned char uint_uhr_t; +typedef unsigned short int uint_ur_t; +typedef unsigned int uint_ulr_t; +typedef unsigned short int uint_uhk_t; +typedef unsigned int uint_uk_t; +typedef unsigned long long uint_ulk_t; + +#endif // LLVM_LIBC_TYPES_STDFIX_TYPES_H diff --git a/libc/include/llvm-libc-types/struct_dirent.h b/libc/include/llvm-libc-types/struct_dirent.h new file mode 100644 index 000000000000..f950869fc77d --- /dev/null +++ b/libc/include/llvm-libc-types/struct_dirent.h @@ -0,0 +1,29 @@ +//===-- Definition of type struct dirent ----------------------------------===// +// +// 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_TYPES_STRUCT_DIRENT_H +#define LLVM_LIBC_TYPES_STRUCT_DIRENT_H + +#include "ino_t.h" +#include "off_t.h" + +struct dirent { + ino_t d_ino; +#ifdef __linux__ + off_t d_off; + unsigned short d_reclen; +#endif + unsigned char d_type; + // The user code should use strlen to determine actual the size of d_name. + // Likewise, it is incorrect and prohibited by the POSIX standard to detemine + // the size of struct dirent type using sizeof. The size should be got using + // a different method, for example, from the d_reclen field on Linux. + char d_name[1]; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_DIRENT_H diff --git a/libc/include/llvm-libc-types/struct_dl_phdr_info.h b/libc/include/llvm-libc-types/struct_dl_phdr_info.h new file mode 100644 index 000000000000..2b9a5d21b4a1 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_dl_phdr_info.h @@ -0,0 +1,30 @@ +//===-- Definition of type struct dl_phdr_info ---------------------------===// +// +// 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_TYPES_STRUCT_DL_PHDR_INFO_H +#define LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H + +#include "../llvm-libc-macros/link-macros.h" +#include "size_t.h" +#include <elf.h> +#include <stdint.h> + +struct dl_phdr_info { + ElfW(Addr) dlpi_addr; + const char *dlpi_name; + const ElfW(Phdr) * dlpi_phdr; + ElfW(Half) dlpi_phnum; + + uint64_t dlpi_adds; + uint64_t dlpi_subs; + + size_t dlpi_tls_modid; + void *dlpi_tls_data; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_DL_PHDR_INFO_H diff --git a/libc/include/llvm-libc-types/struct_epoll_data.h b/libc/include/llvm-libc-types/struct_epoll_data.h new file mode 100644 index 000000000000..7200276a141e --- /dev/null +++ b/libc/include/llvm-libc-types/struct_epoll_data.h @@ -0,0 +1,21 @@ +//===-- Definition of epoll_data 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_TYPES_STRUCT_EPOLL_DATA_H +#define LLVM_LIBC_TYPES_STRUCT_EPOLL_DATA_H + +union epoll_data { + void *ptr; + int fd; + __UINT32_TYPE__ u32; + __UINT64_TYPE__ u64; +}; + +typedef union epoll_data epoll_data_t; + +#endif // LLVM_LIBC_TYPES_STRUCT_EPOLL_DATA_H diff --git a/libc/include/llvm-libc-types/struct_epoll_event.h b/libc/include/llvm-libc-types/struct_epoll_event.h new file mode 100644 index 000000000000..f95fd1a92bc8 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_epoll_event.h @@ -0,0 +1,23 @@ +//===-- Definition of epoll_event 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_TYPES_STRUCT_EPOLL_EVENT_H +#define LLVM_LIBC_TYPES_STRUCT_EPOLL_EVENT_H + +#include "struct_epoll_data.h" + +typedef struct +#ifdef __x86_64__ + [[gnu::packed]] // Necessary for compatibility. +#endif + epoll_event { + __UINT32_TYPE__ events; + epoll_data_t data; +} epoll_event; + +#endif // LLVM_LIBC_TYPES_STRUCT_EPOLL_EVENT_H diff --git a/libc/include/llvm-libc-types/struct_f_owner_ex.h b/libc/include/llvm-libc-types/struct_f_owner_ex.h new file mode 100644 index 000000000000..87d4b8988178 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_f_owner_ex.h @@ -0,0 +1,25 @@ +//===-- Definition of type struct f_owner_ex ------------------------------===// +// +// 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_TYPES_STRUCT_F_OWNER_EX_H +#define LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H + +#include "pid_t.h" + +enum pid_type { + F_OWNER_TID = 0, + F_OWNER_PID, + F_OWNER_PGRP, +}; + +struct f_owner_ex { + enum pid_type type; + pid_t pid; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H diff --git a/libc/include/llvm-libc-types/struct_flock.h b/libc/include/llvm-libc-types/struct_flock.h new file mode 100644 index 000000000000..d4bde09045e8 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_flock.h @@ -0,0 +1,25 @@ +//===-- Definition of type struct flock64 ---------------------------------===// +// +// 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_TYPES_STRUCT_FLOCK_H +#define LLVM_LIBC_TYPES_STRUCT_FLOCK_H + +#include "off_t.h" +#include "pid_t.h" + +#include <stdint.h> + +struct flock { + int16_t l_type; + int16_t l_whence; + off_t l_start; + off_t l_len; + pid_t l_pid; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_FLOCK_H diff --git a/libc/include/llvm-libc-types/struct_flock64.h b/libc/include/llvm-libc-types/struct_flock64.h new file mode 100644 index 000000000000..8e485d737738 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_flock64.h @@ -0,0 +1,25 @@ +//===-- Definition of type struct flock64 ---------------------------------===// +// +// 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_TYPES_STRUCT_FLOCK64_H +#define LLVM_LIBC_TYPES_STRUCT_FLOCK64_H + +#include "off64_t.h" +#include "pid_t.h" + +#include <stdint.h> + +struct flock64 { + int16_t l_type; + int16_t l_whence; + off64_t l_start; + off64_t l_len; + pid_t l_pid; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_FLOCK64_H diff --git a/libc/include/llvm-libc-types/struct_hsearch_data.h b/libc/include/llvm-libc-types/struct_hsearch_data.h new file mode 100644 index 000000000000..cdb1d0c5da14 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_hsearch_data.h @@ -0,0 +1,17 @@ +//===-- Definition of type struct hsearch_data ----------------------------===// +// +// 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_TYPES_STRUCT_HSEARCH_DATA_H +#define LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H + +struct hsearch_data { + void *__opaque; + unsigned int __unused[2]; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H diff --git a/libc/include/llvm-libc-types/struct_iovec.h b/libc/include/llvm-libc-types/struct_iovec.h new file mode 100644 index 000000000000..db2ca64cc1a1 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_iovec.h @@ -0,0 +1,19 @@ +//===-- Definition of struct iovec ----------------------------------------===// +// +// 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_TYPES_STRUCT_IOVEC_H +#define LLVM_LIBC_TYPES_STRUCT_IOVEC_H + +#include "size_t.h" + +struct iovec { + void *iov_base; + size_t iov_len; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_IOVEC_H diff --git a/libc/include/llvm-libc-types/struct_itimerval.h b/libc/include/llvm-libc-types/struct_itimerval.h new file mode 100644 index 000000000000..e23f1e6076df --- /dev/null +++ b/libc/include/llvm-libc-types/struct_itimerval.h @@ -0,0 +1,19 @@ +//===-- Definition of struct itimerval ------------------------------------===// +// +// 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_TYPES_STRUCT_ITIMERVAL_H +#define LLVM_LIBC_TYPES_STRUCT_ITIMERVAL_H + +#include "struct_timeval.h" + +struct itimerval { + struct timeval it_interval; /* Interval for periodic timer */ + struct timeval it_value; /* Time until next expiration */ +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_ITIMERVAL_H diff --git a/libc/include/llvm-libc-types/struct_lconv.h b/libc/include/llvm-libc-types/struct_lconv.h new file mode 100644 index 000000000000..9d69f055484d --- /dev/null +++ b/libc/include/llvm-libc-types/struct_lconv.h @@ -0,0 +1,39 @@ +//===-- Definition of type lconv ------------------------------------------===// +// +// 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_TYPES_LCONV_H +#define LLVM_LIBC_TYPES_LCONV_H + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char *currency_symbol; + char frac_digits; + char p_cs_precedes; + char n_cs_precedes; + char p_sep_by_space; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char *int_curr_symbol; + char int_frac_digits; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + +#endif // LLVM_LIBC_TYPES_LCONV_H diff --git a/libc/include/llvm-libc-types/struct_msghdr.h b/libc/include/llvm-libc-types/struct_msghdr.h new file mode 100644 index 000000000000..7933de190f34 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_msghdr.h @@ -0,0 +1,26 @@ +//===-- Definition of struct msghdr ---------------------------------------===// +// +// 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_TYPES_STRUCT_MSGHDR_H +#define LLVM_LIBC_TYPES_STRUCT_MSGHDR_H + +#include "size_t.h" +#include "socklen_t.h" +#include "struct_iovec.h" + +struct msghdr { + void *msg_name; /* Optional address */ + socklen_t msg_namelen; /* Size of address */ + struct iovec *msg_iov; /* Scatter/gather array */ + size_t msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* Ancillary data, see below */ + size_t msg_controllen; /* Ancillary data buffer len */ + int msg_flags; /* Flags (unused) */ +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_MSGHDR_H diff --git a/libc/include/llvm-libc-types/struct_pollfd.h b/libc/include/llvm-libc-types/struct_pollfd.h new file mode 100644 index 000000000000..80abc8e76efc --- /dev/null +++ b/libc/include/llvm-libc-types/struct_pollfd.h @@ -0,0 +1,18 @@ +//===-- Definition of type struct pollfd ----------------------------------===// +// +// 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_TYPES_STRUCT_POLLFD_H +#define LLVM_LIBC_TYPES_STRUCT_POLLFD_H + +struct pollfd { + int fd; + short events; + short revents; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_POLLFD_H diff --git a/libc/include/llvm-libc-types/struct_rlimit.h b/libc/include/llvm-libc-types/struct_rlimit.h new file mode 100644 index 000000000000..15d8c0e16a64 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_rlimit.h @@ -0,0 +1,19 @@ +//===-- Definition of type struct rlimit ----------------------------------===// +// +// 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_TYPES_STRUCT_RLIMIT_H +#define LLVM_LIBC_TYPES_STRUCT_RLIMIT_H + +#include "rlim_t.h" + +struct rlimit { + rlim_t rlim_cur; + rlim_t rlim_max; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_RLIMIT_H diff --git a/libc/include/llvm-libc-types/struct_rusage.h b/libc/include/llvm-libc-types/struct_rusage.h new file mode 100644 index 000000000000..59fe9f7c1d2b --- /dev/null +++ b/libc/include/llvm-libc-types/struct_rusage.h @@ -0,0 +1,37 @@ +//===-- Definition of type struct rusage ----------------------------------===// +// +// 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_TYPES_STRUCT_RUSAGE_H +#define LLVM_LIBC_TYPES_STRUCT_RUSAGE_H + +#include "struct_timeval.h" + +struct rusage { + struct timeval ru_utime; + struct timeval ru_stime; +#ifdef __linux__ + // Following fields are linux extensions as expected by the + // linux syscalls. + long ru_maxrss; // Maximum resident set size + long ru_ixrss; // Integral shared memory size + long ru_idrss; // Integral unshared data size + long ru_isrss; // Integral unshared stack size + long ru_minflt; // Page reclaims + long ru_majflt; // Page faults + long ru_nswap; // Swaps + long ru_inblock; // Block input operations + long ru_oublock; // Block output operations + long ru_msgsnd; // Messages sent + long ru_msgrcv; // Messages received + long ru_nsignals; // Signals received + long ru_nvcsw; // Voluntary context switches + long ru_nivcsw; // Involuntary context switches +#endif +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_RUSAGE_H diff --git a/libc/include/llvm-libc-types/struct_sched_param.h b/libc/include/llvm-libc-types/struct_sched_param.h new file mode 100644 index 000000000000..e44a00bc0e87 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_sched_param.h @@ -0,0 +1,21 @@ +//===-- Definition of type struct sched_param -----------------------------===// +// +// 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_TYPES_STRUCT_SCHED_PARAM_H +#define LLVM_LIBC_TYPES_STRUCT_SCHED_PARAM_H + +#include "pid_t.h" +#include "struct_timespec.h" +#include "time_t.h" + +struct sched_param { + // Process or thread execution scheduling priority. + int sched_priority; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_SCHED_PARAM_H diff --git a/libc/include/llvm-libc-types/struct_sigaction.h b/libc/include/llvm-libc-types/struct_sigaction.h new file mode 100644 index 000000000000..907418b5e0f9 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_sigaction.h @@ -0,0 +1,28 @@ +//===-- Definition of struct __sigaction ----------------------------------===// +// +// 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_TYPES_STRUCT_SIGACTION_H +#define LLVM_LIBC_TYPES_STRUCT_SIGACTION_H + +#include "siginfo_t.h" +#include "sigset_t.h" + +struct sigaction { + union { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t *, void *); + }; + sigset_t sa_mask; + int sa_flags; +#ifdef __linux__ + // This field is present on linux for most targets. + void (*sa_restorer)(void); +#endif +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_SIGACTION_H diff --git a/libc/include/llvm-libc-types/struct_sockaddr.h b/libc/include/llvm-libc-types/struct_sockaddr.h new file mode 100644 index 000000000000..b7579e9c6ba7 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_sockaddr.h @@ -0,0 +1,21 @@ +//===-- Definition of struct sockaddr -------------------------------------===// +// +// 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_TYPES_STRUCT_SOCKADDR_H +#define LLVM_LIBC_TYPES_STRUCT_SOCKADDR_H + +#include "sa_family_t.h" + +struct sockaddr { + sa_family_t sa_family; + // sa_data is a variable length array. It is provided with a length of one + // here as a placeholder. + char sa_data[1]; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_SOCKADDR_H diff --git a/libc/include/llvm-libc-types/struct_sockaddr_un.h b/libc/include/llvm-libc-types/struct_sockaddr_un.h new file mode 100644 index 000000000000..5ed31a49ebb5 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_sockaddr_un.h @@ -0,0 +1,22 @@ +//===-- Definition of struct sockaddr_un ----------------------------------===// +// +// 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_TYPES_STRUCT_SOCKADDR_UN_H +#define LLVM_LIBC_TYPES_STRUCT_SOCKADDR_UN_H + +#include "sa_family_t.h" + +// This is the sockaddr specialization for AF_UNIX or AF_LOCAL sockets, as +// defined by posix. + +struct sockaddr_un { + sa_family_t sun_family; /* AF_UNIX */ + char sun_path[108]; /* Pathname */ +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_SOCKADDR_UN_H diff --git a/libc/include/llvm-libc-types/struct_stat.h b/libc/include/llvm-libc-types/struct_stat.h new file mode 100644 index 000000000000..4026679f8d67 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_stat.h @@ -0,0 +1,39 @@ +//===-- Definition of struct stat -----------------------------------------===// +// +// 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_TYPES_STRUCT_STAT_H +#define LLVM_LIBC_TYPES_STRUCT_STAT_H + +#include "blkcnt_t.h" +#include "blksize_t.h" +#include "dev_t.h" +#include "gid_t.h" +#include "ino_t.h" +#include "mode_t.h" +#include "nlink_t.h" +#include "off_t.h" +#include "struct_timespec.h" +#include "uid_t.h" + +struct stat { + dev_t st_dev; + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + off_t st_size; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; + blksize_t st_blksize; + blkcnt_t st_blocks; +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_STAT_H diff --git a/libc/include/llvm-libc-types/struct_statvfs.h b/libc/include/llvm-libc-types/struct_statvfs.h new file mode 100644 index 000000000000..9c649af151ff --- /dev/null +++ b/libc/include/llvm-libc-types/struct_statvfs.h @@ -0,0 +1,29 @@ +//===-- Definition of type struct statvfs ---------------------------------===// +// +// 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_TYPES_STRUCT_STATVFS_H +#define LLVM_LIBC_TYPES_STRUCT_STATVFS_H + +#include "fsblkcnt_t.h" +#include "fsfilcnt_t.h" + +struct statvfs { + unsigned long f_bsize; /* Filesystem block size */ + unsigned long f_frsize; /* Fragment size */ + fsblkcnt_t f_blocks; /* Size of fs in f_frsize units */ + fsblkcnt_t f_bfree; /* Number of free blocks */ + fsblkcnt_t f_bavail; /* Number of free blocks for unprivileged users */ + fsfilcnt_t f_files; /* Number of inodes */ + fsfilcnt_t f_ffree; /* Number of free inodes */ + fsfilcnt_t f_favail; /* Number of free inodes for unprivileged users */ + unsigned long f_fsid; /* Filesystem ID */ + unsigned long f_flag; /* Mount flags */ + unsigned long f_namemax; /* Maximum filename length */ +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_STATVFS_H diff --git a/libc/include/llvm-libc-types/struct_termios.h b/libc/include/llvm-libc-types/struct_termios.h new file mode 100644 index 000000000000..e3c5f2809e43 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_termios.h @@ -0,0 +1,32 @@ +//===-- Definition of struct termios --------------------------------------===// +// +// 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_TYPES_STRUCT_TERMIOS_H__ +#define __LLVM_LIBC_TYPES_STRUCT_TERMIOS_H__ + +#include "cc_t.h" +#include "speed_t.h" +#include "tcflag_t.h" + +struct termios { + tcflag_t c_iflag; // Input mode flags + tcflag_t c_oflag; // Output mode flags + tcflag_t c_cflag; // Control mode flags + tcflag_t c_lflag; // Local mode flags +#ifdef __linux__ + cc_t c_line; // Line discipline +#endif // __linux__ + // NCCS is defined in llvm-libc-macros/termios-macros.h. + cc_t c_cc[NCCS]; // Control characters +#ifdef __linux__ + speed_t c_ispeed; // Input speed + speed_t c_ospeed; // output speed +#endif // __linux__ +}; + +#endif // __LLVM_LIBC_TYPES_STRUCT_TERMIOS_H__ diff --git a/libc/include/llvm-libc-types/struct_timespec.h b/libc/include/llvm-libc-types/struct_timespec.h new file mode 100644 index 000000000000..28b5a571f679 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_timespec.h @@ -0,0 +1,20 @@ +//===-- Definition of struct timespec -------------------------------------===// +// +// 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_TYPES_STRUCT_TIMESPEC_H +#define LLVM_LIBC_TYPES_STRUCT_TIMESPEC_H + +#include "time_t.h" + +struct timespec { + time_t tv_sec; /* Seconds. */ + /* TODO: BIG_ENDIAN may require padding. */ + long tv_nsec; /* Nanoseconds. */ +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_TIMESPEC_H diff --git a/libc/include/llvm-libc-types/struct_timeval.h b/libc/include/llvm-libc-types/struct_timeval.h new file mode 100644 index 000000000000..9595d85a46c8 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_timeval.h @@ -0,0 +1,20 @@ +//===-- Definition of struct timeval -------------------------------------===// +// +// 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_TYPES_STRUCT_TIMEVAL_H +#define LLVM_LIBC_TYPES_STRUCT_TIMEVAL_H + +#include "suseconds_t.h" +#include "time_t.h" + +struct timeval { + time_t tv_sec; // Seconds + suseconds_t tv_usec; // Micro seconds +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_TIMEVAL_H diff --git a/libc/include/llvm-libc-types/struct_tm.h b/libc/include/llvm-libc-types/struct_tm.h new file mode 100644 index 000000000000..2ec74ecac029 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_tm.h @@ -0,0 +1,25 @@ +//===-- Definition of struct tm -------------------------------------------===// +// +// 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_TYPES_STRUCT_TM_H +#define LLVM_LIBC_TYPES_STRUCT_TM_H + +struct tm { + int tm_sec; // seconds after the minute + int tm_min; // minutes after the hour + int tm_hour; // hours since midnight + int tm_mday; // day of the month + int tm_mon; // months since January + int tm_year; // years since 1900 + int tm_wday; // days since Sunday + int tm_yday; // days since January + int tm_isdst; // Daylight Saving Time flag + // TODO: add tm_gmtoff and tm_zone? (posix extensions) +}; + +#endif // LLVM_LIBC_TYPES_STRUCT_TM_H diff --git a/libc/include/llvm-libc-types/struct_utsname.h b/libc/include/llvm-libc-types/struct_utsname.h new file mode 100644 index 000000000000..e474171c7285 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_utsname.h @@ -0,0 +1,34 @@ +//===-- Definition of struct utsname --------------------------------------===// +// +// 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_TYPES_STRUCT_UTSNAME_H +#define LLVM_LIBC_TYPES_STRUCT_UTSNAME_H + +#if defined(__linux__) +#define __UTS_NAME_LENGTH 65 +#elif defined(__APPLE__) +#define __UTS_NAME_LENGTH 256 +#else +// Arbitray default. Should be specialized for each platform. +#define __UTS_NAME_LENGTH 1024 +#endif + +struct utsname { + char sysname[__UTS_NAME_LENGTH]; + char nodename[__UTS_NAME_LENGTH]; + char release[__UTS_NAME_LENGTH]; + char version[__UTS_NAME_LENGTH]; + char machine[__UTS_NAME_LENGTH]; +#ifdef __linux__ + char domainname[__UTS_NAME_LENGTH]; +#endif +}; + +#undef __UTS_NAME_LENGTH + +#endif // LLVM_LIBC_TYPES_STRUCT_UTSNAME_H diff --git a/libc/include/llvm-libc-types/suseconds_t.h b/libc/include/llvm-libc-types/suseconds_t.h new file mode 100644 index 000000000000..8e926e8401f5 --- /dev/null +++ b/libc/include/llvm-libc-types/suseconds_t.h @@ -0,0 +1,19 @@ +//===-- Definition of suseconds_t 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_TYPES_SUSECONDS_T_H +#define LLVM_LIBC_TYPES_SUSECONDS_T_H + +// Per posix: suseconds_t shall be a signed integer type capable of storing +// values at least in the range [-1, 1000000]. [...] the widths of [other +// types...] and suseconds_t are no greater than the width of type long. + +// The kernel expects 64 bit suseconds_t at least on x86_64. +typedef long suseconds_t; + +#endif // LLVM_LIBC_TYPES_SUSECONDS_T_H diff --git a/libc/include/llvm-libc-types/tcflag_t.h b/libc/include/llvm-libc-types/tcflag_t.h new file mode 100644 index 000000000000..2978487df434 --- /dev/null +++ b/libc/include/llvm-libc-types/tcflag_t.h @@ -0,0 +1,14 @@ +//===-- Definition of tcflag_t 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_TYPES_TCFLAG_T_H +#define LLVM_LIBC_TYPES_TCFLAG_T_H + +typedef unsigned int tcflag_t; + +#endif // LLVM_LIBC_TYPES_TCFLAG_T_H diff --git a/libc/include/llvm-libc-types/test_rpc_opcodes_t.h b/libc/include/llvm-libc-types/test_rpc_opcodes_t.h new file mode 100644 index 000000000000..7129768dc8b9 --- /dev/null +++ b/libc/include/llvm-libc-types/test_rpc_opcodes_t.h @@ -0,0 +1,21 @@ +//===-- Definition of RPC opcodes used for internal tests -----------------===// +// +// 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_TYPES_TEST_RPC_OPCODES_T_H +#define LLVM_LIBC_TYPES_TEST_RPC_OPCODES_T_H + +// We consider the first 32768 opcodes as reserved for libc purposes. We allow +// extensions to use any other number without conflicting with anything else. +typedef enum : unsigned short { + RPC_TEST_NOOP = 1 << 15, + RPC_TEST_INCREMENT, + RPC_TEST_INTERFACE, + RPC_TEST_STREAM, +} rpc_test_opcode_t; + +#endif // LLVM_LIBC_TYPES_TEST_RPC_OPCODES_T_H diff --git a/libc/include/llvm-libc-types/thrd_start_t.h b/libc/include/llvm-libc-types/thrd_start_t.h new file mode 100644 index 000000000000..1fb21bccc036 --- /dev/null +++ b/libc/include/llvm-libc-types/thrd_start_t.h @@ -0,0 +1,14 @@ +//===-- Definition of thrd_start_t 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_TYPES_THRD_START_T_H +#define LLVM_LIBC_TYPES_THRD_START_T_H + +typedef int (*thrd_start_t)(void *); + +#endif // LLVM_LIBC_TYPES_THRD_START_T_H diff --git a/libc/include/llvm-libc-types/thrd_t.h b/libc/include/llvm-libc-types/thrd_t.h new file mode 100644 index 000000000000..d5f31064f2fe --- /dev/null +++ b/libc/include/llvm-libc-types/thrd_t.h @@ -0,0 +1,16 @@ +//===-- Definition of thrd_t 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_TYPES_THRD_T_H +#define LLVM_LIBC_TYPES_THRD_T_H + +#include "__thread_type.h" + +typedef __thread_type thrd_t; + +#endif // LLVM_LIBC_TYPES_THRD_T_H diff --git a/libc/include/llvm-libc-types/time_t.h b/libc/include/llvm-libc-types/time_t.h new file mode 100644 index 000000000000..76920dc07ec6 --- /dev/null +++ b/libc/include/llvm-libc-types/time_t.h @@ -0,0 +1,18 @@ +//===-- Definition of the type time_t, for use during the libc build ------===// +// +// 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_TYPES_TIME_T_H +#define LLVM_LIBC_TYPES_TIME_T_H + +#ifdef LIBC_TYPES_TIME_T_IS_32_BIT +#include "time_t_32.h" +#else +#include "time_t_64.h" +#endif + +#endif // LLVM_LIBC_TYPES_TIME_T_H diff --git a/libc/include/llvm-libc-types/time_t_32.h b/libc/include/llvm-libc-types/time_t_32.h new file mode 100644 index 000000000000..2c415f6fa9dc --- /dev/null +++ b/libc/include/llvm-libc-types/time_t_32.h @@ -0,0 +1,14 @@ +//===-- Definition of the type time_t -------------------------------------===// +// +// 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_TYPES_TIME_T_32_H +#define LLVM_LIBC_TYPES_TIME_T_32_H + +typedef __INT32_TYPE__ time_t; + +#endif // LLVM_LIBC_TYPES_TIME_T_32_H diff --git a/libc/include/llvm-libc-types/time_t_64.h b/libc/include/llvm-libc-types/time_t_64.h new file mode 100644 index 000000000000..8f7fd3233646 --- /dev/null +++ b/libc/include/llvm-libc-types/time_t_64.h @@ -0,0 +1,14 @@ +//===-- Definition of the type time_t -------------------------------------===// +// +// 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_TYPES_TIME_T_64_H +#define LLVM_LIBC_TYPES_TIME_T_64_H + +typedef __INT64_TYPE__ time_t; + +#endif // LLVM_LIBC_TYPES_TIME_T_64_H diff --git a/libc/include/llvm-libc-types/tss_dtor_t.h b/libc/include/llvm-libc-types/tss_dtor_t.h new file mode 100644 index 000000000000..c54b34e7d8b7 --- /dev/null +++ b/libc/include/llvm-libc-types/tss_dtor_t.h @@ -0,0 +1,14 @@ +//===-- Definition of the type tss_dtor_t ---------------------------------===// +// +// 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_TYPES_TSS_DTOR_T_H +#define LLVM_LIBC_TYPES_TSS_DTOR_T_H + +typedef void (*tss_dtor_t)(void *); + +#endif // LLVM_LIBC_TYPES_TSS_DTOR_T_H diff --git a/libc/include/llvm-libc-types/tss_t.h b/libc/include/llvm-libc-types/tss_t.h new file mode 100644 index 000000000000..92bc7ef451ca --- /dev/null +++ b/libc/include/llvm-libc-types/tss_t.h @@ -0,0 +1,14 @@ +//===-- Definition of the type tss_t --------------------------------------===// +// +// 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_TYPES_TSS_T_H +#define LLVM_LIBC_TYPES_TSS_T_H + +typedef unsigned int tss_t; + +#endif // LLVM_LIBC_TYPES_TSS_T_H diff --git a/libc/include/llvm-libc-types/uid_t.h b/libc/include/llvm-libc-types/uid_t.h new file mode 100644 index 000000000000..4f6c6479186b --- /dev/null +++ b/libc/include/llvm-libc-types/uid_t.h @@ -0,0 +1,14 @@ +//===-- Definition of uid_t 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_TYPES_UID_T_H +#define LLVM_LIBC_TYPES_UID_T_H + +typedef __UINT32_TYPE__ uid_t; + +#endif // LLVM_LIBC_TYPES_UID_T_H diff --git a/libc/include/llvm-libc-types/union_sigval.h b/libc/include/llvm-libc-types/union_sigval.h new file mode 100644 index 000000000000..5f83cd220308 --- /dev/null +++ b/libc/include/llvm-libc-types/union_sigval.h @@ -0,0 +1,17 @@ +//===-- Definition of type union sigval -----------------------------------===// +// +// 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_TYPES_UNION_SIGVAL_H +#define LLVM_LIBC_TYPES_UNION_SIGVAL_H + +union sigval { + int sival_int; + void *sival_ptr; +}; + +#endif // LLVM_LIBC_TYPES_UNION_SIGVAL_H diff --git a/libc/include/llvm-libc-types/wchar_t.h b/libc/include/llvm-libc-types/wchar_t.h new file mode 100644 index 000000000000..bf2633a1c244 --- /dev/null +++ b/libc/include/llvm-libc-types/wchar_t.h @@ -0,0 +1,19 @@ +//===-- Definition of wchar_t types ---------------------------------------===// +// +// 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_TYPES_WCHAR_T_H +#define LLVM_LIBC_TYPES_WCHAR_T_H + +// wchar_t is a fundamental type in C++. +#ifndef __cplusplus + +typedef __WCHAR_TYPE__ wchar_t; + +#endif + +#endif // LLVM_LIBC_TYPES_WCHAR_T_H diff --git a/libc/include/llvm-libc-types/wint_t.h b/libc/include/llvm-libc-types/wint_t.h new file mode 100644 index 000000000000..a53c6e3cb622 --- /dev/null +++ b/libc/include/llvm-libc-types/wint_t.h @@ -0,0 +1,14 @@ +//===-- Definition of wint_t types ----------------------------------------===// +// +// 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_TYPES_WINT_T_H +#define LLVM_LIBC_TYPES_WINT_T_H + +typedef __WINT_TYPE__ wint_t; + +#endif // LLVM_LIBC_TYPES_WINT_T_H diff --git a/libc/include/sys/queue.h b/libc/include/sys/queue.h new file mode 100644 index 000000000000..fc739b4a253b --- /dev/null +++ b/libc/include/sys/queue.h @@ -0,0 +1,14 @@ +//===-- BSD sys/queue.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 SYS_QUEUE_H +#define SYS_QUEUE_H + +#include "../llvm-libc-macros/sys-queue-macros.h" + +#endif // SYS_QUEUE_H |
