Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions include/fast_io_hosted/platforms/posix_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned long>::max()))
{
throw_posix_error(EINVAL);
}
}
s390_mmap_arg_struct args{
reinterpret_cast<unsigned long>(addr),
static_cast<unsigned long>(len),
static_cast<unsigned long>(prot),
static_cast<unsigned long>(flags),
static_cast<unsigned long>(fd),
static_cast<unsigned long>(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<off_t>::max()))
Expand All @@ -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))
{
Expand Down
Loading