#ifndef SCUDO_COMMON_H_
#define SCUDO_COMMON_H_
#include "internal_defs.h"
#include "fuchsia.h"
#include "linux.h"
#include "trusty.h"
#include <stddef.h>
#include <string.h>
#include <unistd.h>
namespace scudo {
template <class Dest, class Source> inline Dest bit_cast(const Source &S) { … }
inline constexpr bool isPowerOfTwo(uptr X) { … }
inline constexpr uptr roundUp(uptr X, uptr Boundary) { … }
inline constexpr uptr roundUpSlow(uptr X, uptr Boundary) { … }
inline constexpr uptr roundDown(uptr X, uptr Boundary) { … }
inline constexpr uptr roundDownSlow(uptr X, uptr Boundary) { … }
inline constexpr bool isAligned(uptr X, uptr Alignment) { … }
inline constexpr bool isAlignedSlow(uptr X, uptr Alignment) { … }
template <class T> constexpr T Min(T A, T B) { … }
template <class T> constexpr T Max(T A, T B) { … }
template <class T> void Swap(T &A, T &B) { … }
inline uptr getMostSignificantSetBitIndex(uptr X) { … }
inline uptr roundUpPowerOfTwo(uptr Size) { … }
inline uptr getLeastSignificantSetBitIndex(uptr X) { … }
inline uptr getLog2(uptr X) { … }
inline u32 getRandomU32(u32 *State) { … }
inline u32 getRandomModN(u32 *State, u32 N) { … }
template <typename T> inline void shuffle(T *A, u32 N, u32 *RandState) { … }
inline void computePercentage(uptr Numerator, uptr Denominator, uptr *Integral,
uptr *Fractional) { … }
#if defined(SCUDO_PAGE_SIZE)
inline constexpr uptr getPageSizeCached() { return SCUDO_PAGE_SIZE; }
inline constexpr uptr getPageSizeSlow() { return getPageSizeCached(); }
inline constexpr uptr getPageSizeLogCached() {
return static_cast<uptr>(__builtin_ctzl(SCUDO_PAGE_SIZE));
}
#else
extern uptr PageSizeCached;
extern uptr PageSizeLogCached;
uptr getPageSizeSlow();
inline uptr getPageSizeCached() { … }
inline uptr getPageSizeLogCached() { … }
#endif
u32 getNumberOfCPUs();
const char *getEnv(const char *Name);
u64 getMonotonicTime();
u64 getMonotonicTimeFast();
u32 getThreadID();
constexpr uptr MaxRandomLength = …;
bool getRandom(void *Buffer, uptr Length, bool Blocking = false);
#define MAP_ALLOWNOMEM …
#define MAP_NOACCESS …
#define MAP_RESIZABLE …
#define MAP_MEMTAG …
#define MAP_PRECOMMIT …
void *map(void *Addr, uptr Size, const char *Name, uptr Flags = 0,
MapPlatformData *Data = nullptr);
#define UNMAP_ALL …
void unmap(void *Addr, uptr Size, uptr Flags = 0,
MapPlatformData *Data = nullptr);
void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
MapPlatformData *Data = nullptr);
void releasePagesToOS(uptr BaseAddress, uptr Offset, uptr Size,
MapPlatformData *Data = nullptr);
void setAbortMessage(const char *Message);
struct BlockInfo { … };
enum class Option : u8 { … };
enum class ReleaseToOS : u8 { … };
constexpr unsigned char PatternFillByte = …;
enum FillContentsMode { … };
}
#endif