From c817e85f4cddeddf534ea2890f7f741388ed1ff8 Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Tue, 5 May 2020 02:23:49 +0900 Subject: [PATCH] Linux updates (#14170) * Add posix_memalign() * Add linux-specific open() flags O_TMPFILE: since Linux 3.11 O_PATH: since Linux 2.6.39 O_NOATIME: since Linux 2.6.8 O_DIRECT: since Linux 2.4.10 * Fix Stat type * Fix POSIX AF_INET* const generation --- lib/posix/posix.nim | 2 ++ lib/posix/posix_linux_amd64.nim | 9 +-------- lib/posix/posix_linux_amd64_consts.nim | 15 ++++++++++++++- tools/detect/detect.nim | 21 ++++++++++++++++----- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 3e423c64b573..96203b736035 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -1043,6 +1043,8 @@ proc mkdtemp*(tmpl: cstring): pointer {.importc, header: "", sideEffec when defined(linux) or defined(bsd): proc mkostemp*(tmpl: cstring, oflags: cint): cint {.importc, header: "", sideEffect.} + proc posix_memalign*(memptr: pointer, alignment: csize_t, size: csize_t): cint {.importc, header: "".} + proc utimes*(path: cstring, times: ptr array[2, Timeval]): int {. importc: "utimes", header: "", sideEffect.} ## Sets file access and modification times. diff --git a/lib/posix/posix_linux_amd64.nim b/lib/posix/posix_linux_amd64.nim index bb82d9e5e845..7f6a589f0850 100644 --- a/lib/posix/posix_linux_amd64.nim +++ b/lib/posix/posix_linux_amd64.nim @@ -34,9 +34,6 @@ type type SocketHandle* = distinct cint # The type used to represent socket descriptors -# not detected by detect.nim, guarded by #ifdef __USE_UNIX98 in glibc -const SIG_HOLD* = cast[Sighandler](2) - type Time* {.importc: "time_t", header: "".} = distinct clong @@ -228,7 +225,7 @@ type st_mode*: Mode ## Mode of file (see below). st_uid*: Uid ## User ID of file. st_gid*: Gid ## Group ID of file. - pad0: cint + pad0 {.importc: "__pad0".}: cint st_rdev*: Dev ## Device ID (if file is character or block special). st_size*: Off ## For regular files, the file size in bytes. ## For symbolic links, the length in bytes of the @@ -244,8 +241,6 @@ type st_atim*: Timespec ## Time of last access. st_mtim*: Timespec ## Time of last data modification. st_ctim*: Timespec ## Time of last status change. - reserved: array[3, clong] - Statvfs* {.importc: "struct statvfs", header: "", final, pure.} = object ## struct statvfs @@ -573,8 +568,6 @@ var # Regenerate using detect.nim! include posix_linux_amd64_consts -const POSIX_SPAWN_USEVFORK* = cint(0x40) # needs _GNU_SOURCE! - # proc WEXITSTATUS*(s: cint): cint = (s and 0xff00) shr 8 proc WTERMSIG*(s:cint): cint = s and 0x7f diff --git a/lib/posix/posix_linux_amd64_consts.nim b/lib/posix/posix_linux_amd64_consts.nim index 84296eb9b979..f3230f71d6a3 100644 --- a/lib/posix/posix_linux_amd64_consts.nim +++ b/lib/posix/posix_linux_amd64_consts.nim @@ -128,6 +128,10 @@ const O_RDONLY* = cint(0) const O_RDWR* = cint(2) const O_WRONLY* = cint(1) const O_CLOEXEC* = cint(524288) +const O_DIRECT* = cint(16384) +const O_PATH* = cint(2097152) +const O_NOATIME* = cint(262144) +const O_TMPFILE* = cint(4259840) const POSIX_FADV_NORMAL* = cint(0) const POSIX_FADV_SEQUENTIAL* = cint(2) const POSIX_FADV_RANDOM* = cint(1) @@ -174,13 +178,20 @@ const FNM_NOMATCH* = cint(1) const FNM_PATHNAME* = cint(1) const FNM_PERIOD* = cint(4) const FNM_NOESCAPE* = cint(2) +const FNM_NOSYS* = cint(-1) # const FTW_F* = cint(0) const FTW_D* = cint(1) const FTW_DNR* = cint(2) +const FTW_DP* = cint(5) const FTW_NS* = cint(3) const FTW_SL* = cint(4) +const FTW_SLN* = cint(6) +const FTW_PHYS* = cint(1) +const FTW_MOUNT* = cint(2) +const FTW_DEPTH* = cint(8) +const FTW_CHDIR* = cint(4) # const GLOB_APPEND* = cint(32) @@ -402,6 +413,7 @@ const SS_ONSTACK* = cint(1) const SS_DISABLE* = cint(2) const MINSIGSTKSZ* = cint(2048) const SIGSTKSZ* = cint(8192) +const SIG_HOLD* = cast[Sighandler](2) const SIG_DFL* = cast[Sighandler](0) const SIG_ERR* = cast[Sighandler](-1) const SIG_IGN* = cast[Sighandler](1) @@ -473,7 +485,7 @@ const SOCK_SEQPACKET* = cint(5) const SOCK_STREAM* = cint(1) const SOCK_CLOEXEC* = cint(524288) const SOL_SOCKET* = cint(1) -const SOMAXCONN* = cint(128) +const SOMAXCONN* = cint(4096) const SO_REUSEPORT* = cint(15) const MSG_NOSIGNAL* = cint(16384) const MSG_PEEK* = cint(2) @@ -531,6 +543,7 @@ const POSIX_SPAWN_SETSCHEDPARAM* = cint(16) const POSIX_SPAWN_SETSCHEDULER* = cint(32) const POSIX_SPAWN_SETSIGDEF* = cint(4) const POSIX_SPAWN_SETSIGMASK* = cint(8) +const POSIX_SPAWN_USEVFORK* = cint(64) # const IOFBF* = cint(0) diff --git a/tools/detect/detect.nim b/tools/detect/detect.nim index 0a19a795188d..720e249751cc 100644 --- a/tools/detect/detect.nim +++ b/tools/detect/detect.nim @@ -20,6 +20,8 @@ const cfile = """ /* Generated by detect.nim */ +#define _GNU_SOURCE +#define _POSIX_C_SOURCE 200809L #include #include @@ -119,10 +121,14 @@ proc v(name: string, typ = "cint", no_other = false) = addf(tl, "#ifdef $3\n fprintf(f, \"const $1* = $2(%ld)\\n\", $3);\n#endif\n", n, t, name) - of "cint", "cshort", "InAddrScalar", "TSa_Family": + of "cint", "cshort", "TSa_Family": addf(tl, "#ifdef $3\n fprintf(f, \"const $1* = $2(%d)\\n\", $3);\n#endif\n", n, t, name) + of "InAddrScalar": + addf(tl, + "#ifdef $3\n fprintf(f, \"const $1* = $2(%u)\\n\", $3);\n#endif\n", + n, t, name) else: addf(tl, "#ifdef $3\n fprintf(f, \"const $1* = cast[$2](%d)\\n\", $3);\n#endif\n", @@ -256,6 +262,10 @@ v("O_RDONLY") v("O_RDWR") v("O_WRONLY") v("O_CLOEXEC") +v("O_DIRECT") +v("O_PATH") +v("O_NOATIME") +v("O_TMPFILE") v("POSIX_FADV_NORMAL") v("POSIX_FADV_SEQUENTIAL") v("POSIX_FADV_RANDOM") @@ -433,6 +443,7 @@ header("") v("IPPROTO_IP") v("IPPROTO_IPV6") v("IPPROTO_ICMP") +v("IPPROTO_ICMPV6") v("IPPROTO_RAW") v("IPPROTO_TCP") v("IPPROTO_UDP") @@ -631,10 +642,10 @@ v("MSG_NOSIGNAL", no_other = true) v("MSG_PEEK") v("MSG_TRUNC") v("MSG_WAITALL") -v("AF_INET", "TSa_Family") -v("AF_INET6", "TSa_Family") -v("AF_UNIX", "TSa_Family") -v("AF_UNSPEC", "TSa_Family") +v("AF_INET") +v("AF_INET6") +v("AF_UNIX") +v("AF_UNSPEC") v("SHUT_RD") v("SHUT_RDWR") v("SHUT_WR")