Skip to content

Commit b63d24d

Browse files
authored
Merge pull request #248 from glessard/updates-1.6.1
Updates for 1.6.1 tag
2 parents 0bb855a + a717516 commit b63d24d

File tree

10 files changed

+343
-68
lines changed

10 files changed

+343
-68
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ jobs:
99
name: Test
1010
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
1111
with:
12-
linux_exclude_swift_versions: '[{"swift_version": "5.8"}]'
12+
linux_os_versions: '["jammy", "focal"]'
13+
enable_macos_checks: false
14+
macos_xcode_versions: '["16.3"]'
15+
1316
soundness:
1417
name: Soundness
1518
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main

Sources/CSystem/include/CSystemWASI.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift System open source project
33
4-
Copyright (c) 2024 Apple Inc. and the Swift System project authors
4+
Copyright (c) 2024 - 2025 Apple Inc. and the Swift System project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
77
See https://swift.org/LICENSE.txt for license information
@@ -11,8 +11,10 @@
1111

1212
#if __wasi__
1313

14+
#include <dirent.h>
1415
#include <errno.h>
1516
#include <fcntl.h>
17+
#include <limits.h> // For NAME_MAX
1618

1719
// wasi-libc defines the following constants in a way that Clang Importer can't
1820
// understand, so we need to expose them manually.
@@ -28,4 +30,37 @@ static inline int32_t _getConst_O_WRONLY(void) { return O_WRONLY; }
2830
static inline int32_t _getConst_EWOULDBLOCK(void) { return EWOULDBLOCK; }
2931
static inline int32_t _getConst_EOPNOTSUPP(void) { return EOPNOTSUPP; }
3032

33+
static inline uint8_t _getConst_DT_DIR(void) { return DT_DIR; }
34+
35+
// Modified dirent struct that can be imported to Swift
36+
struct _system_dirent {
37+
ino_t d_ino;
38+
unsigned char d_type;
39+
// char d_name[] cannot be imported to Swift
40+
char d_name[NAME_MAX + 1];
41+
};
42+
43+
// Convert WASI dirent with d_name[] to _system_dirent
44+
static inline
45+
struct _system_dirent *
46+
_system_dirent_from_wasi_dirent(const struct dirent *wasi_dirent) {
47+
48+
// Match readdir behavior and use thread-local storage for the converted dirent
49+
static __thread struct _system_dirent _converted_dirent;
50+
51+
if (wasi_dirent == NULL) {
52+
return NULL;
53+
}
54+
55+
memset(&_converted_dirent, 0, sizeof(struct _system_dirent));
56+
57+
_converted_dirent.d_ino = wasi_dirent->d_ino;
58+
_converted_dirent.d_type = wasi_dirent->d_type;
59+
60+
strncpy(_converted_dirent.d_name, wasi_dirent->d_name, NAME_MAX);
61+
_converted_dirent.d_name[NAME_MAX] = '\0';
62+
63+
return &_converted_dirent;
64+
}
65+
3166
#endif

Sources/CSystem/include/io_uring.h

Lines changed: 186 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,195 @@
11
#include <unistd.h>
22
#include <sys/syscall.h>
33
#include <sys/uio.h>
4-
54
#include <signal.h>
5+
6+
#define __SWIFT_IORING_SQE_FALLBACK_STRUCT { \
7+
__u8 opcode; \
8+
__u8 flags; \
9+
__u16 ioprio; \
10+
__s32 fd; \
11+
union { \
12+
__u64 off; \
13+
__u64 addr2; \
14+
struct { \
15+
__u32 cmd_op; \
16+
__u32 __pad1; \
17+
}; \
18+
}; \
19+
union { \
20+
__u64 addr; \
21+
__u64 splice_off_in; \
22+
struct { \
23+
__u32 level; \
24+
__u32 optname; \
25+
}; \
26+
}; \
27+
__u32 len; \
28+
union { \
29+
__kernel_rwf_t rw_flags; \
30+
__u32 fsync_flags; \
31+
__u16 poll_events; \
32+
__u32 poll32_events; \
33+
__u32 sync_range_flags; \
34+
__u32 msg_flags; \
35+
__u32 timeout_flags; \
36+
__u32 accept_flags; \
37+
__u32 cancel_flags; \
38+
__u32 open_flags; \
39+
__u32 statx_flags; \
40+
__u32 fadvise_advice; \
41+
__u32 splice_flags; \
42+
__u32 rename_flags; \
43+
__u32 unlink_flags; \
44+
__u32 hardlink_flags; \
45+
__u32 xattr_flags; \
46+
__u32 msg_ring_flags; \
47+
__u32 uring_cmd_flags; \
48+
__u32 waitid_flags; \
49+
__u32 futex_flags; \
50+
__u32 install_fd_flags; \
51+
__u32 nop_flags; \
52+
}; \
53+
__u64 user_data; \
54+
union { \
55+
__u16 buf_index; \
56+
__u16 buf_group; \
57+
} __attribute__((packed)); \
58+
__u16 personality; \
59+
union { \
60+
__s32 splice_fd_in; \
61+
__u32 file_index; \
62+
__u32 optlen; \
63+
struct { \
64+
__u16 addr_len; \
65+
__u16 __pad3[1]; \
66+
}; \
67+
}; \
68+
union { \
69+
struct { \
70+
__u64 addr3; \
71+
__u64 __pad2[1]; \
72+
}; \
73+
__u64 optval; \
74+
__u8 cmd[0]; \
75+
}; \
76+
}
77+
78+
#if __has_include(<linux/io_uring.h>)
679
#include <linux/io_uring.h>
780

