Skip to content

Commit 813bac3

Browse files
committed
Merge tag '2023q3-bsd-user-pull-request' of https://gitlab.com/bsdimp/qemu into staging
Pull request for bsd-user 2023 Q3 (first batch) First batch of commits submitted by my GSoC student Karim Taha These implement the stat, statfs, statfh and dirents system calls. In addition, fix a missing break statment, and submit Richard Henderson's elf stat mmap cleansup. # -----BEGIN PGP SIGNATURE----- # Comment: GPGTools - https://gpgtools.org # # iQIzBAABCgAdFiEEIDX4lLAKo898zeG3bBzRKH2wEQAFAmTtL6EACgkQbBzRKH2w # EQALHQ//WOoHYxpNS1hy+oYIAvjW0JOqz9gCSFR0d56mDBShm7WO/9FZA6eGAzYQ # i5kBSVFwEBlM76K5vLTbRvCbCbAwlpAdMgI7HXValjspNhvu/66DNWmdil6GnXKu # 4QRaM/QGrobmYrNmf4SdgyjlMVH7wGyTrCTpXfvPfktZLAbQq7dCyNPTsOYXJP2V # LASk8j2gyW6fDi3z1AxTNVfS7BJX6DWMhPhlvC/aUOLVVGgj9Hw9uxPaKXC1t47D # bpZ+wJb4GMkcsmuiGJ40CXowjQ+M1lBrA4rN+lTMJNttZJ+TUYmizTFkYhX+B28h # Q2JZy5eLXlsxxRByOkOwFczfDT6jlG4BlK4jmDOvKlrTPLaWIHjezztTavWIZDlU # ce1oXQo3KEdWoa/QEsuxLeBbE+uZpu5+NqLeCk1cU4GPks8nbAcD7BGl6dDHKXM4 # 8vCcOMZLwO+xi5Etgcf/MtTPMpSO0rD9fTq2VSdYX0H197mkOdyCDAXjfKPsBUIE # VLAnCFfajMNRc5ITobEbz4GiMD/xy5s8eDZNeefG8lgySpl9XB2Lvw7SWDz1imsL # nBgQH6RHznU65wEvVGtnCGMj5kIMbohY2AGR75iGkRdgR+t2zMjUIiaU/qivD+6z # IEJ2jqDWqtQb81jFNrFzJlsim+GYRl0HcaEmyye2bgf5LHRSSNM= # =ORJ7 # -----END PGP SIGNATURE----- # gpg: Signature made Mon 28 Aug 2023 19:37:05 EDT # gpg: using RSA key 2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 # gpg: Good signature from "Warner Losh <[email protected]>" [unknown] # gpg: aka "Warner Losh <[email protected]>" [unknown] # gpg: aka "Warner Losh <[email protected]>" [unknown] # gpg: aka "Warner Losh <[email protected]>" [unknown] # gpg: aka "Warner Losh <[email protected]>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 2035 F894 B00A A3CF 7CCD E1B7 6C1C D128 7DB0 1100 * tag '2023q3-bsd-user-pull-request' of https://gitlab.com/bsdimp/qemu: (36 commits) bsd-user: Add missing break after do_bsd_preadv bsd-user: Add getdents and fcntl related system calls bsd-user: Add glue for statfs related system calls bsd-user: Add glue for getfh and related syscalls bsd-user: Add glue for the freebsd11_stat syscalls bsd-user: Add os-stat.c to the build bsd-user: Implement do_freebsd_realpathat syscall bsd-user: Implement freebsd11 netbsd stat related syscalls bsd-user: Implement freebsd11 getdirents related syscalls bsd-user: Implement freebsd11 statfs related syscalls bsd-user: Implement freebsd11 fstat and fhstat related syscalls bsd-user: Implement freebsd11 stat related syscalls bsd-user: Implement stat related syscalls bsd-user: Implement getdents related syscalls bsd-user: Implement statfs related syscalls bsd-user: Implement statfh related syscalls bsd-user: Implement stat related syscalls bsd-uesr: Implement h2t_freebsd_stat and h2t_freebsd_statfs functions bsd-user: Implement target_to_host_fcntl_cmd bsd-user: Implement h2t_freebds11_statfs ... Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents f5fe7c1 + f51e7c4 commit 813bac3

