2 * FreeBSD sysctl() and sysarch() system call emulation
4 * Copyright (c) 2013-15 Stacey D. Son
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.
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.
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/>.
20 #include "qemu/osdep.h"
22 #include "target_arch_sysarch.h"
24 #include <sys/sysctl.h>
27 * Length for the fixed length types.
28 * 0 means variable length for strings and structures
29 * Compare with sys/kern_sysctl.c ctl_size
30 * Note: Not all types appear to be used in-tree.
32 static const int G_GNUC_UNUSED guest_ctl_size
[CTLTYPE
+ 1] = {
33 [CTLTYPE_INT
] = sizeof(abi_int
),
34 [CTLTYPE_UINT
] = sizeof(abi_uint
),
35 [CTLTYPE_LONG
] = sizeof(abi_long
),
36 [CTLTYPE_ULONG
] = sizeof(abi_ulong
),
37 [CTLTYPE_S8
] = sizeof(int8_t),
38 [CTLTYPE_S16
] = sizeof(int16_t),
39 [CTLTYPE_S32
] = sizeof(int32_t),
40 [CTLTYPE_S64
] = sizeof(int64_t),
41 [CTLTYPE_U8
] = sizeof(uint8_t),
42 [CTLTYPE_U16
] = sizeof(uint16_t),
43 [CTLTYPE_U32
] = sizeof(uint32_t),
44 [CTLTYPE_U64
] = sizeof(uint64_t),
47 static const int G_GNUC_UNUSED host_ctl_size
[CTLTYPE
+ 1] = {
48 [CTLTYPE_INT
] = sizeof(int),
49 [CTLTYPE_UINT
] = sizeof(u_int
),
50 [CTLTYPE_LONG
] = sizeof(long),
51 [CTLTYPE_ULONG
] = sizeof(u_long
),
52 [CTLTYPE_S8
] = sizeof(int8_t),
53 [CTLTYPE_S16
] = sizeof(int16_t),
54 [CTLTYPE_S32
] = sizeof(int32_t),
55 [CTLTYPE_S64
] = sizeof(int64_t),
56 [CTLTYPE_U8
] = sizeof(uint8_t),
57 [CTLTYPE_U16
] = sizeof(uint16_t),
58 [CTLTYPE_U32
] = sizeof(uint32_t),
59 [CTLTYPE_U64
] = sizeof(uint64_t),
64 * Limit the amount of available memory to be most of the 32-bit address
65 * space. 0x100c000 was arrived at through trial and error as a good
66 * definition of 'most'.
68 static const abi_ulong guest_max_mem
= UINT32_MAX
- 0x100c000 + 1;
70 static abi_ulong G_GNUC_UNUSED
cap_memory(uint64_t mem
)
72 return MIN(guest_max_mem
, mem
);
76 static abi_ulong G_GNUC_UNUSED
scale_to_guest_pages(uint64_t pages
)
78 /* Scale pages from host to guest */
79 pages
= muldiv64(pages
, qemu_real_host_page_size(), TARGET_PAGE_SIZE
);
81 /* cap pages if need be */
82 pages
= MIN(pages
, guest_max_mem
/ (abi_ulong
)TARGET_PAGE_SIZE
);
88 /* Used only for TARGET_ABI32 */
89 static abi_long G_GNUC_UNUSED
h2g_long_sat(long l
)
93 } else if (l
< INT32_MIN
) {
99 static abi_ulong G_GNUC_UNUSED
h2g_ulong_sat(u_long ul
)
101 return MIN(ul
, UINT32_MAX
);
106 * placeholder until bsd-user downstream upstreams this with its thread support
108 #define bsd_get_ncpu() 1
110 /* sysarch() is architecture dependent. */
111 abi_long
do_freebsd_sysarch(void *cpu_env
, abi_long arg1
, abi_long arg2
)
113 return do_freebsd_arch_sysarch(cpu_env
, arg1
, arg2
);