1 /*
2 * Copyright (C) 2023 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 #include <sys/stat.h>
18
19 #include <cstddef>
20 #include <tuple>
21 #include <utility>
22
23 #include "berberis/guest_state/guest_addr.h"
24 #include "berberis/kernel_api/exec_emulation.h"
25 #include "berberis/kernel_api/fcntl_emulation.h"
26 #include "berberis/kernel_api/sys_ptrace_emulation.h"
27
28 #include "riscv64/guest_types.h"
29
30 namespace berberis {
31
GetGuestPlatformVarPrefixWithSize()32 std::pair<const char*, size_t> GetGuestPlatformVarPrefixWithSize() {
33 static constexpr char kGuestPlatformVarPrefix[] = "BERBERIS_GUEST_";
34 return {kGuestPlatformVarPrefix, sizeof(kGuestPlatformVarPrefix) - 1};
35 }
36
GuestFcntlArch(int,int,long)37 std::tuple<bool, int> GuestFcntlArch(int, int, long) {
38 return {false, -1};
39 }
40
PtraceForGuestArch(int,pid_t,void *,void *)41 std::tuple<bool, int> PtraceForGuestArch(int, pid_t, void*, void*) {
42 return {false, -1};
43 }
44
ConvertHostStatToGuestArch(const struct stat & host_stat,GuestAddr guest_addr)45 void ConvertHostStatToGuestArch(const struct stat& host_stat, GuestAddr guest_addr) {
46 auto* guest_stat = ToHostAddr<Guest_stat>(guest_addr);
47 guest_stat->st_dev = host_stat.st_dev;
48 guest_stat->st_ino = host_stat.st_ino;
49 guest_stat->st_mode = host_stat.st_mode;
50 guest_stat->st_nlink = host_stat.st_nlink;
51 guest_stat->st_uid = host_stat.st_uid;
52 guest_stat->st_gid = host_stat.st_gid;
53 guest_stat->st_rdev = host_stat.st_rdev;
54 guest_stat->st_size = host_stat.st_size;
55 guest_stat->st_blksize = host_stat.st_blksize;
56 guest_stat->st_blocks = host_stat.st_blocks;
57 guest_stat->st_atim = host_stat.st_atim;
58 guest_stat->st_mtim = host_stat.st_mtim;
59 guest_stat->st_ctim = host_stat.st_ctim;
60 }
61
62 } // namespace berberis
63