This is what perldoc -f syscall
says:
There's a problem with
syscall(SYS_pipe())
: it returns the file number of the read end of the pipe it creates, but there is no way to retrieve the file number of the other end. You can avoid this problem by usingpipe
instead.
However, that doesn't check out. syscall
works with SYS_pipe
just like with any other system call, and I'm perfectly able to retrieve both ends:
perl -e '
require "syscall.ph";
my $p = pack "i2";
syscall SYS_pipe(), $p;
print join(",", unpack "i2", $p), "\n"
'
3,4
That was on linux, it's the same on openbsd and solaris provided that you take care of some differences (on solaris, the system call is actually pipe2(2)
, so syscall 42, $p, 0
).
A comment in fs/pipe.c
in the linux kernel source says:
/* * sys_pipe() is the normal C calling standard for creating * a pipe. It's not the way Unix traditionally does this, though. */
So what was that "traditional" way? And are there any modern systems where that's still the case?
traditional UNIX implementations often return the two file descriptors in registers
(commit: https://github.com/torvalds/linux/commit/d35c7b0e54a596c5a8134d75999b7f391a9c6550) – Danila Kiver Feb 05 '19 at 11:52