blob: 99da1ebc6df4a85e44068bc3c4884e2c789b9422 [file] [log] [blame]
Andrei Homescu74a54452021-12-10 05:30:21 +00001/*
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
Ayrton Munoz04137372022-08-03 17:05:09 -040017#if defined(TRUSTY_USERSPACE)
Andrei Homescu74a54452021-12-10 05:30:21 +000018#include <openssl/rand.h>
Andrei Homescu1c18a802022-08-17 04:59:01 +000019#include <trusty_ipc.h>
Ayrton Munoz04137372022-08-03 17:05:09 -040020#else
21#include <lib/rand/rand.h>
22#endif
Andrei Homescu74a54452021-12-10 05:30:21 +000023
Andrei Homescu024727b2022-08-24 23:54:59 +000024#include <binder/RpcTransportTipcTrusty.h>
25
Andrei Homescu74a54452021-12-10 05:30:21 +000026#include "../OS.h"
Andrei Homescu1c18a802022-08-17 04:59:01 +000027#include "TrustyStatus.h"
Andrei Homescu74a54452021-12-10 05:30:21 +000028
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -070029using android::binder::borrowed_fd;
30using android::binder::unique_fd;
31
Tomasz Wasilczyk0d9dec22023-10-06 20:28:49 +000032namespace android::binder::os {
Andrei Homescu74a54452021-12-10 05:30:21 +000033
Tomasz Wasilczykdaf727a2023-11-21 13:50:09 -080034void trace_begin(uint64_t, const char*) {}
35
36void trace_end(uint64_t) {}
37
38uint64_t GetThreadId() {
39 return 0;
40}
41
42bool report_sysprop_change() {
43 return false;
44}
45
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -070046status_t setNonBlocking(borrowed_fd /*fd*/) {
Andrei Homescu74a54452021-12-10 05:30:21 +000047 // Trusty IPC syscalls are all non-blocking by default.
Tomasz Wasilczyk88aa8c32023-11-01 09:46:07 -070048 return OK;
Andrei Homescu74a54452021-12-10 05:30:21 +000049}
50
51status_t getRandomBytes(uint8_t* data, size_t size) {
Ayrton Munoz04137372022-08-03 17:05:09 -040052#if defined(TRUSTY_USERSPACE)
Andrei Homescu74a54452021-12-10 05:30:21 +000053 int res = RAND_bytes(data, size);
54 return res == 1 ? OK : UNKNOWN_ERROR;
Ayrton Munoz04137372022-08-03 17:05:09 -040055#else
56 int res = rand_get_bytes(data, size);
57 return res == 0 ? OK : UNKNOWN_ERROR;
58#endif // TRUSTY_USERSPACE
Andrei Homescu74a54452021-12-10 05:30:21 +000059}
60
Andrei Homescu1c18a802022-08-17 04:59:01 +000061status_t dupFileDescriptor(int oldFd, int* newFd) {
62 int res = dup(oldFd);
63 if (res < 0) {
64 return statusFromTrusty(res);
65 }
66
67 *newFd = res;
68 return OK;
Andrei Homescu24ad36e2022-08-04 01:33:33 +000069}
70
Andrei Homescu024727b2022-08-24 23:54:59 +000071std::unique_ptr<RpcTransportCtxFactory> makeDefaultRpcTransportCtxFactory() {
72 return RpcTransportCtxFactoryTipcTrusty::make();
73}
74
David Brazdilc3964f62022-10-24 23:06:14 +010075ssize_t sendMessageOnSocket(
David Brazdil21c887c2022-09-23 12:25:18 +010076 const RpcTransportFd& /* socket */, iovec* /* iovs */, int /* niovs */,
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -070077 const std::vector<std::variant<unique_fd, borrowed_fd>>* /* ancillaryFds */) {
David Brazdil21c887c2022-09-23 12:25:18 +010078 errno = ENOTSUP;
79 return -1;
80}
81
David Brazdilc3964f62022-10-24 23:06:14 +010082ssize_t receiveMessageFromSocket(
David Brazdil21c887c2022-09-23 12:25:18 +010083 const RpcTransportFd& /* socket */, iovec* /* iovs */, int /* niovs */,
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -070084 std::vector<std::variant<unique_fd, borrowed_fd>>* /* ancillaryFds */) {
David Brazdil21c887c2022-09-23 12:25:18 +010085 errno = ENOTSUP;
86 return -1;
87}
88
Tomasz Wasilczyk0d9dec22023-10-06 20:28:49 +000089} // namespace android::binder::os