From nobody Sun Feb 8 13:13:16 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1654956104; cv=none; d=zohomail.com; s=zohoarc; b=bzA9kik6U7IcT7lupZkdnZG0pJd7hRmlLupaV/fq15gYPMUhY9BLwtJuvloCHuKX6Lk78Ui9eJ0RpVLvWpweEQxYqacXIR/kL+Qe/OSLeTSJ/cQ/LnCBrVhsmi454wzTXpAeojQ+mgRG12qEgtjpWRur4adNg4mkXHka2ZrgUt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654956104; 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=UU9aKWHmya49MhhlUASZM5Nfo6AfFU5F7b0DJrVDkxg=; b=jn5eSd/s+92RYtq6eC8xsDdCeKcG2A3lttbpHnxybWEAtMyFewVQHSPpn55eLp3Hde220LSH+rf1UXBosYa95g61EVDVT1mBC6gnjk5A+/i5ZXBfeoTYo5UVJJRtCy/Tavzg/svdlt/fI1f42LUMdSCSgwAzeQ92FWC3ykvZOJ4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654956104727713.6463466309416; Sat, 11 Jun 2022 07:01:44 -0700 (PDT) Received: from localhost ([::1]:49410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o01gN-0006ec-7n for importer@patchew.org; Sat, 11 Jun 2022 10:01:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o01a0-0006ey-3D for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:08 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]:33494) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o01Zw-0003ch-SU for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:06 -0400 Received: by mail-io1-xd2b.google.com with SMTP id p69so1736218iod.0 for ; Sat, 11 Jun 2022 06:55:03 -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 13-20020a056e0211ad00b002d781cc0875sm1023578ilj.29.2022.06.11.06.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 06:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UU9aKWHmya49MhhlUASZM5Nfo6AfFU5F7b0DJrVDkxg=; b=jeTjFfVKQ7Z1YFM/IBhvxYXSRj4QExYiN8gpQHVf16BU0ViXwCbCyNyTWFnooze2uQ etpQlbrtva16ORwl2ZGOKy7hsk+7UAcK9LS39FNAyg7SYsTsXR1aEy0N0lCTOD2E7+93 ikOUOsNZ4jeGlpvlzozNh7Uny3Lci8wLdUWgiKdGsUzP+sgv3rg1zM31JyJUDC/NSbUk iqGkiMDjiNjFylIJSvZUlG0/T25g0H/ZQ8R3/uN9Rag6ZmHg2iIV1vcGxVG5Kh3ccYJZ OKV0FleFDeBJldzL2AvgCC6ife+MzE3Hd3Mp3gtO9pT/G/LsBpHMGDEfWT88+NvKCl7v 634A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UU9aKWHmya49MhhlUASZM5Nfo6AfFU5F7b0DJrVDkxg=; b=VI8G5A1LSZpdpW1wFli3jlsjXSxtPCHGv/Kfro9ueBD65oItStie880sdWzevc2STQ DD4PqgrtMX0M9BHFSoaMAzDfwgz58PnQAJMrtRsvN6G9y5AHL1vuiOk2Eyq2OJ4Y0Ix6 1b0ca3UDCWrEZJtdIi3cupbrhfnv5uZ/g+7PxF9rynxSoqk1I5dLS0AAOiXmghTy90dY Rf1HVPv9xsi4tJ9fKHpn3vJ+nGsKkAu0LVAHm5wF7hUVBQ2ZtBg1z7uvD2eqqyNquV93 A2QidscDDdEXBqciaWfR2Ip8dw/89MQXnku44d9cxJ7sJ+Tg2k1HrsmMapROkdoJ3EbL 73nA== X-Gm-Message-State: AOAM532lzo2iBUY3XGxo4asX275dV/XIG6FrUUB/D4Gwycf1kNmuo/Tf rADVduuUjs7RYLolGDFIOo4hDQP/20LTRQ== X-Google-Smtp-Source: ABdhPJyTKAEAMZA9bBCQksaNPSR3VJovv0gBF1Qv15LZ66Sj5nGMk8sZVcy3XLpEJK1/i5e16C8BjQ== X-Received: by 2002:a05:6638:389f:b0:331:b463:fbee with SMTP id b31-20020a056638389f00b00331b463fbeemr16994839jav.145.1654955702769; Sat, 11 Jun 2022 06:55:02 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: def@freebsd.org, arrowd@freebsd.org, Kyle Evans , Warner Losh , jrtc27@FreeBSD.org, Richard Henderson Subject: [PULL 1/6] bsd-user/freebsd/os-syscall.c: lock_iovec Date: Sat, 11 Jun 2022 07:55:09 -0600 Message-Id: <20220611135514.92882-2-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220611135514.92882-1-imp@bsdimp.com> References: <20220611135514.92882-1-imp@bsdimp.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: 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, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1654956105409100001 Content-Type: text/plain; charset="utf-8" lock_iovec will lock an I/O vec and the memory to which it refers and create a iovec in the host space that refers to it, with full error unwinding. Add helper_iovec_unlock to unlock the partially locked iovec in case there's an error. The code will be used in iovec_unlock when that is committed. Note: memory handling likely could be rewritten to use q_autofree. That will be explored in the future since what we have now works well enough. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index d272478e7b0..67851937a8f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -73,6 +73,108 @@ bool is_error(abi_long ret) return (abi_ulong)ret >=3D (abi_ulong)(-4096); } =20 +/* + * Unlocks a iovec. Unlike unlock_iovec, it assumes the tvec array itself = is + * already locked from target_addr. It will be unlocked as well as all the= iovec + * elements. + */ +static void helper_unlock_iovec(struct target_iovec *target_vec, + abi_ulong target_addr, struct iovec *vec, + int count, int copy) +{ + for (int i =3D 0; i < count; i++) { + abi_ulong base =3D tswapal(target_vec[i].iov_base); + + if (vec[i].iov_base) { + unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0); + } + } + unlock_user(target_vec, target_addr, 0); +} + +struct iovec *lock_iovec(int type, abi_ulong target_addr, + int count, int copy) +{ + struct target_iovec *target_vec; + struct iovec *vec; + abi_ulong total_len, max_len; + int i; + int err =3D 0; + + if (count =3D=3D 0) { + errno =3D 0; + return NULL; + } + if (count < 0 || count > IOV_MAX) { + errno =3D EINVAL; + return NULL; + } + + vec =3D g_try_new0(struct iovec, count); + if (vec =3D=3D NULL) { + errno =3D ENOMEM; + return NULL; + } + + target_vec =3D lock_user(VERIFY_READ, target_addr, + count * sizeof(struct target_iovec), 1); + if (target_vec =3D=3D NULL) { + err =3D EFAULT; + goto fail2; + } + + max_len =3D 0x7fffffff & MIN(TARGET_PAGE_MASK, PAGE_MASK); + total_len =3D 0; + + for (i =3D 0; i < count; i++) { + abi_ulong base =3D tswapal(target_vec[i].iov_base); + abi_long len =3D tswapal(target_vec[i].iov_len); + + if (len < 0) { + err =3D EINVAL; + goto fail; + } else if (len =3D=3D 0) { + /* Zero length pointer is ignored. */ + vec[i].iov_base =3D 0; + } else { + vec[i].iov_base =3D lock_user(type, base, len, copy); + /* + * If the first buffer pointer is bad, this is a fault. But + * subsequent bad buffers will result in a partial write; this= is + * realized by filling the vector with null pointers and zero + * lengths. + */ + if (!vec[i].iov_base) { + if (i =3D=3D 0) { + err =3D EFAULT; + goto fail; + } else { + /* + * Fail all the subsequent addresses, they are already + * zero'd. + */ + goto out; + } + } + if (len > max_len - total_len) { + len =3D max_len - total_len; + } + } + vec[i].iov_len =3D len; + total_len +=3D len; + } +out: + unlock_user(target_vec, target_addr, 0); + return vec; + +fail: + helper_unlock_iovec(target_vec, target_addr, vec, i, copy); +fail2: + g_free(vec); + errno =3D err; + return NULL; +} + /* * do_syscall() should always have a single exit point at the end so that * actions, such as logging of syscall results, can be performed. All err= nos --=20 2.33.1 From nobody Sun Feb 8 13:13:16 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1654955871; cv=none; d=zohomail.com; s=zohoarc; b=Toy7EvbTE4knnhSANeBdNZE2wTWPlXJwXUlGiyYuVSdaXnvPcB46Oi85MJUC52cvNnr6A3BV1nVFVXu2gyuiM3yRiJlsBLn8Tb8JRnERMqBhmQfrjeOkPHhQh2mjxXYq5+Wa63FSpMyTCl0mQLZj7evGbcHRW2XOPaXDirQl3ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654955871; 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=NI+N2VEe5Mw6h4lhur+4hOroAOpLSh2NXyD5ov8MTCU=; b=ip/W+1g+6BTuL7noV3HH9/tsXSYwAqy7VI/ElcETMS1etBBSpQjVIHScQrrkq+H0gQY8LGKUPD9svRNNtmZmwV9EpfaALkH8WHg/+JoDr9vsb13ji/DOXlj9v+R2KJ7Alcqlh+DTYq+MdVkjwx0rZf3+aGG+aRLYiaZVrB5IWrk= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654955870595750.581521575416; Sat, 11 Jun 2022 06:57:50 -0700 (PDT) Received: from localhost ([::1]:43082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o01cb-0002LC-4S for importer@patchew.org; Sat, 11 Jun 2022 09:57:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o01a0-0006ef-27 for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:08 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]:45630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o01Zx-0003dl-41 for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:07 -0400 Received: by mail-il1-x12d.google.com with SMTP id a15so1195183ilq.12 for ; Sat, 11 Jun 2022 06:55:04 -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 13-20020a056e0211ad00b002d781cc0875sm1023578ilj.29.2022.06.11.06.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 06:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NI+N2VEe5Mw6h4lhur+4hOroAOpLSh2NXyD5ov8MTCU=; b=MmUQpy7qlxYRBj1BeWoiSN9UHypkjw8Txve7YAowYpAkTbKFgQ3P6mv6TzhTF60sQQ /G9slimQATZ+8VtQH4Vjk0HYVRMvl1iCghWaDJ/eNarZ4OLfX0C5cNWvonkjDrs2IQE0 iQYRVxu3UbbrNaLWi2rIHLYyedbUeiKK/8DnhiNJuGWl328xgpShbtyQQiLxk/DIBC4I Su4AiD2CVRbH4Chc0tX1Ok3z0pgJAGFlqOwIdYG54BJTmjasipy6AtMoGcHZOVvrGr15 3XwpsLSlCqO3q24vySpKyLBr0Hxpqm/7a5I+T5zvj7dTeNvYrT4+NZsMNwa6Po4YQQI1 qJ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NI+N2VEe5Mw6h4lhur+4hOroAOpLSh2NXyD5ov8MTCU=; b=ktVA4gBw8bU3GZZqmwUZiSo7lO31U0rRTL1WY9hoEkNmKKZNwmtLPhF+rI1IKScgAZ UHey4Hpe6OBKEY62hV4UWsNxD0oEPMv+OipwkZX6ZM8rDULIqd0SX4b7u6+BTfES9woG loUoo/qcAFMhquT2JEp74CHTnIfiIPb4sqhd4J0UnSOapHXHYs2m/dRJMPWuf91sYWQX qiwagAd/oytWOCKJ0grVh+W1u2yBWcX1u/rI01+mXMkoED+x25HRx1+qYFjdZ9YD4pWP so8kZJ/DQOkCbBST4Ont2xNY+cojotJGVJtDDmk70daX/6HfcatJah7Lbr6abfLl/aw1 totA== X-Gm-Message-State: AOAM532khR1yrsaYQspfL1ei2tH853R4BDt/GoR1QAslGEUsIJzJqSZb Gnwjf+NIgCuRmdQ/QIEac2A+Bip9rAkPlA== X-Google-Smtp-Source: ABdhPJx38y7gDYzZwLzIjo68YtphO7o4ZAyQufWo8DsSQ+kwSiiBRZp8x956uGG6kLef/RMILwHIFA== X-Received: by 2002:a05:6e02:1a0e:b0:2d3:f72e:eaf1 with SMTP id s14-20020a056e021a0e00b002d3f72eeaf1mr26152369ild.260.1654955703732; Sat, 11 Jun 2022 06:55:03 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: def@freebsd.org, arrowd@freebsd.org, Kyle Evans , Warner Losh , jrtc27@FreeBSD.org, Richard Henderson Subject: [PULL 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec Date: Sat, 11 Jun 2022 07:55:10 -0600 Message-Id: <20220611135514.92882-3-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220611135514.92882-1-imp@bsdimp.com> References: <20220611135514.92882-1-imp@bsdimp.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: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.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, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1654955872406100001 Content-Type: text/plain; charset="utf-8" Releases the references to the iovec created by lock_iovec. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 67851937a8f..52093d479d8 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -175,6 +175,20 @@ fail2: return NULL; } =20 +void unlock_iovec(struct iovec *vec, abi_ulong target_addr, + int count, int copy) +{ + struct target_iovec *target_vec; + + target_vec =3D lock_user(VERIFY_READ, target_addr, + count * sizeof(struct target_iovec), 1); + if (target_vec) { + helper_unlock_iovec(target_vec, target_addr, vec, count, copy); + } + + g_free(vec); +} + /* * do_syscall() should always have a single exit point at the end so that * actions, such as logging of syscall results, can be performed. All err= nos --=20 2.33.1 From nobody Sun Feb 8 13:13:16 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1654956051; cv=none; d=zohomail.com; s=zohoarc; b=LpLEFEJPFrUCVnRjUA2dFbJ3rQE6InNbYK+yzAhLx1VnUxMcgU23VJGEeV14hRLKWDnUPWEaxByUwf8lor++uyzNk0c5e6SQaR5JptNi8RVok/JG5QlYvB7e+YN5/Z7Q6ZAvGeajCtSit2Z6dlN72SDeKvIkhAZSBY0cRBH0qVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654956051; 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=RHJEYVxUrkFuENo0R0EF9MoWMsEaIiFo82F16iYg1f0=; b=mmg8ykcVRWfxcySleHDbIMWaT4o2rPYG6hMXgPZDEacspwDPFJ347+Yb7gZtF60xdYsvIKcX9w4MgWMRCeQ6iuwGHv8EymXbxjEJSaiJ8+25Kl4yvK8jVhRA0D1BlzMV1St+nV43SbhBe38tpAgneBZWB31XFJTErAbX/BGk6kw= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654956051435711.4160320458369; Sat, 11 Jun 2022 07:00:51 -0700 (PDT) Received: from localhost ([::1]:48428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o01fW-0005xL-0s for importer@patchew.org; Sat, 11 Jun 2022 10:00:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o01aA-0006wm-M1 for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:20 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:45860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o01a9-0003gS-4E for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:18 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 184so1635349pga.12 for ; Sat, 11 Jun 2022 06:55: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 13-20020a056e0211ad00b002d781cc0875sm1023578ilj.29.2022.06.11.06.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 06:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RHJEYVxUrkFuENo0R0EF9MoWMsEaIiFo82F16iYg1f0=; b=xN+JfCnVgcJ8WoAuiEnBv9Qx/FVUeFMz+ZdJQQXHiiS+rJgo5+UZpqI8qx1SXFrZNM kiStN2IPu+cR2mWZgsstuTNzpughOBPW9pRonZrj3c45vpZCtLYyuOQS8rgxRdSR3yBr PtibErKBQHtFSYbSW02Yuw+rZTcwiOQKwWdA43iAEJP35Wn57F9bisYkrB7O0AJbDXXT fjJQhFNue91i2r4JgIgRVHCH3BzkLR0i6r7UiYL/Rx9SSvd+JuhV0jcLSA2kGLLc0dcE /is0uAibVG4KGOsmHGzziB4eurOAtdsupK51kfDoVoVxC4UDdmdQg3Zrw0wEsQcEoZfn IrMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RHJEYVxUrkFuENo0R0EF9MoWMsEaIiFo82F16iYg1f0=; b=RkctlHm0CFd+sBlaSPqYHSFSAJBIYjziYw/vYoHD4RQRCih16ZgBqeKZ//mcqVUbAd 1iMvwaFIGnmqOBliuskBh2m77VluD9MGLr5614zhdm/OYFNv7ELbDivPQ8mcnYjlrsCh aW6zN7tvP5FJOkVIIG1noJmzwtBhzXP1qO7DoaXpfFj7IswT1C8mmYZ6YVXFfzcVKJNB x2PR21foQEflTalwJTA5NoX2OZRLj2yMiaV1DKJg1mPQgvzpdHGLc6sxJvSDrqbS6rFH qVRUiWgx7lEzrAJzNYYfmiH1YUpDpcZOylQ1wGXriSlvf6NoVnfNDpoNGjqwYwX+easO zdiw== X-Gm-Message-State: AOAM530f+wGDRf7q78qYSJZG//9mIWUwkWBFARAy95PA18fruOhlbXZR V0B2M6LUXdne/P4dJ03Lz7LHwy9YvuAbCA== X-Google-Smtp-Source: ABdhPJyV5UffgGEcpn6Q/Y+QUhmjhv6Eq854q+wRT9W8aGXw/3yrdSGPBM/Crs68TM29CTzyYWtUfg== X-Received: by 2002:a05:6e02:78a:b0:2d3:af3f:a9e2 with SMTP id q10-20020a056e02078a00b002d3af3fa9e2mr28223957ils.96.1654955704707; Sat, 11 Jun 2022 06:55:04 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: def@freebsd.org, arrowd@freebsd.org, Kyle Evans , Warner Losh , jrtc27@FreeBSD.org, Richard Henderson Subject: [PULL 3/6] bsd-user/freebsd/os-syscall.c: Tracing and error boilerplate Date: Sat, 11 Jun 2022 07:55:11 -0600 Message-Id: <20220611135514.92882-4-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220611135514.92882-1-imp@bsdimp.com> References: <20220611135514.92882-1-imp@bsdimp.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: none client-ip=2607:f8b0:4864:20::52c; envelope-from=imp@bsdimp.com; helo=mail-pg1-x52c.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, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1654956053144100001 Content-Type: text/plain; charset="utf-8" Add in the tracing and this system call not implemented boilerplate. Do this by moving the guts of do_freebsd_syscall to freebsd_syscall. Put the tracing in the wrapper function. Since freebsd_syscall is a singleton static function, it will almost certainly be inlined. Fix comments that referred to do_syscall since that was renamed some tie ago. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 44 +++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 52093d479d8..1c4c9983f1a 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -190,16 +190,52 @@ void unlock_iovec(struct iovec *vec, abi_ulong target= _addr, } =20 /* - * do_syscall() should always have a single exit point at the end so that - * actions, such as logging of syscall results, can be performed. All err= nos - * that do_syscall() returns must be -TARGET_. + * All errnos that freebsd_syscall() returns must be -TARGET_. + */ +static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg= 4, + abi_long arg5, abi_long arg6, abi_long arg= 7, + abi_long arg8) +{ + abi_long ret; + + switch (num) { + default: + qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); + ret =3D -TARGET_ENOSYS; + break; + } + + return ret; +} + +/* + * do_freebsd_syscall() should always have a single exit point at the end = so + * that actions, such as logging of syscall results, can be performed. This + * as a wrapper around freebsd_syscall() so that actually happens. Since + * that is a singleton, modern compilers will inline it anyway... */ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, abi_long arg8) { - return 0; + CPUState *cpu =3D env_cpu(cpu_env); + int ret; + + trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,= arg7, arg8); + if (do_strace) { + print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); + } + + ret =3D freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, ar= g6, + arg7, arg8); + if (do_strace) { + print_freebsd_syscall_ret(num, ret); + } + trace_guest_user_syscall_ret(cpu, num, ret); + + return ret; } =20 void syscall_init(void) --=20 2.33.1 From nobody Sun Feb 8 13:13:16 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1654956282; cv=none; d=zohomail.com; s=zohoarc; b=GzxX+QSxzPoWMT9oiXnjiZa6KCOum4VTSAMsHQUK4JAKYuLnsdpZFis0/lpZDx5iANFKGo6iA0IGKAiKkYGMosVHSEA2eM2CVQ9Is4TXY5lKpxfPNDioE6XWTb0qB5w/wjGiKVRPY7xUyL5lwaIjRxSTNJhM2G4TltkYy8BGcGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654956282; 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=lPQvWCRF9x4tBhbiUr+oPIK02WOly+4GntZznQgs7g8=; b=cnnSKKZql+uXpLOFwYBQuqx2W3l7EdWROmmC2pWGoc+HHbaxqTGjci5JxiuvBY7U1dcUQ7qC+6XHLCGu8JGMJ4EydLi/pyP9ubFXqSk1B4JitLJZ18rMRmHPaNRiaHkXbPciaw52QH6uBb4V/IyviJ3Mlt8lbrQj9pp0cGIuOi4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654956282616573.0002703623992; Sat, 11 Jun 2022 07:04:42 -0700 (PDT) Received: from localhost ([::1]:53220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o01jE-00011s-ML for importer@patchew.org; Sat, 11 Jun 2022 10:04:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o01a1-0006fv-SM for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:10 -0400 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]:43898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o01Zz-0003fF-Qb for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:09 -0400 Received: by mail-il1-x12e.google.com with SMTP id h7so1207377ila.10 for ; Sat, 11 Jun 2022 06:55:06 -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 13-20020a056e0211ad00b002d781cc0875sm1023578ilj.29.2022.06.11.06.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 06:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lPQvWCRF9x4tBhbiUr+oPIK02WOly+4GntZznQgs7g8=; b=EghbDpqb1OwBHR/TZTZtgoi1QFzIegmUPn4rQwOm4VFnl5EYPo4OgJqeUEa2woGhbE Kz1fxsSGhfXG09ZboEumirMXJvORmrOs9RR/NU/zoBeMGutp16TJdQ7a/BuzrwrQ4s9k nMUz1SRmWvaR6mgCYBegVhAeHX0HvoezVy6lj4KSHncMTqAPg0K7fOij9x9khS8PS/wY nsltBAQAQ2s443EdZ6R8B5ceeUsRcn7YK8om6kZSbEIhErJcAosHPyNdUztb09tFIE2y y0twrTErk8ahsg/DX/wFvTO/H1kI6e+Lp/r6MAQYvql0RIyZo8WK22Uswg9+yUoZk0Bd fmLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lPQvWCRF9x4tBhbiUr+oPIK02WOly+4GntZznQgs7g8=; b=LY438sjTv4kXNIljfXIJgvn1lACD9cBWjo5IPXemOJGEzjaNARhhOzy65l7w4vSG3I hf+fWlwMhDelOnClN4evx+C0uyh3NrnjZFkpNeTDELgL+TCpGEzRBKUJ0D4K5FcQjjE0 /D6c2RBGvLis0LZWUyjlDkOXX8OykN3pvf2T7GQenpJl0P7WYYblZLT61wJeN/x31bcL l3YL1EiOWak0m6D/McU+t1idLP+VFbHXHVmpi74FNvmZvW2BYSHDrGbld/ZJVpGJzXyr 7IG+h2e5mbHXK/XNmcGRrHxBm/KNap1OZ5lalA4bcUb8r0fmMgEFHNqjvFjwSjYvbGG0 G8fQ== X-Gm-Message-State: AOAM530VJP9aSKjY3SUqUlJuShJEXImspbuvyPD92eUeajxIJDBQuLSq xj8kYIKY295DH2qxO2pqj1CNu37MEOSo6g== X-Google-Smtp-Source: ABdhPJw04/yPitLbtW68mvv8aly4PA+Maq9DzDdU5OQK20sGMEfloFfs69YEKXyOehEjsJ66Vfyo7g== X-Received: by 2002:a05:6e02:4a1:b0:2d3:a778:f0f1 with SMTP id e1-20020a056e0204a100b002d3a778f0f1mr28494619ils.212.1654955705515; Sat, 11 Jun 2022 06:55:05 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: def@freebsd.org, arrowd@freebsd.org, Kyle Evans , Warner Losh , jrtc27@FreeBSD.org, Stacey Son , Kyle Evans , Richard Henderson Subject: [PULL 4/6] bsd-user/bsd-file.h: Add implementations for read, pread, readv and preadv Date: Sat, 11 Jun 2022 07:55:12 -0600 Message-Id: <20220611135514.92882-5-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220611135514.92882-1-imp@bsdimp.com> References: <20220611135514.92882-1-imp@bsdimp.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: none client-ip=2607:f8b0:4864:20::12e; envelope-from=imp@bsdimp.com; helo=mail-il1-x12e.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, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1654956284268100001 Content-Type: text/plain; charset="utf-8" Implement do_bsd_{read,pread,readv,preadv}. Connect them to the system call table. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsd-file.h | 79 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 28 +++++++++++++ 2 files changed, 107 insertions(+) diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h index a6bff3b8c26..839f8c5c55a 100644 --- a/bsd-user/bsd-file.h +++ b/bsd-user/bsd-file.h @@ -27,4 +27,83 @@ extern struct iovec *lock_iovec(int type, abi_ulong targ= et_addr, int count, extern void unlock_iovec(struct iovec *vec, abi_ulong target_addr, int cou= nt, int copy); =20 +ssize_t safe_read(int fd, void *buf, size_t nbytes); +ssize_t safe_pread(int fd, void *buf, size_t nbytes, off_t offset); +ssize_t safe_readv(int fd, const struct iovec *iov, int iovcnt); +ssize_t safe_preadv(int fd, const struct iovec *iov, int iovcnt, off_t off= set); + +/* read(2) */ +static abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) +{ + abi_long ret; + void *p; + + p =3D lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(safe_read(arg1, p, arg3)); + unlock_user(p, arg2, ret); + + return ret; +} + +/* pread(2) */ +static abi_long do_bsd_pread(void *cpu_env, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) +{ + abi_long ret; + void *p; + + p =3D lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + if (regpairs_aligned(cpu_env) !=3D 0) { + arg4 =3D arg5; + arg5 =3D arg6; + } + ret =3D get_errno(safe_pread(arg1, p, arg3, target_arg64(arg4, arg5))); + unlock_user(p, arg2, ret); + + return ret; +} + +/* readv(2) */ +static abi_long do_bsd_readv(abi_long arg1, abi_long arg2, abi_long arg3) +{ + abi_long ret; + struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 0); + + if (vec !=3D NULL) { + ret =3D get_errno(safe_readv(arg1, vec, arg3)); + unlock_iovec(vec, arg2, arg3, 1); + } else { + ret =3D -host_to_target_errno(errno); + } + + return ret; +} + +/* preadv(2) */ +static abi_long do_bsd_preadv(void *cpu_env, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) +{ + abi_long ret; + struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 1); + + if (vec !=3D NULL) { + if (regpairs_aligned(cpu_env) !=3D 0) { + arg4 =3D arg5; + arg5 =3D arg6; + } + ret =3D get_errno(safe_preadv(arg1, vec, arg3, target_arg64(arg4, = arg5))); + unlock_iovec(vec, arg2, arg3, 0); + } else { + ret =3D -host_to_target_errno(errno); + } + + return ret; +} + #endif /* BSD_FILE_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 1c4c9983f1a..8ca92f29857 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -42,6 +42,14 @@ =20 #include "bsd-file.h" =20 +/* I/O */ +safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes); +safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t, + offset); +safe_syscall3(ssize_t, readv, int, fd, const struct iovec *, iov, int, iov= cnt); +safe_syscall4(ssize_t, preadv, int, fd, const struct iovec *, iov, int, io= vcnt, + off_t, offset); + void target_set_brk(abi_ulong new_brk) { } @@ -200,6 +208,26 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, abi_long ret; =20 switch (num) { + + /* + * File system calls. + */ + case TARGET_FREEBSD_NR_read: /* read(2) */ + ret =3D do_bsd_read(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_pread: /* pread(2) */ + ret =3D do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + + case TARGET_FREEBSD_NR_readv: /* readv(2) */ + ret =3D do_bsd_readv(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_preadv: /* preadv(2) */ + ret =3D do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret =3D -TARGET_ENOSYS; --=20 2.33.1 From nobody Sun Feb 8 13:13:16 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1654955829; cv=none; d=zohomail.com; s=zohoarc; b=Sl/B8PFN6Y72d8lrRwwSL0KNSnRzB4kEnNS5cAEj1Tm/Vl6KM/ZnZ1UrO0Fg+YoNvs6o0D9JCPaJwHK4CHXqBV6eN7pfE/B85jGYyZGc8vhKpRIpkMt8KbpojmNYE4O/DmZZXGxzHzMknpSo1UghjeRC2TVdOuvIrzYJSvRpbMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654955829; 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=kDCDikbK+UpGPr1ge2ks5QcyEZLLDVVWAIfJzK+cOk0=; b=XhsEk+kR7TUgTB/OFOsqlndAVo9A1XalHI2C4Mb3Ucog3FAaVz4nVfmVWvmcSv2aiGXXWd002r6LGc09b5ynQHo0l/AVc+lNCIvgEcW0ZS+So6fjs3J1q2EieXC7G2dPpc4TkPJBzQyluL4cNGUzktvl52ATWu0CnE6Nxy2LBT0= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654955828970475.81787787761573; Sat, 11 Jun 2022 06:57:08 -0700 (PDT) Received: from localhost ([::1]:41188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o01bv-00015p-W3 for importer@patchew.org; Sat, 11 Jun 2022 09:57:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o01a2-0006g4-31 for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:10 -0400 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:36600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o01a0-0003fP-Cu for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:09 -0400 Received: by mail-io1-xd31.google.com with SMTP id e80so1697104iof.3 for ; Sat, 11 Jun 2022 06:55: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 13-20020a056e0211ad00b002d781cc0875sm1023578ilj.29.2022.06.11.06.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 06:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kDCDikbK+UpGPr1ge2ks5QcyEZLLDVVWAIfJzK+cOk0=; b=a9zu9EPgEPaCCe9yHulmldrgARhqPLY414aPzR11UONWyMuST+JZZCFMiu2k8epMU6 CXeedewMlbV+7bpy11IPdXnJLSdBkW7SWZOcwh5Jys3TACaYY0fsVSNhwYzy7rULX8Pr eQc3ORU7iJ92oV8/yyyKO1+YInkZ3UfjUggyoCiWQtZLFRKCWZzBUKMfpICqHNLEo4Ze g46FshwHSnlLg35Ab+EfhXY47Ct/zsAVXvaeH2AT9YqMe4QhIVMCyMOPeDkdxLPvdcr1 ed+9q+mqxg3B3Qccu+HbFd4wH1OD2Tnh6fkBE7XXQkSC2/zvNv1+cw7qZeCvs0Qan4kq /3zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kDCDikbK+UpGPr1ge2ks5QcyEZLLDVVWAIfJzK+cOk0=; b=6p166YlfKsOuGhOZRjgORerO88cOx/IBkBeljbxS03mgr8z1P9Xx5OSBbSLvFLBny1 h+68ivV6UelW7aCYavc8Pkp36yCjCERz8K7yEKoDKJM3syJGqcoVCqEVH9/jpdTmVkEf HXBwbGnO0z0j/PbGYf/c0tvqdPo2GRMXN1uGgo+NZJHXTUYDdHU7lPm/ya+RzWssNf1o JwrWWkAtv4Ejh2Fwhx8VQIGlIGHJhJ0Xvqtxna+tvtHIyg6O+Q1++U3FKJ5bpkJQMyZH snkyCmnXKdEmix17q7ZjuvJwcn9d0PPpRXY5GH0Zm79j/lU/n7gEdP3zUMYrwGkk0W8m 0GAw== X-Gm-Message-State: AOAM533xbNA0fvnB5obb/THk2XTTGBi6C5heDmzY8EjNE+RE3WenxJAe omLNmq9BeYeTMY0vnppd6F79Hw3GVWpZuw== X-Google-Smtp-Source: ABdhPJz79eXmX3RVQl4LST1Wa8fWtBEBvsLxIg2MmwaJfRk/1F3md9Jd38ctrH1sVMt3sd8eHcufaQ== X-Received: by 2002:a05:6638:24d6:b0:332:2087:d58c with SMTP id y22-20020a05663824d600b003322087d58cmr3450182jat.226.1654955706971; Sat, 11 Jun 2022 06:55:06 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: def@freebsd.org, arrowd@freebsd.org, Kyle Evans , Warner Losh , jrtc27@FreeBSD.org, Stacey Son , Kyle Evans , Richard Henderson Subject: [PULL 5/6] bsd-user/bsd-file.h: Meat of the write system calls Date: Sat, 11 Jun 2022 07:55:13 -0600 Message-Id: <20220611135514.92882-6-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220611135514.92882-1-imp@bsdimp.com> References: <20220611135514.92882-1-imp@bsdimp.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: 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, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1654955830288100001 Content-Type: text/plain; charset="utf-8" Implement write, writev, pwrite and pwritev and connect them to the system call dispatch routine. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsd-file.h | 84 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 22 +++++++++ 2 files changed, 106 insertions(+) diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h index 839f8c5c55a..e9e2c85eb67 100644 --- a/bsd-user/bsd-file.h +++ b/bsd-user/bsd-file.h @@ -32,6 +32,11 @@ ssize_t safe_pread(int fd, void *buf, size_t nbytes, off= _t offset); ssize_t safe_readv(int fd, const struct iovec *iov, int iovcnt); ssize_t safe_preadv(int fd, const struct iovec *iov, int iovcnt, off_t off= set); =20 +ssize_t safe_write(int fd, void *buf, size_t nbytes); +ssize_t safe_pwrite(int fd, void *buf, size_t nbytes, off_t offset); +ssize_t safe_writev(int fd, const struct iovec *iov, int iovcnt); +ssize_t safe_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t of= fset); + /* read(2) */ static abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) { @@ -106,4 +111,83 @@ static abi_long do_bsd_preadv(void *cpu_env, abi_long = arg1, return ret; } =20 +/* write(2) */ +static abi_long do_bsd_write(abi_long arg1, abi_long arg2, abi_long arg3) +{ + abi_long nbytes, ret; + void *p; + + /* nbytes < 0 implies that it was larger than SIZE_MAX. */ + nbytes =3D arg3; + if (nbytes < 0) { + return -TARGET_EINVAL; + } + p =3D lock_user(VERIFY_READ, arg2, nbytes, 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(safe_write(arg1, p, arg3)); + unlock_user(p, arg2, 0); + + return ret; +} + +/* pwrite(2) */ +static abi_long do_bsd_pwrite(void *cpu_env, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) +{ + abi_long ret; + void *p; + + p =3D lock_user(VERIFY_READ, arg2, arg3, 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + if (regpairs_aligned(cpu_env) !=3D 0) { + arg4 =3D arg5; + arg5 =3D arg6; + } + ret =3D get_errno(safe_pwrite(arg1, p, arg3, target_arg64(arg4, arg5))= ); + unlock_user(p, arg2, 0); + + return ret; +} + +/* writev(2) */ +static abi_long do_bsd_writev(abi_long arg1, abi_long arg2, abi_long arg3) +{ + abi_long ret; + struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); + + if (vec !=3D NULL) { + ret =3D get_errno(safe_writev(arg1, vec, arg3)); + unlock_iovec(vec, arg2, arg3, 0); + } else { + ret =3D -host_to_target_errno(errno); + } + + return ret; +} + +/* pwritev(2) */ +static abi_long do_bsd_pwritev(void *cpu_env, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) +{ + abi_long ret; + struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); + + if (vec !=3D NULL) { + if (regpairs_aligned(cpu_env) !=3D 0) { + arg4 =3D arg5; + arg5 =3D arg6; + } + ret =3D get_errno(safe_pwritev(arg1, vec, arg3, target_arg64(arg4,= arg5))); + unlock_iovec(vec, arg2, arg3, 0); + } else { + ret =3D -host_to_target_errno(errno); + } + + return ret; +} + #endif /* BSD_FILE_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 8ca92f29857..3a33d54fa4d 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -50,6 +50,13 @@ safe_syscall3(ssize_t, readv, int, fd, const struct iove= c *, iov, int, iovcnt); safe_syscall4(ssize_t, preadv, int, fd, const struct iovec *, iov, int, io= vcnt, off_t, offset); =20 +safe_syscall3(ssize_t, write, int, fd, void *, buf, size_t, nbytes); +safe_syscall4(ssize_t, pwrite, int, fd, void *, buf, size_t, nbytes, off_t, + offset); +safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, io= vcnt); +safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, i= ovcnt, + off_t, offset); + void target_set_brk(abi_ulong new_brk) { } @@ -226,6 +233,21 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, =20 case TARGET_FREEBSD_NR_preadv: /* preadv(2) */ ret =3D do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + + case TARGET_FREEBSD_NR_write: /* write(2) */ + ret =3D do_bsd_write(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */ + ret =3D do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + + case TARGET_FREEBSD_NR_writev: /* writev(2) */ + ret =3D do_bsd_writev(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */ + ret =3D do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6= ); break; =20 default: --=20 2.33.1 From nobody Sun Feb 8 13:13:16 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1654955825; cv=none; d=zohomail.com; s=zohoarc; b=e/ttHQS+9PtmCgW18XF2oDevBgm7iviZJt+vqHw8WFDV97vWvy2RU5uQcBs9MJ30lCm1CpWSuWbRqtKBKDSktCuU1Wmqcr2HIBWACwkXzhUS5IeJz6TES7N2lkn8fCAnsodqzBbAyMO4xxJ6r3ZXXGHMOrgt+LjRNjlUi/odmgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654955825; 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=CiXsSVcrhF7BWVAG8uOdFIspQEoyKovlyV1pkZ4B/0A=; b=GbTWt7L+DUSxbWiyMIsxZCfpsMs9Ea271UnAwCr+NmO3+w1nCGYjfoIzo9VkaVz14clIMiuuOrjrZ75ueVVKZ2Qt+TL97u56NBTWFdhpQDeuRSIH/fdyFsrYTIBJ+FyeRni7pC1xiWX+YoxylzUDbZW4aRFRETn2M+f8HLYJLk4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654955825073118.11000628041643; Sat, 11 Jun 2022 06:57:05 -0700 (PDT) Received: from localhost ([::1]:41160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o01br-00014g-UZ for importer@patchew.org; Sat, 11 Jun 2022 09:57:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o01a2-0006g5-P8 for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:10 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]:38890) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o01a0-0003Ts-VP for qemu-devel@nongnu.org; Sat, 11 Jun 2022 09:55:10 -0400 Received: by mail-il1-x129.google.com with SMTP id f7so1220553ilr.5 for ; Sat, 11 Jun 2022 06:55: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 13-20020a056e0211ad00b002d781cc0875sm1023578ilj.29.2022.06.11.06.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 06:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CiXsSVcrhF7BWVAG8uOdFIspQEoyKovlyV1pkZ4B/0A=; b=wVCmQt74SDQPB13xwExZaRkydhPWjzENWyPrnrorYdzoEKK05woRFuSnjDbaLdzkky VP4e7F0CW8EGNARkYRf30EIEOxUwfzxsFX3x6m6l2PwdELVVmRHbD3WnvDKRFq/t5tTe X8KlOe4MGmRkALyUv/u2hWM3NqfoTNRNdMALKrt1FrAffLig8PwTbqFJ432fpbWvYAyT pbpePQnTlC5l8Z0INXuvnuHtQgrZnQebp52iV9meQdLVbS6AC1RVBULJjmE89MM0WoW7 eDecaGEN4crf1gxJhcss+wGL6kTCii7+EfcDHmwPLFh05648hJWH+hkydkJ2X/SE0934 v6jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CiXsSVcrhF7BWVAG8uOdFIspQEoyKovlyV1pkZ4B/0A=; b=pcyIlaGnV9RnVfDCfJJSbkemv4jbzXtItJBXPtPopxrzAAPDg2boFadQAPD/WLR/PI trTW3qUnYLgZKRjKgEJ173b6zWPhL+9RDCWl+p1P5JV/8eVjJPgw8JYO+VWu66noJlnm 7Drun3cISFDoO8m9oQ1F3EE7Gh42TjZC8mYfLAZf7CJJXGKD/RPH7GrKoRNc3tvk/Knp AQ6PgxMTWe3RpodtCoo04+JRFiwNKOLiAm6hGThLJ27AiMRJb7Lxe+Q0OPRl1n3C+F8y 5zZUfWq1HBEML9XsBpGaM+jPn8z7Iv4mZwjZE7ZbxDrfMV63uVd4wXWJJrhBudp5EgjN /9Ew== X-Gm-Message-State: AOAM530ne2lg2IITs4pw7A9eNszRXBfaU9GaLIMRu51q9KJLRkR4OJPZ HUPpj54CuZJ8mw4+uuxXoOWfKHMaUf4A0A== X-Google-Smtp-Source: ABdhPJzGfr3hoW200lBj5ysOyhxgB+jAaSr334tX70+jDmGxclOdgeBD2Q3QT7cpR3hFfGP7K9kJBA== X-Received: by 2002:a05:6e02:b23:b0:2d1:b62a:d9ae with SMTP id e3-20020a056e020b2300b002d1b62ad9aemr26950494ilu.291.1654955707889; Sat, 11 Jun 2022 06:55:07 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: def@freebsd.org, arrowd@freebsd.org, Kyle Evans , Warner Losh , jrtc27@FreeBSD.org, Stacey Son , Richard Henderson , Kyle Evans Subject: [PULL 6/6] bsd-user/freebsd/os-syscall.c: Implement exit Date: Sat, 11 Jun 2022 07:55:14 -0600 Message-Id: <20220611135514.92882-7-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220611135514.92882-1-imp@bsdimp.com> References: <20220611135514.92882-1-imp@bsdimp.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: 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, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1654955826219100001 Content-Type: text/plain; charset="utf-8" Implement the exit system call. Bring in bsd-proc.h to contain all the process system call implementation and helper routines. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/bsd-proc.h | 42 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 7 ++++++ 2 files changed, 49 insertions(+) create mode 100644 bsd-user/bsd-proc.h diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h new file mode 100644 index 00000000000..68b66e571d3 --- /dev/null +++ b/bsd-user/bsd-proc.h @@ -0,0 +1,42 @@ +/* + * process related system call shims and definitions + * + * Copyright (c) 2013-2014 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_PROC_H_ +#define BSD_PROC_H_ + +#include +#include +#include +#include +#include + +/* exit(2) */ +static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) +{ +#ifdef TARGET_GPROF + _mcleanup(); +#endif + gdb_exit(arg1); + qemu_plugin_user_exit(); + _exit(arg1); + + return 0; +} + +#endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 3a33d54fa4d..71aa0d38e03 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -41,6 +41,7 @@ #include "user/syscall-trace.h" =20 #include "bsd-file.h" +#include "bsd-proc.h" =20 /* I/O */ safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes); @@ -215,6 +216,12 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, abi_long ret; =20 switch (num) { + /* + * process system calls + */ + case TARGET_FREEBSD_NR_exit: /* exit(2) */ + ret =3D do_bsd_exit(cpu_env, arg1); + break; =20 /* * File system calls. --=20 2.33.1