From ec4b0e6ea793141ac85aed1b2a41489646ed65e3 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 15:15:53 +0300 Subject: [PATCH 1/9] added mmap, madvice --- runtime-light/k2-platform/k2-api.h | 11 +++++++++++ runtime-light/k2-platform/k2-header.h | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 5818964385..f9292781a0 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(uint64_t* md, void* addr, size_t length, int prot, int flags, uint64_t fd, off_t offset) noexcept { + return k2_mmap(md, addr, length, prot, flags, fd, offset); +} + +inline std::expected madvise(void* addr, size_t length, int 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..d6e55f1a73 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -356,6 +356,18 @@ 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 mmap success. + */ +void* k2_mmap(uint64_t* md, void* addr, size_t length, int prot, int flags, uint64_t fd, off_t offset); + +/** + * Semantically equivalent to libc's `madvise` function. + */ +int k2_madvise(void* addr, size_t length, int advise); + /** * Sets `StreamStatus.please_whutdown_write=true` for the component on the * opposite side (does not affect `StreamStatus` on your side). From d38408935598035458f18ce6963f315e62eaa9eb Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 16:03:01 +0300 Subject: [PATCH 2/9] minor fix --- runtime-light/k2-platform/k2-header.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index d6e55f1a73..a9986a05cc 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -361,12 +361,12 @@ size_t k2_pread(uint64_t stream_d, size_t buf_len, void* buf, uint64_t offset); * * @param `md` A pointer to a `uint64_t` where the mmap descriptor will be stored mmap success. */ -void* k2_mmap(uint64_t* md, void* addr, size_t length, int prot, int flags, uint64_t fd, off_t offset); +void* k2_mmap(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t flags, uint64_t fd, off_t offset); /** * Semantically equivalent to libc's `madvise` function. */ -int k2_madvise(void* addr, size_t length, int advise); +int32_t k2_madvise(void* addr, size_t length, int32_t advise); /** * Sets `StreamStatus.please_whutdown_write=true` for the component on the From a743b177316c119ddf58217caf6c38a4d6bb9bd2 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 16:13:34 +0300 Subject: [PATCH 3/9] minor fix --- runtime-light/k2-platform/k2-header.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index a9986a05cc..2d4ff26c84 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -359,7 +359,7 @@ 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 mmap success. + * @param `md` A pointer to a `uint64_t` where the mmap descriptor will be stored upon success. */ void* k2_mmap(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t flags, uint64_t fd, off_t offset); From c389e04dbe14afcfd7cf7b895fca4b5e45234372 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 21:45:38 +0300 Subject: [PATCH 4/9] minor fix --- runtime-light/k2-platform/k2-api.h | 6 +++--- runtime-light/k2-platform/k2-header.h | 3 ++- third-party/timelib | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index f9292781a0..64623d62b7 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -216,11 +216,11 @@ 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(uint64_t* md, void* addr, size_t length, int prot, int flags, uint64_t fd, off_t offset) noexcept { - return k2_mmap(md, addr, length, prot, flags, fd, offset); +inline void* mmap(uint64_t* md, void* addr, size_t len, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset) noexcept { + return k2_mmap(md, addr, len, prot, flags, fd, offset); } -inline std::expected madvise(void* addr, size_t length, int advise) noexcept { +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}; } diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index 2d4ff26c84..675343acb2 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -360,8 +360,9 @@ 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, off_t offset); +void* k2_mmap(uint64_t* md, void* addr, size_t len, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset); /** * Semantically equivalent to libc's `madvise` function. diff --git a/third-party/timelib b/third-party/timelib index 624cc5bf30..49af698ad1 160000 --- a/third-party/timelib +++ b/third-party/timelib @@ -1 +1 @@ -Subproject commit 624cc5bf301e211237cea427a8ce0a248684c202 +Subproject commit 49af698ad19cc8045cafd1c7ec246db1199d4016 From fb6f5e254aa2469f9b8062b6abed6efc2fc2d8b2 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 21:48:21 +0300 Subject: [PATCH 5/9] Revert "minor fix" This reverts commit c389e04dbe14afcfd7cf7b895fca4b5e45234372. --- runtime-light/k2-platform/k2-api.h | 6 +++--- runtime-light/k2-platform/k2-header.h | 3 +-- third-party/timelib | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 64623d62b7..f9292781a0 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -216,11 +216,11 @@ 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(uint64_t* md, void* addr, size_t len, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset) noexcept { - return k2_mmap(md, addr, len, prot, flags, fd, offset); +inline void* mmap(uint64_t* md, void* addr, size_t length, int prot, int flags, uint64_t fd, off_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 { +inline std::expected madvise(void* addr, size_t length, int advise) noexcept { if (auto error_code{k2_madvise(addr, length, advise)}; error_code != k2::errno_ok) [[unlikely]] { return std::unexpected{error_code}; } diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index 675343acb2..2d4ff26c84 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -360,9 +360,8 @@ 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 len, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset); +void* k2_mmap(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t flags, uint64_t fd, off_t offset); /** * Semantically equivalent to libc's `madvise` function. diff --git a/third-party/timelib b/third-party/timelib index 49af698ad1..624cc5bf30 160000 --- a/third-party/timelib +++ b/third-party/timelib @@ -1 +1 @@ -Subproject commit 49af698ad19cc8045cafd1c7ec246db1199d4016 +Subproject commit 624cc5bf301e211237cea427a8ce0a248684c202 From 3769963cae4fc037f06643d9b48c9275f6ff23ae Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 21:52:27 +0300 Subject: [PATCH 6/9] minor fix --- runtime-light/k2-platform/k2-api.h | 2 +- runtime-light/k2-platform/k2-header.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index f9292781a0..14cac34ccd 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -216,7 +216,7 @@ 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(uint64_t* md, void* addr, size_t length, int prot, int flags, uint64_t fd, off_t offset) noexcept { +inline void* mmap(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset) noexcept { return k2_mmap(md, addr, length, prot, flags, fd, offset); } diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index 2d4ff26c84..8b5dceddc1 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -360,8 +360,9 @@ 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, off_t offset); +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. From bf1e1fcd4574e82a9eff26d8949f6401f1ad5a7d Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 21:53:04 +0300 Subject: [PATCH 7/9] minor fix --- runtime-light/k2-platform/k2-api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 14cac34ccd..331f7628fd 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -220,7 +220,7 @@ inline void* mmap(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t return k2_mmap(md, addr, length, prot, flags, fd, offset); } -inline std::expected madvise(void* addr, size_t length, int advise) noexcept { +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}; } From 7fa5426a0b788ae506f2313cb7846c34e98d8dc0 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 22:04:25 +0300 Subject: [PATCH 8/9] minor fix --- runtime-light/k2-platform/k2-api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 331f7628fd..9e59f15307 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -216,7 +216,7 @@ 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(uint64_t* md, void* addr, size_t length, int32_t prot, int32_t flags, uint64_t fd, uint64_t offset) noexcept { +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); } From 62258fd02026e4da3f90e486ee47d9de3ed8df50 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Fri, 30 Jan 2026 13:11:54 +0300 Subject: [PATCH 9/9] minor fix --- runtime-light/k2-platform/k2-header.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index 8b5dceddc1..3dc5136a38 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -360,7 +360,7 @@ 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. + * @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);