xref: /qemu/bsd-user/bsd-mem.c (revision bd2b7318)
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 
target_set_brk(abi_ulong new_brk)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 
target_to_host_ipc_perm__locked(struct ipc_perm * host_ip,struct target_ipc_perm * target_ip)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 
target_to_host_shmid_ds(struct shmid_ds * host_sd,abi_ulong target_addr)46bd2b7318SStacey Son abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
47bd2b7318SStacey Son                                  abi_ulong target_addr)
48bd2b7318SStacey Son {
49bd2b7318SStacey Son     struct target_shmid_ds *target_sd;
50bd2b7318SStacey Son 
51bd2b7318SStacey Son     if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) {
52bd2b7318SStacey Son         return -TARGET_EFAULT;
53bd2b7318SStacey Son     }
54bd2b7318SStacey Son 
55bd2b7318SStacey Son     target_to_host_ipc_perm__locked(&(host_sd->shm_perm),
56bd2b7318SStacey Son                                     &(target_sd->shm_perm));
57bd2b7318SStacey Son 
58bd2b7318SStacey Son     __get_user(host_sd->shm_segsz,  &target_sd->shm_segsz);
59bd2b7318SStacey Son     __get_user(host_sd->shm_lpid,   &target_sd->shm_lpid);
60bd2b7318SStacey Son     __get_user(host_sd->shm_cpid,   &target_sd->shm_cpid);
61bd2b7318SStacey Son     __get_user(host_sd->shm_nattch, &target_sd->shm_nattch);
62bd2b7318SStacey Son     __get_user(host_sd->shm_atime,  &target_sd->shm_atime);
63bd2b7318SStacey Son     __get_user(host_sd->shm_dtime,  &target_sd->shm_dtime);
64bd2b7318SStacey Son     __get_user(host_sd->shm_ctime,  &target_sd->shm_ctime);
65bd2b7318SStacey Son     unlock_user_struct(target_sd, target_addr, 0);
66bd2b7318SStacey Son 
67bd2b7318SStacey Son     return 0;
68bd2b7318SStacey Son }
69bd2b7318SStacey Son 
host_to_target_ipc_perm__locked(struct target_ipc_perm * target_ip,struct ipc_perm * host_ip)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 
host_to_target_shmid_ds(abi_ulong target_addr,struct shmid_ds * host_sd)82bd2b7318SStacey Son abi_long host_to_target_shmid_ds(abi_ulong target_addr,
83bd2b7318SStacey Son                                  struct shmid_ds *host_sd)
84bd2b7318SStacey Son {
85bd2b7318SStacey Son     struct target_shmid_ds *target_sd;
86bd2b7318SStacey Son 
87bd2b7318SStacey Son     if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
88bd2b7318SStacey Son         return -TARGET_EFAULT;
89bd2b7318SStacey Son     }
90bd2b7318SStacey Son 
91bd2b7318SStacey Son     host_to_target_ipc_perm__locked(&(target_sd->shm_perm),
92bd2b7318SStacey Son                                     &(host_sd->shm_perm));
93bd2b7318SStacey Son 
94bd2b7318SStacey Son     __put_user(host_sd->shm_segsz,  &target_sd->shm_segsz);
95bd2b7318SStacey Son     __put_user(host_sd->shm_lpid,   &target_sd->shm_lpid);
96bd2b7318SStacey Son     __put_user(host_sd->shm_cpid,   &target_sd->shm_cpid);
97bd2b7318SStacey Son     __put_user(host_sd->shm_nattch, &target_sd->shm_nattch);
98bd2b7318SStacey Son     __put_user(host_sd->shm_atime,  &target_sd->shm_atime);
99bd2b7318SStacey Son     __put_user(host_sd->shm_dtime,  &target_sd->shm_dtime);
100bd2b7318SStacey Son     __put_user(host_sd->shm_ctime,  &target_sd->shm_ctime);
101bd2b7318SStacey Son     unlock_user_struct(target_sd, target_addr, 1);
102bd2b7318SStacey Son 
103bd2b7318SStacey Son     return 0;
104bd2b7318SStacey Son }
105