| 1 | /* |
| 2 | * memory management system conversion routines |
| 3 | * |
| 4 | * Copyright (c) 2013 Stacey D. Son |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | #include "qemu/osdep.h" |
| 9 | #include "qemu.h" |
| 10 | #include "qemu-bsd.h" |
| 11 | |
| 12 | struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; |
| 13 | |
| 14 | abi_ulong target_brk; |
| 15 | abi_ulong initial_target_brk; |
| 16 | |
| 17 | void target_set_brk(abi_ulong new_brk) |
| 18 | { |
| 19 | target_brk = TARGET_PAGE_ALIGN(new_brk); |
| 20 | initial_target_brk = target_brk; |
| 21 | } |
| 22 | |
| 23 | void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip, |
| 24 | struct target_ipc_perm *target_ip) |
| 25 | { |
| 26 | __get_user(host_ip->cuid, &target_ip->cuid); |
| 27 | __get_user(host_ip->cgid, &target_ip->cgid); |
| 28 | __get_user(host_ip->uid, &target_ip->uid); |
| 29 | __get_user(host_ip->gid, &target_ip->gid); |
| 30 | __get_user(host_ip->mode, &target_ip->mode); |
| 31 | __get_user(host_ip->seq, &target_ip->seq); |
| 32 | __get_user(host_ip->key, &target_ip->key); |
| 33 | } |
| 34 | |
| 35 | abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, |
| 36 | abi_ulong target_addr) |
| 37 | { |
| 38 | struct target_shmid_ds *target_sd; |
| 39 | |
| 40 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) { |
| 41 | return -TARGET_EFAULT; |
| 42 | } |
| 43 | |
| 44 | target_to_host_ipc_perm__locked(&(host_sd->shm_perm), |
| 45 | &(target_sd->shm_perm)); |
| 46 | |
| 47 | __get_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 48 | __get_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 49 | __get_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 50 | __get_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 51 | __get_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 52 | __get_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 53 | __get_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 54 | unlock_user_struct(target_sd, target_addr, 0); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip, |
| 60 | struct ipc_perm *host_ip) |
| 61 | { |
| 62 | __put_user(host_ip->cuid, &target_ip->cuid); |
| 63 | __put_user(host_ip->cgid, &target_ip->cgid); |
| 64 | __put_user(host_ip->uid, &target_ip->uid); |
| 65 | __put_user(host_ip->gid, &target_ip->gid); |
| 66 | __put_user(host_ip->mode, &target_ip->mode); |
| 67 | __put_user(host_ip->seq, &target_ip->seq); |
| 68 | __put_user(host_ip->key, &target_ip->key); |
| 69 | } |
| 70 | |
| 71 | abi_long host_to_target_shmid_ds(abi_ulong target_addr, |
| 72 | struct shmid_ds *host_sd) |
| 73 | { |
| 74 | struct target_shmid_ds *target_sd; |
| 75 | |
| 76 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) { |
| 77 | return -TARGET_EFAULT; |
| 78 | } |
| 79 | |
| 80 | host_to_target_ipc_perm__locked(&(target_sd->shm_perm), |
| 81 | &(host_sd->shm_perm)); |
| 82 | |
| 83 | __put_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 84 | __put_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 85 | __put_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 86 | __put_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 87 | __put_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 88 | __put_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 89 | __put_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 90 | unlock_user_struct(target_sd, target_addr, 1); |
| 91 | |
| 92 | return 0; |
| 93 | } |