From 360e6f70f034b90f82dbafda66bfc6919ab428d4 Mon Sep 17 00:00:00 2001 From: Kenta Kubo <601636+kkebo@users.noreply.github.com> Date: Fri, 12 Jun 2026 22:31:04 +0900 Subject: [PATCH] Fix missing `O_CLOFORK` on older FreeBSD --- Sources/CSystem/CMakeLists.txt | 1 + Sources/CSystem/include/CSystemFreeBSD.h | 21 +++++++++++++++++++++ Sources/CSystem/include/module.modulemap | 1 + Sources/CSystem/shims.c | 4 ++++ Sources/System/Internals/Constants.swift | 4 +++- 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Sources/CSystem/include/CSystemFreeBSD.h diff --git a/Sources/CSystem/CMakeLists.txt b/Sources/CSystem/CMakeLists.txt index 6bde43c..0088ad1 100644 --- a/Sources/CSystem/CMakeLists.txt +++ b/Sources/CSystem/CMakeLists.txt @@ -16,6 +16,7 @@ install(FILES include/CSystemLinux.h include/CSystemShared.h include/CSystemWindows.h + include/CSystemFreeBSD.h include/module.modulemap DESTINATION include/CSystem) set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS CSystem) diff --git a/Sources/CSystem/include/CSystemFreeBSD.h b/Sources/CSystem/include/CSystemFreeBSD.h new file mode 100644 index 0000000..158f0b4 --- /dev/null +++ b/Sources/CSystem/include/CSystemFreeBSD.h @@ -0,0 +1,21 @@ +/* + This source file is part of the Swift System open source project + + Copyright (c) 2026 Apple Inc. and the Swift System project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See https://swift.org/LICENSE.txt for license information +*/ + +#if defined(__FreeBSD__) + +#include + +#ifdef O_CLOFORK +#define FREEBSD_O_CLOFORK O_CLOFORK +#else +#define FREEBSD_O_CLOFORK 0 +#endif + +#endif + diff --git a/Sources/CSystem/include/module.modulemap b/Sources/CSystem/include/module.modulemap index 73b1004..38c2d46 100644 --- a/Sources/CSystem/include/module.modulemap +++ b/Sources/CSystem/include/module.modulemap @@ -3,5 +3,6 @@ module CSystem { header "CSystemLinux.h" header "CSystemWASI.h" header "CSystemWindows.h" + header "CSystemFreeBSD.h" export * } diff --git a/Sources/CSystem/shims.c b/Sources/CSystem/shims.c index 4130582..eb9126b 100644 --- a/Sources/CSystem/shims.c +++ b/Sources/CSystem/shims.c @@ -12,6 +12,10 @@ #include #endif +#if defined(__FreeBSD__) +#include +#endif + #ifdef __linux__ #define _GNU_SOURCE #include diff --git a/Sources/System/Internals/Constants.swift b/Sources/System/Internals/Constants.swift index 477fc9a..fa76713 100644 --- a/Sources/System/Internals/Constants.swift +++ b/Sources/System/Internals/Constants.swift @@ -631,8 +631,10 @@ internal var _O_CLOEXEC: CInt { #if !os(Windows) @_alwaysEmitIntoClient internal var _O_CLOFORK: CInt { - #if !os(WASI) && !os(Linux) && !os(Android) && !canImport(Darwin) + #if !os(WASI) && !os(Linux) && !os(Android) && !canImport(Darwin) && !os(FreeBSD) O_CLOFORK + #elseif os(FreeBSD) + FREEBSD_O_CLOFORK #else 0 #endif