-
Notifications
You must be signed in to change notification settings - Fork 523
/
Copy pathutils.h
39 lines (34 loc) · 959 Bytes
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <cstddef>
#include <cstdint>
#pragma once
namespace executorch {
namespace etdump {
namespace internal {
/**
* Aligns a pointer to the next multiple of `alignment`.
*
* @param[in] ptr Pointer to align.
* @param[in] alignment Alignment to align to. Must be a power of 2 and cannot
* be 0.
*
* @returns A pointer aligned to `alignment`.
*/
inline uint8_t* align_pointer(void* ptr, size_t alignment) {
intptr_t addr = reinterpret_cast<intptr_t>(ptr);
if ((addr & (alignment - 1)) == 0) {
// Already aligned.
return reinterpret_cast<uint8_t*>(ptr);
}
addr = (addr | (alignment - 1)) + 1;
return reinterpret_cast<uint8_t*>(addr);
}
} // namespace internal
} // namespace etdump
} // namespace executorch