chromium/base/allocator/partition_allocator/src/partition_alloc/shim/shim_alloc_functions.h

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef PARTITION_ALLOC_SHIM_SHIM_ALLOC_FUNCTIONS_H_
#error This header is meant to be included only once by allocator_shim*.cc
#endif

#ifndef PARTITION_ALLOC_SHIM_SHIM_ALLOC_FUNCTIONS_H_
#define PARTITION_ALLOC_SHIM_SHIM_ALLOC_FUNCTIONS_H_

#include <cerrno>

#include "partition_alloc/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/partition_alloc_base/bits.h"
#include "partition_alloc/partition_alloc_base/compiler_specific.h"
#include "partition_alloc/partition_alloc_base/memory/page_size.h"
#include "partition_alloc/partition_alloc_check.h"

namespace {

PA_ALWAYS_INLINE size_t GetCachedPageSize() {}

}  // namespace

// The Shim* functions below are the entry-points into the shim-layer and
// are supposed to be invoked by the allocator_shim_override_*
// headers to route the malloc / new symbols through the shim layer.
// They are defined as ALWAYS_INLINE in order to remove a level of indirection
// between the system-defined entry points and the shim implementations.
extern "C" {

// The general pattern for allocations is:
// - Try to allocate, if succeeded return the pointer.
// - If the allocation failed:
//   - Call the std::new_handler if it was a C++ allocation.
//   - Call the std::new_handler if it was a malloc() (or calloc() or similar)
//     AND Setallocator_shim::internal::CallNewHandlerOnMallocFailure(true).
//   - If the std::new_handler is NOT set just return nullptr.
//   - If the std::new_handler is set:
//     - Assume it will abort() if it fails (very likely the new_handler will
//       just suicide printing a message).
//     - Assume it did succeed if it returns, in which case reattempt the alloc.

PA_ALWAYS_INLINE void* ShimCppNew(size_t size) {}

PA_ALWAYS_INLINE void* ShimCppNewNoThrow(size_t size) {}

PA_ALWAYS_INLINE void* ShimCppAlignedNew(size_t size, size_t alignment) {}

PA_ALWAYS_INLINE void ShimCppDelete(void* address) {}

PA_ALWAYS_INLINE void* ShimMalloc(size_t size, void* context) {}

PA_ALWAYS_INLINE void* ShimCalloc(size_t n, size_t size, void* context) {}

PA_ALWAYS_INLINE void* ShimRealloc(void* address, size_t size, void* context) {}

PA_ALWAYS_INLINE void* ShimMemalign(size_t alignment,
                                    size_t size,
                                    void* context) {}

PA_ALWAYS_INLINE int ShimPosixMemalign(void** res,
                                       size_t alignment,
                                       size_t size) {}

PA_ALWAYS_INLINE void* ShimValloc(size_t size, void* context) {}

PA_ALWAYS_INLINE void* ShimPvalloc(size_t size) {}

PA_ALWAYS_INLINE void ShimFree(void* address, void* context) {}

PA_ALWAYS_INLINE size_t ShimGetSizeEstimate(const void* address,
                                            void* context) {}

PA_ALWAYS_INLINE size_t ShimGoodSize(size_t size, void* context) {}

PA_ALWAYS_INLINE bool ShimClaimedAddress(void* address, void* context) {}

PA_ALWAYS_INLINE unsigned ShimBatchMalloc(size_t size,
                                          void** results,
                                          unsigned num_requested,
                                          void* context) {}

PA_ALWAYS_INLINE void ShimBatchFree(void** to_be_freed,
                                    unsigned num_to_be_freed,
                                    void* context) {}

PA_ALWAYS_INLINE void ShimFreeDefiniteSize(void* ptr,
                                           size_t size,
                                           void* context) {}

PA_ALWAYS_INLINE void ShimTryFreeDefault(void* ptr, void* context) {}

PA_ALWAYS_INLINE void* ShimAlignedMalloc(size_t size,
                                         size_t alignment,
                                         void* context) {}

PA_ALWAYS_INLINE void* ShimAlignedRealloc(void* address,
                                          size_t size,
                                          size_t alignment,
                                          void* context) {}

PA_ALWAYS_INLINE void ShimAlignedFree(void* address, void* context) {}

#undef PA_ALWAYS_INLINE

}  // extern "C"

#endif  // PARTITION_ALLOC_SHIM_SHIM_ALLOC_FUNCTIONS_H_