Alice Wang | fb46ee1 | 2022-09-30 13:08:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #pragma once |
| 18 | |
Andrew Scull | 102067a | 2022-10-07 00:34:40 +0000 | [diff] [blame] | 19 | #include <stdbool.h> |
| 20 | #include <stddef.h> |
Alan Stokes | d4ea5a8 | 2022-11-10 12:17:42 +0000 | [diff] [blame] | 21 | #include <sys/cdefs.h> |
Andrew Scull | 102067a | 2022-10-07 00:34:40 +0000 | [diff] [blame] | 22 | |
Alan Stokes | 52d3c72 | 2022-10-04 17:27:13 +0100 | [diff] [blame] | 23 | #include "vm_main.h" |
| 24 | |
Alan Stokes | d4ea5a8 | 2022-11-10 12:17:42 +0000 | [diff] [blame] | 25 | __BEGIN_DECLS |
Alice Wang | fb46ee1 | 2022-09-30 13:08:52 +0000 | [diff] [blame] | 26 | |
Alice Wang | 2be64f3 | 2022-10-13 14:37:35 +0000 | [diff] [blame] | 27 | struct AIBinder; |
| 28 | typedef struct AIBinder AIBinder; |
| 29 | |
Andrew Scull | d64ae7d | 2022-10-05 17:41:43 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Notifies the host that the payload is ready. |
Andrew Scull | 655e98e | 2022-10-10 22:24:58 +0000 | [diff] [blame] | 32 | * |
Alan Stokes | 65bbb91 | 2022-11-23 09:39:34 +0000 | [diff] [blame^] | 33 | * If the host app has set a `VirtualMachineCallback` for the VM, its |
| 34 | * `onPayloadReady` method will be called. |
| 35 | * |
| 36 | * Note that subsequent calls to this function after the first have no effect; |
| 37 | * `onPayloadReady` is never called more than once. |
Andrew Scull | d64ae7d | 2022-10-05 17:41:43 +0000 | [diff] [blame] | 38 | */ |
Alan Stokes | 65bbb91 | 2022-11-23 09:39:34 +0000 | [diff] [blame^] | 39 | void AVmPayload_notifyPayloadReady(void); |
Alice Wang | fb46ee1 | 2022-09-30 13:08:52 +0000 | [diff] [blame] | 40 | |
Andrew Scull | d64ae7d | 2022-10-05 17:41:43 +0000 | [diff] [blame] | 41 | /** |
Alice Wang | 2be64f3 | 2022-10-13 14:37:35 +0000 | [diff] [blame] | 42 | * Runs a binder RPC server, serving the supplied binder service implementation on the given vsock |
| 43 | * port. |
| 44 | * |
| 45 | * If and when the server is ready for connections (it is listening on the port), `on_ready` is |
| 46 | * called to allow appropriate action to be taken - e.g. to notify clients that they may now |
| 47 | * attempt to connect with `AVmPayload_notifyPayloadReady`. |
| 48 | * |
| 49 | * The current thread is joined to the binder thread pool to handle incoming messages. |
| 50 | * |
| 51 | * \param service the service to bind to the given port. |
| 52 | * \param port vsock port. |
| 53 | * \param on_ready the callback to execute once the server is ready for connections. The callback |
| 54 | * will be called at most once. |
| 55 | * \param param param for the `on_ready` callback. |
| 56 | * |
| 57 | * \return true if the server has shutdown normally, false if it failed in some way. |
| 58 | */ |
| 59 | bool AVmPayload_runVsockRpcServer(AIBinder *service, unsigned int port, |
| 60 | void (*on_ready)(void *param), void *param); |
| 61 | |
| 62 | /** |
Alan Stokes | 0cbfdf9 | 2022-11-21 17:17:53 +0000 | [diff] [blame] | 63 | * Get a secret that is uniquely bound to this VM instance. The secrets are |
Alan Stokes | 65bbb91 | 2022-11-23 09:39:34 +0000 | [diff] [blame^] | 64 | * 32-byte values and the value associated with an identifier will not change |
| 65 | * over the lifetime of the VM instance. |
Andrew Scull | 102067a | 2022-10-07 00:34:40 +0000 | [diff] [blame] | 66 | * |
| 67 | * \param identifier identifier of the secret to return. |
| 68 | * \param identifier_size size of the secret identifier. |
| 69 | * \param secret pointer to size bytes where the secret is written. |
Alan Stokes | 65bbb91 | 2022-11-23 09:39:34 +0000 | [diff] [blame^] | 70 | * \param size number of bytes of the secret to get, <= 32. |
Andrew Scull | 102067a | 2022-10-07 00:34:40 +0000 | [diff] [blame] | 71 | */ |
Alan Stokes | 65bbb91 | 2022-11-23 09:39:34 +0000 | [diff] [blame^] | 72 | void AVmPayload_getVmInstanceSecret(const void *identifier, size_t identifier_size, void *secret, |
Andrew Scull | 655e98e | 2022-10-10 22:24:58 +0000 | [diff] [blame] | 73 | size_t size); |
Andrew Scull | 102067a | 2022-10-07 00:34:40 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
Alice Wang | 6bbb6da | 2022-10-26 12:44:06 +0000 | [diff] [blame] | 76 | * Gets the path to the APK contents. It is a directory, under which are |
| 77 | * the unzipped contents of the APK containing the payload, all read-only |
| 78 | * but accessible to the payload. |
| 79 | * |
| 80 | * \return the path to the APK contents. The returned string should not be |
| 81 | * deleted or freed by the application. The string remains valid for the |
| 82 | * lifetime of the VM. |
| 83 | */ |
| 84 | const char *AVmPayload_getApkContentsPath(void); |
| 85 | |
Alan Stokes | 78d2470 | 2022-11-21 15:28:31 +0000 | [diff] [blame] | 86 | /** |
| 87 | * Gets the path to the encrypted persistent storage for the VM, if any. This is |
| 88 | * a directory under which any files or directories created will be stored on |
| 89 | * behalf of the VM by the host app. All data is encrypted using a key known |
| 90 | * only to the VM, so the host cannot decrypt it, but may delete it. |
| 91 | * |
| 92 | * \return the path to the APK contents, or NULL if no encrypted storage was |
| 93 | * requested in the VM configuration. If non-null the returned string should not |
| 94 | * be deleted or freed by the application and remains valid for the lifetime of |
| 95 | * the VM. |
| 96 | */ |
| 97 | const char *AVmPayload_getEncryptedStoragePath(void); |
| 98 | |
Alan Stokes | d4ea5a8 | 2022-11-10 12:17:42 +0000 | [diff] [blame] | 99 | __END_DECLS |