From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666419; cv=none; d=zohomail.com; s=zohoarc; b=h5VIBuaENrtmsK7YYRHqRLVl7wqbfRol3RK6kXbNlC1zyTSCWOMnubqDYmSqhvVCMtihHhGt0IiQor6obrX7nq8xLOpPoG3Zrkrf4siDZnp3L2Goe5zMN1NnT8Vaya65WRtiwpwSmrl0ZM/1v15TkY9NR/0Cb3E1NilXPih5zmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666419; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/0hUnJo62FgJTQIoivO6Goxg3C9ame5/C7KEuYom5hs=; b=gu8ArAJpsJb9cOJCzxiSZwfVEyf/eMFp8LtyEFZqi1fo7n8wQjhMHNsvnVPpygLJ2run+f6Dv5q5gCXSR1Xo9TKZdEuuMFD1e7xMba0WbBgIf5aoOsNvEkpxq6FJQEURStjYsrlgvADFW1xaU5F5eEJa2zkCllf2DofsC2y2s6M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666419676803.9300576518536; Mon, 25 Sep 2023 11:26:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHN-0001Ae-KS; Mon, 25 Sep 2023 14:25:57 -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 1qkqHL-0001A6-W0 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:25:56 -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 1qkqHK-0007Gn-F5 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:25:55 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4050bd2e33aso74587445e9.2 for ; Mon, 25 Sep 2023 11:25:54 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666352; x=1696271152; 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=PBHuGV66nfz0fj9FWWLCu6BrIfiak8Eqz9TfPmJkD6zCVkx9rOQt7463KjRv++B6gT B/UtirkVg85/ClpA46kS8UXgzV4ZfySNuTiVoQweaB1jK3LLI23XNb0bkd7ADFTJ2ejO 5lzvpp1kFB2jbUT36B92W6gA6g8RwQDev5uiuiQ9eXmwWHNWObwN79sqVYmLTFn83PLJ q1trLHUEZnStxAR6iGrkQ7JGxpb1x/zSGXr98BlMRHi6iIDyKWecL2lIOcYU6jGRAUaV 4bqYcVk/3LHXodzJyyNhw1LjzhJh4OfKWYlTTg/dVYZgmgRfymcE3UnQkw944oNLX2Uv BNXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666352; x=1696271152; 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=c6ylXrblu7DlTyggJ5GeqT8HfzCHONCsaEmZ9nBJZt9xSpQO4MYCp0MoTEkxu8Gm1l a4QIdqD+d5BNeNsFhXFQWYU4UK0Sfp2zUsquNY/5nPIfdGjOOVdMoLuvHe62rS9k6hlA OZvzFO+GHmHPEbKuzzL1Ukql6SrBNIHhpL79nxJArJdDiNzzE2IKeADidBBFDzziP9mz Vy4xEJEds3IOJ0XlxooyrPmEHJjj85/AOAVpvgVn4SxyksME9/EPuvFfnD2u91RIzr7f P4KoEXx1tuHOvSgm7LQkBCtsD/Nq005sAB+MNZOMZDax+rCE9pBAKLLkJ9wJRYzmyws3 hJuw== X-Gm-Message-State: AOJu0Yz5+Iy/AIVUnZ6ByyGGfwrUwKCoKpZlYS/vB+GaOuDvn2JvZQUq xP+MbWYjhAd7Zpz3jPUUg8SWocn5m34= X-Google-Smtp-Source: AGHT+IEHFGl3EuVwc6545wJGi3uDerdAeUvStxKp6aWavQ4UXzh0Aes+utTNZGNY45A6SHI+VBXn/A== X-Received: by 2002:a05:600c:1913:b0:405:95ae:4a94 with SMTP id j19-20020a05600c191300b0040595ae4a94mr1898001wmq.5.1695666352422; Mon, 25 Sep 2023 11:25:52 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Karim Taha , Kyle Evans Subject: [PATCH v5 01/28] bsd-user: define TARGET_RFSPAWN for rfork to use vfork(2) semantics, and fix RLIM_INFINITY Date: Mon, 25 Sep 2023 21:23:58 +0300 Message-ID: <20230925182425.3163-2-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666420370100005 Content-Type: text/plain; charset="utf-8" RLIM_INFINITY on FreeBSD, OpenBSD and NetBSD has value of ~(1<<63), caculat= ed 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 =20 #define TARGET_RLIMIT_CPU 0 #define TARGET_RLIMIT_FSIZE 1 @@ -390,6 +386,10 @@ struct target_freebsd_flock { int32_t l_sysid; } QEMU_PACKED; =20 +/* sys/unistd.h */ +/* user: vfork(2) semantics, clear signals */ +#define TARGET_RFSPAWN (1U << 31) + #define safe_syscall0(type, name) \ type safe_##name(void) \ { \ --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666714; cv=none; d=zohomail.com; s=zohoarc; b=I22w9jQMuD1q9Bc5Er4ntZ/v7D5wrYxOGkWoNjXHuE6f07NLL+Sd3uRlYM8Req+DGBZ5I5To1+K5vmTOOmzUsa4cMZMFEIg2tdPB+/sWhAhHSVD3ExHLG0dxpLtRFM8AZjVNCgNawd103Ua4lP/pVJysPYJlMupUpPa2GUozguI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hPIs14X11Sc9cA1eWwig5Uq4t5+72rZFcQQRqTUVNMo=; b=Adz5MgWEYv4ViCiABUXQnYxF+hsIEsfMeJ3ZrrdVB8iQm10eb03slW2DDZCFAdD8Hy8oChdHLaM+z2i6t592pAZLgHVdhfxM7imdAmH4hDrSkhCp1MA3YzFVHiIkzsbKjLs72VeGa8pwi7H6VXjskOeXFOey8+eNH1xAS5ld1OU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666714683661.664233625718; Mon, 25 Sep 2023 11:31:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHP-0001BP-Io; Mon, 25 Sep 2023 14:25: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 1qkqHO-0001Ah-2j for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:25:58 -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 1qkqHM-0007H0-H3 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:25:57 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-405e48d8cfdso6905605e9.2 for ; Mon, 25 Sep 2023 11:25:55 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666354; x=1696271154; 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=aowcC+kE0faKWr4uhl5V/TL7TPP/M2wIcO7XUwYEfT3ARhDnVk663oPKv0ew1GLXv2 dyfY973F60uV8AOYkcMsKsDUX5ecQYZogVlDHhD5y+Xh0hKZ+YrLhpJypGrJy3wK6OHq PJCUm+dm0rOnoA3cVNxdBbHWXxXGsbmbP6kLs0C7Ry4O2lHvPgKMGEgav9Dl2QVs8yL3 gfUnR9gsnHPFPI5w6ofxh7Cwj6F6/uLNJaLtHuaSwJnzlOwlhc08r11vYS+PJR3VBOQY x4zeAcvLKAOB0AWVoFIMym+DLpUIP0K8Q2WYHtkmCJFb7uVpnRzWnb57YQRpDbxslp6c +/Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666354; x=1696271154; 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=JQVUwFBsxp2sl/lymHzszh0fsU2817XXbAmDaXWYP6nfXfywVmqeZfodq1tYSkPryj rlAqes1gbDBvbynGRp4LKspfEzo/O3rg12WIYmWk3qUHP4s7Nr+6Wi9LFvJm9n+KHofF GlSFItsaeDdQZ7Gg/jhb9S6QOJE+G4Uo4LgPZand8k9jxrAk1iQti9D596Lr9TwceDB5 /ZtBGMMkTQ3UilL+Hg1scpCnRDMwZ13v9d1fLfK8ehDux8XgG13U4sxgJBamQfYHRKd/ fsOT9X6jbLp1xnH1/MAGsUyJi5jC2Wr79W8SXBXUPoAdCcWSCgRBKq/IIqTu9EMwEsrh /esg== X-Gm-Message-State: AOJu0YyOA4C2BKwJTAUqSdDtOEMh/4B37XQhTGMMRwD6rwLBSTQCh5q2 zq2g/XWoGcSdHDQ4b+PRort3Ne2VBBM= X-Google-Smtp-Source: AGHT+IGfgItIOmJ1GmcEKAc51IZvOYe9j7c2i/enI3ASHpjyheRmKUs79Ni+LXMQJuArMJOXR/K9Gw== X-Received: by 2002:a05:600c:1c02:b0:405:7400:1e42 with SMTP id j2-20020a05600c1c0200b0040574001e42mr5089270wms.41.1695666353997; Mon, 25 Sep 2023 11:25:53 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 02/28] bsd-user: Define procctl(2) related structs Date: Mon, 25 Sep 2023 21:23:59 +0300 Message-ID: <20230925182425.3163-3-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666716366100005 Content-Type: text/plain; charset="utf-8" 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) =20 +/* + * 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) \ { \ --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666838; cv=none; d=zohomail.com; s=zohoarc; b=M3fB5UpCCjSqckjy/521MD+wk67jx3rDAWm/rlTZGk+6t2AEheIU6UOn3qo8w/prnm80teGU7YO9f3XI6OmhafTQrXUOsRCuaOrBtN59q6vvYC5cOGbyy0WZ9u8qn/J+F1WVHJZrCEqeivCxlfQrW43+ChM+KQWQNZ0AX3VudoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666838; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v5fw6mGlVPzW+jBOcRjzUpsuKGCpM/DW3RHR4RG7BrI=; b=JjrHcI/gx3L1IqUcrsd6LGG2m/+4MAkmkKpQiE+p78XwCdi8FeSTqdeE/Hy9+381onT51d79H6BIZn8nAR1EFGrnW6yyap19IwkN/WOmAdSB9WCfOcSEwyzi+KtKyjfcpuZQEDeW9cbu5jNtxNL54CMS8pVRzsQslzPqGkgc5qc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666838023160.0615085229971; Mon, 25 Sep 2023 11:33:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHR-0001Bu-De; Mon, 25 Sep 2023 14:26: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 1qkqHP-0001B3-Le for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:25:59 -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 1qkqHN-0007HH-3l for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:25:58 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-404314388ceso76762505e9.2 for ; Mon, 25 Sep 2023 11:25:56 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666355; x=1696271155; 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=BKWWWCUGVZYNf/kNl1OOgR9yM9d0l1SpyvXg7XsVz7QezRZe1OuhlaFsVqrh3BqshG 4dNs/HcSj5/Tw3NwtuB6ypGfcy7GoZ156dpbkIno9uAlyTIlrk60k4Dof1pBMdC8gK5N 4KbZtt3b2h6PwulaZRgkav0WWcJKbJ/XPTD+vFp2ulXroCtzh5z2Pj3Yi5C0edaR9MHE OKyEVNUDuljom/nu8WY8DX5RyPxmFJbKtNam3RUgkcQBmSWU4g2C8qEgCaF4szSDzc+v 81sdain4wD0/bUwYvrT1t2761U6PePM7IqyWErfRdFhOhfPablyIXCbaYCA3OkElYsHw ohNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666355; x=1696271155; 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=djrihBhZnak0leD0Q+4IQFV61VQwLgP4SLenrlm71v1+RsXmtX2AKa/CiDMfYHz6NL GDfvdCvMfhcnMjp7uhWJnjO+jRMwlqChQg7yLXoN6LLIXTe+3JydqPSP0Pa4MJ4rk437 jG8apSqFrxycoeKRHS00xTqBZTkDO79Q1rs6sCEhraWRFFq0S+EJDYoAD9XbuIRcU1zl qfDzdXd9J5z9WbNemwPTtDexXJJ5uVXymDF0cHPrLKPgS0srKV0fXbc+7ky/pf/bRbzY FXXc5IQD2rJDxgIs5iLWhBjjuc0dGi991EwLedqmNWagcPSvLUWxS9Ni0Ldw0bw9Aw41 W09w== X-Gm-Message-State: AOJu0YxDqSTxmiYXr2/H8pBkf2u86In+eD/JRisODSRlaW+S49GKVNGc mbivQrUNpXHJs0xBbbvaufYUnwrs7yo= X-Google-Smtp-Source: AGHT+IEvddGE7Z2lkWHbNfrQSnA3k+5qYjWQqJbVADTJIWA+XSiCbwtRHuRMa+dhFp7hVa8NI9ta9A== X-Received: by 2002:a7b:ce92:0:b0:405:39b4:314f with SMTP id q18-20020a7bce92000000b0040539b4314fmr7193984wmj.24.1695666355238; Mon, 25 Sep 2023 11:25:55 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 03/28] bsd-user: Implement host_to_target_siginfo. Date: Mon, 25 Sep 2023 21:24:00 +0300 Message-ID: <20230925182425.3163-4-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666840012100003 Content-Type: text/plain; charset="utf-8" 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, con= st target_siginfo_t *info) } } =20 +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 =3D (TaskState *)thread_cpu->opaque; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666464; cv=none; d=zohomail.com; s=zohoarc; b=Yl8bSPQjWnCbclfhSrhARNpVcZS7ZnHXCrFx8kSV48yFihxIbABDb/KRyHZn9kw6g57au/DX3r9vnegg36CgL1Nw32v21bfm9JqyFdor6quXUjQxmcNN1HUVSK1/TJpFO/k1vyYtgIrrG8MsD8mMyCly4izv4YJ9AR6WnZwEvys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666464; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gtr4AZcHHxXXmu6rDPP2dwqMNgqNWW0hP+jIdi1BnOc=; b=DtMUO196x7A8chKzjjt5M2/Dw5lLDkoXBK3gf7QGYMzttS9nCagsE2bu0HQfp5gEPJOO1tsRaUStbO6DYa8rxijzKrw6CFHWA3JZSGSTgqDVV7+n5niBE6WQzJ2qyMdwUwVdVXYAB9Rsm2nua5v0xM6ygptX0ZlRWNFHpk1ebzg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666464766879.3027012381939; Mon, 25 Sep 2023 11:27:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHY-0001GJ-Bc; Mon, 25 Sep 2023 14:26: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 1qkqHT-0001Cg-CC for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:03 -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 1qkqHO-0007HO-AY for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:03 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40572aeb6d0so35482595e9.1 for ; Mon, 25 Sep 2023 11:25:57 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666356; x=1696271156; 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=j9B6hG6qi+qaMPpqu6MGAxaaLprEw5afbtaMPug3tcB3Q6hCzLLZHePlNL96SNreVe savVbVVLtJawpvFl39/6tthLD0a5B02ecrX8GhRKAbEgtgAwHYLfd5NcWiji5wxR8yKj 6rzEn/e8jMKs+sSp/npNAhl7i5lqUJ0p6LbAucBpl9cLi35zmiRpKszNN3VJsOdbZOhr y63A5ss/rH3GdSZdHFeZXxa55j7WD0wxRWmrSJ5Jkq79zNcnyz1i8FsMq9nSvoD22FHF scej8lFF6hvdY8MvIOgv5kBUpMB/F0rDrDcVcQJu1E1njKcBBY+x3T8S2JOs3TlVt8Hx Pm9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666356; x=1696271156; 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=XELmzJDwkXMyPbSyytoW4mTi+vreqqViZW72IDZyHmECduj9z4RhQh2QNU9C7nS3rR 852YGuZejl+HDnYD/lmaOec/1Bs+df0PSwXyVGI2oMsrA6x8jSRi7T263lHD8ksYwH9y lHDJ5LK9DRKitbtpHvEKcuWPZuLaKl77hPKF3eMOyJYYrf/jUIUO6CjWomEJ7j3Snbpo ZAHifgSjB2S1HQd63EXuvDSzwYU5toCoY3XQuJU1zImDDtSQXgmycMHkt0bXiTJAl2Mu wzVvd35CIAXj/xrVpCH5lnA7TToSb6pr1OPpD3cLa1hHAVW335UHhRweZe+9XvEsWeE0 BdcA== X-Gm-Message-State: AOJu0Yxn4qBie00MXMVAIp1HKJqV33x1/tLs1v8fyzLnDHprhmBjKnW4 vKrtvwjjWGSo5bUwjzyxw05DA7jemLg= X-Google-Smtp-Source: AGHT+IE5f7q5rBCBufMF0L41T+vobyWXvQa2+BGFjrwUNc7leNB6idDWz/Nf61ttjC0zfMgeiDgQCQ== X-Received: by 2002:a05:600c:22d8:b0:3fb:b3aa:1c8a with SMTP id 24-20020a05600c22d800b003fbb3aa1c8amr6027292wmg.16.1695666356506; Mon, 25 Sep 2023 11:25:56 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 04/28] bsd-user: Add freebsd_exec_common and do_freebsd_procctl to qemu.h. Date: Mon, 25 Sep 2023 21:24:01 +0300 Message-ID: <20230925182425.3163-5-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666466324100003 Content-Type: text/plain; charset="utf-8" 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); =20 +/* 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 nam= elen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newle= n); --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666839; cv=none; d=zohomail.com; s=zohoarc; b=PVRH0+Cee/BD+dLWnbrpu6WSWF5V/2BCTX10ZHOcJ/jtoe1NOCX6+7bvh2vQaywPKUbyMchZJqqQ19ONBkzT+DZgsZnIjnINxYkRmn/185Rrav9srbAYynW16v7WHIDuo5giMBg6W7mA+xuACXMxrFbU/VGcpsCxezIs+IryqI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666839; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8NgIQuhS1pWjXF2WQJZ+g0h0EHjHQYwR2fjodfnfROY=; b=OSYyx7W50x51w/drPSDIiGbAqathSxEu2hH2uRC6ptiTWMQoGrcph1Q00ztwxfzlevsreW65qVb6cTzcG5mbuDAjF92GgjRhzkGcPf3mRovAeyAvxsf2zV1W73gyCl7gak9g2sJloPGImN0aSfVF9opBABUZtfLF/jFPqr6TU98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666839547181.94543273769432; Mon, 25 Sep 2023 11:33:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHV-0001Dn-8F; Mon, 25 Sep 2023 14:26: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 1qkqHS-0001CJ-Qz for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:02 -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 1qkqHP-0007Hd-Sj for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:02 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4054496bde3so53072745e9.1 for ; Mon, 25 Sep 2023 11:25:59 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666358; x=1696271158; 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=HaHy4kgnI5RQBZInNMicEXkHMpj/04PyhUEWMRziMJueRTtifBVrd80Sca29e6eX8l CfEi+cReHOodSLceH0ghpMOcSgCyhxSC/ajMmw4rZX5qqt3SpIh7nMX7ZaIRQjLWMHVP +wZ1zyWFBWJOlNRHAv6uCaHMx6shY3Fqx28aCTpDeGGjRczk/fVMyc+RoZGmGAfDQMmH v/gjbJii36z6NdHgJALwIoGqbsuLn1GiQBAuSCoChUPJMMjYaq4pXXQpiN0puznIU2K+ /1DNpeFq2yYDjHKPPM8bPLeWzXjcUNy6oEJ3/1IKmkNQFdI6QpyQhE3RB7gOPPMuI61/ Gr6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666358; x=1696271158; 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=bV1aEc94lTYwu8Vm3imbKnuR38n+Q5D02cFziPdE7Cmkeuz9DitVNz4VmCWFhBgi91 9Uh+WSBnenGqqRBhIXeVLr6eoxdSb3/v78xdyAYLGOhK5xSXaCXb6JZuQEwXW1jMK/WR V0C3mYfU8LimIFVwQst1lFbt5qGlII6TsTwVIZf1+Z38VTHVmEEqBviqIjkrEQwA2457 5E+zEeWMETEGfzY1fuo9P36k97RzoNCbFXukXUj+yx+fGIqrmEeh1i1doijv39dVWVqo /DGwNxriYCyZF5RvTDbruM4speZBM/52D8nd/vbR5Pm1VCcNnDHsmeSP6GpFDpN5EbC2 mmrg== X-Gm-Message-State: AOJu0YxLWSYxt76XBravKQ4CkhV7aVoji/B0BQkXne8by0lq/BREx8pN 8UN3FBjtUXrtcU5HCX+AARY8/cuMT2k= X-Google-Smtp-Source: AGHT+IHRyj/YD2I3GFwx2hw34y/o9RgqA2T75SICF+xjNWSla6Bj6PAFBd06/MAcuepCRPcoXSudCg== X-Received: by 2002:a7b:c390:0:b0:402:f07c:4b48 with SMTP id s16-20020a7bc390000000b00402f07c4b48mr6283145wmj.28.1695666357683; Mon, 25 Sep 2023 11:25:57 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 05/28] bsd-user: add extern declarations for bsd-proc.c conversion functions Date: Mon, 25 Sep 2023 21:24:02 +0300 Message-ID: <20230925182425.3163-6-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666840045100005 Content-Type: text/plain; charset="utf-8" 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 */ --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666530; cv=none; d=zohomail.com; s=zohoarc; b=IBwGXR/F5TjiL+u2h2tf7xDQjT0oJpasZl/jnlBvbH6RR+6rH/2OQPnM9iroY7JmxbDW51tWLHU7lZaaEl5lGbPOKDv7WnMKqEu7nW0sG/GPEzkAoBTFvEPiUOZAjuJJurCErFsVvwBD0JrybhwsSwpvNMtvI/cXpJrKazqvSCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666530; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B0jw18nchCfPvc4qF6WttckGZZQd4GL3KWtYznFJQBA=; b=KTLO3U7aDfrF5vHVWNVCZbKA/B8vtA7k1sAJAR8Wo7Pn+BPgrfc5iMcjLmEs/y4QG8OHjOQ5MI1dInansfV23xlF/+od67c5Ow+h53tolGWNBAj1/GM4wEC003OPGV7WEtlMmzAzAnhtM+vklBH7rQYIm1jhnDG0MWbaSIzlUik= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666530292914.0677137357193; Mon, 25 Sep 2023 11:28:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHU-0001DG-7w; Mon, 25 Sep 2023 14:26:04 -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 1qkqHT-0001Ch-CN for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:03 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHR-0007Hk-7d for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:03 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4050bd2e33aso74588535e9.2 for ; Mon, 25 Sep 2023 11:26:00 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666359; x=1696271159; 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=B0jw18nchCfPvc4qF6WttckGZZQd4GL3KWtYznFJQBA=; b=jT8+tmVBdypbP9RkFWeWTYJb4bEkMU0lSoOk2V9aQjzmRvi4uDrAUP9+b/aHzFa37u G3ljzdSXVe3lh3FwsXjKfcD+O91Nj9dFtQp5Sr0xtAw0UjMeS8GqjTnqNUUwISP5wTsu /HZPIzSq7edCaUd7U7Vts1QBWcnjKMeLI79Pb2qG6y6TZi95xyQyys6WqA9M9G6JVGPh FH5k9endt7II2g81pJJ2WiZ0S+W8GGuT9DS8tBHmkHtsyCUP7pjtX/cpoGuNns3ekG0U qZHXEPtYMhaxUt2hYQL3WjuEzhhwm6mtMBCeMTv5UvVcFNkjwxrNtikWodafhz4AoVmX N7Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666359; x=1696271159; 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=B0jw18nchCfPvc4qF6WttckGZZQd4GL3KWtYznFJQBA=; b=BaPLcM+sIxK2Wv/IewUJR0t8leakChE6gYz1iYbMhpWvNK3heb80EZ/S9aAdE8wxyZ Y4zxHI2zZ85DAg2sSZ7d8wPpNVj/k9ke5acitHO/hCUbpVn6ePTRdAIz+qTFtw6n6fGH qmG6OODUCRld4F54U26YdEZkOJ53JyuejQq+Vdwxxtz+yAtEOQjPVctNGAL/8n3s00uk X3G4P6FRWQ+osxGt18zb9qUGah3ZeNfVl+egWqsbKN12vyFU4StO/BVbd2FlkwvMFAEs 5drpxkHRIphmHCjUU23m10/Zp4fWrQC3wqDGn/SP7eohqtdABa6tugba8wGI5XDABLUx qepw== X-Gm-Message-State: AOJu0Yza2ezc6jvLBIHNpJsVovEJzXqrWNAb0zwh9so/Bdsy3nuTZzsI q/CM+QeXdGGl4EFnVNdk/6sxlTX0pKY= X-Google-Smtp-Source: AGHT+IG2zySgGPJHODQQlmwsXT1oXECJuOaVsm+u1A67WBKWYa8DYbHTo2AtfPw4FxnGRM5LDwU80g== X-Received: by 2002:a05:600c:3798:b0:402:f501:447c with SMTP id o24-20020a05600c379800b00402f501447cmr6605815wmr.0.1695666358962; Mon, 25 Sep 2023 11:25:58 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 06/28] bsd-user: Implement target_to_host_resource conversion function Date: Mon, 25 Sep 2023 21:24:03 +0300 Message-ID: <20230925182425.3163-7-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666531381100001 Content-Type: text/plain; charset="utf-8" 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 @@ =20 #include =20 +#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 =3D ss.source_set() common_user_inc +=3D include_directories('include') =20 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', )) =20 +elf =3D cc.find_library('elf', required: true) +procstat =3D cc.find_library('procstat', required: true) +kvm =3D cc.find_library('kvm', required: true) +bsd_user_ss.add(elf, procstat, kvm) + # Pull in the OS-specific build glue, if any subdir(targetos) =20 --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666446; cv=none; d=zohomail.com; s=zohoarc; b=C0ryrIWRATkvqFaFmtCRMZf20yH3S+Sk8yfSZfdidcmW0N2B/05OmFsn5XhXml3Bm0iVKeyt4zCJYgQjzIAmb6LHsgyCEyScNJBr+QVX8sjv35VTakPOE4hUZLMjumBCeuUzo+AL+Gaz+ctXZVuqOHn5Jkaj5XG0WvTLCtcIwQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666446; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aNQ9mDc3plWciIdjeE5Tzw1D9iur6gZpe1I8Oy7Sjl4=; b=CnBem7cL9Mj+wLKiO19PPpza9f17qxACitE/EH5KWCCFIbPwiBF4dhVgIPczoKNLIVJcaqKFfBwJVmL/o4A8Nnp9wbPK8ViiNGii93Po0qyub+f7JGhSCUzubghhASZQseQyk0cMt2b6sDjYMyluy0sAolVxsf69jwMEDklXg1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666445918925.1116258136934; Mon, 25 Sep 2023 11:27:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHZ-0001Go-0W; Mon, 25 Sep 2023 14:26: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 1qkqHU-0001DH-GP for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:04 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHS-0007Hq-Ue for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:04 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4053d53a1bfso58991595e9.1 for ; Mon, 25 Sep 2023 11:26:01 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666360; x=1696271160; 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=Gf2bO1uzD3KT+eUQ9B6HFxU2Mn8VHDdUHL1Uli9wGoFSZiivRGUgq3XORlLees9fUo y3sZvQwK0d7X7SFaddGCNAzAi2zO42T6wzKHxCWwVVuOIHI9qtGAmjNSAHiljR/doFAk N+xP86iavvQjyl3dD/i7atrW4E8wsdJptX/79ajXIlMdNwTw7vq2vRaOg+1326NvOlIH Zx+AHmiU/255fDW/trfpsWjo9ohpXV+7F0U6eI/hmDhqA36VWnB6fL37snbcNVRbTquH /iBQ3Gmx0nf6BDz6G3q2Paex9QiPBsPyREsS+rROp7KThEo5lpULLcbGL56YgMK6slO6 1bVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666360; x=1696271160; 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=VkPYwwMHrGsaAvhyizVj9W5sK2o669nLRXV0x5bKt+AI7h32blpuZBd2/ScAZG43a9 NBqjLWWrMNNEm9qj+WJBeC0SdCBtvLArtmdlCYGEkcRGLxCSXK6javiSsq5NuO8k6g8C s9KZziDwneHw3bKSRUIdvEfjS3WYa0gubjP9Eo2dpmG4M3+OSgljFr9hLtxEVMTKo7e7 BzhYD9AL3l2bMv/pAKgo8Vhdx3SJoc0/WaNW8xoZ519JySV+9xeGP8IzG3mGoSHHR8Vz 3F6rsX/lViJr0qg3FbPI9q1U1S8H8/gpEoXluKY3YyqBtgKClXB5eCpk/E84MAdFyFV6 3eDg== X-Gm-Message-State: AOJu0Yz9spUC+cZIDo0gjIJR75IbXRKZUfaG5XiRlXD1tZ82jWBzMon0 h5CjjSymmEh27GbsMNYJeP2quRIkAo4= X-Google-Smtp-Source: AGHT+IFjuQIzcg4wUE3ICcYayg/kGTtTJQtg2R2hA/jRT/TlNH2omTfumX3VjXutcpsN8zw0t6dJ/g== X-Received: by 2002:a05:600c:3b89:b0:405:9666:5242 with SMTP id n9-20020a05600c3b8900b0040596665242mr1264107wms.31.1695666360137; Mon, 25 Sep 2023 11:26:00 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 07/28] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion. Date: Mon, 25 Sep 2023 21:24:04 +0300 Message-ID: <20230925182425.3163-8-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666448061100003 Content-Type: text/plain; charset="utf-8" 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; } =20 +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); +} + --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666431; cv=none; d=zohomail.com; s=zohoarc; b=jZi6PENai0ohOeOOwcjLSYqg6SvZdOdTCY1xKyew1/YFiTvotJ+/Y+e2vqeA/1ZZiUMdCMwN/+ELI8C/wmXFf4F2Cla/Oaagu8Vj8fX+gH/FBNi86eVs2wgs00ivYdPW1xDmETefxahxbU4bllgk6Je+zigKQ0sfceOEY8+U0C4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666431; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iWYm7HyQrlRuQgYVJcs9dh5OBv161buo5dw6WbXP5iU=; b=fJ6ujOKGaHbpIpglEzjqk4xvEoqlgmG5UNJM2Zu7jP8Fl8tqC9J0NybtUWB0cTlsMQYXBo2pjmp7qx6t2bOXIB9UK1WTToFNS2K1skPFzkqj2JP3+hY4k+C/hYZQCvec2V6mHjo3LxGM++XbWGEY3JdIrM80/6Kd8qY/ILwPwQ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666431309838.0452150000367; Mon, 25 Sep 2023 11:27:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHX-0001GL-Rd; Mon, 25 Sep 2023 14:26: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 1qkqHV-0001F5-9B for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:05 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHT-0007Hz-HB for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:04 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4056ce55e7eso37816055e9.2 for ; Mon, 25 Sep 2023 11:26:03 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666361; x=1696271161; 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=bAVPsRk3hvfTGx+BFFVDgJYA1WsIjlxOXhyh8w0j3K0lBRn6T4psuqladH3iYGAgpr qDxFDzg+p42IRM1M/r8rd5gFirLN1BVDM6+//EQ+0qZ5bV5qJY45G7vvEX1CyVLsyx8p WRF6vNt31tVIA8VFY+XOHz0gPMh5JzOOeR51VJ+ay0JKEtGBujHe2+8bt5/j5xQXgGG6 dR5jzCv6wdNJjRBYiHX7PRvZwfyEhPcgrK7c5qH0WcHu0REcCXu5Tl4PaANlvPdwhfnv XOfMAH9Rnp3RDxaLcuEdkHDh0BqDLIVe2Hcxd5kQ/CJJMVm89TASjYk6vqrzExCyOXy6 sHfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666361; x=1696271161; 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=dM9qCSVs7t+Uq0B2/xPYCbmCQ0O4djmP5m1Xhm5rwFKxqal18LIGD3WlUmT/3CdKQe UY9f+EAEvvH3iCOnfq4GQ94IdTFlyqZ8ghW/HrT1L6A5OuDcU6nHk5Pv+r3beYGMsXHl bxCx1gV90zYePt2s7N47IUvfYfNdHlrEfLFhJl9fBihyL13brYuVjkt4akNDHdWWibns sNnX2mzVSP4ghrpxjV2AegHLqhw9nYnmCHXKtaJ9yhfdbMTU/SAzNS4ugCYc0iQAcNBD RIb7PQpDAzz7t36yYyGut/hK+DNRdR+PcvR7dS+ilCAgJcI/C0TzceFisOzTnAilcGlU 9hFQ== X-Gm-Message-State: AOJu0YyS6JIoYTKek/0AtfJ8wTNBAwVOUsVmrpiwiUURBDekKilBFMBc tYqhch4j2J21AKy7w6dqibrwTA4k9yg= X-Google-Smtp-Source: AGHT+IEE5GCtQvEyrJPaLKUMI1CdTSmHy4u4jm4w/1FGHXCrnXg15gDsHoJBsjGrs1BxwRSiAlMTxA== X-Received: by 2002:a7b:ce11:0:b0:3fe:1af6:6542 with SMTP id m17-20020a7bce11000000b003fe1af66542mr6630746wmc.33.1695666361282; Mon, 25 Sep 2023 11:26:01 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 08/28] bsd-user: Implement host_to_target_rusage and host_to_target_wrusage. Date: Mon, 25 Sep 2023 21:24:05 +0300 Message-ID: <20230925182425.3163-9-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666432073100003 Content-Type: text/plain; charset="utf-8" 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); } =20 +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; +} + --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666564; cv=none; d=zohomail.com; s=zohoarc; b=Km66UWHUPU8Vprz/s2Zje5JysJ/q5HJRB8/5jN1TOmfRGbBzXszSX+i9MuxU3R1VTQ80ZwIWRzC/5HVl3uew7geLiXPIn23tT1KYaZ6lJ8EkynbnELsIZgiVk2VaHLe5vl24VuHNhvw2apJO3mNv1j2HXdmXswWNi7tNSgxdw8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666564; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tBa86IcvJ8qZLQPEGuLU5XUlSMmhHoCVoEZs2NT+SAc=; b=JPk/eQOB58vR9sXhQQ+3oE1UKl+hxFM4DsgA/o4gPC5exyeT3uwToCL/NWuJun1wmzSqK7KsGz8NrL9uuhZjaiKtBrZAp+UPq76O8r/DHqcbRRKFFw5GO8i4q6abQM+CIXe0RcaXZUvxdVMS1zXzl4Efow8YDKrT/e42FYy8nN4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169566656465777.35086961482637; Mon, 25 Sep 2023 11:29:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHY-0001Gm-UA; Mon, 25 Sep 2023 14:26: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 1qkqHV-0001Fi-V0 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:05 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHU-0007IL-8y for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:05 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-405621baba7so41372255e9.0 for ; Mon, 25 Sep 2023 11:26:03 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666362; x=1696271162; 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=P1lent43JdfbHELfcAIjCDVFP7n45YP+ThabRZuCABz1ViZWi9K1cn67zKuSYB1rv8 pFvekM0+cMCRWHdVkfe4BPTJ/XY9qc72WYGbdOoLVzlZHx92gJuIbaK1O8t5Ou6nVLRh VEbfGovSumpbzQJvvONYxqI/SK2aZbe0yfJXpn8poNbAc5vsNdrHl/csh7YpYblr+TZi O1otSFirhIPX7f8IuXRtZVevYjXRpV3GkLLCx4z9paD9Z4RMcb+XGyELs6Lwv+uci3rX ndB9Kvu1R4+cP0RpFZuFFTOMjrPKxgFNLWGLCHbb0mYDqiWFuaWKZScTh3BEo/uAJelX XCwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666362; x=1696271162; 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=sglowUTYLDyOGgFqKe3i8CtQNv0ZUUJCZ9hvneTs7fnW7ZUY459/HEuZxcXPihLTlZ eT5fLblMOS4CcnlLGJhVpJmlW4UOfGAE+GIHjJOs+NvG6dhi4geNBpEIpG+/bLzvAWVX 26sl2ppo6Du2u0oZ3aLfwWRE+xcY9sjs7bgMQVi6SpgrVpcdF3xuHBFGDIw/50yP0jzm 8UNhFFwNfNd5NG/azaSTPacdDoTK/eEb9i4Tvykr3RYZYnmIHb9LH0YZ69XFxqHq4VTD kw/QBfnzkjP9CyCIa+kDkdHVZszWqOmxhmd8Mx3r6i8O1Uwc79bxZsowuQFL3MEin9cZ a1AQ== X-Gm-Message-State: AOJu0YwkYiccuggbhM80zTC6KOaP/DIgyXDFFUNCrjHztfKnQ2fzz3YH xpzKQsRObX72ufrnBho52RPtYImXK2Q= X-Google-Smtp-Source: AGHT+IHVIfblWPZvfzpxxWQGWDBvnbFzaL6cUaTrPAeABujGcZOxjoNpZfS808GmUM3Yen7/f7xhbQ== X-Received: by 2002:a05:600c:c1:b0:401:bdd7:49ae with SMTP id u1-20020a05600c00c100b00401bdd749aemr6497431wmm.18.1695666362501; Mon, 25 Sep 2023 11:26:02 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 09/28] bsd-user: Implement host_to_target_waitstatus conversion. Date: Mon, 25 Sep 2023 21:24:06 +0300 Message-ID: <20230925182425.3163-10-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666565411100019 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* + * 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; +} + --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666441; cv=none; d=zohomail.com; s=zohoarc; b=EGMN1KD57uJR9GOiOQ5QiDkmdShlivx9TTnMrB3wWwPtqGl8UW7b0g7WR9m+6jkWMUAyLRbnKmKx0HnN1pIwvQlriztqxMW4TugZxigLf8y1TaKV5YanYVk5pMvE1JhAe9/CgQ284A5yCfU8WTM0FpMYGYdnwGyvPTcV8W/uinE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666441; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C0Dqs0KOjTr5dCbbJ1YQtsQ7bJYAtc0s59yQIYeZ8Mk=; b=bVT3fsrOrVBV5Jtx+wOamuaO5dY9LSRyZG78htBTjPVUpj1OmyssHA7VFcMCcsGINkPoV6RdQRTY9rakK6qvBau7mbi8MoVrcWO0cs3+xokRYumcBs0jrRFhpe8aCDVxpt5K4XJqUwfrql+v80p+LTRzfkec7UIU+VBk/MM95uY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666441681264.43417142026135; Mon, 25 Sep 2023 11:27:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHb-0001IM-NY; Mon, 25 Sep 2023 14:26:11 -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 1qkqHZ-0001HA-EM for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:09 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHX-0007Ia-Sd for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:09 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4053c6f0e50so62761815e9.1 for ; Mon, 25 Sep 2023 11:26:06 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666364; x=1696271164; 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=lTDYqArZLdyXyfZYQe3FXOxA34H07wssWn4PmlhAqECN1yoCb1BWqqToDlLjJ64ECX QbraEsxMm/o5Dc2Q+ObaxcYywZrEvj3reTvR8YLR+Pp1GuWBOnq7Mux078qgERtZIMmI /kRSBNQWm4ArShWNFuwrsIbEjm9LQnSY/9UbjrEl4pV71XpvRsIbTd4mSEIOBDKwQ8db ZJuj7vC51CGdLIzkYYvUVAVuR6sFdDryM37yvAzWMDN/Z7x36PtQXXoNEyhNtSGRVqWF 3vcwzkdFwoN6K+TitNkkt2j8It796OVy3EQX66IZrlbcEjXJQmwcJeFd+CdctD0YgtdS H53w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666364; x=1696271164; 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=SXOLjRyWI3B1KyVlh16mReXB08XQSRQH8MWikkJuyIREgP2BALF6hIwkxM+BLsnj7e G9n6fQKAM4KsQfsM503qk0estQPYaLxV3sov2g0n2c5NHwi6+iZ7HMS79Wt2V91pqxZL Bbm6bWffo/IWalyLz8672NR2riE2AlwZW67hrNDcrcrExw81fgC7Qox9qsBxwVa4ALvU F86g3OJeFqBlxRFg3k4xRB/lRVFdPd4XxhY6bIxZF8P14qEPOCDCBW+Rky2nBsolkb7S wM4kTHxIuQR6/dGWKHoGQSQnyyoJTs8AsiF57B6O3e+8SMVktbuCRTp+h1N5WAkj6CkF 8yrA== X-Gm-Message-State: AOJu0YyNp2iG230sT6M/8JKVUqcWJb8vzMYk6S840gy7T0moDxu5phrO T2k8cAb33JD67spARnOvfaXMX5tEPOQ= X-Google-Smtp-Source: AGHT+IFZMzjPM3rHs/DlYhZ0cBn5NLYBLi00bWf9jZnW3sdrbfzUeQ86PRuW5IixW9i9dfJkpTg/VA== X-Received: by 2002:a7b:c416:0:b0:404:74e3:27a4 with SMTP id k22-20020a7bc416000000b0040474e327a4mr6504110wmi.40.1695666363746; Mon, 25 Sep 2023 11:26:03 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Kyle Evans , Karim Taha Subject: [PATCH v5 10/28] bsd-user: Get number of cpus. Date: Mon, 25 Sep 2023 21:24:07 +0300 Message-ID: <20230925182425.3163-11-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666442304100003 Content-Type: text/plain; charset="utf-8" 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; } =20 +int bsd_get_ncpu(void) +{ + int ncpu =3D -1; + cpuset_t mask; + + CPU_ZERO(&mask); + + if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask= ), + &mask) =3D=3D 0) { + ncpu =3D CPU_COUNT(&mask); + } + + if (ncpu =3D=3D -1) { + ncpu =3D sysconf(_SC_NPROCESSORS_ONLN); + } + + if (ncpu =3D=3D -1) { + gemu_log("XXX Missing bsd_get_ncpu() implementation\n"); + ncpu =3D 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" =20 +int bsd_get_ncpu(void); + /* exit(2) */ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) { --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666840; cv=none; d=zohomail.com; s=zohoarc; b=mcLxGKsG2YkSC6D1bmKYJWHJCqnAMiuP9DX1tOI1Hi0cNypUjhHt6zmGJVvC4IwrVngofODMbXMDzzNY3mk8FB2SAPDgvIu/7v4hac1Zb19X62RIzPjvcPU+w8nqaUNU8w4QGl+ZYwrdFFCf3XaFCtdjDEVQCC+B8G6YLLgDYwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666840; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c+y7I+dQizuXGTfyfswmuzENo8FjWt4FJ1ZjkqfWpTI=; b=Ibp+9/z9jF2BT5QKV4NAlps+42459UTkBAp4Yvk38JQx/yIbFdEQf6T7zu3cFYmShWV+vol9KVf/arjI8oK3dw6GF9f0FTDZYA2MyARy9ARrNQCtoZyrNR+Z1prjo6Lv7iWVTD/WjsUEsI13UWLe69e9vJeK9twafL+/1uGY78s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666840231464.2384318585956; Mon, 25 Sep 2023 11:34:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHc-0001IP-Fd; Mon, 25 Sep 2023 14:26: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 1qkqHa-0001HX-MR for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:10 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHY-0007Ip-SL for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:10 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4053cf48670so58188305e9.0 for ; Mon, 25 Sep 2023 11:26:06 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666365; x=1696271165; 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=Iy9+B+MYfJ74DNwS6RfHU2NigrfxaBUxxvR8YlbBbIXJEW+VL+e354sz06zWZ1hoRa xBnNzRGmydncDwXIgulfpizwClUs9pLH+8jfjta7n5DqaoKflKZwq7OihLlgOKo8UdSP f5LYObx6w3GKJOsR202wJ5BttTCOgT2PAMKOW0xAjgWpt3a/9n8UNbclZzsWkD3VaKUe d8CbKxliIkl88mr5aLG0xsAFhfwlBVhAkyk9L6s+gqIc6KVJS132F/O0Q8SIUCv2gB5d Khu1UtIlmRW2uEgec1i77SnytSAF194QzZu0DGqCIWikQVVeuPXiGgnYRUox7lEv6Cjo UnOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666365; x=1696271165; 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=F4xaaVNUKa90J8KQLclgt1+4AyR/hgHVffVLnVqtAvKHEwONXcqRnmDIXSKoiUVNy3 UQJosuyu5ox+6b4H0x83ZU0+KUXayge2whDl7v7g7pUp+waDlQ2u6o9kttPDYQfzrD9T a7CUwFsSXj9HPta71SKV+KOjrwoAOVYY7Xg4VqQVuPEf2Kc5ko7UkbwYHsORAcD5UCKd uNrSPFGoV9euDMzG+Oc6JSuXtyjuZqKjDbVLtBh09tCg58J1PC+zupqDqzIlss9ZikA3 WSi4h/jZxwFfaEvK+XQHch4IsJiEWgGcD2La1a+PsCOrSv448HqVO7zh7eXy9s4fNhJj lHFQ== X-Gm-Message-State: AOJu0Yy8xyybemsurfwVD/f5I5Jy4xJgCJvENY8xcjp2sr3iG4Pa+fJK 3NNCnu7LWNXAV1R6/p2jZE4KcBnX5uo= X-Google-Smtp-Source: AGHT+IEMWf2LlW1Sk+vi05hieRUMEFYp9jGfC0c+gzL3oL/wH9YD47CibgF03nZQ9pX5NdfEHEgo0A== X-Received: by 2002:a7b:c7ca:0:b0:405:3d04:5f52 with SMTP id z10-20020a7bc7ca000000b004053d045f52mr6824524wmk.24.1695666364974; Mon, 25 Sep 2023 11:26:04 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 11/28] bsd-user: Implement getgroups(2) and setgroups(2) system calls. Date: Mon, 25 Sep 2023 21:24:08 +0300 Message-ID: <20230925182425.3163-12-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666842039100019 Content-Type: text/plain; charset="utf-8" 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_lo= ng arg1) return 0; } =20 +/* 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 =3D g_try_new(gid_t, gidsetsize); + ret =3D get_errno(getgroups(gidsetsize, grouplist)); + if (gidsetsize !=3D 0) { + if (!is_error(ret)) { + target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidsetsize = * 2, 0); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i =3D 0; i < ret; i++) { + target_grouplist[i] =3D 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 =3D g_try_new(gid_t, gidsetsize); + target_grouplist =3D lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i =3D 0; i < gidsetsize; i++) { + grouplist[i] =3D 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 =3D do_bsd_exit(cpu_env, arg1); break; =20 + case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */ + ret =3D do_bsd_getgroups(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setgroups: /* setgroups(2) */ + ret =3D do_bsd_setgroups(arg1, arg2); + break; + + /* * File system calls. */ --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666549; cv=none; d=zohomail.com; s=zohoarc; b=G9s+cIt5AgR7Pxm+LWw2GubvNbu5cnPFsHt1ivYxZQoEfyZj7zOEDDnbGnJa2bDlV3A6t9J1uzJ7WCqJttqF2llGb8sP/mG1h4nRVItY+hYG4JPT/0k2mEgCua3ql4dmB9MxzYX5QXH+2cfHwx2PfM2+1A8OsXml5TkOjuGfNLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666549; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kfhgSFFzN1XkrYqOz6DoCPBLs5/WucsM++tn8gnV0CY=; b=mBmkz19tUUsuqYZpOab58f/jVhJG1alyajo59QOc1nuT/6GIxkyAMOanYjxwXqzZkrddUzJe7oXN0tGT9F/QYQYF4dhc9XbmM7YAxoc0kzMyl+kIgJjtNzVAkNTjY9l2ypF2MMyzhJ22+5gRIuLr9++hyxwvKynNulAg34zQjWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666549068618.2209007615987; Mon, 25 Sep 2023 11:29:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHc-0001IQ-UP; Mon, 25 Sep 2023 14:26: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 1qkqHa-0001Hb-Pl for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:10 -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 1qkqHY-0007KL-Vm for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:10 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40594697600so19231475e9.1 for ; Mon, 25 Sep 2023 11:26:08 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666366; x=1696271166; 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=kfhgSFFzN1XkrYqOz6DoCPBLs5/WucsM++tn8gnV0CY=; b=VHV8aPBSBghmQl1evEavf39+E0PN9uJO5yS2Uu6LSElcNdl1QMT1kTGkcdBVxh0vS+ NRnOeTMxgnHoqeDrhVC5TVmOCezX6hBkPv/ZeIKsdY90i5xZzY8pBR0q0mYnUSqcplBz LHYWknrP59vNJaFqdVE38NtnJEKz0j8nS/cICpAb8SFWy+fm5LTk6IEWqTDyAp7HQr1L g41gfp0mWT89is02VUA7Ju4q/wJfpYfbiITW9DvTg4JZWa4O4OdgZFTEFS9cUKVCGR0T Jtmwa6UY3NP7ypE8FkMiFfhS3NRMsF+SBmC7gWqdLnhFtwbwLLklpKE3+GB5itcuov10 QmOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666366; x=1696271166; 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=kfhgSFFzN1XkrYqOz6DoCPBLs5/WucsM++tn8gnV0CY=; b=cY47W1JlIzncGGVjTYk189j0RquVpsXl5UGNpWqITHw1hCE83Wmoh+SNNphWI6GQVQ Tr9AgYCVw/ScwZaBX5ktLToU7pTh/QUWRscQSp1N/+hFUJ4yQDeb2QGRgWZO5XO3aGsm pjXhMElq54bYdDl1i3RoyuI2XW71PoVUUp81XIplnj8cLBXcpLXx51XfIVHk+sHUHRe6 U7dmdA2aGmgELqyWrwvWQo8iRqbYBbEltyeocukWIl30FS/ydGXO5FZS4yp2gSSgJgr/ Foz0i6E+T0ZQpciFhNzSuiuwkg68Hp1vF2zIRPlYykN/ABncMWzmJYxbUm6NAH0/OQb9 Xspw== X-Gm-Message-State: AOJu0Yzxq9HkpZ7JMeBZztaxzE6F0A81WJ/uw8mRF2uCxU720jTce+Fo 1c1HA7BZVB5FaxR1Qwmu2oXowMVEePI= X-Google-Smtp-Source: AGHT+IEVvz2C4JggdJANvsTtC1PG6AGwpMzyqy6n465iETm9FqZc3JchSIIrdYYcMepWm/Q/C5JXpQ== X-Received: by 2002:a05:600c:20d4:b0:402:e68f:888e with SMTP id y20-20020a05600c20d400b00402e68f888emr6435170wmm.4.1695666366353; Mon, 25 Sep 2023 11:26:06 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 12/28] bsd-user: Implement umask(2), setlogin(2) and getlogin(2) Date: Mon, 25 Sep 2023 21:24:09 +0300 Message-ID: <20230925182425.3163-13-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666549657100001 Content-Type: text/plain; charset="utf-8" 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" =20 +extern int _getlogin(char*, int); int bsd_get_ncpu(void); =20 /* exit(2) */ @@ -85,4 +86,42 @@ static inline abi_long do_bsd_setgroups(abi_long gidsets= ize, abi_long arg2) return get_errno(setgroups(gidsetsize, grouplist)); } =20 +/* 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 =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D 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 =3D lock_user(VERIFY_WRITE, arg1, arg2, 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D 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 =3D do_bsd_setgroups(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_umask: /* umask(2) */ + ret =3D do_bsd_umask(arg1); + break; + + case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */ + ret =3D do_bsd_setlogin(arg1); + break; + + case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */ + ret =3D do_bsd_getlogin(arg1, arg2); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666714; cv=none; d=zohomail.com; s=zohoarc; b=W611+CId9rd+AqO/NgUTJy9QFx70Wpa6No7pLwuOleedpTdx6sAqR9u9We0DuXLKF7sSilr0lX6F2wyitcEVPWsgF7QohsOam8EZz7LY7FEq0MzXnHP+tx0+Y85iJvwxvoB0TUR3hbcB5Y1clsya/qvpPjdDm3byepYc2Qk2sus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wP1rfp1dDRIiBnhp1KylL3inypQKBVqgIftLFJMUFhc=; b=LjQ/3VMEDE63fYxOiOf/V2TrQXH1MbEum1gCqIeUUObSTzJmxZ9f87C1Khwg/bSFuzdxv5rCgkgDVLREUzWO7rYYAEODbqzsEkHzBlNQV9C2f0hfdqi6qFCafMQZjx3vjymvN0dGifyM+ZYNk087LQDhIZUk8jNDksYd9C9lSNI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666714830347.16453141915304; Mon, 25 Sep 2023 11:31:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHe-0001JU-JP; Mon, 25 Sep 2023 14:26:14 -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 1qkqHa-0001Ho-Vk for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:11 -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 1qkqHZ-0007KW-8q for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:10 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40594697600so19231655e9.1 for ; Mon, 25 Sep 2023 11:26:08 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666367; x=1696271167; 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=Zmpb0krVNvykN+WskEtOwc4q+ZgckbUbKcsp1ZmrRnU+EooeVlVg179EeRJz7hlR/W twsBkKHFjvUe0MiR4666oOXgPbQ+i3mw6YeWnddMxssmxA2o8lWq/Yx/v1PI52Feawxl o9pt0IJh/LmQ7W56Mb4dmpJijG0KtROAxVshLMJ02ZCpcDCW6afYJW9IQWbs89I/7+3l D2PCO2PNeOuAASVOzuGVqetziTQiDBJud8OQxt49XEe/2cwJOw7YbP9TEnfkViYqBJNL z2fsPA8OjsNYXXHCFJYyzWWzezM96QrHfmpE2XSg58OEh6fM2IXdRp8ZAzV+lj8OHjKS 8HUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666367; x=1696271167; 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=pj4maorfqohMnmz/p6rF1kLTp4cUqo4mTi1ueXBZQ3YN8Osmwttkp3tqwFew1WeGsL +7Axv1+GD+nxi5nfKB8eju05Lvxvpumo7gR0PlTx09omS+ZwWnpZ4S5TDsmRqpWqFAcb bgzl4dP48Fq0r89mrCx5tDbI23YxCGnDVnOJX09ImIXXkox9DY85RCLWHWTiG96gRjr+ 5HawZBPaqJNSgb7tksVYPSwM6ebYvm5SKgJGjY2yrO2rq7zV7kvP+qcCsSU4w6Xlq0Zp sXRpRBrTkd8Zb5K9X7DP84UQGVkDAIG0QkB54j7xOM1k4QZS5hro0FwsT1oD539e4Nxa P3/A== X-Gm-Message-State: AOJu0YyNCxF8Ec8l4P0BbQK4PDsANlcfv9R0rwzCc+mGPTU9+DXHynzq oCYcubHi7jAMvZqmphBDQsLPPMNPJGE= X-Google-Smtp-Source: AGHT+IGpC19Tvza5qVDKymvnXZZppwMc8rkDsXEf6ghoNNMDgjNwAXExgrZ55V5bgulE/SObCqMixA== X-Received: by 2002:a7b:ce92:0:b0:405:39b4:314f with SMTP id q18-20020a7bce92000000b0040539b4314fmr7194402wmj.24.1695666367615; Mon, 25 Sep 2023 11:26:07 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 13/28] bsd-user: Implement getrusage(2). Date: Mon, 25 Sep 2023 21:24:10 +0300 Message-ID: <20230925182425.3163-14-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666716328100003 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* getrusage(2) */ +static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_add= r) +{ + abi_long ret; + struct rusage rusage; + + ret =3D 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 =3D do_bsd_getlogin(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_getrusage: /* getrusage(2) */ + ret =3D do_bsd_getrusage(arg1, arg2); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666629; cv=none; d=zohomail.com; s=zohoarc; b=LBY7X65eTesfYiBxG6lQozd3ALXQA+V4Yj4XY3S8KHFkywe/S+f9Sp5+1STigrmEUnKPW4NGIOciJLQXHhG1Bmju6luIitsXRo6OPcQCh0DcmMy/p+Xt1tKgcyCjrAXIBsaCYcR7MMuR2PVtGTggFfwgd0kAHDn3Un/qB7NMgOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666629; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lQFZwC0LDHIWACO0/rcAxG3mL7h/9iuVdTmtYhQ4JHQ=; b=JXsQmVEepn+i9tfI4TgN/Igm8Ao/uYdYxeKiEEz+gpJfPjZaHszkjim4LiSSZACpuj6oY5ilZoW8dIRoIBBFCgY3SRHDhajPSJm9vlREA4N0uTOoxJoUWgAAhhf+RKlr7b3tdwcmOaphtFv4WdMIF1IczMl55eMYI9rXyBx26ak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666629315511.658606076203; Mon, 25 Sep 2023 11:30:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHe-0001JM-1M; Mon, 25 Sep 2023 14:26:14 -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 1qkqHd-0001IW-7B for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:13 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHa-0007Kt-Ib for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:12 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-401d6f6b2e0so55319645e9.1 for ; Mon, 25 Sep 2023 11:26:10 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666369; x=1696271169; 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=TblBe7Eb5Hlaeg1b2jEfJS+BbIr0XYYIfYZgo9gLYXsYSKTGnr907DDal9RNTfhWvU R1IiwInby3/Q8IE3QkZ9fx4kxltGdp+SE8bSQtit43qMHzrrJc2RCBGNkwoTx2fijmno HOQn1S/6Te706KFb5CquXOnj1or30uC7dBmt+tBqcv+St4hBCfUQ9uZ/670vWXGzklMT gq96ew2X5F7nnTNUm0RaQZR73JKA4Fr2mQiiBl8rlw3k+09t8seNxWEpapKz+9r6tVZY x9bAkcl5BV7YsD4AL8Lw1Vrp+WycWr/YXsJo0RFUjYxP16qXGMj8/uRMzeZlfFJkb12m GacA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666369; x=1696271169; 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=wtK8djPEnb7ZPMW3u7C02noNBIee98yr74JnT2jjvJD4ZfvOohJhdLU13QLFnqtQbl ISanbxwR9nfOxjTaZFRPUAae9DPLDcMkKRa0RSjHOZZ7TloCB0rsdeGEiRt+dJgI3qoK zoP9385qIGnFr7rHXhSk3mNC+mKu6viNaor5YJDXioHN9AmP51fdag1lxneYSdRpfKnp +xrR745+KcTeKc6xW1in/0eRLke/6dVNq9S/v+CeIxaiAM/rq6XKZfLbdQp3JVTs/KAm t/ftj9BIxMOeHWqrU4z1VcgW33/ckMPd8mW/cf0dD9Z/uAac8Wd6kM0BSSO9uIgVN3fp bXTA== X-Gm-Message-State: AOJu0YypWth66vwA7VVGKnlNN2eOS4SZt1deSyUTti8EsLH9mJXMZ9cJ v4Bv4W3tOye7FAcuFY5Hn6+8j2P0E8Y= X-Google-Smtp-Source: AGHT+IH8wG8BWytw0VdBSk+SCDdZfFsKuSoHvetMch+K2Fa6rMj1IvOH9dg6SYnzRTvgRLP/x5uBoQ== X-Received: by 2002:a05:600c:22ca:b0:401:b0f2:88d3 with SMTP id 10-20020a05600c22ca00b00401b0f288d3mr323974wmg.19.1695666368851; Mon, 25 Sep 2023 11:26:08 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 14/28] bsd-user: Implement getrlimit(2) and setrlimit(2) Date: Mon, 25 Sep 2023 21:24:11 +0300 Message-ID: <20230925182425.3163-15-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666631044100002 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* getrlimit(2) */ +static inline abi_long do_bsd_getrlimit(abi_long arg1, abi_ulong arg2) +{ + abi_long ret; + int resource =3D target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + switch (resource) { + case RLIMIT_STACK: + rlim.rlim_cur =3D target_dflssiz; + rlim.rlim_max =3D target_maxssiz; + ret =3D 0; + break; + + case RLIMIT_DATA: + rlim.rlim_cur =3D target_dfldsiz; + rlim.rlim_max =3D target_maxdsiz; + ret =3D 0; + break; + + default: + ret =3D 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 =3D host_to_target_rlim(rlim.rlim_cur); + target_rlim->rlim_max =3D 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 =3D target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + if (RLIMIT_STACK =3D=3D resource) { + /* XXX We should, maybe, allow the stack size to shrink */ + ret =3D -TARGET_EPERM; + } else { + if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) { + return -TARGET_EFAULT; + } + rlim.rlim_cur =3D target_to_host_rlim(target_rlim->rlim_cur); + rlim.rlim_max =3D target_to_host_rlim(target_rlim->rlim_max); + unlock_user_struct(target_rlim, arg2, 0); + ret =3D 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 =3D do_bsd_getrusage(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_getrlimit: /* getrlimit(2) */ + ret =3D do_bsd_getrlimit(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setrlimit: /* setrlimit(2) */ + ret =3D do_bsd_setrlimit(arg1, arg2); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666407; cv=none; d=zohomail.com; s=zohoarc; b=KqrGE3kFDH3bfZ9CWhUeGDV0Zc2ymt/JS0brGpJwFotTZqKsCgKGM99WkFx2TpTP4upcdpL9K5eh3Hoe0zcQrprKKJkPhe/5qQYG8p3dkp0uoc0MKBB2vvsjYpGkWS4XkqxlEUimq1w2LuIUKzHKX5epv8eBBSqNrvorDhob+TM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666407; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+e4yFlvYdu/hYdNO+o3b9LtvOAePOEZiwqvJAYO+t24=; b=N74f02lAPks8dF4sLTsBdyO+lZ74uur8fyUJBoB16QLQ9qrkbsDOawqu8YnMPV91pJlKLZORevORl+bymDNp/UmEfYMTz8R3CqhnOvk+mUlIPS/MibSNPrXTxl57BXKa0KW5waMSnT3gxjXAquXUZFUSV8aa0KIZOzNoPLuYOxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666407650426.79895573219585; Mon, 25 Sep 2023 11:26:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHg-0001KY-Te; Mon, 25 Sep 2023 14:26:16 -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 1qkqHd-0001JL-Uq for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:13 -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 1qkqHc-0007LJ-5u for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:13 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4053d53a1bfso58994465e9.1 for ; Mon, 25 Sep 2023 11:26:11 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666370; x=1696271170; 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=J4vW5JbB9w0ezf8PyPBgJuvfgW7Oo7buoMrqqf148JG5LXO5xjBfIU+U76fXeHhpX0 V5up92XM3UoY7XJRHLh8YkjbpIsuSD+tFysKilbaY85lFRWCPxpr/P03iGmMvd1bRgsP xZ87xmP7MpsDs7aj0tGN5hHYWdiclJWb41yNZGylLNNJbb7ZZyH8kthL5dueRprssqbW gkZnAXhPiAUFk5bqEi3TfkDtA8mo/YI40B9sO7Wf20+VO5ehNjG2vp35+yZwHatVSCkl cFUk2AruWWAeVdqweX7thR7FzJk+9mmaM3QwIUNP3AuRJXD7m7xcghz0c0Z7wVQXWMiq Ko4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666370; x=1696271170; 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=O4uDyKKZ/x7iq298LlEVkRjgAtHviOu3ZocqlIsQvsCxr7yCCvKArYrTl/f71NoR0w OyjtNAZWxfRFXj1vPyklxpeh46FKqyy0h0XRvKTSXvwVNCg9Bhc9UT3ELX+BdoEmp4z/ hNEfShdAC/0PoQM+8JkS3eonaald+FGY9Jcank27nEQZgu1xmQ7Oy4JdXFKhb8KjlTON hAxLVs7AkwE5WL49AsTow5MVHLvW7umZfNsu04v1GNkWhkvRW/h6HURroc8WG6/hgVoj TCbehjvZCk2E1+uKb713ejLL8EtF3YOm+I+W4b6PA+RewT1rGFib4urQANJcaW4/1/d0 lYGQ== X-Gm-Message-State: AOJu0Yzbjdoh/cJhXChKOAbrEEtBVwLUdukqlg1uXMr+nj0QgvD8gfTd PlCdjcHeO5G4elbFgOvgLj187JIcBdE= X-Google-Smtp-Source: AGHT+IErLCkzzfphTceps2SLpibn8bI7BSNAnHLgeYYC7sndT6BqbEywdb6MCWv8GXHO4xAkaaplmA== X-Received: by 2002:a7b:c456:0:b0:405:4c3a:796f with SMTP id l22-20020a7bc456000000b004054c3a796fmr7088676wmi.2.1695666370192; Mon, 25 Sep 2023 11:26:10 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 15/28] bsd-user: Implement several get/set system calls: Date: Mon, 25 Sep 2023 21:24:12 +0300 Message-ID: <20230925182425.3163-16-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666409564100001 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* 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 =3D do_bsd_setrlimit(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_getpid: /* getpid(2) */ + ret =3D do_bsd_getpid(); + break; + + case TARGET_FREEBSD_NR_getppid: /* getppid(2) */ + ret =3D do_bsd_getppid(); + break; + + case TARGET_FREEBSD_NR_getuid: /* getuid(2) */ + ret =3D do_bsd_getuid(); + break; + + case TARGET_FREEBSD_NR_geteuid: /* geteuid(2) */ + ret =3D do_bsd_geteuid(); + break; + + case TARGET_FREEBSD_NR_getgid: /* getgid(2) */ + ret =3D do_bsd_getgid(); + break; + + case TARGET_FREEBSD_NR_getegid: /* getegid(2) */ + ret =3D do_bsd_getegid(); + break; + + case TARGET_FREEBSD_NR_setuid: /* setuid(2) */ + ret =3D do_bsd_setuid(arg1); + break; + + case TARGET_FREEBSD_NR_seteuid: /* seteuid(2) */ + ret =3D do_bsd_seteuid(arg1); + break; + + case TARGET_FREEBSD_NR_setgid: /* setgid(2) */ + ret =3D do_bsd_setgid(arg1); + break; + + case TARGET_FREEBSD_NR_setegid: /* setegid(2) */ + ret =3D do_bsd_setegid(arg1); + break; + + case TARGET_FREEBSD_NR_getpgrp: /* getpgrp(2) */ + ret =3D do_bsd_getpgrp(); + break; + + case TARGET_FREEBSD_NR_getpgid: /* getpgid(2) */ + ret =3D do_bsd_getpgid(arg1); + break; + + case TARGET_FREEBSD_NR_setpgid: /* setpgid(2) */ + ret =3D do_bsd_setpgid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setreuid: /* setreuid(2) */ + ret =3D do_bsd_setreuid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setregid: /* setregid(2) */ + ret =3D do_bsd_setregid(arg1, arg2); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666419; cv=none; d=zohomail.com; s=zohoarc; b=ZQL32vaLvk/k5QXPs8M4xAwHmf7bArtJkrAaTnPgNyygyq27XsejWtiyEApyvD9bQ41FQKkdfIDCWojygL3AoPEK6D+OugCdkMv1moH6ZgB7l5VGeYWoqgzliPBpOLTwLOCQT4cHPm2xgQaxIuzyuwFETlKxFnoBYM9CJbssDd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666419; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nclM6JiCGY7mFmLYiUs3Sh+q/hGi5ONE8JD20ZP5YqQ=; b=O0GjF6Ykzajhb1ymyYyB2O2nhS721WgPleJg0c7MNdk+iEXtKNDUABIbmBKLq8CG7N7hFgY9h3jHUWXqCUvlU8uO41SLuLV3NB2k4m1RP1C4Gl8vVu/2klBnZzn9QymVxmz2xtOv+RdeBGF9VnOLnaZlwSazj8cZwWZjsIIIQ5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666419757767.5932838430759; Mon, 25 Sep 2023 11:26:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHg-0001Kd-VD; Mon, 25 Sep 2023 14:26:16 -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 1qkqHf-0001Jm-8v for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:15 -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 1qkqHd-0007Le-Gk for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:14 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-32179d3c167so6065805f8f.1 for ; Mon, 25 Sep 2023 11:26:13 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666371; x=1696271171; 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=eTpAwGtiGYFfPVaVlWGR2Gf/R1ize4n3vJd8tg+nQV17nZfC8v0tBeviMYd+3iAdbn X4fJRuR05PIK8VOx+Y0abhhEAn3Eu/Pxhz/Vandp/s1SBt/2bh/LHb1ycTxj83zdiNx9 rdQCi3bwG4xegBw3fCV6T8n9kqXq6mMuTGPqYxDs9UU23k/QgsSnoHDpPLOsaScXceQW 3gSmSIOHgZwXZg9j3qOTovWxUpUSjolCpGunmdW3UCpa3Vr3KQI7CVLQDEDy9iq2aWIY TWXlZYvNGjWvMsjSQg9fmj0URCtFicSiNrPPr6H0Fb7sGq53NcLCFkDphuNzoqV9szia JPgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666371; x=1696271171; 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=FKiZMWK4olZPyq0qZdufj/VxSLa3PhCYnf4LV7B2IxU9VwcIscnPchNTzEsbQYIcEt u9LcXNrNAidi0LNu9fhMBEu/Ig1dmfeHiVa+iOAuNaY2tNoZ8OipkzhupU9CcblhcpEW PMO9dqkRSURRomCvHxb0PRIApvQfhRaYZDjra3cFjG/w493yXINqPY2R/SGIVp884Z3k +wnw98MwxNNf/lzJznENnqfR/H94oiTtQO6tBVQhpxcCZ1B8dYOW+DEoUBDMxHOkDcf8 C4Rqt1kh51rFWoI/MFyflMlGxuStZKDJaxe84bOmbTSnSqMVcnHsqob6vzknR+lgAwTI +UHw== X-Gm-Message-State: AOJu0Yw1WjmGq1raGpLdLQVxT3Qi6+fdgzYEDwgAmyOZstX4XvurDgsJ YsjyBZUmIDjWW8zuEQi+zp9bNwFe5pc= X-Google-Smtp-Source: AGHT+IEtPSZaADLHiTrvBqEg1e/+bcM3X66Op/aa8AIgynWSDMMBnmQ+YvcG99ZTNjuYIOUuSR6dSA== X-Received: by 2002:a5d:60d2:0:b0:321:6bed:1646 with SMTP id x18-20020a5d60d2000000b003216bed1646mr6849134wrt.14.1695666371419; Mon, 25 Sep 2023 11:26:11 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 16/28] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid. Date: Mon, 25 Sep 2023 21:24:13 +0300 Message-ID: <20230925182425.3163-17-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666420247100002 Content-Type: text/plain; charset="utf-8" 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)); } =20 +/* 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 =3D 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 =3D 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 =3D do_bsd_setregid(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_getresuid: /* getresuid(2) */ + ret =3D do_bsd_getresuid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getresgid: /* getresgid(2) */ + ret =3D do_bsd_getresgid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_setresuid: /* setresuid(2) */ + ret =3D do_bsd_setresuid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_setresgid: /* setresgid(2) */ + ret =3D do_bsd_setresgid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getsid: /* getsid(2) */ + ret =3D do_bsd_getsid(arg1); + break; + + case TARGET_FREEBSD_NR_setsid: /* setsid(2) */ + ret =3D do_bsd_setsid(); + break; + + case TARGET_FREEBSD_NR_issetugid: /* issetugid(2) */ + ret =3D do_bsd_issetugid(); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666562; cv=none; d=zohomail.com; s=zohoarc; b=ehZLzU+e0iHHoxSZ4fzWiP3UvdNr5c+V28/OAzE3q6ry3qtYkUJArAWYJtVTLry0sJm3OOzYF5zU54A5E2ER4qnALKBMjmgQHn/rttx+EnKWm1XaTq+oBAoOGb1w5otoWhJo+oP8PaW+AqmpGpg4kqQhKrnB8ztN9D/Vep+23Es= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666562; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QhivGYb84XE/TlLEmop+Tew1vEbaCLi2YOrvGhy8DCw=; b=fCwzFa5WIbb9RvRlDtRMxG2yc+4llAYDGHCpgXM7+G20f5ydrEo4KqvlYJZIW8DB7yJ63RhUXSfagLmdh2eq8mxqPueEQvT3YW0a44q79JxPnyz+GFekzmIQ9pBSEo0b6y98BGd/RVJ5zl60CcsWrKwPd58PemTjDMcFGUU8wqs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666562152631.6594022811072; Mon, 25 Sep 2023 11:29:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHh-0001LF-MZ; Mon, 25 Sep 2023 14:26:17 -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 1qkqHg-0001Kc-J2 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:16 -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 1qkqHe-0007MW-KQ for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:16 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-405621baba7so41374965e9.0 for ; Mon, 25 Sep 2023 11:26:14 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666373; x=1696271173; 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=Pu4TXczUioJmBBU2WOgi43rRz5BiK98QN4hpHo/L78DFZxpboJxplrOZUd4n9WMIqW dTW4Sg6YBGYfCQu4mAHp/u0Dwj4/8KwqAC/QNWJR0dG4NX/jDLs3V6zb9UycCrwxUZzL F+noEBNCCNwHvfWsRZEpxBqfoLrtCNhZsafTueI9ByzeiPV/jv43YzRpdbBd3Qao2/0Y lu4alRoOj4dXx3HTVduTVk1wogM/Avup50w3KSDFTtT9mbOzd7erVUXE7UDsbSJsfTw6 P3Uu0XadGANA2OeUki2syoaeuTIGWwKCWoE+X5BhUMW1+slSAhbdwCNxjvFWOk2wSOVv 9v/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666373; x=1696271173; 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=KnhW/BabadkAG0G8Yur0aozGYvqa1L+v+w7vdmARoBq+j4eyLUnykFdWgdzo64v8Oj r6/tO7ayf0liLBbVsseSMwe6tHPxQoe95JxAQ5F2/tSxbPI2Qv6INWrb0L1vNgTJomu+ Ldermvpsi4jCDSFfxU4zv9zAYQDp49IPsW3r7rs4q7ZyjHxcsa4zSb7KIKe3AJmNYlqQ yuy/+hrInXRX+zZembi+//IKqAIeAve9w/QBkPg23bcHAzrAtmvSvKX0JzMrrkJNBQUm n8tT3EIMt24hNay3Y5NV0h3w/yK/97z1dlOiMGn8W37IavuiCJ8Cmsp0eDK7NG+kTkHI ldzQ== X-Gm-Message-State: AOJu0Yz3HN6DhFyunMcg/OAc7HzaDhzKClOc98IccXEMLDzRLl2EQvXM KLSycuGN+s/Em9iUaO7JeCfl+Un12dk= X-Google-Smtp-Source: AGHT+IEAIq1k1h8ogbaTAAWQsLEO0tbF776nMBLsiNOcjijKg87MBK7IUzxee9q3o1iIdK9y68YGzQ== X-Received: by 2002:a1c:7904:0:b0:405:1c14:9227 with SMTP id l4-20020a1c7904000000b004051c149227mr6699308wme.33.1695666372748; Mon, 25 Sep 2023 11:26:12 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 17/28] bsd-user: Add stubs for profil(2), ktrace(2), utrace(2) and ptrace(2). Date: Mon, 25 Sep 2023 21:24:14 +0300 Message-ID: <20230925182425.3163-18-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666563955100009 Content-Type: text/plain; charset="utf-8" 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()); } =20 +/* 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 =3D do_bsd_issetugid(); break; =20 + case TARGET_FREEBSD_NR_profil: /* profil(2) */ + ret =3D do_bsd_profil(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_ktrace: /* ktrace(2) */ + ret =3D do_bsd_ktrace(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ + ret =3D do_bsd_utrace(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_ptrace: /* ptrace(2) */ + ret =3D do_bsd_ptrace(arg1, arg2, arg3, arg4); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666840; cv=none; d=zohomail.com; s=zohoarc; b=SGQBRJAdzda7PJ6c09130uAOLKATE5sU34CTFnLD7gee4BfTKHQCWGCHc0WuVV6miqovO7Tiv9T0cPzHcoZJYezf7hvXi3Mpi9VibKG3EmSBpFKY/63aKeuEvVnTU3iKRki8jYwn8AikAeN8w54EOtbFGo/hcjiIR38wR7emiV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666840; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NJNgA7i1skSBgo3G8Dhw1FER8/CjFW3btNuWKszZ4Dk=; b=hQ6E5NGPvyq9TdSthtNUiFPPx/1xwUaGsKg738gv/EqR36b+QVsCAUMyK75lwYeYwOFTRMJuJXVj9k9zemBEDOR05FWOEV1q3nu6m+aJ5gq6TbLEIyWFRiC2LTo6wuSHMA9ZIhnyllN3P/eAYOzwS8m23zavZi8mMeZALFGTGFw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169566684029452.242077712439254; Mon, 25 Sep 2023 11:34:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHj-0001Lb-02; Mon, 25 Sep 2023 14:26:19 -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 1qkqHh-0001LD-HV for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:17 -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 1qkqHf-0007Mk-N3 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:17 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4054496bde3so53076925e9.1 for ; Mon, 25 Sep 2023 11:26:15 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666374; x=1696271174; 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=OSgd85bmOEeWLoXk/HO0JzbXEG0AYgLYB3JPtD/298awgqViDu37wqinIuYYwb4tZD 8+tfofqUdUNP3ILz8N3azt0Y/dY7HrfZZViD/bTfK8gxZwI8Erp9+QIM66S7BcleprrZ StASK9/Y8uLFCktklwL1Jbi5SIqu7ZO/quF+P4iF0ycGkp5ol1c5zBLncUrRNJUodoJn +mqGg1r0ohxrhCyxQWFJE1I6lb7nWwB3FUjUPGWC23rcl7GbPkamown1iO0oy25Yhu+j 78RECYBqLWNJ9/HEdtKR6X+ERZBvjyRLJT59PJIzsogAVlWObMzu1vQ89nQpZmqPEzrj onkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666374; x=1696271174; 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=OfqgmAk9bVCFIABVIw3mO5E9xkDmcZFduw67V2YGf9zCbUz1MyF6fzdLexU11HByI2 /vnWo3DxJ0nG/DsQt5AVTzsip4YICKALg0CgSYrB2vxadXiyepGaJX+zZ90GDMFQozyp sLsBnO/b29sRCTitRnjaD4HmljopYZQAVaz0UpJrSm5D9LgNwlxGOtpV7UOyDqM5zeHO hoSqtnPviNpC13Is8L6vy6keFDoJX9fVL5Jn4j7zOEEDJQthtCid9t6BBpbqfj2T2sgO H3/jFIxJ/wiJQWHKivFiBo0q5lTN4N+aX9SIevmCzhWHJZg4UqyGJc0unxT9Zvi5qa/w zA6A== X-Gm-Message-State: AOJu0Yyy+EzZ042GoVrY58hEWwnFgabTT5kbx0TZu4zgvreHOT8sFEZj hkdOJhtThV5ygaSshC42oyZ+K97dlB4= X-Google-Smtp-Source: AGHT+IHWZxOa+zHBS/8XVL4w7naQ5mPZJCobQAsOM5Q/LYQPT/bK2AdpueYsmIdCloQqshAuL3AL0w== X-Received: by 2002:a7b:cc81:0:b0:3fe:687a:abb8 with SMTP id p1-20020a7bcc81000000b003fe687aabb8mr5938086wma.7.1695666373989; Mon, 25 Sep 2023 11:26:13 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 18/28] bsd-user: Implement getpriority(2) and setpriority(2). Date: Mon, 25 Sep 2023 21:24:15 +0300 Message-ID: <20230925182425.3163-19-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666841845100017 Content-Type: text/plain; charset="utf-8" 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, ab= i_long arg2, return -TARGET_ENOSYS; } =20 +/* 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 =3D 0; + ret =3D getpriority(which, who); + if (ret =3D=3D -1 && errno !=3D 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 =3D do_bsd_ptrace(arg1, arg2, arg3, arg4); break; =20 + case TARGET_FREEBSD_NR_getpriority: /* getpriority(2) */ + ret =3D do_bsd_getpriority(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setpriority: /* setpriority(2) */ + ret =3D do_bsd_setpriority(arg1, arg2, arg3); + break; + =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666464; cv=none; d=zohomail.com; s=zohoarc; b=BsjXfnyp3TbBUdIbrLFQfayowsvoy2tmea/0jLfsg0muY6EgbSECbn9e9QAKC8y0K65TzKkGgkw5cI8EVTi0w3c9AkpeQC8EcJnMBvUKe+Deafvxgq3qwKuVbKGoXEpnRjurvlgxjPZZXF7bbbuzuso6Et4vntiWpvhGlHdv1Og= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666464; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TztszCQiHOclcaF2WsULwVYzhpKz4VJgE5PYB7dlSh4=; b=fqgSQqvkSipuYbnmcTY9yzuY9jqmuOTzok2WYygwD4EG3dxEHzBmezNipvGZla/Kdl6QPtGGGD3jk6dn9Pb3x5TLpLmZU8v87f+SJ1/Gk77m5gL7GC/a0oE8mClu+JqvXa66UqAEHPexRjXno3T6j9N7zHbihSGLQO1t/jVY7Ds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666464712498.1768455756942; Mon, 25 Sep 2023 11:27:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHo-0001MR-NX; Mon, 25 Sep 2023 14:26:24 -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 1qkqHm-0001Lz-Gd for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:22 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHi-0007Q6-8j for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:22 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-405621baba7so41375905e9.0 for ; Mon, 25 Sep 2023 11:26:17 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666376; x=1696271176; 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=PoEH5hAXNPMdreso3L8IwdGeT1ipZaKe+hQyAz8PPn2RP+GtJpPqnITrSPdrXRzUwk pvzC6/Kcw/Tec3EiDqQRSyjNvQPYqh5KVrdz6B+f9gblAOCs7bRIzeS5ZfhzuyE3lDoY k7HuGEE/Ko0Tc/ggFwdZlvehhhXlNQX0rkoAj9gHJ7s1wTRBCEYP4eJZjUKL8J9BT8+2 +K4wmQpkf+g9bA5v+E+Im2/kweSxP8oXvNxpkBE1H2zANxOFAGJm81d5HmHAvCmnTN4j vRG1aMoqe1H00BFRqJxDfPhcfk8Dyj9UlmCQeBWDXB9ESFPPz3PBQQms8djh0saJI4py WSWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666376; x=1696271176; 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=WZfMRc+kxrXd1HNewx4mk6swy4MuW6DHajbYsvSo0Rn02dzxcm65oFnurpUjs9HxId tBsrL9oZ3tUwQAFbzqd/Jlactvd8z9PceSr5tj5gK5/zyAeNZALHA7sCGb4COZkCLawg qxAA1Muapdq1c7Gtvjl+jG6OXAQJPenWAisrXH0PLf4phph2RVZij0b+USCEJo2/NWlY mi89P5yCyejBeaay1ZMwCAVyWC5g/6FW1pvHiLZocUOiYYdi5A0bG2fghZLJjIQFSfy+ FLI03j76NFTQbMWebRvBGLn4k92hhtXCOUlxD5qDVZChtwQ3rudbo+xX8SY5YWdCMOKn Ecig== X-Gm-Message-State: AOJu0Yx5GN3cbR3i7F99ruali7YZlGscF3hc0vScRrO6qVXSBWFBwfzw BBpwT3f8JXaQfofimTB9am3bQg1MVvw= X-Google-Smtp-Source: AGHT+IGMLFyMeRt/bN5gIpIlO3/hRpIwDcF1U89Tju3GHhtSjBJF86KSrld7MOUnro78phOcKO5Vow== X-Received: by 2002:a05:600c:2254:b0:401:d947:c8a9 with SMTP id a20-20020a05600c225400b00401d947c8a9mr6985891wmm.19.1695666375218; Mon, 25 Sep 2023 11:26:15 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Karim Taha , Stacey Son Subject: [PATCH v5 19/28] bsd-user: Implement get_filename_from_fd. Date: Mon, 25 Sep 2023 21:24:16 +0300 Message-ID: <20230925182425.3163-20-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666465421100001 Content-Type: text/plain; charset="utf-8" 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 =3D NULL; + unsigned int cnt; + struct procstat *procstat =3D NULL; + struct kinfo_proc *kp =3D NULL; + struct filestat_list *head =3D NULL; + struct filestat *fst; + + procstat =3D procstat_open_sysctl(); + if (procstat =3D=3D NULL) { + goto out; + } + + kp =3D procstat_getprocs(procstat, KERN_PROC_PID, pid, &cnt); + if (kp =3D=3D NULL) { + goto out; + } + + head =3D procstat_getfiles(procstat, kp, 0); + if (head =3D=3D NULL) { + goto out; + } + + STAILQ_FOREACH(fst, head, next) { + if (fd =3D=3D fst->fs_fd) { + if (fst->fs_path !=3D NULL) { + (void)strlcpy(filename, fst->fs_path, len); + ret =3D filename; + } + break; + } + } + +out: + if (head !=3D NULL) { + procstat_freefiles(procstat, head); + } + if (kp !=3D NULL) { + procstat_freeprocs(procstat, kp); + } + if (procstat !=3D NULL) { + procstat_close(procstat); + } + return ret; +} + --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666562; cv=none; d=zohomail.com; s=zohoarc; b=nGSSDAmnCIxJGKJfCfzuZp5w96VK9PPm1wKH8b6Fx7C7wgeHN2GWPjJ563DPwCM5zV16eGSCxtrEfFSYwteBIsn/OKb1bCjgAO4dHHqRkYwRSl0rkLYKHW6IwIDHgZBmu5DQwLHTnQ6EqN55VGJ8urG8jTdGlRiYh1WWxc1ejIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666562; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uxI2BautFYuM9X/6LgOM/mAy2btm9htJw+uHfz45eMY=; b=M/G1aeEFWJjLqsNmaY/G7xP1y3s22Cw52P0syh2Tmix2R3/Vtd8VAk3iMVv3SuXF2x3J9ngbls5NjOSKSSYF/Stbpi+e93fqMtN0tQDRUOFKoenIVo7Nz+7bpBpCRk4wIOw4uJ9V3MycRbL3touKftSAbIJecv2tNJ1yPClVKJc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666562386651.2618860166754; Mon, 25 Sep 2023 11:29:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHp-0001Mu-N3; Mon, 25 Sep 2023 14:26:25 -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 1qkqHn-0001M9-UV for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:23 -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 1qkqHj-0007R4-Rz for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:23 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40572aeb6d0so35488685e9.1 for ; Mon, 25 Sep 2023 11:26:19 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666377; x=1696271177; 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=jfStwEuRSRW6NYVsKYPouIDKH8JNNQQ56+4VZQncSN7+RZcuSAnox6YZVQn1yMN23/ L8lnxsccHrJAooScVmfkXM3odDhSrfpc1ns4FnSRnDCj/WgaJ+fNNppu3UC9X1guUGMf lRVw+Qw7PeKjk0L8zApNYn1eLwD+GvL0F+bvYgZT9dAFXGgI1Fj5hXUn+Rej9Vlv2YSr OKgz1tyVWMU6hOS+TaTfkTr1sZzArcV8Gkc4uOUL3gKKqvNqaS/OitpORqXUH8lBZFyc K+XdVj4jcijeYMPDwM4H29XwL1Q/YgjO00p/AT+YSS/9Q8fwhjqREYVe5ZfzUa/LhFaX 4Riw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666377; x=1696271177; 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=ra1ubG/oWLftl/4kxKQJvlbMbc9Ol/76ZdsBeyRDfcO5CtrHM13xWllNdG4P/W/6PM D3ycC16fLAmlsVlNgasT8YlZ6E0c2Vty7df5PXJa4hqGRzwl2Jc8ddX6RO7VekRvG+6B xS3QeJPh5/pG5au2WuOhosNMXvOHHdiMJf8KW8bHXZwzA/KGUHU4BudvsZwgEnc91Kl2 QDPWrSpzt2VIolOTZ3Z1R56jXsAZghrNAPnHGAdlV7XYzn10MfY5+Kq/GAzYGuu+UeL3 voaqsPFm2U0Cv8BuDUPbWKS7h0llNyqBsSsHFzuA/xhFAe1MmfXeBfurnz4CnQY7U6xD sR3w== X-Gm-Message-State: AOJu0YwPFzW3p554UaVJnjnZO0lU1ualFywM1wQbQcXD1N4a2NsgqkbU 3sa6bLcJygwT5mfJvOQmNzcomC4H2Pk= X-Google-Smtp-Source: AGHT+IEGEAV47AR9MxKYtm4f0qWw8Jbr0wdFhMr+l5dUAw3OeVqNZ4Xlr6OR6LYjXStwKwgjogphOA== X-Received: by 2002:a05:600c:141:b0:400:ce4f:f184 with SMTP id w1-20020a05600c014100b00400ce4ff184mr6632576wmm.41.1695666377488; Mon, 25 Sep 2023 11:26:17 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 20/28] bsd-user: Implement freebsd_exec_common, used in implementing execve/fexecve. Date: Mon, 25 Sep 2023 21:24:17 +0300 Message-ID: <20230925182425.3163-21-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666564016100011 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* + * 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 =3D 0; + void *p; + abi_long ret; + + argc =3D 0; + for (gp =3D guest_argp; gp; gp +=3D sizeof(abi_ulong)) { + if (get_user_ual(addr, gp)) { + return -TARGET_EFAULT; + } + if (!addr) { + break; + } + argc++; + } + envc =3D 0; + for (gp =3D guest_envp; gp; gp +=3D sizeof(abi_ulong)) { + if (get_user_ual(addr, gp)) { + return -TARGET_EFAULT; + } + if (!addr) { + break; + } + envc++; + } + + qarg0 =3D argp =3D g_new0(char *, argc + 9); + /* save the first agrument for the emulator */ + *argp++ =3D (char *)getprogname(); + qargp =3D argp; + *argp++ =3D (char *)getprogname(); + qarg1 =3D argp; + envp =3D g_new0(char *, envc + 1); + for (gp =3D guest_argp, q =3D argp; gp; gp +=3D sizeof(abi_ulong), q++= ) { + if (get_user_ual(addr, gp)) { + ret =3D -TARGET_EFAULT; + goto execve_end; + } + if (!addr) { + break; + } + *q =3D lock_user_string(addr); + if (*q =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + goto execve_end; + } + total_size +=3D strlen(*q) + 1; + } + *q++ =3D NULL; + qargend =3D q; + + for (gp =3D guest_envp, q =3D envp; gp; gp +=3D sizeof(abi_ulong), q++= ) { + if (get_user_ual(addr, gp)) { + ret =3D -TARGET_EFAULT; + goto execve_end; + } + if (!addr) { + break; + } + *q =3D lock_user_string(addr); + if (*q =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + goto execve_end; + } + total_size +=3D strlen(*q) + 1; + } + *q =3D 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 =3D -TARGET_E2BIG; + goto execve_end; + } + + if (do_fexec) { + if (((int)path_or_fd > 0 && + is_target_elf_binary((int)path_or_fd)) =3D=3D 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)) !=3D NULL) { + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg= 1)); + qarg1[1] =3D qarg1[0]; + qarg1[0] =3D (char *)"-0"; + qarg1 +=3D 2; + qargend +=3D 2; + *qarg1 =3D execpath; +#ifndef DONT_INHERIT_INTERP_PREFIX + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg= 1)); + *qarg1++ =3D (char *)"-L"; + *qarg1++ =3D (char *)interp_prefix; +#endif + ret =3D get_errno(execve(qemu_proc_pathname, qargp, envp)); + } else { + /* Getting the filename path failed. */ + ret =3D -TARGET_EBADF; + goto execve_end; + } + } else { + ret =3D get_errno(fexecve((int)path_or_fd, argp, envp)); + } + } else { + int fd; + + p =3D lock_user_string(path_or_fd); + if (p =3D=3D NULL) { + ret =3D -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 =3D open(p, O_RDONLY | O_CLOEXEC); + if (fd > 0 && is_target_elf_binary(fd) =3D=3D 1) { + close(fd); + /* execve() as a target binary using emulator. */ + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + qarg1[1] =3D qarg1[0]; + qarg1[0] =3D (char *)"-0"; + qarg1 +=3D 2; + qargend +=3D 2; + *qarg1 =3D (char *)p; +#ifndef DONT_INHERIT_INTERP_PREFIX + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + *qarg1++ =3D (char *)"-L"; + *qarg1++ =3D (char *)interp_prefix; +#endif + ret =3D get_errno(execve(qemu_proc_pathname, qargp, envp)); + } else { + close(fd); + /* Execve() as a host native binary. */ + ret =3D get_errno(execve(p, argp, envp)); + } + unlock_user(p, path_or_fd, 0); + } + +execve_end: + for (gp =3D guest_argp, q =3D argp; *q; gp +=3D sizeof(abi_ulong), q++= ) { + if (get_user_ual(addr, gp) || !addr) { + break; + } + unlock_user(*q, addr, 0); + } + + for (gp =3D guest_envp, q =3D envp; *q; gp +=3D 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 =3D MAX_RESERVED_VA; unsigned long reserved_va; #endif =20 -static const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; +const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ =20 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; =20 void stop_all_tasks(void); +extern const char *interp_prefix; extern const char *qemu_uname_release; =20 /* --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666562; cv=none; d=zohomail.com; s=zohoarc; b=AMyV21/RFbVY1IgVQ6tinReditbkWoMU+XKd/8zTaXrLRAI4uCw+LNx4wBxIdFQLYJJBAyZGnojoyV3rFkZ21R8+hEky0EvhCjfywHDk4FxJNLfc0BFZLidoRm8P2e0WXPF8gfP+wOiuhytaxmxILneu57svI6ZPr+Nsx4TMR6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666562; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qbayE6l6JhvDk5JDDSA3CFMkQpsKKYUY+hJNz9DZm5c=; b=frDd8pGGRegytO9/jQK5SfYu0hlD3l3ldFqTYVlMJiGE5yLPA6P0R4Y7n76vAup4xnF5sRx0Sf95+vANFgaFfymtMriMQAsBNoofWN45K4ptjCtGW6iaCMMRNiOSSTRqDucQo9JOtvmJvhzzEn6RLLsGC2cDpAzDS0NxCSlWl3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666562679404.1573707987361; Mon, 25 Sep 2023 11:29:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHr-0001NS-LM; Mon, 25 Sep 2023 14:26:27 -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 1qkqHp-0001Mn-C5 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:25 -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 1qkqHk-0007RA-LJ for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:23 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4060b623e64so3203995e9.0 for ; Mon, 25 Sep 2023 11:26:20 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666379; x=1696271179; 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=qbayE6l6JhvDk5JDDSA3CFMkQpsKKYUY+hJNz9DZm5c=; b=AmqYysI4n5SpS236GPJWReCltmdtJFFxGg/Ehmq2tHfX5TennzRzA80TVTV4olxFM5 HgEC3YF6JGEGwthGUb9mp+fNrZnwu8wy3qQnAtZzs0r87ieGX2IDZY0ieo2huFwBL1KO OIfiMGN7cr4Olv7HMKmTIOSHX8ynjse3+r+uLtXzdDKJuRUFyIonzwxWyBd4RKWD3HTb 5pi80ZkgMnO7RuadCIkkExlX+0S/XUBbjGyZIh3QmPLOf9NHt7wVJmLPNduIAgqXc6Vb WIxntwLiz3FSDCty4ODaaoV3+9oejWOaL+0Y0wSAE4lf+7KpQXdqOLtiu4ZY9DSCuMG2 LLcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666379; x=1696271179; 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=qbayE6l6JhvDk5JDDSA3CFMkQpsKKYUY+hJNz9DZm5c=; b=iBpxZwRq2fN+YLek5dAb8UiPEx32e5Xbf6r7kv2bP8QHBWej5EqtEhE15r+hs7AMSf W0ZIlUs/8VUnhVVJ10Ijjx7dRkiGmq1gy91NnXxlM9RLgLwCEFnHpVgKz00a/naREKju 2fw1y8b6e8l9JgEKsiLvJ1YXQ6ri6P6LMCjYmXf4ivJm6GJjsgiIfPe6X1/yz3GJudyI 7aj4xS0RSTx45vtVo4izP1knYgWPPdG43xeecyggY5Z9gYO3X0oAfK9BmjeFqqLQiIJ3 G8PdLdbUB5lOzVJuVNb+cMYC5bouGBim6g4/GIIpXQnnSAiwdc8bkQDfOG/2WcLCdy81 drAA== X-Gm-Message-State: AOJu0Yzq0wXUbpafBrQ7jPplTiwpxs+I5+WLeWRnonHvNNgWILTQddcJ yk8zO1RbPKIZq6In1vjlL8TnBeTWJH4= X-Google-Smtp-Source: AGHT+IHdiWQBnQOX2ynZV4kgCuEGZp7YHUysaKZ6+yy87x+YJg6+Zh/yPZMa2iB9MawFBOUXWK7C5g== X-Received: by 2002:a05:600c:2044:b0:405:3941:ce2c with SMTP id p4-20020a05600c204400b004053941ce2cmr370925wmg.6.1695666378731; Mon, 25 Sep 2023 11:26:18 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 21/28] bsd-user: Implement procctl(2) along with necessary conversion functions. Date: Mon, 25 Sep 2023 21:24:18 +0300 Message-ID: <20230925182425.3163-22-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666563860100007 Content-Type: text/plain; charset="utf-8" From: Stacey Son Implement t2h_procctl_cmd, h2t_reaper_status, h2t_reaper_pidinfo and h2t/t2= h 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; } =20 +#include + +static abi_long +t2h_procctl_cmd(int target_cmd, int *host_cmd) +{ + switch (target_cmd) { + case TARGET_PROC_SPROTECT: + *host_cmd =3D PROC_SPROTECT; + break; + + case TARGET_PROC_REAP_ACQUIRE: + *host_cmd =3D PROC_REAP_ACQUIRE; + break; + + case TARGET_PROC_REAP_RELEASE: + *host_cmd =3D PROC_REAP_RELEASE; + break; + + case TARGET_PROC_REAP_STATUS: + *host_cmd =3D PROC_REAP_STATUS; + break; + + case TARGET_PROC_REAP_KILL: + *host_cmd =3D 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_a= ddr) +{ + 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 ar= g3, + abi_ulong arg4, abi_ulong arg5, abi_ulong arg6) +{ + abi_long error =3D 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 =3D=3D 32 + /* See if we need to align the register pairs. */ + if (regpairs_aligned(cpu_env)) { + id =3D (id_t)target_arg64(arg3, arg4); + target_cmd =3D (int)arg5; + target_arg =3D arg6; + } else { + id =3D (id_t)target_arg64(arg2, arg3); + target_cmd =3D (int)arg4; + target_arg =3D arg5; + } +#else + id =3D (id_t)arg2; + target_cmd =3D (int)arg3; + target_arg =3D arg4; +#endif + + error =3D t2h_procctl_cmd(target_cmd, &host_cmd); + if (error) { + return error; + } + switch (host_cmd) { + case PROC_SPROTECT: + data =3D &flags; + break; + + case PROC_REAP_ACQUIRE: + case PROC_REAP_RELEASE: + if (target_arg =3D=3D 0) { + data =3D NULL; + } else { + error =3D -TARGET_EINVAL; + } + break; + + case PROC_REAP_STATUS: + data =3D &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 =3D target_rp_count; + host.rp.rp_pids =3D g_try_new(struct procctl_reaper_pidinfo,target= _rp_count); + + if (host.rp.rp_pids =3D=3D NULL) { + error =3D -TARGET_ENOMEM; + } else { + data =3D &host.rp; + } + break; + + case PROC_REAP_KILL: + error =3D t2h_reaper_kill(target_arg, &host.rk); + break; + } + + if (error) { + return error; + } + error =3D 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 =3D h2t_reaper_status(&host.rs, target_arg); + break; + + case PROC_REAP_GETPIDS: + /* copyout reaper pidinfo */ + for (u =3D 0; u < target_rp_count; u++) { + error =3D 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 =3D 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 =3D do_bsd_setpriority(arg1, arg2, arg3); break; =20 + case TARGET_FREEBSD_NR_procctl: /* procctl(2) */ + ret =3D do_freebsd_procctl(cpu_env, arg1, arg2, arg3, arg4, arg5, = arg6); + break; =20 /* * File system calls. --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666434; cv=none; d=zohomail.com; s=zohoarc; b=LgwZJm1CTjB/CdUZexn8KF5L6xzTCO51xUINuDMM5dwzk68k0tgu17I5rD40iV0O6SHP2kchLAmdD8+X4wgSmlgaoNVKfIdPrcnFMz1G2yi+iaaVs7pUKpyVaAIV/lwCk5BSJfPCQPxfn0Jtu5IOYo0GDrH6NgY7vmCANsaVR1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666434; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3vvWAJOaU9svMDhrs7MJr+20FyL1xi564pnSJRDac5w=; b=WzwJAcPyuUaw60C/PQMQHgLd843yxY3Of2UfAI9aiFm5uxQohJSXR2HtnBOr0hXbZ1QyPjynyR47MeKhvhtJasO5SUkl48q5ezJBBjwdB/XY44GkkuXL4KbNiOgZeqwhh8XUArpTjYEnblvc6I9ho6Xr0DF3Yx5icXYJiIzSUlM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666434203778.1253319876971; Mon, 25 Sep 2023 11:27:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHr-0001NT-My; Mon, 25 Sep 2023 14:26:27 -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 1qkqHn-0001MA-UT for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:23 -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 1qkqHl-0007RG-VY for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:23 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-32179d3c167so6066087f8f.1 for ; Mon, 25 Sep 2023 11:26:21 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666380; x=1696271180; 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=Xd6vGa/Dx2WKjt1nyHC/cpgPfkCgBMgBlycYcRYWegm2Lmp3ippmY5hOXsq4UuOU6G gBldAefS6ACRjU7mGL6vSQmlxVz0cNXGsgqNYLzcJ01spIs/3wX09pGFQ8EbhomjuWkK FcutebLWGJ/DPEsFfqLmNmUmidWc4kkMVPReAvR2fbejDHvCFV5oCZiOvKnBYTx7rUqm 0XEUDYJ9PDGp6m5NlG+QOWOA5SqmQm1SSmpZrEtUTxffexvLgtT3iv8+dnly/cGo5RTX XP0xTGgLkuGY5DVNe4iagpJI2YeoVaU8Osv+7fOucb1KWJhDvsZW67X8dk0UiIGrpOAw 7ymw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666380; x=1696271180; 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=sVuIxIZwGPZDdVIosl2go9ouF8na+cBMoK0io7iw0VJwiuN6n0k6kOI4wd2w2z3XTj HptBFqFSoAZGv5T62KLkitVUTBK8TbFfkAYVbuRNfSxdVEK/U+V0knh8tYyqWMER5e0t JAKEEDVh+hxO06quTZc1u2KAyYz9k0yAO3ntzEAVS7kIGaDomn/GfmOQCEOw0Knsaunf 3rGD6+4Zcye8Wff5W4jHBhTuPweiZ76AMBENlFsi4PuDrESvTVmdeaWCZNDfA0TCmEcu RqgZV6l3dgj8nERQXWdpRArA2odg3zHxfQDEW7i3HukdXuIoUxZ47guFa8cEPHUjo4cB +EAA== X-Gm-Message-State: AOJu0Yw4S2hkLVqYlrv7a7zNh4+wccm73a4vob2hGM4H09q9G5XFXeDL 9h4d0lpXOkber5ufvYf6AVhy7lde5w8= X-Google-Smtp-Source: AGHT+IEhmhJyOA2pQX399BN6e0IIBqc25bRR89CY7VPw4pbAizlxuLKyfl7ACDmPwxiHrI/gN1FObg== X-Received: by 2002:adf:f9ce:0:b0:317:55c:4936 with SMTP id w14-20020adff9ce000000b00317055c4936mr6811624wrr.9.1695666380033; Mon, 25 Sep 2023 11:26:20 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Karim Taha , Stacey Son Subject: [PATCH v5 22/28] bsd-user: Implement execve(2) and fexecve(2) system calls. Date: Mon, 25 Sep 2023 21:24:19 +0300 Message-ID: <20230925182425.3163-23-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666434513100001 Content-Type: text/plain; charset="utf-8" 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 a= rgp, + 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" =20 -/* *BSD dependent syscall shims */ +/* BSD dependent syscall shims */ #include "os-stat.h" +#include "os-proc.h" =20 /* 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 =3D do_freebsd_execve(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_fexecve: /* fexecve(2) */ + ret =3D do_freebsd_fexecve(arg1, arg2, arg3); + break; + case TARGET_FREEBSD_NR_exit: /* exit(2) */ ret =3D do_bsd_exit(cpu_env, arg1); break; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666561; cv=none; d=zohomail.com; s=zohoarc; b=Nt4PB6NlIe3K8hBdpGSa82Jt5lkFCAfgdml/BcY/HU5WCicz19YcSr8Wy88eFFrIyW+ONnUdpMUY4nRgDBlDA3i9+wmq4+ICiXCULReKjA6fKNiFQfvw2XHjzbexLn3KpBnlnINJyHwr2ikdrnYbdrmYBJXQUAYAbCZF0MvB3NA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666561; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oNRGUiedGrBZcKnPVe6hDv+7hpOHxkGwTyAPpB6vPFU=; b=gfT9paf5OGgrbHH8FhytoWAh9oIpMSG0xaamf2LMO+dxSl+7YMwVjwBIEGFgPM+XPgxjobayw34r13RLXM6KOEmVgXUNnROZkxdgKfVl4DKlqxVy5y48c3u2isnN0rSkJLr/sp2OYZw5OdNjpVKQjJ/FMsgpfCesHXTv4WX0wvU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666561968304.34928672173464; Mon, 25 Sep 2023 11:29:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHs-0001OB-CT; Mon, 25 Sep 2023 14:26:28 -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 1qkqHp-0001Mm-Bg for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:25 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHm-0007RM-UV for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:24 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-405524e6768so48216815e9.2 for ; Mon, 25 Sep 2023 11:26:22 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666381; x=1696271181; 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=oNRGUiedGrBZcKnPVe6hDv+7hpOHxkGwTyAPpB6vPFU=; b=GWUz0QnZlA0ay2vlcXcDCep5xC7cPSFuxvUkBqNTPXd+gkJK6DDerwTOyLI0+k+JIr +a/u0vz2XELiIz9tAQeCV4WKR1ZpwteKYCrB3MCtaIPl2CekbDqpFztSC9HC/rYSdLuC gILvIR6BmDDUEbsZN9Pz7kuGqbeyFZaOFtsNOfsBOW4JfrickbFNuir+c+HFUyenW/R4 pBkNA3noPONxuy3M1cSV0dsG8Sjp6v5rm5nx3dls+RTQoc1xj4305lcCvtr3mVp3DJEw y1pvC5pXa5dR+zn0ILv7DJTPcJicXo4lpSQpNe5OD8DdfUvpTthqJqmflFWFeLHWGbyL UA5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666381; x=1696271181; 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=oNRGUiedGrBZcKnPVe6hDv+7hpOHxkGwTyAPpB6vPFU=; b=vrOWwZnliHgEpwv/J9reFxkGw1YTePU+axYqo+LvYSIDFO4cU4Wl2wV8+zfEq4iyeZ Ai/KvkudQyb5jQr/+LoXkxnCjarSBl2zOQtc7pIPHs8SaHzbpLeMRJ0L0OPblRywts8c gLlwgJkMhb6WWG5pxZYA7R6Z5loZ3JejyqEYg3OyDgBgSc9ETGGx4urIs/rM9RohwkqS kB5aZK3bxAxZgLuOkkDjKuwJP9TEQilbLllcu/GiBbJzgrWLtDo1iYkznrP/4ZWj0gqn l1q0WE9kRWrwls53t/dvIDPbWJLYzWjUQKIgx1OymS1N4dztjhtfElKtn6f6TSnCymP0 O1XQ== X-Gm-Message-State: AOJu0YwudM2FxRDhhvDhE9POC4pAwZ8uYFh0LAD17t5SCC8nIouwsYsC PULVij4MXBR+dT/gjIw46lfxPL/c/WI= X-Google-Smtp-Source: AGHT+IFrOYBFO0PAnzCDsre5dDUxm/YacSi2+6DpdT9fj+L5wFAZuxDuGoivS6RRa/KGachvNI+QZg== X-Received: by 2002:a05:600c:2215:b0:402:e68f:888c with SMTP id z21-20020a05600c221500b00402e68f888cmr5954438wml.7.1695666381284; Mon, 25 Sep 2023 11:26:21 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 23/28] bsd-user: Implement wait4(2) and wait6(2) system calls. Date: Mon, 25 Sep 2023 21:24:20 +0300 Message-ID: <20230925182425.3163-24-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666563343100001 Content-Type: text/plain; charset="utf-8" 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 @@ =20 #include "target_arch_cpu.h" =20 +pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusa= ge); +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 a= rgp, 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); } =20 +/* wait4(2) */ +static inline abi_long do_freebsd_wait4(abi_long arg1, abi_ulong target_st= atus, + abi_long arg3, abi_ulong target_rusage) +{ + abi_long ret; + int status; + struct rusage rusage, *rusage_ptr =3D NULL; + + if (target_rusage) { + rusage_ptr =3D &rusage; + } + ret =3D get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr)); + + if (ret < 0) { + return ret; + } + if (target_status !=3D 0) { + status =3D host_to_target_waitstatus(status); + if (put_user_s32(status, target_status) !=3D 0) { + return -TARGET_EFAULT; + } + } + if (target_rusage !=3D 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 =3D NULL; + siginfo_t info; + void *p; + + if (regpairs_aligned(cpu_env) !=3D 0) { + /* printf("shifting args\n"); */ + /* 64-bit id is aligned, so shift all the arguments over by one */ + id1 =3D id2; + id2 =3D target_status; + target_status =3D options; + options =3D target_wrusage; + target_wrusage =3D target_infop; + target_infop =3D pad1; + } + + if (target_wrusage) { + wrusage_ptr =3D &wrusage; + } + ret =3D get_errno(safe_wait6(idtype, target_arg64(id1, id2), + &status, options, wrusage_ptr, &info)); + + if (ret < 0) { + return ret; + } + if (target_status !=3D 0) { + status =3D host_to_target_waitstatus(status); + if (put_user_s32(status, target_status) !=3D 0) { + return -TARGET_EFAULT; + } + } + if (target_wrusage !=3D 0) { + host_to_target_wrusage(target_wrusage, &wrusage); + } + if (target_infop !=3D 0) { + p =3D lock_user(VERIFY_WRITE, target_infop, sizeof(target_siginfo_= t), 0); + if (p =3D=3D 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" =20 +/* 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 =3D do_freebsd_fexecve(arg1, arg2, arg3); break; =20 + case TARGET_FREEBSD_NR_wait4: /* wait4(2) */ + ret =3D do_freebsd_wait4(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_wait6: /* wait6(2) */ + ret =3D do_freebsd_wait6(cpu_env, arg1, arg2, arg3, + arg4, arg5, arg6, arg7, arg8); + break; + case TARGET_FREEBSD_NR_exit: /* exit(2) */ ret =3D do_bsd_exit(cpu_env, arg1); break; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666606; cv=none; d=zohomail.com; s=zohoarc; b=gkxyPhxtAw6sjKKMi8wX8AHUStyBlNW5j2JB/GEjqNahNTipJHTPvP1uypcQwtZjKrpRhGUcG4NzZcqG6UNu/pkPz3y6bWBtITlhw/S5DVuNRhKB++Xb3yMrPui5bqE78JCHN3auKJBnlMcfom96HoFCtYnyYjRuSfItSUYKNiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666606; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PyM+L5pDaFr2bIbdcn+AZXO2bqBFg5Oap17M0Gq1JLg=; b=ZP+vytD63TvvbTPaXavPcPJMOO0H7MSPsgXwYwPpcIqmi9gbE0V/Tq97OGUC0eTF6tC1muoaPHxrQR/9U2cCyET0Kqvh/DjTGxKeyu83xMYHPc3VsPTt4WKY64roSCRG4FxL1gxIjbsMZlAZnGf6NejOIjalPG9bvPnYXZNkL8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666606490492.10977879182644; Mon, 25 Sep 2023 11:30:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHs-0001OK-VC; Mon, 25 Sep 2023 14:26:28 -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 1qkqHr-0001NJ-5n for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:27 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHp-0007Ri-4O for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:26 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-404314388ceso76769605e9.2 for ; Mon, 25 Sep 2023 11:26:23 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666382; x=1696271182; 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=PyM+L5pDaFr2bIbdcn+AZXO2bqBFg5Oap17M0Gq1JLg=; b=E2abJttN5wuu7dVIojnwBKQS5frlFPfiGRNu5lTbbcB5qZ20M25IYae73yIbQroxSI fM7+HLd7NSZGhJN+48hggcYEBgiqrXP3QrL0Ou3kMyz+kkduq77NZlPZfhrFOZsxjtHg lZDFPfK/i5FpQ70JdUeS3S3FbGO1e2XhS5BfItuUS4Y65wZKW8BG+an/Fvu+x1cg2AQf gjSzLb8R/tMLN6GW3C0FDLZqcqv/HWEJMkybsiquFaSf9yntvBToCJ4i39sxxi4sF7iz qJMKCz0ClJ8TVqkkWyVAp5i15ZEWGuHfmPR4DDv1Oy3Khlun0/Ebo0cVxRMAXq4AJ7yT wqYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666382; x=1696271182; 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=PyM+L5pDaFr2bIbdcn+AZXO2bqBFg5Oap17M0Gq1JLg=; b=Q0Ij4ewg1eaUTS2iduxADZMEPgjPZ+SF1jJ0kCDXcf9903npIwXSogYQ3YjQ8y59Ag pGffnhWJiGETAA60IgkSSeL3STTGpMEWnHsoKZKp5v1WQhfywiF8UQUvsOTKleJXclg+ mx9RXMq5Zhu9FeyAnT3q54VC0/rHnQLRiWDZ1vu9Rot5BTOyr067tRobOfHV3SwI1Rvb 9SjW48ieCULqrrB6+2iMVcQAeemqnY2CbhHIu9+DlddctMMXbvLFZ6333jpBVKA01s/P gAWiLIFLip//CmyNOp3my9krrRX5eO+YCODtsZ+a9t2e4TZW2c6ihntDHfNYgs4gKpPl 6FiQ== X-Gm-Message-State: AOJu0YyA8Wf46ei2M/IOxHgKBlQaU/vJWKi72iu0Ez5U4c3X4Dx/RleD m7DDkZdMic3dwKKTwvvlR8lEk/FyQAM= X-Google-Smtp-Source: AGHT+IEkHbYuTgHWv+mkxtanFD6QdU5w9dG2k7sqRIHUi0i4bjFfuKLWTsEA9mYuRVa7ui3Q5Q45nA== X-Received: by 2002:a05:600c:895:b0:405:95ae:4aa7 with SMTP id l21-20020a05600c089500b0040595ae4aa7mr1858609wmp.10.1695666382481; Mon, 25 Sep 2023 11:26:22 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 24/28] bsd-user: Implement setloginclass(2) and getloginclass(2) system calls. Date: Mon, 25 Sep 2023 21:24:21 +0300 Message-ID: <20230925182425.3163-25-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666608647100003 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* setloginclass(2) */ +static inline abi_long do_freebsd_setloginclass(abi_ulong arg1) +{ + abi_long ret; + void *p; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D 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 =3D lock_user(VERIFY_WRITE, arg1, arg2, 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D 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 =3D do_bsd_ktrace(arg1, arg2, arg3, arg4); break; =20 + case TARGET_FREEBSD_NR_setloginclass: /* setloginclass(2) */ + ret =3D do_freebsd_setloginclass(arg1); + break; + + case TARGET_FREEBSD_NR_getloginclass: /* getloginclass(2) */ + ret =3D do_freebsd_getloginclass(arg1, arg2); + break; + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ ret =3D do_bsd_utrace(arg1, arg2); break; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666565; cv=none; d=zohomail.com; s=zohoarc; b=CmrKv18m171SyV38xGeWyTtfrjpb9oRHU0WPbs9gOeeu5zIeuTOcTM6hFhJ8evhDv2sQoeDQasBXwmrB2rb9g4LhIZohbvoiJs8Vr5iuUgBJ16RMvb3e3otk2uyE2UkDB0nZRzUPi7TMXrjcPi59n1jLcxDNOuJCTfkHUoaoLmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666565; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ui1+qIKrTBmzcr3qsqV9UD7vfUvAao2pDCb7RttOZ4I=; b=VoV3fwEBckF5c+f5ni7k+z4YDPEWjE8ip4/pxE0d0iwFr1NYEbKLinPx88vkCcDgpoFI7ctH9HAADwXK/22rk4QN+VOQWAhKc0d1f+yj6zzJ/0NltMRCbl/CaWH7uLrCS7d+ViAQ8QUbDNXpS3Kks+ouCRUsBkmyWnU/NKxibMo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666565062960.9167121641772; Mon, 25 Sep 2023 11:29:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHw-0001P6-6C; Mon, 25 Sep 2023 14:26:32 -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 1qkqHs-0001OD-JH for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:28 -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 1qkqHq-0007S1-Uc for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:28 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40537481094so69792035e9.0 for ; Mon, 25 Sep 2023 11:26:25 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666384; x=1696271184; 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=Ui1+qIKrTBmzcr3qsqV9UD7vfUvAao2pDCb7RttOZ4I=; b=W6oJHPFOIuphTNRhXbhRLTofCTATYEcIGvW+6i+on63Na3ryUODozVBp4chHtANES6 wLfFjpHyIUkQfoLEOHgFDKejUipKCgnx2Nf9yngvcJQM9u90x0mDYCBKiWTp6Z0E0AM1 UUozN8h3WzDCvZf6wLzXyg31t5+SBFeaMr/246sf1U5oe3glhOKd5a/+KkU2hh4JprA7 4VjCScWPk4vIG/q0F7Sma7c+6EwVKLZBkndx3MN0bYcnscpa+aNrwu9pYVGN5hgqxSDo pD26OXkuURo3cAqKZj9gDhdr6kJdXCK/hZ8vuNZEgQsPu1tfHBm/caMNDJZMbe0RardY 3FwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666384; x=1696271184; 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=Ui1+qIKrTBmzcr3qsqV9UD7vfUvAao2pDCb7RttOZ4I=; b=humkFKIvRp7Y2wFPwsuIJ3UbU9dlfVHMuQuKkprekZFLQrLULiMemi0ixGcaCPxs0i H7444jCZLnwg173pasjllDWJUC0PHp4ngI4q5ypo1yF8aCciNdbS+GPoXgn5ULzYaZDm p7pwho4rcSrttDEgM0n3MtUF483ioQkM8XMz4V0K5SHPTnN9Mep3Oa0+aL0mRuURaa/O Rf2gSZkU1nT9crznv8vunr7KE7mgK4d5Uorb6H3qpVd49LhnWoeEkpwzzn5iY1N4IUSZ PwOxst8OmVZlAiqhHuc/F11gFRv/Z9wjU4waPsJL0nva9Dvi9X24yf/2SMXaQgogOQ+4 2E8A== X-Gm-Message-State: AOJu0YwlJ2w5tmUEpQGyGKuC4s5gMCbW7A3v9ZOibmC/GiHmrv/mQlZJ L715lz8WCKSgjavJPHRxScU4Zq+iWZ4= X-Google-Smtp-Source: AGHT+IFC1k4RisdKNAi8Fa2MlLPSFM9sBnMRLYrZo0iO1eb0YGsCjYqjF2yW/2IvQ8LEynV+X/Pwlw== X-Received: by 2002:a7b:c847:0:b0:401:b652:b6cf with SMTP id c7-20020a7bc847000000b00401b652b6cfmr6969590wml.13.1695666383698; Mon, 25 Sep 2023 11:26:23 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 25/28] bsd-user: Implement pdgetpid(2) and the undocumented setugid. Date: Mon, 25 Sep 2023 21:24:22 +0300 Message-ID: <20230925182425.3163-26-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666565308100017 Content-Type: text/plain; charset="utf-8" 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, st= ruct rusage *rusage); pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options, struct __wrusage *wrusage, siginfo_t *infop); =20 +extern int __setugid(int flag); + /* execve(2) */ static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong a= rgp, abi_ulong envp) @@ -162,4 +164,25 @@ static inline abi_long do_freebsd_getloginclass(abi_ul= ong arg1, abi_ulong arg2) return ret; } =20 +/* pdgetpid(2) */ +static inline abi_long do_freebsd_pdgetpid(abi_long fd, abi_ulong target_p= idp) +{ + abi_long ret; + pid_t pid; + + ret =3D 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 =3D do_freebsd_getloginclass(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_pdgetpid: /* pdgetpid(2) */ + ret =3D do_freebsd_pdgetpid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR___setugid: /* undocumented */ + ret =3D do_freebsd___setugid(arg1); + break; + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ ret =3D do_bsd_utrace(arg1, arg2); break; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666434; cv=none; d=zohomail.com; s=zohoarc; b=kiGugJWMlaNs3O9Gxe6RiEO4K9aFsDDmTzs2opr242oQZBwP/vmpiGvLaA3P3MbkCEAlu1XhDXlsEYHegNk7EFnCxNoQg4jhhxn5Ab5S3I1h+6HAJenT5I3tym2oLqxnQQrz3FjsLiViSy6P69OZFGVyUZFFBRjN2aQURTqxo7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666434; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ApAZc94aZDAcSIMEKeIK9l509Mfqm71ecKv5+mWNoME=; b=gnJY/vfq99m7uN+5dKYy7bWPzhTDu+llrhs7a7HWD9RQnOmAIxZHd92B+mwcK64mNIe2pw6EX/KD5dHS4PQCMLPbH03MqGQokr2Br2J1Z3bsBZjNFl9eYeme1NAIUOOuOJyMOT1HG7FqO4psTDeiBVZB1KqRRHdoXQ0BmhckQgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666434568386.2960041231263; Mon, 25 Sep 2023 11:27:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHz-0001S6-3v; Mon, 25 Sep 2023 14:26: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 1qkqHt-0001OQ-Jt for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:30 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkqHq-0007SQ-Ut for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:29 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-404314388ceso76770205e9.2 for ; Mon, 25 Sep 2023 11:26:26 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666385; x=1696271185; 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=ZBfivFyWTUlQpM+Z5j2mb6vt7xR8RxuFXpRQ1GBghGAqHL/UxZ5yy496h8mVfAOGyn bvw5AmZ5rvJkcL0EbYLzc4DdQPdIh3OLjHA0cDCYQObMmT2dQlSOGZ9v7FpBEMfVaLdv p7wQD+PkXi/1ncavn0aXT99SqSfyHcKjD0cG3KlCAOco85Y5pwuxKBKT/6BLOlPuEZNc jtV62bHOmpPbEElkL39tb0XUcVsn2CyZFWLzA4oIAl8ckCdNpTeVwp/Py2Fq907SecgI qIoVvPKIkwe2SGMRn+A+pAbYT+p793Vap+wAYtI+xvd83fiqW5e4tjJo9bZMMlk7CwSD DmsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666385; x=1696271185; 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=UpAIfRrh7cQVWoNAiN63y5jVv7Bq3jFFvTteGTIh9yTY2SEx/ngJNipEP79nD+HWHX H4emu4qDgfm2WCLMKQiQ42BnXimZRa1dxnv81AV/UFafC0x7KnlkGWuys2/TmaLPXzoT biDod9RR/MV47bf+rc8Fit5xagiK/nkPPK7xzy2c7uMHJAHS6nmIceoZq7X+SQ2b88S1 Pgg2ikxnr+oPCWRVCZI1eulu64KjnTgDRYXAZJE80asOfI4Db/UHVX9Gx7vL/fgVQnPK /CiCebz3Oe1lkcEkXiwSVw7kMS8phfulPNGSUh8VnMbH1MDlpUfrmw8PCbleoNznCIUN dyHw== X-Gm-Message-State: AOJu0Yxr5wUra4uqSljr8AepvCLhJb4U8fKh5q9oVbzuQp8M9uPAlK4Q kGT1J4brdnm0Oj9+C3XPQaIscDurT1s= X-Google-Smtp-Source: AGHT+IFzIrpeSgOnqMf+3eXVlAdHWULE0WFf0PYt0UpUl5IdObGLvVmFoQunz06W35QEKHB4tXiTJA== X-Received: by 2002:a7b:ce10:0:b0:405:3d04:5f4c with SMTP id m16-20020a7bce10000000b004053d045f4cmr6470151wmc.38.1695666384933; Mon, 25 Sep 2023 11:26:24 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 26/28] bsd-user: Implement fork(2) and vfork(2) system calls. Date: Mon, 25 Sep 2023 21:24:23 +0300 Message-ID: <20230925182425.3163-27-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666436697100007 Content-Type: text/plain; charset="utf-8" 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 a= rg1) return -TARGET_ENOSYS; } =20 +/* fork(2) */ +static inline abi_long do_freebsd_fork(void *cpu_env) +{ + abi_long ret; + abi_ulong child_flag; + + fork_start(); + ret =3D fork(); + if (ret =3D=3D 0) { + /* child */ + child_flag =3D 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag =3D 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 =3D do_freebsd_fork(cpu_env); + break; + + case TARGET_FREEBSD_NR_vfork: /* vfork(2) */ + ret =3D do_freebsd_vfork(cpu_env); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret =3D do_freebsd_execve(arg1, arg2, arg3); break; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666460; cv=none; d=zohomail.com; s=zohoarc; b=VJCL1duw+ZS5gGWRLbPy0UMyElgHxFf28L84U4n8c8v6JnqN5ec44v/XEv5N52Y1B0iO5Xz2RSMPBYZEu4QplLy/pUiXoP/QZ/ryxIyQpCI+hcphpAsof6hhmvdewJCVZqYNAu3UuxZ99oHd5dXb07xX+/XDCuUGtbNdHyYTHa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666460; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rpy9YRc98hoKi4x0RvdoeeuQK0Rj8grNwDEdhtMUgjI=; b=bE331azI9m4FLNwZftQ9XEBgojce36RzHBhEsDscHno+5a5ocK5NFCsJYO8pybU4DS6NPVy4J/bklAqSoD1jecTK+5JacijQido4oBIkF3NxhGIDd/Z5IDF6iLxQKLHRSZBHCwkrPX7ZfV6Smhz6ubd1NUC+GqCwbJtiMZ3RgPI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666460707658.3775447404503; Mon, 25 Sep 2023 11:27:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHy-0001RR-Hz; Mon, 25 Sep 2023 14:26:34 -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 1qkqHt-0001OR-MI for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:31 -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 1qkqHr-0007Sd-S6 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:29 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4053cb57f02so58796915e9.1 for ; Mon, 25 Sep 2023 11:26:27 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666386; x=1696271186; 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=TIiuZnYtv/eB/GWP3XVXBT/2Mh32I45MArFaLua0NYlfleNSg4+vXtV2WabxJanVM8 kYrx0o/5Up63xduo7EtHeAFaNNpu/tNFdOlf2NoNSbFuAtruq20AWLeNx5MdDtXb8zAP BZpomQXgPKEZMDguPexK4wultoNKw8sA9aZZfw068zLqqhZ46JojPfa3nqGuMOqjFF8J c9YkLBBa/l1ArA+58VIW1gye6DBA4aFpr527kzjxEQZRaKiaSjPA12p0xcvv7WgFHz91 sHzRwbfIyFbFR40O5gL13RzsDDw4iwgI+7a0J8eLimN2+gAYZtbkess0Bv9L1Jhva960 HE3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666386; x=1696271186; 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=rk0I0w5HjSstJpHsRBsSzEd7DpceyU8GxkwvnkLv10z/7OqpxDfwU8lj4LlXMd7qDC ObNa+0K9LdCyhPQvPW/1JjJWJifytF0YIDVVoCCP22+E0MQAgRICAH3lr7wQMZtRL/Ju 4JShOH42FmwGyQAM1q1ly02umUY5sk9lYTB+Vca9TLzNiqXPoZgRdr++6t+Uaf+PB9um AKTJ2GIBt0nYYhBVSpP2M8lYiFagzfh3O415oxt8drY7jU25Us+zoflQKDqaXJRbli9i n2nbmlhrGJcqURoDXof/jNZOPbCp2JO7yC+x9p9V9pNLJfxIB6ZctPZZ40rRhKQBt6QZ gqXQ== X-Gm-Message-State: AOJu0YzChQw/51QE342itMejNXhHzO9CjljS4OH8eYg6J+b3R8v72Xk8 Y98jEfu4z/5zGVzM1B8nC2gohyg3h10= X-Google-Smtp-Source: AGHT+IF1YcMQfeuq6FHDnIqi0tZ96rV5f1wue2Ta3aNCZMP3N9X+Fh7FkazXiz17oao/KyB4+zdUkA== X-Received: by 2002:a7b:c456:0:b0:405:39b4:3145 with SMTP id l22-20020a7bc456000000b0040539b43145mr6859079wmi.2.1695666386257; Mon, 25 Sep 2023 11:26:26 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 27/28] bsd-user: Implement rfork(2) system call. Date: Mon, 25 Sep 2023 21:24:24 +0300 Message-ID: <20230925182425.3163-28-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666462180100001 Content-Type: text/plain; charset="utf-8" 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); } =20 +/* 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 exe= cute + * 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_sp= awn + * and it will fall back to classic vfork(2) if we return EINVAL. + */ + if ((flags & TARGET_RFSPAWN) !=3D 0) { + return -TARGET_EINVAL; + } + fork_start(); + ret =3D rfork(flags); + if (ret =3D=3D 0) { + /* child */ + child_flag =3D 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag =3D 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 =3D do_freebsd_vfork(cpu_env); break; =20 + case TARGET_FREEBSD_NR_rfork: /* rfork(2) */ + ret =3D do_freebsd_rfork(cpu_env, arg1); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret =3D do_freebsd_execve(arg1, arg2, arg3); break; --=20 2.42.0 From nobody Wed May 15 09:22:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1695666468; cv=none; d=zohomail.com; s=zohoarc; b=JPWAirh4fI2y9VI1iDBYjWAMMrz/M7fuRzYQK3c5jvwHYMQStDBhIk32IT8Rl0Dh39NHQS2eMxrRTnsN2HKpMTXUl1qyF6/q2+CM89rWE6JKqAo7Un8M/nc/TJzeE+D4LqcvRBgE4y0894Lq7AOdQB9kwBHGLq16MmcvMOmb6TU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695666468; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EEpfVHQYJiHs/o3VXa4xKMUM5FKYuciwQMorXR+KT/8=; b=WeJMrBrF6EFrdqXy0XV0Q8fgn/9n9ZfiyFDMsX3PUdfsm9kTiDSeHEeGmeaRVkusMANPEBl/n1R5t24cjvayINNLOpkXvr0fUPUJz5JCmqZwRljGPr9yqDjWTVSUTaxcQMhAHNhekE3OYF4bkcCFrRQKh5I0IXQOVXFe59VrYbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695666468247336.9551404679223; Mon, 25 Sep 2023 11:27:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqHy-0001R3-HQ; Mon, 25 Sep 2023 14:26:34 -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 1qkqHu-0001OY-R9 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:31 -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 1qkqHt-0007Sz-C4 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 14:26:30 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-405497850dbso51113895e9.0 for ; Mon, 25 Sep 2023 11:26:29 -0700 (PDT) Received: from karim.my.domain ([197.39.209.18]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b00405953973c3sm2232858wmf.6.2023.09.25.11.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695666388; x=1696271188; 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=aKhi0QAG4tG261DmFLKRxaQayxq2/6eenTYcaaArYL6C2WErMj4tApV21ctFotjp5z jVIaZ9br6wAlUGOpHPlEVXfF9XKlTmVOJGhg9YXu6+jXjqM1jU1pomZo1HcflG7FkUA+ 6JzpW/h5FVYTbiTqsYZx2QbsvUtVYwgF3A/Zw/V4vabhen43JRolHiHEv+T3HqxVqbFM PYRXC5xPtPKJcnnde38QYMalMeshJ3nercoFgXAOGkLt5vU1Vx03ZRNJ8/z0l+5LGUMX 9Hl6QGOnz2TaR9feZLYivzgQD/HHXwkpsKVVTSvpSN2zcGbKhwevdoeEpBEVA/tAPcw1 R/Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695666388; x=1696271188; 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=D2Es86lICNOla8w+3AVbiU2pTrIwx3aSE2G46KqzZR5irRHrHjuyluLxmucbtjhb1f BfBJl4JPfTCJ2DouQBF6gbSvPq60X6Ue2iW0cQujmGvT9qg9SuitgsIIX8MdPEhjtado HqmcdfsqAgsidAZTWV3Kuwz+phgi+l++5LWwYXEwQToxed9OL6kLrXF9B915tLD3gY/f neEdGBva+6DWT6xi7TgnutnC8UVXi2zA20gSHcUp3gMV9LpvKSYi+SB7CDvBojyhT83J bo2qIeu90Q7B+OaZSBOchUdhfnpQLoN7lp/tF7ukJtxjNpYj1bmf7kaFLBLzEunU+fHq vTZA== X-Gm-Message-State: AOJu0YwLzNqmbFakqO9QPcXLFCWPNbh4xYrInX37EC3maaBgJD0nf21Y gqOHY7cT/6MzUDzq2d6Z4TzSaKqRnus= X-Google-Smtp-Source: AGHT+IGLmlvUt9EqS8k4MlaUcLuFmVRb6plx4ex5f/4yxJ8YsiBUpsNK6jiEj24XyEPraiMk/7niCw== X-Received: by 2002:a05:600c:3658:b0:405:1bfb:ff14 with SMTP id y24-20020a05600c365800b004051bfbff14mr7379331wmq.9.1695666387606; Mon, 25 Sep 2023 11:26:27 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Warner Losh , Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v5 28/28] bsd-user: Implement pdfork(2) system call. Date: Mon, 25 Sep 2023 21:24:25 +0300 Message-ID: <20230925182425.3163-29-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925182425.3163-1-kariem.taha2.7@gmail.com> References: <20230925182425.3163-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, 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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1695666469426100011 Content-Type: text/plain; charset="utf-8" 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) =20 } =20 +/* pdfork(2) */ +static inline abi_long do_freebsd_pdfork(void *cpu_env, abi_ulong target_f= dp, + abi_long flags) +{ + abi_long ret; + abi_ulong child_flag; + int fd; + + fork_start(); + ret =3D pdfork(&fd, flags); + if (ret =3D=3D 0) { + /* child */ + child_flag =3D 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag =3D 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 =3D do_freebsd_rfork(cpu_env, arg1); break; =20 + case TARGET_FREEBSD_NR_pdfork: /* pdfork(2) */ + ret =3D do_freebsd_pdfork(cpu_env, arg1, arg2); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret =3D do_freebsd_execve(arg1, arg2, arg3); break; --=20 2.42.0