* Reduce code duplication. The Apple and Haiku PALs both had *almost* identical code to the POSIX PAL, differing only in some small argument variables. This is fragile and easy to accidentally get out of sync. For example, the changes to `reserve_at_least` involved copying identical code into multiple PALs and it's easy to accidentally miss one. This change introduces two optional fields on POSIX-derived PALs: - `default_mmap_flags` allows a PAL to provide additional `MAP_*` flags to all `mmap` calls. - `anonymous_memory_fd` allows the PAL to override the default file descriptor used for memory mappings. If a PAL does not provide these, default values are used. Fixes #219
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#ifdef __APPLE__
|
|
# include "pal_bsd.h"
|
|
|
|
# include <mach/vm_statistics.h>
|
|
# include <utility>
|
|
|
|
namespace snmalloc
|
|
{
|
|
/**
|
|
* PAL implementation for Apple systems (macOS, iOS, watchOS, tvOS...).
|
|
*/
|
|
template<int PALAnonID = PALAnonDefaultID>
|
|
class PALApple : public PALBSD<PALApple<>>
|
|
{
|
|
public:
|
|
/**
|
|
* The features exported by this PAL.
|
|
*
|
|
* Currently, these are identical to the generic BSD PAL. This field is
|
|
* declared explicitly to remind anyone who modifies this class that they
|
|
* should add any required features.
|
|
*/
|
|
static constexpr uint64_t pal_features = PALBSD::pal_features;
|
|
|
|
/**
|
|
* Anonymous page tag ID.
|
|
*
|
|
* Darwin platform allows to gives an ID to anonymous pages via
|
|
* the VM_MAKE_TAG's macro, from 240 up to 255 are guaranteed
|
|
* to be free of usage, however eventually a lower could be taken
|
|
* (e.g. LLVM sanitizers has 99) so we can monitor their states
|
|
* via vmmap for instance. This value is provided to `mmap` as the file
|
|
* descriptor for the mapping.
|
|
*/
|
|
static constexpr int anonymous_memory_fd = VM_MAKE_TAG(PALAnonID);
|
|
};
|
|
} // namespace snmalloc
|
|
#endif
|