Skip to content

Commit

Permalink
Merge tag 'bsd-user-mmap-pull-request' of https://gitlab.com/bsdimp/qemu
Browse files Browse the repository at this point in the history
 into staging

bsd-user mmap and exec branches from gsoc

This pull request represents the mmap and exec changes from Karim Taha
for his GSoC project.

They represent all the mmap and exec related system calls and get bsd-user to
the point that a dynamic hello-world works (at least for armv7).

There are a couple of patch check errors, but they are the lessor evil: I made
purposely bad style choices to ensure all the commits compiled (and i undid the
style choices in subsequent commits).

I pushed an earlier version to gitlab, and all but the riscv64 pipelines were
green.  Since bsd-user doesn't change anything related to ricsv64 (there's no
support in qemu-project repo, though we do have it in the bsd-user fork: coming
soon).

I think this is good to go.

https://gitlab.com/bsdimp/qemu.git

Warner

# -----BEGIN PGP SIGNATURE-----
# Comment: GPGTools - https://gpgtools.org
#
# iQIzBAABCgAdFiEEIDX4lLAKo898zeG3bBzRKH2wEQAFAmUcpC4ACgkQbBzRKH2w
# EQDD9xAA3Rg0AnfnFrd+AoWRb/1/gOuO0v+dEGXj50qnGY8OmHeYtg3XecYPArBq
# EicZzL/OG7UZKMl5OfrmGP9tbr32yfeRUTe3AGGHfmnSb11q0yeSaEFZI7felLHj
# 9nlq4H/2EDRrY+7EnG1TWqtnuqDJAJf/7M0giiVxIk77XGX+USUNPOSG4NP/yc8E
# D5p2GN23pUsvnI0jBZkyP3gyeXVNCNG5+KobwqJM3r6OjEiTRmLEVBw98YzG12bh
# OY9ekMtVUKHi4Cvsf+2TtkDGRya0wX4uqm4UB1TtV1VUDoCWhYgEKBHp3ozCoVjB
# J+ygbx7/jNfY53cpgEpKUBFH7rnOq1yQQ+ad5Ap5hbp4j6WSvPwdp1N3RCnkZzd/
# L50VIaySd+P6enAgPO5Mbt3kMMVd/eDGhQDWdzNToIjyhXBb5hUNfumg9AgdEwTh
# rW/kKT39YLYWLO123hIJCy2CKU9nvoea9588ExkKb22v0ltrtDcAlWfCbZvZYxNN
# wRzh+MFBt7Cd/bqk7HaJ0J/YyPToqImoUjNuBnBSDPqZQP2H4U8v/FoICQ0mm5kR
# jZCmGLMEP1PiDlusjUjaW0iamHvXiSP8KEzaAbIxx5UUiTWTTkQm4CKY/xPxC9VQ
# 0ygJqJVrKHlNrAY9u6ggJAXtorVwmC55z4ZqIVQH6cbzUYFMuJU=
# =WpL4
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 03 Oct 2023 19:30:54 EDT
# gpg:                using RSA key 2035F894B00AA3CF7CCDE1B76C1CD1287DB01100
# gpg: Good signature from "Warner Losh <wlosh@netflix.com>" [unknown]
# gpg:                 aka "Warner Losh <imp@bsdimp.com>" [unknown]
# gpg:                 aka "Warner Losh <imp@freebsd.org>" [unknown]
# gpg:                 aka "Warner Losh <imp@village.org>" [unknown]
# gpg:                 aka "Warner Losh <wlosh@bsdimp.com>" [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 'bsd-user-mmap-pull-request' of https://gitlab.com/bsdimp/qemu: (51 commits)
  bsd-user: Add stubs for vadvise(), sbrk() and sstk()
  bsd-user: Implement shmat(2) and shmdt(2)
  bsd-user: Implement shmctl(2)
  bsd-user: Implement shm_unlink(2) and shmget(2)
  bsd-user: Implement shm_open(2)
  bsd-user: Implement do_obreak function
  bsd-user: Implement mincore(2)
  bsd-user: Implment madvise(2) to match the linux-user implementation.
  bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2)
  bsd-user: Implement msync(2)
  bsd-user: Implement mprotect(2)
  bsd-user: Implement mmap(2) and munmap(2)
  bsd-user: Introduce bsd-mem.h to the source tree
  bsd-user: Implement shmid_ds conversion between host and target.
  bsd-user: Implement ipc_perm conversion between host and target.
  bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c
  bsd-user: Add bsd-mem.c to meson.build
  bsd-user: Implement shm_rename(2) system call
  bsd-user: Implement shm_open2(2) system call
  bsd-user: Introduce freebsd/os-misc.h to the source tree
  ...

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
stefanhaRH committed Oct 4, 2023
2 parents c7c907b + dfa1d91 commit 80dcaf6
Show file tree
Hide file tree
Showing 17 changed files with 2,428 additions and 10 deletions.
104 changes: 104 additions & 0 deletions bsd-user/bsd-mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* memory management system conversion routines
*
* Copyright (c) 2013 Stacey D. Son
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu/osdep.h"
#include "qemu.h"
#include "qemu-bsd.h"

struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS];

abi_ulong target_brk;
abi_ulong initial_target_brk;

void target_set_brk(abi_ulong new_brk)
{
target_brk = TARGET_PAGE_ALIGN(new_brk);
initial_target_brk = target_brk;
}

void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip,
struct target_ipc_perm *target_ip)
{
__get_user(host_ip->cuid, &target_ip->cuid);
__get_user(host_ip->cgid, &target_ip->cgid);
__get_user(host_ip->uid, &target_ip->uid);
__get_user(host_ip->gid, &target_ip->gid);
__get_user(host_ip->mode, &target_ip->mode);
__get_user(host_ip->seq, &target_ip->seq);
__get_user(host_ip->key, &target_ip->key);
}

abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
abi_ulong target_addr)
{
struct target_shmid_ds *target_sd;

if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) {
return -TARGET_EFAULT;
}

target_to_host_ipc_perm__locked(&(host_sd->shm_perm),
&(target_sd->shm_perm));

__get_user(host_sd->shm_segsz, &target_sd->shm_segsz);
__get_user(host_sd->shm_lpid, &target_sd->shm_lpid);
__get_user(host_sd->shm_cpid, &target_sd->shm_cpid);
__get_user(host_sd->shm_nattch, &target_sd->shm_nattch);
__get_user(host_sd->shm_atime, &target_sd->shm_atime);
__get_user(host_sd->shm_dtime, &target_sd->shm_dtime);
__get_user(host_sd->shm_ctime, &target_sd->shm_ctime);
unlock_user_struct(target_sd, target_addr, 0);

return 0;
}

void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip,
struct ipc_perm *host_ip)
{
__put_user(host_ip->cuid, &target_ip->cuid);
__put_user(host_ip->cgid, &target_ip->cgid);
__put_user(host_ip->uid, &target_ip->uid);
__put_user(host_ip->gid, &target_ip->gid);
__put_user(host_ip->mode, &target_ip->mode);
__put_user(host_ip->seq, &target_ip->seq);
__put_user(host_ip->key, &target_ip->key);
}

abi_long host_to_target_shmid_ds(abi_ulong target_addr,
struct shmid_ds *host_sd)
{
struct target_shmid_ds *target_sd;

if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
return -TARGET_EFAULT;
}

host_to_target_ipc_perm__locked(&(target_sd->shm_perm),
&(host_sd->shm_perm));

__put_user(host_sd->shm_segsz, &target_sd->shm_segsz);
__put_user(host_sd->shm_lpid, &target_sd->shm_lpid);
__put_user(host_sd->shm_cpid, &target_sd->shm_cpid);
__put_user(host_sd->shm_nattch, &target_sd->shm_nattch);
__put_user(host_sd->shm_atime, &target_sd->shm_atime);
__put_user(host_sd->shm_dtime, &target_sd->shm_dtime);
__put_user(host_sd->shm_ctime, &target_sd->shm_ctime);
unlock_user_struct(target_sd, target_addr, 1);

return 0;
}

0 comments on commit 80dcaf6

Please sign in to comment.