Skip to content

Commit 8097250

Browse files
authored
Add support for pipe2 API. NFC (#26480)
Becuase we support `pipe` already we already support the `flags=0` version of `pipe2`. Simply deleting the definition of `SYS_pipe` musl will use `__syscall_pipe2` for both `pipe` and `pipe2`. See #14824 (this doesn't fix the issue but works around the specific instance of it).
1 parent ebfb605 commit 8097250

File tree

10 files changed

+25
-14
lines changed

10 files changed

+25
-14
lines changed

src/lib/libsigs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ sigs = {
261261
__syscall_mknodat__sig: 'iipii',
262262
__syscall_newfstatat__sig: 'iippi',
263263
__syscall_openat__sig: 'iipip',
264-
__syscall_pipe__sig: 'ip',
264+
__syscall_pipe2__sig: 'ipi',
265265
__syscall_poll__sig: 'ipii',
266266
__syscall_readlinkat__sig: 'iippp',
267267
__syscall_recvfrom__sig: 'iippipp',

src/lib/libsyscall.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,14 @@ var SyscallsLibrary = {
194194
var old = SYSCALLS.getStreamFromFD(fd);
195195
return FS.dupStream(old).fd;
196196
},
197-
__syscall_pipe__deps: ['$PIPEFS'],
198-
__syscall_pipe: (fdPtr) => {
197+
__syscall_pipe2__deps: ['$PIPEFS'],
198+
__syscall_pipe2: (fdPtr, flags) => {
199199
if (fdPtr == 0) {
200200
throw new FS.ErrnoError({{{ cDefs.EFAULT }}});
201201
}
202+
if (flags && flags != {{{ cDefs.O_CLOEXEC }}}) {
203+
throw new FS.ErrnoError({{{ cDefs.ENOTSUP }}});
204+
}
202205
203206
var res = PIPEFS.createPipe();
204207

src/struct_info.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"F_SETLKW",
103103
"F_GETLK",
104104
"S_ISVTX",
105+
"O_CLOEXEC",
105106
"O_RDONLY",
106107
"O_ACCMODE",
107108
"F_DUPFD",

system/lib/libc/emscripten_syscall_stubs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ weak int __syscall_setsockopt(int sockfd, int level, int optname, intptr_t optva
262262

263263
UNIMPLEMENTED(acct, (intptr_t filename))
264264
UNIMPLEMENTED(mincore, (intptr_t addr, size_t length, intptr_t vec))
265-
UNIMPLEMENTED(pipe2, (intptr_t fds, int flags))
266265
UNIMPLEMENTED(pselect6, (int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout, intptr_t sigmaks))
267266
UNIMPLEMENTED(ppoll, (intptr_t fds, int nfds, intptr_t timeout, intptr_t sigmask, int size))
268267
UNIMPLEMENTED(recvmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ...))

system/lib/libc/musl/arch/emscripten/bits/syscall.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#define SYS_sync __syscall_sync
66
#define SYS_rmdir __syscall_rmdir
77
#define SYS_dup __syscall_dup
8-
#define SYS_pipe __syscall_pipe
98
#define SYS_acct __syscall_acct
109
#define SYS_ioctl __syscall_ioctl
1110
#define SYS_setpgid __syscall_setpgid

system/lib/libc/musl/arch/emscripten/syscall_arch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ int __syscall_access(intptr_t path, int amode);
2121
int __syscall_sync(void);
2222
int __syscall_rmdir(intptr_t path);
2323
int __syscall_dup(int fd);
24-
int __syscall_pipe(intptr_t fd);
2524
int __syscall_acct(intptr_t filename);
2625
int __syscall_ioctl(int fd, int request, ...);
2726
int __syscall_setpgid(int pid, int gpid);

system/lib/wasmfs/syscalls.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,11 @@ int __syscall_ioctl(int fd, int request, ...) {
13311331
}
13321332
}
13331333

1334-
int __syscall_pipe(intptr_t fd) {
1334+
int __syscall_pipe2(intptr_t fd, int flags) {
13351335
auto* fds = (__wasi_fd_t*)fd;
1336+
if (flags && flags != O_CLOEXEC) {
1337+
return -ENOTSUP;
1338+
}
13361339

13371340
// Make a pipe: Two PipeFiles that share a single data source between them, so
13381341
// that writing to one can be read in the other.

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 244330,
3-
"a.out.nodebug.wasm": 577696,
4-
"total": 822026,
2+
"a.out.js": 244367,
3+
"a.out.nodebug.wasm": 577720,
4+
"total": 822087,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",
@@ -247,7 +247,7 @@
247247
"__syscall_mknodat",
248248
"__syscall_newfstatat",
249249
"__syscall_openat",
250-
"__syscall_pipe",
250+
"__syscall_pipe2",
251251
"__syscall_poll",
252252
"__syscall_readlinkat",
253253
"__syscall_recvfrom",
@@ -1436,7 +1436,7 @@
14361436
"env.__syscall_mknodat",
14371437
"env.__syscall_newfstatat",
14381438
"env.__syscall_openat",
1439-
"env.__syscall_pipe",
1439+
"env.__syscall_pipe2",
14401440
"env.__syscall_poll",
14411441
"env.__syscall_readlinkat",
14421442
"env.__syscall_recvfrom",
@@ -1889,7 +1889,6 @@
18891889
"__syscall_munlockall",
18901890
"__syscall_munmap",
18911891
"__syscall_pause",
1892-
"__syscall_pipe2",
18931892
"__syscall_ppoll",
18941893
"__syscall_prlimit64",
18951894
"__syscall_pselect6",
@@ -3752,7 +3751,6 @@
37523751
"$__syscall_msync",
37533752
"$__syscall_munmap",
37543753
"$__syscall_pause",
3755-
"$__syscall_pipe2",
37563754
"$__syscall_ppoll",
37573755
"$__syscall_prlimit64",
37583756
"$__syscall_pselect6",

test/unistd/misc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ int main() {
8080
printf(", errno: %d\n", errno);
8181
errno = 0;
8282

83+
printf("pipe2(good): %d", pipe2(pipe_arg, 0));
84+
printf(", errno: %d\n", errno);
85+
errno = 0;
86+
printf("pipe2(bad): %d", pipe2(0, 0));
87+
printf(", errno: %d\n", errno);
88+
errno = 0;
89+
8390
char* exec_argv[] = {"arg", 0};
8491
char* exec_env[] = {"a=b", 0};
8592
printf("execl: %d", execl("working/program", "arg", 0));

test/unistd/misc.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ nice: -1, errno: 63
1313
pause: -1, errno: 27
1414
pipe(good): 0, errno: 0
1515
pipe(bad): -1, errno: 21
16+
pipe2(good): 0, errno: 0
17+
pipe2(bad): -1, errno: 21
1618
execl: -1, errno: 45
1719
execle: -1, errno: 45
1820
execlp: -1, errno: 45

0 commit comments

Comments
 (0)