File tree

15 files changed

+1384
-77
lines changed

15 files changed

+1384
-77
lines changed

bsd-user/arm/target_arch_elf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#ifndef TARGET_ARCH_ELF_H
2121
#define TARGET_ARCH_ELF_H
2222

23-
#define ELF_START_MMAP 0x80000000
2423
#define ELF_ET_DYN_LOAD_ADDR 0x500000
2524

2625
#define elf_check_arch(x) ((x) == EM_ARM)

bsd-user/elfload.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
738738
/* OK, This is the point of no return */
739739
info->end_data = 0;
740740
info->end_code = 0;
741-
info->start_mmap = (abi_ulong)ELF_START_MMAP;
742-
info->mmap = 0;
743741
elf_entry = (abi_ulong) elf_ex.e_entry;
744742

745743
/* XXX Join this with PT_INTERP search? */
@@ -813,7 +811,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
813811
bprm->stringp, &elf_ex, load_addr,
814812
et_dyn_addr, interp_load_addr, info);
815813
info->load_addr = reloc_func_desc;
816-
info->start_brk = info->brk = elf_brk;
814+
info->brk = elf_brk;
817815
info->start_stack = bprm->p;
818816
info->load_bias = 0;
819817

bsd-user/freebsd/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bsd_user_ss.add(files(
2+
'os-stat.c',
23
'os-sys.c',
34
'os-syscall.c',
45
))

