clean up runtime helpers

This commit is contained in:
nmzik
2026-09-17 19:50:21 +04:00
parent 218e7200bb
commit 1211958b4e
12 changed files with 74 additions and 143 deletions
+3 -6
View File
@@ -13,6 +13,7 @@
#include <algorithm>
#include <array>
#include <atomic>
#include <bit>
#include <cstddef>
#include <cstdlib>
#include <cstring>
@@ -3879,10 +3880,6 @@ static bool IsAligned(uint64_t value, uint64_t alignment) {
return alignment == 0 || (value & (alignment - 1u)) == 0;
}
static bool IsPowerOfTwo(uint64_t value) {
return value != 0 && (value & (value - 1u)) == 0;
}
static void MemoryPoolSubtractCommitted(uint64_t len) {
auto current = g_memory_pool_committed.load(std::memory_order_relaxed);
while (current != 0) {
@@ -3904,7 +3901,7 @@ int KYTY_SYSV_ABI KernelMemoryPoolExpand(int64_t search_start, int64_t search_en
if (search_start < 0 || search_end <= search_start || len == 0 ||
(len & (POOL_PAGE_SIZE - 1u)) != 0 || phys_addr_out == nullptr ||
(alignment != 0 &&
(!IsPowerOfTwo(alignment) || (alignment & (POOL_PAGE_SIZE - 1u)) != 0))) {
(!std::has_single_bit(alignment) || (alignment & (POOL_PAGE_SIZE - 1u)) != 0))) {
return KERNEL_ERROR_EINVAL;
}
if (static_cast<uint64_t>(search_end - search_start) < len) {
@@ -3953,7 +3950,7 @@ int KYTY_SYSV_ABI KernelMemoryPoolReserve(void* addr_in, size_t len, size_t alig
return KERNEL_ERROR_EINVAL;
}
if (alignment != 0 &&
(!IsPowerOfTwo(alignment) || !IsAligned(alignment, POOL_RESERVE_ALIGNMENT))) {
(!std::has_single_bit(alignment) || !IsAligned(alignment, POOL_RESERVE_ALIGNMENT))) {
return KERNEL_ERROR_EINVAL;
}
-7
View File
@@ -1202,13 +1202,6 @@ static int32_t GetDstSeconds() {
#endif
}
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS
static void sec_to_timeval(KernelTimeval* ts, double sec) {
ts->tv_sec = static_cast<int64_t>(sec);
ts->tv_usec = static_cast<int64_t>((sec - static_cast<double>(ts->tv_sec)) * 1000000.0);
}
#endif
static bool GetPosixClockId(KernelClockid clock_id, clockid_t* out) {
EXIT_IF(out == nullptr);