Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/CoreFoundation/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const char *_CFProcessPath(void) {

#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_BSD
CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread(void) {
#if defined(__OpenBSD__)
#if defined(__OpenBSD__) || defined(__FreeBSD__)
return pthread_equal(pthread_self(), _CFMainPThread) != 0;
#else
return pthread_main_np() == 1;
Expand Down Expand Up @@ -928,9 +928,13 @@ static void __CFTSDFinalize(void *arg) {
#if _POSIX_THREADS && !TARGET_OS_WASI
if (table->destructorCount == PTHREAD_DESTRUCTOR_ITERATIONS - 1) { // On PTHREAD_DESTRUCTOR_ITERATIONS-1 call, destroy our data
free(table);


// FreeBSD libthr emits debug message to stderr if there are leftover nonnull TSD after PTHREAD_DESTRUCTOR_ITERATIONS
// On this platform, the destructor will never be called again, therefore it is unneccessary to set the TSD to CF_TSD_BAD_PTR
#if !defined(FreeBSD)
// Now if the destructor is called again we will take the shortcut at the beginning of this function.
__CFTSDSetSpecific(CF_TSD_BAD_PTR);
#endif
return;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/include/CoreFoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

#include "ForSwiftFoundationOnly.h"

#if TARGET_OS_OSX || TARGET_OS_IPHONE || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
#if TARGET_OS_OSX || TARGET_OS_IPHONE || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI || TARGET_OS_BSD
# if !TARGET_OS_WASI
#include "CFMessagePort.h"
#include "CFPlugIn.h"
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/internalInclude/CFBundle_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ CF_PRIVATE const CFStringRef _kCFBundleUseAppleLocalizationsKey;
// The buffer must be PATH_MAX long or more.
static bool _CFGetPathFromFileDescriptor(int fd, char *path);

#if TARGET_OS_MAC || (TARGET_OS_BSD && !defined(__OpenBSD__))
#if TARGET_OS_MAC || (TARGET_OS_BSD && !defined(__OpenBSD__) && !defined(__FreeBSD__))

static bool _CFGetPathFromFileDescriptor(int fd, char *path) {
return fcntl(fd, F_GETPATH, path) != -1;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/FileManager+POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension FileManager {
}
urls = mountPoints(statBuf, Int(fsCount))
}
#elseif os(OpenBSD)
#elseif os(OpenBSD) || os(FreeBSD)
func mountPoints(_ statBufs: UnsafePointer<statfs>, _ fsCount: Int) -> [URL] {
var urls: [URL] = []

Expand Down
8 changes: 7 additions & 1 deletion Sources/Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,15 @@ extension FileManager {
flags |= flagsToSet
flags &= ~flagsToUnset

guard chflags(fsRep, flags) == 0 else {
#if os(FreeBSD)
guard chflags(path, UInt(flags)) == 0 else {
throw _NSErrorWithErrno(errno, reading: false, path: path)
}
#else
guard chflags(path, flags) == 0 else {
throw _NSErrorWithErrno(errno, reading: false, path: path)
}
#endif
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Foundation/Host.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ open class Host: NSObject {
let family = ifa_addr.pointee.sa_family
if family == sa_family_t(AF_INET) || family == sa_family_t(AF_INET6) {
let sa_len: socklen_t = socklen_t((family == sa_family_t(AF_INET6)) ? MemoryLayout<sockaddr_in6>.size : MemoryLayout<sockaddr_in>.size)
#if os(OpenBSD)
#if os(OpenBSD) || os(FreeBSD)
let hostlen = size_t(NI_MAXHOST)
#else
let hostlen = socklen_t(NI_MAXHOST)
Expand Down Expand Up @@ -294,7 +294,7 @@ open class Host: NSObject {
}
var hints = addrinfo()
hints.ai_family = PF_UNSPEC
#if os(macOS) || os(iOS) || os(Android) || os(OpenBSD) || canImport(Musl)
#if os(macOS) || os(iOS) || os(Android) || os(OpenBSD) || canImport(Musl) || os(FreeBSD)
hints.ai_socktype = SOCK_STREAM
#else
hints.ai_socktype = Int32(SOCK_STREAM.rawValue)
Expand Down Expand Up @@ -324,7 +324,7 @@ open class Host: NSObject {
}
let sa_len: socklen_t = socklen_t((family == AF_INET6) ? MemoryLayout<sockaddr_in6>.size : MemoryLayout<sockaddr_in>.size)
let lookupInfo = { (content: inout [String], flags: Int32) in
#if os(OpenBSD)
#if os(OpenBSD) || os(FreeBSD)
let hostlen = size_t(NI_MAXHOST)
#else
let hostlen = socklen_t(NI_MAXHOST)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Foundation/NSLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension NSLocking {
private typealias _MutexPointer = UnsafeMutablePointer<SRWLOCK>
private typealias _RecursiveMutexPointer = UnsafeMutablePointer<CRITICAL_SECTION>
private typealias _ConditionVariablePointer = UnsafeMutablePointer<CONDITION_VARIABLE>
#elseif CYGWIN || os(OpenBSD)
#elseif CYGWIN || os(OpenBSD) || os(FreeBSD)
private typealias _MutexPointer = UnsafeMutablePointer<pthread_mutex_t?>
private typealias _RecursiveMutexPointer = UnsafeMutablePointer<pthread_mutex_t?>
private typealias _ConditionVariablePointer = UnsafeMutablePointer<pthread_cond_t?>
Expand Down Expand Up @@ -287,14 +287,14 @@ open class NSRecursiveLock: NSObject, NSLocking, @unchecked Sendable {
InitializeConditionVariable(timeoutCond)
InitializeSRWLock(timeoutMutex)
#else
#if CYGWIN || os(OpenBSD)
#if CYGWIN || os(OpenBSD) || os(FreeBSD)
var attrib : pthread_mutexattr_t? = nil
#else
var attrib = pthread_mutexattr_t()
#endif
withUnsafeMutablePointer(to: &attrib) { attrs in
pthread_mutexattr_init(attrs)
#if os(OpenBSD)
#if os(OpenBSD) || os(FreeBSD)
let type = Int32(PTHREAD_MUTEX_RECURSIVE.rawValue)
#else
let type = Int32(PTHREAD_MUTEX_RECURSIVE)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/NSPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if os(macOS) || os(iOS)
fileprivate let _NSPageSize = Int(vm_page_size)
#elseif os(Linux) || os(Android) || os(OpenBSD)
#elseif os(Linux) || os(Android) || os(OpenBSD) || os(FreeBSD)
fileprivate let _NSPageSize = Int(getpagesize())
#elseif os(Windows)
import WinSDK
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/Port.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM
fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP
#endif

#if canImport(Glibc) && !os(Android) && !os(OpenBSD)
#if canImport(Glibc) && !os(Android) && !os(OpenBSD) && !os(FreeBSD)
import Glibc
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
Expand All @@ -119,7 +119,7 @@ fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
#endif

#if canImport(Glibc) && os(Android) || os(OpenBSD)
#if canImport(Glibc) && os(Android) || os(OpenBSD) || os(FreeBSD)
import Glibc
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ open class Process: NSObject, @unchecked Sendable {
}

var taskSocketPair : [Int32] = [0, 0]
#if os(macOS) || os(iOS) || os(Android) || os(OpenBSD) || canImport(Musl)
#if os(macOS) || os(iOS) || os(Android) || os(OpenBSD) || os(FreeBSD) || canImport(Musl)
socketpair(AF_UNIX, SOCK_STREAM, 0, &taskSocketPair)
#else
socketpair(AF_UNIX, Int32(SOCK_STREAM.rawValue), 0, &taskSocketPair)
Expand Down Expand Up @@ -936,7 +936,7 @@ open class Process: NSObject, @unchecked Sendable {
useFallbackChdir = false
}

#if canImport(Darwin) || os(Android) || os(OpenBSD)
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
var spawnAttrs: posix_spawnattr_t? = nil
#else
var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t()
Expand Down
13 changes: 10 additions & 3 deletions Sources/Foundation/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ open class Thread : NSObject {
get { _attrStorage.value }
set { _attrStorage.value = newValue }
}
#elseif CYGWIN || os(OpenBSD)
#elseif CYGWIN || os(OpenBSD) || os(FreeBSD)
internal var _attr : pthread_attr_t? = nil
#else
internal var _attr = pthread_attr_t()
Expand Down Expand Up @@ -264,7 +264,7 @@ open class Thread : NSObject {
_status = .finished
return
}
#if CYGWIN || os(OpenBSD)
#if CYGWIN || os(OpenBSD) || os(FreeBSD)
if let attr = self._attr {
_thread = self.withRetainedReference {
return _CFThreadCreate(attr, NSThreadStart, $0)
Expand Down Expand Up @@ -388,6 +388,8 @@ open class Thread : NSObject {
#elseif os(Windows)
let count = RtlCaptureStackBackTrace(0, DWORD(maxSupportedStackDepth),
addrs, nil)
#elseif os(FreeBSD)
let count = backtrace(addrs, maxSupportedStackDepth)
#else
let count = backtrace(addrs, Int32(maxSupportedStackDepth))
#endif
Expand Down Expand Up @@ -449,7 +451,12 @@ open class Thread : NSObject {
#else
return backtraceAddresses({ (addrs, count) in
var symbols: [String] = []
if let bs = backtrace_symbols(addrs, Int32(count)) {
#if os(FreeBSD)
let bs = backtrace_symbols(addrs, count)
#else
let bs = backtrace_symbols(addrs, Int32(count))
#endif
if let bs {
symbols = UnsafeBufferPointer(start: bs, count: count).map {
guard let symbol = $0 else {
return "<null>"
Expand Down