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