blob: a084378406285c6061ec2f834140ef607589d8c6 [file] [log] [blame]
Orion Hodson01ecfa12019-07-18 12:57:47 +01001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_HIDDEN_API_JNI_H_
18#define ART_RUNTIME_HIDDEN_API_JNI_H_
19
20#include "base/macros.h"
21
22namespace art {
23
24class Thread;
25
26namespace hiddenapi {
27
28// Stack markers that should be instantiated in JNI Get{Field,Method}Id methods (and
29// their static equivalents) to allow native caller checks to take place.
30class ScopedCorePlatformApiCheck final {
31 public:
32 ScopedCorePlatformApiCheck();
33 ~ScopedCorePlatformApiCheck();
34
35 // Check whether the caller is automatically approved based on location. Code in the run-time or
36 // in an APEX is considered to be automatically approved.
37 static bool IsCurrentCallerApproved(Thread* self);
38
39 private:
40 // Captures calling PC for frame above the frame allocating the current ScopedCorePlatformApiCheck
41 // instance.
42 void* CaptureCallerPc();
43
44 // Instances should only be stack allocated, copy and assignment not useful.
45 DISALLOW_ALLOCATION();
46 DISALLOW_COPY_AND_ASSIGN(ScopedCorePlatformApiCheck);
47};
48
49void JniInitializeNativeCallerCheck();
50void JniShutdownNativeCallerCheck();
51
52} // namespace hiddenapi
53} // namespace art
54
55#endif // ART_RUNTIME_HIDDEN_API_JNI_H_