diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 5818964385..9e59f15307 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -216,6 +216,17 @@ inline size_t pread(k2::descriptor descriptor, std::span buffer, uint return k2_pread(descriptor, buffer.size(), static_cast(buffer.data()), offset); } +inline void* mmap(k2::descriptor* md, void* addr, size_t length, int32_t prot, int32_t flags, k2::descriptor fd, uint64_t offset) noexcept { + return k2_mmap(md, addr, length, prot, flags, fd, offset); +} + +inline std::expected madvise(void* addr, size_t length, int32_t advise) noexcept { + if (auto error_code{k2_madvise(addr, length, advise)}; error_code != k2::errno_ok) [[unlikely]] { + return std::unexpected{error_code}; + } + return {}; +} + inline void please_shutdown(k2::descriptor descriptor) noexcept { k2_please_shutdown(descriptor); } diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index 5d16c73890..3dc5136a38 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -356,6 +356,19 @@ size_t k2_read(uint64_t stream_d, size_t buf_len, void* buf); */ size_t k2_pread(uint64_t stream_d, size_t buf_len, void* buf, uint64_t offset); +/** + * Semantically equivalent to libc's `mmap` function. + * + * @param `md` A pointer to a `uint64_t` where the mmap descriptor will be stored upon success. + * @param `addr` Must always be nullptr. + */ +void* k2_mmap(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset); + +/** + * Semantically equivalent to libc's `madvise` function. + */ +int32_t k2_madvise(void* addr, size_t length, int32_t advise); + /** * Sets `StreamStatus.please_whutdown_write=true` for the component on the * opposite side (does not affect `StreamStatus` on your side).