bsd-user/freebsd/os-stat.c

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
/*
2+
* FreeBSD stat related 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+
21+
#include "qemu.h"
22+
23+
/*
24+
* stat conversion
25+
*/
26+
abi_long h2t_freebsd11_stat(abi_ulong target_addr,
27+
struct freebsd11_stat *host_st)
28+
{
29+
struct target_freebsd11_stat *target_st;
30+
31+
if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
32+
return -TARGET_EFAULT;
33+
}
34+
memset(target_st, 0, sizeof(*target_st));
35+
__put_user(host_st->st_dev, &target_st->st_dev);
36+
__put_user(host_st->st_ino, &target_st->st_ino);
37+
__put_user(host_st->st_mode, &target_st->st_mode);
38+
__put_user(host_st->st_nlink, &target_st->st_nlink);
39+
__put_user(host_st->st_uid, &target_st->st_uid);
40+
__put_user(host_st->st_gid, &target_st->st_gid);
41+
__put_user(host_st->st_rdev, &target_st->st_rdev);
42+
__put_user(host_st->st_atim.tv_sec, &target_st->st_atim.tv_sec);
43+
__put_user(host_st->st_atim.tv_nsec, &target_st->st_atim.tv_nsec);
44+
__put_user(host_st->st_mtim.tv_sec, &target_st->st_mtim.tv_sec);
45+
__put_user(host_st->st_mtim.tv_nsec, &target_st->st_mtim.tv_nsec);
46+
__put_user(host_st->st_ctim.tv_sec, &target_st->st_ctim.tv_sec);
47+
__put_user(host_st->st_ctim.tv_nsec, &target_st->st_ctim.tv_nsec);
48+
__put_user(host_st->st_size, &target_st->st_size);
49+
__put_user(host_st->st_blocks, &target_st->st_blocks);
50+
__put_user(host_st->st_blksize, &target_st->st_blksize);
51+
__put_user(host_st->st_flags, &target_st->st_flags);
52+
__put_user(host_st->st_gen, &target_st->st_gen);
53+
/* st_lspare not used */
54+
__put_user(host_st->st_birthtim.tv_sec, &target_st->st_birthtim.tv_sec);
55+
__put_user(host_st->st_birthtim.tv_nsec, &target_st->st_birthtim.tv_nsec);
56+
unlock_user_struct(target_st, target_addr, 1);
57+
58+
return 0;
59+
}
60+
61+
abi_long h2t_freebsd_stat(abi_ulong target_addr,
62+
struct stat *host_st)
63+
{
64+
struct target_stat *target_st;
65+
66+
if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
67+
return -TARGET_EFAULT;
68+
}
69+
memset(target_st, 0, sizeof(*target_st));
70+
__put_user(host_st->st_dev, &target_st->st_dev);
71+
__put_user(host_st->st_ino, &target_st->st_ino);
72+
__put_user(host_st->st_nlink, &target_st->st_nlink);
73+
__put_user(host_st->st_mode, &target_st->st_mode);
74+
__put_user(host_st->st_uid, &target_st->st_uid);
75+
__put_user(host_st->st_gid, &target_st->st_gid);
76+
__put_user(host_st->st_rdev, &target_st->st_rdev);
77+
__put_user(host_st->st_atim.tv_sec, &target_st->st_atim.tv_sec);
78+
__put_user(host_st->st_atim.tv_nsec, &target_st->st_atim.tv_nsec);
79+
#ifdef TARGET_HAS_STAT_TIME_T_EXT
80+
/* __put_user(host_st->st_mtim_ext, &target_st->st_mtim_ext); XXX */
81+
#endif
82+
__put_user(host_st->st_mtim.tv_sec, &target_st->st_mtim.tv_sec);
83+
__put_user(host_st->st_mtim.tv_nsec, &target_st->st_mtim.tv_nsec);
84+
#ifdef TARGET_HAS_STAT_TIME_T_EXT
85+
/* __put_user(host_st->st_ctim_ext, &target_st->st_ctim_ext); XXX */
86+
#endif
87+
__put_user(host_st->st_ctim.tv_sec, &target_st->st_ctim.tv_sec);
88+
__put_user(host_st->st_ctim.tv_nsec, &target_st->st_ctim.tv_nsec);
89+
#ifdef TARGET_HAS_STAT_TIME_T_EXT
90+
/* __put_user(host_st->st_birthtim_ext, &target_st->st_birthtim_ext); XXX */
91+
#endif
92+
__put_user(host_st->st_birthtim.tv_sec, &target_st->st_birthtim.tv_sec);
93+
__put_user(host_st->st_birthtim.tv_nsec, &target_st->st_birthtim.tv_nsec);
94+
95+
__put_user(host_st->st_size, &target_st->st_size);
96+
__put_user(host_st->st_blocks, &target_st->st_blocks);
97+
__put_user(host_st->st_blksize, &target_st->st_blksize);
98+
__put_user(host_st->st_flags, &target_st->st_flags);
99+
__put_user(host_st->st_gen, &target_st->st_gen);
100+
unlock_user_struct(target_st, target_addr, 1);
101+
102+
return 0;
103+
}
104+
105+
abi_long h2t_freebsd11_nstat(abi_ulong target_addr,
106+
struct freebsd11_stat *host_st)
107+
{
108+
struct target_freebsd11_nstat *target_st;
109+
110+
if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
111+
return -TARGET_EFAULT;
112+
}
113+
memset(target_st, 0, sizeof(*target_st));
114+
__put_user(host_st->st_dev, &target_st->st_dev);
115+
__put_user(host_st->st_ino, &target_st->st_ino);
116+
__put_user(host_st->st_mode, &target_st->st_mode);
117+
__put_user(host_st->st_nlink, &target_st->st_nlink);
118+
__put_user(host_st->st_uid, &target_st->st_uid);
119+
__put_user(host_st->st_gid, &target_st->st_gid);
120+
__put_user(host_st->st_rdev, &target_st->st_rdev);
121+
__put_user(host_st->st_atim.tv_sec, &target_st->st_atim.tv_sec);
122+
__put_user(host_st->st_atim.tv_nsec, &target_st->st_atim.tv_nsec);
123+
__put_user(host_st->st_mtim.tv_sec, &target_st->st_mtim.tv_sec);
124+
__put_user(host_st->st_mtim.tv_nsec, &target_st->st_mtim.tv_nsec);
125+
__put_user(host_st->st_ctim.tv_sec, &target_st->st_ctim.tv_sec);
126+
__put_user(host_st->st_ctim.tv_nsec, &target_st->st_ctim.tv_nsec);
127+
__put_user(host_st->st_size, &target_st->st_size);
128+
__put_user(host_st->st_blocks, &target_st->st_blocks);
129+
__put_user(host_st->st_blksize, &target_st->st_blksize);
130+
__put_user(host_st->st_flags, &target_st->st_flags);
131+
__put_user(host_st->st_gen, &target_st->st_gen);
132+
__put_user(host_st->st_birthtim.tv_sec, &target_st->st_birthtim.tv_sec);
133+
__put_user(host_st->st_birthtim.tv_nsec, &target_st->st_birthtim.tv_nsec);
134+
unlock_user_struct(target_st, target_addr, 1);
135+
136+
return 0;
137+
}
138+
139+
/*
140+
* file handle conversion
141+
*/
142+
abi_long t2h_freebsd_fhandle(fhandle_t *host_fh, abi_ulong target_addr)
143+
{
144+
target_freebsd_fhandle_t *target_fh;
145+
146+
if (!lock_user_struct(VERIFY_READ, target_fh, target_addr, 1)) {
147+
return -TARGET_EFAULT;
148+
}
149+
__get_user(host_fh->fh_fsid.val[0], &target_fh->fh_fsid.val[0]);
150+
__get_user(host_fh->fh_fsid.val[1], &target_fh->fh_fsid.val[0]);
151+
__get_user(host_fh->fh_fid.fid_len, &target_fh->fh_fid.fid_len);
152+
/* u_short fid_data0; */
153+
memcpy(host_fh->fh_fid.fid_data, target_fh->fh_fid.fid_data,
154+
TARGET_MAXFIDSZ);
155+
unlock_user_struct(target_fh, target_addr, 0);
156+
return 0;
157+
}
158+
159+
abi_long h2t_freebsd_fhandle(abi_ulong target_addr, fhandle_t *host_fh)
160+
{
161+
target_freebsd_fhandle_t *target_fh;
162+
163+
if (!lock_user_struct(VERIFY_WRITE, target_fh, target_addr, 0)) {
164+
return -TARGET_EFAULT;
165+
}
166+
__put_user(host_fh->fh_fsid.val[0], &target_fh->fh_fsid.val[0]);
167+
__put_user(host_fh->fh_fsid.val[1], &target_fh->fh_fsid.val[0]);
168+
__put_user(host_fh->fh_fid.fid_len, &target_fh->fh_fid.fid_len);
169+
/* u_short fid_data0; */
170+
memcpy(target_fh->fh_fid.fid_data, host_fh->fh_fid.fid_data,
171+
TARGET_MAXFIDSZ);
172+
unlock_user_struct(target_fh, target_addr, 1);
173+
return 0;
174+
}
175+
176+
/*
177+
* file system stat
178+
*/
179+
abi_long h2t_freebsd11_statfs(abi_ulong target_addr,
180+
struct freebsd11_statfs *host_statfs)
181+
{
182+
struct target_freebsd11_statfs *target_statfs;
183+
184+
if (!lock_user_struct(VERIFY_WRITE, target_statfs, target_addr, 0)) {
185+
return -TARGET_EFAULT;
186+
}
187+
__put_user(host_statfs->f_version, &target_statfs->f_version);
188+
__put_user(host_statfs->f_type, &target_statfs->f_type);
189+
__put_user(host_statfs->f_flags, &target_statfs->f_flags);
190+
__put_user(host_statfs->f_bsize, &target_statfs->f_bsize);
191+
__put_user(host_statfs->f_iosize, &target_statfs->f_iosize);
192+
__put_user(host_statfs->f_blocks, &target_statfs->f_blocks);
193+
__put_user(host_statfs->f_bfree, &target_statfs->f_bfree);
194+
__put_user(host_statfs->f_bavail, &target_statfs->f_bavail);
195+
__put_user(host_statfs->f_files, &target_statfs->f_files);
196+
__put_user(host_statfs->f_ffree, &target_statfs->f_ffree);
197+
__put_user(host_statfs->f_syncwrites, &target_statfs->f_syncwrites);
198+
__put_user(host_statfs->f_asyncwrites, &target_statfs->f_asyncwrites);
199+
__put_user(host_statfs->f_syncreads, &target_statfs->f_syncreads);
200+
__put_user(host_statfs->f_asyncreads, &target_statfs->f_asyncreads);
201+
/* uint64_t f_spare[10]; */
202+
__put_user(host_statfs->f_namemax, &target_statfs->f_namemax);
203+
__put_user(host_statfs->f_owner, &target_statfs->f_owner);
204+
__put_user(host_statfs->f_fsid.val[0], &target_statfs->f_fsid.val[0]);
205+
__put_user(host_statfs->f_fsid.val[1], &target_statfs->f_fsid.val[1]);
206+
/* char f_charspace[80]; */
207+
strncpy(target_statfs->f_fstypename, host_statfs->f_fstypename,
208+
sizeof(target_statfs->f_fstypename));
209+
strncpy(target_statfs->f_mntfromname, host_statfs->f_mntfromname,
210+
sizeof(target_statfs->f_mntfromname));
211+
strncpy(target_statfs->f_mntonname, host_statfs->f_mntonname,
212+
sizeof(target_statfs->f_mntonname));
213+
unlock_user_struct(target_statfs, target_addr, 1);
214+
return 0;
215+
}
216+
217+
abi_long h2t_freebsd_statfs(abi_ulong target_addr,
218+
struct statfs *host_statfs)
219+
{
220+
struct target_statfs *target_statfs;
221+
222+
if (!lock_user_struct(VERIFY_WRITE, target_statfs, target_addr, 0)) {
223+
return -TARGET_EFAULT;
224+
}
225+
__put_user(host_statfs->f_version, &target_statfs->f_version);
226+
__put_user(host_statfs->f_type, &target_statfs->f_type);
227+
__put_user(host_statfs->f_flags, &target_statfs->f_flags);
228+
__put_user(host_statfs->f_bsize, &target_statfs->f_bsize);
229+
__put_user(host_statfs->f_iosize, &target_statfs->f_iosize);
230+
__put_user(host_statfs->f_blocks, &target_statfs->f_blocks);
231+
__put_user(host_statfs->f_bfree, &target_statfs->f_bfree);
232+
__put_user(host_statfs->f_bavail, &target_statfs->f_bavail);
233+
__put_user(host_statfs->f_files, &target_statfs->f_files);
234+
__put_user(host_statfs->f_ffree, &target_statfs->f_ffree);
235+
__put_user(host_statfs->f_syncwrites, &target_statfs->f_syncwrites);
236+
__put_user(host_statfs->f_asyncwrites, &target_statfs->f_asyncwrites);
237+
__put_user(host_statfs->f_syncreads, &target_statfs->f_syncreads);
238+
__put_user(host_statfs->f_asyncreads, &target_statfs->f_asyncreads);
239+
/* uint64_t f_spare[10]; */
240+
__put_user(host_statfs->f_namemax, &target_statfs->f_namemax);
241+
__put_user(host_statfs->f_owner, &target_statfs->f_owner);
242+
__put_user(host_statfs->f_fsid.val[0], &target_statfs->f_fsid.val[0]);
243+
__put_user(host_statfs->f_fsid.val[1], &target_statfs->f_fsid.val[1]);
244+
/* char f_charspace[80]; */
245+
strncpy(target_statfs->f_fstypename, host_statfs->f_fstypename,
246+
sizeof(target_statfs->f_fstypename));
247+
strncpy(target_statfs->f_mntfromname, host_statfs->f_mntfromname,
248+
sizeof(target_statfs->f_mntfromname));
249+
strncpy(target_statfs->f_mntonname, host_statfs->f_mntonname,
250+
sizeof(target_statfs->f_mntonname));
251+
unlock_user_struct(target_statfs, target_addr, 1);
252+
return 0;
253+
}
254+
255+
/*
256+
* fcntl cmd conversion
257+
*/
258+
abi_long target_to_host_fcntl_cmd(int cmd)
259+
{
260+
return cmd;
261+
}
262+

0 commit comments

Comments
 (0)