81+
#ifdef IORING_TIMEOUT_BOOTTIME
82+
// Kernel version >= 5.15, io_uring_sqe has file_index
83+
// and all current Swift operations are supported.
84+
#define __SWIFT_IORING_SUPPORTED true
85+
typedef struct io_uring_sqe swift_io_uring_sqe;
86+
#else
87+
// io_uring_sqe is missing properties that IORequest expects.
88+
// This configuration is not supported for now.
89+
//
90+
// Define a fallback struct to avoid build errors, but IORing
91+
// will throw ENOTSUP on initialization.
92+
#define __SWIFT_IORING_SUPPORTED false
93+
typedef struct __SWIFT_IORING_SQE_FALLBACK_STRUCT swift_io_uring_sqe;
94+
#endif
95+
96+
// We can define more specific availability later
97+
98+
#ifdef IORING_FEAT_RW_CUR_POS
99+
// Kernel version >= 5.6, io_uring_sqe has open_flags
100+
#endif
101+
102+
#ifdef IORING_FEAT_NODROP
103+
// Kernel version >= 5.5, io_uring_sqe has cancel_flags
104+
#endif
105+
106+
#else
107+
// Minimal fallback definitions when linux/io_uring.h is not available (e.g. static SDK)
108+
#include <stdint.h>
109+
110+
#define __SWIFT_IORING_SUPPORTED false
111+
112+
#define IORING_OFF_SQ_RING 0ULL
113+
#define IORING_OFF_CQ_RING 0x8000000ULL
114+
#define IORING_OFF_SQES 0x10000000ULL
115+
116+
#define IORING_ENTER_GETEVENTS (1U << 0)
117+
118+
#define IORING_FEAT_SINGLE_MMAP (1U << 0)
119+
#define IORING_FEAT_NODROP (1U << 1)
120+
#define IORING_FEAT_SUBMIT_STABLE (1U << 2)
121+
#define IORING_FEAT_RW_CUR_POS (1U << 3)
122+
#define IORING_FEAT_CUR_PERSONALITY (1U << 4)
123+
#define IORING_FEAT_FAST_POLL (1U << 5)
124+
#define IORING_FEAT_POLL_32BITS (1U << 6)
125+
#define IORING_FEAT_SQPOLL_NONFIXED (1U << 7)
126+
#define IORING_FEAT_EXT_ARG (1U << 8)
127+
#define IORING_FEAT_NATIVE_WORKERS (1U << 9)
128+
#define IORING_FEAT_RSRC_TAGS (1U << 10)
129+
#define IORING_FEAT_CQE_SKIP (1U << 11)
130+
#define IORING_FEAT_LINKED_FILE (1U << 12)
131+
#define IORING_FEAT_REG_REG_RING (1U << 13)
132+
#define IORING_FEAT_RECVSEND_BUNDLE (1U << 14)
133+
#define IORING_FEAT_MIN_TIMEOUT (1U << 15)
134+
#define IORING_FEAT_RW_ATTR (1U << 16)
135+
#define IORING_FEAT_NO_IOWAIT (1U << 17)
136+
137+
typedef uint8_t __u8;
138+
typedef uint16_t __u16;
139+
typedef uint32_t __u32;
140+
typedef uint64_t __u64;
141+
typedef int32_t __s32;
142+
143+
#ifndef __kernel_rwf_t
144+
typedef int __kernel_rwf_t;
145+
#endif
146+
147+
typedef struct __SWIFT_IORING_SQE_FALLBACK_STRUCT swift_io_uring_sqe;
148+
149+
struct io_uring_cqe {
150+
__u64 user_data;
151+
__s32 res;
152+
__u32 flags;
153+
};
154+
155+
struct io_sqring_offsets {
156+
__u32 head;
157+
__u32 tail;
158+
__u32 ring_mask;
159+
__u32 ring_entries;
160+
__u32 flags;
161+
__u32 dropped;
162+
__u32 array;
163+
__u32 resv1;
164+
__u64 user_addr;
165+
};
166+
167+
struct io_cqring_offsets {
168+
__u32 head;
169+
__u32 tail;
170+
__u32 ring_mask;
171+
__u32 ring_entries;
172+
__u32 overflow;
173+
__u32 cqes;
174+
__u32 flags;
175+
__u32 resv1;
176+
__u64 user_addr;
177+
};
178+
179+
struct io_uring_params {
180+
__u32 sq_entries;
181+
__u32 cq_entries;
182+
__u32 flags;
183+
__u32 sq_thread_cpu;
184+
__u32 sq_thread_idle;
185+
__u32 features;
186+
__u32 wq_fd;
187+
__u32 resv[3];
188+
struct io_sqring_offsets sq_off;
189+
struct io_cqring_offsets cq_off;
190+
};
191+
#endif // __has_include(<linux/io_uring.h>)
192+
8193
#ifndef SWIFT_IORING_C_WRAPPER
9194
#define SWIFT_IORING_C_WRAPPER
10195

Sources/System/FileOperations.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift System open source project
33

4-
Copyright (c) 2020 - 2024 Apple Inc. and the Swift System project authors
4+
Copyright (c) 2020 - 2025 Apple Inc. and the Swift System project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -509,6 +509,7 @@ extension FileDescriptor {
509509
}
510510
}
511511

512+
#if !os(WASI) // WASI has no umask
512513
extension FilePermissions {
513514
/// The file creation permission mask (aka "umask").
514515
///
@@ -549,3 +550,4 @@ extension FilePermissions {
549550
return system_umask(mode)
550551
}
551552
}
553+
#endif

0 commit comments

Comments
 (0)