From aeed549ae23b54e846e008fe168dbfee4df64909 Mon Sep 17 00:00:00 2001 From: MacroModel <33865334+MacroModel@users.noreply.github.com> Date: Mon, 22 Jun 2026 05:55:29 +0800 Subject: [PATCH] Update posix_mapping.h --- .../fast_io_hosted/platforms/posix_mapping.h | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/fast_io_hosted/platforms/posix_mapping.h b/include/fast_io_hosted/platforms/posix_mapping.h index 2431568d8..4a5e769b6 100644 --- a/include/fast_io_hosted/platforms/posix_mapping.h +++ b/include/fast_io_hosted/platforms/posix_mapping.h @@ -11,6 +11,36 @@ namespace details inline ::std::byte *sys_mmap(void *addr, ::std::size_t len, int prot, int flags, int fd, ::std::uintmax_t offset) { #if defined(__linux__) && defined(__NR_mmap) && !defined(__NR_mmap2) +#if defined(__s390__) || defined(__s390x__) + // s390 __NR_mmap is the old single-argument entry; pass the kernel's mmap argument block. + struct s390_mmap_arg_struct + { + unsigned long addr; + unsigned long len; + unsigned long prot; + unsigned long flags; + unsigned long fd; + unsigned long offset; + }; + + if constexpr (sizeof(::std::uintmax_t) > sizeof(unsigned long)) + { + if (offset > static_cast<::std::uintmax_t>(::std::numeric_limits::max())) + { + throw_posix_error(EINVAL); + } + } + s390_mmap_arg_struct args{ + reinterpret_cast(addr), + static_cast(len), + static_cast(prot), + static_cast(flags), + static_cast(fd), + static_cast(offset)}; + ::std::ptrdiff_t ret{system_call<__NR_mmap, ::std::ptrdiff_t>(__builtin_addressof(args))}; + system_call_throw_error(ret); + return reinterpret_cast<::std::byte *>(static_cast<::std::uintptr_t>(ret)); +#else if constexpr (sizeof(::std::uintmax_t) > sizeof(off_t)) { if (offset > static_cast<::std::uintmax_t>(::std::numeric_limits::max())) @@ -21,6 +51,7 @@ inline ::std::byte *sys_mmap(void *addr, ::std::size_t len, int prot, int flags, ::std::ptrdiff_t ret{system_call<__NR_mmap, ::std::ptrdiff_t>(addr, len, prot, flags, fd, offset)}; system_call_throw_error(ret); return reinterpret_cast<::std::byte *>(static_cast<::std::uintptr_t>(ret)); +#endif #elif defined(HAVE_MMAP64) if constexpr (sizeof(::std::uintmax_t) > sizeof(off64_t)) {