fix: get right page size when malloc uses 0 alignment

Related-To: GSD-7103

Signed-off-by: Lu, Wenbin <wenbin.lu@intel.com>
This commit is contained in:
Lu, Wenbin
2023-12-05 19:30:46 +00:00
committed by Compute-Runtime-Automation
parent 739d181026
commit 67fa39c9a1
5 changed files with 39 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -25,6 +25,15 @@ constexpr inline TNoRef alignUp(T before, size_t alignment) {
return (before + mask) & ~mask;
}
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
constexpr inline TNoRef alignUpNonZero(T before, size_t alignment) {
if (before == 0) {
return alignment;
} else {
return alignUp(before, alignment);
}
}
template <typename T>
constexpr inline T *alignUp(T *ptrBefore, size_t alignment) {
return reinterpret_cast<T *>(alignUp(reinterpret_cast<uintptr_t>(ptrBefore), alignment));