Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions runtime-light/k2-platform/k2-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,17 @@ inline size_t pread(k2::descriptor descriptor, std::span<std::byte> buffer, uint
return k2_pread(descriptor, buffer.size(), static_cast<void*>(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<void, int32_t> 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);
}
Expand Down
13 changes: 13 additions & 0 deletions runtime-light/k2-platform/k2-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading