1 // Copyright 2019 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 #include "host-common/address_space_device.h"
15 #include "host-common/AddressSpaceService.h"
16 #include "host-common/address_space_graphics.h"
17 #ifndef AEMU_MIN
18 #include "host-common/address_space_host_media.h"
19 #endif
20 #include "host-common/address_space_host_memory_allocator.h"
21 #include "host-common/address_space_shared_slots_host_memory_allocator.h"
22 #include "host-common/vm_operations.h"
23
24 #include "aemu/base/synchronization/Lock.h"
25
26 #include <map>
27 #include <unordered_map>
28 #include <memory>
29
30 using android::base::AutoLock;
31 using android::base::Lock;
32 using android::base::Stream;
33 using android::emulation::asg::AddressSpaceGraphicsContext;
34
35 using namespace android::emulation;
36
37 #define AS_DEVICE_DEBUG 0
38
39 #if AS_DEVICE_DEBUG
40 #define AS_DEVICE_DPRINT(fmt,...) fprintf(stderr, "%s:%d " fmt "\n", __func__, __LINE__, ##__VA_ARGS__);
41 #else
42 #define AS_DEVICE_DPRINT(fmt,...)
43 #endif
44
45 const QAndroidVmOperations* sVmOps = nullptr;
46
47 namespace {
48
49 class AddressSpaceDeviceState {
50 public:
51 AddressSpaceDeviceState() = default;
52 ~AddressSpaceDeviceState() = default;
53
genHandle()54 uint32_t genHandle() {
55 AutoLock lock(mContextsLock);
56
57 auto res = mHandleIndex;
58
59 if (!res) {
60 ++res;
61 mHandleIndex += 2;
62 } else {
63 ++mHandleIndex;
64 }
65
66 AS_DEVICE_DPRINT("new handle: %u", res);
67 return res;
68 }
69
destroyHandle(uint32_t handle)70 void destroyHandle(uint32_t handle) {
71 AS_DEVICE_DPRINT("erase handle: %u", handle);
72
73 std::unique_ptr<AddressSpaceDeviceContext> context;
74
75 {
76 AutoLock lock(mContextsLock);
77
78 auto contextDescriptionIt = mContexts.find(handle);
79 if (contextDescriptionIt == mContexts.end()) return;
80 auto& contextDescription = contextDescriptionIt->second;
81
82 context = std::move(contextDescription.device_context);
83
84 mContexts.erase(contextDescriptionIt);
85 }
86
87 // Destroy `context` without holding the lock.
88 }
89
tellPingInfo(uint32_t handle,uint64_t gpa)90 void tellPingInfo(uint32_t handle, uint64_t gpa) {
91 AutoLock lock(mContextsLock);
92 auto& contextDesc = mContexts[handle];
93 contextDesc.pingInfo =
94 (AddressSpaceDevicePingInfo*)
95 sVmOps->physicalMemoryGetAddr(gpa);
96 contextDesc.pingInfoGpa = gpa;
97 AS_DEVICE_DPRINT("Ping info: gpa 0x%llx @ %p\n", (unsigned long long)gpa,
98 contextDesc.pingInfo);
99 }
100
createInstance(const struct AddressSpaceCreateInfo & create)101 void createInstance(const struct AddressSpaceCreateInfo& create) {
102 AutoLock lock(mContextsLock);
103 auto& contextDesc = mContexts[create.handle];
104 contextDesc.device_context = buildAddressSpaceDeviceContext(create);
105 }
106
ping(uint32_t handle)107 void ping(uint32_t handle) {
108 AutoLock lock(mContextsLock);
109 auto& contextDesc = mContexts[handle];
110 AddressSpaceDevicePingInfo* pingInfo = contextDesc.pingInfo;
111
112 const uint64_t phys_addr = pingInfo->phys_addr;
113
114 AS_DEVICE_DPRINT(
115 "handle %u data 0x%llx -> %p size %llu meta 0x%llx\n", handle,
116 (unsigned long long)phys_addr,
117 sVmOps->physicalMemoryGetAddr(phys_addr),
118 (unsigned long long)pingInfo->size, (unsigned long long)pingInfo->metadata);
119
120 AddressSpaceDeviceContext *device_context = contextDesc.device_context.get();
121 if (device_context) {
122 device_context->perform(pingInfo);
123 } else {
124 // The first ioctl establishes the device type
125 struct AddressSpaceCreateInfo create = {0};
126 create.type = static_cast<AddressSpaceDeviceType>(pingInfo->metadata);
127 create.physAddr = phys_addr;
128
129 contextDesc.device_context = buildAddressSpaceDeviceContext(create);
130 pingInfo->metadata = contextDesc.device_context ? 0 : -1;
131 }
132 }
133
pingAtHva(uint32_t handle,AddressSpaceDevicePingInfo * pingInfo)134 void pingAtHva(uint32_t handle, AddressSpaceDevicePingInfo* pingInfo) {
135 AutoLock lock(mContextsLock);
136 auto& contextDesc = mContexts[handle];
137
138 const uint64_t phys_addr = pingInfo->phys_addr;
139
140 AS_DEVICE_DPRINT(
141 "handle %u data 0x%llx -> %p size %llu meta 0x%llx\n", handle,
142 (unsigned long long)phys_addr,
143 sVmOps->physicalMemoryGetAddr(phys_addr),
144 (unsigned long long)pingInfo->size, (unsigned long long)pingInfo->metadata);
145
146 AddressSpaceDeviceContext *device_context = contextDesc.device_context.get();
147 if (device_context) {
148 device_context->perform(pingInfo);
149 } else {
150 struct AddressSpaceCreateInfo create = {0};
151 create.type = static_cast<AddressSpaceDeviceType>(pingInfo->metadata);
152 create.physAddr = phys_addr;
153
154 contextDesc.device_context = buildAddressSpaceDeviceContext(create);
155 pingInfo->metadata = contextDesc.device_context ? 0 : -1;
156 }
157 }
158
registerDeallocationCallback(uint64_t gpa,void * context,address_space_device_deallocation_callback_t func)159 void registerDeallocationCallback(uint64_t gpa, void* context, address_space_device_deallocation_callback_t func) {
160 AutoLock lock(mContextsLock);
161 auto& currentCallbacks = mDeallocationCallbacks[gpa];
162
163 DeallocationCallbackEntry entry = {
164 context,
165 func,
166 };
167
168 currentCallbacks.push_back(entry);
169 }
170
runDeallocationCallbacks(uint64_t gpa)171 void runDeallocationCallbacks(uint64_t gpa) {
172 AutoLock lock(mContextsLock);
173
174 auto it = mDeallocationCallbacks.find(gpa);
175 if (it == mDeallocationCallbacks.end()) return;
176
177 auto& callbacks = it->second;
178
179 for (auto& entry: callbacks) {
180 entry.func(entry.context, gpa);
181 }
182
183 mDeallocationCallbacks.erase(gpa);
184 }
185
handleToContext(uint32_t handle)186 AddressSpaceDeviceContext* handleToContext(uint32_t handle) {
187 AutoLock lock(mContextsLock);
188 if (mContexts.find(handle) == mContexts.end()) return nullptr;
189
190 auto& contextDesc = mContexts[handle];
191 return contextDesc.device_context.get();
192 }
193
hostmemRegister(const struct MemEntry * entry)194 uint64_t hostmemRegister(const struct MemEntry *entry) {
195 return sVmOps->hostmemRegister(entry);
196 }
197
hostmemUnregister(uint64_t id)198 void hostmemUnregister(uint64_t id) {
199 sVmOps->hostmemUnregister(id);
200 }
201
save(Stream * stream) const202 void save(Stream* stream) const {
203 // Pre-save
204 for (const auto &kv : mContexts) {
205 const AddressSpaceContextDescription &desc = kv.second;
206 const AddressSpaceDeviceContext *device_context = desc.device_context.get();
207 if (device_context) {
208 device_context->preSave();
209 }
210 }
211
212 AddressSpaceGraphicsContext::globalStatePreSave();
213
214 // Save
215 AddressSpaceSharedSlotsHostMemoryAllocatorContext::globalStateSave(stream);
216 AddressSpaceGraphicsContext::globalStateSave(stream);
217
218 stream->putBe32(mHandleIndex);
219 stream->putBe32(mContexts.size());
220
221 for (const auto &kv : mContexts) {
222 const uint32_t handle = kv.first;
223 const AddressSpaceContextDescription &desc = kv.second;
224 const AddressSpaceDeviceContext *device_context = desc.device_context.get();
225
226 stream->putBe32(handle);
227 stream->putBe64(desc.pingInfoGpa);
228
229 if (device_context) {
230 stream->putByte(1);
231 stream->putBe32(device_context->getDeviceType());
232 device_context->save(stream);
233 } else {
234 stream->putByte(0);
235 }
236 }
237
238 // Post save
239
240 AddressSpaceGraphicsContext::globalStatePostSave();
241
242 for (const auto &kv : mContexts) {
243 const AddressSpaceContextDescription &desc = kv.second;
244 const AddressSpaceDeviceContext *device_context = desc.device_context.get();
245 if (device_context) {
246 device_context->postSave();
247 }
248 }
249 }
250
load(Stream * stream)251 bool load(Stream* stream) {
252 // First destroy all contexts, because
253 // this can be done while an emulator is running
254 clear();
255
256 if (!AddressSpaceSharedSlotsHostMemoryAllocatorContext::globalStateLoad(
257 stream,
258 get_address_space_device_control_ops(),
259 get_address_space_device_hw_funcs())) {
260 return false;
261 }
262
263 asg::AddressSpaceGraphicsContext::init(get_address_space_device_control_ops());
264
265 if (!AddressSpaceGraphicsContext::globalStateLoad(
266 stream)) {
267 return false;
268 }
269
270 const uint32_t handleIndex = stream->getBe32();
271 const size_t size = stream->getBe32();
272
273 Contexts contexts;
274 for (size_t i = 0; i < size; ++i) {
275 const uint32_t handle = stream->getBe32();
276 const uint64_t pingInfoGpa = stream->getBe64();
277
278 std::unique_ptr<AddressSpaceDeviceContext> context;
279 switch (stream->getByte()) {
280 case 0:
281 break;
282
283 case 1: {
284 struct AddressSpaceCreateInfo create = {0};
285 create.type = static_cast<AddressSpaceDeviceType>(stream->getBe32());
286 create.physAddr = pingInfoGpa;
287 create.fromSnapshot = true;
288
289 context = buildAddressSpaceDeviceContext(create);
290 if (!context || !context->load(stream)) {
291 return false;
292 }
293 }
294 break;
295
296 default:
297 return false;
298 }
299
300 auto &desc = contexts[handle];
301 desc.pingInfoGpa = pingInfoGpa;
302 if (desc.pingInfoGpa == ~0ULL) {
303 fprintf(stderr, "%s: warning: restoring hva-only ping\n", __func__);
304 } else {
305 desc.pingInfo = (AddressSpaceDevicePingInfo*)
306 sVmOps->physicalMemoryGetAddr(pingInfoGpa);
307 }
308 desc.device_context = std::move(context);
309 }
310
311 {
312 AutoLock lock(mContextsLock);
313 mHandleIndex = handleIndex;
314 mContexts = std::move(contexts);
315 }
316
317 return true;
318 }
319
clear()320 void clear() {
321 AutoLock lock(mContextsLock);
322 mContexts.clear();
323 AddressSpaceSharedSlotsHostMemoryAllocatorContext::globalStateClear();
324 auto it = mMemoryMappings.begin();
325 std::vector<std::pair<uint64_t, uint64_t>> gpasSizesToErase;
326 for (auto it: mMemoryMappings) {
327 auto gpa = it.first;
328 auto size = it.second.second;
329 gpasSizesToErase.push_back({gpa, size});
330 }
331 for (const auto& gpaSize : gpasSizesToErase) {
332 removeMemoryMappingLocked(gpaSize.first, gpaSize.second);
333 }
334 mMemoryMappings.clear();
335 }
336
addMemoryMapping(uint64_t gpa,void * ptr,uint64_t size)337 bool addMemoryMapping(uint64_t gpa, void *ptr, uint64_t size) {
338 AutoLock lock(mMemoryMappingsLock);
339 return addMemoryMappingLocked(gpa, ptr, size);
340 }
341
removeMemoryMapping(uint64_t gpa,uint64_t size)342 bool removeMemoryMapping(uint64_t gpa, uint64_t size) {
343 AutoLock lock(mMemoryMappingsLock);
344 return removeMemoryMappingLocked(gpa, size);
345 }
346
getHostPtr(uint64_t gpa) const347 void *getHostPtr(uint64_t gpa) const {
348 AutoLock lock(mMemoryMappingsLock);
349 return getHostPtrLocked(gpa);
350 }
351
352 private:
353 mutable Lock mContextsLock;
354 uint32_t mHandleIndex = 1;
355 typedef std::unordered_map<uint32_t, AddressSpaceContextDescription> Contexts;
356 Contexts mContexts;
357
buildAddressSpaceDeviceContext(const struct AddressSpaceCreateInfo & create)358 std::unique_ptr<AddressSpaceDeviceContext> buildAddressSpaceDeviceContext(
359 const struct AddressSpaceCreateInfo& create) {
360 typedef std::unique_ptr<AddressSpaceDeviceContext> DeviceContextPtr;
361
362 switch (create.type) {
363 case AddressSpaceDeviceType::Graphics:
364 asg::AddressSpaceGraphicsContext::init(get_address_space_device_control_ops());
365 return DeviceContextPtr(new asg::AddressSpaceGraphicsContext(create));
366 #ifndef AEMU_MIN
367 case AddressSpaceDeviceType::Media:
368 AS_DEVICE_DPRINT("allocating media context");
369 return DeviceContextPtr(
370 new AddressSpaceHostMediaContext(create, get_address_space_device_control_ops()));
371 #endif
372 case AddressSpaceDeviceType::Sensors:
373 return nullptr;
374 case AddressSpaceDeviceType::Power:
375 return nullptr;
376 case AddressSpaceDeviceType::GenericPipe:
377 return nullptr;
378 case AddressSpaceDeviceType::HostMemoryAllocator:
379 return DeviceContextPtr(new AddressSpaceHostMemoryAllocatorContext(
380 get_address_space_device_control_ops(),
381 get_address_space_device_hw_funcs()));
382 case AddressSpaceDeviceType::SharedSlotsHostMemoryAllocator:
383 return DeviceContextPtr(new AddressSpaceSharedSlotsHostMemoryAllocatorContext(
384 get_address_space_device_control_ops(),
385 get_address_space_device_hw_funcs()));
386
387 case AddressSpaceDeviceType::VirtioGpuGraphics:
388 asg::AddressSpaceGraphicsContext::init(get_address_space_device_control_ops());
389 return DeviceContextPtr(new asg::AddressSpaceGraphicsContext(create));
390
391 default:
392 AS_DEVICE_DPRINT("Bad device type");
393 return nullptr;
394 }
395 }
396
addMemoryMappingLocked(uint64_t gpa,void * ptr,uint64_t size)397 bool addMemoryMappingLocked(uint64_t gpa, void *ptr, uint64_t size) {
398 if (mMemoryMappings.insert({gpa, {ptr, size}}).second) {
399 sVmOps->mapUserBackedRam(gpa, ptr, size);
400 return true;
401 } else {
402 fprintf(stderr, "%s: failed: hva %p -> gpa [0x%llx 0x%llx]\n", __func__,
403 ptr,
404 (unsigned long long)gpa,
405 (unsigned long long)size);
406 return false;
407 }
408 }
409
removeMemoryMappingLocked(uint64_t gpa,uint64_t size)410 bool removeMemoryMappingLocked(uint64_t gpa, uint64_t size) {
411 if (mMemoryMappings.erase(gpa) > 0) {
412 sVmOps->unmapUserBackedRam(gpa, size);
413 return true;
414 } else {
415 fprintf(stderr, "%s: failed: gpa [0x%llx 0x%llx]\n", __func__,
416 (unsigned long long)gpa,
417 (unsigned long long)size);
418 *(uint32_t*)(123) = 12;
419 return false;
420 }
421 }
422
getHostPtrLocked(uint64_t gpa) const423 void *getHostPtrLocked(uint64_t gpa) const {
424 auto i = mMemoryMappings.lower_bound(gpa); // i->first >= gpa (or i==end)
425 if ((i != mMemoryMappings.end()) && (i->first == gpa)) {
426 return i->second.first; // gpa is exactly the beginning of the range
427 } else if (i == mMemoryMappings.begin()) {
428 return nullptr; // can't '--i', see below
429 } else {
430 --i;
431
432 if ((i->first + i->second.second) > gpa) {
433 // move the host ptr by +(gpa-base)
434 return static_cast<char *>(i->second.first) + (gpa - i->first);
435 } else {
436 return nullptr; // the range does not cover gpa
437 }
438 }
439 }
440
441 mutable Lock mMemoryMappingsLock;
442 std::map<uint64_t, std::pair<void *, uint64_t>> mMemoryMappings; // do not save/load
443
444 struct DeallocationCallbackEntry {
445 void* context;
446 address_space_device_deallocation_callback_t func;
447 };
448
449 std::map<uint64_t, std::vector<DeallocationCallbackEntry>> mDeallocationCallbacks; // do not save/load, users re-register on load
450 };
451
sAddressSpaceDeviceState()452 static AddressSpaceDeviceState* sAddressSpaceDeviceState() {
453 static AddressSpaceDeviceState* s = new AddressSpaceDeviceState;
454 return s;
455 }
456
sAddressSpaceDeviceGenHandle()457 static uint32_t sAddressSpaceDeviceGenHandle() {
458 return sAddressSpaceDeviceState()->genHandle();
459 }
460
sAddressSpaceDeviceDestroyHandle(uint32_t handle)461 static void sAddressSpaceDeviceDestroyHandle(uint32_t handle) {
462 sAddressSpaceDeviceState()->destroyHandle(handle);
463 }
464
sAddressSpaceDeviceCreateInstance(const struct AddressSpaceCreateInfo & create)465 static void sAddressSpaceDeviceCreateInstance(const struct AddressSpaceCreateInfo& create) {
466 sAddressSpaceDeviceState()->createInstance(create);
467 }
468
sAddressSpaceDeviceTellPingInfo(uint32_t handle,uint64_t gpa)469 static void sAddressSpaceDeviceTellPingInfo(uint32_t handle, uint64_t gpa) {
470 sAddressSpaceDeviceState()->tellPingInfo(handle, gpa);
471 }
472
sAddressSpaceDevicePing(uint32_t handle)473 static void sAddressSpaceDevicePing(uint32_t handle) {
474 sAddressSpaceDeviceState()->ping(handle);
475 }
476
sAddressSpaceDeviceAddMemoryMapping(uint64_t gpa,void * ptr,uint64_t size)477 int sAddressSpaceDeviceAddMemoryMapping(uint64_t gpa, void *ptr, uint64_t size) {
478 return sAddressSpaceDeviceState()->addMemoryMapping(gpa, ptr, size) ? 1 : 0;
479 }
480
sAddressSpaceDeviceRemoveMemoryMapping(uint64_t gpa,void * ptr,uint64_t size)481 int sAddressSpaceDeviceRemoveMemoryMapping(uint64_t gpa, void *ptr, uint64_t size) {
482 (void)ptr; // TODO(lfy): remove arg
483 return sAddressSpaceDeviceState()->removeMemoryMapping(gpa, size) ? 1 : 0;
484 }
485
sAddressSpaceDeviceGetHostPtr(uint64_t gpa)486 void* sAddressSpaceDeviceGetHostPtr(uint64_t gpa) {
487 return sAddressSpaceDeviceState()->getHostPtr(gpa);
488 }
489
sAddressSpaceHandleToContext(uint32_t handle)490 static void* sAddressSpaceHandleToContext(uint32_t handle) {
491 return (void*)(sAddressSpaceDeviceState()->handleToContext(handle));
492 }
493
sAddressSpaceDeviceClear()494 static void sAddressSpaceDeviceClear() {
495 sAddressSpaceDeviceState()->clear();
496 }
497
sAddressSpaceDeviceHostmemRegister(const struct MemEntry * entry)498 static uint64_t sAddressSpaceDeviceHostmemRegister(const struct MemEntry *entry) {
499 return sAddressSpaceDeviceState()->hostmemRegister(entry);
500 }
501
sAddressSpaceDeviceHostmemUnregister(uint64_t id)502 static void sAddressSpaceDeviceHostmemUnregister(uint64_t id) {
503 sAddressSpaceDeviceState()->hostmemUnregister(id);
504 }
505
sAddressSpaceDevicePingAtHva(uint32_t handle,void * hva)506 static void sAddressSpaceDevicePingAtHva(uint32_t handle, void* hva) {
507 sAddressSpaceDeviceState()->pingAtHva(
508 handle, (AddressSpaceDevicePingInfo*)hva);
509 }
510
sAddressSpaceDeviceRegisterDeallocationCallback(void * context,uint64_t gpa,address_space_device_deallocation_callback_t func)511 static void sAddressSpaceDeviceRegisterDeallocationCallback(
512 void* context, uint64_t gpa, address_space_device_deallocation_callback_t func) {
513 sAddressSpaceDeviceState()->registerDeallocationCallback(gpa, context, func);
514 }
515
sAddressSpaceDeviceRunDeallocationCallbacks(uint64_t gpa)516 static void sAddressSpaceDeviceRunDeallocationCallbacks(uint64_t gpa) {
517 sAddressSpaceDeviceState()->runDeallocationCallbacks(gpa);
518 }
519
sAddressSpaceDeviceControlGetHwFuncs()520 static const struct AddressSpaceHwFuncs* sAddressSpaceDeviceControlGetHwFuncs() {
521 return get_address_space_device_hw_funcs();
522 }
523
524
525 } // namespace
526
527 extern "C" {
528
529 static struct address_space_device_control_ops sAddressSpaceDeviceOps = {
530 &sAddressSpaceDeviceGenHandle, // gen_handle
531 &sAddressSpaceDeviceDestroyHandle, // destroy_handle
532 &sAddressSpaceDeviceTellPingInfo, // tell_ping_info
533 &sAddressSpaceDevicePing, // ping
534 &sAddressSpaceDeviceAddMemoryMapping, // add_memory_mapping
535 &sAddressSpaceDeviceRemoveMemoryMapping, // remove_memory_mapping
536 &sAddressSpaceDeviceGetHostPtr, // get_host_ptr
537 &sAddressSpaceHandleToContext, // handle_to_context
538 &sAddressSpaceDeviceClear, // clear
539 &sAddressSpaceDeviceHostmemRegister, // hostmem register
540 &sAddressSpaceDeviceHostmemUnregister, // hostmem unregister
541 &sAddressSpaceDevicePingAtHva, // ping_at_hva
542 &sAddressSpaceDeviceRegisterDeallocationCallback, // register_deallocation_callback
543 &sAddressSpaceDeviceRunDeallocationCallbacks, // run_deallocation_callbacks
544 &sAddressSpaceDeviceControlGetHwFuncs, // control_get_hw_funcs
545 &sAddressSpaceDeviceCreateInstance, // create_instance
546 };
547
get_address_space_device_control_ops(void)548 struct address_space_device_control_ops* get_address_space_device_control_ops(void) {
549 return &sAddressSpaceDeviceOps;
550 }
551
552 static const struct AddressSpaceHwFuncs* sAddressSpaceHwFuncs = nullptr;
553
address_space_set_hw_funcs(const AddressSpaceHwFuncs * hwFuncs)554 const struct AddressSpaceHwFuncs* address_space_set_hw_funcs(
555 const AddressSpaceHwFuncs* hwFuncs) {
556 const AddressSpaceHwFuncs* result = sAddressSpaceHwFuncs;
557 sAddressSpaceHwFuncs = hwFuncs;
558 return result;
559 }
560
get_address_space_device_hw_funcs(void)561 const struct AddressSpaceHwFuncs* get_address_space_device_hw_funcs(void) {
562 return sAddressSpaceHwFuncs;
563 }
564
address_space_set_vm_operations(const QAndroidVmOperations * vmops)565 void address_space_set_vm_operations(const QAndroidVmOperations* vmops) {
566 sVmOps = vmops;
567 }
568
569 } // extern "C"
570
571 namespace android {
572 namespace emulation {
573
goldfish_address_space_set_vm_operations(const QAndroidVmOperations * vmops)574 void goldfish_address_space_set_vm_operations(const QAndroidVmOperations* vmops) {
575 sVmOps = vmops;
576 }
577
goldfish_address_space_get_vm_operations()578 const QAndroidVmOperations* goldfish_address_space_get_vm_operations() {
579 return sVmOps;
580 }
581
goldfish_address_space_memory_state_load(android::base::Stream * stream)582 int goldfish_address_space_memory_state_load(android::base::Stream *stream) {
583 return sAddressSpaceDeviceState()->load(stream) ? 0 : 1;
584 }
585
goldfish_address_space_memory_state_save(android::base::Stream * stream)586 int goldfish_address_space_memory_state_save(android::base::Stream *stream) {
587 sAddressSpaceDeviceState()->save(stream);
588 return 0;
589 }
590
591 } // namespace emulation
592 } // namespace android
593