From nobody Fri Oct 18 04:34:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694989493; cv=none; d=zohomail.com; s=zohoarc; b=dt0mZ42QCeOdCLtWp5q2PEnNVIVPy2H/xAy9RaxdNDpwcbKWzQ/Rv2BGuXmtXOzV21IMR0ctBX9Lysnz8gO+ERTOBkUxXUGvw9gwcuMhly4dOCpVc+jVroUxnFIZY/hgo7cFBFtVneMPE9wbrwn0bo3FDso4VNDYKIX8DgICO9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694989493; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mw8oJ6RJMLfyGngcXE7kSkbQnhvZ0mfQP6CsE/YxQqI=; b=jOsg5SyV8LhmR3GifGhuyZnzzmT+Kqo3TxRAn3nLRb2Jk02K1guuzD8txZF8To6zY1D0IpKAUFSzS9eXlqEW6SjFVko01r+FvRqHbks4f6JP0QSQC3MkayOXHI9GwnKEQ7VPmvE7WMOtwsj4NKb+kx5ib40KEw1HAwSDmtT85+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694989493535549.270887022252; Sun, 17 Sep 2023 15:24:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qi0C6-0006ff-3E; Sun, 17 Sep 2023 18:24: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 1qi0C4-0006ey-Ol for qemu-devel@nongnu.org; Sun, 17 Sep 2023 18:24:44 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qi0C3-0002yr-5d for qemu-devel@nongnu.org; Sun, 17 Sep 2023 18:24:44 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31f7400cb74so3427773f8f.2 for ; Sun, 17 Sep 2023 15:24:42 -0700 (PDT) Received: from karim.my.domain ([197.39.215.8]) by smtp.gmail.com with ESMTPSA id f7-20020adff987000000b0031c8a43712asm10652527wrr.69.2023.09.17.15.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 15:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989481; x=1695594281; 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=mw8oJ6RJMLfyGngcXE7kSkbQnhvZ0mfQP6CsE/YxQqI=; b=cIOih3pA1Xci/pxeSmNjtpubMGxCsGLqlmTyneQZAw2HEwctryU27awFSDBj3T30pM p/3gw9m3he9tAFhCv+IYN54uP98doT073brqB/OvV7+OjgG7JPbqSZQD05ivsv5GBG+l WaeuTna5QOAKGIunvfJezEhm5rA14utYv5FwPzy73jyWo53NF61rz3rBiD4CIYhOPHil qlJDUTumfoKWYPfI5D+fFh7YatlwLD0FV4FusdrCbqoGjUxg2GvSbIzY/ygvHp8X+DjZ 4mXCgtmzTxm0JL/20gC7IcdlIAFN/FM9YCTpB4Auo2xyMQ8OmB2diYMgd8aB8uqL5PUr 7Afw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694989481; x=1695594281; 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=mw8oJ6RJMLfyGngcXE7kSkbQnhvZ0mfQP6CsE/YxQqI=; b=YbPsDyglUbQPX7t7+K+3ur1UnCVKMCE648OnrFVBaAdBArXEGHRNiaYZXlH32TyNCD Pi9zVTMShJaFKZOD0v02JT4YFxz+EQH1h8WFZLE2C8VX2Z0Ckepw6r3jNJDb+J1kdNVv P+IUVhiGO2gradCJFgh7NhNbEWR4bi9PLnhFztQ6bavILo7VFeWmkAoUM8HNBG/o5AOM Zji0D7oufP++5yDirSSwSATvi33ORHdmI6MknHJzpsd0QfkTbZMsf3wvwEjP95c9xhFe x4p0aYVDA65+Q7r4RxE3Zb/J08BZSe0MwpmGFySchKAWE/bhICQZhja7a22i5zmQKdXW k88g== X-Gm-Message-State: AOJu0YyfJLRBInhFnYN8XAzZsdtlNbFmAWm7Hz7CjAcIByZg3YWd1yic C7bWUMV6cYPFdGpIgYF1JaRbCnUa6ZI= X-Google-Smtp-Source: AGHT+IF+G8VdYiZ8iqkIWwojTqGMATZ2pqg7P2MBu6dFL8igNNzVYeydKyDmql9K4h2T+6SwxIqjeg== X-Received: by 2002:a05:6000:1f9b:b0:31f:fb63:12d8 with SMTP id bw27-20020a0560001f9b00b0031ffb6312d8mr5090792wrb.44.1694989481363; Sun, 17 Sep 2023 15:24:41 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: Richard Henderson , imp@bsdimp.com, Stacey Son , Karim Taha Subject: [PATCH v3 27/28] bsd-user: Implement rfork(2) system call. Date: Mon, 18 Sep 2023 01:22:44 +0300 Message-ID: <20230917222246.1921-28-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230917222246.1921-1-kariem.taha2.7@gmail.com> References: <20230917222246.1921-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x434.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694989495091100007 Content-Type: text/plain; charset="utf-8" From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 23b2f77a73..6121af9efd 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -212,4 +212,43 @@ static inline abi_long do_freebsd_vfork(void *cpu_env) return do_freebsd_fork(cpu_env); } =20 +/* rfork(2) */ +static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) +{ + abi_long ret; + abi_ulong child_flag; + + /* + * XXX We need to handle RFMEM here, as well. Neither are safe to exe= cute + * as-is on x86 hosts because they'll split memory but not the stack, + * wreaking havoc on host architectures that use the stack to store the + * return address as both threads try to pop it off. Rejecting RFSPAWN + * entirely for now is ok, the only consumer at the moment is posix_sp= awn + * and it will fall back to classic vfork(2) if we return EINVAL. + */ + if ((flags & TARGET_RFSPAWN) !=3D 0) { + return -TARGET_EINVAL; + } + fork_start(); + ret =3D rfork(flags); + if (ret =3D=3D 0) { + /* child */ + child_flag =3D 1; + target_cpu_clone_regs(cpu_env, 0); + } else { + /* parent */ + child_flag =3D 0; + } + + /* + * The fork system call sets a child flag in the second return + * value: 0 for parent process, 1 for child process. + */ + set_second_rval(cpu_env, child_flag); + fork_end(child_flag); + + return ret; + +} + #endif /* BSD_USER_FREEBSD_OS_PROC_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index cb9425c9ba..4c4e773d1d 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -234,6 +234,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, ret =3D do_freebsd_vfork(cpu_env); break; =20 + case TARGET_FREEBSD_NR_rfork: /* rfork(2) */ + ret =3D do_freebsd_rfork(cpu_env, arg1); + break; + case TARGET_FREEBSD_NR_execve: /* execve(2) */ ret =3D do_freebsd_execve(arg1, arg2, arg3); break; --=20 2.42.0