From patchwork Tue Oct 3 23:31:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93EBFE8FDBF for ; Tue, 3 Oct 2023 23:40:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnov6-0003vS-75; Tue, 03 Oct 2023 19:35: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 1qnov4-0003vA-7q for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:14 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov1-0006gW-71 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:13 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-79fc3d32a2fso60161939f.1 for ; Tue, 03 Oct 2023 16:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376108; x=1696980908; 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=IWdm+hDV/GXkOmrbOCDP//62BDkJTz7eQAUm8g6H/pk=; b=pI+p2q0DCqHgkfw+ntQpEWRSlMCXp3LiSgpL72dGfABdwbZoUGDwH9gbFysEpYZU4u hCBrbO/IRW3Kl3XZwSstIKduUV/bQJy0uN+YRvxZ0qsi+AldKCP8AYrxcZALj1pi3BF0 8+Jc47fRnXijRVEwbJ6s1ozCYEpWTfAsoTxrFwZ7mY2fpg6Gj80n+q94hC4cdmYephuP nmia7bBPRzlVcRaNJoPqKS24ff6UHJJSbsAWkbI8UQ//VdNceyq4CTpOr9Yn/RhUao5b GQ+W/RduAPA58t7ZCsmGEj7hjrAx8FZid9oWw9JZIJ3jyVwq6NWTerGtn0kV+QEG7a+f zQmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376108; x=1696980908; 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=IWdm+hDV/GXkOmrbOCDP//62BDkJTz7eQAUm8g6H/pk=; b=piGjBLWxo3Y1QoWVbFt5TPq8foJ7JN3Br8nQE3LRbcYYbUaDes8IPbWOfcaXJmacKg VCxkrFfW8nDMfbGa+jJNY3jHhGSzj9Q96hTe4AuD11Q15yDbnYbU7bUVAOFe+/ReQ1J8 v2f0IRYyGHNi3WZoLNnm5V2zydYqe7pW8mSOrUq0uxE+ld+6BrHkjYq72jlXpZLjp1Dl jNBX2TenjlUIbnqpfvc2n5koYtep1pJwpMWqvWjNaK6vN7pcuSh94UYVsDNWkc3Qw+kV 5DlWbwOXTIFPh/NDedi/rIMpm38ycGLU+P0+pYfuPN17hw/FtMmXNVKK3wB46wZ1jvyd UV1A== X-Gm-Message-State: AOJu0YwyRFD6eVFy5fGhUEKZTZ1e3HqQa5nqVZmaMibFpA4JVTnNBI15 wVHU3k5XBijF8RQu4cPw1h245hUhFiZ3Kubu6/r4gA== X-Google-Smtp-Source: AGHT+IE9dMWSyqEayfRJFF7JquFMLPPymh1C06GHHWp03sqM2FU/sMIM7lTCeGQw8g98Zud7MHZEhw== X-Received: by 2002:a6b:5b03:0:b0:787:1555:efca with SMTP id v3-20020a6b5b03000000b007871555efcamr977020ioh.5.1696376107841; Tue, 03 Oct 2023 16:35:07 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:07 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Kyle Evans , Richard Henderson Subject: [PULL 01/51] bsd-user: define TARGET_RFSPAWN for rfork to use vfork(2) semantics, and fix RLIM_INFINITY Date: Tue, 3 Oct 2023 17:31:25 -0600 Message-ID: <20231003233215.95557-2-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Karim Taha RLIM_INFINITY on FreeBSD, OpenBSD and NetBSD has value of ~(1<<63), caculated one way or another. Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-2-kariem.taha2.7@gmail.com> --- 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 9c90616baae..ddd38c13e08 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -130,11 +130,7 @@ struct target_freebsd_timeval { /* * sys/resource.h */ -#if defined(__FreeBSD__) #define TARGET_RLIM_INFINITY RLIM_INFINITY -#else -#define TARGET_RLIM_INFINITY ((abi_ulong)-1) -#endif #define TARGET_RLIMIT_CPU 0 #define TARGET_RLIMIT_FSIZE 1 @@ -390,6 +386,10 @@ struct target_freebsd_flock { int32_t l_sysid; } QEMU_PACKED; +/* sys/unistd.h */ +/* user: vfork(2) semantics, clear signals */ +#define TARGET_RFSPAWN (1U << 31) + #define safe_syscall0(type, name) \ type safe_##name(void) \ { \ From patchwork Tue Oct 3 23:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01715E8FDC0 for ; Tue, 3 Oct 2023 23:41:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnov7-0003wj-NQ; Tue, 03 Oct 2023 19:35: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 1qnov5-0003vL-JN for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:15 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov2-0006gd-4F for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:15 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-79fa416b7ffso60867739f.2 for ; Tue, 03 Oct 2023 16:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376109; x=1696980909; 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=u5huf7WpcMpMUeKt9etdLQ59Hm45g8cQi4QWAhrlxD0=; b=OzQdUBF4LXCL4QGdL4u2XDgWOQXOtMGJm7UOqTOJpVnUno1yFMXMYXIm5/2a3E4zYS 7xy4yr7WFMBsm7VDybiJenBPGeUjXqyJdci1vGqzMH902/e1zEyNTFYJ+WI74h+UTah9 8iNnve42P73nUllKDekReeR4IN5r448S6Kx523l43mEUoyocW/4Tg8oNAdM1WBe0qBqc ezpZS5a3ovjxUHypflSnDQH+empEgo0sz9yJvm5Oojs5rguThdRqmhJYLJxENmfbBBnc SsgN6kjNDkdWPfBauvvcgKCdH8pe7D/gvT31p+7/MjjpQDNbZ7KZEF5ZmNFXqY0YoWYB wqPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376109; x=1696980909; 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=u5huf7WpcMpMUeKt9etdLQ59Hm45g8cQi4QWAhrlxD0=; b=uUe0sS2uIdEWQQ1QdltsNjro20//pFO2GROBCFJ+83BzfqPYr7titjf73t10UdLAh6 Dbm7xlLdrNd0aFMepozVHSLdV6tg+KO1C1yuxJaVh6+9hJwN7TQ/+3xLnkhGFVP8sJ0g atR17RRuY2pCgzEWgc4mW9nSN6YTChWlxsTr0RBkWuwKBEIAvPyEU8Ez9vrswBA2O78z F2MOmxBzgvdem0KxO+VmaXVqiWzzua96UOiKUmCdgkh5EhTsK3NIO/6KcWNKNtza1L9n q7hxSwy9eGkzH9fUCYeIJPN5BPIB3rfea+Nm+1mtYdagOTR5nFiB+31isprvrmfS0UEi twVg== X-Gm-Message-State: AOJu0Yy/zrpfL9u2/WnItgbf6jU8ypqpx9uL/H7reevCLIW6dEGbCzBt yQmJ2K/1RTOqi0TBvdyH6tO67p37MT96pPiRS65umA== X-Google-Smtp-Source: AGHT+IFUJ122Ie9NCheR/OEg3UPU2Ta3L2B6lAXRj7/VLZ6ONiYOkhGZdjY0WNruVgsDFLyYfsI94w== X-Received: by 2002:a5e:8c0c:0:b0:795:16b8:85fc with SMTP id n12-20020a5e8c0c000000b0079516b885fcmr1004957ioj.0.1696376108730; Tue, 03 Oct 2023 16:35:08 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:08 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 02/51] bsd-user: Define procctl(2) related structs Date: Tue, 3 Oct 2023 17:31:26 -0600 Message-ID: <20231003233215.95557-3-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Implement procctl flags and related structs: struct target_procctl_reaper_status struct target_procctl_reaper_pidinfo struct target_procctl_reaper_pids struct target_procctl_reaper_kill Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-3-kariem.taha2.7@gmail.com> --- 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 ddd38c13e08..a3bc738ff89 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -390,6 +390,48 @@ struct target_freebsd_flock { /* user: vfork(2) semantics, clear signals */ #define TARGET_RFSPAWN (1U << 31) +/* + * from sys/procctl.h + */ +#define TARGET_PROC_SPROTECT 1 +#define TARGET_PROC_REAP_ACQUIRE 2 +#define TARGET_PROC_REAP_RELEASE 3 +#define TARGET_PROC_REAP_STATUS 4 +#define TARGET_PROC_REAP_GETPIDS 5 +#define TARGET_PROC_REAP_KILL 6 + +struct target_procctl_reaper_status { + uint32_t rs_flags; + uint32_t rs_children; + uint32_t rs_descendants; + uint32_t rs_reaper; + uint32_t rs_pid; + uint32_t rs_pad0[15]; +}; + +struct target_procctl_reaper_pidinfo { + uint32_t pi_pid; + uint32_t pi_subtree; + uint32_t pi_flags; + uint32_t pi_pad0[15]; +}; + +struct target_procctl_reaper_pids { + uint32_t rp_count; + uint32_t rp_pad0[15]; + abi_ulong rp_pids; +}; + +struct target_procctl_reaper_kill { + int32_t rk_sig; + uint32_t rk_flags; + uint32_t rk_subtree; + uint32_t rk_killed; + uint32_t rk_fpid; + uint32_t rk_pad0[15]; +}; + + #define safe_syscall0(type, name) \ type safe_##name(void) \ { \ From patchwork Tue Oct 3 23:31:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1D36E8FDC2 for ; Tue, 3 Oct 2023 23:37:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnov7-0003w3-0O; Tue, 03 Oct 2023 19:35: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 1qnov5-0003vK-JC for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:15 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov2-0006gk-4X for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:15 -0400 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-79faf4210b2so57687839f.2 for ; Tue, 03 Oct 2023 16:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376110; x=1696980910; 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=nRg9pwrrUdH7ek792cGQPFuJ+z7VOTPX+WRxVjZhFoc=; b=BprEymcq4J/buBWwmvCYsFvX3z86nNBh93UcKSzGdtGOYvmgCMBTKhJevYtz4DQri9 6i/VVY0jd3/ZHnsAN6N5c5kOWKE/DFikzNSzMgAP50XE8IDPaRoa+iZdXnfRnNk+j4By 4ukGXmHi9yBZUQkwH2Le/y9+GHR9cd3vQ6j11eQhZm8klN/q5d6Kwj9Jk07cW2A6SFKz Fvw1/c2wiiK6kZsNFlVcb9CosiHfd+6u4g3tF8Yq2CRLSUcy07DkfpV0tGdO/ZlCYTVn BLkNtw+kYJgi1sy12CcQQED9G3OGIXYN8HLnPfetiv010ig++lk6dWdQWPpnILdlgOnS oiOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376110; x=1696980910; 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=nRg9pwrrUdH7ek792cGQPFuJ+z7VOTPX+WRxVjZhFoc=; b=PCTDT2AiXvZY8/XDK5XJci97cVnheupsjOzG8flNH2hK9OQNdgRXSTTkTnjlrHMEkZ 7t7W/UTwRqo6Y6l0QB634JXg1TVlPV+Zd8/b+XyxyMw7CjN4SS9DXGzaapxAnvm8roVZ ETN8qsCvp3oTzcQ0feJpLCBEVq4pIWArzrHUH7AmIxeP7YUVxohTiPEAt+1M7VsBsRnN N7qD6DS0OBe9ahv6JV2Bm7tbZpekHA01rRDSQJN9rdO/bYrUtYDIGyJ1CkPv3FJR2EZJ ihX7iJs2nBcTg7uJjWJ7lrHPUfrRLrrwYxPeTP5rou8EAGw4XzANPuA2ZQ18jfo/ssBb laHQ== X-Gm-Message-State: AOJu0Yx6EhOPMW/o7xxElXkbENNYyNY3CUGBTh1EM5TIAGuzat97OjVy UwJpPj7f99j8xgPZEY+vFXRnT16flBPFqA5SPdlwtA== X-Google-Smtp-Source: AGHT+IFfBD717TINbasu/Asf5Ff90RhANH8U6G4QpdRPE6inx0tgqIKTOOiMk2Z2CnY0Ppoam7h/3A== X-Received: by 2002:a5e:c24d:0:b0:79f:e9ac:f60a with SMTP id w13-20020a5ec24d000000b0079fe9acf60amr861018iop.20.1696376109717; Tue, 03 Oct 2023 16:35:09 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:09 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 03/51] bsd-user: Implement host_to_target_siginfo. Date: Tue, 3 Oct 2023 17:31:27 -0600 Message-ID: <20231003233215.95557-4-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Used in wait6 system call Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-4-kariem.taha2.7@gmail.com> --- 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 c044e811653..77d7c7a78b7 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 b6beab659e1..ea82241b70b 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -311,6 +311,12 @@ static void tswap_siginfo(target_siginfo_t *tinfo, const target_siginfo_t *info) } } +void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) +{ + host_to_target_siginfo_noswap(tinfo, info); + tswap_siginfo(tinfo, tinfo); +} + int block_signals(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; From patchwork Tue Oct 3 23:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD3DEE8FDC1 for ; Tue, 3 Oct 2023 23:39:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovH-00045g-BI; Tue, 03 Oct 2023 19:35: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 1qnovE-00042x-3r for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:24 -0400 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov2-0006go-Sz for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:23 -0400 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-79fa7e33573so58980239f.0 for ; Tue, 03 Oct 2023 16:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376110; x=1696980910; 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=jzja6mNX65PpCCE06Mbtlzy3xvt/FsjtzuhPRGjLIms=; b=EqytJkaDM8SWnvM3CJX1ie4CpcfiRL+xluIA+rTFLy0b8Qtr6NzlvRNLCotygRyhMk 8aEkrVX3nb+QGEJVrFCPJSm4U2WAhGJcZK82PdsVWjnsnh+c10PzbKkILTqE6Ko1siFB j4L/qpbg/BZDO1uCGZHiUf/LMdZA4AevsIPjZ7Bko3JArENFOqY1ckoUem4rIrzUF480 IDWcn34e2s9o2F1C7WZ6Dendm1gWeHCInGUn+UyftXH0+jqf5Jd6P7kLW/Ij8h5qZSko v2lGEMbgIRgPsx0WeS0+vE/sAq7dg30WIPbnpPt1rCNlU39B4s3h6IlnyQKWtqNBitvc pKrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376110; x=1696980910; 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=jzja6mNX65PpCCE06Mbtlzy3xvt/FsjtzuhPRGjLIms=; b=MGrB1zAS+ynUp2uni3QU3tLH37shipc56RjiuShRqcWYOv57i5NLNhRgHJ3EJ8WsHO PEA+lKtsZB2Pg7q0axPBdiaH+lMUQgynGZTAN8s73Ox6VCEL/Tf+r2HIXBcD3IGDEtZv cpQa/BF/lQqk9brRwsDBAkLfGgm7ei9PeruKE+hykvQpWuDdxc8ddEK0fY4x4x8ldmK0 gb4Ifi57edxNoAUCYYaYuYR1DjOsA88/O7uqLBZF1N4NOPOwEWBNH620vcBEKgNCmGqI 9hKdrUnAY3sJGYCQm/KMv/z2bjb/IMPeQeO9oo/VvUAwXUY8xHLFXf6wgPGo77ekw3aD x8iA== X-Gm-Message-State: AOJu0YyAnB5fLovlLuSYmXDgnrtoUe4GTNUagEcIzokB6eq+yyXFN1iQ RAk5jtDaDnNrfe1uAC8ZZ3uSl7/s4dy472PRAsjvPg== X-Google-Smtp-Source: AGHT+IF/BCWCGZiB7eEc3AFzNcEWEKbSfeTt/NuYIOfecsuJkLwQ5ZIlvWL4WnLoEtwt1bddfPOkTA== X-Received: by 2002:a6b:6514:0:b0:783:550e:33c0 with SMTP id z20-20020a6b6514000000b00783550e33c0mr961383iob.7.1696376110631; Tue, 03 Oct 2023 16:35:10 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:10 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 04/51] bsd-user: Add freebsd_exec_common and do_freebsd_procctl to qemu.h. Date: Tue, 3 Oct 2023 17:31:28 -0600 Message-ID: <20231003233215.95557-5-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-5-kariem.taha2.7@gmail.com> --- bsd-user/qemu.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index d9507137cca..41c7bd31d3c 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -249,6 +249,12 @@ abi_long get_errno(abi_long ret); bool is_error(abi_long ret); int host_to_target_errno(int err); +/* os-proc.c */ +abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, + abi_ulong guest_envp, int do_fexec); +abi_long do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong arg2, + abi_ulong arg3, abi_ulong arg4, abi_ulong arg5, abi_ulong arg6); + /* os-sys.c */ abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); From patchwork Tue Oct 3 23:31:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41899E8FDC1 for ; Tue, 3 Oct 2023 23:35:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnov6-0003vy-Sv; Tue, 03 Oct 2023 19:35: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 1qnov5-0003vJ-JI for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:15 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov3-0006gt-Ax for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:15 -0400 Received: by mail-io1-xd41.google.com with SMTP id ca18e2360f4ac-79fa5d9f3a2so57643839f.3 for ; Tue, 03 Oct 2023 16:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376111; x=1696980911; 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=4s+TJxjVa/sdg7uCzCwkoZKCJLn5htyPFKNsiln+QBw=; b=y4ZCvDNhdmWbtkn3yh9CtfmS+reM7iuB7S3IaNlPFex/TcZoh3tk5sTNdf/YqSeSFX nXSIcgLUa2TFdwPgRcuk4RD9I2GByQDdwIfMVpJprbED1Lai/q2fZDaxIxxO3GimFPj5 n8xapsKZZHNjZPU9dojjhgP1Cxlt/AJw80r6vB8yA/3DRqEGCDOxGPAX9etc4nq6GKoX jp/GlXHbGDZjYvKWZxloZpcqD2JmOKcga84V10R+iV8rR/iQxT0FU390tMfS3Prv8QLi y0TTjjEDGzu0CqEVHKnsaCv2q4cbMccoqB66MfoZLQ8hA10o6iVq+GoVXVFdOm+kB/uY XoAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376111; x=1696980911; 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=4s+TJxjVa/sdg7uCzCwkoZKCJLn5htyPFKNsiln+QBw=; b=fVXoh4D12U2Z/jA54avjwUEh2ZTQqKIyCiEQzKs7P778u9/gYGD8VeHmikN/pX3G4i FDNe8qBIeCvokAdUI2UeexwdPX9+JakGxfHTzm5G6dfhX6VFRQVq28ydxEDzIibzRk+6 yoHf293CCRhOPXe4H3tEES8yvdrN+e8UBRgYvWZbA9Zz9gNfSQ1IDGse6QJOXMj7b8KQ vE4d2nbwJWaGZZ/ZFgb7MKSsuitlCj2M6n813mGvpjZBrkLi9OnKGbYrVfmdiYyFTzuq llPtl3UQnyj+3CXah7VNbBRVC1Wgj2OlFk5d8Hfjd4oGWDxrP3PdEA0u1T/9pmvegQxV WD8w== X-Gm-Message-State: AOJu0YykzHdTibyzVjtODSfa3ti1bzBi+xUjnPw339P9w62v+6MqrV05 vSQPYSGJokUu76FPhmmiXrFhky7Y6G7/qJWMyEbEGpqW X-Google-Smtp-Source: AGHT+IGHnT0CRyYakx1Jgv1pLjRzTb5shPJnnnPDviDb9N4EiawHfBGYiGFW2IcX0/2UzvuVuMc+kQ== X-Received: by 2002:a6b:7e05:0:b0:792:7f26:dc95 with SMTP id i5-20020a6b7e05000000b007927f26dc95mr863243iom.14.1696376111521; Tue, 03 Oct 2023 16:35:11 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:11 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 05/51] bsd-user: add extern declarations for bsd-proc.c conversion functions Date: Tue, 3 Oct 2023 17:31:29 -0600 Message-ID: <20231003233215.95557-6-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-6-kariem.taha2.7@gmail.com> --- 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 00000000000..b93a0b7fd5b --- /dev/null +++ b/bsd-user/qemu-bsd.h @@ -0,0 +1,38 @@ +/* + * BSD conversion extern declarations + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef QEMU_BSD_H +#define QEMU_BSD_H + +#include +#include + +/* bsd-proc.c */ +int target_to_host_resource(int code); +rlim_t target_to_host_rlim(abi_llong target_rlim); +abi_llong host_to_target_rlim(rlim_t rlim); +abi_long host_to_target_rusage(abi_ulong target_addr, + const struct rusage *rusage); +abi_long host_to_target_wrusage(abi_ulong target_addr, + const struct __wrusage *wrusage); +int host_to_target_waitstatus(int status); +void h2g_rusage(const struct rusage *rusage, + struct target_freebsd_rusage *target_rusage); + +#endif /* QEMU_BSD_H */ From patchwork Tue Oct 3 23:31:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3BE11E8FDC0 for ; Tue, 3 Oct 2023 23:35:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnov9-0003y0-Vo; Tue, 03 Oct 2023 19:35:20 -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 1qnov6-0003vx-Lq for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:16 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov3-0006gy-UL for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:16 -0400 Received: by mail-io1-xd44.google.com with SMTP id ca18e2360f4ac-79f915e5b47so59899339f.2 for ; Tue, 03 Oct 2023 16:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376112; x=1696980912; 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=xFpktNXIySwtSsbpcJMzWq911+k8gCH4IHFHAdVVqKM=; b=E++xI/zizL7OjRk7lk61mjLYqrpizSdeWJGEEGzBnw1hBJSd6YT3A728j3JCRliNF6 eiFHXp2sHC30QFUFUHaj7adf7SE2cUe3pltO532bGdy5Tt1BfO/9vJpqSkBjLGP6vrBP t/02TxF4v+xPRO6XOo6DlFQzDetRo6FRoaDAnGfHjMzBC5RFa5Ttf8PAPG8Xh9ouPGCe Q7wVRn4vu85IBWXFFfzb3gmzL9kCLAnXr+bR4auSutTKadtPp9LMlOumEXXoWQD40uWm e4oYzStGjThIedEEA3BGEZcqAYDm9IMqcgRdadCQ3Dn8MKgg6WvQ3x83fzcYArgr5ZtS QJnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376112; x=1696980912; 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=xFpktNXIySwtSsbpcJMzWq911+k8gCH4IHFHAdVVqKM=; b=cqfXgBT8c3njWQNKbnk50arRj2JVG0BlSZgxPdTc3cnTqWUz8vHpoWh47dZBHzOgGE UbowWz7UmzJpnutm6XaZG35oHKelRIk0OdeflCR15QDyWcHDwj+UB2KArZSJ5Wc1SdOH /e0vASLFrG104oalLd+2AmTFEyB3p0yQ75xn7z1n/5BSPLntAMnsE/HHAjujKICNPQ2/ TOqgmta7WwMLGPIhBhE3PhVVao1ZoIgafJP1Y4MSoSxMZTjZpFERLiRab9ivfQhQ36td ucDfz92cUAbDYQdRf4CAVhNZzCCQzGv48P101sLyD7o5lsdUeLLnCQJIKIooErP53eI0 9U4w== X-Gm-Message-State: AOJu0YxTN8ra/0fLvCmxxQZerLuIGtQ/vyZSXqhSA7dX/3gqKIcVPufa 6wIOUz+bkAGZKxDB3cnAG8Tp+V+SxkzOwOloT1HNGReb X-Google-Smtp-Source: AGHT+IEKgm8wmfJAJGTrKRwsn7yuTREMwSJ/dCr2EA7jHzkdPeFF4asHknSy4uYifxXyD4FZjmPduA== X-Received: by 2002:a5e:8804:0:b0:7a2:9fd3:5684 with SMTP id l4-20020a5e8804000000b007a29fd35684mr835735ioj.18.1696376112473; Tue, 03 Oct 2023 16:35:12 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:12 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 06/51] bsd-user: Implement target_to_host_resource conversion function Date: Tue, 3 Oct 2023 17:31:30 -0600 Message-ID: <20231003233215.95557-7-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d44; envelope-from=imp@bsdimp.com; helo=mail-io1-xd44.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-7-kariem.taha2.7@gmail.com> --- 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 00000000000..68410a0aa9d --- /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 a1061bffb8f..048773a75dd 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -22,6 +22,10 @@ #include +#include "qemu-bsd.h" +#include "gdbstub/syscalls.h" +#include "qemu/plugin.h" + /* exit(2) */ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) { diff --git a/bsd-user/meson.build b/bsd-user/meson.build index 5243122fc56..b97fce14722 100644 --- a/bsd-user/meson.build +++ b/bsd-user/meson.build @@ -7,6 +7,7 @@ bsd_user_ss = ss.source_set() common_user_inc += include_directories('include') bsd_user_ss.add(files( + 'bsd-proc.c', 'bsdload.c', 'elfload.c', 'main.c', @@ -16,6 +17,11 @@ bsd_user_ss.add(files( 'uaccess.c', )) +elf = cc.find_library('elf', required: true) +procstat = cc.find_library('procstat', required: true) +kvm = cc.find_library('kvm', required: true) +bsd_user_ss.add(elf, procstat, kvm) + # Pull in the OS-specific build glue, if any subdir(targetos) From patchwork Tue Oct 3 23:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E93C9E8FDBF for ; Tue, 3 Oct 2023 23:37:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnov7-0003wZ-Ki; Tue, 03 Oct 2023 19:35: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 1qnov6-0003vz-Rx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:16 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov5-0006hl-Ay for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:16 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-7a2a9e5451bso58458339f.1 for ; Tue, 03 Oct 2023 16:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376113; x=1696980913; 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=qAzCYw2NEfSKNP7dM+RUN8lAAw5B4Z+NHtHEbIs3+uw=; b=jRepES0hLoCFN5mZF/I2IM2SMeZhrG36Mh8riZA3wA8He0E/UIdRnMUrAfDc89hpV7 u12R2BqXgSTqlTc1i0ZrHho5695MnRLnrD5OCMk6xgZcQ3LYtdv24BcCrSLgpCS04HzD Z6KI4NBHm9u2GNQZM1QuNobYfIRJPVOk9avC7byh32w6BdfuHgTEYFElHDvvluXOdwXx ni9VZctDICCdXVH5JWN/S2AOhnABAh+uHFqlrbZbN45oRY7OLSyz5rLe5lzQNbS/6yvW oVz+RP/9qtefLEt8FeVyJCfs5oQQxX6USbZI32fsoeI/GpQFpYPyhr0JNKjYqM3wuzH0 2JUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376113; x=1696980913; 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=qAzCYw2NEfSKNP7dM+RUN8lAAw5B4Z+NHtHEbIs3+uw=; b=WeTis2S0YUinbPNI1ZKIBYnVoUeDXWY2VTqXMYkdyLgcPgW47MB3ANsWOnyVKlKADo 4hIx/K2oVMJKln2gXvWLEYOniPXpS1cAAriEpBXVJvyhJUC5cQu5YjPQav7tIcRWtRl5 edmi277KDFClUSYnEwv9sPP4pRSVQNUDSmab5Vq9bplBn6Tjez1TaeAQMxzP5h1OyvL4 w6sVffsHjq7uOXQpkO5f9ymZEeyq8OUnB22yoUCGy3XDl+IBvkVqghZnobvKXArbboDg IKOglrkaac3FXeBDx4/wcDpYnGuUu6aa+ChWTTmD7o0AO+g5FDss2eL+6epbQiIhK5ia 6faQ== X-Gm-Message-State: AOJu0YwJ+/OJiEvzvAA4ZXdmGzv6sL/9kRw5MATtJHyYlNiaXdTB1501 bstWGF/MDgRG6dbuSqxM4FUlTWelI7xvGfZ8K1zUWw== X-Google-Smtp-Source: AGHT+IG90aPxYsj1Nu4V14DoTqZI2eaArW07wSDQHrRombzQoAqJJ4/yW0/Mugjt+lbAUx0mpkHKcw== X-Received: by 2002:a6b:7e05:0:b0:792:7f26:dc95 with SMTP id i5-20020a6b7e05000000b007927f26dc95mr863296iom.14.1696376113341; Tue, 03 Oct 2023 16:35:13 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:13 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 07/51] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion. Date: Tue, 3 Oct 2023 17:31:31 -0600 Message-ID: <20231003233215.95557-8-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-8-kariem.taha2.7@gmail.com> --- 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 68410a0aa9d..19e39a2f764 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -38,3 +38,13 @@ int target_to_host_resource(int code) return code; } +rlim_t target_to_host_rlim(abi_llong target_rlim) +{ + return tswap64(target_rlim); +} + +abi_llong host_to_target_rlim(rlim_t rlim) +{ + return tswap64(rlim); +} + From patchwork Tue Oct 3 23:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0AF92E8FDC1 for ; Tue, 3 Oct 2023 23:37:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovA-0003y2-0W; Tue, 03 Oct 2023 19:35:20 -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 1qnov7-0003wW-DQ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:17 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov5-0006iM-PZ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:17 -0400 Received: by mail-io1-xd41.google.com with SMTP id ca18e2360f4ac-79fe6da0095so60238539f.0 for ; Tue, 03 Oct 2023 16:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376114; x=1696980914; 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=JWF4bLnZdn+X6WLEHlvePe0JZlfECQ9IWk4w/3GZptI=; b=lDAFgN6+UT+xRp4EN/hoNNKLgQwer9eoduB3jthnEMRgL5A/EhxiQhiy9sOAsuxo/5 SaTO2GP7ad7/+ZNYf2wi+VYlLAEyQYLoCUm8gZxzH3lRNnijQg7EdaQAIusaCNVEc7u/ d0bRgfYfB5Xeix6s114obsgc8lT0hD8/xgGIxYecWfJehUGKJw9QfOvasEeekjGsFANW MGoozWJh3VpszCWP684u9Uy3+iUp7mHkcrFSpSpI0RckRY17aCybnRFoOOZ7kL9vCEtC htIQ6ThgsVOYJYzlyzpLcyqqwB0/8E3f03ARJY2566SPZqraoMh27KdpPI7IiCDg5Y2H 9O1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376114; x=1696980914; 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=JWF4bLnZdn+X6WLEHlvePe0JZlfECQ9IWk4w/3GZptI=; b=dZKRsn7m4degEbv73oomhiDCn2LfQYnbGX/uNfzfsGS/EIsShUHe2KYWAG/Q5yD/7y 1aiAmVtdFNPCoY7LRYF3yELsOFP0uDt72/3+6MW9e5VLINkdzMdSr9C38l7mZFArUdkY MvKuBIvlRC6+S975cyMgZOq8PT7VDjzA7cUBMVQSZLgB8d4B6LVNXILQhKkEz+qmh4Rh uhjYbw4cprp8qvq9NRC+qt/73twuPKX8Vb4aT4EbebvYDJ8JxQvadYu9eWbpO4VsZAhG x185248uw6mQqi7AOu5kLXLf11bfD6Rk8ItzWAzJaCoPD1iZmimI94hdXJWuayKU7zZ1 lWzg== X-Gm-Message-State: AOJu0YzRZLUYMeiiZDj62jILvYALiq/7KhAt5eMtrZE0W0QOZ8UHJvX5 9RM6+tfBoPzJwsjozpUqMhufx1MluTQNK+mk78e9Xaw7 X-Google-Smtp-Source: AGHT+IGJmjY1RHkj3MxMan6j9kAJq/5A641UxM+oZB6HsJcRZThUHtMCsDb3QPxAR1LxMI1JY5+gfA== X-Received: by 2002:a5d:9946:0:b0:77e:249e:d84 with SMTP id v6-20020a5d9946000000b0077e249e0d84mr907010ios.5.1696376114263; Tue, 03 Oct 2023 16:35:14 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:13 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 08/51] bsd-user: Implement host_to_target_rusage and host_to_target_wrusage. Date: Tue, 3 Oct 2023 17:31:32 -0600 Message-ID: <20231003233215.95557-9-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, TVD_SPACE_RATIO=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-9-kariem.taha2.7@gmail.com> --- 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 19e39a2f764..aa386ff4820 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -48,3 +48,57 @@ abi_llong host_to_target_rlim(rlim_t rlim) return tswap64(rlim); } +void h2g_rusage(const struct rusage *rusage, + struct target_freebsd_rusage *target_rusage) +{ + __put_user(rusage->ru_utime.tv_sec, &target_rusage->ru_utime.tv_sec); + __put_user(rusage->ru_utime.tv_usec, &target_rusage->ru_utime.tv_usec); + + __put_user(rusage->ru_stime.tv_sec, &target_rusage->ru_stime.tv_sec); + __put_user(rusage->ru_stime.tv_usec, &target_rusage->ru_stime.tv_usec); + + __put_user(rusage->ru_maxrss, &target_rusage->ru_maxrss); + __put_user(rusage->ru_idrss, &target_rusage->ru_idrss); + __put_user(rusage->ru_idrss, &target_rusage->ru_idrss); + __put_user(rusage->ru_isrss, &target_rusage->ru_isrss); + __put_user(rusage->ru_minflt, &target_rusage->ru_minflt); + __put_user(rusage->ru_majflt, &target_rusage->ru_majflt); + __put_user(rusage->ru_nswap, &target_rusage->ru_nswap); + __put_user(rusage->ru_inblock, &target_rusage->ru_inblock); + __put_user(rusage->ru_oublock, &target_rusage->ru_oublock); + __put_user(rusage->ru_msgsnd, &target_rusage->ru_msgsnd); + __put_user(rusage->ru_msgrcv, &target_rusage->ru_msgrcv); + __put_user(rusage->ru_nsignals, &target_rusage->ru_nsignals); + __put_user(rusage->ru_nvcsw, &target_rusage->ru_nvcsw); + __put_user(rusage->ru_nivcsw, &target_rusage->ru_nivcsw); +} + +abi_long host_to_target_rusage(abi_ulong target_addr, + const struct rusage *rusage) +{ + struct target_freebsd_rusage *target_rusage; + + if (!lock_user_struct(VERIFY_WRITE, target_rusage, target_addr, 0)) { + return -TARGET_EFAULT; + } + h2g_rusage(rusage, target_rusage); + unlock_user_struct(target_rusage, target_addr, 1); + + return 0; +} + +abi_long host_to_target_wrusage(abi_ulong target_addr, + const struct __wrusage *wrusage) +{ + struct target_freebsd__wrusage *target_wrusage; + + if (!lock_user_struct(VERIFY_WRITE, target_wrusage, target_addr, 0)) { + return -TARGET_EFAULT; + } + h2g_rusage(&wrusage->wru_self, &target_wrusage->wru_self); + h2g_rusage(&wrusage->wru_children, &target_wrusage->wru_children); + unlock_user_struct(target_wrusage, target_addr, 1); + + return 0; +} + From patchwork Tue Oct 3 23:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EEF9BE8FDC2 for ; Tue, 3 Oct 2023 23:36:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovC-00041d-TL; Tue, 03 Oct 2023 19:35:22 -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 1qnov8-0003xN-Sm for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:18 -0400 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov6-0006no-Nf for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:18 -0400 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7a26fd82847so59598839f.3 for ; Tue, 03 Oct 2023 16:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376115; x=1696980915; 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=hSOU5X81V46msYlqeKtgkBYQcLTO4MUKpgJ2TqbhBJ4=; b=Sd17vx6mPJnVDbhQGFe8veuqwKwUQlrnqBb9yTz5wHi7yBjZU7B+PkeBAQuvErZIon eLEG9j+DgotawFbgUCRXMXuL7D9P/gIB3xGf+2D4Q/EzMoR28zBnx0TrUmdmTYkM5/pw F6+VN2uRCwYDkCTjU6LUDMUcUWa7AIKGa2T42EmIwjNlcVvW+/hxrgdetaznkrY6VOjR 6tEdh0V791yVZtNRHXkBjgmxHaOJdbg34XP8Z7veoNmTT+Cf2KaC6vI8VzV6IUF62F9d /MNoxp2NzR79Dz3pWupcrfvE2wmAGWMaffWbXfp3EIpBScgVR96DZFcbDhSeOUAdLSyV h1bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376115; x=1696980915; 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=hSOU5X81V46msYlqeKtgkBYQcLTO4MUKpgJ2TqbhBJ4=; b=MS4NCpIb9w5tTpmHrT9mokE3oFEE8wkq+mj8mOhBfcXJodtsD9vFrqeF6gB/rzcT85 tX5y4KFqTfcYf2JDAFEUxqdaKLZEhNBNAweB9O5ayBZKrvYwSLuAl4hzUClizDkiAT4Y FxmctiDY7Dz4cylw7cXvaXm0E8xFDwxsY+Kgpva3i4Gm26/39tQTxmJ/1Gn4GjQGfC6E v0qW/s5KulqzJErT+leVSHxv2WhTraHfOo6R2py8s88YGNa9msNKzaKiyGalSswgXxsU cvNBwVykSNE4BXAsQjaZwzpFp3tb+cXJqNp7XszjFjg2hjmvDrLi/W+6FD1+DYvvdjL0 heaQ== X-Gm-Message-State: AOJu0YzU2SWqTMJPKaTgf+3UkdiHOpC7UMmsKF40pBKq7Xo6VZQK++BW cQEou5UGwaDWCEtnf7KBwKHdNGvSIopiyGCW2J8VfA== X-Google-Smtp-Source: AGHT+IG5PNLmQyRmAMa1NbA085CROIItjB8d06zzgrt/o4J5y34IYtYFQAX1TH3vlmpjusYlwNLoiw== X-Received: by 2002:a5d:9cd5:0:b0:79f:d4e6:5175 with SMTP id w21-20020a5d9cd5000000b0079fd4e65175mr981597iow.16.1696376115226; Tue, 03 Oct 2023 16:35:15 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:14 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 09/51] bsd-user: Implement host_to_target_waitstatus conversion. Date: Tue, 3 Oct 2023 17:31:33 -0600 Message-ID: <20231003233215.95557-10-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2c; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-10-kariem.taha2.7@gmail.com> --- 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 aa386ff4820..19f6efe1f78 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -102,3 +102,20 @@ abi_long host_to_target_wrusage(abi_ulong target_addr, return 0; } +/* + * wait status conversion. + * + * Map host to target signal numbers for the wait family of syscalls. + * Assume all other status bits are the same. + */ +int host_to_target_waitstatus(int status) +{ + if (WIFSIGNALED(status)) { + return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); + } + if (WIFSTOPPED(status)) { + return (host_to_target_signal(WSTOPSIG(status)) << 8) | (status & 0xff); + } + return status; +} + From patchwork Tue Oct 3 23:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D7A6E8FDC1 for ; Tue, 3 Oct 2023 23:37:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovC-00041Z-Sf; Tue, 03 Oct 2023 19:35:22 -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 1qnov9-0003xn-84 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:19 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov7-0006ph-NW for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:18 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79f95cd15dfso58506839f.0 for ; Tue, 03 Oct 2023 16:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376116; x=1696980916; 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=7FAk+UvZhi8lAunIPUyYc1Eov2CJXu6KRzN3IKE5mSs=; b=nHbrOhc+JIHn8E/18Qd+LQCidWORKbCg2slFxOA8LShoZR+SjeLfj+XVe0HLYnzGos yPFNgLgoaTsSVb6ACqDkrDdcSUx0H0QXCBpM0OryI4aNlwO/cn1oBdpkhyrsy8MTokN8 x/lf04sE5MMqfKA919dsKD4Z99yUY5a4Ga8duBHqSL+LG1U15zVcMcAQcVE3OP9u8hGV co0Oqp1Gv3jbiyCzycgQjRsYkGrHR1HZA6p3gTe/iu61lb9EzZEnQVhFuYOR3bNtWOdX OsLJQZP5ZPyB3fRO8HJgz6hcRLabxnr99J0aWRNRL/hSb1gDOAuoM8Rcnus9ZGCh8Drw wiEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376116; x=1696980916; 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=7FAk+UvZhi8lAunIPUyYc1Eov2CJXu6KRzN3IKE5mSs=; b=Wyy7VTWyWk/P3mH8yXEgIgyTcuJwAtBBGdiZibJZmywSzPSkZSGo2gckAl/Fkt07xP vHQsGfOMqPuTWcJ7u5Syo8LD42TleCHEDEwk7hHZ7WvYahNUVHjiWWEzKoZfQKz3RSRT 2oPwGD2dxyuD20vivdSWzwH6bj3rLiQRB1xmI2pE7nbBIZzHNODTzZABqLh63WkzyY9g LhF7DH1ivglKzaYCtx+oo4MawRIML343WHXevZpsKTZIupLHqZe/WQxTwrcAFBN+ujxq bQAJK03p65YvP9OO+YsLvWlvVEJxl5Fu4rVBjXR7Exa2bjMdaZp+W+2Ycuvupeb1qpcu yYrw== X-Gm-Message-State: AOJu0Yx4K4fG0rotSaj+e09rcE8QbcVUidvH5KeA1j3x4pPmDHqkCwbo esXjdQvceEnSnuqiduQpcGOuy5MUZUaoyMie54wFFw== X-Google-Smtp-Source: AGHT+IGRgjFxlsD69e0vWVBL+UzIOcI8W4zqbyGYNbaD2jGXCR/6TyzlRaJFbu05Vb/KM5fRyXW7Ng== X-Received: by 2002:a6b:7b05:0:b0:791:280:839e with SMTP id l5-20020a6b7b05000000b007910280839emr875375iop.16.1696376116160; Tue, 03 Oct 2023 16:35:16 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:15 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Kyle Evans , Karim Taha Subject: [PULL 10/51] bsd-user: Get number of cpus. Date: Tue, 3 Oct 2023 17:31:34 -0600 Message-ID: <20231003233215.95557-11-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Kyle Evans Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-11-kariem.taha2.7@gmail.com> --- 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 19f6efe1f78..ca3c1bf94f4 100644 --- a/bsd-user/bsd-proc.c +++ b/bsd-user/bsd-proc.c @@ -119,3 +119,27 @@ int host_to_target_waitstatus(int status) return status; } +int bsd_get_ncpu(void) +{ + int ncpu = -1; + cpuset_t mask; + + CPU_ZERO(&mask); + + if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask), + &mask) == 0) { + ncpu = CPU_COUNT(&mask); + } + + if (ncpu == -1) { + ncpu = sysconf(_SC_NPROCESSORS_ONLN); + } + + if (ncpu == -1) { + gemu_log("XXX Missing bsd_get_ncpu() implementation\n"); + ncpu = 1; + } + + return ncpu; +} + diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 048773a75dd..b6225e520ea 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -26,6 +26,8 @@ #include "gdbstub/syscalls.h" #include "qemu/plugin.h" +int bsd_get_ncpu(void); + /* exit(2) */ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) { From patchwork Tue Oct 3 23:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97145E8FDBF for ; Tue, 3 Oct 2023 23:44:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovD-00042h-UV; Tue, 03 Oct 2023 19:35:23 -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 1qnovA-0003z2-9P for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:21 -0400 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov8-0006pv-Kk for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:20 -0400 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-79fa416b7ffso60872039f.2 for ; Tue, 03 Oct 2023 16:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376117; x=1696980917; 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=cAZ4CluLSnk0lLew81sItiili5rTiFhyUaEMqNMoRMs=; b=InlRV+GrrLWiwbT94sXnLHeuAce6qQAuuJ1yf25QtFQP6t5U4CbYbImR6bi+q8oaB7 6wNeGppXW/p+CUvRV+M7eaton6tk3fNwkBm0J2SGRtI2sqIXm1dt8QEG3/uasDwh+pzA wARkKaoNhEKXY8aNNuiIctWd+ua27yTwwe78f8qT4w+iaGMJWPtF6S53CckLkTnmS0LI ZRGkDXHJb82bb3aFTnIX1gV98L+KMivpvmLkWa3MG/bBWFwwtsRP4bE2zzn4H9rMZfd3 5BDCkBp5FQEp3uBk98154wWKTliiFp2rzPxXwziZIaLQCkgQJK1fpF/bUfyKPUVzRsH8 l6qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376117; x=1696980917; 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=cAZ4CluLSnk0lLew81sItiili5rTiFhyUaEMqNMoRMs=; b=JZsUSYzv+MLDLHGkEfDEBB5s5mndhATxijJY0rA09N11GQwSwHa6vBsc5GH1yCT4aR D9YmtRWjj8AuBiapix4Crhwt9yl1Vu7iaHDpCyEnjXdI1FVQBIjeKxW49Ac1nYdCKq6i w6N+ljhQ3F/aFVX6+yzxheuwZQaaS2FRrhiufv5adax26aiq0MyhV/YyZXdGQAekOpN2 H/gf2iVpMKmlQbkEJfSs7qXsG7UfOM0YsEBNxlR5CrFH49M9+sWassFSBSAI60pgxY9i JHqHOQUhHA/8pGZHW3SQw+9ORk3mbxcqhbTvq9QbKiyUVFRgTOjAk7vhnNPv5MVnOLiK f7MQ== X-Gm-Message-State: AOJu0YyV8bx0vbrR0sTwACvflIjl3YKl1+LA80wTVsAzJmxT2Y4DdRLW t67jCVKrTWJLgP1W+w1zKUi32gB4SE9c7A+7oapd3Q== X-Google-Smtp-Source: AGHT+IF53ey32ANStuXRcWk9D8de1+JirYX4n7HCg5044cYeS2waK8s6bP9CkJIuMdnjKefApoJCpw== X-Received: by 2002:a6b:ea15:0:b0:790:a010:4c42 with SMTP id m21-20020a6bea15000000b00790a0104c42mr1035876ioc.13.1696376117069; Tue, 03 Oct 2023 16:35:17 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:16 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 11/51] bsd-user: Implement getgroups(2) and setgroups(2) system calls. Date: Tue, 3 Oct 2023 17:31:35 -0600 Message-ID: <20231003233215.95557-12-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d31; envelope-from=imp@bsdimp.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-12-kariem.taha2.7@gmail.com> --- 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 b6225e520ea..7b25aa19829 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -41,4 +41,48 @@ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) return 0; } +/* getgroups(2) */ +static inline abi_long do_bsd_getgroups(abi_long gidsetsize, abi_long arg2) +{ + abi_long ret; + uint32_t *target_grouplist; + g_autofree gid_t *grouplist; + int i; + + grouplist = g_try_new(gid_t, gidsetsize); + ret = get_errno(getgroups(gidsetsize, grouplist)); + if (gidsetsize != 0) { + if (!is_error(ret)) { + target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i = 0; i < ret; i++) { + target_grouplist[i] = tswap32(grouplist[i]); + } + unlock_user(target_grouplist, arg2, gidsetsize * 2); + } + } + return ret; +} + +/* setgroups(2) */ +static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2) +{ + uint32_t *target_grouplist; + g_autofree gid_t *grouplist; + int i; + + grouplist = g_try_new(gid_t, gidsetsize); + target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i = 0; i < gidsetsize; i++) { + grouplist[i] = tswap32(target_grouplist[i]); + } + unlock_user(target_grouplist, arg2, 0); + return get_errno(setgroups(gidsetsize, grouplist)); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index fa60df529ef..535e6287bde 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -223,6 +223,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_exit(cpu_env, arg1); break; + case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */ + ret = do_bsd_getgroups(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setgroups: /* setgroups(2) */ + ret = do_bsd_setgroups(arg1, arg2); + break; + + /* * File system calls. */ From patchwork Tue Oct 3 23:31:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D427AE8FDC0 for ; Tue, 3 Oct 2023 23:37:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovE-000444-O2; Tue, 03 Oct 2023 19:35: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 1qnovB-00040K-8q for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:21 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnov9-0006q9-Gi for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:20 -0400 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-35133097583so5856445ab.1 for ; Tue, 03 Oct 2023 16:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376118; x=1696980918; 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=0ieaVmtKu6WB7XBYFcTLrCbXTONlGyxzlpnV4UW4ZRY=; b=vgG0NfFSs826xUkDXUwaQwvw856BpYzk7dSL3OOH47EoZ5sOKHJ+tPc7KwKPPyJRdh 1b2CfQnzV/yBZBSsvDSoGqvCCqMbgJNP/0PdGv51ae2NlNpDqZVCB+4Q2xk+xryrRfUf 3ZTSQgYIGjQPQvVjoYMzilNjYw8LYEho9kMsG0PcOpUH9PCUvrIDcYQQbuWETOIXttV4 gsE5m8GbTf7LBWfy8GSQ/sn/EoPGu5uzbiTo/tqVsIqssUwf2cgKVDR7sPVwQen+4sb4 wj2vYDv4UjnZxXABaKsrm2dqGJsYiWrIRUptfUPYcCKx8GGNDXbTeiHXuPbfZ3GmOEir uevw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376118; x=1696980918; 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=0ieaVmtKu6WB7XBYFcTLrCbXTONlGyxzlpnV4UW4ZRY=; b=TLGys+DwL5ZQWvKjH65LDD6hvCiNBtqoD9jY9LiV89jgizU2fdo+/OWHuE+0Gzeurg rYO9gr1L6uEOvTKpnzlP38yRfhJeQu0B9a2YmbsLtb6/VMYeeCLItzEdZXgOgRXRB2SU 6LJm/Dv1kMKXgAuqp3Am3DUds3tL/9psYbhW4joiy7We4i6e80f/RxUWarEFB3gMA4eM Gr9++q3cTy9r9m8zLaM3qQf7RIW4HSYjavAglUHbBuz0Ya5j/MRqFx2vmnZpWKW3oAlz J2X3UXIR3U3ULKE0O5eXqSEBT/kmGvdUHespVqktCYNQ4k5Za7ifa/rGwBf7BimuSNPo QvLA== X-Gm-Message-State: AOJu0Yy3vQXewp96S+m6/B5c7A5NIRVtU5gOXff6A40BflCKjSnDDDVs SB/EDrZZPf66/sVF3PsfFxRimZBJOLNISAc6ELBB2w== X-Google-Smtp-Source: AGHT+IFMtdvEoOHG9DOjBFAK1IjGbs+cEgXLsDRAScOqeqR/wHqtYhLnQlokB6ZZgA/mS32iskYxAQ== X-Received: by 2002:a6b:c413:0:b0:79a:b526:2f2a with SMTP id y19-20020a6bc413000000b0079ab5262f2amr823991ioa.5.1696376117918; Tue, 03 Oct 2023 16:35:17 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:17 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 12/51] bsd-user: Implement umask(2), setlogin(2) and getlogin(2) Date: Tue, 3 Oct 2023 17:31:36 -0600 Message-ID: <20231003233215.95557-13-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-13-kariem.taha2.7@gmail.com> --- 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 7b25aa19829..cb7c69acb0c 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -26,6 +26,7 @@ #include "gdbstub/syscalls.h" #include "qemu/plugin.h" +extern int _getlogin(char*, int); int bsd_get_ncpu(void); /* exit(2) */ @@ -85,4 +86,42 @@ static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2) return get_errno(setgroups(gidsetsize, grouplist)); } +/* umask(2) */ +static inline abi_long do_bsd_umask(abi_long arg1) +{ + return get_errno(umask(arg1)); +} + +/* setlogin(2) */ +static inline abi_long do_bsd_setlogin(abi_long arg1) +{ + abi_long ret; + void *p; + + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(setlogin(p)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* getlogin(2) */ +static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + + p = lock_user(VERIFY_WRITE, arg1, arg2, 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(_getlogin(p, arg2)); + unlock_user(p, arg1, arg2); + + return ret; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 535e6287bde..44cbf52f087 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -231,6 +231,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setgroups(arg1, arg2); break; + case TARGET_FREEBSD_NR_umask: /* umask(2) */ + ret = do_bsd_umask(arg1); + break; + + case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */ + ret = do_bsd_setlogin(arg1); + break; + + case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */ + ret = do_bsd_getlogin(arg1, arg2); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B4D4E8FDBF for ; Tue, 3 Oct 2023 23:39:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovG-00044P-3P; Tue, 03 Oct 2023 19:35:26 -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 1qnovD-00041v-3R for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:23 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovA-0006qR-9Y for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:22 -0400 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-79545e141c7so14837939f.0 for ; Tue, 03 Oct 2023 16:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376119; x=1696980919; 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=C7VRFr4gHk91MagU57mxTPEhJmPz5+DN76M+3LJyxsA=; b=3FeLSFVnivgvxTLodcbyaV+PWwF17To8sjkZNQOHcHsQbwlXIcgPrJy7utrrTlpoXe 7ZXFd9qv98yyHZyrsXMc+QaEAPxfvYuSs9+g8QU6W3H2+bufLV/ajA4vREAG1ok+Oi4a nEi/v5ilVvff3T9rvyx6hgC1V5mxmf4ChVqDyXdixsj1PK6g+v7Hr1So/2FotGfnQbvV amFHrpbZJ5a4EclFJWO998RfeLPdfNf2BNE7odHmj8AZhEtFFliC0fM4Z+QedEvxJ8Hw f5zn4JvNBc8QgNRCEXybkWaYzE6dG/a15goolbPPv9ean9Ysw0dIDwwVQcEmwxeNwpUZ 1VhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376119; x=1696980919; 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=C7VRFr4gHk91MagU57mxTPEhJmPz5+DN76M+3LJyxsA=; b=mWlVoKL2pp9eCztqOn2LM2O7KlzRNXq/F6gmwc+1CJ+WCN7XTK3x0hCqFBqGtvKxnu 3GLSd4Yzly2OcYZI6P80/vkklulPUUvjZUJLqTtcyYmXyY2d6PMVG9xTf/q1D8oKAMIL ylPonGqw1coHPdkW8JoGL4hUWOQEU1hU8GMBHcOvrN0VjixGt8rbT4ZyLS3Gd5CNz0yl BO9QA0v0uKYPQT1tfmiAr6aTnpEfMBmjdni2aiovoctW+iE8RBxe7Km3XcQeCkBfPowA mNgZVVqLZIsFsbRAUeP6d5AOj+yfhy3oV7otQp3bkb4dJnmoHsKVDBzVfdVlM65TlDeU 6QUA== X-Gm-Message-State: AOJu0Yxlk3RRMoQ+E8V+QKSExKWcfDge93siritPXJYLFegbXXRt1YMu 6E8ApOPAULj7AQj3BbWSlr1ObXuGa04/Zq9fhfkygg== X-Google-Smtp-Source: AGHT+IEbBdmKKfbHwDq0CPzm+u8y/OaUYYygPT0FNV9jBQxLPC6xSVZkVB8UBcNwtiso3ONvfera8w== X-Received: by 2002:a05:6602:2c4c:b0:79f:e800:ea95 with SMTP id x12-20020a0566022c4c00b0079fe800ea95mr4015629iov.3.1696376118823; Tue, 03 Oct 2023 16:35:18 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:18 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 13/51] bsd-user: Implement getrusage(2). Date: Tue, 3 Oct 2023 17:31:37 -0600 Message-ID: <20231003233215.95557-14-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-14-kariem.taha2.7@gmail.com> --- 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 cb7c69acb0c..133c1b0eaf8 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -124,4 +124,17 @@ static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2) return ret; } +/* getrusage(2) */ +static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_addr) +{ + abi_long ret; + struct rusage rusage; + + ret = get_errno(getrusage(who, &rusage)); + if (!is_error(ret)) { + host_to_target_rusage(target_addr, &rusage); + } + return ret; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 44cbf52f087..5d8693ed550 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -243,6 +243,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_getlogin(arg1, arg2); break; + case TARGET_FREEBSD_NR_getrusage: /* getrusage(2) */ + ret = do_bsd_getrusage(arg1, arg2); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5F6AEE8FDC0 for ; Tue, 3 Oct 2023 23:39:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovG-00046A-Ru; Tue, 03 Oct 2023 19:35:26 -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 1qnovD-00042e-Lp for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:23 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovC-0006uM-16 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:23 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-79fa2dbd793so64824839f.2 for ; Tue, 03 Oct 2023 16:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376120; x=1696980920; 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=+wZeMIbIZWAaczukeU9kCYH0/v8NZZkLUqmuVnhx+go=; b=FWPY3CwqhWgXLpXpus/On1XD0gH5NJj52UzR60NxL8YFuQbtqcFB5iXM7xm6toBynu 2z7y0rivH5H3kcedc4gL32xfu2330MgloaZJD9Pv+OBP8qyw6rhviruWYAtkFXoqgjb4 H4iTF/gNXMwnBVVagYii0pFOSoYL44OYl7avm/EowlmckifyiC8PkXlxRd7XeI6uVf2G voAjuD3zMKVxOgRjA3j1c2AY8ckOGvVfySc4sYb6evZPA795otr2zaU8Q6NM5OFEDNze nYFSVYZdw7tuzns2LHzSUeKvI+pkO/N46flc1I/Ab9gVxBtQf62lC8+QutJr/8Mk1FiU W+pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376120; x=1696980920; 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=+wZeMIbIZWAaczukeU9kCYH0/v8NZZkLUqmuVnhx+go=; b=tH7sXQrjnKnUFsQUcZBZINOMox2wey8ozkaba9oNmxX+XM4Z5QTDSKX+eFth3oDz// NSZIpgzOvrtwhncZRQTo0+o2lFX7BShR6mKr4j98STVsbqGnS8z0to10tR34w27KMsSu 9UMsh9fRjK+y1fNLYdWavoXPvuGBim8RLrZvm4DPXKZVBHKFMAANyElv78PdiGY6d/HW IVVWacb8aIwA6qpDr1zPVLv+iXHffpuf8NVDrGo2/aNXyWCZtEjJgGbYbHQpWSQdYYq+ nGex1s/M1oPJenpWZkycYRV2jpvwzX0kgIpHNFoL40jkOAL5I/gKfoxpS/KMykrDiy5f vKIQ== X-Gm-Message-State: AOJu0YzgD4kdnWPsd2xZy7NRwtGKsF20xdNhXcNtZA7K/u6Fe2N+8lFU 8tw8PsDaPyF8EkUamUYGdiODcdHDzui1S/cxk1pYaA== X-Google-Smtp-Source: AGHT+IF06LilV5Cn0XrVWSHUAxItPfBp/84dkxgYmTo6aI8/AMpUgKW8GXT7rmL/pg+EOHUs+44A6w== X-Received: by 2002:a6b:fd01:0:b0:790:c3d0:8f87 with SMTP id c1-20020a6bfd01000000b00790c3d08f87mr834956ioi.19.1696376119699; Tue, 03 Oct 2023 16:35:19 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:19 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 14/51] bsd-user: Implement getrlimit(2) and setrlimit(2) Date: Tue, 3 Oct 2023 17:31:38 -0600 Message-ID: <20231003233215.95557-15-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-15-kariem.taha2.7@gmail.com> --- 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 133c1b0eaf8..38d1324034c 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -137,4 +137,63 @@ static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_addr) return ret; } +/* getrlimit(2) */ +static inline abi_long do_bsd_getrlimit(abi_long arg1, abi_ulong arg2) +{ + abi_long ret; + int resource = target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + switch (resource) { + case RLIMIT_STACK: + rlim.rlim_cur = target_dflssiz; + rlim.rlim_max = target_maxssiz; + ret = 0; + break; + + case RLIMIT_DATA: + rlim.rlim_cur = target_dfldsiz; + rlim.rlim_max = target_maxdsiz; + ret = 0; + break; + + default: + ret = get_errno(getrlimit(resource, &rlim)); + break; + } + if (!is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) { + return -TARGET_EFAULT; + } + target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); + target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); + unlock_user_struct(target_rlim, arg2, 1); + } + return ret; +} + +/* setrlimit(2) */ +static inline abi_long do_bsd_setrlimit(abi_long arg1, abi_ulong arg2) +{ + abi_long ret; + int resource = target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + if (RLIMIT_STACK == resource) { + /* XXX We should, maybe, allow the stack size to shrink */ + ret = -TARGET_EPERM; + } else { + if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) { + return -TARGET_EFAULT; + } + rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); + rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); + unlock_user_struct(target_rlim, arg2, 0); + ret = get_errno(setrlimit(resource, &rlim)); + } + return ret; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 5d8693ed550..5cb60862303 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -247,6 +247,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_getrusage(arg1, arg2); break; + case TARGET_FREEBSD_NR_getrlimit: /* getrlimit(2) */ + ret = do_bsd_getrlimit(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setrlimit: /* setrlimit(2) */ + ret = do_bsd_setrlimit(arg1, arg2); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD200E8FDC0 for ; Tue, 3 Oct 2023 23:39:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovI-000489-TW; Tue, 03 Oct 2023 19:35: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 1qnovE-00042z-4i for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:24 -0400 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovC-0006uU-13 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:23 -0400 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-79fe87cd74eso59103939f.3 for ; Tue, 03 Oct 2023 16:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376120; x=1696980920; 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=qie3M6dlAyV2pYetlYDOFKB5joUdVo7JudFsExcH3bA=; b=HYmlepfJtwsGATV4Wpa3oLA7H+74P+y5vWQoIt3YS8/nEsHzknmRGchVY5jtZ1LL9j 5bh4pBSnQ27pqKF2Jy8Qptee1Z/I9awolLxt8wyo/H8jZ4XNliIHUzKSagNKPVpLHNcC 4DbENKNxaP6T200Wqo0Rmwes+TWiAUuuaGBoRegncxxhHKJV4wnUghrSDZ++/HxcICnm pnqa6w2dKQAbONLqfwGfnSSRClJ4awZ4D3SHcL3eeR4JqryRe3rl5blupQE7vA8piw/S 59YUfGR7g6+dBlugHQJxGZC2gaWt7HCkKH2JWwoCG1wGyhYHal2dgnHkQyystYHlyy3w d4eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376120; x=1696980920; 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=qie3M6dlAyV2pYetlYDOFKB5joUdVo7JudFsExcH3bA=; b=hEnYjv8E8/i5gfzGfQomO+mW1JBkxMqWOA0MWdBgAhykrNw7L8GYR7Bx9qwXb+L6b+ T2988/0ZSGJMjuaq+WoeKAVvEH+t42kuQUSGJ5cqVdpsXTbnlS4sbkknX+Jelp4mBplE 9ht0V4UhSxRMZ7/fRSwNu66gkvZaC9b8alLQNZ1MYl2ERPHGZRQqWSTwMr3vh22Cb0d/ xdZOUa14QRqEBpJIHmwsNDFte4nAnusWqZ2uu4Uq59SWfa8c6gtttK0jlLtnlhYHndlT ysvaGdY0HgghtM3K6FYuzIQ706gYvyiUaCCgcIa8ARegZKro/annEQNbstrT0nzJGFLg SdEA== X-Gm-Message-State: AOJu0YxXgE4jCydB3OyoA1q4Y25sj46GzbChWZ/fJbKkWFcnpXUK4BdM 5LUl210nlZmieAJZxrOY/+oaUTZaV/IcgAfRlkRq4A== X-Google-Smtp-Source: AGHT+IGnUKk3qHhAD7F8kJABbW+kQnQ2d/TyJbQes9WuZRm/PbGT/kUry6eUuNu/gFn769V2Ss/i9w== X-Received: by 2002:a6b:6f09:0:b0:79f:ca2f:9198 with SMTP id k9-20020a6b6f09000000b0079fca2f9198mr816906ioc.2.1696376120636; Tue, 03 Oct 2023 16:35:20 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:20 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 15/51] bsd-user: Implement several get/set system calls: Date: Tue, 3 Oct 2023 17:31:39 -0600 Message-ID: <20231003233215.95557-16-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son getpid(2), getppid(2), getpgrp(2) setreuid(2), setregid(2) getuid(2), geteuid(2), getgid(2), getegid(2), getpgid(2) setuid(2), seteuid(2), setgid(2), setegid(2), setpgid(2) Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-16-kariem.taha2.7@gmail.com> --- 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 38d1324034c..6ff07c0ac36 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -196,4 +196,94 @@ static inline abi_long do_bsd_setrlimit(abi_long arg1, abi_ulong arg2) return ret; } +/* getpid(2) */ +static inline abi_long do_bsd_getpid(void) +{ + return get_errno(getpid()); +} + +/* getppid(2) */ +static inline abi_long do_bsd_getppid(void) +{ + return get_errno(getppid()); +} + +/* getuid(2) */ +static inline abi_long do_bsd_getuid(void) +{ + return get_errno(getuid()); +} + +/* geteuid(2) */ +static inline abi_long do_bsd_geteuid(void) +{ + return get_errno(geteuid()); +} + +/* getgid(2) */ +static inline abi_long do_bsd_getgid(void) +{ + return get_errno(getgid()); +} + +/* getegid(2) */ +static inline abi_long do_bsd_getegid(void) +{ + return get_errno(getegid()); +} + +/* setuid(2) */ +static inline abi_long do_bsd_setuid(abi_long arg1) +{ + return get_errno(setuid(arg1)); +} + +/* seteuid(2) */ +static inline abi_long do_bsd_seteuid(abi_long arg1) +{ + return get_errno(seteuid(arg1)); +} + +/* setgid(2) */ +static inline abi_long do_bsd_setgid(abi_long arg1) +{ + return get_errno(setgid(arg1)); +} + +/* setegid(2) */ +static inline abi_long do_bsd_setegid(abi_long arg1) +{ + return get_errno(setegid(arg1)); +} + +/* getpgid(2) */ +static inline abi_long do_bsd_getpgid(pid_t pid) +{ + return get_errno(getpgid(pid)); +} + +/* setpgid(2) */ +static inline abi_long do_bsd_setpgid(int pid, int pgrp) +{ + return get_errno(setpgid(pid, pgrp)); +} + +/* getpgrp(2) */ +static inline abi_long do_bsd_getpgrp(void) +{ + return get_errno(getpgrp()); +} + +/* setreuid(2) */ +static inline abi_long do_bsd_setreuid(abi_long arg1, abi_long arg2) +{ + return get_errno(setreuid(arg1, arg2)); +} + +/* setregid(2) */ +static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2) +{ + return get_errno(setregid(arg1, arg2)); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 5cb60862303..7565e69e76d 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -255,6 +255,66 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setrlimit(arg1, arg2); break; + case TARGET_FREEBSD_NR_getpid: /* getpid(2) */ + ret = do_bsd_getpid(); + break; + + case TARGET_FREEBSD_NR_getppid: /* getppid(2) */ + ret = do_bsd_getppid(); + break; + + case TARGET_FREEBSD_NR_getuid: /* getuid(2) */ + ret = do_bsd_getuid(); + break; + + case TARGET_FREEBSD_NR_geteuid: /* geteuid(2) */ + ret = do_bsd_geteuid(); + break; + + case TARGET_FREEBSD_NR_getgid: /* getgid(2) */ + ret = do_bsd_getgid(); + break; + + case TARGET_FREEBSD_NR_getegid: /* getegid(2) */ + ret = do_bsd_getegid(); + break; + + case TARGET_FREEBSD_NR_setuid: /* setuid(2) */ + ret = do_bsd_setuid(arg1); + break; + + case TARGET_FREEBSD_NR_seteuid: /* seteuid(2) */ + ret = do_bsd_seteuid(arg1); + break; + + case TARGET_FREEBSD_NR_setgid: /* setgid(2) */ + ret = do_bsd_setgid(arg1); + break; + + case TARGET_FREEBSD_NR_setegid: /* setegid(2) */ + ret = do_bsd_setegid(arg1); + break; + + case TARGET_FREEBSD_NR_getpgrp: /* getpgrp(2) */ + ret = do_bsd_getpgrp(); + break; + + case TARGET_FREEBSD_NR_getpgid: /* getpgid(2) */ + ret = do_bsd_getpgid(arg1); + break; + + case TARGET_FREEBSD_NR_setpgid: /* setpgid(2) */ + ret = do_bsd_setpgid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setreuid: /* setreuid(2) */ + ret = do_bsd_setreuid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setregid: /* setregid(2) */ + ret = do_bsd_setregid(arg1, arg2); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408112 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A16DBE8FDC0 for ; Tue, 3 Oct 2023 23:37:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovK-00048d-Hq; Tue, 03 Oct 2023 19:35:30 -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 1qnovE-000445-Oh for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:24 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovC-0006yQ-Rr for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:24 -0400 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-79545e141c7so14838439f.0 for ; Tue, 03 Oct 2023 16:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376121; x=1696980921; 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=xg910hClygM/w6Q17aFFZ0+QF/l/YWUoxR0V7peyA8Y=; b=f6FNrg2W6/ejP6y0xwjMzGL61J2APLHZNbRStvzjnTAnDdaaOu+RhoEzwyv3N9Xf3q KPYhm51nOqE+HaDQSpfg2vNJCH2M99BtdIsms2n/eHyeqUmaagnyg4KK/zwwQ+4zx+zD 9K3oZsomRUA5ygaslfcPU+g1c+vW6pU3XsHci54v5HLKBvVb/lEWuPz2UZTCxlBA9+Jm nI0NE4It5ui2N+TFzNyWzxtl6Gks9uUmjlaoCV2JV7nOBbWYB6jO7MPowZZHfpiDSw/9 N2MCiC+U1P3xSO5QxhgH3b56GUAEGKieL9O/7c1XzpqsjPEwMIRHmG56Mf5D9VrtiyO8 AOcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376121; x=1696980921; 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=xg910hClygM/w6Q17aFFZ0+QF/l/YWUoxR0V7peyA8Y=; b=FEYR6Y7Lh2IkSQ+rr/DqeAjqS9lHOpBlvgcuI6Vby2I7Mgx1cw+z6Lqt9/rpnStxaq V6Y9ACmolGlX6F+bOSNVZBzRtnIS0TJxP0y8SZ02w8YvCJ96n4n2xW5kmoYsok2Jjjjy RGZuHL1Mjh1GW8gS0OCUzgSWO22BacNwGNZsTfNu1Iw5Dp06yv5zOLcmS9nnh00zeLs/ tsm2omELcL0r6IhjGksQzu37rBYPQ2EiV06Ji7ZGLqXbnIhjauV9TcqTiW5EPJvNA5V2 p49u/4ynL7Oam2sEedy2wb+ZhatF5XgZ5bLcE8295SnhXs3+Tn7n6vYHtn114DAvQxLH OyfA== X-Gm-Message-State: AOJu0YxwirCQKc6zlunAFa7mx0ppvlO01IaN3LJOklBpfRSXfqG93/2x yxJ0/R+EFRPFS7XYxTRulArpCKHk5iUZH46dZxFytw== X-Google-Smtp-Source: AGHT+IGC8Xy/X/xViCnHld6BISjIwpaCRCcii3SWQKrC+2BwwTLPCscoiFHBKpSozaO5og4EiRouEQ== X-Received: by 2002:a5e:c90c:0:b0:79f:b4f1:186a with SMTP id z12-20020a5ec90c000000b0079fb4f1186amr526394iol.1.1696376121472; Tue, 03 Oct 2023 16:35:21 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:21 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 16/51] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid. Date: Tue, 3 Oct 2023 17:31:40 -0600 Message-ID: <20231003233215.95557-17-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-17-kariem.taha2.7@gmail.com> --- 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 6ff07c0ac36..a5f301c72ff 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -286,4 +286,80 @@ static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2) return get_errno(setregid(arg1, arg2)); } +/* setresgid(2) */ +static inline abi_long do_bsd_setresgid(gid_t rgid, gid_t egid, gid_t sgid) +{ + return get_errno(setresgid(rgid, egid, sgid)); +} + +/* setresuid(2) */ +static inline abi_long do_bsd_setresuid(uid_t ruid, uid_t euid, uid_t suid) +{ + return get_errno(setresuid(ruid, euid, suid)); +} + +/* getresuid(2) */ +static inline abi_long do_bsd_getresuid(abi_ulong arg1, abi_ulong arg2, + abi_ulong arg3) +{ + abi_long ret; + uid_t ruid, euid, suid; + + ret = get_errno(getresuid(&ruid, &euid, &suid)); + if (is_error(ret)) { + return ret; + } + if (put_user_s32(ruid, arg1)) { + return -TARGET_EFAULT; + } + if (put_user_s32(euid, arg2)) { + return -TARGET_EFAULT; + } + if (put_user_s32(suid, arg3)) { + return -TARGET_EFAULT; + } + return ret; +} + +/* getresgid(2) */ +static inline abi_long do_bsd_getresgid(abi_ulong arg1, abi_ulong arg2, + abi_ulong arg3) +{ + abi_long ret; + uid_t ruid, euid, suid; + + ret = get_errno(getresgid(&ruid, &euid, &suid)); + if (is_error(ret)) { + return ret; + } + if (put_user_s32(ruid, arg1)) { + return -TARGET_EFAULT; + } + if (put_user_s32(euid, arg2)) { + return -TARGET_EFAULT; + } + if (put_user_s32(suid, arg3)) { + return -TARGET_EFAULT; + } + return ret; +} + +/* getsid(2) */ +static inline abi_long do_bsd_getsid(abi_long arg1) +{ + return get_errno(getsid(arg1)); +} + +/* setsid(2) */ +static inline abi_long do_bsd_setsid(void) +{ + return get_errno(setsid()); +} + +/* issetugid(2) */ +static inline abi_long do_bsd_issetugid(void) +{ + return get_errno(issetugid()); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7565e69e76d..7b51f4f16e4 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -315,6 +315,34 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setregid(arg1, arg2); break; + case TARGET_FREEBSD_NR_getresuid: /* getresuid(2) */ + ret = do_bsd_getresuid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getresgid: /* getresgid(2) */ + ret = do_bsd_getresgid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_setresuid: /* setresuid(2) */ + ret = do_bsd_setresuid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_setresgid: /* setresgid(2) */ + ret = do_bsd_setresgid(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getsid: /* getsid(2) */ + ret = do_bsd_getsid(arg1); + break; + + case TARGET_FREEBSD_NR_setsid: /* setsid(2) */ + ret = do_bsd_setsid(); + break; + + case TARGET_FREEBSD_NR_issetugid: /* issetugid(2) */ + ret = do_bsd_issetugid(); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35F79E8FDC3 for ; Tue, 3 Oct 2023 23:37:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovI-00047l-Kr; Tue, 03 Oct 2023 19:35: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 1qnovF-00045N-Qx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:25 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovE-00070n-0F for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:25 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79f8e4108c3so64861039f.3 for ; Tue, 03 Oct 2023 16:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376122; x=1696980922; 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=zC6tWs4rfSzDMqqF62xFCimHfrup5j1pBNgITHNb/0k=; b=nYSR44qxyJvpGlWBujbeUWKVeRqCNBi3k8iapNP4q44j5o2P/tDnjgkQoAFNU1rVMc bI1VJFERW/8yMF+aC1X9nYXEpTnJY6iozCbYFcbqSh1IKsCACg7mLRN/dg5OzEUkWhaS ILEPfZkGmMIh4wzVfww6hTo+Hk7tBYQQaNVzQUntEd1HZRc1agy4dfcBZ8kM7sU/LuVr cSADprbKSqT3gQQUngJeIjmNx1ic21LQ6fMmApn+pEvLNgoZF0uA69HVybq5m/0FFeJt QVxeMNW7x2ErWjqLFD0SN2IlYKmIYNYQPp1gI+jdbAvZ0jPv91GpoRYOdX/MDRmxLj38 KhMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376122; x=1696980922; 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=zC6tWs4rfSzDMqqF62xFCimHfrup5j1pBNgITHNb/0k=; b=Rwsca4QRdZ3NC9Tr7g1AdJjhnJHd+Qt0dTt2/noKR3r74HS5JulMdwgW6nijSdCI5O 95dC2qgNtGAOtdr888iOJ8x5RFNAaEsGNFHwjJyXTebPvdQ0anH6yc5DNPBND39m8tqv QYpCP2vAMQUYRuPI3Ilm9+cMhxR5R7/B9UaoRoi3v3mMOjpqVgirIwW9I40TsKd1v7ND iZkKMGdkU1BIiW3nRlnjS7jubZWdNE9zowtaorwXd7c8VFGKtjHG+YUEIJrzHPDizU8t UesU8Nzl7VfWo4ykIf0giXuOlGvYFOyURPt0I83QVmAPP5gYxKnKwcos0Lk8nmY6x1ya EKFA== X-Gm-Message-State: AOJu0YyVF6HtnQIY6l7lN9rInbW25n4UN5UOolR+aFLN6SYO2/QHe10m lkSxQqGRYzN0hV9Ww5vn8N45apzd+8bpqK3VYy2SRw== X-Google-Smtp-Source: AGHT+IEgvy38efNg4J5FZthuXhfl+xpTKfx0io9lT/m+8ulb/uQBYchlvjujBlkp7JFAZ9HxxboU9Q== X-Received: by 2002:a6b:f209:0:b0:79f:9574:b93c with SMTP id q9-20020a6bf209000000b0079f9574b93cmr879342ioh.0.1696376122486; Tue, 03 Oct 2023 16:35:22 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:22 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 17/51] bsd-user: Add stubs for profil(2), ktrace(2), utrace(2) and ptrace(2). Date: Tue, 3 Oct 2023 17:31:41 -0600 Message-ID: <20231003233215.95557-18-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-18-kariem.taha2.7@gmail.com> --- 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 a5f301c72ff..2c1a9ae22fa 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -362,4 +362,32 @@ static inline abi_long do_bsd_issetugid(void) return get_errno(issetugid()); } +/* profil(2) */ +static inline abi_long do_bsd_profil(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4) +{ + return -TARGET_ENOSYS; +} + +/* ktrace(2) */ +static inline abi_long do_bsd_ktrace(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4) +{ + return -TARGET_ENOSYS; +} + +/* utrace(2) */ +static inline abi_long do_bsd_utrace(abi_long arg1, abi_long arg2) +{ + return -TARGET_ENOSYS; +} + + +/* ptrace(2) */ +static inline abi_long do_bsd_ptrace(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4) +{ + return -TARGET_ENOSYS; +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7b51f4f16e4..1a760b13808 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -343,6 +343,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_issetugid(); break; + case TARGET_FREEBSD_NR_profil: /* profil(2) */ + ret = do_bsd_profil(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_ktrace: /* ktrace(2) */ + ret = do_bsd_ktrace(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ + ret = do_bsd_utrace(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_ptrace: /* ptrace(2) */ + ret = do_bsd_ptrace(arg1, arg2, arg3, arg4); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2188E8FDC0 for ; Tue, 3 Oct 2023 23:39:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovI-00047P-3H; Tue, 03 Oct 2023 19:35: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 1qnovG-00045h-Aw for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:26 -0400 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovE-000719-M8 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:26 -0400 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-79fe6da0095so60241539f.0 for ; Tue, 03 Oct 2023 16:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376123; x=1696980923; 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=tN2OEe5rYzQGfb+nOOMon2seHs5SrR+EQ42mg0JPMFg=; b=oRtvZQN/ok44oUDkrKAQJLiElIfAAADDhzzQHhinGmjDVcDOz1VNHG63sshI4+c/B8 T60vOK/eDdoOvHbtx53o2tnwamDtAGNMYWgTQFBDOOKdOXHw1OA3K2IuDXb/sQ4VJ+2L JKui/M9OzbLDyxtiDzfNmB8ADYp7Iv9wl3A6iAoNqGb9xh6O8fVHZpp5A9vz9JPXcnln YmU+nsdwK3rpuzVq9QTARHo1MbIxDSLLuj+zqrAJPTWfay+Z/C4HYCUY2o1PZVH18iFl f2E6fFrjwPNpTxFsrQyyOH8yZcsVlWMKzF2YXT4k/08bg48LG/jI5siSZ9VPjaJUxyo1 Re0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376123; x=1696980923; 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=tN2OEe5rYzQGfb+nOOMon2seHs5SrR+EQ42mg0JPMFg=; b=FJyGCu4/dkt+qF+k9W3vfrfoMMJTKgkt29RbhD3x98fZWzu6NhHJVBYd3wYy7avNvA +XVrNSCPSEsv1U8uxkhG+U2DYghsn4yK0ztwclzS26pR+Sg/Ku0OBwu3Mr9p4uLJWcOA 8dwLQNt8ii0JxPS2qWyYOIbjvXIz62qo9H0ZNs9eijH2fGMH4M1pi1rxtxMHuiAPKS+t 7lyYHBwJ7PjWnN53WXUVgEprd6c9/ucX+AnIKObMwSYq6eLE/sz03axyYh/MR/6g72DW k9R3C1gmYHy55XInBn8zNWWi5WlrwpXyqIYaEhjLpEul50UQ0z0vMwYXVV8YE1cEY43U hPFA== X-Gm-Message-State: AOJu0YyO0rtMV/BZp9qrKA2Umx7L1OG3yBfbFX0SrBDVgU4A7OPNeSrE YaNT+dSZFo4J9vvqSc6GrO50zLU19YM0jgHhJIdLAA== X-Google-Smtp-Source: AGHT+IGu73C870FKUKyG6qdiMQofMSs+XPxu0tSixF/UVsAwldP05qJ6CzVK6ArPBhsKGAqD3rpasw== X-Received: by 2002:a05:6602:220e:b0:786:f352:e3d4 with SMTP id n14-20020a056602220e00b00786f352e3d4mr983515ion.7.1696376123392; Tue, 03 Oct 2023 16:35:23 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:23 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 18/51] bsd-user: Implement getpriority(2) and setpriority(2). Date: Tue, 3 Oct 2023 17:31:42 -0600 Message-ID: <20231003233215.95557-19-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-19-kariem.taha2.7@gmail.com> --- 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 2c1a9ae22fa..9a8912361f6 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -390,4 +390,28 @@ static inline abi_long do_bsd_ptrace(abi_long arg1, abi_long arg2, return -TARGET_ENOSYS; } +/* getpriority(2) */ +static inline abi_long do_bsd_getpriority(abi_long which, abi_long who) +{ + abi_long ret; + /* + * Note that negative values are valid for getpriority, so we must + * differentiate based on errno settings. + */ + errno = 0; + ret = getpriority(which, who); + if (ret == -1 && errno != 0) { + return -host_to_target_errno(errno); + } + + return ret; +} + +/* setpriority(2) */ +static inline abi_long do_bsd_setpriority(abi_long which, abi_long who, + abi_long prio) +{ + return get_errno(setpriority(which, who, prio)); +} + #endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 1a760b13808..71a2657dd0f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -359,6 +359,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_ptrace(arg1, arg2, arg3, arg4); break; + case TARGET_FREEBSD_NR_getpriority: /* getpriority(2) */ + ret = do_bsd_getpriority(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setpriority: /* setpriority(2) */ + ret = do_bsd_setpriority(arg1, arg2, arg3); + break; + /* * File system calls. From patchwork Tue Oct 3 23:31:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61EA5E8FDC1 for ; Tue, 3 Oct 2023 23:40:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovL-00049W-5E; Tue, 03 Oct 2023 19:35:31 -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 1qnovJ-00048T-UD for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:29 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovI-00071Q-4Z for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:29 -0400 Received: by mail-io1-xd41.google.com with SMTP id ca18e2360f4ac-79f915e5b47so59904339f.2 for ; Tue, 03 Oct 2023 16:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376124; x=1696980924; 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=vv+aIku3DmAqisUQxx9HbMj8tI0pAJwZVGFoGM6lqnw=; b=kokjwctmR6dOZXx8mqR/7KOyarl6r7QTq5FaSo6N9kkW+CzVtjqd7LjVAsW11xLePW Mi+6X9kdkMLWt7FmLCsAJRaNEWf9bqgS6x5O3pEFuXt2tbAjYDIUhcKaScaZzyuVJ7yo Ms6XPwLl1/2g0n9GpBgihIL6wvodm4ore9L8QXln0SphV2EhACCBXbNK3yRbB3/JjH0H hGfRPRwI2UNODPd4yNMwPYjhRjdUG+l86zPqjz+rmtBDdlTBPmMIrEVxMNm3okq3BrRg J9eJ2sogXFEUlkL49Pp+ai21oUxk9aGduWI9Te8NppKLW/gbYFyaNLs1zt5BPnp0iBo3 ZkGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376124; x=1696980924; 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=vv+aIku3DmAqisUQxx9HbMj8tI0pAJwZVGFoGM6lqnw=; b=C1zdKnyHieWmca/LwzSlJELQR3r/9g4q40UhbImWMV6cmGFHoB2mS+EKsKdUQxxmMu 1mbqhw+WgLdQVFt6Pf4WVWuJbqr2essTixXP5JPsBGEkSJLmTVAS2PJzMbyWgxV0GJAh b8aXTNAM3c1AY2wjFLm133oQyUsHnL1huUPr4WZ0ea+irx8fBe/pZQ49U/glnkjg/zQn AB8ttyZpMK0dyKRbrh9vkdNPnnSYDP/eWcSKMAiN9b7Zl+1ZUjt4jrlB6a0Rx7YOZtWr GUZQAJk0leoiFBnJ8GMCgaFQT5DE72qLdwgWxa6slLFBWG5+03pg7eKzeOO9K/3TsB99 kHWA== X-Gm-Message-State: AOJu0YwPGz4ky4bixA9Q4wpoZyOWI76Pc/vdmgWIIDrZY8Sj1aHpdKxn cUWuwc+omUSwVTiLh1DqvjQ0IJK3W/QsTH01wygelhpZ X-Google-Smtp-Source: AGHT+IFw4OoDwo4flJGVdNrfgTtXrScqPpMtqyLxdUBmxMbcaRVLolhNc8uhX597cfLvsI7THGuRbg== X-Received: by 2002:a5d:9943:0:b0:79f:9eb4:3ea1 with SMTP id v3-20020a5d9943000000b0079f9eb43ea1mr1019417ios.3.1696376124287; Tue, 03 Oct 2023 16:35:24 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:23 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Stacey Son , Richard Henderson Subject: [PULL 19/51] bsd-user: Implement get_filename_from_fd. Date: Tue, 3 Oct 2023 17:31:43 -0600 Message-ID: <20231003233215.95557-20-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Karim Taha Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-20-kariem.taha2.7@gmail.com> --- bsd-user/freebsd/meson.build | 1 + bsd-user/freebsd/os-proc.c | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 83 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 f2f047cca31..8fd6c7cfb82 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 00000000000..2603c5c6538 --- /dev/null +++ b/bsd-user/freebsd/os-proc.c @@ -0,0 +1,82 @@ +/* + * 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. + */ +char * +get_filename_from_fd(pid_t pid, int fd, char *filename, size_t len); +char * +get_filename_from_fd(pid_t pid, int fd, char *filename, size_t len) +{ + char *ret = NULL; + unsigned int cnt; + struct procstat *procstat = NULL; + struct kinfo_proc *kp = NULL; + struct filestat_list *head = NULL; + struct filestat *fst; + + procstat = procstat_open_sysctl(); + if (procstat == NULL) { + goto out; + } + + kp = procstat_getprocs(procstat, KERN_PROC_PID, pid, &cnt); + if (kp == NULL) { + goto out; + } + + head = procstat_getfiles(procstat, kp, 0); + if (head == NULL) { + goto out; + } + + STAILQ_FOREACH(fst, head, next) { + if (fd == fst->fs_fd) { + if (fst->fs_path != NULL) { + (void)strlcpy(filename, fst->fs_path, len); + ret = filename; + } + break; + } + } + +out: + if (head != NULL) { + procstat_freefiles(procstat, head); + } + if (kp != NULL) { + procstat_freeprocs(procstat, kp); + } + if (procstat != NULL) { + procstat_close(procstat); + } + return ret; +} + From patchwork Tue Oct 3 23:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2DBAE8FDC1 for ; Tue, 3 Oct 2023 23:41:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovK-00049N-Tk; Tue, 03 Oct 2023 19:35:30 -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 1qnovI-000486-Lk for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:28 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovG-00072n-Pb for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:28 -0400 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-79fe8986355so59681139f.2 for ; Tue, 03 Oct 2023 16:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376125; x=1696980925; 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=sv5fIcvD1HSjiZO4IkYJ3Frs5DqY4m3pn2tlZXjMwRw=; b=NzOkPeKZDKo5R8PFmAP5/IiOgx3c/2pyDiCGz43xiZPrn7M0RO9Yoz3NFUzbwirNBF rjJ+5BHAklZ2fqasZ//HcGFPdfUUXXblCWzVDJsw6dIYcMdhrdHLYgotrpYr0/H8lfJx iA+m4gVmQFycyxGovqamuN72E6TyRgwLtfMzsLqJvjF3FP+kechZL2pQaWKY4fD1Fg16 PIT5mkbj9kELQ192ljafjBJ/CLmVSaBbR5F/KWZYUuTInkSbdmw6eD1BbnBr363IhG66 fia47EVVQ5gJnS1STg0JKKMDnWjiPwZiHVU09sJVzWte0DHFLHgBrxmLM4h1gUHovUBk dFFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376125; x=1696980925; 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=sv5fIcvD1HSjiZO4IkYJ3Frs5DqY4m3pn2tlZXjMwRw=; b=CkYJNyDPdS/fGxQVjVgubtfjen9NpGMVSbaQ2EMVEUgOg9loXOh7AJ2tSeidyJBgMC EKP0pdRwFVKuMXFwsY9ud+877OCnYfPy2CFa3VUQH8EXWRP4EN7H2HmgJcLCYY2TUDzP SsGFzcaoaAb9TTbsE0UNQZ6TVI1oOY4kLwTnwhBP0SpxcWI+Rw6J31pXfT76Gx2qebg2 RdE62UIs4QBUFl46oO1RaSnU+KigpTY8KAP3DE2b/9XDT16CqprG2CBMc81UDvxqg7XJ e9b3Q8NhKOFkrydeQIY57drFQ9Vu4QSD+QxfBRJdYHIvpyiiZ+0KYlwrsaANB53c+LfE mDkw== X-Gm-Message-State: AOJu0YzUrFDDEFyN8v1oyNyxE0j/d4O89w4/oQHAx6dQRHksnEPGoRez 7Yi/y4pWIyvET+l0+/7DDP88GYcbKW86Il9qJZ516g== X-Google-Smtp-Source: AGHT+IHihLl8StzxS1Av2J8nfFrSkmsiigD5A2jkilmvDE6tVDJ3UGgleQ8UsZyDqLw3y8uNlwkClw== X-Received: by 2002:a5d:9e19:0:b0:792:82f8:7402 with SMTP id h25-20020a5d9e19000000b0079282f87402mr991412ioh.16.1696376125147; Tue, 03 Oct 2023 16:35:25 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:24 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 20/51] bsd-user: Implement freebsd_exec_common, used in implementing execve/fexecve. Date: Tue, 3 Oct 2023 17:31:44 -0600 Message-ID: <20231003233215.95557-21-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-21-kariem.taha2.7@gmail.com> --- bsd-user/freebsd/os-proc.c | 181 ++++++++++++++++++++++++++++++++++++- bsd-user/main.c | 2 +- bsd-user/qemu.h | 1 + 3 files changed, 180 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c index 2603c5c6538..12d78b7fc98 100644 --- a/bsd-user/freebsd/os-proc.c +++ b/bsd-user/freebsd/os-proc.c @@ -30,9 +30,7 @@ struct kinfo_proc; * Get the filename for the given file descriptor. * Note that this may return NULL (fail) if no longer cached in the kernel. */ -char * -get_filename_from_fd(pid_t pid, int fd, char *filename, size_t len); -char * +static char * get_filename_from_fd(pid_t pid, int fd, char *filename, size_t len) { char *ret = NULL; @@ -80,3 +78,180 @@ out: return ret; } +/* + * execve/fexecve + */ +abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, + abi_ulong guest_envp, int do_fexec) +{ + char **argp, **envp, **qargp, **qarg1, **qarg0, **qargend; + int argc, envc; + abi_ulong gp; + abi_ulong addr; + char **q; + int total_size = 0; + void *p; + abi_long ret; + + argc = 0; + for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) { + if (get_user_ual(addr, gp)) { + return -TARGET_EFAULT; + } + if (!addr) { + break; + } + argc++; + } + envc = 0; + for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) { + if (get_user_ual(addr, gp)) { + return -TARGET_EFAULT; + } + if (!addr) { + break; + } + envc++; + } + + qarg0 = argp = g_new0(char *, argc + 9); + /* save the first agrument for the emulator */ + *argp++ = (char *)getprogname(); + qargp = argp; + *argp++ = (char *)getprogname(); + qarg1 = argp; + envp = g_new0(char *, envc + 1); + for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp)) { + ret = -TARGET_EFAULT; + goto execve_end; + } + if (!addr) { + break; + } + *q = lock_user_string(addr); + if (*q == NULL) { + ret = -TARGET_EFAULT; + goto execve_end; + } + total_size += strlen(*q) + 1; + } + *q++ = NULL; + qargend = q; + + for (gp = guest_envp, q = envp; gp; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp)) { + ret = -TARGET_EFAULT; + goto execve_end; + } + if (!addr) { + break; + } + *q = lock_user_string(addr); + if (*q == NULL) { + ret = -TARGET_EFAULT; + goto execve_end; + } + total_size += strlen(*q) + 1; + } + *q = NULL; + + /* + * This case will not be caught by the host's execve() if its + * page size is bigger than the target's. + */ + if (total_size > MAX_ARG_PAGES * TARGET_PAGE_SIZE) { + ret = -TARGET_E2BIG; + goto execve_end; + } + + if (do_fexec) { + if (((int)path_or_fd > 0 && + is_target_elf_binary((int)path_or_fd)) == 1) { + char execpath[PATH_MAX]; + + /* + * The executable is an elf binary for the target + * arch. execve() it using the emulator if we can + * determine the filename path from the fd. + */ + if (get_filename_from_fd(getpid(), (int)path_or_fd, execpath, + sizeof(execpath)) != NULL) { + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + qarg1[1] = qarg1[0]; + qarg1[0] = (char *)"-0"; + qarg1 += 2; + qargend += 2; + *qarg1 = execpath; +#ifndef DONT_INHERIT_INTERP_PREFIX + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + *qarg1++ = (char *)"-L"; + *qarg1++ = (char *)interp_prefix; +#endif + ret = get_errno(execve(qemu_proc_pathname, qargp, envp)); + } else { + /* Getting the filename path failed. */ + ret = -TARGET_EBADF; + goto execve_end; + } + } else { + ret = get_errno(fexecve((int)path_or_fd, argp, envp)); + } + } else { + int fd; + + p = lock_user_string(path_or_fd); + if (p == NULL) { + ret = -TARGET_EFAULT; + goto execve_end; + } + + /* + * Check the header and see if it a target elf binary. If so + * then execute using qemu user mode emulator. + */ + fd = open(p, O_RDONLY | O_CLOEXEC); + if (fd > 0 && is_target_elf_binary(fd) == 1) { + close(fd); + /* execve() as a target binary using emulator. */ + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + qarg1[1] = qarg1[0]; + qarg1[0] = (char *)"-0"; + qarg1 += 2; + qargend += 2; + *qarg1 = (char *)p; +#ifndef DONT_INHERIT_INTERP_PREFIX + memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); + *qarg1++ = (char *)"-L"; + *qarg1++ = (char *)interp_prefix; +#endif + ret = get_errno(execve(qemu_proc_pathname, qargp, envp)); + } else { + close(fd); + /* Execve() as a host native binary. */ + ret = get_errno(execve(p, argp, envp)); + } + unlock_user(p, path_or_fd, 0); + } + +execve_end: + for (gp = guest_argp, q = argp; *q; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp) || !addr) { + break; + } + unlock_user(*q, addr, 0); + } + + for (gp = guest_envp, q = envp; *q; gp += sizeof(abi_ulong), q++) { + if (get_user_ual(addr, gp) || !addr) { + break; + } + unlock_user(*q, addr, 0); + } + + g_free(qarg0); + g_free(envp); + + return ret; +} + diff --git a/bsd-user/main.c b/bsd-user/main.c index f913cb55a72..a12b4be80f1 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -88,7 +88,7 @@ unsigned long reserved_va = MAX_RESERVED_VA; unsigned long reserved_va; #endif -static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; +const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 41c7bd31d3c..6047805ae38 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -111,6 +111,7 @@ typedef struct TaskState { } __attribute__((aligned(16))) TaskState; void stop_all_tasks(void); +extern const char *interp_prefix; extern const char *qemu_uname_release; /* From patchwork Tue Oct 3 23:31:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408110 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E003E8FDBF for ; Tue, 3 Oct 2023 23:37:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovZ-0004FS-4E; Tue, 03 Oct 2023 19:35:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovW-0004Ee-PH for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:43 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovH-00077d-DD for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:42 -0400 Received: by mail-io1-xd44.google.com with SMTP id ca18e2360f4ac-79fbbb2bed0so12694439f.1 for ; Tue, 03 Oct 2023 16:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376126; x=1696980926; 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=XzrnmNRArI5YZLKP54kV4TVNyU5J4UUrUXJQ/E152oI=; b=lcMnqVVdFImCWDT5CLciz2VyEOeuOL6Iov2ksGwf75PcqvPqBSxwzJKmZBokJqnQBe ghIxD5ArHqBpogc2DaJVpAeJ+pRrCYLjxDlmuZ/RO0FEUFKwnkF7rwpCie5DlB1M/UUh 4R32bCUZAfRIX8vs8GnPFwi3aPiN4juGS3SeVkASZqNP0ubllv6zzXJhVoEQ6IFapFHD oBZdTZumRoYlkog+srl5Gkt3hsGqlVQsCqo8eSEMi5+tNOKhWKMtuZ47J6UeFZdEfmvY L25AXDtRqY2CD8tPkiun+Sspu8w0bqjladyeB69q66K7YF4bH3xipL/0NAY+saXshSrY AgJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376126; x=1696980926; 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=XzrnmNRArI5YZLKP54kV4TVNyU5J4UUrUXJQ/E152oI=; b=lEPS912//S+1OcQFumjUGpGKG50F6SOPcyD8ZzoyntVweYh3Mgs0hUBVO/+EyfUXrP 7fJTemS9pXM5PU5q0l+C9D/bap2C3VuaehSuSYe1MVBmGpH+6Q2bQ6HGtCvqrR31Vz7T j/JR0CzqBCE0WnXsLRJo9j0aFAPOb/BCCMXxEOvu4kFd7imuDnLkq+J8dNY3SkNNXW4E aNdbcNUJ6lIiOW+lx5VEOftM4/fUi7eqPq3iE4WgpPrK97EtDVAqYodLIQJ9FVTbhIOk wIOnl/0DUAds1f1a930rjkDJujaXxjz0+9AVYfAidDKY13yvHkcbCZxJv3Ci4IDQE66c sCUQ== X-Gm-Message-State: AOJu0Yyam8Dq3c43BoblCilNCqH1WTZ27gk5e/xad7Nex/QPMTl/ugqQ 0m8a5jxHboIqcVgOOpcqCqBRshivsELjlvg2/U274Hqr X-Google-Smtp-Source: AGHT+IEOM6zCTFwEwwYHJOFC6Z92TAqv1Eg04bCd4ztp56QCTf5GFBqIn8nUxX3MhljOaMezxPFmxA== X-Received: by 2002:a6b:740d:0:b0:790:aed5:d0b0 with SMTP id s13-20020a6b740d000000b00790aed5d0b0mr578583iog.0.1696376126114; Tue, 03 Oct 2023 16:35:26 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:25 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 21/51] bsd-user: Implement procctl(2) along with necessary conversion functions. Date: Tue, 3 Oct 2023 17:31:45 -0600 Message-ID: <20231003233215.95557-22-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d44; envelope-from=imp@bsdimp.com; helo=mail-io1-xd44.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Implement t2h_procctl_cmd, h2t_reaper_status, h2t_reaper_pidinfo and h2t/t2h reaper_kill conversion functions. Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-22-kariem.taha2.7@gmail.com> --- bsd-user/freebsd/os-proc.c | 223 ++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 3 + 2 files changed, 226 insertions(+) diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c index 12d78b7fc98..4e67ae4d56c 100644 --- a/bsd-user/freebsd/os-proc.c +++ b/bsd-user/freebsd/os-proc.c @@ -255,3 +255,226 @@ execve_end: return ret; } +#include + +static abi_long +t2h_procctl_cmd(int target_cmd, int *host_cmd) +{ + switch (target_cmd) { + case TARGET_PROC_SPROTECT: + *host_cmd = PROC_SPROTECT; + break; + + case TARGET_PROC_REAP_ACQUIRE: + *host_cmd = PROC_REAP_ACQUIRE; + break; + + case TARGET_PROC_REAP_RELEASE: + *host_cmd = PROC_REAP_RELEASE; + break; + + case TARGET_PROC_REAP_STATUS: + *host_cmd = PROC_REAP_STATUS; + break; + + case TARGET_PROC_REAP_KILL: + *host_cmd = PROC_REAP_KILL; + break; + + default: + return -TARGET_EINVAL; + } + + return 0; +} + +static abi_long +h2t_reaper_status(struct procctl_reaper_status *host_rs, + abi_ulong target_rs_addr) +{ + struct target_procctl_reaper_status *target_rs; + + if (!lock_user_struct(VERIFY_WRITE, target_rs, target_rs_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_rs->rs_flags, &target_rs->rs_flags); + __put_user(host_rs->rs_children, &target_rs->rs_children); + __put_user(host_rs->rs_descendants, &target_rs->rs_descendants); + __put_user(host_rs->rs_reaper, &target_rs->rs_reaper); + __put_user(host_rs->rs_pid, &target_rs->rs_pid); + unlock_user_struct(target_rs, target_rs_addr, 1); + + return 0; +} + +static abi_long +t2h_reaper_kill(abi_ulong target_rk_addr, struct procctl_reaper_kill *host_rk) +{ + struct target_procctl_reaper_kill *target_rk; + + if (!lock_user_struct(VERIFY_READ, target_rk, target_rk_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_rk->rk_sig, &target_rk->rk_sig); + __get_user(host_rk->rk_flags, &target_rk->rk_flags); + __get_user(host_rk->rk_subtree, &target_rk->rk_subtree); + __get_user(host_rk->rk_killed, &target_rk->rk_killed); + __get_user(host_rk->rk_fpid, &target_rk->rk_fpid); + unlock_user_struct(target_rk, target_rk_addr, 0); + + return 0; +} + +static abi_long +h2t_reaper_kill(struct procctl_reaper_kill *host_rk, abi_ulong target_rk_addr) +{ + struct target_procctl_reaper_kill *target_rk; + + if (!lock_user_struct(VERIFY_WRITE, target_rk, target_rk_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_rk->rk_sig, &target_rk->rk_sig); + __put_user(host_rk->rk_flags, &target_rk->rk_flags); + __put_user(host_rk->rk_subtree, &target_rk->rk_subtree); + __put_user(host_rk->rk_killed, &target_rk->rk_killed); + __put_user(host_rk->rk_fpid, &target_rk->rk_fpid); + unlock_user_struct(target_rk, target_rk_addr, 1); + + return 0; +} + +static abi_long +h2t_procctl_reaper_pidinfo(struct procctl_reaper_pidinfo *host_pi, + abi_ulong target_pi_addr) +{ + struct target_procctl_reaper_pidinfo *target_pi; + + if (!lock_user_struct(VERIFY_WRITE, target_pi, target_pi_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_pi->pi_pid, &target_pi->pi_pid); + __put_user(host_pi->pi_subtree, &target_pi->pi_subtree); + __put_user(host_pi->pi_flags, &target_pi->pi_flags); + unlock_user_struct(target_pi, target_pi_addr, 1); + + return 0; +} + +abi_long +do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong arg2, abi_ulong arg3, + abi_ulong arg4, abi_ulong arg5, abi_ulong arg6) +{ + abi_long error = 0, target_rp_pids; + void *data; + int host_cmd, flags; + uint32_t u, target_rp_count; + g_autofree union { + struct procctl_reaper_status rs; + struct procctl_reaper_pids rp; + struct procctl_reaper_kill rk; + } host; + struct target_procctl_reaper_pids *target_rp; + id_t id; /* 64-bit */ + int target_cmd; + abi_ulong target_arg; + +#if TARGET_ABI_BITS == 32 + /* See if we need to align the register pairs. */ + if (regpairs_aligned(cpu_env)) { + id = (id_t)target_arg64(arg3, arg4); + target_cmd = (int)arg5; + target_arg = arg6; + } else { + id = (id_t)target_arg64(arg2, arg3); + target_cmd = (int)arg4; + target_arg = arg5; + } +#else + id = (id_t)arg2; + target_cmd = (int)arg3; + target_arg = arg4; +#endif + + error = t2h_procctl_cmd(target_cmd, &host_cmd); + if (error) { + return error; + } + switch (host_cmd) { + case PROC_SPROTECT: + data = &flags; + break; + + case PROC_REAP_ACQUIRE: + case PROC_REAP_RELEASE: + if (target_arg == 0) { + data = NULL; + } else { + error = -TARGET_EINVAL; + } + break; + + case PROC_REAP_STATUS: + data = &host.rs; + break; + + case PROC_REAP_GETPIDS: + if (!lock_user_struct(VERIFY_READ, target_rp, target_arg, 1)) { + return -TARGET_EFAULT; + } + __get_user(target_rp_count, &target_rp->rp_count); + __get_user(target_rp_pids, &target_rp->rp_pids); + unlock_user_struct(target_rp, target_arg, 0); + host.rp.rp_count = target_rp_count; + host.rp.rp_pids = g_try_new(struct procctl_reaper_pidinfo, + target_rp_count); + + if (host.rp.rp_pids == NULL) { + error = -TARGET_ENOMEM; + } else { + data = &host.rp; + } + break; + + case PROC_REAP_KILL: + error = t2h_reaper_kill(target_arg, &host.rk); + break; + } + + if (error) { + return error; + } + error = get_errno(procctl(idtype, id, host_cmd, data)); + + if (error) { + return error; + } + switch (host_cmd) { + case PROC_SPROTECT: + if (put_user_s32(flags, target_arg)) { + return -TARGET_EFAULT; + } + break; + + case PROC_REAP_STATUS: + error = h2t_reaper_status(&host.rs, target_arg); + break; + + case PROC_REAP_GETPIDS: + /* copyout reaper pidinfo */ + for (u = 0; u < target_rp_count; u++) { + error = h2t_procctl_reaper_pidinfo(&host.rp.rp_pids[u], + target_rp_pids + + (u * sizeof(struct target_procctl_reaper_pidinfo))); + if (error) { + break; + } + } + break; + + case PROC_REAP_KILL: + error = h2t_reaper_kill(&host.rk, target_arg); + break; + } + + return error; +} diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 71a2657dd0f..b7bd0b92a65 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -367,6 +367,9 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_setpriority(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_procctl: /* procctl(2) */ + ret = do_freebsd_procctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; /* * File system calls. From patchwork Tue Oct 3 23:31:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A90ADE8FDC2 for ; Tue, 3 Oct 2023 23:36:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovS-0004DN-NT; Tue, 03 Oct 2023 19:35:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovN-0004AZ-PR for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:33 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovI-00077q-CZ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:33 -0400 Received: by mail-io1-xd41.google.com with SMTP id ca18e2360f4ac-79fa7e33573so58985339f.0 for ; Tue, 03 Oct 2023 16:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376127; x=1696980927; 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=khpHNEzdfaCxbzIOhGKqgUaYTgRrgL4oE446jB+w2fk=; b=jEHKqPNNid6cj37tjHV71FKm/wBiTNCwcgi1EDvdqJEmdeyjkU8Vn7eX+cGSCjM/dz wMMU+rQvqPe3S3z/SGHLZwQuIeqU0XSZkdOnsar77bubHLxEOxF9a5ftACE92tIhbMno tP6CkDbfUUO2KL5b4fbXa3bJ3y0j/gmofqBr1m6olVGzBcQ0/aXhm3GoCTLLmGX/lZnv GyV0YhQ7spuCCndnm3DRs8yzS0Syn1/jFFKPArajVc4yYMj1iK0kL3LxGWWBeepZsFwW 8BwKWLNrlpFfsJ5E8DLypu6atW9Qtu3SEzfoFiXEcPssfhHHNELFfhlmOM6KoPSIq9Qf d7YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376127; x=1696980927; 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=khpHNEzdfaCxbzIOhGKqgUaYTgRrgL4oE446jB+w2fk=; b=gKGpWcEEYoj4ZYkOG19v98ShWUE4fk0Wf2rKPJ+f/gXO25Rr+PnzUONrlyLc0tNT8o ekJokhm851R8TAeJhQQAaD2XzG+g+odfvznFp1J05TXZwrLsPQxibfyTy/5x/3oRp/q+ 1Cv65Flxrq63W8BbnCbCVzIQtMaO+sxQJQXbw3FHfXObk9tFGFeYbqrARmXHytCYgjU/ 1F6q7UXCOqW9vK4S9CN6sm2lNCw9VykjAf6sRc+N7Yf2HbA1tJRRwgP64fCbPLVF9Ry/ UYHq/WBg8yH6rwxfcg6H2u2d8ovyEtnB5ebYpaCJquSFrRrfED4ri/y/KnNrP0TH+WzW 1QzQ== X-Gm-Message-State: AOJu0YzaGpg9r315Lb/grWkRqiB5gdfc9kAyngsr7PeNCHiPqH/mmOAc /8v16c8AVO/YsEQz12dZ2tKFjR3YrJSweprMbjD95WqQ X-Google-Smtp-Source: AGHT+IEPv+LwyuqopHtCwJPkJmaoe6ylMiGdwKP7pV7r3B7QYlLzRXCazGXaRgnZ+XsSe231hKzOsA== X-Received: by 2002:a5e:dd0d:0:b0:786:7100:72de with SMTP id t13-20020a5edd0d000000b00786710072demr895056iop.16.1696376127036; Tue, 03 Oct 2023 16:35:27 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:26 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Stacey Son , Richard Henderson Subject: [PULL 22/51] bsd-user: Implement execve(2) and fexecve(2) system calls. Date: Tue, 3 Oct 2023 17:31:46 -0600 Message-ID: <20231003233215.95557-23-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Karim Taha Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-23-kariem.taha2.7@gmail.com> --- 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 00000000000..75ed39f8ddd --- /dev/null +++ b/bsd-user/freebsd/os-proc.h @@ -0,0 +1,49 @@ +/* + * process related system call shims and definitions + * + * Copyright (c) 2013-14 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef BSD_USER_FREEBSD_OS_PROC_H +#define BSD_USER_FREEBSD_OS_PROC_H + +#include +#include +#include +#include +#include +#include +#include + +#include "target_arch_cpu.h" + +/* execve(2) */ +static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp, + abi_ulong envp) +{ + + return freebsd_exec_common(path_or_fd, argp, envp, 0); +} + +/* fexecve(2) */ +static inline abi_long do_freebsd_fexecve(abi_ulong path_or_fd, abi_ulong argp, + abi_ulong envp) +{ + + return freebsd_exec_common(path_or_fd, argp, envp, 1); +} + +#endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index b7bd0b92a65..515eaaf31f1 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -36,8 +36,9 @@ #include "bsd-file.h" #include "bsd-proc.h" -/* *BSD dependent syscall shims */ +/* BSD dependent syscall shims */ #include "os-stat.h" +#include "os-proc.h" /* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); @@ -219,6 +220,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, /* * process system calls */ + case TARGET_FREEBSD_NR_execve: /* execve(2) */ + ret = do_freebsd_execve(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_fexecve: /* fexecve(2) */ + ret = do_freebsd_fexecve(arg1, arg2, arg3); + break; + case TARGET_FREEBSD_NR_exit: /* exit(2) */ ret = do_bsd_exit(cpu_env, arg1); break; From patchwork Tue Oct 3 23:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70B1EE8FDC2 for ; Tue, 3 Oct 2023 23:36:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovN-0004AV-Mx; Tue, 03 Oct 2023 19:35:33 -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 1qnovL-0004A0-UB for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:31 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovK-00078O-7W for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:31 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-79fe6da0095so60242839f.0 for ; Tue, 03 Oct 2023 16:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376128; x=1696980928; 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=MApO9kv1LCt8gsX2fOSXKRD/PiBDzPPW73bw9SC1hGs=; b=NPY8/T8ENlSffc5jdN7f/Kdr8n7lBr6rx+kA3o98VSNaKC+oNC7sGkPSP/a63DUZoc 6XYUoKDImG0VsYSuUwruKT9rxiROmQd6BrmgFTpAuTCvIO0QvbV3Vf+cuwHGNGl37VXu bw7hmTKrnGqBvbFhVk6ZntRReem7d2Qm+ZzDT0nh4uu956psSpokWasIpxnVZi7MWt8I IvOJwHSec8qO7Bo2l1d0hTv4bFmI1DEyZ+PBjsBkwDMYJOp4tNyB93V2EUY0SZNzYQHa EHPKstq0m37RKTm8iky8ffcAcvMMxtljz382keIt2401fnEkKmeB72p/i1pPJ/NyBS1x +MFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376128; x=1696980928; 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=MApO9kv1LCt8gsX2fOSXKRD/PiBDzPPW73bw9SC1hGs=; b=I8W7JXK2pzm2j3PsSypaV0W5tVbjFtzk3e8/CaNlbh0LDG93fcM4CCiFpzYlXs2Jog m63LPp7hjUYD4ZXsmS4psLiUy0XdW8N0E/CwhtuU6w3JXHe+Acobp1Wi9AvfxMlQoV9O /+Ycle6EZ3+lFYAO3tCQ9o3adGNW0QNOgo+nrpuksHFfLEO6fx2PADhdRmG4eFvex23n lZeAASjoYjdEkmKbqkYY9j5vJkkitUyNTA5lVnTv8thZtPEj6NNBZYjiOAhFKSEmpxbi 8MJ3gZSaPsKFTzWjPe7T/rmCDHp2xkXKpVAKyk25+KDlI7ANQadmSrAinoscZdkuhyB5 KkBw== X-Gm-Message-State: AOJu0YyfpgJD1kqWlgX8GXZJQlrQe8sId7HrVlV3cZDOY+yJ318bnwEn JD1JWcEJEnlFLBYBeUHHExygBupPD1VXxTg6sMDEpg== X-Google-Smtp-Source: AGHT+IHIJ6CnXCwlI+pGUidKxP3QG8+BUfiwt0sbHrTYnK9ER6aKuIGeRFogbKP8opbDfERVgNOUQg== X-Received: by 2002:a6b:5b16:0:b0:79f:d04d:ce59 with SMTP id v22-20020a6b5b16000000b0079fd04dce59mr976623ioh.6.1696376127996; Tue, 03 Oct 2023 16:35:27 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:27 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 23/51] bsd-user: Implement wait4(2) and wait6(2) system calls. Date: Tue, 3 Oct 2023 17:31:47 -0600 Message-ID: <20231003233215.95557-24-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-24-kariem.taha2.7@gmail.com> --- 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 75ed39f8ddd..04bce755e58 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -30,6 +30,10 @@ #include "target_arch_cpu.h" +pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage); +pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options, + struct __wrusage *wrusage, siginfo_t *infop); + /* execve(2) */ static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp, abi_ulong envp) @@ -46,4 +50,84 @@ static inline abi_long do_freebsd_fexecve(abi_ulong path_or_fd, abi_ulong argp, return freebsd_exec_common(path_or_fd, argp, envp, 1); } +/* wait4(2) */ +static inline abi_long do_freebsd_wait4(abi_long arg1, abi_ulong target_status, + abi_long arg3, abi_ulong target_rusage) +{ + abi_long ret; + int status; + struct rusage rusage, *rusage_ptr = NULL; + + if (target_rusage) { + rusage_ptr = &rusage; + } + ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr)); + + if (ret < 0) { + return ret; + } + if (target_status != 0) { + status = host_to_target_waitstatus(status); + if (put_user_s32(status, target_status) != 0) { + return -TARGET_EFAULT; + } + } + if (target_rusage != 0) { + host_to_target_rusage(target_rusage, &rusage); + } + return ret; +} + +/* wait6(2) */ +static inline abi_long do_freebsd_wait6(void *cpu_env, abi_long idtype, + abi_long id1, abi_long id2, + abi_ulong target_status, abi_long options, abi_ulong target_wrusage, + abi_ulong target_infop, abi_ulong pad1) +{ + abi_long ret; + int status; + struct __wrusage wrusage, *wrusage_ptr = NULL; + siginfo_t info; + void *p; + + if (regpairs_aligned(cpu_env) != 0) { + /* printf("shifting args\n"); */ + /* 64-bit id is aligned, so shift all the arguments over by one */ + id1 = id2; + id2 = target_status; + target_status = options; + options = target_wrusage; + target_wrusage = target_infop; + target_infop = pad1; + } + + if (target_wrusage) { + wrusage_ptr = &wrusage; + } + ret = get_errno(safe_wait6(idtype, target_arg64(id1, id2), + &status, options, wrusage_ptr, &info)); + + if (ret < 0) { + return ret; + } + if (target_status != 0) { + status = host_to_target_waitstatus(status); + if (put_user_s32(status, target_status) != 0) { + return -TARGET_EFAULT; + } + } + if (target_wrusage != 0) { + host_to_target_wrusage(target_wrusage, &wrusage); + } + if (target_infop != 0) { + p = lock_user(VERIFY_WRITE, target_infop, sizeof(target_siginfo_t), 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + host_to_target_siginfo(p, &info); + unlock_user(p, target_infop, sizeof(target_siginfo_t)); + } + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 515eaaf31f1..55e68e48159 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -40,6 +40,12 @@ #include "os-stat.h" #include "os-proc.h" +/* used in os-proc */ +safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, + struct rusage *, rusage); +safe_syscall6(pid_t, wait6, idtype_t, idtype, id_t, id, int *, status, int, + options, struct __wrusage *, wrusage, siginfo_t *, infop); + /* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t, @@ -228,6 +234,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_fexecve(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_wait4: /* wait4(2) */ + ret = do_freebsd_wait4(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_wait6: /* wait6(2) */ + ret = do_freebsd_wait6(cpu_env, arg1, arg2, arg3, + arg4, arg5, arg6, arg7, arg8); + break; + case TARGET_FREEBSD_NR_exit: /* exit(2) */ ret = do_bsd_exit(cpu_env, arg1); break; From patchwork Tue Oct 3 23:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B73A8E8FDC0 for ; Tue, 3 Oct 2023 23:41:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovQ-0004CM-VC; Tue, 03 Oct 2023 19:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovO-0004B2-7K for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:34 -0400 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovK-0007Cm-9F for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:32 -0400 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-79f909071c3so60621439f.0 for ; Tue, 03 Oct 2023 16:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376129; x=1696980929; 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=jUbIdhN9Y3KW08Z4NFjwxOiSbSnqRae3Iwiwnvnh+H4=; b=QfVLKGNoe2H/3DpPLXtE/ZiUs5T/FuqUhB5qs3tpl+ivpKa68iYtzVwHjvy/P9FHQC UAG/SplyIfG/p6LEfzHO/TPUk9vkGVvMrkPzEDbX5E9L3hd3JDnnSQuu3gPEohzn6oS+ tbiWsB8KvdSF+euZ3eARgZcbd2TFprp5C0TaY0IDCSs1eYINQQb6UmUpY7UiFWbPjq+H eT9UdMPuTyi1wymSeLjYSOclyYizmDlWymPqpSuo4D0ziKSamF6hgCbo5Jn6ynUXjDEb LQ6Jh3V1aNEuyxNFX05Cqk6UcM8kXLkYFl/mYSmzF3SJubyNM0VdX7x/N/Gn3gEGtSsG jKlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376129; x=1696980929; 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=jUbIdhN9Y3KW08Z4NFjwxOiSbSnqRae3Iwiwnvnh+H4=; b=wNbGkqr0hhbT9lhtEZgBESaDEmKrYK5ctjDwOkWxlI2UX3v3Eh334P4MhbtYZ3RA/7 1dL/U/E4bQ5QSZiLDIolsIMt3MprSlfIqRmEFkibuD42yGOtLQQDzfqS7E4sk48YP9te XnpvlKtSs7OkIwxPmqFzdLcgVTKrul0pl35tA2IKuVtTj+5zjvSeaefxGArX5Ew6dyGv b3xy1HuPCwqn4ntrYQfZozpktw2dNtywYcf5ZKsH2T+vdAUdbLaDnowjFygMq3GVKHtu +5FDchMYnHfmZ0ffOzjnew79pUt0vNfR5MfE/J7LTBMUFwygqVeNfBZfVxMLpe8KxLuQ hlpQ== X-Gm-Message-State: AOJu0YwPDlr93NOwNJyOTLi8za1NLkOQ1lNYvv0aFB6B69suhoefGHNZ L8ygNsiyFOC6Ho5rm3jP62Cm+sKRFRL1JaVWp+bU/w== X-Google-Smtp-Source: AGHT+IEZUz1APCDkGc4HP7xH/e6MXjZtYED1MPQI0gtnrQy0+BEJrwGfzepntQuNF6EoMTfXtkq83w== X-Received: by 2002:a05:6602:39a:b0:790:f735:4d30 with SMTP id f26-20020a056602039a00b00790f7354d30mr946352iov.13.1696376128874; Tue, 03 Oct 2023 16:35:28 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:28 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 24/51] bsd-user: Implement setloginclass(2) and getloginclass(2) system calls. Date: Tue, 3 Oct 2023 17:31:48 -0600 Message-ID: <20231003233215.95557-25-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-25-kariem.taha2.7@gmail.com> --- 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 04bce755e58..2eaba141dcd 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -130,4 +130,36 @@ static inline abi_long do_freebsd_wait6(void *cpu_env, abi_long idtype, return ret; } +/* setloginclass(2) */ +static inline abi_long do_freebsd_setloginclass(abi_ulong arg1) +{ + abi_long ret; + void *p; + + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(setloginclass(p)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* getloginclass(2) */ +static inline abi_long do_freebsd_getloginclass(abi_ulong arg1, abi_ulong arg2) +{ + abi_long ret; + void *p; + + p = lock_user(VERIFY_WRITE, arg1, arg2, 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(getloginclass(p, arg2)); + unlock_user(p, arg1, arg2); + + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 55e68e48159..d614409e694 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -375,6 +375,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_ktrace(arg1, arg2, arg3, arg4); break; + case TARGET_FREEBSD_NR_setloginclass: /* setloginclass(2) */ + ret = do_freebsd_setloginclass(arg1); + break; + + case TARGET_FREEBSD_NR_getloginclass: /* getloginclass(2) */ + ret = do_freebsd_getloginclass(arg1, arg2); + break; + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ ret = do_bsd_utrace(arg1, arg2); break; From patchwork Tue Oct 3 23:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60A7DE8FDBF for ; Tue, 3 Oct 2023 23:41:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovQ-0004Bl-AH; Tue, 03 Oct 2023 19:35:36 -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 1qnovN-0004AL-BN for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:33 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovL-0007DD-0k for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:33 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-7a2a9e5451bso58465439f.1 for ; Tue, 03 Oct 2023 16:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376130; x=1696980930; 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=lXNCT8uVBORK7tv8PpGRtzJSxuc5NgZcrHLSenHKxTc=; b=WL6lpS0aIoRyLXEm7Lu0on0wHlPAc+Dm77ZvispNHchVMrwy621OqwN7XRPa0PjjlR 80YYLvECD442JHl0EcP67+DTK4kEKhC5Mrs6faYZeLFfg9Ya4iNbZmZpkCrgAwKzgdW5 RqtDPhRMU4A02UynGT3rGRkxTcnwrw+CWKHrwf+Bumh7gZPJy3s985TG2Q7sFcXAgJwY Sy6YZIRceYA5LlUqTned37gw3f5L2+iKuYTTp8HLXkJBN31Mv97IihUKZUAH2WVl9+Im 2sjreC5Gij+dpU3XHmbpf1gkcz84rjZN7xltw0iy3HI+XflKIQiSXnNi/MTbB9VoNS6e qxqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376130; x=1696980930; 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=lXNCT8uVBORK7tv8PpGRtzJSxuc5NgZcrHLSenHKxTc=; b=Jszaua+0rwTB0XjlR14h8FWLzAxJiTZKdrjaS1J5zcRODct0XDLXGEu1vHCBqdiGVE r/gLJ1lEN0mnZpZb4B6JzHY6CUuxTzMQBYd81JMk9MtDO3gPbtaBgSdSLiPAA1cpfgvx de3oupqifNs0ZjN3hKlTwkQP5zfaqUmbJ9GsuNDaQ5k0nkuU+DVrxOLaUl3yoAmbPakF 3BzJGY45aqtYSWlphqVNWRwH71U2bsq9JkPfYsZgfiLBASkAMqQeVDiMcGsHbOgbcRck W7Cn366BMkFVTOaHc4J79O0txcMB80YtujlfqfgG7VyGERn3KcVbuUoGrhK0piK9uZJ+ 50JQ== X-Gm-Message-State: AOJu0Yx9l1q/q7tDM9Q2UEpPXPzn0bcBFTbw9LlTaesiVB6m3sFXU/1S nhdl89Bq5yh8Uhdic3sXm2Lzxt7kR3FH3t26tq8ytA== X-Google-Smtp-Source: AGHT+IGcgKaQM5/o72V5tJG92Oz0a/1MC4XmMh29lPgmGK8By8b5Z1IU1/Yp1y3uJhNHaAcX69F7tQ== X-Received: by 2002:a6b:e31a:0:b0:791:acd7:233f with SMTP id u26-20020a6be31a000000b00791acd7233fmr724023ioc.15.1696376129726; Tue, 03 Oct 2023 16:35:29 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:29 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 25/51] bsd-user: Implement pdgetpid(2) and the undocumented setugid. Date: Tue, 3 Oct 2023 17:31:49 -0600 Message-ID: <20231003233215.95557-26-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-26-kariem.taha2.7@gmail.com> --- 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 2eaba141dcd..42bdd61904b 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -34,6 +34,8 @@ pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage); pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options, struct __wrusage *wrusage, siginfo_t *infop); +extern int __setugid(int flag); + /* execve(2) */ static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp, abi_ulong envp) @@ -162,4 +164,25 @@ static inline abi_long do_freebsd_getloginclass(abi_ulong arg1, abi_ulong arg2) return ret; } +/* pdgetpid(2) */ +static inline abi_long do_freebsd_pdgetpid(abi_long fd, abi_ulong target_pidp) +{ + abi_long ret; + pid_t pid; + + ret = get_errno(pdgetpid(fd, &pid)); + if (!is_error(ret)) { + if (put_user_u32(pid, target_pidp)) { + return -TARGET_EFAULT; + } + } + return ret; +} + +/* undocumented __setugid */ +static inline abi_long do_freebsd___setugid(abi_long arg1) +{ + return -TARGET_ENOSYS; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index d614409e694..99af0f6b156 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -383,6 +383,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_getloginclass(arg1, arg2); break; + case TARGET_FREEBSD_NR_pdgetpid: /* pdgetpid(2) */ + ret = do_freebsd_pdgetpid(arg1, arg2); + break; + + case TARGET_FREEBSD_NR___setugid: /* undocumented */ + ret = do_freebsd___setugid(arg1); + break; + case TARGET_FREEBSD_NR_utrace: /* utrace(2) */ ret = do_bsd_utrace(arg1, arg2); break; From patchwork Tue Oct 3 23:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32FE0E8FDC0 for ; Tue, 3 Oct 2023 23:40:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovP-0004Bo-Be; Tue, 03 Oct 2023 19:35: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 1qnovN-0004AU-K6 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:33 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovL-0007F7-Sx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:33 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79f915e5b47so59907139f.2 for ; Tue, 03 Oct 2023 16:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376130; x=1696980930; 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=wO4tVRw6GlbIQ1GG5INdJAgQnEIiQn4ZKOXZr2a9REg=; b=SLvtC4hncjChD5ZpgsuOqTHaOFzcl1QsOEl+C+FppjndkAUmYTplzr/SIVM1wa1aL8 /HuDqwx1yg494D8m1HAtrIeBBzl1nKmpuxxh+0ZCdYYbinPiti3FpmWujMS5F+OAPZmo 9/PfjCANLqm83OlWD+b2UHJVPkJecCzsetiV/x0A8Vo18GVrAIGujyxwGBVWuBkzglNX 4o0kpHSbIEMoWnk5jFWXduFk6p1aJ8RCrORoQj9D2WhecxhhRY3tEuVHBSEOaqzKSq0N P+CCUxX4BwiVjWpEmKSUWsghfyhnbp8P9GfcvavZooXLDqmIUFfd5m99ByC9rVifP6Qx h6+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376130; x=1696980930; 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=wO4tVRw6GlbIQ1GG5INdJAgQnEIiQn4ZKOXZr2a9REg=; b=XMsuhXT69VdNkCzJEYJFNPkTGfgizxDn7y3rnFgS0HsMS0z6vd3mI0o/HfEfNleUec ciCkv/mp2FREDXMW+WPTDXyl4knj5m3l3lwHGtmDo7354sR7mklzJvhE+buptNzwowXM Aj2FF9L+R8Q9ufZL74U73+01/uFgvWMkL6Af0T06pxX17LXP5nNgnzCrUBr8OTas4VjO nJSuItbon7oF3HqMDPNmm0MnTs3vDN39NxYFEsf4VLaD/odhLYb3BttqJGAIetNNses6 K6Mvu1vDG2nriA/dhGsQ+Ky4fnGonp6iWKQ8FFpjsfSnTpRkz44llTQ3m8miTpfdNwoL h2fQ== X-Gm-Message-State: AOJu0YyJeos6Ow0Yi2wMRyRhq16OABuCkHWm8tqb9WGw+DPMYZ5Z4tPT qz/bGrYB/Xc9qVCHL/rUPmQXiu3aMw4ANNEgliVFcQ== X-Google-Smtp-Source: AGHT+IGy6my0ZZD3fR0/wBbzmX+GSQs9ow4UL5S88V2q6PF3OzIxSy9z7nR/MitvADImGLqJT9UXkw== X-Received: by 2002:a5d:9c1a:0:b0:790:fa58:69d2 with SMTP id 26-20020a5d9c1a000000b00790fa5869d2mr958587ioe.20.1696376130604; Tue, 03 Oct 2023 16:35:30 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:30 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 26/51] bsd-user: Implement fork(2) and vfork(2) system calls. Date: Tue, 3 Oct 2023 17:31:50 -0600 Message-ID: <20231003233215.95557-27-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-27-kariem.taha2.7@gmail.com> --- 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 42bdd61904b..7b2e6a9f796 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -185,4 +185,38 @@ static inline abi_long do_freebsd___setugid(abi_long arg1) return -TARGET_ENOSYS; } +/* fork(2) */ +static inline abi_long do_freebsd_fork(void *cpu_env) +{ + abi_long ret; + abi_ulong child_flag; + + fork_start(); + ret = fork(); + if (ret == 0) { + /* child */ + child_flag = 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag = 0; + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + + fork_end(child_flag); + + return ret; +} + +/* vfork(2) */ +static inline abi_long do_freebsd_vfork(void *cpu_env) +{ + return do_freebsd_fork(cpu_env); +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 99af0f6b156..cb9425c9bab 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -226,6 +226,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, /* * process system calls */ + case TARGET_FREEBSD_NR_fork: /* fork(2) */ + ret = do_freebsd_fork(cpu_env); + break; + + case TARGET_FREEBSD_NR_vfork: /* vfork(2) */ + ret = do_freebsd_vfork(cpu_env); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret = do_freebsd_execve(arg1, arg2, arg3); break; From patchwork Tue Oct 3 23:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A458E8FDC0 for ; Tue, 3 Oct 2023 23:43:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovQ-0004CL-VX; Tue, 03 Oct 2023 19:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovO-0004B9-GK for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:34 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovM-0007Ia-SK for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:34 -0400 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-79fd60f40ebso14549639f.1 for ; Tue, 03 Oct 2023 16:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376131; x=1696980931; 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=SQQ6DsBUp3HuF6Th08+OwRbSNoljuWJ7IZ0BaPOPKuU=; b=DgMx/F4TzGh65v5iKlAazAvWIRffmccsifR9+eFmpK95Rhne8l9me1SMAptN3+KJsZ Nef9JW9Xd8gLqZhVbtYzSHiH1R8TOppuNXwM1JI0Zpa02PgQ8UgIkF1qI4SYq6cH/3lF bfyyL6/+c32aqmHzEhBOCd1MFGnC9TjoFqkDEZgSRozC+eRoG1PaUUAIBVm1rHr4xR1t 0HYALDI3WXHxMaQQEonHRhuJHlQPLZEsyA3fu4/rUP/3TwxBjRrSM95gH5Zl67GBo7+a 7tG1GPDf4WgPoA8BuyMVJelS8uYQKAXjAjnj8IUfJK/KEwqT2tkHbqSJJWGWrbOuuIEJ QPfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376131; x=1696980931; 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=SQQ6DsBUp3HuF6Th08+OwRbSNoljuWJ7IZ0BaPOPKuU=; b=eix8awYOhUe7YKShxAnnC+BRFCcUn5XpZ6pdg7zw79EFwlIyMwcwvFI1c+Vu47MgKF ZrF6JH111EAKoQm02L6bWHqo7LzPm5TxsPEdAHCG7LbeyBCOoTYM6HsuNaIqn3pvXgti 7VTBIFKtTBGhAI26Ai+p0U6/O+aK8O9wW7M1bn7gEjO3FLzBDTymY1boy5xcYL0a8aXj rAkStXZQQ3CQ/wkAMEdFlMcOMcPXm1rUsw3AUMFFiyUCEh6qJvgW9EcCTWpxcYTDi+Jn 6XlZz/jpSS7xZu7CqBUGgnN02eq6Di7r3jwriqa8N89KYeBWQ65Fb8f6uPxtVpHGWvvv Rg3A== X-Gm-Message-State: AOJu0Yxdl4OiEja9Mblln9+30bVFR/igwOMQBbqjGa8mN8Gx+iR9g6F/ AFz06Y1ir1d/bW1jyqjkYcBKQdgLPC+LUJf7/ntgwQ== X-Google-Smtp-Source: AGHT+IHA0YZegynhPVgC+6AGqr0VQC9nz2t1IK9PjcbvwxDyW+15XF3/FcgWRvrwJUUGliAbuaz/hQ== X-Received: by 2002:a6b:7f4a:0:b0:79f:88af:500c with SMTP id m10-20020a6b7f4a000000b0079f88af500cmr543723ioq.4.1696376131531; Tue, 03 Oct 2023 16:35:31 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:31 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 27/51] bsd-user: Implement rfork(2) system call. Date: Tue, 3 Oct 2023 17:31:51 -0600 Message-ID: <20231003233215.95557-28-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-28-kariem.taha2.7@gmail.com> --- 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 7b2e6a9f796..0a3cd0ef57c 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -219,4 +219,43 @@ static inline abi_long do_freebsd_vfork(void *cpu_env) return do_freebsd_fork(cpu_env); } +/* rfork(2) */ +static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) +{ + abi_long ret; + abi_ulong child_flag; + + /* + * XXX We need to handle RFMEM here, as well. Neither are safe to execute + * as-is on x86 hosts because they'll split memory but not the stack, + * wreaking havoc on host architectures that use the stack to store the + * return address as both threads try to pop it off. Rejecting RFSPAWN + * entirely for now is ok, the only consumer at the moment is posix_spawn + * and it will fall back to classic vfork(2) if we return EINVAL. + */ + if ((flags & TARGET_RFSPAWN) != 0) { + return -TARGET_EINVAL; + } + fork_start(); + ret = rfork(flags); + if (ret == 0) { + /* child */ + child_flag = 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag = 0; + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + fork_end(child_flag); + + return ret; + +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index cb9425c9bab..4c4e773d1d3 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -234,6 +234,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_vfork(cpu_env); break; + case TARGET_FREEBSD_NR_rfork: /* rfork(2) */ + ret = do_freebsd_rfork(cpu_env, arg1); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret = do_freebsd_execve(arg1, arg2, arg3); break; From patchwork Tue Oct 3 23:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1626E8FDBF for ; Tue, 3 Oct 2023 23:40:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovU-0004Da-8F; Tue, 03 Oct 2023 19:35:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovQ-0004CE-JY for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:36 -0400 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovO-0007LN-W0 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:36 -0400 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-352a22e1471so3963935ab.0 for ; Tue, 03 Oct 2023 16:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376132; x=1696980932; 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=DTFZRe9LfB18mFM3p+ZpT+MrPqZPyJHc23fZZDwLdFE=; b=D9T2BYTxt++7e/53rwE4X5T4bRkeX2DG+cYF8aMVKm0l57r5c97iBFo62ohLy5aWIP S3+BtSlh1fl3ue7bybbwHFjRnkxTNJeEQaM2NPPswvtOB8n27BkO6ltDjCKkkeT44XtD yYZerYQzNp2gS69oX0Zod88G5V4UFMjnrigKdkjN21VOHCtUoNwJ7DorfjvfWEh6tVSv rr+Pp9LP2+SNEK3FqsV47945HqURnMDvA9DNuThDG6jsRl9nvoS8kd7B0mPPl07oCzh5 WCSfAuTCnQRgYAQnJKqw83yrTdPwEwWlXHKcemLX1ZB3zFu8C2xVWm+h10S+kggjS9tf Qm3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376132; x=1696980932; 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=DTFZRe9LfB18mFM3p+ZpT+MrPqZPyJHc23fZZDwLdFE=; b=ORUx0Yyl7iILL2cpYWuSoYnWlGm2Er6j3GI959rgmxbHVRNaWX5HDPi/Oj2UHQdqJ8 hg7tN58hLI92MxuEMoFXiojp1nR+Yrwy+sfbDVe5ADuwUPq42bplNUzq8Qy/JSBVQu61 OVlJJAd+rkP3ZxO+y1emLvAefKRs4N/0VsEhiDZNmS4BMBGItu42OAbI0nCkOsUX5lAW COpTD4TTEkK7kOqV1TCXQylILfuUsDZb1x4axKQ1S5HoGY/bnx8dxVoZZGe41k0obhKc ZcmsvrF+9OGL/9ZiKX3hbbCPeLsxaobKfsHsW4vY/iCCKcOgYU8HxMkMJ94PrWXJHA5L +XtA== X-Gm-Message-State: AOJu0YyFxrvGvzzITj6/XG+FPZ3uroGDg7aBe3V+hpsKOs8Hp4Q1aLXC QutQUBhgNCWAzC5DFh4VrqwG2Pg4vvYDKSA7eFvxPA== X-Google-Smtp-Source: AGHT+IGvTmrSLkZuJjT+BfaWx+ag3NAfOIblLqYg1kSir8JnTT+It79ypmJyGEaw4Is9GC25EJlUtA== X-Received: by 2002:a05:6602:3351:b0:795:16b8:8601 with SMTP id c17-20020a056602335100b0079516b88601mr911418ioz.0.1696376132452; Tue, 03 Oct 2023 16:35:32 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:32 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 28/51] bsd-user: Implement pdfork(2) system call. Date: Tue, 3 Oct 2023 17:31:52 -0600 Message-ID: <20231003233215.95557-29-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Acked-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182425.3163-29-kariem.taha2.7@gmail.com> --- 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 0a3cd0ef57c..d6418780344 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -258,4 +258,36 @@ static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) } +/* pdfork(2) */ +static inline abi_long do_freebsd_pdfork(void *cpu_env, abi_ulong target_fdp, + abi_long flags) +{ + abi_long ret; + abi_ulong child_flag; + int fd; + + fork_start(); + ret = pdfork(&fd, flags); + if (ret == 0) { + /* child */ + child_flag = 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag = 0; + if (put_user_s32(fd, target_fdp)) { + return -TARGET_EFAULT; + } + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + fork_end(child_flag); + + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 4c4e773d1d3..d04712f0a7e 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -238,6 +238,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_rfork(cpu_env, arg1); break; + case TARGET_FREEBSD_NR_pdfork: /* pdfork(2) */ + ret = do_freebsd_pdfork(cpu_env, arg1, arg2); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret = do_freebsd_execve(arg1, arg2, arg3); break; From patchwork Tue Oct 3 23:31:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 489F7E8FDC0 for ; Tue, 3 Oct 2023 23:36:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovS-0004DO-Mm; Tue, 03 Oct 2023 19:35:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovQ-0004C4-3C for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:36 -0400 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovO-0007Mx-LY for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:35 -0400 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-79fce245bf6so58303839f.1 for ; Tue, 03 Oct 2023 16:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376133; x=1696980933; 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=azy/SYSaQ16IVZQzbRRCdYoe/s4kbJ733g8Itr242Ak=; b=LrNVoSpGcix51dVDz75z8iuPx0I5MCAMFl8zc5a5ZJEdyzZr3LBP7lhBBuqF4FvmHu hVipKubW8Pktj47+MZLWdiHCPmd6linurKJy3JiR24YG2zeA7qLRyDDu84wCc5ivNYNx 2mhYXQykeaBfWZXapoSkMJMq7ka2TUDqhIMj1qEEm/1F8CpUuvP2XCz7eOi7zKAM1bkD uqAwiiwNRcdNKeMMegwEAKpIFOYR07HPJKuT5RS1bkRQQLl9Lff9OjcT9j1os1JDVwHI no/1UK/jUbD5TrBpf/SRME9WTN8X5Vi69jIi9GEZK/BUhdSFVIFljO0w8uZfxlBj1hgZ 6bBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376133; x=1696980933; 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=azy/SYSaQ16IVZQzbRRCdYoe/s4kbJ733g8Itr242Ak=; b=Qfp8oYnoDq6CUD/yAxkUKkgldy0j+fY6PtxuFrjDMH3wpHhzX8LRe7+v+mUEzSw2pJ 4SxZqs6CcT+sZU/znsvc8JblUiIl258QcbiQKbLvkt+VAHm+1J5objtRijKHIsVVu7sm WgbXTJqxrqSrivFrVkCGMbPEajFp+kRlhF/WlhY4BsGDCZNDxzPHh9Tlca+tNUua5Yds Z7F5p0Zj2pTNo96hlTpR/wCaCLux15S0XyeYpEccPrmh0ucqMrAiKDPX3lOi4NoedHWB 4QHrtQlrOLEdNMEX7pRnGpw1jDi9m4ZEksRwT1EzTys2Kt/aJ47+u/l11tQ1c1sITL4j BuYg== X-Gm-Message-State: AOJu0YwQot5AtZ6bgzLWTZ3bYAPPMf9ARppju5h2B/bFw9FIt5oGZ8wf 8E6feYtQ+vKXDZkcueEM6oeA4TACxWbB4X8qS56Pyw== X-Google-Smtp-Source: AGHT+IH/lqG4uzzUMfFhHWMdPvFEcvbvSkBfz2WcmuPUt56nPuR7jWtoxxbGaXNodf2lxoMTiNdh4A== X-Received: by 2002:a5e:dd0d:0:b0:786:7100:72de with SMTP id t13-20020a5edd0d000000b00786710072demr895226iop.16.1696376133350; Tue, 03 Oct 2023 16:35:33 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:33 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 29/51] bsd-user: Implement struct target_ipc_perm Date: Tue, 3 Oct 2023 17:31:53 -0600 Message-ID: <20231003233215.95557-30-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d31; envelope-from=imp@bsdimp.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-2-kariem.taha2.7@gmail.com> --- bsd-user/syscall_defs.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index a3bc738ff89..0e54d7df690 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -55,6 +55,23 @@ struct target_iovec { abi_long iov_len; /* Number of bytes */ }; +/* + * sys/ipc.h + */ +struct target_ipc_perm { + uint32_t cuid; /* creator user id */ + uint32_t cgid; /* creator group id */ + uint32_t uid; /* user id */ + uint32_t gid; /* group id */ + uint16_t mode; /* r/w permission */ + uint16_t seq; /* sequence # */ + abi_long key; /* user specified msg/sem/shm key */ +}; + +#define TARGET_IPC_RMID 0 /* remove identifier */ +#define TARGET_IPC_SET 1 /* set options */ +#define TARGET_IPC_STAT 2 /* get options */ + /* * sys/mman.h */ From patchwork Tue Oct 3 23:31:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3228E8FDC0 for ; Tue, 3 Oct 2023 23:43:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovU-0004DX-7G; Tue, 03 Oct 2023 19:35:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovR-0004Cn-BN for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:37 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovP-0007PC-JH for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:37 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79fa5d9f3a2so57655039f.3 for ; Tue, 03 Oct 2023 16:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376134; x=1696980934; 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=ye1cEufpabX0kbmM/Z2tKJUqMwLD3um1kdO4giPewb0=; b=ztUoqKUqGlkrLPx8k+O3vpI4RgaqSp3OpwQgqRPMM0kxakIdX6H1zZKtpXUiRcv0wU yeoc2EhyoozLQOZ4BTeX/edfUWcefAaXp1/uPJcll09Us4kIbPmVz1u88nzAjcyId6qM mKVw49yXyT6qxYcHrZAO9jquBadYw1I0zn/Vy7crFWTOo96vh04wS0V/n7a/VfJx6RqH TEzU4qlzSICU5rwlJO4Qp/J5sa+Is5SfrrjKRZGe6uD1K2q+AoHKEQQf1iyYTXatGd2j lI91+pvw5fgVJO8ykf/xsVKbYFgEQq9KBhaIKWn+6tTlBfQjezq28HMl3mVyNZLGvG4R CBgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376134; x=1696980934; 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=ye1cEufpabX0kbmM/Z2tKJUqMwLD3um1kdO4giPewb0=; b=iw/m1XzHVDD4R60r1e8fJnkEx3Pvgf5OABZ13siLdP2jV3TORthfwpOXYi3CmRK4hs ftrjR/9QP9hY6/d4jHPVmSBfx0+KQgKtBjNzX/M5vJmhtt5Y4zw3CVui+OXqaZGf190n MnSDPYoFCGrjaGdCbIQI2nSPOIRHi94DBY66KmGTm3ZJJORsLIyEkDeFhfTAU3hZBz+8 oZxyHlqYHz2z2p1LQiOA8SBSBQh3NS550/MJGi05BD/DuDd1htwp6t2p9iB2LYZ200vE jTgJ05YVdTby44jBSmLp1Xjy9Dc9gd+swP+bzObaljBLCktB1e/iweV56X76ZT9gjYEP F+LA== X-Gm-Message-State: AOJu0Yycl6fzOA5/x0XSf984xF5vy8G8sZc4dfcd8dEKPrWz7CzaCQ4B sM15iXDOBtnq5DRtdF7NF5j6QrHnv/+S+ZFdCI/WYw== X-Google-Smtp-Source: AGHT+IGeB6hdWA8FRXupStEbwSYbK7kOP4iMD8WJtFXxXJ6IGSRlpS8jwXaOXi+4eERcrvvF/X5RUQ== X-Received: by 2002:a6b:e31a:0:b0:791:acd7:233f with SMTP id u26-20020a6be31a000000b00791acd7233fmr724119ioc.15.1696376134255; Tue, 03 Oct 2023 16:35:34 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:33 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 30/51] bsd-user: Implement struct target_shmid_ds Date: Tue, 3 Oct 2023 17:31:54 -0600 Message-ID: <20231003233215.95557-31-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-3-kariem.taha2.7@gmail.com> --- bsd-user/syscall_defs.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 0e54d7df690..ff692814333 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -72,6 +72,26 @@ struct target_ipc_perm { #define TARGET_IPC_SET 1 /* set options */ #define TARGET_IPC_STAT 2 /* get options */ +/* + * sys/shm.h + */ +struct target_shmid_ds { + struct target_ipc_perm shm_perm; /* peration permission structure */ + abi_ulong shm_segsz; /* size of segment in bytes */ + int32_t shm_lpid; /* process ID of last shared memory op */ + int32_t shm_cpid; /* process ID of creator */ + int32_t shm_nattch; /* number of current attaches */ + target_time_t shm_atime; /* time of last shmat() */ + target_time_t shm_dtime; /* time of last shmdt() */ + target_time_t shm_ctime; /* time of last change by shmctl() */ +}; + +#define N_BSD_SHM_REGIONS 32 +struct bsd_shm_regions { + abi_long start; + abi_long size; +}; + /* * sys/mman.h */ From patchwork Tue Oct 3 23:31:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43A12E8FDC0 for ; Tue, 3 Oct 2023 23:44:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovT-0004DU-So; Tue, 03 Oct 2023 19:35:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovS-0004DF-26 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:38 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovQ-0007PN-H8 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:37 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-79fa5d9f3a2so57655539f.3 for ; Tue, 03 Oct 2023 16:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376135; x=1696980935; 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=xbdd7u9NeVPCkT9yPQuY1ndY3BOt1BhLoy0Idqk3wZ0=; b=XFpoU95FBMaxl5vVpYbRYXCjGj+oiluW3ouUBElxZgNoIjv/42OoMtB4H/1ilc9C2B mGEAF6IypEUdmz57dSzsQtNavT9L7LlKC5iwcCwZCcA8dKivYcz/hzk2a8FZhnUPp/+o XfDGKmoyWisHxxfZN/fy3GupDAgCVNYHIrhRSjYENiJAhf5AlzU9pIB1kwogKiksmK5f H18TAf7li5V0EsnFGuwScE1bml47jLtXckNPs6eTdbhLd5J+lQctoKFDt6E95+nSxX5W VgPUezbODL15nFShLapgH2zklptzNoRyKRp8SkSNmzMXFQIZ7X2oK1U+yE+H79fsg/m/ inBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376135; x=1696980935; 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=xbdd7u9NeVPCkT9yPQuY1ndY3BOt1BhLoy0Idqk3wZ0=; b=YwQhzb3D0j/3Om34WefJP0ox85Fdi3jM4ToWRHXFi+OX0JNZED9GVNlj85covO25Po C/qs5TNcvSrmnb6353GhWiDXIIHsK7s935n5NxI7UpneU/s7mWN8x7hV0D9M0M5Bs/XY EIqGGf+MhAfCbGOXE4c6mHjQWOCEEV7L7+AN8ynu3gIsO3tjQXROKMd7h3zmwlH9vFyF UDTOSon1wODPgfqWbMUexo7CIWixlkX5T1/FTGh424o6XZDlgIXPm9+Y3+M1WSo2fcMJ 9TYIXkzc8k5F0cOzPvKM/mT1V8HMijuVU2oqT7nLZgnMOGHPSS1RgfSeCO3MADh2Ivid K6Pw== X-Gm-Message-State: AOJu0YxnRwqd/j7HCqMueGQOdf+HM9s/rMlp8KwhvhaXflBuMxpijQ4F BCXhEpouLJrwQ0f/GSa/HuyyttRsRCu1Twh9QA368w== X-Google-Smtp-Source: AGHT+IFmSOg8VqZyhZRuh2gBPHeO8RkxjzjDX47q1Jnw4RUwOmgkh5K+xip80MGigalbqPujIAu7tA== X-Received: by 2002:a05:6602:228a:b0:79f:a25b:51c with SMTP id d10-20020a056602228a00b0079fa25b051cmr969481iod.11.1696376135171; Tue, 03 Oct 2023 16:35:35 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:34 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 31/51] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions Date: Tue, 3 Oct 2023 17:31:55 -0600 Message-ID: <20231003233215.95557-32-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-4-kariem.taha2.7@gmail.com> --- bsd-user/qemu-bsd.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h index b93a0b7fd5b..ffc64bb244a 100644 --- a/bsd-user/qemu-bsd.h +++ b/bsd-user/qemu-bsd.h @@ -22,6 +22,16 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* bsd-proc.c */ int target_to_host_resource(int code); @@ -35,4 +45,14 @@ int host_to_target_waitstatus(int status); void h2g_rusage(const struct rusage *rusage, struct target_freebsd_rusage *target_rusage); +/* bsd-mem.c */ +void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip, + struct target_ipc_perm *target_ip); +void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip, + struct ipc_perm *host_ip); +abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, + abi_ulong target_addr); +abi_long host_to_target_shmid_ds(abi_ulong target_addr, + struct shmid_ds *host_sd); + #endif /* QEMU_BSD_H */ From patchwork Tue Oct 3 23:31:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F7B7E8FDC0 for ; Tue, 3 Oct 2023 23:41:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovn-0004QQ-4K; Tue, 03 Oct 2023 19:35: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 1qnovl-0004MH-L7 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovR-0007Pn-Ch for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:52 -0400 Received: by mail-io1-xd41.google.com with SMTP id ca18e2360f4ac-79fc3d32a2fso60170339f.1 for ; Tue, 03 Oct 2023 16:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376136; x=1696980936; 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=Ci9IVvBHiMF+Kz9t9dpXV7nFDmS/9Z/PKiZ4KFlDEC8=; b=EL0z/VGJ1wHeuZlsfVMFhXIzvdVMP1l18o0b55Y7ZZ445PL1B4FiP1/fpmwachEoGo mSG+REXbAAHQ8eq5iA94C1FtOUd4OX6CisuDUg+qX5qh5JPfZxyamGhdn98YibaJNtU7 csu12xXn1q19ltSIV5AqEUIORvrYSunYEcXeJMbZwnujBB06PKm4oKG7bq47WD/gk2II cCCPgCm2Bp8CGvFrEkRR07YYRG3WT7xRI8RCnV7/5o4i7ZFUIB0dw2+nIul9b2ea7Nw+ Fak8BOdULgBZfBF7qGn4CpayC+eve4KI1VCK8t4OGrbtt7i4jgOBFnFmxqSarisUZMo3 OMaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376136; x=1696980936; 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=Ci9IVvBHiMF+Kz9t9dpXV7nFDmS/9Z/PKiZ4KFlDEC8=; b=Q23oZCa0zKxarUdkz4g0dvzfVfeRkcaHwWPqVYnrT6vj0cNa6Y19gZC7lkhiHDzA2o 2ljR/syH9GS2SO9Y5uYSxDOCjSgsTm4SWVrvrqgYnHiCbsD5iVXuouWY/XJnlWUDc06e Hp2HIDg+9z/avG41y5VP+Hk57NtgAOvZA+6ONFgpJZWyQ3r9oJWEpFtpptBO8E+6iZ8w W1Mqkh4TpS7h+6+aJ1IZ65pBhxW1x+r2uEVDTR2Px7F4cMVoaI7Mc7xEqU19lxmhRsuR ZdTEviImISMAA9kFBgjtTcP+pBlb7UpoUQ2nD+Ql2skbiRhYQHaHwQJzpyRL1oW/LiOA HtDw== X-Gm-Message-State: AOJu0Yx/+BaH6g5pVO7Xd6oDKs38SAJ8CuVxMExAlrZUPcySVmxYh9Yw CmF1wJcKb6Wd8Zk34ldPfMJzmpgSSCTN0/iGaXSERkbK X-Google-Smtp-Source: AGHT+IFCPkyodsoP7KEVRj3inRcDTDEVAL3WglJsXJD2pdw/bMGLW1eYlKvqHT2PEG0kB+snbPQgiw== X-Received: by 2002:a6b:7841:0:b0:79f:e99b:474a with SMTP id h1-20020a6b7841000000b0079fe99b474amr865190iop.18.1696376136111; Tue, 03 Oct 2023 16:35:36 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:35 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 32/51] bsd-user: Introduce freebsd/os-misc.h to the source tree Date: Tue, 3 Oct 2023 17:31:56 -0600 Message-ID: <20231003233215.95557-33-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_NONE=0.001, T_SPF_HELO_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son To preserve the copyright notice and help with the 'Author' info for subsequent changes to the file. Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-5-kariem.taha2.7@gmail.com> --- bsd-user/freebsd/os-misc.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bsd-user/freebsd/os-misc.h diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h new file mode 100644 index 00000000000..8436ccb2f7d --- /dev/null +++ b/bsd-user/freebsd/os-misc.h @@ -0,0 +1,28 @@ +/* + * miscellaneous FreeBSD system call shims + * + * 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 OS_MISC_H +#define OS_MISC_H + +#include +#include +#include + + +#endif /* OS_MISC_H */ From patchwork Tue Oct 3 23:31:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C32D2E8FDC1 for ; Tue, 3 Oct 2023 23:43:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovY-0004Eq-3f; Tue, 03 Oct 2023 19:35:44 -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 1qnovW-0004EW-1g for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:42 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovS-0007Q3-A6 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:40 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79fb78e297bso61796539f.0 for ; Tue, 03 Oct 2023 16:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376137; x=1696980937; 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=9k2xFREJ+w8CMIVs9kMy/TL+LfskRJju2B00DBUrNyk=; b=wparATsjCtYScuR3dh8DZNV35+ocs6LUEKa57sWPoKkwrukPImllUoXJtNL707lLpl DR/kkBryl6SgB9fm3QunJOCycUkUKEbbJrJhiMnmqS8DgG2gC5sRVs3cgyYOOxRbIxzb iDLqY/DbIp7/l8wur31UnP4vMj8UH6VmkXQEBAQt38tOqa4gmneeRuXNGds7/5tbXiX5 mfoG/ZtS/IJ/P3WwtKWmJaWBqVwKS2CBwnmsqR6b2iyG4iaAFM1X6vo6/3MTf/enRimj /YtHSC0M6LYCp/1HfiIyxns/PskJZKnKbV1Y0naL2biEvxxP85mCkA0xPPiqwVYteteb YmHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376137; x=1696980937; 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=9k2xFREJ+w8CMIVs9kMy/TL+LfskRJju2B00DBUrNyk=; b=IHbt4HeAi1cOr0+jBO3MlbwISBnoWgGbYfk517z4dH6Wn+uJXq9gDx5IEQulxXBt1x YoBGqoaoEQN8IaIUk7J9tYxMZTQNPnjxxuXlYgW6isDgNjkTAWwk7H1PualTbXalZTr0 iyvevaQv9dsxnaMmvniqiyXzi6eWSLDI1s+rNDPEeNprAnU+6r02QUC6K0Ixw5AvBR0Y CgFlgXNLAvWrbgFkUq3p0Qx2KfO3AoZ6aQwkKtG1y42H9jaUi7WFFxwUX0xcwrtEp01L fpbhAFQWWmFxhkOPsRDLQbKzs2HPA5XwPQtDzWJChhj9LLYXL8qH4eE45vJ5ecmW9zJ5 dP6g== X-Gm-Message-State: AOJu0YytPA19PL2q796VMmkYposV6JMZQMgMe4ggEtE3qu4ywWadI8qV nQzkAO+Gq1Ga7n9DgeHXJrnYvnp/6FrgWs+Tn6L8Lg== X-Google-Smtp-Source: AGHT+IEXvxd++3vx1MPatOmVfIjdDMCH25RkSj/Vd4sxC/x7wwpwnFatxOZ64owcaFiVKyBejeBLmg== X-Received: by 2002:a6b:4f0b:0:b0:783:5209:c01 with SMTP id d11-20020a6b4f0b000000b0078352090c01mr990534iob.17.1696376137025; Tue, 03 Oct 2023 16:35:37 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:36 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Kyle Evans , Richard Henderson Subject: [PULL 33/51] bsd-user: Implement shm_open2(2) system call Date: Tue, 3 Oct 2023 17:31:57 -0600 Message-ID: <20231003233215.95557-34-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Karim Taha Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-6-kariem.taha2.7@gmail.com> --- bsd-user/freebsd/os-misc.h | 46 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 22 ++++++++++++----- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 8436ccb2f7d..d5e8b5484c8 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -24,5 +24,51 @@ #include #include +/* + * shm_open2 isn't exported, but the __sys_ alias is. We can use either for the + * static version, but to dynamically link we have to use the sys version. + */ +int __sys_shm_open2(const char *path, int flags, mode_t mode, int shmflags, + const char *); + +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 +/* shm_open2(2) */ +static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags, + abi_long mode, abi_ulong shmflags, abi_ulong nameptr) +{ + int ret; + void *uname, *upath; + + if (pathptr == (uintptr_t)SHM_ANON) { + upath = SHM_ANON; + } else { + upath = lock_user_string(pathptr); + if (upath == NULL) { + return -TARGET_EFAULT; + } + } + + uname = NULL; + if (nameptr != 0) { + uname = lock_user_string(nameptr); + if (uname == NULL) { + unlock_user(upath, pathptr, 0); + return -TARGET_EFAULT; + } + } + ret = get_errno(__sys_shm_open2(upath, + target_to_host_bitmask(flags, fcntl_flags_tbl), mode, + target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname)); + + if (upath != SHM_ANON) { + unlock_user(upath, pathptr, 0); + } + if (uname != NULL) { + unlock_user(uname, nameptr, 0); + } + return ret; +} +#endif /* __FreeBSD_version >= 1300048 */ + #endif /* OS_MISC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index d04712f0a7e..122e186b501 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -33,18 +33,14 @@ #include "signal-common.h" #include "user/syscall-trace.h" +/* BSD independent syscall shims */ #include "bsd-file.h" #include "bsd-proc.h" /* BSD dependent syscall shims */ #include "os-stat.h" #include "os-proc.h" - -/* used in os-proc */ -safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, - struct rusage *, rusage); -safe_syscall6(pid_t, wait6, idtype_t, idtype, id_t, id, int *, status, int, - options, struct __wrusage *, wrusage, siginfo_t *, infop); +#include "os-misc.h" /* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); @@ -65,6 +61,12 @@ safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt); safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt, off_t, offset); +/* 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); + void target_set_brk(abi_ulong new_brk) { } @@ -796,6 +798,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_fcntl(arg1, arg2, arg3); break; + /* + * Memory management system calls. + */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 + case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ + ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); + break; +#endif /* * sys{ctl, arch, call} From patchwork Tue Oct 3 23:31:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 132F2E8FDC1 for ; Tue, 3 Oct 2023 23:39:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnova-0004Ga-SI; Tue, 03 Oct 2023 19:35:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovZ-0004Ff-AT for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:45 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovT-0007QG-7r for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:45 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-79fa387fb96so59614439f.1 for ; Tue, 03 Oct 2023 16:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376138; x=1696980938; 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=snLfS2fmcfQu7v+qFvXCzYllQM35vPKtXXGh7bze+p8=; b=vylYitD2pk2dn9bkA/Em4T3PyTXXFGammOLqrTvZ+VnlpddavYE6nBu579hMYhl5/2 xtiXqiiQh9YoJbd52zmhv37jb6atXQOPZbnVIINP7GAxvPdjQ4nlrQcJDIPbvaWKx8Ql Dfp2cbNWcjKrPk9C0+6FGOIekggEhY+lPKtO2toHfZ/dlj1ZiOaUCphlJyvIufae385p M29X28NipsvhTzZY5xa55/uPFAsM6+sfAwz3+eKr9SSaXvUgmdCQTMO4AlB5bsDwUCeA F02g4dUTcpyHUOu+f5ucstNBH1QOhWQ5Go4RFTGy/ZsNaVW+lsmh/vlMVjd84djNPnA8 Cvyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376138; x=1696980938; 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=snLfS2fmcfQu7v+qFvXCzYllQM35vPKtXXGh7bze+p8=; b=aoFXb6tvMExXdr4SV7ohH/F5e0J+efbOBZOW5m5aq41agxnwtQAUcJD0gzYlfj4EMu wlU9ASzoFRkd0F2lyovQH70aIp2wlqB4TTkz3vk8u2iXTO0rmSSWNJCzfSotONE683ui JXDrSfg6TSmiTlaL555P79rTorln9qJp1IZsyS+Bn66lyi7GcRaAwn+OkQBaeIWyaEYY 0bvE6Ykya3KxYNJ5NvJE+IGnN2wyx9259zPLlDO1FsWGBVPYhngmgaCdtZBR9uKJwVZP 6p0UEWVmoeQYLcv9Xq/EKqfOjXRFaSj2rqDkEv+D97zkv5rzNzl1/BxCuZi0nd/xIL+i mrIQ== X-Gm-Message-State: AOJu0YxayNUJZEnSW7wxdJeEamCWasgcKHatzfUfMM1it8H2FS4Wfum6 1wjSL5A4z0bM0AMTVipZZ/kg/pfvWsem3k5z322vRA== X-Google-Smtp-Source: AGHT+IGYKg2LvvQOV0NqnYxEDxK5SFIv2jJoDtbxF7lgzJERLovzPpCs1+xsqQx481RDwL45NeGf1w== X-Received: by 2002:a5e:8919:0:b0:787:34d:f1ea with SMTP id k25-20020a5e8919000000b00787034df1eamr873017ioj.8.1696376137916; Tue, 03 Oct 2023 16:35:37 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:37 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Kyle Evans , Karim Taha , Richard Henderson Subject: [PULL 34/51] bsd-user: Implement shm_rename(2) system call Date: Tue, 3 Oct 2023 17:31:58 -0600 Message-ID: <20231003233215.95557-35-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_NONE=0.001, T_SPF_HELO_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Kyle Evans Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-7-kariem.taha2.7@gmail.com> --- bsd-user/freebsd/os-misc.h | 24 ++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index d5e8b5484c8..71145764a4d 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -70,5 +70,29 @@ static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags, } #endif /* __FreeBSD_version >= 1300048 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049 +/* shm_rename(2) */ +static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong toptr, + abi_ulong flags) +{ + int ret; + void *ufrom, *uto; + + ufrom = lock_user_string(fromptr); + if (ufrom == NULL) { + return -TARGET_EFAULT; + } + uto = lock_user_string(toptr); + if (uto == NULL) { + unlock_user(ufrom, fromptr, 0); + return -TARGET_EFAULT; + } + ret = get_errno(shm_rename(ufrom, uto, flags)); + unlock_user(ufrom, fromptr, 0); + unlock_user(uto, toptr, 0); + + return ret; +} +#endif /* __FreeBSD_version >= 1300049 */ #endif /* OS_MISC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 122e186b501..5fb42b2c218 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -807,6 +807,12 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, break; #endif +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049 + case TARGET_FREEBSD_NR_shm_rename: /* shm_rename(2) */ + ret = do_freebsd_shm_rename(arg1, arg2, arg3); + break; +#endif + /* * sys{ctl, arch, call} */ From patchwork Tue Oct 3 23:31:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64DE1E8FDC0 for ; Tue, 3 Oct 2023 23:37:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovn-0004Qg-E1; Tue, 03 Oct 2023 19:35: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 1qnovk-0004M6-Lh for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovU-0007QR-7H for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:53 -0400 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-79fa2dbd793so64833339f.2 for ; Tue, 03 Oct 2023 16:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376139; x=1696980939; 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=Lf2DJ/U5pZm2sH4vEROH814jsncDavzfH54NHOK5mnI=; b=beIBeVRIwr+iSLVT759fEoGoOwGNpIPQliRIS6sMlQ8MoCKGALY1CsDugMFvH2jwDL VikPvFILhUxjiZwMGZm/pAwnw7lqxGUvn8X4SwWSoFI8y1W7bT7DBX162p6SuR8azRLo IeLoggEYfhYUb0zWgdpy4hcWqNj0WcSI9qyftwk5NGZc8VoJNHo6/u6MVTf84ayj9QYc rOgkfMJAZraL4eqWFOOdhNoTlukg021sZuoidbQMmVt6cMF6Gx5s1OSWxPxAEHJyGNLI W5f+ugVjMozDCfEwWM8WjMI3oLjIV5XUiMfpFVrUeDP2T7YJ2ns4EVoZwsdQV5lnmFl2 eFQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376139; x=1696980939; 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=Lf2DJ/U5pZm2sH4vEROH814jsncDavzfH54NHOK5mnI=; b=tQC7m/otSkgZfLNwSaA8oIS+F4yX3NY6vmZC7GyzcLEb8KYnwppnq1JuCuIa+ekil/ /jailcvE4KK4/NGVJFYD8roJAvRLOEtkMpU9xMC0eRZ9fkfsjZhadd2JR1LjVZb6NSXj 4SReFeDvGrE+SdLyd3JY3oQ/iymd6sjqVzMztdDn/EwRPDGMCiTBNZhsdjkJmdGjj706 ztANSq9owQjghQAS7u0/Unz2KkEjeAQnn2cZO6i787Tf9xtfQEYx+D/XmXQohX291mz6 DD13GGxT+cPBtQBpebx1CI4bmPOrVmNslb6ElF/F/m9ZOV30xu66EKaIa9WsB53g7ueJ mLNA== X-Gm-Message-State: AOJu0YxWt33S+7Umh3+1Mckyx1MS/vnXmsKqgG0hdT28bnsMZ5bTYqfT i/wXeXsmnHw43Szg0B1GSMNPpjr8cmGOyN48vAm0yg== X-Google-Smtp-Source: AGHT+IGeMItmvoNFnerw+z4zcjU4ecusxV9/NxaqduSB0gjpJvCGQ+oL+5u6yjH70RsXsGI/Vah4dQ== X-Received: by 2002:a6b:a05:0:b0:792:70f2:a8ed with SMTP id z5-20020a6b0a05000000b0079270f2a8edmr963506ioi.4.1696376138891; Tue, 03 Oct 2023 16:35:38 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:38 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Richard Henderson Subject: [PULL 35/51] bsd-user: Add bsd-mem.c to meson.build Date: Tue, 3 Oct 2023 17:31:59 -0600 Message-ID: <20231003233215.95557-36-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Karim Taha Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-8-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.c | 0 bsd-user/meson.build | 1 + 2 files changed, 1 insertion(+) create mode 100644 bsd-user/bsd-mem.c diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bsd-user/meson.build b/bsd-user/meson.build index b97fce14722..c6bfd3b2b53 100644 --- a/bsd-user/meson.build +++ b/bsd-user/meson.build @@ -7,6 +7,7 @@ bsd_user_ss = ss.source_set() common_user_inc += include_directories('include') bsd_user_ss.add(files( + 'bsd-mem.c', 'bsd-proc.c', 'bsdload.c', 'elfload.c', From patchwork Tue Oct 3 23:32:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C49DE8FDC2 for ; Tue, 3 Oct 2023 23:39:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnova-0004Fe-8N; Tue, 03 Oct 2023 19:35:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovY-0004FE-BK for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:44 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovV-0007Qe-6H for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:44 -0400 Received: by mail-io1-xd44.google.com with SMTP id ca18e2360f4ac-79faf4210b2so57699239f.2 for ; Tue, 03 Oct 2023 16:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376140; x=1696980940; 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=enWxn1UiA0RiRwD9f+pbmm7z2XRqILatx/jv7cDD9xY=; b=V+7rP5znmNxti0xymyZZZW52NeCzjJAwI7ExzqGzCWg5kyUy5heV7yaOHTdw+GLNFT QD4mR169sgzWC+5e6+vRHcaZiGxn5XfWY1F1JoJN9eolFSWibttR2fWM1B+0YAJpmtm5 ioPLcHEPaI6nVLrvo8MrG/vEi3q5HOF3zms5qxpUPnqfBw6O+TF/mya9iZVH1Ejv44HY w0pmu+ZGmOgr2oWC0uMI5kHvctmrvW18bD4MroEdJ6xFa7IaHftHrYmJdWa7wfF2sSIK +mJBUCUky4Rh0cVMUnfnmzHbl0dHeEJULV2yVqFuH4oCeFn+e2ynUSZl1yzs6EIo7YkG XLHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376140; x=1696980940; 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=enWxn1UiA0RiRwD9f+pbmm7z2XRqILatx/jv7cDD9xY=; b=U2MHQ0wCQdm72gdGPFwq1/vmnVULrqNRHP0hPydjg+MpraPJhEhrXGHOqH6kBVm5LX ls619OWdEv3UInNbnQWFIn31t5o8mfKpKN2uPL9NShds4X8HQudWvTjoccdmW4ZTm5mt B6mvjWhwzw6mtb2KhWU8//iij3uILzZmZtNTV4HWra6d3/G3/m4pmRdkNzOyFzfMPEva jil0+EBj+/xddNK7Ks5KSaFBXQaiBB+J1+IAjA0jOifgbqXp0c/ppd+8KfknlJRWzKT4 JsTq28RQl0GwogFlFqnFaOwK2cavHhjl/EBHnxmeSooC6JBpAdTETdjoCo5n2ILOmxmK L8bg== X-Gm-Message-State: AOJu0YwWfHeEPANBGOwP7/cFPwKn9GEoZOeMpeiYXjg0dhPx7hj02P54 AvIulaelxt6y4aCYP5ITc4LFwElSSB8QSe4iF/ky4GGQ X-Google-Smtp-Source: AGHT+IG1PN+TTC13IgUFUMmXjQSeDrl8VXPgpUcimciK6K0BCojl31ibeyV1qW42AtXaoy+fBavJrw== X-Received: by 2002:a5d:9943:0:b0:79f:d194:d6e2 with SMTP id v3-20020a5d9943000000b0079fd194d6e2mr1054224ios.10.1696376139827; Tue, 03 Oct 2023 16:35:39 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:39 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , =?utf-8?q?M?= =?utf-8?q?ika=C3=ABl_Urankar?= , Karim Taha , Richard Henderson Subject: [PULL 36/51] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c Date: Tue, 3 Oct 2023 17:32:00 -0600 Message-ID: <20231003233215.95557-37-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d44; envelope-from=imp@bsdimp.com; helo=mail-io1-xd44.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son The definitions and variables names matches the corresponding ones in linux-user/syscall.c, for making later implementation of do_obreak easier Co-authored-by: Mikaël Urankar Signed-off-by: Mikaël Urankar Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-9-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.c | 32 ++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c index e69de29bb2d..8834ab2e588 100644 --- a/bsd-user/bsd-mem.c +++ b/bsd-user/bsd-mem.c @@ -0,0 +1,32 @@ +/* + * memory management system conversion routines + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" +#include "qemu.h" +#include "qemu-bsd.h" + +struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; + +abi_ulong target_brk; +abi_ulong initial_target_brk; + +void target_set_brk(abi_ulong new_brk) +{ + target_brk = TARGET_PAGE_ALIGN(new_brk); + initial_target_brk = target_brk; +} diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 5fb42b2c218..c9d34b59bbe 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -67,10 +67,6 @@ safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, safe_syscall6(pid_t, wait6, idtype_t, idtype, id_t, id, int *, status, int, options, struct __wrusage *, wrusage, siginfo_t *, infop); -void target_set_brk(abi_ulong new_brk) -{ -} - /* * errno conversion. */ From patchwork Tue Oct 3 23:32:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F1C6E8FDC0 for ; Tue, 3 Oct 2023 23:40:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovb-0004H2-Ob; Tue, 03 Oct 2023 19:35:47 -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 1qnovZ-0004Fm-Ho for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:45 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovW-0007Qr-Ec for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:45 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79f909071c3so60627139f.0 for ; Tue, 03 Oct 2023 16:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376140; x=1696980940; 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=8GmmJ7cOFUeiFT48AhnZ61JPhLUFSCR6i7jpIveL+bg=; b=jcg5XqXdj2NNzOqZK/2TjorH0TgUZqT/oEDxkEIvB1HDggN4QS0lvwdWCTSXG5zd3p RF4dWl79J/wBAtKM/Jodt1kxse9AlEUkrF5Krl7YGDvkGgc+ltbW/+DQU0bLFL5ks8mF 4z+uakmLVqJvEMTm9iMIfTCcVGcGdTANOrL7O2cWkKgoxAViGxbeMmAZduQcE8sz6kJb LVTcxe1EUOTiBMPZBVJq3zzBd4A43cGI4qUUr5Pfk4pHKQ69veN0W3OuAqEJaCxNyVtB kBfSrNr4KVEP72nm0BvO1/4KoDvHwpub3s2V4Et+KDbDmiYF9ti+1glOFwgvQDMOfOOV HhSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376140; x=1696980940; 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=8GmmJ7cOFUeiFT48AhnZ61JPhLUFSCR6i7jpIveL+bg=; b=D1XmmvP8s6O8eehkvoXVS5FEk45zq+CrVX/1CH+PARa93lIR9UUG3XUFMn/fdghtv6 +Vdb0Fa7uevmejFfQ4dFxcJ1WOdspojo+SvjrkIPWzl4CsTvpoG4JX2bb8GoQlQ+M2yO j6yxK+qMvejOs1PUe6P2J2ewUrWlkBShtAVYkNaUU6p6sRMiKJkAcQyR4FWQ/HlpDgEY EVQK2cYOWzSorsif20j2zLf7KUZzv5tg960IPfrJo0uvPxFQ+7RZtB59Ir+4myib5yIK LniNly4egOR33GeI0i/LhB8/5iv3shnTQOEXEl/rJBccl8e/fQ0WGBjuR/Q4636QTsdK 2YGQ== X-Gm-Message-State: AOJu0Yyz+4XL13NsGdL+KvyIGMMcLSvsiq0HZxqQWBxGmITnFFTOjo+0 ectElGcE33vdMHKdmzUAl7rPpH4OeWG+e2Xjr6Lfrg== X-Google-Smtp-Source: AGHT+IFuvLGJBbbrYBuwSC45c6lMiKnZtKLDhd2uYkDOtA+yvnSz3576Z2cSIC3fuO+VieGB44TKiw== X-Received: by 2002:a5d:9ec3:0:b0:790:bc17:1c63 with SMTP id a3-20020a5d9ec3000000b00790bc171c63mr942882ioe.1.1696376140677; Tue, 03 Oct 2023 16:35:40 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:40 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 37/51] bsd-user: Implement ipc_perm conversion between host and target. Date: Tue, 3 Oct 2023 17:32:01 -0600 Message-ID: <20231003233215.95557-38-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-10-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c index 8834ab2e588..46cda8eb5ce 100644 --- a/bsd-user/bsd-mem.c +++ b/bsd-user/bsd-mem.c @@ -30,3 +30,28 @@ void target_set_brk(abi_ulong new_brk) target_brk = TARGET_PAGE_ALIGN(new_brk); initial_target_brk = target_brk; } + +void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip, + struct target_ipc_perm *target_ip) +{ + __get_user(host_ip->cuid, &target_ip->cuid); + __get_user(host_ip->cgid, &target_ip->cgid); + __get_user(host_ip->uid, &target_ip->uid); + __get_user(host_ip->gid, &target_ip->gid); + __get_user(host_ip->mode, &target_ip->mode); + __get_user(host_ip->seq, &target_ip->seq); + __get_user(host_ip->key, &target_ip->key); +} + +void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip, + struct ipc_perm *host_ip) +{ + __put_user(host_ip->cuid, &target_ip->cuid); + __put_user(host_ip->cgid, &target_ip->cgid); + __put_user(host_ip->uid, &target_ip->uid); + __put_user(host_ip->gid, &target_ip->gid); + __put_user(host_ip->mode, &target_ip->mode); + __put_user(host_ip->seq, &target_ip->seq); + __put_user(host_ip->key, &target_ip->key); +} + From patchwork Tue Oct 3 23:32:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B63EE8FDBF for ; Tue, 3 Oct 2023 23:39:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovw-0004Z2-41; Tue, 03 Oct 2023 19:36: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 1qnovm-0004Pd-Jh for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:58 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovX-0007R2-0j for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:58 -0400 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-79faba5fe12so57774439f.3 for ; Tue, 03 Oct 2023 16:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376141; x=1696980941; 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=Gu7LXH0KtqoAmWr0NOHNKS6NC88NWxHbhJG+bHoQChE=; b=rClnTB0/dqFgMyRzNKcDHMjwD1cWcCo3rX97qVlL8Q0d8EwdFcFHWl3JU6l9S/VASL NsE6bZOM4eKGjwXfe640RG+pZaA7N8SF6BVOQmYDClvax52PYXDYBxL87T668HqS+uEL k2O1Aitqn7aCIk6TFER/cRqrwdZCluulJ6skjI6EIAPZArHV0trOZOJs3QQVtBai0sh3 xBcasPbUhvnU+i/zT1Xom3DVeW3NWrGFdbljDl+6qM2MNTQlsazUGpdRqnJl9JN9UETP bG9unRyUbFyF/YPZFTsvI6Nm9gkaS1HZEITRd0Ha336T4Bz4qyESXR4A2hrTv8BTYa2W lahQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376141; x=1696980941; 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=Gu7LXH0KtqoAmWr0NOHNKS6NC88NWxHbhJG+bHoQChE=; b=Q7fqahNV8i9JarTbJcmSSGwQFu+dirEpGBC/cKbxvjtDxlO/sl0u3POocAVl0Ily3o zpIQRAvLmnmmveJVBUXJzX0hBNQ8tU5zyi3HBn3PVTYG4d+WKgVV9hTl8fX76DxbpmD7 RTa2tnu49IdAVOxQDoPvTjWZoRLdGjQzED7xHDKd6CufO3BkSJdWa+879GMeKA+iDJy0 SbBueK6OOO0fNrHE/hRFcgSTFLfeEKzAKmP82tEWzr67PLcg/dsBKdwMr4KCCnMvJJRS kncKCAEPhBlClh+DdNI7njeAR9gBK/OINAuVHGh+L3/KZjBdiOhvozxTrOnxxvjkVC48 ODsw== X-Gm-Message-State: AOJu0Yz+cr/pi+E3DQPne7bLRLFNz6JpdkzrhdbPE2sOtDWUgtKw0ziK yYKJyQuWIusIdbWNJc6r7lwbRhfnDl/WOU3T/QfMVg== X-Google-Smtp-Source: AGHT+IFw9EtrHE1xzilxHySckHYty5OkfbUttYYQ1PHJJOTMfig8QHD+OXPkVpns8NVYJUbC1JJZQA== X-Received: by 2002:a05:6602:22d8:b0:794:c9a2:5fe3 with SMTP id e24-20020a05660222d800b00794c9a25fe3mr977403ioe.4.1696376141497; Tue, 03 Oct 2023 16:35:41 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:41 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 38/51] bsd-user: Implement shmid_ds conversion between host and target. Date: Tue, 3 Oct 2023 17:32:02 -0600 Message-ID: <20231003233215.95557-39-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-11-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c index 46cda8eb5ce..2ab1334b700 100644 --- a/bsd-user/bsd-mem.c +++ b/bsd-user/bsd-mem.c @@ -43,6 +43,30 @@ void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip, __get_user(host_ip->key, &target_ip->key); } +abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, + abi_ulong target_addr) +{ + struct target_shmid_ds *target_sd; + + if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) { + return -TARGET_EFAULT; + } + + target_to_host_ipc_perm__locked(&(host_sd->shm_perm), + &(target_sd->shm_perm)); + + __get_user(host_sd->shm_segsz, &target_sd->shm_segsz); + __get_user(host_sd->shm_lpid, &target_sd->shm_lpid); + __get_user(host_sd->shm_cpid, &target_sd->shm_cpid); + __get_user(host_sd->shm_nattch, &target_sd->shm_nattch); + __get_user(host_sd->shm_atime, &target_sd->shm_atime); + __get_user(host_sd->shm_dtime, &target_sd->shm_dtime); + __get_user(host_sd->shm_ctime, &target_sd->shm_ctime); + unlock_user_struct(target_sd, target_addr, 0); + + return 0; +} + void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip, struct ipc_perm *host_ip) { @@ -55,3 +79,26 @@ void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip, __put_user(host_ip->key, &target_ip->key); } +abi_long host_to_target_shmid_ds(abi_ulong target_addr, + struct shmid_ds *host_sd) +{ + struct target_shmid_ds *target_sd; + + if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) { + return -TARGET_EFAULT; + } + + host_to_target_ipc_perm__locked(&(target_sd->shm_perm), + &(host_sd->shm_perm)); + + __put_user(host_sd->shm_segsz, &target_sd->shm_segsz); + __put_user(host_sd->shm_lpid, &target_sd->shm_lpid); + __put_user(host_sd->shm_cpid, &target_sd->shm_cpid); + __put_user(host_sd->shm_nattch, &target_sd->shm_nattch); + __put_user(host_sd->shm_atime, &target_sd->shm_atime); + __put_user(host_sd->shm_dtime, &target_sd->shm_dtime); + __put_user(host_sd->shm_ctime, &target_sd->shm_ctime); + unlock_user_struct(target_sd, target_addr, 1); + + return 0; +} From patchwork Tue Oct 3 23:32:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05984E8FDC0 for ; Tue, 3 Oct 2023 23:40:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovc-0004HS-Dv; Tue, 03 Oct 2023 19:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovb-0004Gc-1I for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:47 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovY-0007RG-0f for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:46 -0400 Received: by mail-io1-xd42.google.com with SMTP id ca18e2360f4ac-79fc3d32a2fso60172639f.1 for ; Tue, 03 Oct 2023 16:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376142; x=1696980942; 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=toTg5XymdIq2DzzIW6fWIsDHgRoIQT+xw06H9JfCJnM=; b=PSkApX6NmnhZjKaBmHRJtcD8bY+AteuQhtfqVuootL0q3+SZuQfCmB13ok2gi/r46N 3QuwEgnIAFc2ow7F2S2i8sRtuqne3UGHTK16REXi4k5xlL+HdnrRsdEcxgIItKp3G+KI aWg+WpUgmvNnJtQX/EWSCFL0LnyTr/A37fAxdNnuqWLEKDbB4rYK3s3hcwZHHs3WX/Hw jDJk95j2P/DtAYkoEUwsJOGOBskwPbPQxozRxvVzYK4ZeXFrTMhJwdG/Lse3jXr6a+7G D7W4xOhLmymkW2HT20Dpli09ccQA9kwTVrLpWCiHFRZP/qlGw22Ey00xao8jbuUkMJue wPWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376142; x=1696980942; 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=toTg5XymdIq2DzzIW6fWIsDHgRoIQT+xw06H9JfCJnM=; b=kSqCmFJIn5pZx11Aq6xBQcoVRglB3ATQ0d3c8TXFY9R6Dy/x4hjtHVTJF43/iT/sbD hs5KmUtfvZ9RLghJAmxNZG7jGB82dj4DeE1neNy4ZAkli9rQ9Ygg3VMXiWkQOA4nnHJh tkT4Y5aZ81cSugy1QPbYxdKR21SW2kr78ZVsYsQpARV/pPhmhS9aYbRUeLia/s/vt2ii k1/mIUsoSw4dZCto+YQa2Hj2qW/j9PXeSC9J2yhxdlzWlBRi5r8QyD9urpo1ZCJPp8a1 5Op90OKvSeSY1Y9VULit4QsfdOlqTFN+j1DjkFjQgTBCG05P8tXqhJxvNAJA+fZBaE0S lqkw== X-Gm-Message-State: AOJu0YzqIsMmiIHatfflhUgKCHR8TzkuBvKpsrRe9j/DyD5LYyWqaTwA WEdTyurd8qbCLDB7asVWYQzebWe8m0nh4mLh68UGKuFZ X-Google-Smtp-Source: AGHT+IGiD29wlcXmF7+48ZnH/u2i1ITbKGOxX/BJd8+QJRZMALPSFj8TRI+1ELOoWnB9jIPkzcP7VQ== X-Received: by 2002:a5d:9943:0:b0:787:ff98:c38c with SMTP id v3-20020a5d9943000000b00787ff98c38cmr1100009ios.10.1696376142413; Tue, 03 Oct 2023 16:35:42 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:42 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 39/51] bsd-user: Introduce bsd-mem.h to the source tree Date: Tue, 3 Oct 2023 17:32:03 -0600 Message-ID: <20231003233215.95557-40-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d42; envelope-from=imp@bsdimp.com; helo=mail-io1-xd42.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Preserve the copyright notice and help with the 'Author' info for subsequent changes to the file. Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-12-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 64 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 1 + 2 files changed, 65 insertions(+) create mode 100644 bsd-user/bsd-mem.h diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h new file mode 100644 index 00000000000..d865e0807d8 --- /dev/null +++ b/bsd-user/bsd-mem.h @@ -0,0 +1,64 @@ +/* + * memory management system call shims and definitions + * + * 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 . + */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef BSD_USER_BSD_MEM_H +#define BSD_USER_BSD_MEM_H + +#include +#include +#include +#include +#include + +#include "qemu-bsd.h" + +extern struct bsd_shm_regions bsd_shm_regions[]; +extern abi_ulong target_brk; +extern abi_ulong initial_target_brk; + +#endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index c9d34b59bbe..7887ad4c0c6 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -35,6 +35,7 @@ /* BSD independent syscall shims */ #include "bsd-file.h" +#include "bsd-mem.h" #include "bsd-proc.h" /* BSD dependent syscall shims */ From patchwork Tue Oct 3 23:32:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2EC00E8FDC3 for ; Tue, 3 Oct 2023 23:44:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovd-0004Hp-Lv; Tue, 03 Oct 2023 19:35:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovc-0004HN-83 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:48 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovY-0007RV-KQ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:47 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79fce245bf6so58308039f.1 for ; Tue, 03 Oct 2023 16:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376143; x=1696980943; 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=5PHERJl8GQhbey89K8x6f4j4Q8OwnuZ/ncrkVlq5O9w=; b=cCcwhsB1+oqnUmB3xg+W9BA/ssR1rHLUQqXLGEXAws2fkl1wWJL5UVmg+gTuLi2xvR uIZcBWO6JPU/WX4yDDjUF3jFgAPx7sUbMC8/ONsofXTgOnVDxT8EM3mggeRJ4G8HaFjN VDBG19ms68AKHbnCdRPlfpvoP52aM6e0WP5z+f9Fl7CJYf7ZW4HKEk0GSuEkkaZ3u0k5 isDZr/oGAqVa9pPxXRiLaF/XeAy1hrNvYIHQ5Lcc6TAgvpd9dcnKHM1PV1mPzUwwijQG bwlh314nH4X15wG6QSV9PK93xKTYLPNkM46Xo7lhjiQJ5S2ttd6K2idgn0SW4AWM/ZLc fahw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376143; x=1696980943; 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=5PHERJl8GQhbey89K8x6f4j4Q8OwnuZ/ncrkVlq5O9w=; b=HrucR3rD9UjVsVyS1STBuHE4XL56cR6olYnZvRpox8gTq8RVGvHaMlyOr3KBvHd2Fd kuNGiITNTKbou9rnGUjh1Qo2BnKAagFGTVeiLtCfozbEbNDzkE2Ozi8m4+uhTV5HVjX0 z5vMdFXTIBtvo/FFk3ueIcWVTcpGWi6ULOqadcvL4srd47Wqtw1L7EffJMAr/yLTvH33 eFJxsFZFtalysfUgxNAW5hFFUhxzPd1UGg6NWKJ6el+R7kx0MF0AQyIWQtd9c0+rPjnJ acQOQJGuztaDie/46vseAIYXSKDlkrwxxI0mkpCJqup1DOkHaJM4zP8qrA46Hbx08b4T JxuA== X-Gm-Message-State: AOJu0Yy9h4xnP08nmn32M6iT4cPLGsTKRxHcAT1bM0uSgYH4tDnyF1Bn Abf9Zs2YKtcJ4b7DQbzv89uFRTdZUlctJdvwVW2UOg== X-Google-Smtp-Source: AGHT+IGgHX/teRChYawrxjQXFIcTwY0y2OSfMDOhMTtXYTkyTcBre7viDHKFtGo17DW9FBpYWK7DkA== X-Received: by 2002:a05:6602:220c:b0:786:fff8:13c2 with SMTP id n12-20020a056602220c00b00786fff813c2mr973198ion.11.1696376143372; Tue, 03 Oct 2023 16:35:43 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:43 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 40/51] bsd-user: Implement mmap(2) and munmap(2) Date: Tue, 3 Oct 2023 17:32:04 -0600 Message-ID: <20231003233215.95557-41-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-13-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 20 ++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index d865e0807d8..76b504f70c5 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -61,4 +61,24 @@ extern struct bsd_shm_regions bsd_shm_regions[]; extern abi_ulong target_brk; extern abi_ulong initial_target_brk; +/* mmap(2) */ +static inline abi_long do_bsd_mmap(void *cpu_env, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, + abi_long arg8) +{ + if (regpairs_aligned(cpu_env) != 0) { + arg6 = arg7; + arg7 = arg8; + } + return get_errno(target_mmap(arg1, arg2, arg3, + target_to_host_bitmask(arg4, mmap_flags_tbl), + arg5, target_arg64(arg6, arg7))); +} + +/* munmap(2) */ +static inline abi_long do_bsd_munmap(abi_long arg1, abi_long arg2) +{ + return get_errno(target_munmap(arg1, arg2)); +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7887ad4c0c6..b03837d032a 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -798,6 +798,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, /* * Memory management system calls. */ + case TARGET_FREEBSD_NR_mmap: /* mmap(2) */ + ret = do_bsd_mmap(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, + arg8); + break; + + case TARGET_FREEBSD_NR_munmap: /* munmap(2) */ + ret = do_bsd_munmap(arg1, arg2); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); From patchwork Tue Oct 3 23:32:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408104 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 993E9E8FDBF for ; Tue, 3 Oct 2023 23:36:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovq-0004UU-Rh; Tue, 03 Oct 2023 19:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovl-0004MC-KX for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnova-0007Rp-N3 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:53 -0400 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7a2a9e5451bso58473039f.1 for ; Tue, 03 Oct 2023 16:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376144; x=1696980944; 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=jhtBcCLqYRdXH9l+jJ0/HOZSt1P08pHO71aNhpu5SkU=; b=KePwgqR+LjZVCeHEvB6Ra/e50uGGhPKZYGizutrfJfdpSl9FQ0VvQBMLhcXIR/278k QgMvNl50XRhtEhsAoOLyjxcuZsFvanDJP383WOJZqNsLEdG3DLCXzQuARkchJT9VroVo xBQFVJQdzxKH+pKiRjKXBD4HMCMiYfGl2qkd+acXUQLz/6LiodD6uhdfJFGNy/b/ZXJW XM5Bs0Z/eaaoX2m+1tFMsRhDb6Ny0GI0Q3HehJZ2zduWOxobi46RCu5jSTtASKAXp+4e wUQOdpsYXzFcIkhNgq4S1acd41Bs+Nzdn9YrVFYaGDp2nC3rZf4hGrGqjo1HD2eYCdwM pNJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376144; x=1696980944; 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=jhtBcCLqYRdXH9l+jJ0/HOZSt1P08pHO71aNhpu5SkU=; b=Hx+X2TUIrz2OJZ8gq7Tngl8QYQUgqVbaldySasWNf/vdDEsk3MdJ5QjC3GX6ZBUOl6 JxxUQu4cg6KZXOEA88mIOQn3vA8SHUhiTmSQMzyZBuq8Y6MYP5qwdhJDSrnphvQ6aO1Z BE1KbjXtTXCZyapLKU9pHD55L3chzfkecOKS6eGP8QWe0QuFvBcPrvOD9NAN1FJD30og WjCbkKbTaW+Zq3yoDTtvsHExUveOHohpHxQTZ/Sq0crdjAMHop7hvaR9mrpuSz9c0AUs /UFe0bwVjUU2WJjFNrEX1J+o1CscGTNtB88xiON55Hehhah/3Qf6XjzxFNXmEjUaper8 kpfg== X-Gm-Message-State: AOJu0YwdEUVnnUfw9GPZeJtJccBW/x3Td4x2ssgP99Ilj7SJFJJf0DXK HcclBK2vo+P4qr8ttD0eDCm0H4p9/3OC4nUMDJGrtw== X-Google-Smtp-Source: AGHT+IFWNfpsiO8BvmONe6EdFceFlZ5Ap0NP1iqQnIsvyXBQdKEQZ0fgKkbxrsSMYcvwKQdwW8dbvg== X-Received: by 2002:a6b:6816:0:b0:79f:b37f:98e6 with SMTP id d22-20020a6b6816000000b0079fb37f98e6mr839194ioc.20.1696376144232; Tue, 03 Oct 2023 16:35:44 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:43 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 41/51] bsd-user: Implement mprotect(2) Date: Tue, 3 Oct 2023 17:32:05 -0600 Message-ID: <20231003233215.95557-42-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh Message-Id: <20230925182709.4834-14-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 7 +++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 76b504f70c5..0f9e4a1d4be 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -81,4 +81,11 @@ static inline abi_long do_bsd_munmap(abi_long arg1, abi_long arg2) return get_errno(target_munmap(arg1, arg2)); } +/* mprotect(2) */ +static inline abi_long do_bsd_mprotect(abi_long arg1, abi_long arg2, + abi_long arg3) +{ + return get_errno(target_mprotect(arg1, arg2, arg3)); +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index b03837d032a..2d8f1a953b2 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -807,6 +807,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_munmap(arg1, arg2); break; + case TARGET_FREEBSD_NR_mprotect: /* mprotect(2) */ + ret = do_bsd_mprotect(arg1, arg2, arg3); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); From patchwork Tue Oct 3 23:32:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A78D9E8FDC0 for ; Tue, 3 Oct 2023 23:42:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovo-0004TA-DZ; Tue, 03 Oct 2023 19:36:00 -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 1qnovk-0004M5-M7 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnova-0007S7-FL for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:52 -0400 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-79fb64b5265so61150539f.1 for ; Tue, 03 Oct 2023 16:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376145; x=1696980945; 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=fs1dcVqCXTX8RM3B0vVfSAr/XS18s4HpUbI3OIrGI0Y=; b=KTK9fEh5MZYKXqqouRY5vncDUHC4jS6OHf0XghSOL/6648bBUkQvySwJqOnZ92caGW PXjGSyYcZKiYYjY02T27lXQ6l7IP8bCpTj4YO76Xh3xtLaBQUgi3PRvDdWbWdhspofX5 LvvDLz3asDdnR8vRSlFvFExUCvU9oXItKNaSp0aI1tdLRHk3mFpE0Bgi1CM04nCZvFeD Qv4FKoNYiWEkPaU58ZuFsHQEQevKEI/sNm15D6XkWpvvQ0owIrQH99tSj8xj5jPQ9orW YvKv/kVWlVZ7hgVS2NRiBEwo+Epbrzhu3bePg6LFFrY7A4MHH8HHKXaMlgSGNiQKvnku 6WnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376145; x=1696980945; 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=fs1dcVqCXTX8RM3B0vVfSAr/XS18s4HpUbI3OIrGI0Y=; b=Gi6DEG2BiO5ecegixHooU70EQE7mxgr43OiPcI+e+t62O/c/zXXZLtlCE/g6SzNfQj LQyCOzAHiCASHLqRdDYN+j2N95GiBOqHzQ4wq/vRxukhEsDY1pXNiEMPWqw9cAxD1lrQ 0JX43gxKUi/NMej6BPifU/h8HlX/KUoTSRswuRzzDSUY9dcVRkMu1tJT3gKr9tJKd8Yy S3gS+sLtxVOQLZQ17oOv6ynkDOfAf+jKzOSiElobM2kl6+fj89W+16CBnyG86N/tShSx S/3ykATWwMCi7E7ebbi+OLTFKo07meskDCS7rv1LfYrHRMTYmxZHjOvdXOuaiApoRYqT gEgQ== X-Gm-Message-State: AOJu0Yzk/TcPXkAV4Hd2A5f5/GRuVolZ++6X1uh8/wQMNPitfA2xe7X8 PsdA0iw31fXAkOO1qIirVtt95Mp0pUUUOVJN57pWaw== X-Google-Smtp-Source: AGHT+IEHnC7V/j9hifiV5Z5q6mlaapcsOC0dzD+cGD75OjFTY3x7iyienk3kWXWEpQqsqKzoZrKs6A== X-Received: by 2002:a5e:8c0c:0:b0:795:16b8:85fc with SMTP id n12-20020a5e8c0c000000b0079516b885fcmr1006158ioj.0.1696376145177; Tue, 03 Oct 2023 16:35:45 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:44 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Kyle Evans , Karim Taha , Richard Henderson Subject: [PULL 42/51] bsd-user: Implement msync(2) Date: Tue, 3 Oct 2023 17:32:06 -0600 Message-ID: <20231003233215.95557-43-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Co-authored-by: Kyle Evans Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-15-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 11 +++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 0f9e4a1d4be..5e885823a79 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -88,4 +88,15 @@ static inline abi_long do_bsd_mprotect(abi_long arg1, abi_long arg2, return get_errno(target_mprotect(arg1, arg2, arg3)); } +/* msync(2) */ +static inline abi_long do_bsd_msync(abi_long addr, abi_long len, abi_long flags) +{ + if (!guest_range_valid_untagged(addr, len)) { + /* It seems odd, but POSIX wants this to be ENOMEM */ + return -TARGET_ENOMEM; + } + + return get_errno(msync(g2h_untagged(addr), len, flags)); +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 2d8f1a953b2..2525e0bc316 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -811,6 +811,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_mprotect(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_msync: /* msync(2) */ + ret = do_bsd_msync(arg1, arg2, arg3); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); From patchwork Tue Oct 3 23:32:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99C9BE8FDC0 for ; Tue, 3 Oct 2023 23:44:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovp-0004UI-Ol; Tue, 03 Oct 2023 19:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnovk-0004M8-MR for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovc-0007SO-0X for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:53 -0400 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-79fa5d9f3a2so57662039f.3 for ; Tue, 03 Oct 2023 16:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376146; x=1696980946; 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=5NCyHAC9bXim/1mXpJd490XbnS8liuXo8kxgl9Yya/4=; b=FDWWUnQ1/1qa/U0+1VFdwE6hqdijGcGJ5LpGf/hKMVLgwBYwxxP6NS/EIDiEKSo8ri YAVLyWaRRPEUJIsfLWi0ay+BNQNyLkYIgXhsrR23AvoudrID+TwJQERydceRo5KCyXWv fQUJIxYECFFrYsUoIElaM5Cq9iTFlO4SNY6naM9OXCa2PF+pFe5mV5LUmyHLKnBsXmOe 9nS86NoHX/SBY7SLW9TfwiiKtVqf3pHujWIutUGONoD86rYsAC5FBB8nZz/sPyHWQ53X 0YxzlwvKa2Jg7/Twv8sCi88pksrpG1PtLiwCmwccYyhjvTDIeiTh20rP3eC2rk6767WL my8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376146; x=1696980946; 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=5NCyHAC9bXim/1mXpJd490XbnS8liuXo8kxgl9Yya/4=; b=sLQ0tLNwvNm2hJmgOhION2jFWm+pok7pd5E3721A8aGvExWt5D/sKEAPHWhXSDvVpi UzUw+hB4Ka6LZqTFzsiutQMlEjIMQr21np1B///a3TebR20MxirJKJ/6Yc3+w8lP4XAr tDEa9S90xaMDplQiViUJ4rpFmy64Mc5plpCmvtuALQoxZujJ+I3cyzZ4SayMUhoKXfho twPomH+m1AUtfnxGo8EDGN8iXp7TJ+ktm6n32BvnmABCg/h3L0nR2WawvExlBVJ3u4I9 yTSAmr4eQ6n3rUvg9WBRRdSrTR3ZNDUgHu7Hc7rLNNQCDJ1MPg2fiBOvfFxOLEgrcOsn N5Eg== X-Gm-Message-State: AOJu0Yxm3WQlrzcmHOi+ixi6FrdgAvGpNlUNF8ljJGrQ72UJDJMkbbMO My+K89Hqy08vqQP4UM2eaOfCAo1tdlP0hkedugADng== X-Google-Smtp-Source: AGHT+IGsOFW3d+6U1fFTOGki2d3Si6JtXpKrW6BN//d2GpH0FKZwc/xjXi3/J0QlZ1AbKvNshEQgPw== X-Received: by 2002:a05:6602:228a:b0:79f:a25b:51c with SMTP id d10-20020a056602228a00b0079fa25b051cmr969801iod.11.1696376146172; Tue, 03 Oct 2023 16:35:46 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:45 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 43/51] bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2) Date: Tue, 3 Oct 2023 17:32:07 -0600 Message-ID: <20231003233215.95557-44-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2b; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-16-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 37 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 20 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 5e885823a79..16c22593bfd 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -99,4 +99,41 @@ static inline abi_long do_bsd_msync(abi_long addr, abi_long len, abi_long flags) return get_errno(msync(g2h_untagged(addr), len, flags)); } +/* mlock(2) */ +static inline abi_long do_bsd_mlock(abi_long arg1, abi_long arg2) +{ + if (!guest_range_valid_untagged(arg1, arg2)) { + return -TARGET_EINVAL; + } + return get_errno(mlock(g2h_untagged(arg1), arg2)); +} + +/* munlock(2) */ +static inline abi_long do_bsd_munlock(abi_long arg1, abi_long arg2) +{ + if (!guest_range_valid_untagged(arg1, arg2)) { + return -TARGET_EINVAL; + } + return get_errno(munlock(g2h_untagged(arg1), arg2)); +} + +/* mlockall(2) */ +static inline abi_long do_bsd_mlockall(abi_long arg1) +{ + return get_errno(mlockall(arg1)); +} + +/* munlockall(2) */ +static inline abi_long do_bsd_munlockall(void) +{ + return get_errno(munlockall()); +} + +/* minherit(2) */ +static inline abi_long do_bsd_minherit(abi_long addr, abi_long len, + abi_long inherit) +{ + return get_errno(minherit(g2h_untagged(addr), len, inherit)); +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 2525e0bc316..7a7ae26793f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -815,6 +815,26 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_msync(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_mlock: /* mlock(2) */ + ret = do_bsd_mlock(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_munlock: /* munlock(2) */ + ret = do_bsd_munlock(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_mlockall: /* mlockall(2) */ + ret = do_bsd_mlockall(arg1); + break; + + case TARGET_FREEBSD_NR_munlockall: /* munlockall(2) */ + ret = do_bsd_munlockall(); + break; + + case TARGET_FREEBSD_NR_minherit: /* minherit(2) */ + ret = do_bsd_minherit(arg1, arg2, arg3); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); From patchwork Tue Oct 3 23:32:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7F8EE8FDC0 for ; Tue, 3 Oct 2023 23:41:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovs-0004Wl-2o; Tue, 03 Oct 2023 19:36: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 1qnovm-0004Pe-JB for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:58 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnove-0007Sm-C3 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-79fce245bf6so58309539f.1 for ; Tue, 03 Oct 2023 16:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376147; x=1696980947; 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=bS/7XD3QWTqjRTlEK+pQc9fvJl6oodvE6Kcpj/qv1/I=; b=K+FZsvYQn/Dms7+tGp7rIEXU4TyWxNDSuLA8jz8SGQIpE7IeRjsmKBEs/TXBTMYAaW nUdY9KL/1gzLyTX0p47MGCTvSUzi83qNLss6oagKv70/mYi8isaEhZGADCyccx7bUCVz q3bGvXrAni54YbK/MwiUWbKbqFSVQYK8nEt0n3Fjwfvjv5UyNGlcAAqR5ztRClgN0Ndl zG7A6ORMeT7cfGLZYVrgutl5AfXvo5GokWq+QmEbsHjCbgaGXH4pV3QM9lS574ivtULY lv6M//h94T3NBKh/hdcXtImYGqwyvwwKzFHnESSrMhsQRqaqUaPzhnctysda6t6zLh8E ra6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376147; x=1696980947; 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=bS/7XD3QWTqjRTlEK+pQc9fvJl6oodvE6Kcpj/qv1/I=; b=RZDFieL9RBvSB07KN4h0sL5ypgx9+MeIj5Ia1e4QTfvZCaV9+vK6P5/jWD92YA6MDy cGatA4XKgA5VZao395NLryVbpngd9eVrxZEARJzYEF00+cr60O6Or96i1N+HNCR+Fh5K oGa/kn3RlYksRs+rqmLthhSwvO2pUI0UCEOSaW7rAwkK8Pcba3/gciuvkUtgIkLidaC3 jzW1gYeqT1JvLF2tqE2mHMrJUjWYMAdZ4Wc6qJ1QgcNhR3zpR94wPjScIBvB7c5GyP/p HgwiCUmyAzvwrHMp2b3kHvxM6uc97GF8dIFy+6V4mrQUojzgSYvwNCDKf0Gpmy7QIYh3 Wmrg== X-Gm-Message-State: AOJu0Yz5lY6oQyI0TjQerjdf98WkxRuiujwAQvnBaDAwvs7cq+lYacPL 684B/X8LPSMsOJPiCLhTKx927clQvJdJ239iMq32gw== X-Google-Smtp-Source: AGHT+IFTgELGiniy3zspwhILwfQ6tZZeSqWzKg5NIzC/6o8EBcGUX5m24V3c+TJ8PHKa84yt4JeZXA== X-Received: by 2002:a6b:7e05:0:b0:79f:cb49:f476 with SMTP id i5-20020a6b7e05000000b0079fcb49f476mr859321iom.21.1696376147085; Tue, 03 Oct 2023 16:35:47 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:46 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Richard Henderson Subject: [PULL 44/51] bsd-user: Implment madvise(2) to match the linux-user implementation. Date: Tue, 3 Oct 2023 17:32:08 -0600 Message-ID: <20231003233215.95557-45-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Karim Taha Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-17-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 53 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 +++ bsd-user/syscall_defs.h | 2 ++ 3 files changed, 59 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 16c22593bfd..b00ab3aed8e 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -129,6 +129,59 @@ static inline abi_long do_bsd_munlockall(void) return get_errno(munlockall()); } +/* madvise(2) */ +static inline abi_long do_bsd_madvise(abi_long arg1, abi_long arg2, + abi_long arg3) +{ + abi_ulong len; + int ret = 0; + abi_long start = arg1; + abi_long len_in = arg2; + abi_long advice = arg3; + + if (start & ~TARGET_PAGE_MASK) { + return -TARGET_EINVAL; + } + if (len_in == 0) { + return 0; + } + len = TARGET_PAGE_ALIGN(len_in); + if (len == 0 || !guest_range_valid_untagged(start, len)) { + return -TARGET_EINVAL; + } + + /* + * Most advice values are hints, so ignoring and returning success is ok. + * + * However, some advice values such as MADV_DONTNEED, are not hints and + * need to be emulated. + * + * A straight passthrough for those may not be safe because qemu sometimes + * turns private file-backed mappings into anonymous mappings. + * If all guest pages have PAGE_PASSTHROUGH set, mappings have the + * same semantics for the host as for the guest. + * + * MADV_DONTNEED is passed through, if possible. + * If passthrough isn't possible, we nevertheless (wrongly!) return + * success, which is broken but some userspace programs fail to work + * otherwise. Completely implementing such emulation is quite complicated + * though. + */ + mmap_lock(); + switch (advice) { + case MADV_DONTNEED: + if (page_check_range(start, len, PAGE_PASSTHROUGH)) { + ret = get_errno(madvise(g2h_untagged(start), len, advice)); + if (ret == 0) { + page_reset_target_data(start, start + len - 1); + } + } + } + mmap_unlock(); + + return ret; +} + /* minherit(2) */ static inline abi_long do_bsd_minherit(abi_long addr, abi_long len, abi_long inherit) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7a7ae26793f..b8c44cea0ff 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -831,6 +831,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_munlockall(); break; + case TARGET_FREEBSD_NR_madvise: /* madvise(2) */ + ret = do_bsd_madvise(arg1, arg2, arg3); + break; + case TARGET_FREEBSD_NR_minherit: /* minherit(2) */ ret = do_bsd_minherit(arg1, arg2, arg3); break; diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index ff692814333..52f84d5dd17 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -95,6 +95,8 @@ struct bsd_shm_regions { /* * sys/mman.h */ +#define TARGET_MADV_DONTNEED 4 /* dont need these pages */ + #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */ /* MAP_INHERIT */ #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */ From patchwork Tue Oct 3 23:32:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7780E8FDC0 for ; Tue, 3 Oct 2023 23:45:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovu-0004Yz-59; Tue, 03 Oct 2023 19:36: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 1qnovm-0004Pc-JB for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:59 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnove-0007T5-Bs for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-79f9acc857cso54764539f.2 for ; Tue, 03 Oct 2023 16:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376148; x=1696980948; 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=PqkFGNnZr4Hir1xs5a2neZwKr2N6dkSvYPZpyI4/s4A=; b=POGwBzSXi82zmQJOXY8JV948drkEgDqBXWDu6Zdnz0SrdG/ZE3bto1BfImqYdzil0E K7srIHOkqH1q52JkTPpQ+4po0xXACyKLprZzgrtMIEi/J3r69q+OipbAH2uUBRAcRz0v tBCDnEWIGrhyZQMfCblbPaYSWPUVPKK/ej/1SFAfvSoVKEHFFfyw7Gd10NhkMWRfIxpD 4EeHzKSBWIbpau/odvBs1/8yzwGYZmNlG9Iy02E+XfPszoPEaeexpzQSrV0A8Ax8jIe7 1ubQIrYPqs2j3sCB3uj86VxXHtyaYu4pr0qBihxcUo7D/Q8VSzMhMSMSMdIYON5btsPY oqRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376148; x=1696980948; 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=PqkFGNnZr4Hir1xs5a2neZwKr2N6dkSvYPZpyI4/s4A=; b=ivD4kGwxwCMAH6jy1o9ckDueVkF1fuYHDYV75gtWWspg6745LWKZzGpwZBD5qiwCQO zjTDARetIiUTnuoHJ6R3vNUklWDe8NtFij/iKpTZT0rCp6Ev7ysCGfgaCgmFJeTwXyhm MSxcHs7le+dnA3Bvwrcy08+h/BFhZexfSOXhrp5DJhuBE+CnEGaRWyWq2/RZibJXkoyR HCkD2JNcrOPHFc9YIu/9QxqR+IJaCsDwxd3VgaMrc3Ahn97KxZNVEEakuHbb92kJlvmC Lmww3bJfUXZ2kdOTqavJOYJBD8cjeK/cQAgyNuykqoNocwINeAWEeGniY/NgvcWVf+n9 dm4A== X-Gm-Message-State: AOJu0YxxdYuKHyf7FgBdcPCwS/7HYnIhj+2qTKpJnXJe0YCWyjYMD5/W ZDMpZPFHwoDhQuam/RQmS4OsV7ewB+gk08Nzx02Apw== X-Google-Smtp-Source: AGHT+IE8k3C998aY9XOLM13sV0eb+89fAHhmQr2pEZw6OPPLmaYSrl0q+alpWcfbEb5k5ZqcSZcWWQ== X-Received: by 2002:a6b:da06:0:b0:794:d7e8:d239 with SMTP id x6-20020a6bda06000000b00794d7e8d239mr844399iob.17.1696376147942; Tue, 03 Oct 2023 16:35:47 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:47 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 45/51] bsd-user: Implement mincore(2) Date: Tue, 3 Oct 2023 17:32:09 -0600 Message-ID: <20231003233215.95557-46-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-18-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 23 +++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index b00ab3aed8e..0c8d96d9a43 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -189,4 +189,27 @@ static inline abi_long do_bsd_minherit(abi_long addr, abi_long len, return get_errno(minherit(g2h_untagged(addr), len, inherit)); } +/* mincore(2) */ +static inline abi_long do_bsd_mincore(abi_ulong target_addr, abi_ulong len, + abi_ulong target_vec) +{ + abi_long ret; + void *p; + abi_ulong vec_len = DIV_ROUND_UP(len, TARGET_PAGE_SIZE); + + if (!guest_range_valid_untagged(target_addr, len) + || !page_check_range(target_addr, len, PAGE_VALID)) { + return -TARGET_EFAULT; + } + + p = lock_user(VERIFY_WRITE, target_vec, vec_len, 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(mincore(g2h_untagged(target_addr), len, p)); + unlock_user(p, target_vec, vec_len); + + return ret; +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index b8c44cea0ff..f054241cd62 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -839,6 +839,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_minherit(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_mincore: /* mincore(2) */ + ret = do_bsd_mincore(arg1, arg2, arg3); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); From patchwork Tue Oct 3 23:32:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B98ABE8FDBF for ; Tue, 3 Oct 2023 23:44:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovs-0004X1-9e; Tue, 03 Oct 2023 19:36: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 1qnovk-0004M7-ML for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:57 -0400 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnove-0007TE-AV for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:55 -0400 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-79f9acc857cso54765439f.2 for ; Tue, 03 Oct 2023 16:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376149; x=1696980949; 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=ghXvw1CEOFvx+EvpSHrnuN4yclzjxnuEasAI7tTRTeg=; b=dRe8swVltzr+HHlLGyuEfxzrHxNxOTb6hIj1KDSitQoFM2ZxeWd/vV1a0CHPHhnjSZ xo+CQ+nwj8gvYM5/DQpEW+WUTr5yGr8HjoiroFlq9SMSpoM43jpjszBaiuiL8CQxxipu Kee5pHAY0Uq8gFtY0314H8Ba+mSePAqvij/HFV/HY+cqkHhUUsexpeQqcz+rjnHx6lzD 6Z/EQ9/XkqXf2derIglgEoNjcifclV85uYAEg7XbsF8BmgxkevVyG/DA4RKqelfwvmyt 0lBrbsBH70uRoTCtIv6R1oHzFW4BLWGuPg08JgYxx+okMmqvbl71bpOZc3m7PBJZGQC9 P/EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376149; x=1696980949; 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=ghXvw1CEOFvx+EvpSHrnuN4yclzjxnuEasAI7tTRTeg=; b=EUTQWjmnSyYiPgAEVt+yLdN3w/xs0qSoVP3D7tVnpg12CjuVy68e5+umeRz1lE7GlL J9gc8fAVZYBTNwXJDdmxeUgxrlMFcePobMgO+7S88I2RAfUP4n5HdzeyLTgI7iZaYkZl LCq4SNOdENTIINDoHAxYTLdsq7EHIE3RBfwNp6r+eKjBoNXAJuZCpbQmEUYogYh/izoO HoNX8DS+RzPrBRUfc4oBicIyLYqPFArAB0a6mRoStzTCNgRarb4z03pWtKoEksVAHonO 3rvOvY7gdLjqAwADRSXY9UYlr1yBZOULGG04wViw3vFTK9LcJjA9NRjFT4xqSQ/y3N03 poew== X-Gm-Message-State: AOJu0Yx2sqDeLFVlAr1Sb2TJ4yclSnLeKT4zQcR793SdrDWjsdKtr9iB Dh3Jpn7wtPioxbPGK/Shv/CMHxbGcDHnk+f52/STVg== X-Google-Smtp-Source: AGHT+IF+6wKP+V3wIDGh99xCOo70Dp3HH0MoioiFo/BjpX83WufD5quPu81pZ855r0Y+KzcH7kGOTQ== X-Received: by 2002:a6b:c413:0:b0:79f:99f5:fadd with SMTP id y19-20020a6bc413000000b0079f99f5faddmr868530ioa.6.1696376149011; Tue, 03 Oct 2023 16:35:49 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:48 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 46/51] bsd-user: Implement do_obreak function Date: Tue, 3 Oct 2023 17:32:10 -0600 Message-ID: <20231003233215.95557-47-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Match linux-user, by manually applying the following commits, in order: d28b3c90cfad1a7e211ae2bce36ecb9071086129 linux-user: Make sure initial brk(0) is page-aligned 15ad98536ad9410fb32ddf1ff09389b677643faa linux-user: Fix qemu brk() to not zero bytes on current page dfe49864afb06e7e452a4366051697bc4fcfc1a5 linux-user: Prohibit brk() to to shrink below initial heap address eac78a4b0b7da4de2c0a297f4d528ca9cc6256a3 linux-user: Fix signed math overflow in brk() syscall c6cc059eca18d9f6e4e26bb8b6d1135ddb35d81a linux-user: Do not call get_errno() in do_brk() e69e032d1a8ee8d754ca119009a3c2c997f8bb30 linux-user: Use MAP_FIXED_NOREPLACE for do_brk() cb9d5d1fda0bc2312fc0c779b4ea1d7bf826f31f linux-user: Do nothing if too small brk is specified 2aea137a425a87b930a33590177b04368fd7cc12 linux-user: Do not align brk with host page size Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-19-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 45 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 7 ++++++ 2 files changed, 52 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 0c8d96d9a43..b296c5c6f0a 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -212,4 +212,49 @@ static inline abi_long do_bsd_mincore(abi_ulong target_addr, abi_ulong len, return ret; } +/* do_brk() must return target values and target errnos. */ +static inline abi_long do_obreak(abi_ulong brk_val) +{ + abi_long mapped_addr; + abi_ulong new_brk; + abi_ulong old_brk; + + /* brk pointers are always untagged */ + + /* do not allow to shrink below initial brk value */ + if (brk_val < initial_target_brk) { + return target_brk; + } + + new_brk = TARGET_PAGE_ALIGN(brk_val); + old_brk = TARGET_PAGE_ALIGN(target_brk); + + /* new and old target_brk might be on the same page */ + if (new_brk == old_brk) { + target_brk = brk_val; + return target_brk; + } + + /* Release heap if necesary */ + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); + + target_brk = brk_val; + return target_brk; + } + + mapped_addr = target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_EXCL | MAP_ANON | MAP_PRIVATE, + -1, 0); + + if (mapped_addr == old_brk) { + target_brk = brk_val; + return target_brk; + } + + /* For everything else, return the previous break. */ + return target_brk; +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index f054241cd62..92793ab1fb3 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -855,6 +855,13 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, break; #endif + /* + * Misc + */ + case TARGET_FREEBSD_NR_break: + ret = do_obreak(arg1); + break; + /* * sys{ctl, arch, call} */ From patchwork Tue Oct 3 23:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7131CE8FDC0 for ; Tue, 3 Oct 2023 23:40:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnow1-0004sg-F5; Tue, 03 Oct 2023 19:36:13 -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 1qnow0-0004qS-7m for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:12 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovf-0007TW-SA for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:10 -0400 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-79f915e5b47so59914839f.2 for ; Tue, 03 Oct 2023 16:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376150; x=1696980950; 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=5o5uCmY06ZAYAK3HvpohN7Kj3r79hSbBC/UkGrV9km8=; b=jNsHU9AI9DCpKr8bHG/cbqKN4o7grMASAUbf6FtZv1Lb4QLVytvcXgA9X0UtJ+rUsM v64AQwTmiH1Zm7aWa+rN7xHj/N3p/KKldQQaUu70AoOydMbAy1qLWCRXHX1MiMcJgoYK xPOjFZ/obFsiFE2xZ1alTPyWfxHI68sCSDAmH45ZItxH1+MmSOPp+maMso2/QrZ8UT1v KrvoQGHNzsr/CTqDi6bycs0iknoMr7Mllgy2tOgT5ZGCvh29ojDdpV6S3zMuhIUjZ/MQ H8MEXryEVI98DTvRTWXd6KOfgrrbyKwCOEMU3pljujOoema/cI1rs0bdCXMfihH6Rij5 qgRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376150; x=1696980950; 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=5o5uCmY06ZAYAK3HvpohN7Kj3r79hSbBC/UkGrV9km8=; b=OVlZoJGaUFUT/toOQYMo3f65ENmr92GQtwdXn6rY39Tfv6tiS90RGADqKw8Wap1NmF SPw0FRX4sXIHe5m9wDQ6jYJ27mccnB9Hkn+tGMYXjlGOfzZFso/jUE5+yY3qZ0FPZQJD kVC61zD4U0ZvvJtLjlqx/s5LQcK2TmbV+YRM5aoOZPLeCex1KlxfmyP5DEnkB6bqn/qj VtifmWJrtjjxO7n5QamJxLRfcdOwcg94TG+drTFd0GN3yDSm6TXeuIuTnAcsjVGYgWhZ zkXTA7yYaMeQlVrpW6z2DHM4KO/5/ZDxJtRJk4OCrBRysOfRp8QyBeNmIek1XmYCbqvG p4ag== X-Gm-Message-State: AOJu0Yzr4CLuwoz+Yj8cD6fgIp8WH1zFN/MWXhwIhg+MxOpnwyrInxVY 4BNd/jM+YTBFBzMQttlQhIbLsT2m5ef+sJmlA6L2LQ== X-Google-Smtp-Source: AGHT+IGlpaFEVbjQZyw51q+z5W4ZE3DAOlQQ4z1pvtOSFHeJ+sOaFH+nw30bfq5o2dJqOijwKaMRxQ== X-Received: by 2002:a5d:9943:0:b0:79f:9eb4:3ea1 with SMTP id v3-20020a5d9943000000b0079f9eb43ea1mr1020336ios.3.1696376149917; Tue, 03 Oct 2023 16:35:49 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:49 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Kyle Evans , Karim Taha , Richard Henderson Subject: [PULL 47/51] bsd-user: Implement shm_open(2) Date: Tue, 3 Oct 2023 17:32:11 -0600 Message-ID: <20231003233215.95557-48-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_NONE=0.001, T_SPF_HELO_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Co-authored-by: Kyle Evans Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-20-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 25 +++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index b296c5c6f0a..f8dc943c234 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -257,4 +257,29 @@ static inline abi_long do_obreak(abi_ulong brk_val) return target_brk; } +/* shm_open(2) */ +static inline abi_long do_bsd_shm_open(abi_ulong arg1, abi_long arg2, + abi_long arg3) +{ + int ret; + void *p; + + if (arg1 == (uintptr_t)SHM_ANON) { + p = SHM_ANON; + } else { + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + } + ret = get_errno(shm_open(p, target_to_host_bitmask(arg2, fcntl_flags_tbl), + arg3)); + + if (p != SHM_ANON) { + unlock_user(p, arg1, 0); + } + + return ret; +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 92793ab1fb3..0d4c3118f0d 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -843,6 +843,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_mincore(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_freebsd12_shm_open: /* shm_open(2) */ + ret = do_bsd_shm_open(arg1, arg2, arg3); + break; + #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); From patchwork Tue Oct 3 23:32:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA594E8FDC2 for ; Tue, 3 Oct 2023 23:37:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovy-0004nm-6e; Tue, 03 Oct 2023 19:36:10 -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 1qnovq-0004Vi-Af for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:02 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovg-0007Th-KU for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:58 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-79faba5fe12so57777939f.3 for ; Tue, 03 Oct 2023 16:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376151; x=1696980951; 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=MQsJ8aRx34rU+BSo16ILhtd0DDp2FIzYDvvE6gfNhKU=; b=C//SUph2bxxglbF/2VxlSQAGkIcHgj22gZ9INDaZgEx/JM5NO3kGJ8zZxhzSvNHo0N DCEJX39+IKuyJnq9FmFS71wDnkkR+/FQil8ZeDasLKDMaLpHMrimHAVgUiVjzRcYQlik qXqmYCPJddQzRBZcTkG0jQ0CMcY6M+FLjyySNuyaszXnl9yYNlg4nRbEMzr6GmjDkEQm aJGQl/QuYF0NP0G6d9034Eb4nMB6YlT50ESePbiE97OA6jXc0tfAByEsdOzKa1vKPnTE pPqlfpYUpaF5wTCNbw+IlG858esVsc+zZcuQCapKtTo2+zvYM81nkbBnlY1Aaj7u/FMG b8GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376151; x=1696980951; 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=MQsJ8aRx34rU+BSo16ILhtd0DDp2FIzYDvvE6gfNhKU=; b=da6rIaVvJ80lIcyvk05CdHEKpZUoahc5u/ngpIHGyYxCRQyqtCjXzM3HWWI1DQFpAk aJvQ55+ZZcCNrSe78ibKFHOmYkBUfwnP3QsNNo6TZ2TyNHdzoZCiQEyJlP2x9NC+ZEr0 5umg/pC5/a6qllv0Neo5GAeB146ShJZ/IuX9yyiiV70XXi3IXnSnERYmyrxhQZxJedeP I0lbu8E6RuJxLphDLZ0bUONxx3NuRlWd/+HJKa4HITA1UoX3k23osX62wCSYFTcx0hJ0 LLt6cKzFmifAfve5lVxRyoewvowU0+TUB5ccMWMyJiuRmrapbe9kwHW3WZ9/InupRv2X 9qpg== X-Gm-Message-State: AOJu0YzjzkCiJLXnkiauCTbuilUXdH8imdqNsWfdLOgI0Gs1S8SzX3a2 TyC43uSVPHiFKCZW+lBsAPyZBX1E2AdrFH7R3VImcA== X-Google-Smtp-Source: AGHT+IFO8VMixQfnBRpfHvBiTa0e3rYsXETfRm8ppcSf9j0Fwp71HyQvkUkP2dY6u/QmT4gTFfEqKA== X-Received: by 2002:a5d:9943:0:b0:79f:d194:d6e2 with SMTP id v3-20020a5d9943000000b0079fd194d6e2mr1054628ios.10.1696376150744; Tue, 03 Oct 2023 16:35:50 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:50 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 48/51] bsd-user: Implement shm_unlink(2) and shmget(2) Date: Tue, 3 Oct 2023 17:32:12 -0600 Message-ID: <20231003233215.95557-49-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-21-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 23 +++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index f8dc943c234..c362cc07a30 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -282,4 +282,27 @@ static inline abi_long do_bsd_shm_open(abi_ulong arg1, abi_long arg2, return ret; } +/* shm_unlink(2) */ +static inline abi_long do_bsd_shm_unlink(abi_ulong arg1) +{ + int ret; + void *p; + + p = lock_user_string(arg1); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(shm_unlink(p)); /* XXX path(p)? */ + unlock_user(p, arg1, 0); + + return ret; +} + +/* shmget(2) */ +static inline abi_long do_bsd_shmget(abi_long arg1, abi_ulong arg2, + abi_long arg3) +{ + return get_errno(shmget(arg1, arg2, arg3)); +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 0d4c3118f0d..4f67677eb92 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -859,6 +859,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, break; #endif + case TARGET_FREEBSD_NR_shm_unlink: /* shm_unlink(2) */ + ret = do_bsd_shm_unlink(arg1); + break; + + case TARGET_FREEBSD_NR_shmget: /* shmget(2) */ + ret = do_bsd_shmget(arg1, arg2, arg3); + break; + /* * Misc */ From patchwork Tue Oct 3 23:32:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4358E8FDBF for ; Tue, 3 Oct 2023 23:44:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovx-0004k2-05; Tue, 03 Oct 2023 19:36: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 1qnovq-0004Vk-BE for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:02 -0400 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovj-0007Tu-P5 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:59 -0400 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-79fa7e33573so58992439f.0 for ; Tue, 03 Oct 2023 16:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376151; x=1696980951; 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=5Vsuy4csP7DLV7i/HttRGs3+j2Bhu0vejsp7G9mGTsU=; b=M59Z5raogs6+TpWLVQ6iHPKjprtsTaUXch+tExhjU9GUHxCrfcS0ElL0nZPqVrS5te w1j5X2WzWchCv3tZ62B7UEpH8nSQ3XfFesp+J3gLhygioOzqUi5QauY72OuY3c4ImD7j lFbMSTMRSZIkwOOlnLvZ96SUozy2B1Ut79n5lyz/K5CGrku8QKgNIpvVmx53RgynaXtg 4JzrlrVfmADQAuWvLTfqM9R6tShJI+3d0oJSwT6qW0MEPmX3Dy690Ncx9xIsMaaykp08 PEsWyGQ7Jofw3uO4Fu0sTAtUAnTX25QxKQdTzuggZe2dK6lX59atdEIrT4WsXRLiQAqW MxPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376151; x=1696980951; 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=5Vsuy4csP7DLV7i/HttRGs3+j2Bhu0vejsp7G9mGTsU=; b=xACo9D8JXsI51B3gRBPgr/C/DU3dmwFLFsDtnRLv3e6JZ5Swy8ZFZaP3RfPgQP7nDi rF1cQvAoNCnsQMdDDERLhU0T0aXMCI7g/Zd1DAnYiymHNjhl2+2NTX3tI0/S/GbRf2V4 XjMWGFEJgTc/hbJV4eu6hGBGAR6u16r80nX39/4fbjreaJT0XgboOfdQQ8WgwGk4meQ8 twO81AwgDMAtycAnIX/96DmkFqUoA0RcvEJg3Eelh0Y0DDpCZ0/zcaGsaOdTWMD69gKc hGdtD/pBdrwFiPH8CNwTnQ9sFqMeRHd5OjQTfBqxRKus057Cdjv1Mi0cjur/15/RMSBf rUmw== X-Gm-Message-State: AOJu0YymOgwb++qCkmLZuFP/GQQms+yyAGl5dIvl6bP/EGnMeywQHf6q zYZhYIJxlvcfz5s40Y9cx7zQcra0O7kNC8CT5a6L3A== X-Google-Smtp-Source: AGHT+IFKM6vGvz5V+n5lUQ8G0tphd58TGHC6BBWwHIJMXox8P1sm8B9mdnB0Bl8PBb1CcY4B3xjyvQ== X-Received: by 2002:a5e:dd0d:0:b0:786:7100:72de with SMTP id t13-20020a5edd0d000000b00786710072demr895824iop.16.1696376151658; Tue, 03 Oct 2023 16:35:51 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:51 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha , Richard Henderson Subject: [PULL 49/51] bsd-user: Implement shmctl(2) Date: Tue, 3 Oct 2023 17:32:13 -0600 Message-ID: <20231003233215.95557-50-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-22-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 39 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index c362cc07a30..b82f3eaa253 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -305,4 +305,43 @@ static inline abi_long do_bsd_shmget(abi_long arg1, abi_ulong arg2, return get_errno(shmget(arg1, arg2, arg3)); } +/* shmctl(2) */ +static inline abi_long do_bsd_shmctl(abi_long shmid, abi_long cmd, + abi_ulong buff) +{ + struct shmid_ds dsarg; + abi_long ret = -TARGET_EINVAL; + + cmd &= 0xff; + + switch (cmd) { + case IPC_STAT: + if (target_to_host_shmid_ds(&dsarg, buff)) { + return -TARGET_EFAULT; + } + ret = get_errno(shmctl(shmid, cmd, &dsarg)); + if (host_to_target_shmid_ds(buff, &dsarg)) { + return -TARGET_EFAULT; + } + break; + + case IPC_SET: + if (target_to_host_shmid_ds(&dsarg, buff)) { + return -TARGET_EFAULT; + } + ret = get_errno(shmctl(shmid, cmd, &dsarg)); + break; + + case IPC_RMID: + ret = get_errno(shmctl(shmid, cmd, NULL)); + break; + + default: + ret = -TARGET_EINVAL; + break; + } + + return ret; +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 4f67677eb92..0512d41db7c 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -867,6 +867,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_shmget(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_shmctl: /* shmctl(2) */ + ret = do_bsd_shmctl(arg1, arg2, arg3); + break; + /* * Misc */ From patchwork Tue Oct 3 23:32:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B954E8FDC2 for ; Tue, 3 Oct 2023 23:43:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovy-0004nf-78; Tue, 03 Oct 2023 19:36:10 -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 1qnovq-0004Vj-Aq for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:02 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovl-0007U2-EN for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:35:59 -0400 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-79fe8986355so59690739f.2 for ; Tue, 03 Oct 2023 16:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376152; x=1696980952; 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=0xs6F3bQ3X0JBHAPx4Ith6fLrpCOwQaP480klykNHXU=; b=1jXBHGD/moKy7aVUCLb8K9wscR71p5HJndlfTLDp4jf5AORG6Grqq9ZJfZUtvJe/3g SLnvyw7LDJ2csQVUzqf8cBPrui4sDgTs7akMXyJRFQfRICT+Gh0C342bAX+rI9hTr3r4 jZgVIveKPTZJR8HDXXrH3EabMaOzYWa7VVPSqkPNoP6YYuNHJVdtIXSTMtGf8RDl7QbE ufIp5cCilPf6eZDgYNdyfIF3Z3xYaK/ZK1e7xPZkEbGDLVXh8b2ubHT/Xa4H23QlSOwP reqIPpMiKcS57m5GkfYrHHwbK0CqYVAh3/m3RUUZfxCPiah0f6681nUAz9K4Dmqk9GYV truw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376152; x=1696980952; 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=0xs6F3bQ3X0JBHAPx4Ith6fLrpCOwQaP480klykNHXU=; b=psTzFHjFsEKhNLwq5xMp/nb6QHB9Mp+n8ShDlvIPW021Lp6ytwfqPC2iif2sTDeJiu RNFKUeg+j7QnEdaE6P6b/kCazwfi2IJ5zsAVuHEfcZc7LNqwpoOaAmw/sw8+KOEwigeE dFhsW3Idgug1XM8zRUcMRdzx0BL305e2b2avX4s4lmvvSkdR0D2tKkG+76CxGz4CCD6d rCTT1ik/GikuQtRsc6ANvuOHZbF74gDxX6e6h44vP8wAgjK7bOum+NUt92iEsZqqPto6 BlW+HmUOOciwpOj0ekt6XdjVfWIF1VZkSuPUyi9gr0OwVG0pXJzDSU/Y2poVul7dP6KL v+7A== X-Gm-Message-State: AOJu0YxfmcseR/EijHX/SD4QeT2wZi8guwjAo9KB/Dw9nj98AKpeeOrg IMsh8Am4S4O6WgJ4fJ0+rVhnv7VfV8TbcdTcfq0miA== X-Google-Smtp-Source: AGHT+IF8WUqyCpk83nfDn3hIHdJ5tPbzsXtgSwyPH/X++I1YLXERXzMqlKkSrChUGOHxIMFHnMIY7w== X-Received: by 2002:a5e:8c15:0:b0:787:1472:3181 with SMTP id n21-20020a5e8c15000000b0078714723181mr1027873ioj.3.1696376152518; Tue, 03 Oct 2023 16:35:52 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:52 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Stacey Son , Karim Taha Subject: [PULL 50/51] bsd-user: Implement shmat(2) and shmdt(2) Date: Tue, 3 Oct 2023 17:32:14 -0600 Message-ID: <20231003233215.95557-51-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Use `WITH_MMAP_LOCK_GUARD` instead of mmap_lock() and mmap_unlock(), to match linux-user implementation, according to the following commits: 69fa2708a216df715ba5102a0f98468b540a464e linux-user: Use WITH_MMAP_LOCK_GUARD in target_{shmat,shmdt} ceda5688b650646248f269a992c06b11148c5759 linux-user: Fix shmdt Signed-off-by: Stacey Son Signed-off-by: Karim Taha Message-Id: <20230925182709.4834-23-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 87 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++ bsd-user/mmap.c | 2 +- bsd-user/qemu.h | 1 + 4 files changed, 97 insertions(+), 1 deletion(-) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index b82f3eaa253..c512a4e3756 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -344,4 +344,91 @@ static inline abi_long do_bsd_shmctl(abi_long shmid, abi_long cmd, return ret; } +/* shmat(2) */ +static inline abi_long do_bsd_shmat(int shmid, abi_ulong shmaddr, int shmflg) +{ + abi_ulong raddr; + abi_long ret; + struct shmid_ds shm_info; + + /* Find out the length of the shared memory segment. */ + ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); + if (is_error(ret)) { + /* Can't get the length */ + return ret; + } + + if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { + return -TARGET_EINVAL; + } + + WITH_MMAP_LOCK_GUARD() { + void *host_raddr; + + if (shmaddr) { + host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); + } else { + abi_ulong mmap_start; + + mmap_start = mmap_find_vma(0, shm_info.shm_segsz); + + if (mmap_start == -1) { + return -TARGET_ENOMEM; + } + host_raddr = shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + + if (host_raddr == (void *)-1) { + return get_errno(-1); + } + raddr = h2g(host_raddr); + + page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, + PAGE_VALID | PAGE_RESET | PAGE_READ | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); + + for (int i = 0; i < N_BSD_SHM_REGIONS; i++) { + if (bsd_shm_regions[i].start == 0) { + bsd_shm_regions[i].start = raddr; + bsd_shm_regions[i].size = shm_info.shm_segsz; + break; + } + } + } + + return raddr; +} + +/* shmdt(2) */ +static inline abi_long do_bsd_shmdt(abi_ulong shmaddr) +{ + abi_long ret; + + WITH_MMAP_LOCK_GUARD() { + int i; + + for (i = 0; i < N_BSD_SHM_REGIONS; ++i) { + if (bsd_shm_regions[i].start == shmaddr) { + break; + } + } + + if (i == N_BSD_SHM_REGIONS) { + return -TARGET_EINVAL; + } + + ret = get_errno(shmdt(g2h_untagged(shmaddr))); + if (ret == 0) { + abi_ulong size = bsd_shm_regions[i].size; + + bsd_shm_regions[i].start = 0; + page_set_flags(shmaddr, shmaddr + size - 1, 0); + mmap_reserve(shmaddr, size); + } + } + + return ret; +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 0512d41db7c..39e66312da1 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -871,6 +871,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_shmctl(arg1, arg2, arg3); break; + case TARGET_FREEBSD_NR_shmat: /* shmat(2) */ + ret = do_bsd_shmat(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_shmdt: /* shmdt(2) */ + ret = do_bsd_shmdt(arg1); + break; + /* * Misc */ diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 8e148a2ea3e..3ef11b28079 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -636,7 +636,7 @@ fail: return -1; } -static void mmap_reserve(abi_ulong start, abi_ulong size) +void mmap_reserve(abi_ulong start, abi_ulong size) { abi_ulong real_start; abi_ulong real_end; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 6047805ae38..dc842fffa7d 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -233,6 +233,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, int target_msync(abi_ulong start, abi_ulong len, int flags); extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); +void mmap_reserve(abi_ulong start, abi_ulong size); void TSA_NO_TSA mmap_fork_start(void); void TSA_NO_TSA mmap_fork_end(int child); From patchwork Tue Oct 3 23:32:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13408107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B859E8FDBF for ; Tue, 3 Oct 2023 23:37:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnovw-0004jR-UQ; Tue, 03 Oct 2023 19:36: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 1qnovs-0004X2-Al for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:04 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnovl-0007UD-Ef for qemu-devel@nongnu.org; Tue, 03 Oct 2023 19:36:02 -0400 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-79fce245bf6so58311539f.1 for ; Tue, 03 Oct 2023 16:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1696376153; x=1696980953; 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=8QWoVmGnb5jKyajwly1l0ccTXwxvqdiZY2ICtiENtz8=; b=gkjYgtDvyF0zIskyJuTyf1wGj2gNyW+qI5ogHfrGNbSXFstR9blxtfZKIczpxgBy8C AGljVIM20G1aaA3MN5IZZgc5vlPqxfLgFVvAVNl6vQVKTJ03KF05geYjm7p8A51eIb9b sUDTHWApUEolZHquRITvps+J5nPGRrc7Xr11E8TVQ2LsgUuZGavFUkt8uwGIoX+D8ALs /kUljWQjYPoloTsHJ+ick8ehK4RFCrPROAJ7ZEsvrmMHZL5XRyIMxyyFP01Bkrzvisb8 M92/+pDl0uB8f0du840dp7igcKsswy7ELokl9jKtsLVzN04/ijIxkYks/yDIQIr4QAQg ATFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696376153; x=1696980953; 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=8QWoVmGnb5jKyajwly1l0ccTXwxvqdiZY2ICtiENtz8=; b=ther5flVnUbEt7KhpXeeMoZgTsurNPfAv+crdJeiRjc8EdFfVXk9fTCdbqZ+5ScHaf RCsb4uCPQniNtGFGQdbs63zRZ0rO0MaXas0kGY3KKtz2lsrUT9e9KBi44F6DI8SV8n6d sRpNmAPCmtn1jGRpAjY7mFi/ic3ax163Veria4uM0fqU47Hrx7YOnmL34PaSMeqR5yRc 9lMQjEkLKAcYuhHy7Tu/q5j2qJcaJumONsB8PHMho/FqbunfvnspNZWK2xprnq713OxY dZF0pfreT9X7jwqnJaRa6yk/ir4hY8zPYLrJu+6XXVjynx0Kq+UJK6BEfK14QDVF+nln hpvw== X-Gm-Message-State: AOJu0Yz4AUQQBtdMBy5s4wWJ3Sg6m23hwUITX21QPaHdAS1AOjc//CRl 0T7ZrZeyZQpTiZLvFX57r2Dn1U4p2EDUbgsTdq6/GQ== X-Google-Smtp-Source: AGHT+IGpkD2xsr+rgxMVyqd7hKzw9lQxrbyv+l7sgWG+Q+Nt0Y3px9eKMI3FBNQmiBHE4HGgj+PMQg== X-Received: by 2002:a6b:dc0a:0:b0:795:12b0:c2a1 with SMTP id s10-20020a6bdc0a000000b0079512b0c2a1mr933073ioc.10.1696376153327; Tue, 03 Oct 2023 16:35:53 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id w25-20020a6b4a19000000b0079fa1a7cd36sm593596iob.30.2023.10.03.16.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:35:53 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Wainer dos Santos Moschetta , Beraldo Leal , Warner Losh , Kyle Evans , Karim Taha , Richard Henderson Subject: [PULL 51/51] bsd-user: Add stubs for vadvise(), sbrk() and sstk() Date: Tue, 3 Oct 2023 17:32:15 -0600 Message-ID: <20231003233215.95557-52-imp@bsdimp.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003233215.95557-1-imp@bsdimp.com> References: <20231003233215.95557-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2b; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The above system calls are not supported by qemu. Signed-off-by: Warner Losh Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Message-Id: <20230925182709.4834-24-kariem.taha2.7@gmail.com> --- bsd-user/bsd-mem.h | 18 ++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index c512a4e3756..c3e72e3b866 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -431,4 +431,22 @@ static inline abi_long do_bsd_shmdt(abi_ulong shmaddr) return ret; } +static inline abi_long do_bsd_vadvise(void) +{ + /* See sys_ovadvise() in vm_unix.c */ + return -TARGET_EINVAL; +} + +static inline abi_long do_bsd_sbrk(void) +{ + /* see sys_sbrk() in vm_mmap.c */ + return -TARGET_EOPNOTSUPP; +} + +static inline abi_long do_bsd_sstk(void) +{ + /* see sys_sstk() in vm_mmap.c */ + return -TARGET_EOPNOTSUPP; +} + #endif /* BSD_USER_BSD_MEM_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 39e66312da1..ca2f6fdb66e 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -879,6 +879,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_shmdt(arg1); break; + case TARGET_FREEBSD_NR_freebsd11_vadvise: + ret = do_bsd_vadvise(); + break; + + case TARGET_FREEBSD_NR_sbrk: + ret = do_bsd_sbrk(); + break; + + case TARGET_FREEBSD_NR_sstk: + ret = do_bsd_sstk(); + break; + /* * Misc */