perl-5.38.0
syscall NUMBER, LIST

Calls the system call specified as the first element of the list, passing the remaining elements as arguments to the system call. If unimplemented, raises an exception. The arguments are interpreted as follows: if a given argument is numeric, the argument is passed as an int. If not, the pointer to the string value is passed. You are responsible to make sure a string is pre-extended long enough to receive any result that might be written into a string. You can't use a string literal (or other read-only string) as an argument to syscall because Perl has to assume that any string pointer might be written through. If your integer arguments are not literals and have never been interpreted in a numeric context, you may need to add 0 to them to force them to look like numbers. This emulates the syswrite function (or vice versa):

LIST の最初の要素で指定するシステムコールを、残りの要素をその システムコールの引数として呼び出します。 実装されていない場合には、例外が発生します。 引数は、以下のように解釈されます: 引数が数字であれば、int として 引数を渡します。 そうでなければ、文字列値へのポインタが渡されます。 文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、 文字列を予め伸ばしておく必要があります。 文字列リテラル(あるいはその他の読み込み専用の文字列)を syscall の引数として使うことはできません; Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。 整数引数が、リテラルでなく、数値コンテキストで評価されたことのない ものであれば、数値として解釈されるように、 0 を足しておく必要があるかもしれません。 以下は syswrite 関数(あるいは その逆)をエミュレートします。

    require 'syscall.ph';        # may need to run h2ph
    my $s = "hi there\n";
    syscall(SYS_write(), fileno(STDOUT), $s, length $s);

Note that Perl supports passing of up to only 14 arguments to your syscall, which in practice should (usually) suffice.

Perl は、システムコールに最大 14 個の引数しか渡せませんが、 (普通は)実用上問題はないでしょう。

Syscall returns whatever value returned by the system call it calls. If the system call fails, syscall returns -1 and sets $! (errno). Note that some system calls can legitimately return -1. The proper way to handle such calls is to assign $! = 0 before the call, then check the value of $! if syscall returns -1.

syscall は、呼び出したシステムコールが返した値を返します。 システムコールが失敗すると、syscall-1 を 返し、$!(errno) を設定します。 システムコールが正常に -1 を返す 場合がある ことに注意してください。 このようなシステムコールを正しく扱うには、 $! = 0 をシステムコールの前に実行し、それから syscall-1 を返した時には $! の値を調べてください。

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 using pipe instead.

syscall(&SYS_pipe) には問題があり、作ったパイプの、読み出し側の ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。 この問題を避けるためには、代わりに pipe を 使ってください。

Portability issues: "syscall" in perlport.

移植性の問題: "syscall" in perlport