/work/obj-fuzz/dist/include/js/Principals.h
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 | | * vim: set ts=8 sts=4 et sw=4 tw=99: |
3 | | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* JSPrincipals and related interfaces. */ |
8 | | |
9 | | #ifndef js_Principals_h |
10 | | #define js_Principals_h |
11 | | |
12 | | #include "mozilla/Atomics.h" |
13 | | |
14 | | #include <stdint.h> |
15 | | |
16 | | #include "jspubtd.h" |
17 | | |
18 | | struct JSStructuredCloneReader; |
19 | | struct JSStructuredCloneWriter; |
20 | | |
21 | | namespace js { |
22 | | struct JS_PUBLIC_API(PerformanceGroup); |
23 | | } // namespace js |
24 | | |
25 | | struct JSPrincipals { |
26 | | /* Don't call "destroy"; use reference counting macros below. */ |
27 | | mozilla::Atomic<int32_t, |
28 | | mozilla::SequentiallyConsistent, |
29 | | mozilla::recordreplay::Behavior::DontPreserve> refcount; |
30 | | |
31 | | #ifdef JS_DEBUG |
32 | | /* A helper to facilitate principals debugging. */ |
33 | | uint32_t debugToken; |
34 | | #endif |
35 | | |
36 | 5.79k | JSPrincipals() : refcount(0) {} |
37 | | |
38 | 11.5k | void setDebugToken(uint32_t token) { |
39 | | # ifdef JS_DEBUG |
40 | | debugToken = token; |
41 | | # endif |
42 | | } |
43 | | |
44 | | /* |
45 | | * Write the principals with the given |writer|. Return false on failure, |
46 | | * true on success. |
47 | | */ |
48 | | virtual bool write(JSContext* cx, JSStructuredCloneWriter* writer) = 0; |
49 | | |
50 | | /* |
51 | | * This is not defined by the JS engine but should be provided by the |
52 | | * embedding. |
53 | | */ |
54 | | JS_PUBLIC_API(void) dump(); |
55 | | }; |
56 | | |
57 | | extern JS_PUBLIC_API(void) |
58 | | JS_HoldPrincipals(JSPrincipals* principals); |
59 | | |
60 | | extern JS_PUBLIC_API(void) |
61 | | JS_DropPrincipals(JSContext* cx, JSPrincipals* principals); |
62 | | |
63 | | // Return whether the first principal subsumes the second. The exact meaning of |
64 | | // 'subsumes' is left up to the browser. Subsumption is checked inside the JS |
65 | | // engine when determining, e.g., which stack frames to display in a backtrace. |
66 | | typedef bool |
67 | | (* JSSubsumesOp)(JSPrincipals* first, JSPrincipals* second); |
68 | | |
69 | | /* |
70 | | * Used to check if a CSP instance wants to disable eval() and friends. |
71 | | * See GlobalObject::isRuntimeCodeGenEnabled() in vm/GlobalObject.cpp. |
72 | | */ |
73 | | typedef bool |
74 | | (* JSCSPEvalChecker)(JSContext* cx, JS::HandleValue value); |
75 | | |
76 | | struct JSSecurityCallbacks { |
77 | | JSCSPEvalChecker contentSecurityPolicyAllows; |
78 | | JSSubsumesOp subsumes; |
79 | | }; |
80 | | |
81 | | extern JS_PUBLIC_API(void) |
82 | | JS_SetSecurityCallbacks(JSContext* cx, const JSSecurityCallbacks* callbacks); |
83 | | |
84 | | extern JS_PUBLIC_API(const JSSecurityCallbacks*) |
85 | | JS_GetSecurityCallbacks(JSContext* cx); |
86 | | |
87 | | /* |
88 | | * Code running with "trusted" principals will be given a deeper stack |
89 | | * allocation than ordinary scripts. This allows trusted script to run after |
90 | | * untrusted script has exhausted the stack. This function sets the |
91 | | * runtime-wide trusted principal. |
92 | | * |
93 | | * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals). |
94 | | * Instead, the caller must ensure that the given principals stays valid for as |
95 | | * long as 'cx' may point to it. If the principals would be destroyed before |
96 | | * 'cx', JS_SetTrustedPrincipals must be called again, passing nullptr for |
97 | | * 'prin'. |
98 | | */ |
99 | | extern JS_PUBLIC_API(void) |
100 | | JS_SetTrustedPrincipals(JSContext* cx, JSPrincipals* prin); |
101 | | |
102 | | typedef void |
103 | | (* JSDestroyPrincipalsOp)(JSPrincipals* principals); |
104 | | |
105 | | /* |
106 | | * Initialize the callback that is called to destroy JSPrincipals instance |
107 | | * when its reference counter drops to zero. The initialization can be done |
108 | | * only once per JS runtime. |
109 | | */ |
110 | | extern JS_PUBLIC_API(void) |
111 | | JS_InitDestroyPrincipalsCallback(JSContext* cx, JSDestroyPrincipalsOp destroyPrincipals); |
112 | | |
113 | | /* |
114 | | * Read a JSPrincipals instance from the given |reader| and initialize the out |
115 | | * paratemer |outPrincipals| to the JSPrincipals instance read. |
116 | | * |
117 | | * Return false on failure, true on success. The |outPrincipals| parameter |
118 | | * should not be modified if false is returned. |
119 | | * |
120 | | * The caller is not responsible for calling JS_HoldPrincipals on the resulting |
121 | | * JSPrincipals instance, the JSReadPrincipalsOp must increment the refcount of |
122 | | * the resulting JSPrincipals on behalf of the caller. |
123 | | */ |
124 | | using JSReadPrincipalsOp = bool (*)(JSContext* cx, JSStructuredCloneReader* reader, |
125 | | JSPrincipals** outPrincipals); |
126 | | |
127 | | /* |
128 | | * Initialize the callback that is called to read JSPrincipals instances from a |
129 | | * buffer. The initialization can be done only once per JS runtime. |
130 | | */ |
131 | | extern JS_PUBLIC_API(void) |
132 | | JS_InitReadPrincipalsCallback(JSContext* cx, JSReadPrincipalsOp read); |
133 | | |
134 | | |
135 | | #endif /* js_Principals_h */ |