Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 1 | // 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 | |
mikt | dc1d5a6 | 2024-07-29 20:43:02 | [diff] [blame] | 8 | #include "partition_alloc/buildflags.h" |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 9 | |
Arthur Sonzogni | 62e877a | 2024-04-30 16:09:43 | [diff] [blame] | 10 | #if PA_BUILDFLAG(ENABLE_THREAD_ISOLATION) |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 11 | |
Arthur Sonzogni | 62e877a | 2024-04-30 16:09:43 | [diff] [blame] | 12 | #if !PA_BUILDFLAG(ENABLE_PKEYS) |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 13 | #error Not implemented for non-pkey thread isolation |
Arthur Sonzogni | 62e877a | 2024-04-30 16:09:43 | [diff] [blame] | 14 | #endif // PA_BUILDFLAG(ENABLE_PKEYS) |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 15 | |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 16 | #include "gin/gin_export.h" |
mikt | dc1d5a6 | 2024-07-29 20:43:02 | [diff] [blame] | 17 | #include "partition_alloc/partition_alloc.h" |
Nikolaos Papaspyrou | 22c0db4 | 2023-06-21 07:23:24 | [diff] [blame] | 18 | #include "v8/include/v8-platform.h" |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 19 | |
| 20 | namespace gin { |
| 21 | |
| 22 | // This is a wrapper around PartitionAlloc's ThreadIsolated pool that we pass to |
| 23 | // v8. |
| 24 | class 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 Sonzogni | 62e877a | 2024-04-30 16:09:43 | [diff] [blame] | 45 | #endif // PA_BUILDFLAG(ENABLE_THREAD_ISOLATION) |
Stephen Roettger | f704ffd | 2023-05-15 08:18:39 | [diff] [blame] | 46 | |
| 47 | #endif // GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_ |