chromium/v8/src/base/platform/memory.h

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASE_PLATFORM_MEMORY_H_
#define V8_BASE_PLATFORM_MEMORY_H_

#include <cstddef>
#include <cstdlib>

#include "include/v8config.h"
#include "src/base/bits.h"
#include "src/base/logging.h"
#include "src/base/macros.h"

#if V8_OS_STARBOARD
#include "starboard/memory.h"
#endif  // V8_OS_STARBOARD

#if V8_OS_DARWIN
#include <malloc/malloc.h>
#elif V8_OS_OPENBSD
#include <sys/malloc.h>
#elif V8_OS_ZOS
#include <stdlib.h>
#else
#include <malloc.h>
#endif

#if (V8_OS_POSIX && !V8_OS_AIX && !V8_OS_SOLARIS && !V8_OS_ZOS && !V8_OS_OPENBSD) || V8_OS_WIN
#define V8_HAS_MALLOC_USABLE_SIZE
#endif

namespace v8::base {

inline void* Malloc(size_t size) {}

inline void* Realloc(void* memory, size_t size) {}

inline void Free(void* memory) {}

inline void* Calloc(size_t count, size_t size) {}

// Aligned allocation. Memory must be freed with `AlignedFree()` as not all
// platforms support using general free for aligned allocations.
inline void* AlignedAlloc(size_t size, size_t alignment) {}

inline void AlignedFree(void* ptr) {}

#if V8_HAS_MALLOC_USABLE_SIZE

// Note that the use of additional bytes that deviate from the original
// `Malloc()` request returned by `MallocUsableSize()` is not UBSan-safe. Use
// `AllocateAtLeast()` for a safe version.
inline size_t MallocUsableSize(void* ptr) {}

#endif  // V8_HAS_MALLOC_USABLE_SIZE

// Mimics C++23 `allocation_result`.
template <class Pointer>
struct AllocationResult {};

// Allocates at least `n * sizeof(T)` uninitialized storage but may allocate
// more which is indicated by the return value. Mimics C++23
// `allocate_at_least()`.
template <typename T>
V8_NODISCARD AllocationResult<T*> AllocateAtLeast(size_t n) {}

}  // namespace v8::base

#undef V8_HAS_MALLOC_USABLE_SIZE

#endif  // V8_BASE_PLATFORM_MEMORY_H_