[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / gin / thread_isolation.h
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_THREAD_ISOLATION_H_
6 #define GIN_THREAD_ISOLATION_H_
7
8 #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h"
9
10 #if BUILDFLAG(ENABLE_THREAD_ISOLATION)
11
12 #include "base/allocator/partition_allocator/src/partition_alloc/thread_isolation/alignment.h"
13 #include "base/no_destructor.h"
14 #include "gin/gin_export.h"
15 #include "gin/v8_platform_thread_isolated_allocator.h"
16
17 namespace gin {
18
19 // All data used for thread isolation needs to live in this struct since we need
20 // to write-protect it with the same thread isolation mechanism.
21 // The implementation is platform specific, e.g. using pkeys on x64.
22 struct GIN_EXPORT PA_THREAD_ISOLATED_ALIGN ThreadIsolationData {
23   // If we're using pkeys for isolation, we need to allocate the key before
24   // spawning any threads. Otherwise, the other threads will not have read
25   // permissions to memory tagged with this key.
26   void InitializeBeforeThreadCreation();
27
28   // Returns if InitializeBeforeThreadCreation has been called and the
29   // initialization was successful, i.e. the platform supports the isolation
30   // mechanism.
31   bool Initialized() const;
32
33   base::NoDestructor<ThreadIsolatedAllocator> allocator;
34   int pkey = -1;
35 };
36 static_assert(PA_THREAD_ISOLATED_FILL_PAGE_SZ(sizeof(ThreadIsolationData)) ==
37               0);
38
39 GIN_EXPORT ThreadIsolationData& GetThreadIsolationData();
40
41 }  // namespace gin
42
43 #endif  // BUILDFLAG(ENABLE_THREAD_ISOLATION)
44
45 #endif  // GIN_THREAD_ISOLATION_H_