• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "MockAndroidVmOperations.h"
16 #include "HostAddressSpace.h"
17 #include "host-common/HostmemIdMapping.h"
18 
19 using android::HostAddressSpaceDevice;
20 
21 static bool sSkipSnapshotSave = false;
22 
23 static const QAndroidVmOperations sQAndroidVmOperations = {
__anonebad62460102() 24         .vmStop = []() -> bool {
25             return android::MockAndroidVmOperations::mock->vmStop();
26         },
__anonebad62460202() 27         .vmStart = []() -> bool {
28             return android::MockAndroidVmOperations::mock->vmStart();
29         },
30         .vmReset = nullptr,       // Not currently mocked.
31         .vmShutdown = nullptr,    // Not currently mocked.
32         .vmPause = nullptr,       // Not currently mocked.
33         .vmResume = nullptr,      // Not currently mocked.
34         .vmIsRunning = nullptr,   // Not currently mocked.
35         .snapshotList = nullptr,  // Not currently mocked.
36         .snapshotSave = [](const char* name,
37                            void* opaque,
__anonebad62460302() 38                            LineConsumerCallback errConsumer) -> bool {
39             return android::MockAndroidVmOperations::mock->snapshotSave(
40                     name, opaque, errConsumer);
41         },
42         .snapshotLoad = [](const char* name,
43                            void* opaque,
__anonebad62460402() 44                            LineConsumerCallback errConsumer) -> bool {
45             return android::MockAndroidVmOperations::mock->snapshotLoad(
46                     name, opaque, errConsumer);
47         },
48         .snapshotDelete = nullptr,  // Not currently mocked.
49         .snapshotRemap = [](bool shared,
50                             void* opaque,
__anonebad62460502() 51                             LineConsumerCallback errConsumer) -> bool {
52             return android::MockAndroidVmOperations::mock->snapshotRemap(
53                     shared, opaque, errConsumer);
54         },
55         .snapshotExport = [](const char* snapshot,
56                              const char* dest,
57                              void* opaque,
__anonebad62460602() 58                              LineConsumerCallback errConsumer) -> bool {
59             return android::MockAndroidVmOperations::mock->snapshotExport(
60                     snapshot, dest, opaque, errConsumer);
61         },
62         .setSnapshotCallbacks =
__anonebad62460702() 63                 [](void* opaque, const SnapshotCallbacks* callbacks) {
64                     return android::MockAndroidVmOperations::mock
65                             ->setSnapshotCallbacks(opaque, callbacks);
66                 },
67         .mapUserBackedRam =
__anonebad62460802() 68                 [](uint64_t gpa, void* hva, uint64_t size) {
69                     HostAddressSpaceDevice::get()->setHostAddrByPhysAddr(gpa,
70                                                                          hva);
71                 },
72         .unmapUserBackedRam =
__anonebad62460902() 73                 [](uint64_t gpa, uint64_t size) {
74                     HostAddressSpaceDevice::get()->unsetHostAddrByPhysAddr(gpa);
75                 },
76         .getVmConfiguration = nullptr,  // Not currently mocked.
77         .setFailureReason = nullptr,    // Not currently mocked.
78         .setExiting = nullptr,          // Not currently mocked.
79         .allowRealAudio = nullptr,      // Not currently mocked.
80         .physicalMemoryGetAddr =
__anonebad62460a02() 81                 [](uint64_t gpa) {
82                     void* res = HostAddressSpaceDevice::get()->getHostAddr(gpa);
83                     if (!res)
84                         return (void*)(uintptr_t)gpa;
85                     return res;
86                 },
87         .isRealAudioAllowed = nullptr,  // Not currently mocked.
__anonebad62460b02() 88         .setSkipSnapshotSave = [](bool skip) { sSkipSnapshotSave = skip; },
__anonebad62460c02() 89         .isSnapshotSaveSkipped = []() -> bool { return sSkipSnapshotSave; },
90         .hostmemRegister = android_emulation_hostmem_register,
91         .hostmemUnregister = android_emulation_hostmem_unregister,
92         .hostmemGetInfo = android_emulation_hostmem_get_info,
93 };
94 
95 extern "C" const QAndroidVmOperations* const gMockQAndroidVmOperations =
96         &sQAndroidVmOperations;
97 
98 namespace android {
99 
100 MockAndroidVmOperations* MockAndroidVmOperations::mock = nullptr;
101 
102 }  // namespace android
103