[libcxx-commits] [libcxx] [libc++] Add FreeBSD-specific EINTEGRITY errc value (PR #76364)

Dimitry Andric via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 28 05:59:43 PST 2023


https://github.com/DimitryAndric updated https://github.com/llvm/llvm-project/pull/76364

>From 442e59bc4d137dc0df145652157d52c96afec9b7 Mon Sep 17 00:00:00 2001
From: Dimitry Andric <dimitry at andric.com>
Date: Mon, 25 Dec 2023 17:43:32 +0100
Subject: [PATCH 1/2] [libc++] Add FreeBSD-specific EINTEGRITY errc value

Since ~2019 we have been carrying a libc++ patch in FreeBSD, that adds
the `EINTEGRITY` errno value. At the time, I submitted
https://reviews.llvm.org/D56398 for this, but due to the complicated
`ELAST` handling in `errno.h`, which that patch made even more
complicated, it was put on hold.

I would like to try this again, but much simplified: there is no need to
modify `errno.h`, since all supported versions of FreeBSD define both
`EOWNERDEAD` and `ENOTRECOVERABLE`, so the part that attempts to
redefine `ELAST` is effectively never used, and for FreeBSD we can
simply ignore it.

The only proposed changes will now be to optionally add `EINTEGRITY` as
an `enum errc` value, and add a corresponding test to `errc.pass.cpp`.
---
 libcxx/include/__system_error/errc.h          | 30 +++++++++++--------
 .../test/std/diagnostics/syserr/errc.pass.cpp |  3 ++
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/libcxx/include/__system_error/errc.h b/libcxx/include/__system_error/errc.h
index f87df86a71e15a..9a84b478b36b12 100644
--- a/libcxx/include/__system_error/errc.h
+++ b/libcxx/include/__system_error/errc.h
@@ -45,6 +45,7 @@ enum class errc
     identifier_removed,                 // EIDRM
     illegal_byte_sequence,              // EILSEQ
     inappropriate_io_control_operation, // ENOTTY
+    integrity_check_failed,             // EINTEGRITY
     interrupted,                        // EINTR
     invalid_argument,                   // EINVAL
     invalid_seek,                       // ESPIPE
@@ -141,19 +142,22 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
     identifier_removed                 = EIDRM,
     illegal_byte_sequence              = EILSEQ,
     inappropriate_io_control_operation = ENOTTY,
-    interrupted                        = EINTR,
-    invalid_argument                   = EINVAL,
-    invalid_seek                       = ESPIPE,
-    io_error                           = EIO,
-    is_a_directory                     = EISDIR,
-    message_size                       = EMSGSIZE,
-    network_down                       = ENETDOWN,
-    network_reset                      = ENETRESET,
-    network_unreachable                = ENETUNREACH,
-    no_buffer_space                    = ENOBUFS,
-    no_child_process                   = ECHILD,
-    no_link                            = ENOLINK,
-    no_lock_available                  = ENOLCK,
+#ifdef EINTEGRITY
+    integrity_check_failed = EINTEGRITY,
+#endif
+    interrupted         = EINTR,
+    invalid_argument    = EINVAL,
+    invalid_seek        = ESPIPE,
+    io_error            = EIO,
+    is_a_directory      = EISDIR,
+    message_size        = EMSGSIZE,
+    network_down        = ENETDOWN,
+    network_reset       = ENETRESET,
+    network_unreachable = ENETUNREACH,
+    no_buffer_space     = ENOBUFS,
+    no_child_process    = ECHILD,
+    no_link             = ENOLINK,
+    no_lock_available   = ENOLCK,
 #ifdef ENODATA
     no_message_available = ENODATA,
 #else
diff --git a/libcxx/test/std/diagnostics/syserr/errc.pass.cpp b/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
index e44cb50102e3e1..ef18904864b371 100644
--- a/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
@@ -44,6 +44,9 @@ int main(int, char**)
     static_assert(static_cast<int>(std::errc::identifier_removed) == EIDRM, "");
     static_assert(static_cast<int>(std::errc::illegal_byte_sequence) == EILSEQ, "");
     static_assert(static_cast<int>(std::errc::inappropriate_io_control_operation) == ENOTTY, "");
+#ifdef EINTEGRITY
+    static_assert(static_cast<int>(std::errc::integrity_check_failed) == EINTEGRITY, "");
+#endif
     static_assert(static_cast<int>(std::errc::interrupted) == EINTR, "");
     static_assert(static_cast<int>(std::errc::invalid_argument) == EINVAL, "");
     static_assert(static_cast<int>(std::errc::invalid_seek) == ESPIPE, "");

>From 2c44487e5515ac2e3039c6c184a47e8e781add91 Mon Sep 17 00:00:00 2001
From: Dimitry Andric <dimitry at andric.com>
Date: Thu, 28 Dec 2023 14:58:11 +0100
Subject: [PATCH 2/2] Mark EINTEGRITY value as FreeBSD extension, and add
 subsection "Extensions to <system_error>" to the "Libc++ Extensions" section
 in the libcxx documentation.

---
 libcxx/docs/UsingLibcxx.rst                      | 10 ++++++++++
 libcxx/include/__system_error/errc.h             |  4 ++--
 libcxx/test/std/diagnostics/syserr/errc.pass.cpp |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst
index 8d9f795da977e3..a01b6a72ede8f9 100644
--- a/libcxx/docs/UsingLibcxx.rst
+++ b/libcxx/docs/UsingLibcxx.rst
@@ -414,6 +414,16 @@ Extensions to the C++23 modules ``std`` and ``std.compat``
 Like other major implementations, libc++ provides C++23 modules ``std`` and
 ``std.compat`` in C++20 as an extension"
 
+Extensions to ``<system_error>``
+--------------------------------
+
+``std::errc`` contains the values documented in the C++ standard under
+``[system_error.syn]`` (``EINVAL``, ``ENOENT``, etc), but can also
+include platform-specific values as extensions.
+
+As of this writing, the only extension value is ``EINTEGRITY``, which is
+specific to FreeBSD.
+
 Constant-initialized std::string
 --------------------------------
 
diff --git a/libcxx/include/__system_error/errc.h b/libcxx/include/__system_error/errc.h
index 9a84b478b36b12..8e066748c9d857 100644
--- a/libcxx/include/__system_error/errc.h
+++ b/libcxx/include/__system_error/errc.h
@@ -45,7 +45,7 @@ enum class errc
     identifier_removed,                 // EIDRM
     illegal_byte_sequence,              // EILSEQ
     inappropriate_io_control_operation, // ENOTTY
-    integrity_check_failed,             // EINTEGRITY
+    integrity_check_failed,             // EINTEGRITY (FreeBSD extension)
     interrupted,                        // EINTR
     invalid_argument,                   // EINVAL
     invalid_seek,                       // ESPIPE
@@ -142,7 +142,7 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
     identifier_removed                 = EIDRM,
     illegal_byte_sequence              = EILSEQ,
     inappropriate_io_control_operation = ENOTTY,
-#ifdef EINTEGRITY
+#if defined(__FreeBSD__) && defined(EINTEGRITY) // FreeBSD extension
     integrity_check_failed = EINTEGRITY,
 #endif
     interrupted         = EINTR,
diff --git a/libcxx/test/std/diagnostics/syserr/errc.pass.cpp b/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
index ef18904864b371..d5dbb1f145681d 100644
--- a/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
@@ -44,7 +44,7 @@ int main(int, char**)
     static_assert(static_cast<int>(std::errc::identifier_removed) == EIDRM, "");
     static_assert(static_cast<int>(std::errc::illegal_byte_sequence) == EILSEQ, "");
     static_assert(static_cast<int>(std::errc::inappropriate_io_control_operation) == ENOTTY, "");
-#ifdef EINTEGRITY
+#if defined(__FreeBSD__) && defined(EINTEGRITY) // FreeBSD extension
     static_assert(static_cast<int>(std::errc::integrity_check_failed) == EINTEGRITY, "");
 #endif
     static_assert(static_cast<int>(std::errc::interrupted) == EINTR, "");



More information about the libcxx-commits mailing list