blob: 368367635699b44131951853154661b1f65b5bb5 [file] [log] [blame]
Stephen Roettgerf704ffd2023-05-15 08:18:391// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_
6#define GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_
7
miktdc1d5a62024-07-29 20:43:028#include "partition_alloc/buildflags.h"
Stephen Roettgerf704ffd2023-05-15 08:18:399
Arthur Sonzogni62e877a2024-04-30 16:09:4310#if PA_BUILDFLAG(ENABLE_THREAD_ISOLATION)
Stephen Roettgerf704ffd2023-05-15 08:18:3911
Arthur Sonzogni62e877a2024-04-30 16:09:4312#if !PA_BUILDFLAG(ENABLE_PKEYS)
Stephen Roettgerf704ffd2023-05-15 08:18:3913#error Not implemented for non-pkey thread isolation
Arthur Sonzogni62e877a2024-04-30 16:09:4314#endif // PA_BUILDFLAG(ENABLE_PKEYS)
Stephen Roettgerf704ffd2023-05-15 08:18:3915
Stephen Roettgerf704ffd2023-05-15 08:18:3916#include "gin/gin_export.h"
miktdc1d5a62024-07-29 20:43:0217#include "partition_alloc/partition_alloc.h"
Nikolaos Papaspyrou22c0db42023-06-21 07:23:2418#include "v8/include/v8-platform.h"
Stephen Roettgerf704ffd2023-05-15 08:18:3919
20namespace gin {
21
22// This is a wrapper around PartitionAlloc's ThreadIsolated pool that we pass to
23// v8.
24class GIN_EXPORT ThreadIsolatedAllocator final
25 : public v8::ThreadIsolatedAllocator {
26 public:
27 ThreadIsolatedAllocator();
28 ~ThreadIsolatedAllocator() override;
29
30 void Initialize(int pkey);
31
32 void* Allocate(size_t size) override;
33 void Free(void* object) override;
34 enum Type Type() const override;
35
36 int Pkey() const override;
37
38 private:
39 partition_alloc::PartitionAllocator allocator_;
40 int pkey_ = -1;
41};
42
43} // namespace gin
44
Arthur Sonzogni62e877a2024-04-30 16:09:4345#endif // PA_BUILDFLAG(ENABLE_THREAD_ISOLATION)
Stephen Roettgerf704ffd2023-05-15 08:18:3946
47#endif // GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_