From patchwork Sun Sep 24 21:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=AvBhw1gw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6YF2P4Nz1ynX for ; Mon, 25 Sep 2023 12:40:17 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSd-0003D3-Ta; Sun, 24 Sep 2023 22:36:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSc-00038o-88 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:34 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSZ-0008UP-P6 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:33 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40535597f01so54263955e9.3 for ; Sun, 24 Sep 2023 19:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609389; x=1696214189; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/0hUnJo62FgJTQIoivO6Goxg3C9ame5/C7KEuYom5hs=; b=AvBhw1gw7lcHXvjQoM3FxJ5qBe2qTHLaM2jNvJR3L9hASyXRmOKr5YoaAvLRqz8Rt5 SOXKLhRvHal/MCV84OoY56Y3+h+UJ5NOSEO1VzVigDgaMzu35ujkFMd7DbzynXB5ngpW bbXS6sx2QsVkcMFeN2iGpouv//TiCPpY7gMNs6GagJHCpzWCxfz8XY7UTR+1c9Mirxvk 3DYTVQBpOQ/zRyRsfKakkY4dQ4/2qQtFjWxgOX/Cr5etzeHOU1qfdGFagJn0DNY7C+jo ssOIa0QeA5sVpPns6n67keCKWC9g83yHsnc3smYMWwgPdqMCoDz0e63pyg6A/pfLRoGq 8bkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609389; x=1696214189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/0hUnJo62FgJTQIoivO6Goxg3C9ame5/C7KEuYom5hs=; b=M3WcS2LidezZ8OScWCc64afscBC8SuoY4uGPEfNYXFEcqPBHIWibMpKdUXMT0Og3a3 nTO3T88kpzP9872LA8tVlQlQTNjhTCXfQoFH+J3eq4DIWqL7CDXeLda6b7r0AGBQscCy R/LcblJk8loDP04AMDQpwgoyPju1MvnErGdWjxRkxCMQmHMx6WiYTfEtO31JKeuqzpwB sHdLHQyCHgjYD0DqcZrP+USLKJ7znijuoPe6+gth/F/TPN7Kh+cQVFViY2GO9cElDyW3 6K/JJEVWGP7kMGi6djAvO5biXSBA/2Bt9SKTgSGECSMZ0J1BS22l5tmIwNzK0ayisYR7 GcHA== X-Gm-Message-State: AOJu0YzXDpp1kYuxF8aGr9T1L+jlq9xsKu65tSWAw7ylSeE/pMVk2yX/ lln+ExKgNvHbGwvaQClIuvYRCz0zMr8= X-Google-Smtp-Source: AGHT+IFMo5p2QVTQHIgrn/4QE7i9ljQQ+41Z0U+PjUxLCjv4hc2Izx9YmP7zn8r0J9EetYt8WRHHTQ== X-Received: by 2002:a5d:4dc3:0:b0:31f:fc6c:8b75 with SMTP id f3-20020a5d4dc3000000b0031ffc6c8b75mr4342126wru.7.1695609389235; Sun, 24 Sep 2023 19:36:29 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:28 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Karim Taha , Kyle Evans Subject: [PATCH v4 01/28] bsd-user: define TARGET_RFSPAWN for rfork to use vfork(2) semantics, and fix RLIM_INFINITY Date: Mon, 25 Sep 2023 00:01:09 +0300 Message-ID: <20230924210136.11966-2-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org RLIM_INFINITY on FreeBSD, OpenBSD and NetBSD has value of ~(1<<63), caculated one way or another. Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/syscall_defs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 9c90616baa..ddd38c13e0 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -130,11 +130,7 @@ struct target_freebsd_timeval { /* * sys/resource.h */ -#if defined(__FreeBSD__) #define TARGET_RLIM_INFINITY RLIM_INFINITY -#else -#define TARGET_RLIM_INFINITY ((abi_ulong)-1) -#endif #define TARGET_RLIMIT_CPU 0 #define TARGET_RLIMIT_FSIZE 1 @@ -390,6 +386,10 @@ struct target_freebsd_flock { int32_t l_sysid; } QEMU_PACKED; +/* sys/unistd.h */ +/* user: vfork(2) semantics, clear signals */ +#define TARGET_RFSPAWN (1U << 31) + #define safe_syscall0(type, name) \ type safe_##name(void) \ { \ From patchwork Sun Sep 24 21:01:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=E98GeXw1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Vj5WjHz1yng for ; Mon, 25 Sep 2023 12:38:05 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSg-0003EI-Ey; Sun, 24 Sep 2023 22:36:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSc-00038u-FE for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:34 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSa-0008UV-Fn for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:34 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso4920267f8f.0 for ; Sun, 24 Sep 2023 19:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609390; x=1696214190; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hPIs14X11Sc9cA1eWwig5Uq4t5+72rZFcQQRqTUVNMo=; b=E98GeXw1jeJub2B5V8zNjk5LanTMDBIspDIF2uBxSsBuI6OdjtRZ6iXfNaeGHMhiO/ CrM4VaO00ETs7fs9BTmL0hM6CxbIAiJJATgcC72seda/tNHcxItsC1PVoPHfBj+NHrUC AtX01el7VpRnhU2BoA6PzyJOSdH1n3QmDZRXFfHnroRFzlPhKdhcaJN/GxWnA52yoeKF uAbBgVq5K8A+seL3XI/BOFcYNU8V4S8VIwUEjRMwXJiIdAh0FTp/HI4obqZBLD+elh8c Xtv2yQJ6/ZE7K3BBGfrnDLWI9pXyLdl3C8O7NOP88dMdJyDjM2s83S1e0TSXfSSlUVRp wJhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609390; x=1696214190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hPIs14X11Sc9cA1eWwig5Uq4t5+72rZFcQQRqTUVNMo=; b=quW5iDqc/Ma9NLpBd7krZ5r2LjkUibhfXOTcEZh122vOnRClah1uy8AHjp3ieBZ1kD Qzg0HjPBQcVbURFQp9ypOjmAj8CKaXDP4vNSdKiKRSbIbnDMwO+b8jyy5EJ19uMRaUeq 12P6FlrwdLWYKxDXSTL0nNRGPc/aXN6TJA/p+7yiRgPR/fViFdYKAi51QtQjkMAJbCK4 WwihP/KnPfRg5+Po5SN3tXkdO5a1bYlFit7b7Bws9wQMA4vCtfzQmY5XBl4v4Vq3dePA Oz8OrVhUB3VrQjuJjvj5PmKiPo1os1L0LDQBwFAcNWGf/0sDPb0vjVFFMtdtwnk4+1ot pf9Q== X-Gm-Message-State: AOJu0YyZ8VR3G7QgcJf2wJAsQYSehrEcRYwpZzkOieg+JkBWSWKJVLsV GVVeyfNWYS7XKOp9ZIxMBjzue+w32uQ= X-Google-Smtp-Source: AGHT+IE8eXZYhm389TAWRzFX7FK2Fra5VRxlQJ3e29TGg6ITrml27tHc01oWtND6spZeGSMPpGBQYQ== X-Received: by 2002:a05:6000:1c7:b0:31f:bdfd:5d30 with SMTP id t7-20020a05600001c700b0031fbdfd5d30mr5594157wrx.57.1695609390634; Sun, 24 Sep 2023 19:36:30 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:30 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 02/28] bsd-user: Define procctl(2) related structs Date: Mon, 25 Sep 2023 00:01:10 +0300 Message-ID: <20230924210136.11966-3-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Implement procctl flags and related structs: struct target_procctl_reaper_status struct target_procctl_reaper_pidinfo struct target_procctl_reaper_pids struct target_procctl_reaper_kill Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/syscall_defs.h | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index ddd38c13e0..a3bc738ff8 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -390,6 +390,48 @@ struct target_freebsd_flock { /* user: vfork(2) semantics, clear signals */ #define TARGET_RFSPAWN (1U << 31) +/* + * from sys/procctl.h + */ +#define TARGET_PROC_SPROTECT 1 +#define TARGET_PROC_REAP_ACQUIRE 2 +#define TARGET_PROC_REAP_RELEASE 3 +#define TARGET_PROC_REAP_STATUS 4 +#define TARGET_PROC_REAP_GETPIDS 5 +#define TARGET_PROC_REAP_KILL 6 + +struct target_procctl_reaper_status { + uint32_t rs_flags; + uint32_t rs_children; + uint32_t rs_descendants; + uint32_t rs_reaper; + uint32_t rs_pid; + uint32_t rs_pad0[15]; +}; + +struct target_procctl_reaper_pidinfo { + uint32_t pi_pid; + uint32_t pi_subtree; + uint32_t pi_flags; + uint32_t pi_pad0[15]; +}; + +struct target_procctl_reaper_pids { + uint32_t rp_count; + uint32_t rp_pad0[15]; + abi_ulong rp_pids; +}; + +struct target_procctl_reaper_kill { + int32_t rk_sig; + uint32_t rk_flags; + uint32_t rk_subtree; + uint32_t rk_killed; + uint32_t rk_fpid; + uint32_t rk_pad0[15]; +}; + + #define safe_syscall0(type, name) \ type safe_##name(void) \ { \ From patchwork Sun Sep 24 21:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JdR/jrH6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6VC2nBKz1yqR for ; Mon, 25 Sep 2023 12:37:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSf-0003Ds-QT; Sun, 24 Sep 2023 22:36:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSd-0003Cq-HV for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:35 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSc-0008Vz-0k for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:35 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3215f19a13aso5392679f8f.3 for ; Sun, 24 Sep 2023 19:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609392; x=1696214192; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v5fw6mGlVPzW+jBOcRjzUpsuKGCpM/DW3RHR4RG7BrI=; b=JdR/jrH62l0oC8NrtpC1QUct7lw0AsgMPyQcAeFop/A9X46cu+KnjNwLGfRvU19eLA mk+mE7pzbvJigt1zkI1dEIWaAncvaKKMSZIVzMZKq2TuyqGro6EBxV209ugcfGsTs80u oVl+Ow4isNjPtlHC3Np8mBabWneWxBySDenz7es7Uz0h+YFWN1PeY9PDJrEKr3rrVGeY v+vTe/HbKC1vYZEEJXu/IaKI+6IuwaEFGqswI1DL9TYTzLc8RlLrazpKiehqLCW3oZcu /AcuzcM2f4g8gCFBJMQU7auJtaVSUEKYq/EjTWWNd/xtPaYBc9CoyNq5+DWcbmCn3oJ7 rrpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609392; x=1696214192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v5fw6mGlVPzW+jBOcRjzUpsuKGCpM/DW3RHR4RG7BrI=; b=t8ufelQTyDz/ZT3NiyJw5GstRNeQMbL5T0uZaqU8zQDG5WgDclUXFxJy7hGiNuaooa VwCttKAA0nmJIkjz6ORCPWi/1XnlpLxT6FWP0Of5+GDDQqjAhryOj5yiPVwfXvc+OjoA 6flANjBnk2Nko+knzZ7c2/u8Em6RoaNoGyi+1kvpWWJ2mDrmr2KzLL6OxFlr4jVdxx1X GMQrfUQgsTLhzJbeCNFRZVOB0fpKgJa2ewdEcMvGQEtCWIlMFYu5NyyQ7kgFgGEvHIi9 FYQWpfCq+hbG50xf7Az91pgWSHBPT2hJn08HlZ12+1o+mjA8Qly/UZVSejorQ3SCJqlt Xe0g== X-Gm-Message-State: AOJu0YyvC+QBbBpnhLh0dMM9xy1AfLqey+Nk8dHYsK0pvq7mGrTAXcwB 8use4u7Iuyxj1xfeaOGjkoKigvdm5z8= X-Google-Smtp-Source: AGHT+IER9FeS1LjQWnoQFhGC56xhTQVro5R366QZTWAwd7Rl8LQMAIbXjw7eLLmcMiEqbSuX1NKy9g== X-Received: by 2002:a5d:4983:0:b0:321:6de4:a1c7 with SMTP id r3-20020a5d4983000000b003216de4a1c7mr4834152wrq.29.1695609391905; Sun, 24 Sep 2023 19:36:31 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:31 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 03/28] bsd-user: Implement host_to_target_siginfo. Date: Mon, 25 Sep 2023 00:01:11 +0300 Message-ID: <20230924210136.11966-4-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Used in wait6 system call Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/signal-common.h | 1 + bsd-user/signal.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index c044e81165..77d7c7a78b 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -35,6 +35,7 @@ int do_sigaction(int sig, const struct target_sigaction *act, abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); long do_sigreturn(CPUArchState *env, abi_ulong addr); void force_sig_fault(int sig, int code, abi_ulong addr); +void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); int host_to_target_signal(int sig); void host_to_target_sigset(target_sigset_t *d, const sigset_t *s); void process_pending_signals(CPUArchState *env); diff --git a/bsd-user/signal.c b/bsd-user/signal.c index b6beab659e..ea82241b70 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -311,6 +311,12 @@ static void tswap_siginfo(target_siginfo_t *tinfo, const target_siginfo_t *info) } } +void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) +{ + host_to_target_siginfo_noswap(tinfo, info); + tswap_siginfo(tinfo, tinfo); +} + int block_signals(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; From patchwork Sun Sep 24 21:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GbEkQ/O4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6WX0j5vz1yng for ; Mon, 25 Sep 2023 12:38:48 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSh-0003Fu-TL; Sun, 24 Sep 2023 22:36:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSf-0003De-2B for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:37 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSd-0008WG-IX for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:36 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-405497850dbso34381575e9.0 for ; Sun, 24 Sep 2023 19:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609393; x=1696214193; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gtr4AZcHHxXXmu6rDPP2dwqMNgqNWW0hP+jIdi1BnOc=; b=GbEkQ/O44iH3uaMfPa1lpCYVV9KP4nfcNXMVpncw/P+qVHwoXPYI0zGAfJ8p3bwg9m OKpoZnLyGOrsbSyAd0J//+dmMwWLGw5GPP03SIMsJXd/QEGwJRKgOkCjkTSyOgeMNtFF 80OZuRBro0GF4jM1uzFxYh7TH857K5EzJxT+g/6o4/gh/Ffr+EHSdi6YbmAnkBpgWxHh xLDbiNCGevpO2tHUOptnEw/FAZ0WkkZ37fH6j5st3MMgBQko6HnI3ed24JA4ylk46Xx4 DZJMNgeaG1oUkSvV+4fu5MDaElQCfnSxDLd0EugTui50w5ugsCuZfwOTF5ki6BrFoBz9 G5rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609393; x=1696214193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gtr4AZcHHxXXmu6rDPP2dwqMNgqNWW0hP+jIdi1BnOc=; b=qA3QVUPwSMRFpLCG5Q/mz9UzBwUNIJ86Y+EyfdTA59F0MGgNm9wyzRXG2lcg5x0OYY ZBrDjZPbpw90XRQAbrXNxZo/P3JgMNijXbXH9JNgIrhc0YolGCfdudMv7zBD7lpZIjB0 pSC04QQDBlZM0gPIzWmHcmsIqPGrDE8SVLZjBpYYjOFLfMF3Ep8x5m6Tc4q48/60BUdu lBuAOeXz9Ip1pyQihFJcSPoGH0tkfvaVZT0xg9XXqAaGqYKrclFv4azujkr9Is7FKooh QM3BULFMgTYqo8gKaNPe4QtSAIAt1Km6jfwfdUhMOnZv26Gmb35l3cu0FFo5PIWAgf7s BCgg== X-Gm-Message-State: AOJu0YxnxY5F5dgnY+0C+2xrxkpvsvZ8S2el99TCUd10p4rB0l9RU6nl okqetK65c3FNZC6pA0BJHkzGVooLc/0= X-Google-Smtp-Source: AGHT+IFXWIfKMUS013e28TQheRHg9FtD4cITd50981UVFVjStfKMGT9/aK3r9yRXZazReFBVqfpuAg== X-Received: by 2002:a5d:458c:0:b0:321:5e2f:37e1 with SMTP id p12-20020a5d458c000000b003215e2f37e1mr4808182wrq.19.1695609393298; Sun, 24 Sep 2023 19:36:33 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:32 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 04/28] bsd-user: Add freebsd_exec_common and do_freebsd_procctl to qemu.h. Date: Mon, 25 Sep 2023 00:01:12 +0300 Message-ID: <20230924210136.11966-5-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/qemu.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index d9507137cc..41c7bd31d3 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -249,6 +249,12 @@ abi_long get_errno(abi_long ret); bool is_error(abi_long ret); int host_to_target_errno(int err); +/* os-proc.c */ +abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, + abi_ulong guest_envp, int do_fexec); +abi_long do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong arg2, + abi_ulong arg3, abi_ulong arg4, abi_ulong arg5, abi_ulong arg6); + /* os-sys.c */ abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); From patchwork Sun Sep 24 21:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=i0xfpNW2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6VH4wyWz1yp8 for ; Mon, 25 Sep 2023 12:37:43 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSi-0003G2-Do; Sun, 24 Sep 2023 22:36:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSg-0003E5-1m for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:38 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSe-00004t-Es for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:37 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so5244888f8f.3 for ; Sun, 24 Sep 2023 19:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609395; x=1696214195; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8NgIQuhS1pWjXF2WQJZ+g0h0EHjHQYwR2fjodfnfROY=; b=i0xfpNW25WBvJlMwe4u7yVSqaigpP+sOOdXXGCREHf4wmGRoN5QG1lJdJI0czeZs4s /0wxauyjYbBLxKtf5Hi+tAtDg6CBRW2J8XUoXxMSqP55U/2zQyXohYh311N9vOKV5+qs K1n/JvCE+tvtOsm76HvFahCbq1ROnjDrENBq6iB2WEDLJAJXKTE1jFqGzBaTb5ev6Y5f LlGmS7uW8URkf3rJd3Khz+dJwWj8TR4sy0YUk2XekhDpc2NOcNI4BM1NdHJiIuMt7oJH iNjeCE5coxX5EeWupuFMkqssoTbpVlaWYBcA7kt5BorfHiO+Y9lTy5v9vJS36BLcCLSn cpWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609395; x=1696214195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8NgIQuhS1pWjXF2WQJZ+g0h0EHjHQYwR2fjodfnfROY=; b=ac0MQBWNDO/fACiFhMqp2NyaOJ1M52Ua007e02GP8P0UpvUggfz86qM9GsvfZnPniS Dzl5JhKs8LKJzp4yeI1DBCaWwPl+Uu5HeVx4NPMgvpsXzWtv+NJqqZG22ofir9v+osNF We3RGRSjke1UeG0nWn2wrWwMAicGocEHkXEljPzBgeKr1twt5/p2iKSmbOKR9G2O5ZI0 /ABr0BWuu70hDuaQaU19IoTkFP1Zg2Nsdwn/ajt8R3AQwDVGc5IudPshAEYMRLNqtsmU Ju3bgxqFzNxmOb8tadVQOC/TA4Qh9P7idXlTB0mCIfD4vSNBa3aqu9GNg+dVcjbtMzFC 4v9w== X-Gm-Message-State: AOJu0Yzvtg3py4RbfcPzHFe79Mf8th0GAoDsOab3eBFprPDfIDsLvcAq AKEsb0PkbzwwxD/PxpZj6geTytPoEz4= X-Google-Smtp-Source: AGHT+IEk/dY95L6UU4NiAV7C9veI7JKD7aOX5ncWtjNB8pguRg0HV8IpD9ntdEBxmNKtr0Kz4pKfIw== X-Received: by 2002:a5d:44ca:0:b0:31f:d52a:82af with SMTP id z10-20020a5d44ca000000b0031fd52a82afmr4458668wrr.49.1695609394808; Sun, 24 Sep 2023 19:36:34 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:34 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 05/28] bsd-user: add extern declarations for bsd-proc.c conversion functions Date: Mon, 25 Sep 2023 00:01:13 +0300 Message-ID: <20230924210136.11966-6-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/qemu-bsd.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bsd-user/qemu-bsd.h diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h new file mode 100644 index 0000000000..b93a0b7fd5 --- /dev/null +++ b/bsd-user/qemu-bsd.h @@ -0,0 +1,38 @@ +/* + * BSD conversion extern declarations + * + * 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 . + */ + +#ifndef QEMU_BSD_H +#define QEMU_BSD_H + +#include +#include + +/* bsd-proc.c */ +int target_to_host_resource(int code); +rlim_t target_to_host_rlim(abi_llong target_rlim); +abi_llong host_to_target_rlim(rlim_t rlim); +abi_long host_to_target_rusage(abi_ulong target_addr, + const struct rusage *rusage); +abi_long host_to_target_wrusage(abi_ulong target_addr, + const struct __wrusage *wrusage); +int host_to_target_waitstatus(int status); +void h2g_rusage(const struct rusage *rusage, + struct target_freebsd_rusage *target_rusage); + +#endif /* QEMU_BSD_H */ From patchwork Sun Sep 24 21:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lHWCQSiG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XH3g3jz1yng for ; Mon, 25 Sep 2023 12:39:27 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSj-0003H1-DU; Sun, 24 Sep 2023 22:36:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSh-0003Ft-SN for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:39 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSg-000055-3z for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:39 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4053c6f0db8so44954925e9.3 for ; Sun, 24 Sep 2023 19:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609396; x=1696214196; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u1vmTkZas+Mn1wLG44nID34aYL1fdKfYh9PS0Nb3bf0=; b=lHWCQSiG+s0E/rW054RJCbUb/cyihPnDFlWkqQklSrL202zqAa82NpVbnLa7iRDFu1 Gt/ByPmlPjksOjKOVYsvN1dE7cmzr1KoHGgSpZiTwidOdAkVEbND4S6cuye6+DFZXsXc 5H4VqYf6hg9Jq2OXCiecSdZccetoAsRjF9JGOAkVMR5HAvd8UWuPt119wcmnI2UsloHi arWu/4I1wsO66zemdo0ckQiXMiO7MzEmfGn5dXr1El9dhLppUsEP/Vh/0/egqEFXefEE MyJa5Olr4xMyC6s/GYZNiuSMv8OAexEbnEnZnz6fLB8HsRXAADMvwu35PZkAifdgIGqs xTBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609396; x=1696214196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u1vmTkZas+Mn1wLG44nID34aYL1fdKfYh9PS0Nb3bf0=; b=bCqUtXfh5f6WdG9I6v4gIcZyKLK5Airm/+ZA9PrtyD4atekAJml9QgvsLK5Tkgtccx dY9MVHI1YeKpqBu/JOigI5HEGPyMD+VAIpfe5KpRgNbAEm4oCRcYtPJpksKzkX+Y/RK4 THYo+/xNFHOHv1TE7KEJOjlYV+WdUeAwM+vAFVH/tPfofd2yWSiTDqrTdoZTdoHx6N8/ acosLmpQWZ+wkV9bB22oYlkG6Awq+i0W6s2F9XvL2zNKVuN91yR/4z9RBjizmUPw1kov c9PQAG0I1p+3EzNc7nsuRUV9d+HjSfe9cO7XTBO3Vjum3kQymF3a89hNXrlckua9rSOP nebw== X-Gm-Message-State: AOJu0Ywxl8FkBhlaXpO3vVikcmBD7g4Z9gq8VgUCwz1YRmT1qxTVP679 3ZHODOJgWr67yBrUZUY7fIvVZMV50RM= X-Google-Smtp-Source: AGHT+IGAPcL3kYSahaDH+Kieh9ygu0xNycz0CqpVjJgcKiSqwIeXp/zyX+cy3oeHfrMA2E0tvEcEMw== X-Received: by 2002:a7b:cd88:0:b0:401:1b58:72f7 with SMTP id y8-20020a7bcd88000000b004011b5872f7mr4451714wmj.38.1695609396309; Sun, 24 Sep 2023 19:36:36 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:35 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 06/28] bsd-user: Implement target_to_host_resource conversion function Date: Mon, 25 Sep 2023 00:01:14 +0300 Message-ID: <20230924210136.11966-7-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/bsd-proc.c | 40 ++++++++++++++++++++++++++++++++++++++++ bsd-user/bsd-proc.h | 4 ++++ bsd-user/meson.build | 6 ++++++ 3 files changed, 50 insertions(+) create mode 100644 bsd-user/bsd-proc.c diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c new file mode 100644 index 0000000000..68410a0aa9 --- /dev/null +++ b/bsd-user/bsd-proc.c @@ -0,0 +1,40 @@ +/* + * BSD process related system call helpers + * + * Copyright (c) 2013-14 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 . + */ +#include "qemu/osdep.h" + +#include +#include +#include +#include +#include + +#include "qemu.h" +#include "qemu-bsd.h" +#include "signal-common.h" + +#include "bsd-proc.h" + +/* + * resource/rusage conversion + */ +int target_to_host_resource(int code) +{ + return code; +} + diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index a1061bffb8..048773a75d 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -22,6 +22,10 @@ #include +#include "qemu-bsd.h" +#include "gdbstub/syscalls.h" +#include "qemu/plugin.h" + /* exit(2) */ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) { diff --git a/bsd-user/meson.build b/bsd-user/meson.build index 5243122fc5..b97fce1472 100644 --- a/bsd-user/meson.build +++ b/bsd-user/meson.build @@ -7,6 +7,7 @@ bsd_user_ss = ss.source_set() common_user_inc += include_directories('include') bsd_user_ss.add(files( + 'bsd-proc.c', 'bsdload.c', 'elfload.c', 'main.c', @@ -16,6 +17,11 @@ bsd_user_ss.add(files( 'uaccess.c', )) +elf = cc.find_library('elf', required: true) +procstat = cc.find_library('procstat', required: true) +kvm = cc.find_library('kvm', required: true) +bsd_user_ss.add(elf, procstat, kvm) + # Pull in the OS-specific build glue, if any subdir(targetos) From patchwork Sun Sep 24 21:01:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=d6LdvbsF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XV2phMz1yng for ; Mon, 25 Sep 2023 12:39:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSl-0003Hp-Cx; Sun, 24 Sep 2023 22:36:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSj-0003GJ-0U for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:41 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSh-00005G-HM for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:40 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3226cc3e324so4501387f8f.3 for ; Sun, 24 Sep 2023 19:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609397; x=1696214197; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aNQ9mDc3plWciIdjeE5Tzw1D9iur6gZpe1I8Oy7Sjl4=; b=d6LdvbsFJW48LbOkCx/pSXY+7i6dUymN47yD/OF6UUGTUDYtN3bB+mM3sHeR2ODBhW X0akd98XVMXraaVoM5e9jyQwethu3swTcF1+edQELGB3hpUEtym1Q0RJFqr18WuUmEOP nr42F8SsE02QhrVW8DIY/IA6qaD1DPk7/d3w+T4SI/TUQZkAdPUj53ftB9mso1AdpGtF dLVfQv30eff976g5RDRX4ANwR3DrVDOA2xWgCJtju9YFoTCDT2ZYWEKlgmpW6DLy2ftG MnKiD6rQCGCDdwhE3dmCkyDy2Y+JzanEybMaOaBHrrRpJPuoMU006ywfc53dHcF4y+dX KsCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609397; x=1696214197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aNQ9mDc3plWciIdjeE5Tzw1D9iur6gZpe1I8Oy7Sjl4=; b=jVT0Rjj0x/xDXSq8wacRiq42WkxoEdNkxowOYXbV2l9zejO0dTMhxKKU4YKSRXuS+2 D4czHieuDaNOjeScFEvri9tkliNjzWUFLG4od5nQv6xJYJ+Hsq+oWwAaMEm43zl+CHuM HGfkwTJISr7nMt606qbwiujzB3eURHUk3P02iA1C/Q/AGPXtKvS1ElSVxZwCxA5phpj4 48QyIK4mD7n/sRB/hcGBqhFUEvRyGJL/BQQSK+FvbR/11cOe9hlZLuj/feMpze99UbCg h0UvpFA58kqrDpTBtQWD+0dkWvFwzHqk7Gf78O8OfPeRw/KWmULenfZiNtbk9b6uDuzr zOIw== X-Gm-Message-State: AOJu0Yx6YXOplvXgfEZgilmIrjih2NKTi7dp4HzvQAZdu0mTjkqM5dcJ ORU4mZ/gtsHwFf5lkABCPA2msm9O6o8= X-Google-Smtp-Source: AGHT+IFhz2G7GozwqvYHlwccfXooAUAFOB8WjHlmQ1/MdEB6xiH2yTcEVPMd4fVJj5Qu1UL3+nDA2g== X-Received: by 2002:a5d:4390:0:b0:31f:b79a:c4b7 with SMTP id i16-20020a5d4390000000b0031fb79ac4b7mr5058070wrq.24.1695609397676; Sun, 24 Sep 2023 19:36:37 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:37 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 07/28] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion. Date: Mon, 25 Sep 2023 00:01:15 +0300 Message-ID: <20230924210136.11966-8-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c index 68410a0aa9..19e39a2f76 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -38,3 +38,13 @@ int target_to_host_resource(int code) return code; } +rlim_t target_to_host_rlim(abi_llong target_rlim) +{ + return tswap64(target_rlim); +} + +abi_llong host_to_target_rlim(rlim_t rlim) +{ + return tswap64(rlim); +} + From patchwork Sun Sep 24 21:01:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TNOSMUnP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6VH4Ksjz1yng for ; Mon, 25 Sep 2023 12:37:43 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSn-0003II-VA; Sun, 24 Sep 2023 22:36:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSk-0003Ha-K3 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:42 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSj-00005Q-15 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:42 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-317c3ac7339so5263457f8f.0 for ; Sun, 24 Sep 2023 19:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609399; x=1696214199; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iWYm7HyQrlRuQgYVJcs9dh5OBv161buo5dw6WbXP5iU=; b=TNOSMUnPX2/Lew+84gijP9A1gbt6+J4BKJwOkaSaXs1qo5D05Cqmapdqv0D2kvlWk/ 3F48dkAw2JscTEvsNZe64c1mDc2d8fIo/E5vOGQWdTCmOepC6ppySGCOH0YXln/VEIMu 5wLJCOoJ/dRX7VTr92EIEdj6AdDE7I91NljBmsLx+ZNOMj/IlMc2jdZsB1eZFAGZii+I KtW/5FxQve6jna3qlYHScGn5KI75mfRIrL+qorbCT+R4LCSuRIX+6YEx8GadCCcrmcA3 27NdhlerqOasWYWQwXYjWKR990AAzpCnFAgxr/yrAu0VTvzQzmyZQOxBPeOwAqsSwArY vgtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609399; x=1696214199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iWYm7HyQrlRuQgYVJcs9dh5OBv161buo5dw6WbXP5iU=; b=pAMCv4/d8yzmCSXnduEunnLl8zXlR+ZBEegdLkMksB1HHnYZL2oaeM9/DYmq9PASRS 1uMyU7IWpibrxJ/ojo0msnC/vVpcPAdQIMUtjRytL32sKrtieR0Rya4E5RS5urS2x/v/ biKFVF+PPbW/hndSJqs2fYPUnxvTrVIC09hNzkrKy5qyz2eRgvLtV6QpuyG+zCiqyxfw EkWSqv7Wonw9w+S0SaXSJdEsq/q+6frd0sR+GsGP2Y2EdxQkBBff1Zz6EHv3gAKpcdc3 6CCCW6Zs1I/aXAWbFsAzFprE5TsW8xUnopCpHb2u3pWuAh4rh5aZbbN8oU6o0so9hels qMkg== X-Gm-Message-State: AOJu0Yzjl7KfqlZddUGD/gkdMihaWpjJRoUsWFPxCGT6O87bledWBrYx uwV7BnREEedcGcau1T/VUGNARlKSz+Q= X-Google-Smtp-Source: AGHT+IEW/EO0g7gNHODR8ZJlE/kTTljDZhdYV01RelHOGdGYJR4OQGHzvnxXO2/T1Rbkc6hGZ820iw== X-Received: by 2002:a5d:5582:0:b0:31f:ffd1:6cf4 with SMTP id i2-20020a5d5582000000b0031fffd16cf4mr4985118wrv.12.1695609399151; Sun, 24 Sep 2023 19:36:39 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:38 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 08/28] bsd-user: Implement host_to_target_rusage and host_to_target_wrusage. Date: Mon, 25 Sep 2023 00:01:16 +0300 Message-ID: <20230924210136.11966-9-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c index 19e39a2f76..aa386ff482 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -48,3 +48,57 @@ abi_llong host_to_target_rlim(rlim_t rlim) return tswap64(rlim); } +void h2g_rusage(const struct rusage *rusage, + struct target_freebsd_rusage *target_rusage) +{ + __put_user(rusage->ru_utime.tv_sec, &target_rusage->ru_utime.tv_sec); + __put_user(rusage->ru_utime.tv_usec, &target_rusage->ru_utime.tv_usec); + + __put_user(rusage->ru_stime.tv_sec, &target_rusage->ru_stime.tv_sec); + __put_user(rusage->ru_stime.tv_usec, &target_rusage->ru_stime.tv_usec); + + __put_user(rusage->ru_maxrss, &target_rusage->ru_maxrss); + __put_user(rusage->ru_idrss, &target_rusage->ru_idrss); + __put_user(rusage->ru_idrss, &target_rusage->ru_idrss); + __put_user(rusage->ru_isrss, &target_rusage->ru_isrss); + __put_user(rusage->ru_minflt, &target_rusage->ru_minflt); + __put_user(rusage->ru_majflt, &target_rusage->ru_majflt); + __put_user(rusage->ru_nswap, &target_rusage->ru_nswap); + __put_user(rusage->ru_inblock, &target_rusage->ru_inblock); + __put_user(rusage->ru_oublock, &target_rusage->ru_oublock); + __put_user(rusage->ru_msgsnd, &target_rusage->ru_msgsnd); + __put_user(rusage->ru_msgrcv, &target_rusage->ru_msgrcv); + __put_user(rusage->ru_nsignals, &target_rusage->ru_nsignals); + __put_user(rusage->ru_nvcsw, &target_rusage->ru_nvcsw); + __put_user(rusage->ru_nivcsw, &target_rusage->ru_nivcsw); +} + +abi_long host_to_target_rusage(abi_ulong target_addr, + const struct rusage *rusage) +{ + struct target_freebsd_rusage *target_rusage; + + if (!lock_user_struct(VERIFY_WRITE, target_rusage, target_addr, 0)) { + return -TARGET_EFAULT; + } + h2g_rusage(rusage, target_rusage); + unlock_user_struct(target_rusage, target_addr, 1); + + return 0; +} + +abi_long host_to_target_wrusage(abi_ulong target_addr, + const struct __wrusage *wrusage) +{ + struct target_freebsd__wrusage *target_wrusage; + + if (!lock_user_struct(VERIFY_WRITE, target_wrusage, target_addr, 0)) { + return -TARGET_EFAULT; + } + h2g_rusage(&wrusage->wru_self, &target_wrusage->wru_self); + h2g_rusage(&wrusage->wru_children, &target_wrusage->wru_children); + unlock_user_struct(target_wrusage, target_addr, 1); + + return 0; +} + From patchwork Sun Sep 24 21:01:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LEgVtk6+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Vg693tz1yng for ; Mon, 25 Sep 2023 12:38:03 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSo-0003IT-49; Sun, 24 Sep 2023 22:36:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSl-0003Hy-KP for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:43 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSk-00005g-4l for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:43 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3232be274a0so212539f8f.1 for ; Sun, 24 Sep 2023 19:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609400; x=1696214200; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tBa86IcvJ8qZLQPEGuLU5XUlSMmhHoCVoEZs2NT+SAc=; b=LEgVtk6+B+aPAqCD3kANPC5cSqrcNp/9tuj5lC/yKsqtiKyp/8r0jTlpvucF5TcXRZ 5Aei5zkFKDoXjC0inv4NQgHGhEME+DokBszHIcjT6v97Ov2RkOFGHOAvxWTi9BaEh8JP IZD7XL4QjxgJ4Z/WZwoRp/8p4kFH9bKvkMFcBzVZUAtvxLx6OLugichHdbPHuvGKcmh2 UhlC7KDcK0tjcZUC6sa5Cs9j9uCTmL4VLlb4VI6FcubAeP2YWtt8GKEYOMWzz6uhs9jp 1tMXvFQ72vQs4UroPFXEA99bUio3ukwjd+LDceuJCJdc0bOTWYS7S+B+pka9UloxrnT6 35Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609400; x=1696214200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tBa86IcvJ8qZLQPEGuLU5XUlSMmhHoCVoEZs2NT+SAc=; b=qwOyGraMXzjs7kenJT2deMakiJmG9V/aV9OKGpquvPDjztnMZMQtePDeyQmcRJdtwW jOF+sAL5yso9JNWGsCrz7Q7OzhBoBEjew7wbN06hff50wOHPYWPklV8r54VOHEbmVc8/ RlK7Caa+B7oQjMeNWT7xcv7ClBNcuHxTZ7pf1Zp7i9ucI1ISBGKgsIC+WtBxI8WFBvyl JJyEAbVUTYDHSHsn3UXmQhUoSShsE1WIUHlzs+0j4GYPiqyzO5lvVs+LqoQCtHoIYijx nHHlVCNbwJBGc5KHq+tCOEERjzcg10Uq3F+LfIvmdr+R0d8WiGg+T5d5PBYODYKxPhDR qMbQ== X-Gm-Message-State: AOJu0YxUQ8WhI2uw4CvuajWdQU4ByOfaQth01DScrO/LB2rzhrnch+qU 9u2rPE2nTsi9s7olsUTO2y3UtxgLK+c= X-Google-Smtp-Source: AGHT+IFCXUVtYSV7eoDl+Ir2u2V11Luw4Z/Gbo7DmwFKoMkqPtbG4k6neAyXVE6BIGAaemV8TeZitA== X-Received: by 2002:adf:dcc7:0:b0:31f:c89b:91fc with SMTP id x7-20020adfdcc7000000b0031fc89b91fcmr6561142wrm.7.1695609400379; Sun, 24 Sep 2023 19:36:40 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:40 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 09/28] bsd-user: Implement host_to_target_waitstatus conversion. Date: Mon, 25 Sep 2023 00:01:17 +0300 Message-ID: <20230924210136.11966-10-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c index aa386ff482..19f6efe1f7 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -102,3 +102,20 @@ abi_long host_to_target_wrusage(abi_ulong target_addr, return 0; } +/* + * wait status conversion. + * + * Map host to target signal numbers for the wait family of syscalls. + * Assume all other status bits are the same. + */ +int host_to_target_waitstatus(int status) +{ + if (WIFSIGNALED(status)) { + return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); + } + if (WIFSTOPPED(status)) { + return (host_to_target_signal(WSTOPSIG(status)) << 8) | (status & 0xff); + } + return status; +} + From patchwork Sun Sep 24 21:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jBndt5K2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XF6qBnz1yng for ; Mon, 25 Sep 2023 12:39:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSq-0003Jr-6C; Sun, 24 Sep 2023 22:36:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSn-0003IJ-CU for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:45 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSl-00005m-BO for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:44 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-405524e6740so32083445e9.1 for ; Sun, 24 Sep 2023 19:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609401; x=1696214201; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C0Dqs0KOjTr5dCbbJ1YQtsQ7bJYAtc0s59yQIYeZ8Mk=; b=jBndt5K2MqQQg6WyD83V6NpLvNe3cbBPXxU4xcezzOLmCsD39dEQDegjmL1BaqePo3 rt4/Fs9DlryD+11mtiNfn2nzLt6dADGzTbuFkYJg2oVNzukFi+b6mwPqe/LfqFaLSKh+ 01AeRBOrlscqct7jsv6/+2k0YQmjA8KSWJr+BHIIt9pmiu6TrCcOsN85tRVmS9Plekaz UyrLx4RXbVKuzy/1+0KMGDfkhKEPTco/PEkCnMG2a4dAJH1/dpWEJfjdZr++YZYcD4wz RjplR8erTHJx11H1iK1/HUoLfakSE38AjVnu7wPkWqd2OOgCu/t1bstoDFwywfpVrqCu aQUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609401; x=1696214201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C0Dqs0KOjTr5dCbbJ1YQtsQ7bJYAtc0s59yQIYeZ8Mk=; b=PYjLtznKIUTyOK2WJAI19+ZsmIFcZHkx/5+Qfp68dXrJdZJVTn+nNGah+HmfXRY0wJ qj4i0zy80T72wSMjfT40YrmrOnoaZElAGkYCKzEVHzbfJ4mZ1teb+K6knKvyQNI0GKT6 QO+2AK9LFVXdke/0Kkv7mYhZ4FwRb234TU4YeN6oAIMRlVmJr6shnEq0wlM4eVHOb94E MUcI0pTyI4QJWaSbNZ4s3JJJDOJy9ea62V/QSNx+ps6P89WW8wBr8kHx342jeSjyRmFH cBmjBkZXn3j0nCln2vTunIyJwxAOUO3EmdWIzrYR7GGQc2ITvuE/k9o0xPFGkpqmzxPu ileA== X-Gm-Message-State: AOJu0YyEgEhzLZ2kTI28ZGkbWKTqk6flkExuFbOMKXWI6FjpGMcU5YB0 SAcDSvQhMugdtBRzJEIEh6LA5LFXPcI= X-Google-Smtp-Source: AGHT+IHx+oyPZI1yaWpPNYYUmyyR5iXoE6WV4gG6D4eG+E0vvzOxsHpNlrywaU5zx15eco1KRg6DRg== X-Received: by 2002:adf:ec4b:0:b0:313:f4e2:901d with SMTP id w11-20020adfec4b000000b00313f4e2901dmr5946333wrn.22.1695609401652; Sun, 24 Sep 2023 19:36:41 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:41 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Kyle Evans , Karim Taha Subject: [PATCH v4 10/28] bsd-user: Get number of cpus. Date: Mon, 25 Sep 2023 00:01:18 +0300 Message-ID: <20230924210136.11966-11-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kyle Evans Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/bsd-proc.c | 24 ++++++++++++++++++++++++ bsd-user/bsd-proc.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c index 19f6efe1f7..ca3c1bf94f 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -119,3 +119,27 @@ int host_to_target_waitstatus(int status) return status; } +int bsd_get_ncpu(void) +{ + int ncpu = -1; + cpuset_t mask; + + CPU_ZERO(&mask); + + if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask), + &mask) == 0) { + ncpu = CPU_COUNT(&mask); + } + + if (ncpu == -1) { + ncpu = sysconf(_SC_NPROCESSORS_ONLN); + } + + if (ncpu == -1) { + gemu_log("XXX Missing bsd_get_ncpu() implementation\n"); + ncpu = 1; + } + + return ncpu; +} + diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 048773a75d..b6225e520e 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -26,6 +26,8 @@ #include "gdbstub/syscalls.h" #include "qemu/plugin.h" +int bsd_get_ncpu(void); + /* exit(2) */ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) { From patchwork Sun Sep 24 21:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YBiEUlhl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6VC2g58z1yng for ; Mon, 25 Sep 2023 12:37:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSr-0003Ks-HC; Sun, 24 Sep 2023 22:36:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSo-0003Im-M7 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:46 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSn-000062-5P for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:46 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-32320381a07so1360602f8f.0 for ; Sun, 24 Sep 2023 19:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609403; x=1696214203; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c+y7I+dQizuXGTfyfswmuzENo8FjWt4FJ1ZjkqfWpTI=; b=YBiEUlhl43KGxD+GlRWYhiEOwf4jO3IBxlDrIFkeeUJXeI+e2nqJjse9+p2mEM7U/n MUXGgSPQA0yu6T9um9e4qdnskcn2bcwXfn4eOre2A0htO828bLUG7/DqwVu6miCeHIBn audlHACyp+RzM8o/vHCJRu668/y4HhkBfrPP/sgjjBfUouKD29+w5u4OT/lK2DyisT9R Htwpp33KMJNqHq/JQSUoZetIomAM3kpWyAHwJnehated2NIDbL0gSxRNnYLBD/SauneK X2diJWNXyIYSM+Z1Lc6p9pZLcOJ0i7qnkjeTzWw3cOOYsYNNdnGeuNHqp8iCbX+ZcW6E M55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609403; x=1696214203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c+y7I+dQizuXGTfyfswmuzENo8FjWt4FJ1ZjkqfWpTI=; b=EqtWoWKgc+17gPMN48oWliKKWcFkPIRRZnWo4E1ajBuGk7xF/T0dlGOBKuRNOddsR5 9DRVI4MYiMCLby670r6l9/jhS+yXcMyYFrvIuzk7tEBlQR3KiM8u5Xd10o06mwc/We3v w78RZJU4MBLk7JmuYumFSbNMkQfuWvhoav99U/jK7oT+SUMAdQTtMiwXc1IhprQSv1u7 fY6QoDKlzcIydeZIEe54WnRuuKA0ewLfwpqf6Ik5rU+cK7wzX3MUcVmCiHNtm1to95R7 QJtOtEbnWo8t1amS9SIvWmWZLHJr6cxPPQe4EAfncp+fkApIDJgX2LJINrZjtplH554q 72Dg== X-Gm-Message-State: AOJu0YwGS3dLJxZfDOm26iYqPNj4MmtHi7lBIhz/t/6KGenv3uwUZTra tqsdUVp98yeVqTryt/SbxXTooSMWINA= X-Google-Smtp-Source: AGHT+IEl7upApJ2GmTlp/8FUF32PelCCrObpvn95+ZdAeAEE9ad2i4vvQG7HjFjWPHF/Wa8dXQEMIQ== X-Received: by 2002:adf:cb8e:0:b0:323:22d9:4930 with SMTP id q14-20020adfcb8e000000b0032322d94930mr1580625wrh.33.1695609402938; Sun, 24 Sep 2023 19:36:42 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:42 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 11/28] bsd-user: Implement getgroups(2) and setgroups(2) system calls. Date: Mon, 25 Sep 2023 00:01:19 +0300 Message-ID: <20230924210136.11966-12-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 44 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 9 +++++++ 2 files changed, 53 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index b6225e520e..7b25aa1982 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -41,4 +41,48 @@ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) return 0; } +/* getgroups(2) */ +static inline abi_long do_bsd_getgroups(abi_long gidsetsize, abi_long arg2) +{ + abi_long ret; + uint32_t *target_grouplist; + g_autofree gid_t *grouplist; + int i; + + grouplist = g_try_new(gid_t, gidsetsize); + ret = get_errno(getgroups(gidsetsize, grouplist)); + if (gidsetsize != 0) { + if (!is_error(ret)) { + target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i = 0; i < ret; i++) { + target_grouplist[i] = tswap32(grouplist[i]); + } + unlock_user(target_grouplist, arg2, gidsetsize * 2); + } + } + return ret; +} + +/* setgroups(2) */ +static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2) +{ + uint32_t *target_grouplist; + g_autofree gid_t *grouplist; + int i; + + grouplist = g_try_new(gid_t, gidsetsize); + target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i = 0; i < gidsetsize; i++) { + grouplist[i] = tswap32(target_grouplist[i]); + } + unlock_user(target_grouplist, arg2, 0); + return get_errno(setgroups(gidsetsize, grouplist)); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index fa60df529e..535e6287bd 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -223,6 +223,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_exit(cpu_env, arg1); break; + case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */ + ret = do_bsd_getgroups(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setgroups: /* setgroups(2) */ + ret = do_bsd_setgroups(arg1, arg2); + break; + + /* * File system calls. */ From patchwork Sun Sep 24 21:01:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ExBLZUJ0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6YR33R2z1ynX for ; Mon, 25 Sep 2023 12:40:27 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSs-0003Ku-6R; Sun, 24 Sep 2023 22:36:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSq-0003Jl-1L for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:48 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSo-00006H-7z for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:47 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-307d20548adso4643531f8f.0 for ; Sun, 24 Sep 2023 19:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609404; x=1696214204; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BH2k0bQHStmKZhT8YGVTXBpS6n5Baw57rePQXzkWAzc=; b=ExBLZUJ0gAcmK9psQk0inIng6A5Q8r/Kx8vElozLCnafFwnqjRW6em6cIQ5fU37+tB KA02Js0cR+L2pYP6pp/IeZjn0RrYubRWV6jGDQLO5QBrwpZ7R7Zf0Fkotta+AsetRaeo nxzw7vOuYMRtfLhrzD5craTpdd5f57Vs0VD8yz81Teou1adw+mmNCw25rB6xm+2hqdSQ XjazYTzPRXvn66gq5WSZWh0EK36sTq3A/+s8Ea5Ql/y8/Dl0InJigm34U3/MJK2+QaDe bnI5Br3TDDjWjdXN8Ilh5KqIVm+0bs/q06yIDz1ztwG9MK3EtnzDQXn4F+mAPzxZbvTC DjZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609404; x=1696214204; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BH2k0bQHStmKZhT8YGVTXBpS6n5Baw57rePQXzkWAzc=; b=cslqeKJ24ZrYwVkY+gtpz96Aia8qeM1kCG2GVy0KWhum94gtElHEcilk3FY9z4oaXA rmCMhzssCi+d947AHqrstIw5eSxXvNMuJV3x4I+MZoahGsgnhi79V8Nm2n7SZVMJvwPD lE7SQa3CcVFZb0tu32Tpd3PImO2qP50AnbvyVhUB8Y7uqyTZAbABNGS9ePaw82sr2AmN 3rNpI1qT/orLwlm0vb2CkVLxT0qifOgCxwdTlL7upEpuFBJisMZ7ZaTKmFzHEhoGRTIo cjCc9s8LNoSwDN3Q8OArI4yjgh2xbLg0teZUX8f3Facr8hHXaCihp1DgAnG+s4QCez5Q gx8A== X-Gm-Message-State: AOJu0Yxp87df+uDE3LoF9wFl4vCcBDFfdn/DRMf2U8g3GFcsVtcaX3vU AFeS1cwIME3RGm5RoL4/lFwItRqFjwI= X-Google-Smtp-Source: AGHT+IHS/IBnE6UkvyVQ1/YRBtir8G/pY9LH6hv1bWl5KOCRS166CUdFAXiiWhsI95GyNN4rC8iXyw== X-Received: by 2002:adf:ffd2:0:b0:31f:e8df:bb52 with SMTP id x18-20020adfffd2000000b0031fe8dfbb52mr5027529wrs.7.1695609404301; Sun, 24 Sep 2023 19:36:44 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:43 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 12/28] bsd-user: Implement umask(2), setlogin(2) and getlogin(2) Date: Mon, 25 Sep 2023 00:01:20 +0300 Message-ID: <20230924210136.11966-13-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 39 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 12 +++++++++++ 2 files changed, 51 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 7b25aa1982..cb7c69acb0 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -26,6 +26,7 @@ #include "gdbstub/syscalls.h" #include "qemu/plugin.h" +extern int _getlogin(char*, int); int bsd_get_ncpu(void); /* exit(2) */ @@ -85,4 +86,42 @@ static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2) return get_errno(setgroups(gidsetsize, grouplist)); } +/* umask(2) */ +static inline abi_long do_bsd_umask(abi_long arg1) +{ + return get_errno(umask(arg1)); +} + +/* setlogin(2) */ +static inline abi_long do_bsd_setlogin(abi_long arg1) +{ + abi_long ret; + void *p; + + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(setlogin(p)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* getlogin(2) */ +static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + + p = lock_user(VERIFY_WRITE, arg1, arg2, 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(_getlogin(p, arg2)); + unlock_user(p, arg1, arg2); + + return ret; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 535e6287bd..44cbf52f08 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -231,6 +231,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setgroups(arg1, arg2); break; + case TARGET_FREEBSD_NR_umask: /* umask(2) */ + ret = do_bsd_umask(arg1); + break; + + case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */ + ret = do_bsd_setlogin(arg1); + break; + + case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */ + ret = do_bsd_getlogin(arg1, arg2); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=h1a5ebEH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6YM2MqWz1ynX for ; Mon, 25 Sep 2023 12:40:23 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSs-0003M8-QU; Sun, 24 Sep 2023 22:36:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSq-0003KQ-L3 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:48 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSp-00006X-6a for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:48 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3231df68584so1680659f8f.1 for ; Sun, 24 Sep 2023 19:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609405; x=1696214205; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wP1rfp1dDRIiBnhp1KylL3inypQKBVqgIftLFJMUFhc=; b=h1a5ebEHrX1q1X0lbAks6wcmhUoMd0F0O3o8de/3KS2Av23GKFbmRwQLl2Qw5gbTpp AXNxSet86p8VvUHIYyz37/zf9DNcMCSIXd+PRqPtfqnL9wv+YROxs0KZAOq/mx8DUBoL nCDSnaqjTso8mpRch49YmLGZL3gOAaAzZ2jk6Zq0HAwY4kC0/H7CEqt5L4SGmjlxGJ9t tavgQh5vd2JLAenJxvr8jrF8PfT2d4k6iFuqUy6kWl92VSCbH5qTRAvnm3SIiuaN2LeZ BnZN2wBoQUN8ip7vdtFKqM61SF6n/3o9KnXawlVOY7axJTyFhpf5eS0yHDZ+cmhwvt+0 e80Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609405; x=1696214205; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wP1rfp1dDRIiBnhp1KylL3inypQKBVqgIftLFJMUFhc=; b=bssD3e+FXr/2O7RqwW2pz3qkaVt/xcpvlv/hFGFBY+d6Bzl+KQXtDM5d0R8bDfN7sF HKd/ZCjgQTnGqMcHAnm7YJp8UGh80UuatrO4pFynHgdcUCbMcnVTO3LkfZqZv8wnBXDn IBbXwgqb2JLmEecG1sdqsAiw++mcyRaC0+DH9WFpkXBa9wf/d9kIQS/R6ma1TQQGblJI jQ2IUuA0QojVyNndwRlonXPRpj+TmbswHQzVtuMiJ0rK4uMJr+/gwSnYy4OXln0nV2/3 sLYcT3YdFIQ22rj2SkNHB92w4OhOS5IqQFsaWeSgy74vXRRupA4T7uBY4aIVmUPQnC28 K35w== X-Gm-Message-State: AOJu0YyOjflTT+XA72V54sO6UotAIY8jeeMtvQ0vg2qt6smfa7pTEiv6 CvfWEwYNXWPHGmlKPlcA/AThVmhyK+M= X-Google-Smtp-Source: AGHT+IHWBv9dRYPUB3m1RKnvGL9GfIMs0fkw+l0+h56OAuJ43rzNDwJopSCFWNszNMCdnFScXo+GJA== X-Received: by 2002:a5d:404d:0:b0:321:4df5:b85e with SMTP id w13-20020a5d404d000000b003214df5b85emr5119700wrp.26.1695609405521; Sun, 24 Sep 2023 19:36:45 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:45 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 13/28] bsd-user: Implement getrusage(2). Date: Mon, 25 Sep 2023 00:01:21 +0300 Message-ID: <20230924210136.11966-14-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 13 +++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index cb7c69acb0..133c1b0eaf 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -124,4 +124,17 @@ static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2) return ret; } +/* getrusage(2) */ +static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_addr) +{ + abi_long ret; + struct rusage rusage; + + ret = get_errno(getrusage(who, &rusage)); + if (!is_error(ret)) { + host_to_target_rusage(target_addr, &rusage); + } + return ret; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 44cbf52f08..5d8693ed55 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -243,6 +243,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_getlogin(arg1, arg2); break; + case TARGET_FREEBSD_NR_getrusage: /* getrusage(2) */ + ret = do_bsd_getrusage(arg1, arg2); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WFw6ATCL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Xw4mpDz1yng for ; Mon, 25 Sep 2023 12:40:00 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSv-0003S6-6L; Sun, 24 Sep 2023 22:36:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSs-0003L9-KN for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:50 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSr-00006n-0b for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:50 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-32320381a07so1360656f8f.0 for ; Sun, 24 Sep 2023 19:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609407; x=1696214207; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lQFZwC0LDHIWACO0/rcAxG3mL7h/9iuVdTmtYhQ4JHQ=; b=WFw6ATCL7BnZ3qXGyHtqIz9TKbGM4xe4SJSM/yIAc6FEyV+n5vYJfM8hp4FhH5B7cw XxvRc8eI3qXnWCVOIyYNcQopAwzeLQI3dKVUMOjNPBUtD5x5OF9PTZ73QSz09K01qbAU Cx65k4jj4Tn/cokTYaczP6IgDu1L+aY8IIHNpdVCKaHbTI8ifpC7Q/3MYNHWAPjAp2+e TTWivwh2gLLtxhA76DMHuSdYXJjhvcXepN21NYXQKulwrpMvH9AUeU5SlN2EHcahuy8F 1bIi8UigvceTSgm9BSDcYmotqkzmLkZGELRvp4V8zNVK7cSfJfhhABolxSV8jRfDbHlK ASiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609407; x=1696214207; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lQFZwC0LDHIWACO0/rcAxG3mL7h/9iuVdTmtYhQ4JHQ=; b=DGwVQgTjG+XPwFCRcAfqU9v+zPkTmpmV7LYNGf8gHabwezgClnHtISMhBR7WBWIIJ5 xKjcXjyeNDwYUphwbugmashJA6W5C91Y69BLcQyU9lnPEEvyLckiOnpJf8QqXSLEZmJe ETU+XC4FNT9/uJ3STwStAS/Q0mf+VGLJEpv35wFoGs2DQP0sJj9YQLmIRECjr6hCKTjf GIHEN1BUoygm6KsWJHIoqv4thGPVH2leF7/M/PcyOmDAxA4dp7cILBCbZr1HpPYgSSmC VTZAAoQ9CsOwdKrc8+s9elhFTS5mx5599ysSsvvnT9f6ickc3VwjzakFxDYYVt3nnk6A WAtQ== X-Gm-Message-State: AOJu0YynstFsF95ZosW0FY7yYdXg3HYowVHGFAVqlrUfchT2gwPaWWUe vkzsKA2acXEY9x8sl9QhK5cveOpcx7E= X-Google-Smtp-Source: AGHT+IEh6ccs13jFQ+HD9VgKXLGdDaW+8A9OxvwxewF8YIhCB/UL1Ha4ZHsOyndKk8RFyHAfXHpJMQ== X-Received: by 2002:a5d:6382:0:b0:319:8c35:378 with SMTP id p2-20020a5d6382000000b003198c350378mr4745285wru.44.1695609406939; Sun, 24 Sep 2023 19:36:46 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:46 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 14/28] bsd-user: Implement getrlimit(2) and setrlimit(2) Date: Mon, 25 Sep 2023 00:01:22 +0300 Message-ID: <20230924210136.11966-15-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 59 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 +++++ 2 files changed, 67 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 133c1b0eaf..38d1324034 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -137,4 +137,63 @@ static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_addr) return ret; } +/* getrlimit(2) */ +static inline abi_long do_bsd_getrlimit(abi_long arg1, abi_ulong arg2) +{ + abi_long ret; + int resource = target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + switch (resource) { + case RLIMIT_STACK: + rlim.rlim_cur = target_dflssiz; + rlim.rlim_max = target_maxssiz; + ret = 0; + break; + + case RLIMIT_DATA: + rlim.rlim_cur = target_dfldsiz; + rlim.rlim_max = target_maxdsiz; + ret = 0; + break; + + default: + ret = get_errno(getrlimit(resource, &rlim)); + break; + } + if (!is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) { + return -TARGET_EFAULT; + } + target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); + target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); + unlock_user_struct(target_rlim, arg2, 1); + } + return ret; +} + +/* setrlimit(2) */ +static inline abi_long do_bsd_setrlimit(abi_long arg1, abi_ulong arg2) +{ + abi_long ret; + int resource = target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + if (RLIMIT_STACK == resource) { + /* XXX We should, maybe, allow the stack size to shrink */ + ret = -TARGET_EPERM; + } else { + if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) { + return -TARGET_EFAULT; + } + rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); + rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); + unlock_user_struct(target_rlim, arg2, 0); + ret = get_errno(setrlimit(resource, &rlim)); + } + return ret; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 5d8693ed55..5cb6086230 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -247,6 +247,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_getrusage(arg1, arg2); break; + case TARGET_FREEBSD_NR_getrlimit: /* getrlimit(2) */ + ret = do_bsd_getrlimit(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setrlimit: /* setrlimit(2) */ + ret = do_bsd_setrlimit(arg1, arg2); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=MtBr7ndf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Wk1khwz1yng for ; Mon, 25 Sep 2023 12:38:58 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSy-0003WQ-0V; Sun, 24 Sep 2023 22:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSu-0003Qd-Dj for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:52 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSs-000070-N9 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:52 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-307d20548adso4643566f8f.0 for ; Sun, 24 Sep 2023 19:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609408; x=1696214208; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+e4yFlvYdu/hYdNO+o3b9LtvOAePOEZiwqvJAYO+t24=; b=MtBr7ndfQ8YjOoeKTo1leycuvyLAUhYB2+IMOaGAXg3algPdw5qVc8+h388z5gO6me 7vZnbFDjXSUSO/0UKbUQ2yaIZeBX4z1er+2MFy/s7t9aqqtq2israJkx8FUFgH1VVNhB Th/XW40EPxE1ylKdRHsKStA0W8xFY+199JwhHcNh+0k6m4fVnYo4/JPmSY4K91PYQyQa pGjoJXDIstXZMYdDJUU+ppN5K5c8l5QN4PAfj38oKlinkUQmkam2t2z2IF/l8kStHcG9 k/tpMJ/NXJdzR+PBV2IHaM9CW8mva9LRlnkn+I3GKtI7JTIKsK7XFm2KG2AOJ7efNI08 UAzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609408; x=1696214208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+e4yFlvYdu/hYdNO+o3b9LtvOAePOEZiwqvJAYO+t24=; b=OBxtROL9tzYxH3gGzD5guYo3u4xe44UmX4acL97fx2G2r7beU+SPOJBe/H3jZchSpw zpd3sIQA3vmyoH+jRDWVjsed8gLroOa2kjmOr++LzdaEzHVuaNSghbM5OryYfMclosId 7nsaUsEIdv4wZx0ob7ha/RDt9hZiF7Jnnu9G+SBWOs7+8+DAph2gkJwsBvFIAKDZ26xe 68kG314iwMUJ6QmLGDU1vf49AbnzS9Bap8LRoR+kukMur6ARjGKAfjfSeW7KTmAsE9JG yhYiPJGX6VnFibeJsyfOJ0BZvQ32TY+T3DaVgj/59Tw0xeV+OQeMMUCJJJnY3f3PaYuO nulw== X-Gm-Message-State: AOJu0YxI+ln/s/EEpcuOYj6JTlZOdeorPRDCjxpt9LPyOWwNOPpZ5twK ZkHdtnsxjc6j71j1t7fzalaTamfQ/zA= X-Google-Smtp-Source: AGHT+IEo4z0U+toNAI0nRt7EXROqi++Xy+jF6m3WM9J0EeaAEr3OKQGxLEzHn9mPcuSIe+QfArk3hQ== X-Received: by 2002:a5d:6990:0:b0:31f:c033:686c with SMTP id g16-20020a5d6990000000b0031fc033686cmr4935993wru.49.1695609408200; Sun, 24 Sep 2023 19:36:48 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:47 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 15/28] bsd-user: Implement several get/set system calls: Date: Mon, 25 Sep 2023 00:01:23 +0300 Message-ID: <20230924210136.11966-16-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son getpid(2), getppid(2), getpgrp(2) setreuid(2), setregid(2) getuid(2), geteuid(2), getgid(2), getegid(2), getpgid(2) setuid(2), seteuid(2), setgid(2), setegid(2), setpgid(2) Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 90 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 60 +++++++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 38d1324034..6ff07c0ac3 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -196,4 +196,94 @@ static inline abi_long do_bsd_setrlimit(abi_long arg1, abi_ulong arg2) return ret; } +/* getpid(2) */ +static inline abi_long do_bsd_getpid(void) +{ + return get_errno(getpid()); +} + +/* getppid(2) */ +static inline abi_long do_bsd_getppid(void) +{ + return get_errno(getppid()); +} + +/* getuid(2) */ +static inline abi_long do_bsd_getuid(void) +{ + return get_errno(getuid()); +} + +/* geteuid(2) */ +static inline abi_long do_bsd_geteuid(void) +{ + return get_errno(geteuid()); +} + +/* getgid(2) */ +static inline abi_long do_bsd_getgid(void) +{ + return get_errno(getgid()); +} + +/* getegid(2) */ +static inline abi_long do_bsd_getegid(void) +{ + return get_errno(getegid()); +} + +/* setuid(2) */ +static inline abi_long do_bsd_setuid(abi_long arg1) +{ + return get_errno(setuid(arg1)); +} + +/* seteuid(2) */ +static inline abi_long do_bsd_seteuid(abi_long arg1) +{ + return get_errno(seteuid(arg1)); +} + +/* setgid(2) */ +static inline abi_long do_bsd_setgid(abi_long arg1) +{ + return get_errno(setgid(arg1)); +} + +/* setegid(2) */ +static inline abi_long do_bsd_setegid(abi_long arg1) +{ + return get_errno(setegid(arg1)); +} + +/* getpgid(2) */ +static inline abi_long do_bsd_getpgid(pid_t pid) +{ + return get_errno(getpgid(pid)); +} + +/* setpgid(2) */ +static inline abi_long do_bsd_setpgid(int pid, int pgrp) +{ + return get_errno(setpgid(pid, pgrp)); +} + +/* getpgrp(2) */ +static inline abi_long do_bsd_getpgrp(void) +{ + return get_errno(getpgrp()); +} + +/* setreuid(2) */ +static inline abi_long do_bsd_setreuid(abi_long arg1, abi_long arg2) +{ + return get_errno(setreuid(arg1, arg2)); +} + +/* setregid(2) */ +static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2) +{ + return get_errno(setregid(arg1, arg2)); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 5cb6086230..7565e69e76 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -255,6 +255,66 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setrlimit(arg1, arg2); break; + case TARGET_FREEBSD_NR_getpid: /* getpid(2) */ + ret = do_bsd_getpid(); + break; + + case TARGET_FREEBSD_NR_getppid: /* getppid(2) */ + ret = do_bsd_getppid(); + break; + + case TARGET_FREEBSD_NR_getuid: /* getuid(2) */ + ret = do_bsd_getuid(); + break; + + case TARGET_FREEBSD_NR_geteuid: /* geteuid(2) */ + ret = do_bsd_geteuid(); + break; + + case TARGET_FREEBSD_NR_getgid: /* getgid(2) */ + ret = do_bsd_getgid(); + break; + + case TARGET_FREEBSD_NR_getegid: /* getegid(2) */ + ret = do_bsd_getegid(); + break; + + case TARGET_FREEBSD_NR_setuid: /* setuid(2) */ + ret = do_bsd_setuid(arg1); + break; + + case TARGET_FREEBSD_NR_seteuid: /* seteuid(2) */ + ret = do_bsd_seteuid(arg1); + break; + + case TARGET_FREEBSD_NR_setgid: /* setgid(2) */ + ret = do_bsd_setgid(arg1); + break; + + case TARGET_FREEBSD_NR_setegid: /* setegid(2) */ + ret = do_bsd_setegid(arg1); + break; + + case TARGET_FREEBSD_NR_getpgrp: /* getpgrp(2) */ + ret = do_bsd_getpgrp(); + break; + + case TARGET_FREEBSD_NR_getpgid: /* getpgid(2) */ + ret = do_bsd_getpgid(arg1); + break; + + case TARGET_FREEBSD_NR_setpgid: /* setpgid(2) */ + ret = do_bsd_setpgid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setreuid: /* setreuid(2) */ + ret = do_bsd_setreuid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setregid: /* setregid(2) */ + ret = do_bsd_setregid(arg1, arg2); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XAaSEOfk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6WK1Mvlz1yng for ; Mon, 25 Sep 2023 12:38:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbSw-0003Vm-Os; Sun, 24 Sep 2023 22:36:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSu-0003Qn-Rv for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:52 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSt-00007D-5R for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:52 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-32003aae100so4495687f8f.0 for ; Sun, 24 Sep 2023 19:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609409; x=1696214209; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nclM6JiCGY7mFmLYiUs3Sh+q/hGi5ONE8JD20ZP5YqQ=; b=XAaSEOfkpCMKVEuCdbiTV8ol+8c1eEaDeFtOiIfRH/v6AkBXZkIBt2ET5823Fa+vHd dd5+2Ae5QsOCVr8KA+koT1cIyRdKWCDwAfNJsRxMQ0gkVcBTIaHJHr3aMKChFUD9bIua u2a36g3dZRi9qjeDxGB5yiBVTvJgkHL0Fns+i3Glc2kMY8qj2p4ZLkHbBCtM1+z92xvN IVKtjQaR7ymMGA8rvhAs5o0Kj3eP1twzCW+ltB38rm8S0x19L1y1U1EiwRjcFjvz6A14 XRjDp0NA9BQYq36gkKNCQLcQIrcOEUrHsDB+1F30o3EdhBw7bnlRyHIOXi0XCvmCLqXC gD/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609409; x=1696214209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nclM6JiCGY7mFmLYiUs3Sh+q/hGi5ONE8JD20ZP5YqQ=; b=RbCW1L5QNPLAQNXhP0eNYtVH0Yjy91dpy+2hYYFYycLl5TckVYb0BLpAqbb+x8KlVp ghVPaMq3wXK8J1sSu3uSa+e2DxCHPAo0rnvs/J5ihTpq5WQHhe4lXWPw863JAhd97Fjd EVw6/AjPkVAN6YTgvhdDjaeDMUjGi/lb2HCOza54Mq2lfKQnLtWMBfOi2GqKsjO3W/dY ZvfRKoRMOIfdzXgrsPazxe0rg8uswQ+GGBDK5/0qKCjpsvJBNg0LsO3F52PGP3bltv7h xuz+ihEDDwI8Aym/KsXjWE9RABLOPozE2jwMKgY+1YdbnXVosOL50Nt31yVILMd7qwky N6Kg== X-Gm-Message-State: AOJu0Ywontw79wZBJLmnHcqD6cXs++vNIWhfuc9IgRr9vqP41DiU5q3Q tv9mfuUZ2UWkFotvCNs6hq0IqnxOOrQ= X-Google-Smtp-Source: AGHT+IEY+jUmo8Q0r2TIy8yAotVK48bGiwyLJ24NxTKUcEOssa9DchX0hLCnjDZzit0IfWaNg86uuw== X-Received: by 2002:adf:ef8d:0:b0:313:f75b:c552 with SMTP id d13-20020adfef8d000000b00313f75bc552mr3734888wro.15.1695609409419; Sun, 24 Sep 2023 19:36:49 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:49 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 16/28] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid. Date: Mon, 25 Sep 2023 00:01:24 +0300 Message-ID: <20230924210136.11966-17-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 76 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 28 +++++++++++++ 2 files changed, 104 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 6ff07c0ac3..a5f301c72f 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -286,4 +286,80 @@ static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2) return get_errno(setregid(arg1, arg2)); } +/* setresgid(2) */ +static inline abi_long do_bsd_setresgid(gid_t rgid, gid_t egid, gid_t sgid) +{ + return get_errno(setresgid(rgid, egid, sgid)); +} + +/* setresuid(2) */ +static inline abi_long do_bsd_setresuid(uid_t ruid, uid_t euid, uid_t suid) +{ + return get_errno(setresuid(ruid, euid, suid)); +} + +/* getresuid(2) */ +static inline abi_long do_bsd_getresuid(abi_ulong arg1, abi_ulong arg2, + abi_ulong arg3) +{ + abi_long ret; + uid_t ruid, euid, suid; + + ret = get_errno(getresuid(&ruid, &euid, &suid)); + if (is_error(ret)) { + return ret; + } + if (put_user_s32(ruid, arg1)) { + return -TARGET_EFAULT; + } + if (put_user_s32(euid, arg2)) { + return -TARGET_EFAULT; + } + if (put_user_s32(suid, arg3)) { + return -TARGET_EFAULT; + } + return ret; +} + +/* getresgid(2) */ +static inline abi_long do_bsd_getresgid(abi_ulong arg1, abi_ulong arg2, + abi_ulong arg3) +{ + abi_long ret; + uid_t ruid, euid, suid; + + ret = get_errno(getresgid(&ruid, &euid, &suid)); + if (is_error(ret)) { + return ret; + } + if (put_user_s32(ruid, arg1)) { + return -TARGET_EFAULT; + } + if (put_user_s32(euid, arg2)) { + return -TARGET_EFAULT; + } + if (put_user_s32(suid, arg3)) { + return -TARGET_EFAULT; + } + return ret; +} + +/* getsid(2) */ +static inline abi_long do_bsd_getsid(abi_long arg1) +{ + return get_errno(getsid(arg1)); +} + +/* setsid(2) */ +static inline abi_long do_bsd_setsid(void) +{ + return get_errno(setsid()); +} + +/* issetugid(2) */ +static inline abi_long do_bsd_issetugid(void) +{ + return get_errno(issetugid()); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7565e69e76..7b51f4f16e 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -315,6 +315,34 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setregid(arg1, arg2); break; + case TARGET_FREEBSD_NR_getresuid: /* getresuid(2) */ + ret = do_bsd_getresuid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getresgid: /* getresgid(2) */ + ret = do_bsd_getresgid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_setresuid: /* setresuid(2) */ + ret = do_bsd_setresuid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_setresgid: /* setresgid(2) */ + ret = do_bsd_setresgid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getsid: /* getsid(2) */ + ret = do_bsd_getsid(arg1); + break; + + case TARGET_FREEBSD_NR_setsid: /* setsid(2) */ + ret = do_bsd_setsid(); + break; + + case TARGET_FREEBSD_NR_issetugid: /* issetugid(2) */ + ret = do_bsd_issetugid(); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DTc/8nxN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6WG4vrrz1yng for ; Mon, 25 Sep 2023 12:38:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT0-0003Yy-7A; Sun, 24 Sep 2023 22:36:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSw-0003Vf-HN for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:54 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSv-00007R-0N for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:54 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-404314388ceso60771565e9.2 for ; Sun, 24 Sep 2023 19:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609411; x=1696214211; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QhivGYb84XE/TlLEmop+Tew1vEbaCLi2YOrvGhy8DCw=; b=DTc/8nxN6cFQf6Z8b25P25wbH/xgbZlyqPa97vUgRMTcrjtZ15ZAPmxjNgmmFTLsSk gJq7N2GnTE9nfy6ikJuiRUD4kMk6erhviI+u38ghU8tU/4A8YqeKQm/w4FKMeIFOnzMK iCN8tc1rOnyem06oK/bZHwjokjMAhwvpjujmg9XKnoAiVrRYWvvOd3tEt1QIl8TsF4ID 1SrrylRh/Rt2xvxwzpHPgyD1Lw6qFdumMifjilVIDrqn2zmLJMloX8axl0Hs9g2nElSC 1+7RxhHm/R2v9OCQoVupkynbg7zwmwVGChgGgD6/m1Duwu9Izjl7jNqJOuWDzgO+iLc/ P6Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609411; x=1696214211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QhivGYb84XE/TlLEmop+Tew1vEbaCLi2YOrvGhy8DCw=; b=UEFhmh+RSMn5osWEW6492GYaCCrX+c9UfZuEWWXHzLs04E/hLBtMnBaBX7clioEaAy hAjD2dWi82zeDF0g8MD22RDY2Kwv+Y3YhuZz8U6Ffk3CzQYzubtO9snN6ysWYf1HlilB ndf/EpZbeygdbSLW+yE3p765B/MTdwdJoh1XmwIm0ExYp7TmCkE1zsKleMjn4/a5jiYY RPYio2pEsjZsRLLdrDD6rJ/lEBCVSrHencqfb3EtJn6ReMRLP4OF6lSPFrNv+hRPcNCk +11COqEqw+XumbOv/A+P5ZicyFVWVwGEpOJAbZi6NupK1OCFelMwbchg5NIhZrkEBJzO 07vQ== X-Gm-Message-State: AOJu0Ywry7FRPWe2j8eMz7VsmiapBKqZynirbgT08qJYGtlbQpO2UoWG PR1c3Hf57EV5YItH6VR70sFEHf40rNI= X-Google-Smtp-Source: AGHT+IG1MqMDYN3DAuKPH9SZU3IkrPm+hA0BRB+xC0oWlkS7lnxpUvv8G930MYTpTTTwQYBTRpfefw== X-Received: by 2002:adf:ed82:0:b0:31a:ed75:75e9 with SMTP id c2-20020adfed82000000b0031aed7575e9mr5905924wro.13.1695609410878; Sun, 24 Sep 2023 19:36:50 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:50 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 17/28] bsd-user: Add stubs for profil(2), ktrace(2), utrace(2) and ptrace(2). Date: Mon, 25 Sep 2023 00:01:25 +0300 Message-ID: <20230924210136.11966-18-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 28 ++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index a5f301c72f..2c1a9ae22f 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -362,4 +362,32 @@ static inline abi_long do_bsd_issetugid(void) return get_errno(issetugid()); } +/* profil(2) */ +static inline abi_long do_bsd_profil(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4) +{ + return -TARGET_ENOSYS; +} + +/* ktrace(2) */ +static inline abi_long do_bsd_ktrace(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4) +{ + return -TARGET_ENOSYS; +} + +/* utrace(2) */ +static inline abi_long do_bsd_utrace(abi_long arg1, abi_long arg2) +{ + return -TARGET_ENOSYS; +} + + +/* ptrace(2) */ +static inline abi_long do_bsd_ptrace(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4) +{ + return -TARGET_ENOSYS; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7b51f4f16e..1a760b1380 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -343,6 +343,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_issetugid(); break; + case TARGET_FREEBSD_NR_profil: /* profil(2) */ + ret = do_bsd_profil(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_ktrace: /* ktrace(2) */ + ret = do_bsd_ktrace(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ + ret = do_bsd_utrace(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_ptrace: /* ptrace(2) */ + ret = do_bsd_ptrace(arg1, arg2, arg3, arg4); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=P7gOFedI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6VL063Gz1yng for ; Mon, 25 Sep 2023 12:37:45 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT0-0003Z5-EH; Sun, 24 Sep 2023 22:36:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSx-0003WN-Rj for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:55 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSw-00007o-8N for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:55 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so5245155f8f.3 for ; Sun, 24 Sep 2023 19:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609412; x=1696214212; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NJNgA7i1skSBgo3G8Dhw1FER8/CjFW3btNuWKszZ4Dk=; b=P7gOFedIEqO5lwno00loIF3wfUPtm2MA2slXBdGRx/P1iOZbRmc4lMkiXkGu6hPbAs CsKKWc/5CN9ujDBQci9r3NGZ34TLrfeLdMbAV64VHi9C7QsTJJwBHzIroPgOx95LjAxI qA5vT5DgB6EisD5y87rPveXmD9NjXunf5F9E201WPGw5gtL7WF/e/SDm/QgZYj1o2Ggm Ki44TbJRKLK5JsWtPY3z7bpOYw7Fz5uylZW/y58brq/uFbz7R4B7EogY0goos6vGoR7G cMNNakhYbO/Waa6TVrKJjK7Mv33EctQEnUP1PCT9P6zpxdjVqnVvmizjuwucX8DAMAmn Znag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609412; x=1696214212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NJNgA7i1skSBgo3G8Dhw1FER8/CjFW3btNuWKszZ4Dk=; b=I3ACTuPJG3Ip6v2ZFScXUfFVUzSQtF0o5MnY8gbsz9J5woE9RvFqITBbni54/QOuos Xvqcw+X9w5NVPySIGhh+zdiPh8BKKBrEXBz1wEOgxMxKPrC3Wwr5C67ebpE2sbwp2a+z ktg9/lEVR390PJVzlNPAPQCj99WPx5ytvljIjjFChqiNkbHoKzTGLsvm/tc/hmiWwqoT ZiEoSeuEaF1ZR/bVSeCtRak7qdk6k9UTckav1AZTGimwlws70z7ynk5+yC38ecpwB7Dd OzXjjxLt8EHsuvxo4p2tyjdVD04kwjunrBiZ4hbv/xSEHNl2KSyDEMCJhccz6iQO3S+Z HOlw== X-Gm-Message-State: AOJu0Yw+vBSmArriPHZc87th8WLoTRo84IFaRt5UGyX/iPnejIIAQkOm HdIn4CZxssLrOc1kpe1cnFJamAm3bm0= X-Google-Smtp-Source: AGHT+IG/lu12jtLuQtzmCYGOrHexLypslvCGGe8vvy3qGGiPAkAxQadjpqAdVFlRbsYZZ9UA0U7hvw== X-Received: by 2002:a05:6000:1c7:b0:320:261:b87f with SMTP id t7-20020a05600001c700b003200261b87fmr5342430wrx.62.1695609412069; Sun, 24 Sep 2023 19:36:52 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:51 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 18/28] bsd-user: Implement getpriority(2) and setpriority(2). Date: Mon, 25 Sep 2023 00:01:26 +0300 Message-ID: <20230924210136.11966-19-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/bsd-proc.h | 24 ++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 2c1a9ae22f..9a8912361f 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -390,4 +390,28 @@ static inline abi_long do_bsd_ptrace(abi_long arg1, abi_long arg2, return -TARGET_ENOSYS; } +/* getpriority(2) */ +static inline abi_long do_bsd_getpriority(abi_long which, abi_long who) +{ + abi_long ret; + /* + * Note that negative values are valid for getpriority, so we must + * differentiate based on errno settings. + */ + errno = 0; + ret = getpriority(which, who); + if (ret == -1 && errno != 0) { + return -host_to_target_errno(errno); + } + + return ret; +} + +/* setpriority(2) */ +static inline abi_long do_bsd_setpriority(abi_long which, abi_long who, + abi_long prio) +{ + return get_errno(setpriority(which, who, prio)); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 1a760b1380..71a2657dd0 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -359,6 +359,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_ptrace(arg1, arg2, arg3, arg4); break; + case TARGET_FREEBSD_NR_getpriority: /* getpriority(2) */ + ret = do_bsd_getpriority(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setpriority: /* setpriority(2) */ + ret = do_bsd_setpriority(arg1, arg2, arg3); + break; + /* * File system calls. From patchwork Sun Sep 24 21:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=m7JB1IhA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XX63ZPz1yng for ; Mon, 25 Sep 2023 12:39:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT1-0003ZY-1b; Sun, 24 Sep 2023 22:36:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbSz-0003Y7-3D for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:57 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSx-000083-6t for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:56 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3232be274a0so212637f8f.1 for ; Sun, 24 Sep 2023 19:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609413; x=1696214213; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TztszCQiHOclcaF2WsULwVYzhpKz4VJgE5PYB7dlSh4=; b=m7JB1IhAPdMEp1HkD6OVBLBe3mjZd5zq2De+shiCNMPNeygDIASFwrLSbUYucRFMBt wd8I+NWv6OkaJk4U0rjgkyPX1XMbPl4kkw9qRWXoL0gsU62WF2VODvmxBO2nxvTdOrsu MrLRn7uHUtY7AB2wYCTcIlKt8KaO74/MaESrLdTFxkkftiugNIoi0kGFjKdDNJekvBjh G3xFmh+QCGhSupsR8DLf8TbaEMncsZY5epy9QLP8pirNSskTxQpGox3TFK1mgZ2SjVr3 jcQVsUJkPxaSdq9h+2cmBC2W53XETRsBBZvMc86D50g23/sktsrs8lIYdFc/mrgr1KoG neOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609413; x=1696214213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TztszCQiHOclcaF2WsULwVYzhpKz4VJgE5PYB7dlSh4=; b=bxBuyhUg/qCY9F1vgfW90Mclikermno4a+MJ1OcqxsK1JbKc6QBYfqtNi1vS/7ZVQ6 1w7mNgFYYPOQT9xWBp60m16wl7x8opWHM05jQ7nsqqQshYfUKv8PJlyS9Ph5VPLVlY0W j76yXztDWLvTKj1bACss6yKUASGtsGN8gJUIr62AkblVWL6H0AMZh1zvMuPrP3/b6tkz 6UzlI1TEm2Md0TKgFiefWoTg7iGzWRf/NKqdT/6bNw0f1aNesqeGKFVGarwAGRHMtV7W 3NU5UOxPJFimBB2etACEbuJPxVvlMz7KxJRPTWMUI3oaewLqvV9cbfpYNl3PzPodl23d WZgg== X-Gm-Message-State: AOJu0YzFh8iSxeVlBsojx1pIZEtYWrlbEdkwh14YBiTWopXwvyw1LIVd QmtDS5qarKPelK1ZHT2UlayP3MMKOq0= X-Google-Smtp-Source: AGHT+IErIMyUPsx2nwBVYXMyigAHyHhnHd4TKbyKeO2x9wtFQI2OcCQ757lq2KSbhC+W3oYPJ5tpvw== X-Received: by 2002:adf:cc8c:0:b0:320:2b29:7041 with SMTP id p12-20020adfcc8c000000b003202b297041mr6539361wrj.24.1695609413407; Sun, 24 Sep 2023 19:36:53 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:52 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Karim Taha , Stacey Son Subject: [PATCH v4 19/28] bsd-user: Implement get_filename_from_fd. Date: Mon, 25 Sep 2023 00:01:27 +0300 Message-ID: <20230924210136.11966-20-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/freebsd/meson.build | 1 + bsd-user/freebsd/os-proc.c | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 bsd-user/freebsd/os-proc.c diff --git a/bsd-user/freebsd/meson.build b/bsd-user/freebsd/meson.build index f2f047cca3..8fd6c7cfb8 100644 --- a/bsd-user/freebsd/meson.build +++ b/bsd-user/freebsd/meson.build @@ -1,5 +1,6 @@ bsd_user_ss.add(files( 'os-stat.c', + 'os-proc.c', 'os-sys.c', 'os-syscall.c', )) diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c new file mode 100644 index 0000000000..cb35f29f10 --- /dev/null +++ b/bsd-user/freebsd/os-proc.c @@ -0,0 +1,80 @@ +/* + * FreeBSD process related emulation code + * + * Copyright (c) 2013-15 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 . + */ +#include "qemu/osdep.h" + +#include +#include +#include +struct kinfo_proc; +#include + +#include "qemu.h" + +/* + * Get the filename for the given file descriptor. + * Note that this may return NULL (fail) if no longer cached in the kernel. + */ +static char * +get_filename_from_fd(pid_t pid, int fd, char *filename, size_t len) +{ + char *ret = NULL; + unsigned int cnt; + struct procstat *procstat = NULL; + struct kinfo_proc *kp = NULL; + struct filestat_list *head = NULL; + struct filestat *fst; + + procstat = procstat_open_sysctl(); + if (procstat == NULL) { + goto out; + } + + kp = procstat_getprocs(procstat, KERN_PROC_PID, pid, &cnt); + if (kp == NULL) { + goto out; + } + + head = procstat_getfiles(procstat, kp, 0); + if (head == NULL) { + goto out; + } + + STAILQ_FOREACH(fst, head, next) { + if (fd == fst->fs_fd) { + if (fst->fs_path != NULL) { + (void)strlcpy(filename, fst->fs_path, len); + ret = filename; + } + break; + } + } + +out: + if (head != NULL) { + procstat_freefiles(procstat, head); + } + if (kp != NULL) { + procstat_freeprocs(procstat, kp); + } + if (procstat != NULL) { + procstat_close(procstat); + } + return ret; +} + From patchwork Sun Sep 24 21:01:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hWsMTM23; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XG4KRDz1yp8 for ; Mon, 25 Sep 2023 12:39:26 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT3-0003bE-0M; Sun, 24 Sep 2023 22:37:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT0-0003ZD-PQ for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:58 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSy-00008N-Vk for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:58 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-405361bb9cdso52650355e9.0 for ; Sun, 24 Sep 2023 19:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609415; x=1696214215; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uxI2BautFYuM9X/6LgOM/mAy2btm9htJw+uHfz45eMY=; b=hWsMTM23syj0f0o4d1Olv5aeblW/Y74PKdQJyBFD1pVoxN71Cz5MqJ+9LnCtP+sXT8 u+Ro4Sb8d6oqmUnBAuHBj20lljRod5sEeZjj3M4j2PwqN5M9tLHovew83XDXw39O5eXb rkel3KJFxqEUGWBFa7xfZesBigy0BDvlZRb98qO7EU2ZgpRzasu1GgUK0up39QUs5AUl TWFXxndz7nhgaZScC4Xa10+VvhOz9nXXt0nK6f7FnvOMNK232VvSwq/643lZhK+cuqnY gyyZmS2yGZ7aTJSmaKIjhlDokbpJwCwL95GmSlRQeCTPBfZCcKzV0UCfu5HilUgMW2ow xHkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609415; x=1696214215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uxI2BautFYuM9X/6LgOM/mAy2btm9htJw+uHfz45eMY=; b=ss0IHPZoTJ/hdlnsJirZcHlpS1QRyy0ZxO1SQuLcZwP6CktFi1rOJiP3ExwBfotMtu rmqNKeo9e9A9oJBcA1CpSQgl4YxUeePOl9hrJmOkA5lJkTuxsIggARpNYNRR4Mel7UQp 9czbtdtOsfav5a8T9lmrHxJle7APKXqv2VQIQp04LMcfgtc3n1Oik/MbDcKL2MTK44H0 6urQxKELdTyFSy3z/LccgSkItWhQimGWRPwCuCxRIk0UgrQP8NZDsJfqCdUChVBoovJD isc1c6m9AU/9aM4tE5UCApNbBFtinEdMTG7o9waPbC4sEOLsscKC5wAhiO8ML8WqwJ3m GmYA== X-Gm-Message-State: AOJu0YxjlEZr0sRZa7DIZUKhE/VcT4fGgzNr14hee9uZJWOkqcSfoH/G l8EooZGZmMx7Ru+iqePOAqkgEuZ1AFg= X-Google-Smtp-Source: AGHT+IEtOW9AO6wp817Eb1i2j5DAYxVRm4LGCNtDrWuuA8zmpMSfa+tBuNJABSn3oIuUK48F9ZBwwg== X-Received: by 2002:a7b:ce16:0:b0:402:f8eb:28d8 with SMTP id m22-20020a7bce16000000b00402f8eb28d8mr4713066wmc.6.1695609414673; Sun, 24 Sep 2023 19:36:54 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:54 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 20/28] bsd-user: Implement freebsd_exec_common, used in implementing execve/fexecve. Date: Mon, 25 Sep 2023 00:01:28 +0300 Message-ID: <20230924210136.11966-21-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.c | 177 +++++++++++++++++++++++++++++++++++++ bsd-user/main.c | 2 +- bsd-user/qemu.h | 1 + 3 files changed, 179 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c index cb35f29f10..12d78b7fc9 100644 --- a/bsd-user/freebsd/os-proc.c +++ b/bsd-user/freebsd/os-proc.c @@ -78,3 +78,180 @@ out: return ret; } +/* + * execve/fexecve + */ +abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, + abi_ulong guest_envp, int do_fexec) +{ + char **argp, **envp, **qargp, **qarg1, **qarg0, **qargend; + int argc, envc; + abi_ulong gp; + abi_ulong addr; + char **q; + int total_size = 0; + void *p; + abi_long ret; + + argc = 0; + for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) { + if (get_user_ual(addr, gp)) { + return -TARGET_EFAULT; + } + if (!addr) { + break; + } + argc++; + } + envc = 0; + for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) { + if (get_user_ual(addr, gp)) { + return -TARGET_EFAULT; + } + if (!addr) { + break; + } + envc++; + } + + qarg0 = argp = g_new0(char *, argc + 9); + /* save the first agrument for the emulator */ + *argp++ = (char *)getprogname(); + qargp = argp; + *argp++ = (char *)getprogname(); + qarg1 = argp; + envp = g_new0(char *, envc + 1); + for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp)) { + ret = -TARGET_EFAULT; + goto execve_end; + } + if (!addr) { + break; + } + *q = lock_user_string(addr); + if (*q == NULL) { + ret = -TARGET_EFAULT; + goto execve_end; + } + total_size += strlen(*q) + 1; + } + *q++ = NULL; + qargend = q; + + for (gp = guest_envp, q = envp; gp; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp)) { + ret = -TARGET_EFAULT; + goto execve_end; + } + if (!addr) { + break; + } + *q = lock_user_string(addr); + if (*q == NULL) { + ret = -TARGET_EFAULT; + goto execve_end; + } + total_size += strlen(*q) + 1; + } + *q = NULL; + + /* + * This case will not be caught by the host's execve() if its + * page size is bigger than the target's. + */ + if (total_size > MAX_ARG_PAGES * TARGET_PAGE_SIZE) { + ret = -TARGET_E2BIG; + goto execve_end; + } + + if (do_fexec) { + if (((int)path_or_fd > 0 && + is_target_elf_binary((int)path_or_fd)) == 1) { + char execpath[PATH_MAX]; + + /* + * The executable is an elf binary for the target + * arch. execve() it using the emulator if we can + * determine the filename path from the fd. + */ + if (get_filename_from_fd(getpid(), (int)path_or_fd, execpath, + sizeof(execpath)) != NULL) { + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + qarg1[1] = qarg1[0]; + qarg1[0] = (char *)"-0"; + qarg1 += 2; + qargend += 2; + *qarg1 = execpath; +#ifndef DONT_INHERIT_INTERP_PREFIX + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + *qarg1++ = (char *)"-L"; + *qarg1++ = (char *)interp_prefix; +#endif + ret = get_errno(execve(qemu_proc_pathname, qargp, envp)); + } else { + /* Getting the filename path failed. */ + ret = -TARGET_EBADF; + goto execve_end; + } + } else { + ret = get_errno(fexecve((int)path_or_fd, argp, envp)); + } + } else { + int fd; + + p = lock_user_string(path_or_fd); + if (p == NULL) { + ret = -TARGET_EFAULT; + goto execve_end; + } + + /* + * Check the header and see if it a target elf binary. If so + * then execute using qemu user mode emulator. + */ + fd = open(p, O_RDONLY | O_CLOEXEC); + if (fd > 0 && is_target_elf_binary(fd) == 1) { + close(fd); + /* execve() as a target binary using emulator. */ + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + qarg1[1] = qarg1[0]; + qarg1[0] = (char *)"-0"; + qarg1 += 2; + qargend += 2; + *qarg1 = (char *)p; +#ifndef DONT_INHERIT_INTERP_PREFIX + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + *qarg1++ = (char *)"-L"; + *qarg1++ = (char *)interp_prefix; +#endif + ret = get_errno(execve(qemu_proc_pathname, qargp, envp)); + } else { + close(fd); + /* Execve() as a host native binary. */ + ret = get_errno(execve(p, argp, envp)); + } + unlock_user(p, path_or_fd, 0); + } + +execve_end: + for (gp = guest_argp, q = argp; *q; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp) || !addr) { + break; + } + unlock_user(*q, addr, 0); + } + + for (gp = guest_envp, q = envp; *q; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp) || !addr) { + break; + } + unlock_user(*q, addr, 0); + } + + g_free(qarg0); + g_free(envp); + + return ret; +} + diff --git a/bsd-user/main.c b/bsd-user/main.c index f913cb55a7..a12b4be80f 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -88,7 +88,7 @@ unsigned long reserved_va = MAX_RESERVED_VA; unsigned long reserved_va; #endif -static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; +const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 41c7bd31d3..6047805ae3 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -111,6 +111,7 @@ typedef struct TaskState { } __attribute__((aligned(16))) TaskState; void stop_all_tasks(void); +extern const char *interp_prefix; extern const char *qemu_uname_release; /* From patchwork Sun Sep 24 21:01:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mePgnZjQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XV5BKHz1yp8 for ; Mon, 25 Sep 2023 12:39:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT3-0003bf-V0; Sun, 24 Sep 2023 22:37:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT1-0003Zf-Mg for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:00 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbSz-00008k-Ty for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:36:59 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4050bd2e33aso57896455e9.2 for ; Sun, 24 Sep 2023 19:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609416; x=1696214216; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8myFaMuRwtNV88tZcliLDFGNAk+0SshlfIoUoSyXCDo=; b=mePgnZjQ3SMkuzRYy5wxNjBkaD2GpCP5ZBu9sF7xmgerx4eB4C/H0+7y6Y2zjnufbF 84EzREPMgIkuO2QHmTzNjkOzA/PK3b2S+4SeMKhoyk8bS8trpZE/hwRD+KQZPf31wO5n /6ji0he+lcjEicLh4voWNksKCECNeJeQZ5n5VEyxBNAPJJmGpwKmBexBqw+74ykhpAJ7 4hNMEkegs8Rrh6mYu/ahL59b4syFiRnvKAQpf6obigOXrySLtJ1UqTq0tXhEmY1Ibdxd 9Vs0nUD26Uo1XThCm46m6NWN2P1sPjCt91NMmfpKNy3hOpf07Jv0d24IsFp4STsNqLyf RH7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609416; x=1696214216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8myFaMuRwtNV88tZcliLDFGNAk+0SshlfIoUoSyXCDo=; b=ZxOObh70aUVyT7Kyyse6jfbD+9U9BCod0bwEIxIbhNAzVcsOi4RWoHJ0NF6OvAmGz1 qOBrMP4zvv41qcRzUtDUxAIE2Hur4l/n8JIV9pa3Yfco7S8vQgmRF9e1yaSeGx44UXU3 Of6iL/c4+ydLevRrLHQXCMu7Vhfmf52Og/kczGjwz09N5eZCBwMwaHS5sCIjake/UuBN PdWnX+hpKDTL1lNqWcLSxlVg4J7DqVXFqh/fzInBHYcqOy/D2VHtrnjo8fb2UtIUhXmH qTwLmW3LzYJ8TkKx+3e2fOo23eYS0SVB2fNzhbGWKdpUlkmnVb/IFVkRNA+JoIeVCI46 QTlg== X-Gm-Message-State: AOJu0Yx+SQVqbv6X1nMn1mI7IRFtNzTsq/65p1eaG9ygSY0Jd1DwnJVp nfxNQqrM3/8e3VuZzKL8gcOqPZMWnjc= X-Google-Smtp-Source: AGHT+IGiBuZTvXXpv1euO0uxZxUne5mStVUDsEPTeNgGysOr0faLhTIUZqKArPW5OrOBvGt55CLRog== X-Received: by 2002:a05:600c:2481:b0:405:4a78:a890 with SMTP id 1-20020a05600c248100b004054a78a890mr4908384wms.8.1695609416112; Sun, 24 Sep 2023 19:36:56 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:55 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 21/28] bsd-user: Implement procctl(2) along with necessary conversion functions. Date: Mon, 25 Sep 2023 00:01:29 +0300 Message-ID: <20230924210136.11966-22-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Implement t2h_procctl_cmd, h2t_reaper_status, h2t_reaper_pidinfo and h2t/t2h reaper_kill conversion functions. Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.c | 222 ++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 3 + 2 files changed, 225 insertions(+) diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c index 12d78b7fc9..6c0c7a9d67 100644 --- a/bsd-user/freebsd/os-proc.c +++ b/bsd-user/freebsd/os-proc.c @@ -255,3 +255,225 @@ execve_end: return ret; } +#include + +static abi_long +t2h_procctl_cmd(int target_cmd, int *host_cmd) +{ + switch (target_cmd) { + case TARGET_PROC_SPROTECT: + *host_cmd = PROC_SPROTECT; + break; + + case TARGET_PROC_REAP_ACQUIRE: + *host_cmd = PROC_REAP_ACQUIRE; + break; + + case TARGET_PROC_REAP_RELEASE: + *host_cmd = PROC_REAP_RELEASE; + break; + + case TARGET_PROC_REAP_STATUS: + *host_cmd = PROC_REAP_STATUS; + break; + + case TARGET_PROC_REAP_KILL: + *host_cmd = PROC_REAP_KILL; + break; + + default: + return -TARGET_EINVAL; + } + + return 0; +} + +static abi_long +h2t_reaper_status(struct procctl_reaper_status *host_rs, + abi_ulong target_rs_addr) +{ + struct target_procctl_reaper_status *target_rs; + + if (!lock_user_struct(VERIFY_WRITE, target_rs, target_rs_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_rs->rs_flags, &target_rs->rs_flags); + __put_user(host_rs->rs_children, &target_rs->rs_children); + __put_user(host_rs->rs_descendants, &target_rs->rs_descendants); + __put_user(host_rs->rs_reaper, &target_rs->rs_reaper); + __put_user(host_rs->rs_pid, &target_rs->rs_pid); + unlock_user_struct(target_rs, target_rs_addr, 1); + + return 0; +} + +static abi_long +t2h_reaper_kill(abi_ulong target_rk_addr, struct procctl_reaper_kill *host_rk) +{ + struct target_procctl_reaper_kill *target_rk; + + if (!lock_user_struct(VERIFY_READ, target_rk, target_rk_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_rk->rk_sig, &target_rk->rk_sig); + __get_user(host_rk->rk_flags, &target_rk->rk_flags); + __get_user(host_rk->rk_subtree, &target_rk->rk_subtree); + __get_user(host_rk->rk_killed, &target_rk->rk_killed); + __get_user(host_rk->rk_fpid, &target_rk->rk_fpid); + unlock_user_struct(target_rk, target_rk_addr, 0); + + return 0; +} + +static abi_long +h2t_reaper_kill(struct procctl_reaper_kill *host_rk, abi_ulong target_rk_addr) +{ + struct target_procctl_reaper_kill *target_rk; + + if (!lock_user_struct(VERIFY_WRITE, target_rk, target_rk_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_rk->rk_sig, &target_rk->rk_sig); + __put_user(host_rk->rk_flags, &target_rk->rk_flags); + __put_user(host_rk->rk_subtree, &target_rk->rk_subtree); + __put_user(host_rk->rk_killed, &target_rk->rk_killed); + __put_user(host_rk->rk_fpid, &target_rk->rk_fpid); + unlock_user_struct(target_rk, target_rk_addr, 1); + + return 0; +} + +static abi_long +h2t_procctl_reaper_pidinfo(struct procctl_reaper_pidinfo *host_pi, + abi_ulong target_pi_addr) +{ + struct target_procctl_reaper_pidinfo *target_pi; + + if (!lock_user_struct(VERIFY_WRITE, target_pi, target_pi_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_pi->pi_pid, &target_pi->pi_pid); + __put_user(host_pi->pi_subtree, &target_pi->pi_subtree); + __put_user(host_pi->pi_flags, &target_pi->pi_flags); + unlock_user_struct(target_pi, target_pi_addr, 1); + + return 0; +} + +abi_long +do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong arg2, abi_ulong arg3, + abi_ulong arg4, abi_ulong arg5, abi_ulong arg6) +{ + abi_long error = 0, target_rp_pids; + void *data; + int host_cmd, flags; + uint32_t u, target_rp_count; + g_autofree union { + struct procctl_reaper_status rs; + struct procctl_reaper_pids rp; + struct procctl_reaper_kill rk; + } host; + struct target_procctl_reaper_pids *target_rp; + id_t id; /* 64-bit */ + int target_cmd; + abi_ulong target_arg; + +#if TARGET_ABI_BITS == 32 + /* See if we need to align the register pairs. */ + if (regpairs_aligned(cpu_env)) { + id = (id_t)target_arg64(arg3, arg4); + target_cmd = (int)arg5; + target_arg = arg6; + } else { + id = (id_t)target_arg64(arg2, arg3); + target_cmd = (int)arg4; + target_arg = arg5; + } +#else + id = (id_t)arg2; + target_cmd = (int)arg3; + target_arg = arg4; +#endif + + error = t2h_procctl_cmd(target_cmd, &host_cmd); + if (error) { + return error; + } + switch (host_cmd) { + case PROC_SPROTECT: + data = &flags; + break; + + case PROC_REAP_ACQUIRE: + case PROC_REAP_RELEASE: + if (target_arg == 0) { + data = NULL; + } else { + error = -TARGET_EINVAL; + } + break; + + case PROC_REAP_STATUS: + data = &host.rs; + break; + + case PROC_REAP_GETPIDS: + if (!lock_user_struct(VERIFY_READ, target_rp, target_arg, 1)) { + return -TARGET_EFAULT; + } + __get_user(target_rp_count, &target_rp->rp_count); + __get_user(target_rp_pids, &target_rp->rp_pids); + unlock_user_struct(target_rp, target_arg, 0); + host.rp.rp_count = target_rp_count; + host.rp.rp_pids = g_try_new(struct procctl_reaper_pidinfo,target_rp_count); + + if (host.rp.rp_pids == NULL) { + error = -TARGET_ENOMEM; + } else { + data = &host.rp; + } + break; + + case PROC_REAP_KILL: + error = t2h_reaper_kill(target_arg, &host.rk); + break; + } + + if (error) { + return error; + } + error = get_errno(procctl(idtype, id, host_cmd, data)); + + if (error) { + return error; + } + switch (host_cmd) { + case PROC_SPROTECT: + if (put_user_s32(flags, target_arg)) { + return -TARGET_EFAULT; + } + break; + + case PROC_REAP_STATUS: + error = h2t_reaper_status(&host.rs, target_arg); + break; + + case PROC_REAP_GETPIDS: + /* copyout reaper pidinfo */ + for (u = 0; u < target_rp_count; u++) { + error = h2t_procctl_reaper_pidinfo(&host.rp.rp_pids[u], + target_rp_pids + + (u * sizeof(struct target_procctl_reaper_pidinfo))); + if (error) { + break; + } + } + break; + + case PROC_REAP_KILL: + error = h2t_reaper_kill(&host.rk, target_arg); + break; + } + + return error; +} diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 71a2657dd0..b7bd0b92a6 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -367,6 +367,9 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setpriority(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_procctl: /* procctl(2) */ + ret = do_freebsd_procctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; /* * File system calls. From patchwork Sun Sep 24 21:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=EoLs/Qxy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6X82kvnz1yng for ; Mon, 25 Sep 2023 12:39:20 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT4-0003cr-TC; Sun, 24 Sep 2023 22:37:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT3-0003bN-2w for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:01 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT1-00008x-Bn for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:00 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31f7638be6eso5266741f8f.3 for ; Sun, 24 Sep 2023 19:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609418; x=1696214218; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3vvWAJOaU9svMDhrs7MJr+20FyL1xi564pnSJRDac5w=; b=EoLs/QxyGt6ZpXa2b8noeXiO8n6hWBZnqVdqQNskjcjF8GsvECEsJWJno2e5faJ42K aoUMSF7h9J+GSWSzizM/C9YZDlmTLxaTMOgs4zlMNn4R/v24a0ovnVEhQunRW+uP063d O7WnwHwbZiwf24XWMO3pihiljlYOfDJ2VwZDtWSJpwkBXB9Dz6hhXwT6zcAO2zriLAP8 r8CoP/lkPPiehABl/pHAqRmQ1GQRZHZEWbM5uc2vFRoN1OniXIp2jXM3MZovZ9bEJMWX 1AgoEWJ29UXeysj0X0ct0eGRykNNv1Y/CGS+3WsCJoSK79cIKnMgmXfoDbJaEPBV0SYD 6Btw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609418; x=1696214218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3vvWAJOaU9svMDhrs7MJr+20FyL1xi564pnSJRDac5w=; b=gzbruqq9UzhWWKzU5lQRc10OaZo+FHFLME+ry2A6qbAXYQnrrTe9SCBWpnpdf0umPf P11uFJ6AmWJTpQiqEqF5axyiSCyUExsmVMP9vMYmL5lKud+KGlkYUymw7XwlkXZQUGZq JUammkQMo6b8g3Sf1lNJVm1LbkWxVT1sUQM2VlGzFKcDi71a0E7BXpKfZ9tv2zJGtLgA vDK8EiiPmbI/S1ZCVE0iopIFgsSYrDAmje/ynGyg7yQUxlT/apMKGI6wAtrRVtVzwTE9 VcbqmyZoaQSqGJ3hWiGazO3KKGg12GpG+kO2zSZoEO/O15ReAZZ5n4n1+NmCqDp6APKi 8NiQ== X-Gm-Message-State: AOJu0Yz4UKnFA97fM+Eco2NCth62WwfjZD6RYyBlAG14VtbaRUhH1NL6 vOZE2KghbKtt2sOqtBIcFhB9L1+lmvY= X-Google-Smtp-Source: AGHT+IF/VivasxlEUN73XZHm1KKhmKJk6a5xDSxNbtFiYqb3SiTzEHOc7E7OiqX1swkVCEE+WmYBgA== X-Received: by 2002:adf:feca:0:b0:320:4cf:5b50 with SMTP id q10-20020adffeca000000b0032004cf5b50mr5171013wrs.5.1695609417653; Sun, 24 Sep 2023 19:36:57 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:57 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Karim Taha , Stacey Son Subject: [PATCH v4 22/28] bsd-user: Implement execve(2) and fexecve(2) system calls. Date: Mon, 25 Sep 2023 00:01:30 +0300 Message-ID: <20230924210136.11966-23-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 49 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 11 +++++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 bsd-user/freebsd/os-proc.h diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h new file mode 100644 index 0000000000..75ed39f8dd --- /dev/null +++ b/bsd-user/freebsd/os-proc.h @@ -0,0 +1,49 @@ +/* + * process related system call shims and definitions + * + * Copyright (c) 2013-14 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 . + */ + +#ifndef BSD_USER_FREEBSD_OS_PROC_H +#define BSD_USER_FREEBSD_OS_PROC_H + +#include +#include +#include +#include +#include +#include +#include + +#include "target_arch_cpu.h" + +/* execve(2) */ +static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp, + abi_ulong envp) +{ + + return freebsd_exec_common(path_or_fd, argp, envp, 0); +} + +/* fexecve(2) */ +static inline abi_long do_freebsd_fexecve(abi_ulong path_or_fd, abi_ulong argp, + abi_ulong envp) +{ + + return freebsd_exec_common(path_or_fd, argp, envp, 1); +} + +#endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index b7bd0b92a6..515eaaf31f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -36,8 +36,9 @@ #include "bsd-file.h" #include "bsd-proc.h" -/* *BSD dependent syscall shims */ +/* BSD dependent syscall shims */ #include "os-stat.h" +#include "os-proc.h" /* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); @@ -219,6 +220,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, /* * process system calls */ + case TARGET_FREEBSD_NR_execve: /* execve(2) */ + ret = do_freebsd_execve(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_fexecve: /* fexecve(2) */ + ret = do_freebsd_fexecve(arg1, arg2, arg3); + break; + case TARGET_FREEBSD_NR_exit: /* exit(2) */ ret = do_bsd_exit(cpu_env, arg1); break; From patchwork Sun Sep 24 21:01:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=A8n5UdK3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Wz24BHz1yng for ; Mon, 25 Sep 2023 12:39:11 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT5-0003da-LE; Sun, 24 Sep 2023 22:37:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT4-0003cE-FB for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:02 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT2-00009K-RL for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:02 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3231df054c4so1690213f8f.0 for ; Sun, 24 Sep 2023 19:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609419; x=1696214219; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3Ly4EPq2uxWF3voxvrVfIvF9YiPa9H2yaSp9mHck8XY=; b=A8n5UdK31w5/4JuT7E/QfWQy09uf0fp4fLdcNxU6EzYU9lOacBbrtnZmKln9XNIX50 3EC3jRlfduFiWbVdnu0dbRHSetSOx5OapHEuVWKdeR6wqSFroEEqZFJ1/HTTl5MSbVtM 2GoZgoKNufFwo+Duld9Z8y3SBLc8pZFFugy0Fl1gF5hk/rD80X93++bAZvZIoxDKLM9A 5tYf0/tWCXfiA4uRwlPlJgN28VJKHhVczqIzwbYbx/HRSrEi060NUpCpL+jBEehj+ca0 l8enmfuc+G99vNG3oaI5h6k19xYcqHvrs3tPXVE7aoshM2ACU/ywRvNfyyTnX7o0jqD1 9h2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609419; x=1696214219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3Ly4EPq2uxWF3voxvrVfIvF9YiPa9H2yaSp9mHck8XY=; b=QvNiFGnk2TcPgHi7iJ/4etfLoQw70KV2HNZi9m8LxGX4cxI4PsKGLtyhoqgelfvoBw Uiezdunnrwvbefb8DAg7kfgu575HfqnQHVFeJnDxJaFqM/UzBummzfBHB/BRXcVuusR7 LZCXEWddhfM09ho/oc153Bjy0YQqdt8i+JjHZlZjv3bT9HrpSXtgJ0z5WIMXZ0RA0ACL Cn8gs1goFHZJsBEKaguJ3KMw3fgd28DurIFJNYyT9Td/g2KBtXPuOMJ+SSj8U3ewqOEi 0Lg18i+kHXP+3HhSebqu3ZnlXdOR6XlUdI3rd9juQz+3xne7dJNc57oAuzBbGrYe7jG1 MgSg== X-Gm-Message-State: AOJu0Yw9oE5hErwUWnrQJge9suDv3eBs4qfziBi8V9QJQF3vlDIWiGv/ hAaPAWb81p9QVJ2mfgL5gclfpee3gSU= X-Google-Smtp-Source: AGHT+IEPpgJxwougX+iB86L7aI/eiBq87rqUdMsm99OdxcA27PWCp6VhsklSiCfjoP6FQb/qBZcM6w== X-Received: by 2002:adf:e981:0:b0:31f:c1b5:d4c1 with SMTP id h1-20020adfe981000000b0031fc1b5d4c1mr5017760wrm.35.1695609419122; Sun, 24 Sep 2023 19:36:59 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:36:58 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 23/28] bsd-user: Implement wait4(2) and wait6(2) system calls. Date: Mon, 25 Sep 2023 00:01:31 +0300 Message-ID: <20230924210136.11966-24-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 84 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 15 +++++++ 2 files changed, 99 insertions(+) diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 75ed39f8dd..04bce755e5 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -30,6 +30,10 @@ #include "target_arch_cpu.h" +pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage); +pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options, + struct __wrusage *wrusage, siginfo_t *infop); + /* execve(2) */ static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp, abi_ulong envp) @@ -46,4 +50,84 @@ static inline abi_long do_freebsd_fexecve(abi_ulong path_or_fd, abi_ulong argp, return freebsd_exec_common(path_or_fd, argp, envp, 1); } +/* wait4(2) */ +static inline abi_long do_freebsd_wait4(abi_long arg1, abi_ulong target_status, + abi_long arg3, abi_ulong target_rusage) +{ + abi_long ret; + int status; + struct rusage rusage, *rusage_ptr = NULL; + + if (target_rusage) { + rusage_ptr = &rusage; + } + ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr)); + + if (ret < 0) { + return ret; + } + if (target_status != 0) { + status = host_to_target_waitstatus(status); + if (put_user_s32(status, target_status) != 0) { + return -TARGET_EFAULT; + } + } + if (target_rusage != 0) { + host_to_target_rusage(target_rusage, &rusage); + } + return ret; +} + +/* wait6(2) */ +static inline abi_long do_freebsd_wait6(void *cpu_env, abi_long idtype, + abi_long id1, abi_long id2, + abi_ulong target_status, abi_long options, abi_ulong target_wrusage, + abi_ulong target_infop, abi_ulong pad1) +{ + abi_long ret; + int status; + struct __wrusage wrusage, *wrusage_ptr = NULL; + siginfo_t info; + void *p; + + if (regpairs_aligned(cpu_env) != 0) { + /* printf("shifting args\n"); */ + /* 64-bit id is aligned, so shift all the arguments over by one */ + id1 = id2; + id2 = target_status; + target_status = options; + options = target_wrusage; + target_wrusage = target_infop; + target_infop = pad1; + } + + if (target_wrusage) { + wrusage_ptr = &wrusage; + } + ret = get_errno(safe_wait6(idtype, target_arg64(id1, id2), + &status, options, wrusage_ptr, &info)); + + if (ret < 0) { + return ret; + } + if (target_status != 0) { + status = host_to_target_waitstatus(status); + if (put_user_s32(status, target_status) != 0) { + return -TARGET_EFAULT; + } + } + if (target_wrusage != 0) { + host_to_target_wrusage(target_wrusage, &wrusage); + } + if (target_infop != 0) { + p = lock_user(VERIFY_WRITE, target_infop, sizeof(target_siginfo_t), 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + host_to_target_siginfo(p, &info); + unlock_user(p, target_infop, sizeof(target_siginfo_t)); + } + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 515eaaf31f..55e68e4815 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -40,6 +40,12 @@ #include "os-stat.h" #include "os-proc.h" +/* used in os-proc */ +safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, + struct rusage *, rusage); +safe_syscall6(pid_t, wait6, idtype_t, idtype, id_t, id, int *, status, int, + options, struct __wrusage *, wrusage, siginfo_t *, infop); + /* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t, @@ -228,6 +234,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_fexecve(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_wait4: /* wait4(2) */ + ret = do_freebsd_wait4(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_wait6: /* wait6(2) */ + ret = do_freebsd_wait6(cpu_env, arg1, arg2, arg3, + arg4, arg5, arg6, arg7, arg8); + break; + case TARGET_FREEBSD_NR_exit: /* exit(2) */ ret = do_bsd_exit(cpu_env, arg1); break; From patchwork Sun Sep 24 21:01:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VN/ChUcn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6XP6grgz1yng for ; Mon, 25 Sep 2023 12:39:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT7-0003f5-4p; Sun, 24 Sep 2023 22:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT5-0003dj-SR for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:03 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT4-00009c-FX for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:03 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-32329d935d4so646047f8f.2 for ; Sun, 24 Sep 2023 19:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609420; x=1696214220; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=veKd30oIcTHeerV4sm6Po5eWbUfHu/04HcESP3anl/c=; b=VN/ChUcnLKp9Du/hkar3EYEdXwS4qGkDFQu/79/J140shYTa4dmWOgtoWx9Os2TnF4 gsFKuLrJS4S55aeFhDXjm00KK9db8rVYWJPEDgHCt+SYRiD9jbnCbu+JkC75De6kB1Pd yslku3pnByjq5zspRfB1gCgJnJbn3NUkk53o2RkoLNVpb3VLZ6uTZsEKuziC2Rsv9JcC O2ve620jfmVjLGTYlVzKCSxs3270asa6mOg43ZCyzNMCcD75u6c/P6qLJrvnqPipDzVk lCsv24UwwlfFbnah9vDuf70PnZWW0zncCRWEWJBGrVyc9vOHPCmTnzHarVzu3wRb101R KP6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609420; x=1696214220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=veKd30oIcTHeerV4sm6Po5eWbUfHu/04HcESP3anl/c=; b=FJ789lSj9ZSuIwODsS0t1SVuMg5UolbSrAxFaXJ0bkHWVph6Wc9RXKTuRkFdTGmbZH 1d88LyJKnqZ7OcOG/AYpB6Rv/7FaS39ICiQm1phEFu+m0noVP622BDcREebukdVVmFDe q6oyHC+fdYIdTqUNYG0Nbi5ZztjArbyubbiL1kJeRYAtOIk+FDl+sKGb2nviZmLYPtyL P345PRglcnb9JMVcDxC2/qOf+FjPqjal8tEv9ACycaW5UsODI6UTYVnmfS+0Db9Xutyj tRoOS43tdsuu6OFot7kY7kbEiwENezyc+TqWArM7b1EwLjpIP5yhzivpTQg7H5wRjJye BWqQ== X-Gm-Message-State: AOJu0YyWGkJHB/ZbZqOvIl9big7Cv52KdtW7w/KBikPwcllPjo6MkfeY spABUnxzYoGl5RNSmT7XoT3Bl2uB6LM= X-Google-Smtp-Source: AGHT+IHVlSUz5TSgKFc37ZzvpmijfXLDXo3gX0H3IvIQpb1TUSPmlbzNOCpsK/4TNIrz2x/ldGoP2Q== X-Received: by 2002:a5d:6084:0:b0:319:785a:fce0 with SMTP id w4-20020a5d6084000000b00319785afce0mr5114915wrt.26.1695609420446; Sun, 24 Sep 2023 19:37:00 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:37:00 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 24/28] bsd-user: Implement setloginclass(2) and getloginclass(2) system calls. Date: Mon, 25 Sep 2023 00:01:32 +0300 Message-ID: <20230924210136.11966-25-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 32 ++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 04bce755e5..2eaba141dc 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -130,4 +130,36 @@ static inline abi_long do_freebsd_wait6(void *cpu_env, abi_long idtype, return ret; } +/* setloginclass(2) */ +static inline abi_long do_freebsd_setloginclass(abi_ulong arg1) +{ + abi_long ret; + void *p; + + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(setloginclass(p)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* getloginclass(2) */ +static inline abi_long do_freebsd_getloginclass(abi_ulong arg1, abi_ulong arg2) +{ + abi_long ret; + void *p; + + p = lock_user(VERIFY_WRITE, arg1, arg2, 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(getloginclass(p, arg2)); + unlock_user(p, arg1, arg2); + + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 55e68e4815..d614409e69 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -375,6 +375,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_ktrace(arg1, arg2, arg3, arg4); break; + case TARGET_FREEBSD_NR_setloginclass: /* setloginclass(2) */ + ret = do_freebsd_setloginclass(arg1); + break; + + case TARGET_FREEBSD_NR_getloginclass: /* getloginclass(2) */ + ret = do_freebsd_getloginclass(arg1, arg2); + break; + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ ret = do_bsd_utrace(arg1, arg2); break; From patchwork Sun Sep 24 21:01:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UCx5rpgq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6WB5xt3z1yng for ; Mon, 25 Sep 2023 12:38:30 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbT8-0003fg-0E; Sun, 24 Sep 2023 22:37:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT6-0003f2-VK for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:04 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT5-00009w-AQ for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:04 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31ff985e292so5152651f8f.1 for ; Sun, 24 Sep 2023 19:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609422; x=1696214222; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hAKBN+FJFhjMRdTpRlb02p0v4uScFILIgAl2mVAC1ik=; b=UCx5rpgqvGpl7Dv/Inc9PVtDpe5A6Wkg80mQub6mouBPtzSnW3PCmBiGeAcbqQ3CG8 NkZIydbXdBEzJgGJ+5DFVO7Fom7RHmBLJv/CKhFBHzW9/wiZxvehbK9X+Jj/KS7i6RG8 ZSfQICX/UaqUffSS7b7aSBO74dSe5RltkUu3d9be6OwafNl341N27C2Cywl2+4E3yAxj iN6NjJNnmXxor7kjwvgZ174ZOAT9CV6rE9fLlo5B7DSStfzAJMznDwk2SKSgzH15M6vU Ldb2X/XmqcAZhJdJSOSvtibh2JhWnfmXhoZOv4wYVaFWKWv0BbkCyE4l2oeh9DWa9oyC cH9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609422; x=1696214222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hAKBN+FJFhjMRdTpRlb02p0v4uScFILIgAl2mVAC1ik=; b=T/ES1w6MnjfWqLPDoQCKvS9KysUTA6IJC7ngwQB4WEvLuHxtbFPBK0icVNPOmalaxW WmJPTZqBvz+L9I7ZrAHc3aktI87OG93lRgGtQMlsggm4pT7Zuzx0T9wrPSl1Lr3Yd1ay uKXyRx+EmHSXgs3q+fAXV4rNcfjsq+YLhlRKNihvrPtL+lQRlJTfZvrhoS5z0fG4Anim 8o+lulOkz4SuWaP6iOgfPeeNE/ptGL45JoOHa/7QyInuV7UdS3xsPC6CiNVhSTmlgXr2 xXhIkFzs6lB0auRIP1LF3sFdwKHoDmCGE0TxXnOOD/Ad1ObVltvjLMYux5Bo+MYOMZJx NF7Q== X-Gm-Message-State: AOJu0YwoXZTQ/dI4UkcGvxhohtLOoyQAtbKwNb1kLB4huR9mq5zHy31C CB9QzHWHV7nEMQVPI63N5CMIaNJDqkY= X-Google-Smtp-Source: AGHT+IFxQOQggnmeqnj4xbJO8I4lG+/GcvaODYAcfvDwFG+m+E7IhU6vwoy3P1yatVgoMk5NVpzo/Q== X-Received: by 2002:a05:6000:10e:b0:311:1dba:ca65 with SMTP id o14-20020a056000010e00b003111dbaca65mr4875930wrx.51.1695609421685; Sun, 24 Sep 2023 19:37:01 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:37:01 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 25/28] bsd-user: Implement pdgetpid(2) and the undocumented setugid. Date: Mon, 25 Sep 2023 00:01:33 +0300 Message-ID: <20230924210136.11966-26-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 23 +++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 2eaba141dc..42bdd61904 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -34,6 +34,8 @@ pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage); pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options, struct __wrusage *wrusage, siginfo_t *infop); +extern int __setugid(int flag); + /* execve(2) */ static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp, abi_ulong envp) @@ -162,4 +164,25 @@ static inline abi_long do_freebsd_getloginclass(abi_ulong arg1, abi_ulong arg2) return ret; } +/* pdgetpid(2) */ +static inline abi_long do_freebsd_pdgetpid(abi_long fd, abi_ulong target_pidp) +{ + abi_long ret; + pid_t pid; + + ret = get_errno(pdgetpid(fd, &pid)); + if (!is_error(ret)) { + if (put_user_u32(pid, target_pidp)) { + return -TARGET_EFAULT; + } + } + return ret; +} + +/* undocumented __setugid */ +static inline abi_long do_freebsd___setugid(abi_long arg1) +{ + return -TARGET_ENOSYS; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index d614409e69..99af0f6b15 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -383,6 +383,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_getloginclass(arg1, arg2); break; + case TARGET_FREEBSD_NR_pdgetpid: /* pdgetpid(2) */ + ret = do_freebsd_pdgetpid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR___setugid: /* undocumented */ + ret = do_freebsd___setugid(arg1); + break; + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ ret = do_bsd_utrace(arg1, arg2); break; From patchwork Sun Sep 24 21:01:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cYpjw2za; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6WL49Fzz1yng for ; Mon, 25 Sep 2023 12:38:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbTB-0003kM-15; Sun, 24 Sep 2023 22:37:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT8-0003fi-54 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:06 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT6-0000AB-Mn for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:05 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4053c6f1087so45543315e9.0 for ; Sun, 24 Sep 2023 19:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609423; x=1696214223; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ApAZc94aZDAcSIMEKeIK9l509Mfqm71ecKv5+mWNoME=; b=cYpjw2zaJ1/CVeW9Kb969Nx8ZBkXqRPuCrA5UgtSvoAvOAvmOZpVXQkPW/t+n+zuFJ P73oAukdMaT2blgqfLIpVuZ3V2l5NypRBBv3sM1lkkzJuoHOAeWYKyO9nQiEeqVMQVKK D4CorKXnxQXooqL9H4kz3vADHcWyp92PQUyaV3n256k9Kjt5OdKvUdXxr2KQC+KECogk Rw5e3tg1jrUrLkjblxZrmL5kjzV4eV/zir9umZXcKBaL5MZ5pWYLL1SyJ0+/M80crPkA 0HsOtC2ahUlxnjaExhPOuImrgSxc1F0Epgk/D5H6SROeQwcf5ihBQngK7E01VQQ7Rkbx NZcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609423; x=1696214223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ApAZc94aZDAcSIMEKeIK9l509Mfqm71ecKv5+mWNoME=; b=N4tvc/zPrHbH3KypvFvgQiDRL9RxNdgAPuK13ewNEHy/q8Q12lTcKikSYOTGbxq6Sm ptvvgOE7WUMfroxLamzMqflmdY9Q2diRQuObInxFLOKENUd4gmCk/Q9uqzLdsaRKraGt amrKmqUB68ah3eXx1b3Koqil329Mf/vs4isTfjcQSXv7O2q0c9Ex6LbwY1LtuxnyHk/J Fa0XQaloX13BqHmWn1NL5GEO9MaI3nOMDE6CmXOOjAERIesUvGFevcQWmx2YRq+wbErm shuBaacePQz2gFiIUOBN26qsQQbZ6jFApEhxGzd080vsOiRAxKCXgNR5vUwviKebGnrH cUUw== X-Gm-Message-State: AOJu0YwDuAMo90UdtM1oSLQlYzR+RiSk9AAZUBO3x/aKKuhkpTMAUOps T9NwI3mWohU/TO+3PULOFHlRjNUvqFA= X-Google-Smtp-Source: AGHT+IG5D1I3wdq9PU6/gcEpbemyqpBgzbYNBEsZCz9g2C/uKM1Dpm06hxBQ2+uwFyxZH/xYDCV8YQ== X-Received: by 2002:adf:f4ca:0:b0:31a:dc58:cdd9 with SMTP id h10-20020adff4ca000000b0031adc58cdd9mr3843686wrp.60.1695609423098; Sun, 24 Sep 2023 19:37:03 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:37:02 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 26/28] bsd-user: Implement fork(2) and vfork(2) system calls. Date: Mon, 25 Sep 2023 00:01:34 +0300 Message-ID: <20230924210136.11966-27-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 34 ++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 42bdd61904..7b2e6a9f79 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -185,4 +185,38 @@ static inline abi_long do_freebsd___setugid(abi_long arg1) return -TARGET_ENOSYS; } +/* fork(2) */ +static inline abi_long do_freebsd_fork(void *cpu_env) +{ + abi_long ret; + abi_ulong child_flag; + + fork_start(); + ret = fork(); + if (ret == 0) { + /* child */ + child_flag = 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag = 0; + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + + fork_end(child_flag); + + return ret; +} + +/* vfork(2) */ +static inline abi_long do_freebsd_vfork(void *cpu_env) +{ + return do_freebsd_fork(cpu_env); +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 99af0f6b15..cb9425c9ba 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -226,6 +226,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, /* * process system calls */ + case TARGET_FREEBSD_NR_fork: /* fork(2) */ + ret = do_freebsd_fork(cpu_env); + break; + + case TARGET_FREEBSD_NR_vfork: /* vfork(2) */ + ret = do_freebsd_vfork(cpu_env); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret = do_freebsd_execve(arg1, arg2, arg3); break; From patchwork Sun Sep 24 21:01:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GQue1tV6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Y51w20z1ynX for ; Mon, 25 Sep 2023 12:40:09 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbTA-0003k7-IA; Sun, 24 Sep 2023 22:37:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbT9-0003jd-Vo for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:07 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT8-0000AR-CJ for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:07 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40537481094so52885515e9.0 for ; Sun, 24 Sep 2023 19:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609424; x=1696214224; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rpy9YRc98hoKi4x0RvdoeeuQK0Rj8grNwDEdhtMUgjI=; b=GQue1tV61go6bCXqi2Zt1Sl2QxQqEr4sb6yZlWwXM4YkJumPfIiapbY7QdAFB/2f/z 0Sl8L7RSsagH1jWdvvV1tyllzyHY+0k/jKUQtCMO9wSvCULf7GUwv/WUorbU/OSV9jBQ U/FcEnJ9/ugU324u4HZa1etbRM72Q7bimY5Ei+1jhGr1MHDzmq5CsVbZI5bumCidLuuL etjpN7TOsQ3npn/fd1DA05W1p8m33zCMpuJJ2qEUCHW+0EAAzim59LYPkqDj3KwaMGDQ 2BQOc1vfLc7yvok9EQ8X7UMtMX8QXHEbhxZ18WzjO8K356m8FXcc9350j0dIorGXyh6t lq3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609424; x=1696214224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rpy9YRc98hoKi4x0RvdoeeuQK0Rj8grNwDEdhtMUgjI=; b=VkbN+cLwAXgdZzIVmSAjfyK4rlpDaGyqI8k5S78ezpc32l5lKH/x4qa/jNfgQggsBR a6M/Hpp4VUVzrHFOJGUflS+ajtGuo86o0SUzjT0NCQ7ViSyW/8WsIEPFPDLuLEDyx2Lx k87/iGHghgRmfbtbs1U3T7aIOczo0dBI+QBBuvzwpkAm/3ff9NSorZSsncRK1M+Mlm/j co17iwg+1PxIUXiKc2RL5QfKaxdOPle5UXas+YamqbYIILQtXpABq1qdf812kz3IRLC+ VhPiXtKsdWuTO+msBPebjSIMxZlw38EwHwcfpqiDrs0ojNrkBHgSuBEe1oMiwyUeck/F DJgA== X-Gm-Message-State: AOJu0Yy56Ps+pdyiTPJ89ME39eooyb79ERgQjMnDDUwyrVLhBPlLa51Z jSABxilYKimrfAV50nd0BoRI9wHm1FA= X-Google-Smtp-Source: AGHT+IGuVKAWA5+XWJwOGJG040wQDnU/LIM3Jjfq4O1hzAtH2ZgUv8LcwYn1iSmNbnA6n0lqgwLVuA== X-Received: by 2002:adf:ed43:0:b0:31f:a25d:e9a with SMTP id u3-20020adfed43000000b0031fa25d0e9amr4638693wro.46.1695609424451; Sun, 24 Sep 2023 19:37:04 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:37:04 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 27/28] bsd-user: Implement rfork(2) system call. Date: Mon, 25 Sep 2023 00:01:35 +0300 Message-ID: <20230924210136.11966-28-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x335.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 39 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 7b2e6a9f79..0a3cd0ef57 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -219,4 +219,43 @@ static inline abi_long do_freebsd_vfork(void *cpu_env) return do_freebsd_fork(cpu_env); } +/* rfork(2) */ +static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) +{ + abi_long ret; + abi_ulong child_flag; + + /* + * XXX We need to handle RFMEM here, as well. Neither are safe to execute + * as-is on x86 hosts because they'll split memory but not the stack, + * wreaking havoc on host architectures that use the stack to store the + * return address as both threads try to pop it off. Rejecting RFSPAWN + * entirely for now is ok, the only consumer at the moment is posix_spawn + * and it will fall back to classic vfork(2) if we return EINVAL. + */ + if ((flags & TARGET_RFSPAWN) != 0) { + return -TARGET_EINVAL; + } + fork_start(); + ret = rfork(flags); + if (ret == 0) { + /* child */ + child_flag = 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag = 0; + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + fork_end(child_flag); + + return ret; + +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index cb9425c9ba..4c4e773d1d 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -234,6 +234,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_vfork(cpu_env); break; + case TARGET_FREEBSD_NR_rfork: /* rfork(2) */ + ret = do_freebsd_rfork(cpu_env, arg1); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret = do_freebsd_execve(arg1, arg2, arg3); break; From patchwork Sun Sep 24 21:01:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1838843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iSWxHcAI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rv6Xn0G61z1yng for ; Mon, 25 Sep 2023 12:39:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkbTE-0003tZ-6m; Sun, 24 Sep 2023 22:37:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkbTA-0003kB-Mq for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:08 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkbT9-0000Ac-62 for qemu-devel@nongnu.org; Sun, 24 Sep 2023 22:37:08 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31ff985e292so5152700f8f.1 for ; Sun, 24 Sep 2023 19:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609425; x=1696214225; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EEpfVHQYJiHs/o3VXa4xKMUM5FKYuciwQMorXR+KT/8=; b=iSWxHcAIRYVBIgdbR5aH41IDO59L7utiP/XJ3u8Wy0eq0oevnCEia0rDrjbLWgOHum q7cqVO9SX1vfA8+N6H3SqoxWBSUlXAsjmDIbGEWOW6oBfX5WkP7/QvtRGa3deUI4ugfV qCdQ8E9zfXtJJmW5FNur3hr4JMc2RfRpVbmDo+T8l8hAESTqEwaXVsLIimBHVNtF1jzR Wwk4d/1vCSM1fFi8J0+wj9t9vhsvw03+8FwEtDq5muU5yNeTwrYr70AfVAwA8rcVs6wA Eq5ZJfqt8FFJ3qArxS5vcxFHP6SieahBgMuHnzQ4llbsHiJ9Rxq8sSQvltbKNUhah+j+ oSkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609425; x=1696214225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EEpfVHQYJiHs/o3VXa4xKMUM5FKYuciwQMorXR+KT/8=; b=sNlGbXsQYy+5A8u1I4zXUG4HDjAyi5SqSAqTJXt0voZ1ZvjAODiF0onc/DyTkktKtj k0deHkgX01pakXc4K1i8NOXBIuE1z5PVuyjci2tT1yJUsSK9gRXhRJX7LBvSICunANqt 33ZrSiiOvVu4QIrFHWNbIhiSKC+is1HpCaQNEwisMxlVD2pRSBFhSfDgoPIGyZ8M3fmy k42lkIozVw4NGcq08JbyFwQOJ9jmF4ex4C8Q6qowvrvmiAmWtp3Cshbe/uDJDn2UFBd9 oP7sAFJk8eePJ6uITsBKUUTVVLiXC938l2z3HsbvEbC4bsp4KE0xqDBR4Gby2jsyeY48 zTRQ== X-Gm-Message-State: AOJu0YyP63O+eWeyoncinBzI7dCnJgYUeI+muuWh44xoz327DZCneFPn 3GLUI4/32xpZ3zRI6c6Df36dSJkU0DM= X-Google-Smtp-Source: AGHT+IFsC63pJBepY4CjQ7kqGZsNvkxk8CkBncfJHqnk0ltvZ03W2j8c9clsyXn1fJFYVSNZZ8fGvw== X-Received: by 2002:adf:ec41:0:b0:319:67ac:4191 with SMTP id w1-20020adfec41000000b0031967ac4191mr4558157wrn.37.1695609425578; Sun, 24 Sep 2023 19:37:05 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id s28-20020adfa29c000000b003232f167df5sm1683wra.108.2023.09.24.19.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:37:05 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , Warner Losh , Stacey Son , Karim Taha Subject: [PATCH v4 28/28] bsd-user: Implement pdfork(2) system call. Date: Mon, 25 Sep 2023 00:01:36 +0300 Message-ID: <20230924210136.11966-29-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924210136.11966-1-kariem.taha2.7@gmail.com> References: <20230924210136.11966-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Acked-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/freebsd/os-proc.h | 32 ++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 0a3cd0ef57..d641878034 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -258,4 +258,36 @@ static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) } +/* pdfork(2) */ +static inline abi_long do_freebsd_pdfork(void *cpu_env, abi_ulong target_fdp, + abi_long flags) +{ + abi_long ret; + abi_ulong child_flag; + int fd; + + fork_start(); + ret = pdfork(&fd, flags); + if (ret == 0) { + /* child */ + child_flag = 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag = 0; + if (put_user_s32(fd, target_fdp)) { + return -TARGET_EFAULT; + } + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + fork_end(child_flag); + + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 4c4e773d1d..d04712f0a7 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -238,6 +238,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_rfork(cpu_env, arg1); break; + case TARGET_FREEBSD_NR_pdfork: /* pdfork(2) */ + ret = do_freebsd_pdfork(cpu_env, arg1, arg2); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret = do_freebsd_execve(arg1, arg2, arg3); break;