forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv8_platform_thread_isolated_allocator.cc
54 lines (40 loc) · 1.5 KB
/
v8_platform_thread_isolated_allocator.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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.
#include "gin/v8_platform_thread_isolated_allocator.h"
#include "base/allocator/partition_allocator/partition_root.h"
#if BUILDFLAG(ENABLE_THREAD_ISOLATION)
#include <sys/mman.h>
#include <sys/syscall.h>
#include "base/allocator/partition_allocator/thread_isolation/pkey.h"
#include "gin/thread_isolation.h"
#if BUILDFLAG(ENABLE_PKEYS)
#else // BUILDFLAG(ENABLE_PKEYS)
#error Not implemented for non-pkey thread isolation
#endif // BUILDFLAG(ENABLE_PKEYS)
namespace gin {
ThreadIsolatedAllocator::ThreadIsolatedAllocator() = default;
ThreadIsolatedAllocator::~ThreadIsolatedAllocator() = default;
void ThreadIsolatedAllocator::Initialize(int pkey) {
pkey_ = pkey;
allocator_.init(partition_alloc::PartitionOptions{
.aligned_alloc =
partition_alloc::PartitionOptions::AlignedAlloc::kAllowed,
.thread_isolation = partition_alloc::ThreadIsolationOption(pkey_),
});
}
void* ThreadIsolatedAllocator::Allocate(size_t size) {
return allocator_.root()->AllocWithFlagsNoHooks(
0, size, partition_alloc::PartitionPageSize());
}
void ThreadIsolatedAllocator::Free(void* object) {
allocator_.root()->FreeNoHooks(object);
}
enum ThreadIsolatedAllocator::Type ThreadIsolatedAllocator::Type() const {
return Type::kPkey;
}
int ThreadIsolatedAllocator::Pkey() const {
return pkey_;
}
} // namespace gin
#endif // BUILDFLAG(ENABLE_THREAD_ISOLATION)