nlib
CentralHeap.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
17 #define INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
18 
19 #include "nn/nlib/heap/NMalloc.h"
20 
21 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
22 #undef NLIB_VIS_PUBLIC
23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
24 #endif
25 
26 NLIB_NAMESPACE_BEGIN
27 namespace heap {
28 
29 class CachedHeap;
30 class TlsHeapCentral;
32  public:
33  typedef void (*DestructorHandler)(void* start, void* end) NLIB_NOEXCEPT_FUNCPTR;
34 
35  CentralHeap() NLIB_NOEXCEPT : central_(NULL),
36  use_virtual_memory_(false),
37  heap_option_(0),
38  start_(NULL),
39  end_(NULL) {}
40  ~CentralHeap() NLIB_NOEXCEPT { this->Finalize(); }
41  errno_t Init(void* start, size_t size, uint32_t heap_option) NLIB_NOEXCEPT;
42  void Finalize() NLIB_NOEXCEPT;
43  NLIB_ALWAYS_INLINE void* Alloc(size_t n) NLIB_NOEXCEPT { return this->Alloc(n, 8); }
44  void* Alloc(size_t n, size_t algn) NLIB_NOEXCEPT;
45  errno_t Free(void* p) NLIB_NOEXCEPT;
46  errno_t FreeWithSize(void* p, size_t size) NLIB_NOEXCEPT;
47  size_t GetAllocSize(const void* p) NLIB_NOEXCEPT;
48  errno_t Realloc(void* ptr, size_t size, void** p) NLIB_NOEXCEPT;
49 
50  bool MakeCache(CachedHeap* ptr) NLIB_NOEXCEPT;
51  errno_t WalkAllocatedPtrs(nmalloc_heapwalk_callback func, void* user_ptr) NLIB_NOEXCEPT;
52  errno_t QueryV(int query, va_list ap) NLIB_NOEXCEPT;
53  errno_t Query(int query, ...) NLIB_NOEXCEPT;
54  static const size_t kPageSize;
55 
56  private:
57  TlsHeapCentral* central_;
58  bool use_virtual_memory_;
59  uint32_t heap_option_;
60  uint8_t* start_;
61  uint8_t* end_;
63 };
64 
65 } // namespace heap
66 NLIB_NAMESPACE_END
67 
68 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
69 #undef NLIB_VIS_PUBLIC
70 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
71 #endif
72 
73 #endif // INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
int(* nmalloc_heapwalk_callback)(void *allocated_ptr, size_t size, void *user_ptr)
User-defined callback function that is called from nmalloc_walk_allocated_ptrs.
Definition: NMalloc.h:121
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:97
CentralHeap() noexcept
Instantiates the object with default parameters (default constructor).
Definition: CentralHeap.h:35
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:163
File that defines functions including nmalloc and nfree.
~CentralHeap() noexcept
Destructor.
Definition: CentralHeap.h:40
static const size_t kPageSize
Page size of the heap (not related to the operating system page size).
Definition: CentralHeap.h:54
Central heap class whose use is paired with CachedHeap. It is used to implement nmalloc.
Definition: CentralHeap.h:31
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
void * Alloc(size_t n) noexcept
Allocates a memory block.
Definition: CentralHeap.h:43
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
Thread-specific cache class whose use is paired with CentralHeap.
Definition: CachedHeap.h:32
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37