1c9cdf0a5SStacey Son /* 2c9cdf0a5SStacey Son * memory management system conversion routines 3c9cdf0a5SStacey Son * 4c9cdf0a5SStacey Son * Copyright (c) 2013 Stacey D. Son 5c9cdf0a5SStacey Son * 6c9cdf0a5SStacey Son * This program is free software; you can redistribute it and/or modify 7c9cdf0a5SStacey Son * it under the terms of the GNU General Public License as published by 8c9cdf0a5SStacey Son * the Free Software Foundation; either version 2 of the License, or 9c9cdf0a5SStacey Son * (at your option) any later version. 10c9cdf0a5SStacey Son * 11c9cdf0a5SStacey Son * This program is distributed in the hope that it will be useful, 12c9cdf0a5SStacey Son * but WITHOUT ANY WARRANTY; without even the implied warranty of 13c9cdf0a5SStacey Son * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14c9cdf0a5SStacey Son * GNU General Public License for more details. 15c9cdf0a5SStacey Son * 16c9cdf0a5SStacey Son * You should have received a copy of the GNU General Public License 17c9cdf0a5SStacey Son * along with this program; if not, see <http://www.gnu.org/licenses/>. 18c9cdf0a5SStacey Son */ 19c9cdf0a5SStacey Son #include "qemu/osdep.h" 20c9cdf0a5SStacey Son #include "qemu.h" 21c9cdf0a5SStacey Son #include "qemu-bsd.h" 22c9cdf0a5SStacey Son 23c9cdf0a5SStacey Son struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; 24c9cdf0a5SStacey Son 25c9cdf0a5SStacey Son abi_ulong target_brk; 26c9cdf0a5SStacey Son abi_ulong initial_target_brk; 27c9cdf0a5SStacey Son 28c9cdf0a5SStacey Son void target_set_brk(abi_ulong new_brk) 29c9cdf0a5SStacey Son { 30c9cdf0a5SStacey Son target_brk = TARGET_PAGE_ALIGN(new_brk); 31c9cdf0a5SStacey Son initial_target_brk = target_brk; 32c9cdf0a5SStacey Son } 3386fbb443SStacey Son 3486fbb443SStacey Son void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip, 3586fbb443SStacey Son struct target_ipc_perm *target_ip) 3686fbb443SStacey Son { 3786fbb443SStacey Son __get_user(host_ip->cuid, &target_ip->cuid); 3886fbb443SStacey Son __get_user(host_ip->cgid, &target_ip->cgid); 3986fbb443SStacey Son __get_user(host_ip->uid, &target_ip->uid); 4086fbb443SStacey Son __get_user(host_ip->gid, &target_ip->gid); 4186fbb443SStacey Son __get_user(host_ip->mode, &target_ip->mode); 4286fbb443SStacey Son __get_user(host_ip->seq, &target_ip->seq); 4386fbb443SStacey Son __get_user(host_ip->key, &target_ip->key); 4486fbb443SStacey Son } 4586fbb443SStacey Son 46*bd2b7318SStacey Son abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, 47*bd2b7318SStacey Son abi_ulong target_addr) 48*bd2b7318SStacey Son { 49*bd2b7318SStacey Son struct target_shmid_ds *target_sd; 50*bd2b7318SStacey Son 51*bd2b7318SStacey Son if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) { 52*bd2b7318SStacey Son return -TARGET_EFAULT; 53*bd2b7318SStacey Son } 54*bd2b7318SStacey Son 55*bd2b7318SStacey Son target_to_host_ipc_perm__locked(&(host_sd->shm_perm), 56*bd2b7318SStacey Son &(target_sd->shm_perm)); 57*bd2b7318SStacey Son 58*bd2b7318SStacey Son __get_user(host_sd->shm_segsz, &target_sd->shm_segsz); 59*bd2b7318SStacey Son __get_user(host_sd->shm_lpid, &target_sd->shm_lpid); 60*bd2b7318SStacey Son __get_user(host_sd->shm_cpid, &target_sd->shm_cpid); 61*bd2b7318SStacey Son __get_user(host_sd->shm_nattch, &target_sd->shm_nattch); 62*bd2b7318SStacey Son __get_user(host_sd->shm_atime, &target_sd->shm_atime); 63*bd2b7318SStacey Son __get_user(host_sd->shm_dtime, &target_sd->shm_dtime); 64*bd2b7318SStacey Son __get_user(host_sd->shm_ctime, &target_sd->shm_ctime); 65*bd2b7318SStacey Son unlock_user_struct(target_sd, target_addr, 0); 66*bd2b7318SStacey Son 67*bd2b7318SStacey Son return 0; 68*bd2b7318SStacey Son } 69*bd2b7318SStacey Son 7086fbb443SStacey Son void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip, 7186fbb443SStacey Son struct ipc_perm *host_ip) 7286fbb443SStacey Son { 7386fbb443SStacey Son __put_user(host_ip->cuid, &target_ip->cuid); 7486fbb443SStacey Son __put_user(host_ip->cgid, &target_ip->cgid); 7586fbb443SStacey Son __put_user(host_ip->uid, &target_ip->uid); 7686fbb443SStacey Son __put_user(host_ip->gid, &target_ip->gid); 7786fbb443SStacey Son __put_user(host_ip->mode, &target_ip->mode); 7886fbb443SStacey Son __put_user(host_ip->seq, &target_ip->seq); 7986fbb443SStacey Son __put_user(host_ip->key, &target_ip->key); 8086fbb443SStacey Son } 8186fbb443SStacey Son 82*bd2b7318SStacey Son abi_long host_to_target_shmid_ds(abi_ulong target_addr, 83*bd2b7318SStacey Son struct shmid_ds *host_sd) 84*bd2b7318SStacey Son { 85*bd2b7318SStacey Son struct target_shmid_ds *target_sd; 86*bd2b7318SStacey Son 87*bd2b7318SStacey Son if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) { 88*bd2b7318SStacey Son return -TARGET_EFAULT; 89*bd2b7318SStacey Son } 90*bd2b7318SStacey Son 91*bd2b7318SStacey Son host_to_target_ipc_perm__locked(&(target_sd->shm_perm), 92*bd2b7318SStacey Son &(host_sd->shm_perm)); 93*bd2b7318SStacey Son 94*bd2b7318SStacey Son __put_user(host_sd->shm_segsz, &target_sd->shm_segsz); 95*bd2b7318SStacey Son __put_user(host_sd->shm_lpid, &target_sd->shm_lpid); 96*bd2b7318SStacey Son __put_user(host_sd->shm_cpid, &target_sd->shm_cpid); 97*bd2b7318SStacey Son __put_user(host_sd->shm_nattch, &target_sd->shm_nattch); 98*bd2b7318SStacey Son __put_user(host_sd->shm_atime, &target_sd->shm_atime); 99*bd2b7318SStacey Son __put_user(host_sd->shm_dtime, &target_sd->shm_dtime); 100*bd2b7318SStacey Son __put_user(host_sd->shm_ctime, &target_sd->shm_ctime); 101*bd2b7318SStacey Son unlock_user_struct(target_sd, target_addr, 1); 102*bd2b7318SStacey Son 103*bd2b7318SStacey Son return 0; 104*bd2b7318SStacey Son } 105