diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -112,6 +112,7 @@ ) elseif(ZOS) list(APPEND LIBCXX_SOURCES + include/ceeedb.h support/ibm/mbsnrtowcs.cpp support/ibm/wcsnrtombs.cpp support/ibm/xlocale_zos.cpp diff --git a/libcxx/src/include/ceeedb.h b/libcxx/src/include/ceeedb.h new file mode 100644 --- /dev/null +++ b/libcxx/src/include/ceeedb.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_IBM_CEEEDB_H +#define _LIBCPP_SUPPORT_IBM_CEEEDB_H + +#ifndef __MVS__ +# error This header should only be included on z/OS +#endif + +#include <__config> +#include <__gfunc.h> + +_LIBCPP_BEGIN_NAMESPACE_STD + +static inline unsigned char __libcpp_ceeedb_flags() { + // Offsets can be found in the z/OS Language Environment Vendor Interfaces book + // https://www-01.ibm.com/servers/resourcelink/svc00100.nsf/pages/zOSV2R4sa380688?OpenDocument +#ifndef __64BIT__ + enum { OFFSET_CEECAAEDB = 0x2f0 }; + enum { OFFSET_CEEEDBFLAG1 = 0x08 }; +#else + enum { OFFSET_CEECAAEDB = 0x388 }; + enum { OFFSET_CEEEDBFLAG1 = 0x100 }; +#endif + + // See the zOS Language Environment Vendor Interfaces book for a description + // of the Common Anchor Area (CEECAA), the Enclave Data Block (CEECAAEDB), + // and the EDB flags (CEEEDBFLAG1). + const unsigned char* CEECAA = static_cast(__gtca()); + const unsigned char* CEECAAEDB = + *static_cast(const_cast(static_cast(CEECAA + OFFSET_CEECAAEDB))); + const unsigned char* CEEEDBFLAG1 = (CEECAAEDB + OFFSET_CEEEDBFLAG1); + return *CEEEDBFLAG1; +} + +static inline bool __libcpp_ceeedb_multithread() { + const unsigned char CEEEDBMULTITHREAD = 0x02; + return __libcpp_ceeedb_flags() & CEEEDBMULTITHREAD; +} + +static inline bool __libcpp_ceeedb_posix() { + const unsigned char CEEEDB_POSIX = 0x04; + return __libcpp_ceeedb_flags() & CEEEDB_POSIX; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SUPPORT_IBM_CEEEDB_H diff --git a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn --- a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn +++ b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn @@ -409,6 +409,7 @@ "__string", "__support/android/locale_bionic.h", "__support/fuchsia/xlocale.h", + "__support/ibm/ceeedb.h", "__support/ibm/gettod_zos.h", "__support/ibm/limits.h", "__support/ibm/locale_mgmt_zos.h",