From patchwork Thu Sep 14 20:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=NSMp2FYT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpK76jq4z1yhd for ; Fri, 15 Sep 2023 06:07:55 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZQ-0002rD-1Y; Thu, 14 Sep 2023 16:04:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsZN-0002qm-OF for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:09 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZM-0001Sc-8Z for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:09 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40473f1fe9fso9771535e9.2 for ; Thu, 14 Sep 2023 13:04:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721846; x=1695326646; 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=W1JJvYfQaijMliqHhsRQy54P2Tgf046fCUOip2mqXz4=; b=NSMp2FYTzDiWTtcTwAcKjTcHm5I/l6loimuSq6rvqkf2ZQrNjk5Xb+aQDoYl6N+Pj7 vr1uOdEPHJkDiI1N5vZht7kgGkNjwdgYkx8uPWov9x1J2RBlPKEarauWvdLlfnwX9rxP 3URiSMhgmnN0M4ucAGcuRZqMluAK56lSPbAJ+nQH24SZKdlpLrwwHBduSmaM8dH6s25o nlBY7UeNu7tPd7/NuhEXDMI16crG3S19AwWoNUtsepAlpRQT9ZqJkbL1+tpr+CPZGDNW 5+eVFj+uD0q8Maa6EJRBkX5iJyoWNFm6P3Py+qKtZ+9/+Qjzzbmd/hX2G5WVaKt85/CW /BJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721846; x=1695326646; 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=W1JJvYfQaijMliqHhsRQy54P2Tgf046fCUOip2mqXz4=; b=P0HGIQ9CFQZSha2uge7uYq4j0dgG5+JpA+6eKEj8jnnOotqMJqPm7thEJCDEuUXGm0 HimkXrIrYSsp1XMiC+QFog2bhy1+5yggKN1mjXSDpxdXxftG0SjryDVyM3UzoXe0EgeS UAdvTOgxEEOdVlL/TYGjxXHhKxXnBArVIvzFfpkCHxQc5f8FYSPlX94CIlXxFF1jMO1z HFxDu6bvFzNCAFFps5EcmxVdSMfLv3bHKW0TkO+ZaNyyWbYfZlyUOdjqnA6jMexG7jM/ yiM0qTE3d0XGiyDH1L7Jh9Md9Y+zeBDQpBTs3nvBk5wxvzXtY0tNuYSovl6nDUf/mQKq huFQ== X-Gm-Message-State: AOJu0Yz2oebrZ27rMh2f4O340fg6hsXBGHGjr1/paWmRelQYa/peVB1J UOZhAzUQxYb7EybRtKeH+WV3vBAlkbI= X-Google-Smtp-Source: AGHT+IH36bohLuLbyDCNDSnj/HZ6a+t5AujjX9kFFu6brnsh3pfdMfImMtJEUg6GQVHWbNZb8vfW4w== X-Received: by 2002:a7b:ca47:0:b0:3fe:4cbc:c345 with SMTP id m7-20020a7bca47000000b003fe4cbcc345mr5675389wml.41.1694721846599; Thu, 14 Sep 2023 13:04:06 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:06 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 01/23] bsd-user: Implement struct target_ipc_perm Date: Thu, 14 Sep 2023 23:02:20 +0300 Message-ID: <20230914200242.20148-2-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/syscall_defs.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index e4825f2662..39a9bc8ed7 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 Thu Sep 14 20:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=SpExUwSG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpHV2xHnz1yhd for ; Fri, 15 Sep 2023 06:06:30 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZQ-0002rU-LU; Thu, 14 Sep 2023 16:04:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsZP-0002r5-Jj for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:11 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZO-0001Sw-3m for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:11 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-401da71b85eso14698505e9.1 for ; Thu, 14 Sep 2023 13:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721848; x=1695326648; 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=sSDh8eEaxRaw92d2xRzd0SmTES9unhbDo+y9Fa/SD2A=; b=SpExUwSGU4Hi5pbG/FznBvQcPyLE5e9FSZY4Nil1mumLTN7Td8l67y7MocQhrHpzIQ LCIgAZNKd5NmJ3SdRKILOb2ctySMGAr44cpCHKbV1AKokhlQAVYCIiXQvxgyrfBkcyaT SqKWHTlxr3r68lkTDiHRasQ+yWddInT2/R2WZwCovSt7hAAbnos7ulBQVjwTx8esSCNf is6PwsVO/5uYdazgefA383PgEwwfFa5Pvn5L+5D6faQTtN1d6FZwovgQnfTIYV2cQ44J 4ORj7E7rbEKt4UWO/vcdLSlT/8+CZ1XL0WcyBoTRTsyJ+2Cti7pIaQF9kOOGNpSL/Dvc igQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721848; x=1695326648; 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=sSDh8eEaxRaw92d2xRzd0SmTES9unhbDo+y9Fa/SD2A=; b=wEOKiLxctfGro/qEKuqiQWKlc9Smtc2koHeHKsLgjJJ5XmRboZPVzvIYM77QbOEWzq 29N4hdCMMony+rlFX7QJRmLo98RsVgmGrBNdJGgtr7ZHO3PhoBqbz6/j72eGdZWoVYsj 9PbrHN4B4kXZVrtWfjIsJg0YWXwlhX9cmEzLz8WmlRO72X4qegR0dqOQ1SM3qxedeo+t ypnLWfrDMCVb3ABkXoV4+mTcYDA6vJPPEAS1jIVberpaK2OWuzvaqveAJFf6Xs/V8XUi RlXeywhE+21pCl0fsRcaALJs+xqg6MV++7ADARgRYphZBfmtWC2ZTvVdyyICbuvUjFad fCBg== X-Gm-Message-State: AOJu0Yy+cDrY9V4wC/MyKpjo+enIrw7IFDg6esG8/4cbC9HSKULeJgOd aIZUcySwbuak0Ox1n4Mr0wvS8c+xIdM= X-Google-Smtp-Source: AGHT+IH6fGEmMq60YjRLJjPHALjOMzvL+nwdbFaIrkHzaUg//HJKdxoUMW6YR0lLjDL6jn+eX5TE+w== X-Received: by 2002:a05:600c:3794:b0:3fe:785:abf9 with SMTP id o20-20020a05600c379400b003fe0785abf9mr5616060wmr.2.1694721848139; Thu, 14 Sep 2023 13:04:08 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:07 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 02/23] bsd-user: Implement struct target_shmid_ds Date: Thu, 14 Sep 2023 23:02:21 +0300 Message-ID: <20230914200242.20148-3-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/syscall_defs.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 39a9bc8ed7..074df7bdd6 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 Thu Sep 14 20:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=TttxfelZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpJN331vz1yhd for ; Fri, 15 Sep 2023 06:07:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZq-0003HN-Pb; Thu, 14 Sep 2023 16:04: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 1qgsZo-0003CA-Hv for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:36 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZP-0001TL-HL for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:26 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-401da71b83cso15460975e9.2 for ; Thu, 14 Sep 2023 13:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721850; x=1695326650; 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=kVq1uGHM9oV6angmlbXbZLjFliHdEcoHMR8Uy2q0vLA=; b=TttxfelZg/PMMKo9wkhfRzjJq4WHZEZukGngdAhdtj3DP3qQ5FEQZ29uhLKitnLLDP gJaIH12vj+5MplId02lPlfZtrVnDjk0ZNRxc3kdtieRgZBLWQpT8jhrQluJjTtI4lpmR oz43/I8UMGeS9DVGy98W3Y0Tna/qdj3mPxicPOTQvkBbkHT+jMGkKmZ8HUf0/myNbIL6 ON73kL6vUna9uy7aDnOnYtfNhzos8f5TlqTXh9bl7ChUdGVC7NgsL6bPEnPMCf2HGeW7 VGQKq3URescBDswhBdoDVDZuN5bm25l6ZeHN7ZhBIRyXOc/rFm3qyXSN9WTHUw2q8yll rZdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721850; x=1695326650; 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=kVq1uGHM9oV6angmlbXbZLjFliHdEcoHMR8Uy2q0vLA=; b=pUM/YHvWnnbLlDlQve/idMXqexn9Pgcoi1l7bnuSoaX4TUD2J+skeRB1BPQlIUdeUj 1hCj07HV7m+jmx/e99k5VQCf+nlKdsT66XVp5ETmvgzDQ0IVXpnElELcSRU0/LQGqwiq D9/QWGbnmT/9SMB4YeJ0xr8xebLFMGOmuMlBBO1r7ixb9p5OBImC6YrZU/IasZHn4IBt p0C1xqTNqHm8gMrpg4cxICuyGqfecDQcg1KkUZCMxRYnCz/PyQyv93tKK8JQYP+RFv5H virMAa0upXAMmN2qrMqvp8U4bTiXcnWaAMApHngIKYpXxCpG7EFAIcvPCTOx0uCxT/20 4rtg== X-Gm-Message-State: AOJu0Yx7JWBHFiYv35gLLwiHuTl/bmoaE5peY0hSFrmeYArZL3PY7+3w xDKEDFgj8zvHdQGoELyK222k4rFR/ok= X-Google-Smtp-Source: AGHT+IFB2RPlhHqWtUzFiXG6x8R7YG7cWI2aRcrGH6oef8CGNdAdZm+w93Ez2rKUTDICgOq9tcp+NA== X-Received: by 2002:a7b:c3d0:0:b0:401:73b2:f043 with SMTP id t16-20020a7bc3d0000000b0040173b2f043mr6107432wmj.1.1694721849376; Thu, 14 Sep 2023 13:04:09 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:09 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 03/23] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions Date: Thu, 14 Sep 2023 23:02:22 +0300 Message-ID: <20230914200242.20148-4-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/qemu-bsd.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 bsd-user/qemu-bsd.h diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h new file mode 100644 index 0000000000..46572ece7d --- /dev/null +++ b/bsd-user/qemu-bsd.h @@ -0,0 +1,45 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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 Thu Sep 14 20:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=C4KQjPoc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpFf3XFdz26jQ for ; Fri, 15 Sep 2023 06:04:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZU-0002sR-TP; Thu, 14 Sep 2023 16:04: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 1qgsZT-0002s8-BN for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:15 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZR-0001Tg-Mg for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:15 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40472f9db24so10294055e9.2 for ; Thu, 14 Sep 2023 13:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721851; x=1695326651; 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=KK7hmPDkvNZ7gao1BckcXOde8JB8Py+cCsJYB29LOaU=; b=C4KQjPocFMmZm9DoBh4KmkCCQ+gmf/8fDwCalKitvH+y8UzSdIqX9w+kdYjlQ+fAIg +VeOOnbdHSy/F0u6rSEzETce+VtCivHWVtrzWj3X4f1TnEzxuPNDc1DLmiZ55eiaWriQ 4y/ow8NS59uqsUKm25d7HTA2oy7nG00NvsquthJ0YAqphWWoIBNTAOcgF+JM98WRQd69 bkqIq+yssy5ZdLygY8dSePC9cVAph2pBiYAlJjvRfYGTa2zUc6JH/wab6pgOy3QJNIMM dMM9CzgF4l5Ukwsh6S+GZlOQlCiGku+1L+bcMtI5LHknWB1GaGOZ5F2JDh0L22xu0jli hRKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721851; x=1695326651; 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=KK7hmPDkvNZ7gao1BckcXOde8JB8Py+cCsJYB29LOaU=; b=oTuYe0tr58eWr2t6wyeKAwqsWqFF4kRwGG9HZWVZ8SeLMcTKw6GTjHi/6dC4gUyUYK Cx30krHbd6niHqgCUPJxOGQcx+8hq077D2gfgyAOZDrd9pKXZEFvAGXdU9bT5WDqZrrw 82VBleAofgonSO8B1CqQGcSOU66KmzXwhqA15vP3TsCMBXG9bW08kNXPwIQcbI4Xt3kT 1m7tF0AypH6quU0Ak7VwpH6dwK9Ze7svk13k1DTdOEK4N7ut3/+sNMrPNZ9EwAo2P8jG wCbQq0rWdtj/lI0Vbq1Fm0pSkfFaHNgFBICtjzyg7DlRRy3DtN1rc5miyqLgoVsl7NVc hcoQ== X-Gm-Message-State: AOJu0YxpSN2bx4FLOsTg4wGvui/rLado2lO6m481T0efJG7v52Lg9Mp1 BOP0UYVyDXWB8WD64mHj7QwM4YZfHc8= X-Google-Smtp-Source: AGHT+IHqqjEy2qf6M5oOImImeKggecrjv83BKTpVEAWylCuesjqAD6iGOrWT26agZ52E4R/yZizzlA== X-Received: by 2002:a7b:c045:0:b0:402:e68f:8896 with SMTP id u5-20020a7bc045000000b00402e68f8896mr5742116wmc.0.1694721850771; Thu, 14 Sep 2023 13:04:10 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:10 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 04/23] bsd-user: Introduce freebsd/os-misc.h to the source tree Date: Thu, 14 Sep 2023 23:02:23 +0300 Message-ID: <20230914200242.20148-5-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 0000000000..8436ccb2f7 --- /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 Thu Sep 14 20:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=VA1icu4w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpKZ4xnfz1yhd for ; Fri, 15 Sep 2023 06:08:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZW-0002tG-DD; Thu, 14 Sep 2023 16:04:18 -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 1qgsZU-0002sO-Hq for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:16 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZR-0001Tv-Uc for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:16 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-404773f2501so4660015e9.0 for ; Thu, 14 Sep 2023 13:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721852; x=1695326652; 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=xnXmZkbpo6/SgIptieBsKXVrN3AJvzb8K8opqiPzen8=; b=VA1icu4wg1bBFUoj3fePH7EI9X+x7aeuhDc0WwQH5wnVGhb26OhJ5Iba9+BOH4IZY4 yVRXWvcyz3fbajYtRGPeWzkq+xHvuxFFZSz5Z/S+z1AoahSPBKv4Yx0iD2fX1NyVPCsw aCLI3K8KhpT1fuqFXbkSRE2INTZB7W6Lj8tYF7KIytdR5LNyjyBHM/B8B1TQiT6uiuUL 4XisNNoSKxpHo/qGPfulePmHT84tsJ4GkWkxkCspUtuo1VT6j0zce+BmG2Fp/RkkYd+n dwD7LItkNcdhY7Q9fG/lJUXGtHJbPNEQAkqWOgt7tqCE8Kp0KeFSwO9OsceaDLIghsfq S13Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721852; x=1695326652; 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=xnXmZkbpo6/SgIptieBsKXVrN3AJvzb8K8opqiPzen8=; b=TqkjsuFXkO2XXkeMprAGPS9YgeBBRzdGfQOkydjWED/QPU/iye2rf3pKR4tiDdnnnS +JvMB599FeogWPxi2MsIvjhHDeKJzMsWP1h2KXEXlefS02Ogg3PhKiHLauVKL/zZME2n W/MBNWOPC2KCXRur4CwJ21eCiHEdQcaKEtXn9BsXwT3p9Kut6dxLCdX+sWewujqUAWu9 QOovHOJ86UlFQFroJ8D+e7wRsC1cqBib3c4mkwL4AZ1JGktyCzMc1FXybJnK1+g+kLXR q/Wg+K+hVCVO+iCJYfOT1xxEcfMW86u7dsy31BbqTeh2cBUK/NHNw1gVjT7GnXVHfpNg 0Ahw== X-Gm-Message-State: AOJu0YxlIOVg5muOBq2HqScbPh/f9kx6eIqDvDCnnM9sPkcT2ioEoDIv Gv9aKmGGeepUliNEZuxaQzIArzLx3v8= X-Google-Smtp-Source: AGHT+IHHfNuDG6FLW5I+VlBFPvFbGeLrNnK6zKvcV3nnsgy3+2B8+KPDX91vNpUgkeUE0fMiIDZxAw== X-Received: by 2002:a7b:ca47:0:b0:3fe:4cbc:c345 with SMTP id m7-20020a7bca47000000b003fe4cbcc345mr5675551wml.41.1694721852301; Thu, 14 Sep 2023 13:04:12 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:11 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Kyle Evans , Karim Taha Subject: [PATCH v4 05/23] bsd-user: Implement shm_open2(2) system call Date: Thu, 14 Sep 2023 23:02:24 +0300 Message-ID: <20230914200242.20148-6-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kyle Evans Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-misc.h | 42 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 13 +++++++++++ 2 files changed, 55 insertions(+) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 8436ccb2f7..6b424b7078 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -24,5 +24,47 @@ #include #include +int 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(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 2224a280ea..b4311db578 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -33,9 +33,13 @@ #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-misc.h" + /* 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, @@ -482,6 +486,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_undelete(arg1); 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 Thu Sep 14 20:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=SzpYOTnf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpFf2wywz1ypW for ; Fri, 15 Sep 2023 06:04:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZX-0002tR-5p; Thu, 14 Sep 2023 16:04:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsZV-0002sl-IH for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:17 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZT-0001UJ-Qw for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:17 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-401d10e3e54so14555025e9.2 for ; Thu, 14 Sep 2023 13:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721854; x=1695326654; 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=9RLJ4zSpc/hhC1DTqvPXVuxIGqkkJ6Cdn6Mza5ndY54=; b=SzpYOTnfrkSMpe2hZlsb5rkQZnsIKLyk7JzXr6fNia4YpLL/NnYBYe22HRa7rjVwZF 1UUJcsQH+QLh9XlcHRRnZIpv/MGFqJGe2dgQ6u+p2gI0kwuR0C5JBYqcC1QlI3w6wcwN 76XTqbrp1LcBs2P1isyorv5hTWxVBqNwdmBuiSmLlZTWVuBvkzvjm/v00ig2s0y0Sv6B ftmWp1Jl+eXTimj24w5QlDvnZRIySvayK0SUUvcTMttQa7PVnmWXX2DYXS8CpWLODDUD iJv++6odIX7SvZy3iQIizKru2pXGIGmnLX0kI5XSzF/Zth1UVKowhS5Um6t+2V5EdUji d7Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721854; x=1695326654; 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=9RLJ4zSpc/hhC1DTqvPXVuxIGqkkJ6Cdn6Mza5ndY54=; b=uMWWHspeGGS0uOm1cFXabfvalJhje8+TO/wXPg31nvCzugTn3/IKf4f4WDZPUemCrU tiplVA/SI+2GV3DlTjhvgwSS7rq49v4u8lpUypBiaChzbBmuBTf7q6jKpl7VJsLHZ/Rb DLFCesyp4e6zEf+yrav+Lbc6l2cb7vBHTvdmqs9rnJjLk7c+DxFvzbuMgNJv+6B+hx5e htIIcbquXXyRXnbjppMDcU36MI4Q7GrnUr51R1qOFWm79o5q0Z/ykdiyV0SuMZwc4LQ6 iKwKlSM+bowtTEqclwjKetNv1mVWA7vjOb7p+OiCvhP0pqcJz4+LTKg+YKDmy64nyYY+ SJ9g== X-Gm-Message-State: AOJu0Yw+rkrM0jfdAkteFP74XiNBetT/1Hgdm90g566NrLY7/IkHLlQ+ riWTAcTSNTr2NnwPQ274E8LRSs5nNGI= X-Google-Smtp-Source: AGHT+IF0ox3gplKzCYY1Kp+pY2oK1i3ipJ6T4Usmnuim++i77+fySNHrTfZAfmo9nbtWGMcwGR7TKA== X-Received: by 2002:a7b:c455:0:b0:3f7:cb42:fa28 with SMTP id l21-20020a7bc455000000b003f7cb42fa28mr5422755wmi.28.1694721853552; Thu, 14 Sep 2023 13:04:13 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:13 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Kyle Evans , Karim Taha Subject: [PATCH v4 06/23] bsd-user: Implement shm_rename(2) system call Date: Thu, 14 Sep 2023 23:02:25 +0300 Message-ID: <20230914200242.20148-7-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kyle Evans Signed-off-by: Kyle Evans Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- 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 6b424b7078..67e450fe7c 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -66,5 +66,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 b4311db578..2920370ad2 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -495,6 +495,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 Thu Sep 14 20:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=FinilrS1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpFf2M9Kz1yhn for ; Fri, 15 Sep 2023 06:04:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZY-0002u8-G8; Thu, 14 Sep 2023 16:04: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 1qgsZW-0002tF-Bo for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:18 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZU-0001Up-IU for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:18 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-313e742a787so926058f8f.1 for ; Thu, 14 Sep 2023 13:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721855; x=1695326655; 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=tWanWC67jhmn9FXRwvcRc23eY0xLvKm6663P3+ePW3g=; b=FinilrS1rMObO5Zmw+dqO2sBU1gV9CJNvtH34RAFwg1PJ/vmJSxowekIi2uMGftGtK Pf3friyQMPAk+8BrBHwOtE+Ofjk6KD4oLBxNLEYoSc3xpzkrFbEH6ES0h2OdI7kQP2pF KleFkRnA7/oMEM7ScGxJhhnCVpV4no/ipp7vk5VIAOjXG5UZY1OvuyCbevDmDbP7VsjG WuRK3mvtM9Ok5iVUEyua/eFbwPtPaQDF3hhOHNQFhadgFEnuaa2agY5hQGx/tOTm8sI6 AGBVqNp3YpMCcgpqtqzhG+BEqEv+6kEZAkDdYIrfTMD6lifymE2+t4fxBVq6SKPvk8It UXIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721855; x=1695326655; 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=tWanWC67jhmn9FXRwvcRc23eY0xLvKm6663P3+ePW3g=; b=tpfIFJaSXOxdAf7uCoCkhOYOAQ9UEqoMSOb2Al/8h7658X0S4TWaa9/E8mroBGonac JJTaQSya3eqICQtaFCPopWG7gfJ4pflsLRaHVrVfqTExreRvhbXQ7KD3bZQM+iJt/ua4 gqKbk6yQeToARuuYi+on22HA2ZTcXoBdacHF/9tqwcU3UNlJiXSzRHVvFqaurbk/LkO9 YLkWPsHyQaOkYwt5u9VxGiooJCzbH8VtbofRf5c9HFkGn7yfDGPddwtZViZrIZdy47N1 IFga83QR4t31aB95Eh0JBPkmsMF69HAlRYELEhi4lcNf8+chxNuxPH1C7NtcD8Nbzq3Q hAJQ== X-Gm-Message-State: AOJu0YzsaENDoOFeSFNEK7dcNP5HwL8/8x2PpjIbHS3oWlsXQZAVg5Ur JCUAVR4bxYU+lCRboWF7WW4io4K/0AM= X-Google-Smtp-Source: AGHT+IF5ynM9qOJSx+Tv+PQu6QzgksME0yEB5PYY4MWDcvw5EYEGD7M2Pz9JaO1l3QVK1zwAT5ip6Q== X-Received: by 2002:adf:db44:0:b0:317:417e:a467 with SMTP id f4-20020adfdb44000000b00317417ea467mr2345066wrj.6.1694721854790; Thu, 14 Sep 2023 13:04:14 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:14 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Karim Taha Subject: [PATCH v4 07/23] bsd-user: Add bsd-mem.c to meson.build Date: Thu, 14 Sep 2023 23:02:26 +0300 Message-ID: <20230914200242.20148-8-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- 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 0000000000..e69de29bb2 diff --git a/bsd-user/meson.build b/bsd-user/meson.build index 5243122fc5..6ee68fdfe7 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', 'bsdload.c', 'elfload.c', 'main.c', From patchwork Thu Sep 14 20:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=MCWc3QkS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpGF32PWz1ypW for ; Fri, 15 Sep 2023 06:05:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZY-0002uC-VQ; Thu, 14 Sep 2023 16:04: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 1qgsZX-0002tw-UP for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:19 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZW-0001Vn-7P for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:19 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40473f1fe9fso9773255e9.2 for ; Thu, 14 Sep 2023 13:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721856; x=1695326656; 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=F866fnYal64jgJhD1WaHqOztZB6EhKD+Jyo2iWQ5ErA=; b=MCWc3QkSmuZ/hwcC0mKX22WvaApTmJUgUWn6YT1wT7AJMv9Ki+4tX7cBtL2U2vhvEm C2z3Qa+1fKp7l43dN1h0/cQagCAUvWgKNFP6iFxNWu+YS7FUGi2CfKkMjjqWTiepRXo6 q0R/ML96nDWcmGSG65R7yD0/Ln/oM3AkQAck32FIJrX+yhNMQa3lYY2v1VvqFkTeZmvA Xe93HCnxoukH4yVaCmov4D5meMgxB4bdkrEimcHjuVKgw71tSEBEyVKpN/CktP+VCiRc /dcdNSPjLQ431ECRoTa5RIBqUvxt58k9O49WFQv/ZYmlQPfWyoAUEZtZTd2QsVEwnpOp G5eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721856; x=1695326656; 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=F866fnYal64jgJhD1WaHqOztZB6EhKD+Jyo2iWQ5ErA=; b=ZkZSREBSTz80A/4Noo2NZJWVwCMnHcPBNBSAjpSUJhEUFz954IzWhACgOyg4WjcQzO 3a2h4N/clJisOpRk9rQk9DtaKNAh8r445JtfB5OL7I/AgseXXtlpaHNh9oFTFmMI5s0H +gZOayVDK27K0cJo3ZOeVcB9a9tX+DGKuq5AzfdsMjseO9HB60MPHQEecpAEWzrZSVDE 6H/lPkTvgGOecdOD2O5TW+UrpfNmUf1ZC4sUAYzNCxN3lvs/ObUBk4Yq2JdEdr8vLSBv 34pBPDspFzH2T8mkA5lv+1N4MP1jl77dgQO+gpUQ6wYp8VpJNCFD8c0HWwmNKWAf8CuF HA9A== X-Gm-Message-State: AOJu0YwEGOhyRZd5dXtO9RG7QheX27Gw79Rz4slk0riEdFO7eF3i6pRG eyGCtCvt8EpUO9M9ngdOwsbvw+K7Hl8= X-Google-Smtp-Source: AGHT+IEhYgYUGPUPP+Cvc5DgQBceASnC67Y8TFAjRmq5uNUHF+IHzaZ/e06rnZKVfecADMCNO2J8zw== X-Received: by 2002:a7b:c3c2:0:b0:3fe:d448:511a with SMTP id t2-20020a7bc3c2000000b003fed448511amr5595823wmj.9.1694721856164; Thu, 14 Sep 2023 13:04:16 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:15 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Karim Taha Subject: [PATCH v4 08/23] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c Date: Thu, 14 Sep 2023 23:02:27 +0300 Message-ID: <20230914200242.20148-9-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 e69de29bb2..8834ab2e58 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 2920370ad2..c0a22eb746 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -59,10 +59,6 @@ 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); -void target_set_brk(abi_ulong new_brk) -{ -} - /* * errno conversion. */ From patchwork Thu Sep 14 20:02:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=jBCaeTVZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpFf2MKsz1ypL for ; Fri, 15 Sep 2023 06:04:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZb-0002vR-2u; Thu, 14 Sep 2023 16:04: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 1qgsZZ-0002ue-5R for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:21 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZX-0001WY-Iw for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:20 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-400a087b0bfso14625275e9.2 for ; Thu, 14 Sep 2023 13:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721858; x=1695326658; 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=6kOFVD7x0CWlInCOpBq7W9+nfPWQu2AwCNVWCQ27xk4=; b=jBCaeTVZSOImL9L6adqQxxmuOzP0Lrp6fq+0HHe3c2pLQFLjKqalXTrVuKq8H1dW2/ 2NdHEXbmmdX0t27gcOUsimPnwS5aHIuh2+Ycn19m2n0E6pRVf2ULAlYPJYNLy3aJUkO5 sKnOwbcFpDhMBqwOt/DU84yGPL7W8Tz90oXO105mRBs8TqDiyWhpwy/2aZvTb8pRwB8c /4rSWpM0G4ejXneEQMHTsTPdU72p0lMcSebSgiWrNnYBiXutXOIOaAChVFP8wxgC5Bxw aDvUYU4+dtZUf7wIvj8QwQLgdaKbkSRP0+q709wSOH51Ey6bf/let5L8C9DrtBg9kWyJ Cvxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721858; x=1695326658; 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=6kOFVD7x0CWlInCOpBq7W9+nfPWQu2AwCNVWCQ27xk4=; b=mRwNi0HwZfEyJAap3sR0pSppEC/uWiuUy3cUvUUgc56cgFnJQmMijbjlNc+1x9Nt15 gFEPjhtvr9v21b0eU56DYeRdDgXNN5JX2i1zrWXUZaY8RgKHrBULBr+JWH9+4tNsayuN nezTmjF+hwqG/D1jx6tGeQFennVqTbINY5VQcPGKOQDDV05Emv/cN6ZWlq03sL+GdG34 JA9h/65VRInbbd5rKl3/C02/4kcJffDJZAzDyMJDuQjpCuC+3qQL+DkdLf1X0TB2y8JG ez347To8DAeW/+DYlN3UZCHo298QP/DFfIrRaDoCy/M2XGKq7dcpYcVU+84g5GG5+4/x FkVg== X-Gm-Message-State: AOJu0YwR3Q31E+5tFMlwsqg72RlHZ+FJ52htdGHwaiTz7pbOJLHIIZbH 00Kk2SiyqdIeptEr5b1MYo9aIcpi0Vc= X-Google-Smtp-Source: AGHT+IG8jzRqIxbpt/750EpYKd9bOU8JHR5C9hb1jFCmvhGPsgNXoqduuh/ClMnYUCH881OI2b+qyg== X-Received: by 2002:a7b:cb8b:0:b0:401:d258:ad26 with SMTP id m11-20020a7bcb8b000000b00401d258ad26mr5317873wmi.19.1694721857557; Thu, 14 Sep 2023 13:04:17 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:17 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 09/23] bsd-user: Implement ipc_perm conversion between host and target. Date: Thu, 14 Sep 2023 23:02:28 +0300 Message-ID: <20230914200242.20148-10-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 8834ab2e58..46cda8eb5c 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 Thu Sep 14 20:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=nHHnWzgw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpGv6xLwz1yhd for ; Fri, 15 Sep 2023 06:05:59 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZc-0002vo-Hd; Thu, 14 Sep 2023 16:04: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 1qgsZa-0002vB-8U for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:22 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZY-0001Xa-Iz for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:21 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4018af103bcso9534165e9.1 for ; Thu, 14 Sep 2023 13:04:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721859; x=1695326659; 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=xTuAkybq2jfJV9OdRT1tDzyr/5NPWRVF8sB4olFps3M=; b=nHHnWzgwgKsnc/Y+FOPc4WphBej/Bd4e+mR5QRqQFa/2AESMQWAU0OT6sAfxL523Vz tDJXQk7jFuOpm7LVcIM78anEzQAICo66J2dC4UM+vdspMMOiwPVQrG1CuPnnRzelJvU8 iwPtKzTS/Pn4ix637Uxbk+h5458Nn9lS4kFM1HI7Ae+Q/6XcNCVEAklaAmz/3kfdaADc oVv9zFiXdOsBgvx5lEXvdL6yaOC03+/CSPzR6r09EWx7XSE11kGTlc4wdJubWnAdC7N0 bmnfKsfDCCxUg/ScdzoWZR3vxXFNXkpZx4iY41VBXh4b7VCIN6hYB38BtxkxXReAojSL 6SmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721859; x=1695326659; 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=xTuAkybq2jfJV9OdRT1tDzyr/5NPWRVF8sB4olFps3M=; b=q5y8eu4Cnqg1sql4EVOxc5Rti1NpeZTlc12r+UxshQSl/M3W+JmQ/f5pdwraL+A8um PsjgTKYnY0aBpj9kWLSF7OB5IO1OXdyNeULML/yz4jcH+XhKZ43h7zRF7peI6lL2JTfd RAunt/YqAXZ6SDy2b22MtGNNgMRDPNPFTfg/bz/+T7rO+o2MGf8D9ornXkZyjRhy2xXJ 6MNC8PcaGBorkJKGdWKRlgjzuvi2FqtuWn9aWHDc7BpGBU6fO5CbjFXH8nrNSV6GfxxD azZ/uuMWCgMIuBsTn6u5wE4ebqrUE2TzJb6E0KoI0EYeetfhkegaQNnhEGnIzHNglcuY 2MHQ== X-Gm-Message-State: AOJu0YxtkMfTUflV8JkE4te0noN0U1OCY3d2Iqhxb/zg1/bX65xucvKo DuOHmXYOKwd3QDAvwJ1qboLjke4ebiU= X-Google-Smtp-Source: AGHT+IHNgRkjtXB3cdgo96ulCEhIZIJRYZh/3TSEyNwEpT0eMVFOmAZcqGB78VZDvn8qWI+pDktbkw== X-Received: by 2002:a05:600c:b4b:b0:401:c7ec:b930 with SMTP id k11-20020a05600c0b4b00b00401c7ecb930mr2132378wmr.10.1694721858912; Thu, 14 Sep 2023 13:04:18 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:18 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 10/23] bsd-user: Implement shmid_ds conversion between host and target. Date: Thu, 14 Sep 2023 23:02:29 +0300 Message-ID: <20230914200242.20148-11-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x332.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 46cda8eb5c..2ab1334b70 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 Thu Sep 14 20:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=KzyWUoqX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpKR1rgjz1yhd for ; Fri, 15 Sep 2023 06:08:11 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZp-0003Fv-Pk; Thu, 14 Sep 2023 16:04: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 1qgsZo-0003CB-IH for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:36 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZa-0001Ya-JO for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:25 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-403012f27e1so14282845e9.1 for ; Thu, 14 Sep 2023 13:04:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721861; x=1695326661; 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=k5y+mDYHYGwFH7Ie7hyZags2xvGxi9R9xwWRldskuV4=; b=KzyWUoqXUOI7XquBAAZtfHryY5AtzAZxBv+b1eML9J6iEXWLS36fvXXJ8JRpZk4+dD d1ZCiHesIaBRCe3TvQrRLpUEOXa4CXfb0XdXTh8ucpWwHhVFUfNeV6nr/QwyvVjWdDnU x27KmNcWqijHN39cDlXHAYPr3+dWn7c7lJbZuGFz6sf3Ut4zDWHL/5YybkCTZxTXUT1L CqymwDG2juXSEXEwIQ6K7V2JaIeQYsVTY+ycagJch6lzxrWGmFXXNvWl7e70JZFTgVai kNDemC3NclaRkl/ic+BG3F72UgZU1wUavAarEZVYIkqLTPhJt1PAeYjHfd0ywTcdR+Fb IqVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721861; x=1695326661; 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=k5y+mDYHYGwFH7Ie7hyZags2xvGxi9R9xwWRldskuV4=; b=G9qWmh1301ntPfUfNzQGMP3m2tFMXyVvaCGiijEIDKS5R+5s2S7HEKMwZdses37FdI Ec7hhxSylRaIt+BlQZULrStFJBCqNRl/l4Dp5Jt57DBdLRMvX099UrPBMB36x8If6+UY J+3R72LfK1aCEGWYbU/kykLQzZtFsSQgXvsEqxjYLpK3e/y/gddburWLHIYhTaxtBAbr 4ye5mYe7svRCNtwH4QEIG+yPzXlqVsJyrqMjk/vEKpilzij0yj79LoYjYiB/JXeaPPLh 0D0m/G0eVux8loozSVW6qKEfHQnKnwMM1quooaHfOkTnu+QacGSB6nDIBLn6hSkrg46d Wjew== X-Gm-Message-State: AOJu0Yw9IaS2dLgZN4Qzo8J+YSXG7i8HCQSUGfwiU6lUHBj55xunewPV R12f9HSFpKng+svQaMURRSu5HcXemxY= X-Google-Smtp-Source: AGHT+IEcPRq5nvyRRpRxycFgXIIDS0pP+dGzmmzOkRyHyZ8o2owzIFXFgjWzxns0odub/aqutT/eow== X-Received: by 2002:a05:600c:152:b0:400:57d1:4913 with SMTP id w18-20020a05600c015200b0040057d14913mr5536070wmm.9.1694721860844; Thu, 14 Sep 2023 13:04:20 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:20 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 11/23] bsd-user: Introduce bsd-mem.h to the source tree Date: Thu, 14 Sep 2023 23:02:30 +0300 Message-ID: <20230914200242.20148-12-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 0000000000..d865e0807d --- /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 c0a22eb746..7e2a395e0f 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 Thu Sep 14 20:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Y/d/Avfp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpLw2Rs7z1yhd for ; Fri, 15 Sep 2023 06:09:28 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZs-0003KK-ES; Thu, 14 Sep 2023 16:04: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 1qgsZo-0003C9-H1 for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:36 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZb-0001Z4-OJ for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:25 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40472c3faadso10348745e9.2 for ; Thu, 14 Sep 2023 13:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721862; x=1695326662; 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=jNK2HNrdMWVVY1+gcX4oM/Wj3OhUzW/K4i4ACmkfmcg=; b=Y/d/AvfpAsTlHB68ivlkCAi/K9C6dRxYS5wg+XPM4pbLHXdbydMC00cYJbTa3Ormgb ZmzpCivwFD8oZd2fSJttx8qmHRYoL74dXRhIzUSXslfrJoDxwVk+oZB9oyc2xLUCZR2L PppqQQMxChv5Bqkj1SiYDpNdGErdxr0nRaLfH8BqPhX6OnbTajH4G58DRMntPuMNxeeo p8nozAVdgdg+/Xl3ODRgoVwLFrizEN5YgyDjYlquQ9t12Dl2cYajqKucOYfjQ79Gbn5t O1/DocsUTFPGjdp7jucj9sGnTCaNZbPDZMFufssiJV1qqNy1ORIs2U9E7mSlWO++oB0p mR5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721862; x=1695326662; 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=jNK2HNrdMWVVY1+gcX4oM/Wj3OhUzW/K4i4ACmkfmcg=; b=OvK3dDy+e0fHkskcPh+AuPaBMHJnxzXZL1Yfysj38KmoRT8fY/obGUF8FKV6qlBs+M kDPbCmJf73S8YujexyiSJlTvhUN00t/l1eQkFbxpEozg5ZRQldhpoBTO9YDGDf9fWZKe i6PtzAK8079ECb02BE19qyVoKwOuzkOY9d/uUhAKhP89M884LUI/cAS/5/rqLj4++NXA FMRmAXf1M9m0K0JKJ9sMrjaUKwIeXw6oXF/0vrWm8yHFk3yzO+gXAth9G0GkOJzPffJw hSavNs5I2sTz20UaXpZ+3ZHC+EUoF/RQiSlxn3j1gJYxAj74QZLY+RrDD+WHoTPVo1MF M44w== X-Gm-Message-State: AOJu0Yzlwxs3bQqCTmiz0Y+TMMNaJFebJF5C1IHSWwLQpzjGh+1Euy2Q lW4iH9lCgbD1qXfEMTNeUuL54tMx6Ug= X-Google-Smtp-Source: AGHT+IHQGD6dz5wEd3MyiZoT4l0hKMxrVa0Aw4dbpAobdzMRgP7Imu5OnaeJFh2yn9ydzrx0zXo1nQ== X-Received: by 2002:a05:600c:20c4:b0:3fe:e85b:425d with SMTP id y4-20020a05600c20c400b003fee85b425dmr5668375wmm.9.1694721862067; Thu, 14 Sep 2023 13:04:22 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:21 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 12/23] bsd-user: Implement mmap(2) and munmap(2) Date: Thu, 14 Sep 2023 23:02:31 +0300 Message-ID: <20230914200242.20148-13-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson --- 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 d865e0807d..76b504f70c 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 7e2a395e0f..d88f62319b 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -486,6 +486,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 Thu Sep 14 20:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=GktrhpuC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpLs1FRlz1ypL for ; Fri, 15 Sep 2023 06:09:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZt-0003L4-GH; Thu, 14 Sep 2023 16:04:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsZr-0003IF-5l for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:39 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZk-0001ZY-Th for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:37 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-404314388ceso12641145e9.2 for ; Thu, 14 Sep 2023 13:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721863; x=1695326663; 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=W7MM4o6hfnwu6xJY7wrfXa5mcuCNPXgDVYr5wwCNE3Q=; b=GktrhpuC1mqlXRKP1vzjhrdna9AinjmWUys41pQoNcHAEu85ck5ms1XnM5UDjIucsw htyeVMLpsCiNkqj9tRAnwbxCrR+HdbP5q0bnrz2DbGfjvT7/8nvf/eSguMxVK9XCCXOS 7w+pqQEo5p4exODu/gVW79bMHlNFYan/BpWOUmzAxYQRK/WxZMn+vG+JZYDl8fGAslY9 NI6tM2LVqQ11Tqaysa20SUtnSTQ7EEHllzD+Ggd9rOBFKQwn0CHattvZhGRbe+ORMpdP 3CMrTqDxevuT/5zuk+iLUoBQMvf5XnC0Jh97Gb34HpnafXBC4ZdHUEBRiBdtSocYc2sD UqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721863; x=1695326663; 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=W7MM4o6hfnwu6xJY7wrfXa5mcuCNPXgDVYr5wwCNE3Q=; b=EUpKjHqlaoVU0mSt9nBXY9KDuKjIttUmgly5QNZg2wdk3PruqTeP3hm4J379K74lba SVmX0hfkBD2vSZKz24000Egqv5rh7t1GMHh8gz5AecC4/5r+X7DSYd7LLLeh7URzedwX V9f9bdwtnzUgnUcplW5lI3rX3qXLWxcc51D8jNV1biockwg++OZsuUV8rd3OurCvXwLg D9g9FaBPEm9Ai1pEkuNyxO0rGWYfirXPqfbVEFDXxSzo4lz1tzOZxKWijzGFkhl5kQWR hNoiwXva4P/6k1omsCN8g1/so+FQ7CD9xoKY0px4PS6IRCJjcL1Iopob90j0Ggew40Mj erzQ== X-Gm-Message-State: AOJu0YzcDnHZ6nMPOq3DiFo2oARwcT09faf7ieRLo8bBaV+vmeG1Z3V0 FQHDilt1QUC2XUi5MO4AI17Q/NzWj0A= X-Google-Smtp-Source: AGHT+IFw6wfzhuq/mFxS/l0mrfK0Ic7xNu2OXHxrELdgSAbPaQETHuL1xj9mbmos1Hd+bcNrLbDvKQ== X-Received: by 2002:a7b:ca52:0:b0:401:38dc:8917 with SMTP id m18-20020a7bca52000000b0040138dc8917mr5666940wml.6.1694721863325; Thu, 14 Sep 2023 13:04:23 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:23 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 13/23] bsd-user: Implement mprotect(2) Date: Thu, 14 Sep 2023 23:02:32 +0300 Message-ID: <20230914200242.20148-14-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/bsd-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 76b504f70c..0f9e4a1d4b 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 d88f62319b..127805e079 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -495,6 +495,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 Thu Sep 14 20:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=i+05+Z3L; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpLv0NxFz1ypL for ; Fri, 15 Sep 2023 06:09:27 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa8-0003dE-KY; Thu, 14 Sep 2023 16:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsa2-0003NZ-92 for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001Zv-Cn for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:38 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-403004a96eeso14586805e9.3 for ; Thu, 14 Sep 2023 13:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721865; x=1695326665; 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=ZzCf4SxTDBS+/M86UxgHIAN1U8HQ8Zh8Ai7mVoDHpm0=; b=i+05+Z3Lf5aJ0w5TXF5R8qjzjz6+qAMSBbdviETNjzyzXsxUY2Hk5CRpbDxWJxN5lQ wWzXytn7zZxCwLKvKX8Y8I5wyUNc5EioPXh3BXdrOodqc5sbz7+vg3jvFxEuu4nDftTv t7OG0qx8EKJnfiezqFVFmaHJ4/5JEjRLp0xNuNANf2VDDuYxcM0xnQ6mRKQtb7npsnRh xn8NN2NC1lp7tcs5JhFFDaAQyCdCY+LObAeD2NBlRrhmNxbxx+ecT8xGcRi9gQ471UA2 h6zWozWudrcxBITcnQ7Vq6eQSO65dveJL3eX9g0qvYfQ1vqPgH0ihoyWjR57t9mGdBQX wn8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721865; x=1695326665; 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=ZzCf4SxTDBS+/M86UxgHIAN1U8HQ8Zh8Ai7mVoDHpm0=; b=qKH1dIYHYi2OAfXY3gVHOFdUjWRvbq8FT5jEg012ZLUj7WhVz8gXSkgZMTAefYQQcK RQG2IptM4BrxF2bOWQ6yAygDuPN1gKN6GCCDXkEGF3VZO3oGEGV28L0CaPLUmx9kXCnM AlCbjx9gZ7Tz3n/8ngtDc0etAV++tcxFmkR+BerrSt4Cq227OZGovb96X/pPWCTnSYsI suZyE7Wt0fhmduJ/atfWpIDe+CnhgMUOyB6uJg3bhrscOVgZ0eIiSO7YjMgGwFL09sYL O1LU8PkXq3Z8pm2JGGsybsp+tjbz4RsXcP5Ae4uEc5EsOowIrmceUluNMXDm/8gWZ+eI EJQg== X-Gm-Message-State: AOJu0YxhbhCYoFHPzJjMxHe/HX9m3GIqABO2WeRqoU3WQtdNjnJUETM4 yyFqEBgBWU0kZQJPgXfIqwgdlouFIJM= X-Google-Smtp-Source: AGHT+IFOhTP03yszajhdw5NjTwa+Op8bFSwNWEBe2n7Xq4EKdRnhcfISriBLEi7J+xVFX8gfVSqKqA== X-Received: by 2002:a05:600c:2218:b0:401:be5a:989 with SMTP id z24-20020a05600c221800b00401be5a0989mr5223819wml.23.1694721864574; Thu, 14 Sep 2023 13:04:24 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:24 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Kyle Evans , Karim Taha Subject: [PATCH v4 14/23] bsd-user: Implement msync(2) Date: Thu, 14 Sep 2023 23:02:33 +0300 Message-ID: <20230914200242.20148-15-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 0f9e4a1d4b..5e885823a7 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 127805e079..859492dee7 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -499,6 +499,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 Thu Sep 14 20:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=S0xDzORK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpLr2HCkz1yhd for ; Fri, 15 Sep 2023 06:09:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa7-0003bt-3m; Thu, 14 Sep 2023 16:04:55 -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 1qgsa2-0003NV-7D for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001aA-FB for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:40 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-401b0d97850so14117935e9.2 for ; Thu, 14 Sep 2023 13:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721866; x=1695326666; 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=HvUkuMDUMC6zord5lIwDs3PjxQ4028j+e76aGZtjWv4=; b=S0xDzORKx4vtX/jWSdGvCmAfdJ/EKJsNM1DkbWvCK9/t3ggmU1Cxhsuj8p0jhfJIEz 2CWbdgETROqgrGDZKQIG7rVLdbQkPF67wV65rl9a5zc+MM7Gw3ExUXLj9NddpGl98ZD7 PKcbepGNMxMAZ/OX2qPyWAGwVuQCSr5bAyKy8Q+ZqrP+u0R+QyUNdlpnZQD/LNdP+MZN xsU7blRQM2h6As7Wl14wslLE9ZJdsabUt7ISq8cmGqfRpgqhZDhgmz8+/r5miLUNIFkh ZFNFItNkBvS1DtRfxx6NOl8Weh5k6g03/zFfi6QBXbQ7uuK3sV/j1kfvDtkn9KAj92nz aoRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721866; x=1695326666; 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=HvUkuMDUMC6zord5lIwDs3PjxQ4028j+e76aGZtjWv4=; b=WIjy4GoUvpndAKFpRQDckaosS4AhpeCEKmcWh5ePznLPYbQKR4Y+SFYhfO6ZfiAEO4 q2gOQOgS9ac+h1umS/PFcJM8QpHkN4Jds9jpZNPPVMnuQ960r5M1d92MYNrC3n9acQCG 3RO57wc5Rfn3rUzsyF/W0q7g70VO2TluVnzQv7WJlgT9drNJyhRVSHCwZAj/0Rem8ppM EV5b0q9/1StezafKjk5aeUUmw13IgFOXrB6pGiKsmtYSq8L3AvzkGnQCfxBNegXlHn8J cSPZcksNb9skcSIfbVSrNAx+l2RZi1DgoFwXnqZOs+BF05957qFy7tUngfyhlhY/9lUQ sSAw== X-Gm-Message-State: AOJu0YwpChdUTwjd4tYWXJMitZuYO8icdFht+mcnMRii+oQo/d3ZPPHE QwDHpeVSWLX6HQN4oW7Zpe/KWodRUO0= X-Google-Smtp-Source: AGHT+IGSsxB8qjTkn2tnZBOux9uk3Q5sW78jHTrpW/a5Yuvo8btyTwVUsgHJ2x+akG+8uDLVwcTTmg== X-Received: by 2002:a1c:770e:0:b0:3fb:b008:2003 with SMTP id t14-20020a1c770e000000b003fbb0082003mr5495692wmi.38.1694721865794; Thu, 14 Sep 2023 13:04:25 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:25 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 15/23] bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2) Date: Thu, 14 Sep 2023 23:02:34 +0300 Message-ID: <20230914200242.20148-16-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 5e885823a7..16c22593bf 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 859492dee7..6eaa705cd3 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -503,6 +503,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 Thu Sep 14 20:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=BfAnnPTw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpLD0SWdz1yhd for ; Fri, 15 Sep 2023 06:08:52 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa8-0003cS-0f; Thu, 14 Sep 2023 16:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsa2-0003NW-8U for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001aQ-ET for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:39 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401b5516104so14639535e9.2 for ; Thu, 14 Sep 2023 13:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721867; x=1695326667; 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=jCqdSZt4JHZhZf+YE8oxI5TH33W7XtN+wtVE9f1Vv5E=; b=BfAnnPTw5g7nCxIL0PYATur84DIZAfqcvFT/gYHF/rhfA0PevhCBWpkOlQvOTUnJ1m WixBYx4QEvMXReGSerCWrBaTNLSh0RQGRC9+0a1Q329vd4Z+lLMCRtGVZNTlJb4c8+3b cIvygUIbLD48iar94KtvV7nffEgjBO8vY3FClwMWxwHWFxDzVy3/EqVu+xdqQTM6EGrc hBDBFVXKrUG6vUd55Ho2rO15MwnJBUypYS11wNx8PCBuMkMGJFR1ysGlQyvkSb3TB4iW BUKee38gBqQUVdxD6XwkqMltuKT4EE9krPoeE8s/Xh2zENAz7ErToMB73oXWjHMojhho EFhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721867; x=1695326667; 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=jCqdSZt4JHZhZf+YE8oxI5TH33W7XtN+wtVE9f1Vv5E=; b=icDmx7YdZWwKFs3t0S7N00iod+F/VEC80pCaI8bhEIprna72mRNXPhUZMm1tHqw2GF C3JmpINdxLOEwU6ciGEZPZHO91lIbt4Ay46oxEkpxbb8W2um9oiCFjlsKmn5br52q1PQ wSKkvGS3jdmM3gsqa386Sv0kAf2YaYjZVJa4dr/P2EDWqhsDSR8Yrr8Xx0adcExlF1WG JrhFUrC7kw71zbhLp9H9Yhzy9Np0wQUUNxrhyLN6tlojK2xReq2hh+KnRnIYHHWqoDCc j4m5jZm0Y41PRJK1rwmm4IR3kwEZIoXNj+5Hukk1W2fp8fiGk+cYfDaJpm0uwBz+5hzo cPlA== X-Gm-Message-State: AOJu0Yxf1VY1HRM0Lc75TsmvxFMzr2uJYdyJkj2JzJLQE8vG98cyh7TY G/oWFRN1+6lOgqdGNIcoFReNJ29Q08g= X-Google-Smtp-Source: AGHT+IFtJ4l0FZHeGVpOp+mLBaazUPGCANnOqIQL2lPS684/TpvEVRuvw4MpNfEJZ7iaP3ZwPioJpg== X-Received: by 2002:a05:600c:5108:b0:404:746e:c601 with SMTP id o8-20020a05600c510800b00404746ec601mr1815733wms.9.1694721867025; Thu, 14 Sep 2023 13:04:27 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:26 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Karim Taha Subject: [PATCH v4 16/23] bsd-user: Implment madvise(2) to match the linux-user implementation. Date: Thu, 14 Sep 2023 23:02:35 +0300 Message-ID: <20230914200242.20148-17-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 16c22593bf..b00ab3aed8 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 6eaa705cd3..f5d60cf902 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -519,6 +519,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 074df7bdd6..76f4856009 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 Thu Sep 14 20:02:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=B3Dw5ymW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpJk2b1dz1yhd for ; Fri, 15 Sep 2023 06:07:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa6-0003XB-2d; Thu, 14 Sep 2023 16:04:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsa2-0003NT-68 for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001ai-Fx for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:41 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3ff1c397405so15051125e9.3 for ; Thu, 14 Sep 2023 13:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721869; x=1695326669; 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=ojwrDVKC7PwdcQ9eMVgezK92ZGwh+WReTfLF0rL9te8=; b=B3Dw5ymWgw6zvdj91zUbPfUCzMZfmE0ygnJJN2RciStB08W5mmyVHMOoLQHI6F7dsR FO53mk1qwloM9FC3jTU+w9rQS7NAG4IKbOQGAE7Jkx/7bOvc7jmgw+dyqqScIxqqyT5l 359gVtSH+feBVGTj68JUug8BwS206Y8Zj4RXvKTWgfzGYHzkQ5+ljpfNheghYZymds/g IKzVSI9eNXtzH6VFqOA0FMuxPLDlmx7FEiq5jK3oEscWRew77HmHYfT9O8EjuKH7/06B aHA4mqbhdhPzPG0+BSjhzpK6FXB7afIcnble82Ms6CHZd4NsPnH/7Wmn0+A7qEtaEffb Ksbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721869; x=1695326669; 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=ojwrDVKC7PwdcQ9eMVgezK92ZGwh+WReTfLF0rL9te8=; b=BBscdNCyT4TY6yIbFIzJHkiixiCBCJ6CUdsiXiDZuKZYyEYc+K8SSEQLhRwg9BfRhU yz2DBfo20GBhrhvcQvgVm/KRz6j/07Ry1jbbWHRbLeN+iGFKwfTBAycPbONC1UVYJ2D9 bOWyyV5Wlu3T8jRe+N1NRDnT5kj+tp2Ku/RqtBoa8MsbH+CQfLnT27LtWbHh6Vx2LigF zZ8mJeWNIECwJJ+cJ09c+AkSC23opNoYhM9sbdPZNvNwZ9M8d7IoRDiR5E3VkVZVhw0O ZBhNzywdn6w4T5U+6Yih7oBwj6giCTR12yMVlqLRfBu57zrhsLsCUaWZ+/LYfG8Uj+7E zJHA== X-Gm-Message-State: AOJu0YxO2MkOv7UR75TKCOVym4PGsTRoQc+508mbJtNK4lBG87ZiG/XX t5zXYcFXmRp7o96PtHUfxEAJ7vA1tng= X-Google-Smtp-Source: AGHT+IEzvjU/Uf2xyp4+TuNHqfKIdBYsVZv6NlJswxE/p8Pho53hdbVYh+PNjhrmP8AMtLHGaQpCWQ== X-Received: by 2002:a05:600c:1d1f:b0:404:6ed9:98d1 with SMTP id l31-20020a05600c1d1f00b004046ed998d1mr2415831wms.41.1694721868740; Thu, 14 Sep 2023 13:04:28 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:28 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 17/23] bsd-user: Implement mincore(2) Date: Thu, 14 Sep 2023 23:02:36 +0300 Message-ID: <20230914200242.20148-18-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 b00ab3aed8..0c8d96d9a4 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 f5d60cf902..8d1cf3b35c 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -527,6 +527,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 Thu Sep 14 20:02:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Q8IKBR9f; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpGD6sjBz1ypL for ; Fri, 15 Sep 2023 06:05:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa9-0003ds-39; Thu, 14 Sep 2023 16:04:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsa6-0003Y2-CH for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:54 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001b3-FJ for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:54 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-404571cbb8dso11883165e9.3 for ; Thu, 14 Sep 2023 13:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721870; x=1695326670; 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=AKVBP+OG1Owyy2sbH7+ilAAxCrqYViuNbwrbBHphySc=; b=Q8IKBR9fdIjpHNr/xbyjadjJG+GReuyZayEqgVFfG8/kqRUownZxzUfFKaosZUoLnb HMyVEMSJp9N5VCn1liEItn55tha+9ERV52RSExXcettJw+O/Jl+VMf0ZLjEYPhFhEVvp MBeqJi8xFfUT6wnvCilkFPpAOwdETFlawpDuFlgX2+SiYQ8EwWHw6f9oRVs9WDRGnycj FxMcciMpHNRVWBOZyDCcemXrqUC54V56oonehxIcFWr2pRlHv9H5oe8rDyves4Xk+g36 ouhaFI9EiMxKiIQIJJXFHE0klGfwt1aG22//rbdSGnrJoxqVZ/gPds4Q9793gO18zNur oESA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721870; x=1695326670; 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=AKVBP+OG1Owyy2sbH7+ilAAxCrqYViuNbwrbBHphySc=; b=bWjjyQxGqM6VTeq3hPSwHyV8EK0xRoYcWAnOgPA2HOSPTopNUzpvWO+x2JsJANBHJB TOlOLBk6gRrrGngs4irVb3JxmLNRtduBovM5vNKQNFJlx5E3SWEX7caDLAWPjU6LQxCo i4zNmlOf3uDIgPLnGSv1Omli48ETm2aiNBlPE1nNtwyLBKgUuMjDQZbns08a0LFkN//k uo9GWzNsm1O01+DQWKCgI/hWNKcvMw1TUODwUd1t6otM2V0XXCFFUwHgqMXMUVCuxhV1 Lth2pq2UCgli4lgIHPyfRMDL0kVWmrpCsXuXmecnvwa5tAH9n/FE5npqOstzu37tolOh GrXg== X-Gm-Message-State: AOJu0YyzfwAMlO20xGlbnhKbgZSJ0BixsK1L4++Kvy3wNqC5ySjJI1p7 zOzbTe6peSzFfyXprxuVKU5MnsOBZ9U= X-Google-Smtp-Source: AGHT+IEnQhSLjAUCwgrFJC9lsQc5nX5CtDbySG8kEk8ZNuN6CCRsVTzK0K/AXhbp/SZzg6gnvnhvuA== X-Received: by 2002:a05:600c:209:b0:401:bd2e:49f7 with SMTP id 9-20020a05600c020900b00401bd2e49f7mr5879050wmi.21.1694721869970; Thu, 14 Sep 2023 13:04:29 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:29 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 18/23] bsd-user: Implement do_obreak function Date: Thu, 14 Sep 2023 23:02:37 +0300 Message-ID: <20230914200242.20148-19-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x335.google.com X-Spam_score_int: -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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 0c8d96d9a4..b296c5c6f0 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 8d1cf3b35c..8dd29fddde 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -543,6 +543,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 Thu Sep 14 20:02:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=BgFqUM52; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpHy2crxz1yhd for ; Fri, 15 Sep 2023 06:06:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsZu-0003MJ-GM; Thu, 14 Sep 2023 16:04:42 -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 1qgsZr-0003IG-5d for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:39 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001ci-7M for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:38 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-404732a0700so10114135e9.0 for ; Thu, 14 Sep 2023 13:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721871; x=1695326671; 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=0VfkzU3g4TZJQAxsKU6UmdXYGb19ZcCTqRB08BetneE=; b=BgFqUM52x79XlccB8c/iFUEdKSijwmHSTq8zHXKhCldi+MKtpg8Hn9obSieOPyNbI+ APCzE7PJuxKS/YL3nSceiy7YGT2hsJw+ujCaDbDYmXtqE+lwnbWZ0zoVtS0zg07Wp2Fp 4FjPGtBLxgSbLiE6ToKo9tb7jBs3wUbm2hXIDnlwmT56vgqq1mn6JTnDawUN6mIaXDKr MZP5B0mLz2jdCMbkbktE9XKJ3s57uy4ruEcgn3S6jXzSwlCCx2wU/ha28c/pNwQNDaME /feWya1w8idojUB+Bi6nne0WCteUfW8m6B8xzJzDtEie+CNUZbj51juSGnEJVykVGAz5 xETw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721871; x=1695326671; 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=0VfkzU3g4TZJQAxsKU6UmdXYGb19ZcCTqRB08BetneE=; b=P2PMyKjXYhAARokKS54Gl8XHsdecN+QlFZwVa+WJ+nUOGjHq+7rTQ/67HO7y+EpUAE 9ZFk3GwggJLSzQtfnv37IanWlK2UqaWS5GbaU5DKBs/Qc+U0CqJRaoY7x2A2czH9XGKq 77X34b76xSBkSKPWacNADf0IoldAO4Z1g0lBNIXqQOtJAj7xfMaCnmkZoZZKHLhxinEl cjdOfGEiCT9YaYijHJHt/DrOjz/zH5M+BCpRwC1IURdxMdcCuJHoM78zLm01rFvA2jFK A27GlzqslsvnVaT/GfajhdIWt0IcO+CImlchLkQLL+/kE0GoplLPgnJptBzS+wRAzpuS QeIA== X-Gm-Message-State: AOJu0YxgPqeSaQJym87qtzGdETa09l5DE8gw42Ab/poQLiEaAbwFoyRr tnZhSGWO22HHOs0T6H+tIQbGWkkBOro= X-Google-Smtp-Source: AGHT+IHY519GyI5rQomek66FTnCq3GZrbFrJNS1wBApY7zWL9U+FPZ8cwNjXnCsRLg3ML+yxxre2qQ== X-Received: by 2002:a05:600c:21d2:b0:3fe:1b4e:c484 with SMTP id x18-20020a05600c21d200b003fe1b4ec484mr5410388wmj.5.1694721871366; Thu, 14 Sep 2023 13:04:31 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:31 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Kyle Evans , Karim Taha Subject: [PATCH v4 19/23] bsd-user: Implement shm_open(2) Date: Thu, 14 Sep 2023 23:02:38 +0300 Message-ID: <20230914200242.20148-20-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 b296c5c6f0..f8dc943c23 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 8dd29fddde..7404b0aa72 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -531,6 +531,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 Thu Sep 14 20:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834460 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=OWkKlVCm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpMZ59CDz1yhd for ; Fri, 15 Sep 2023 06:10:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa7-0003cA-5k; Thu, 14 Sep 2023 16:04:55 -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 1qgsa2-0003Na-8v for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001d0-Fo for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:41 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401da71b83cso15464215e9.2 for ; Thu, 14 Sep 2023 13:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721873; x=1695326673; 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=NS0DB5hX3kwUPaV4Xfxg8VuoBza3wbu8TrNIf4kL3mQ=; b=OWkKlVCmYjzls+5dyfaTyMcrxix0ODDGrWVfXVAC62XvAyKISmuKKZ/v7cjhIW/m6/ a6mrxhPcqpbaxDyM0c7B9u6BOIU1WhnS+gsoBKO+DA55m3OsyEipaSbM3I4nI3uAweRd Hzk+h1dCsrso0PViZv4O3gZG4Xh4R9l2XEvmdX3eRD7M8h6rwunQxygu1wNY0zVUQ3R4 +7huC9gvsjPC0TNJJd4ji9a6DOiegFSvDhBq/+9OaQ9PEk1R5nUJHMftM1COphtZR36I iZBAMzTu1kzKZI24RRFBnvnVkkYI70wRD8DnvmO2bsvWUg2MOlXYxqOyqqSzNJXXIjsY emzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721873; x=1695326673; 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=NS0DB5hX3kwUPaV4Xfxg8VuoBza3wbu8TrNIf4kL3mQ=; b=mJoTVEx2Dnx33NZahb6VlC1VjFRmlsYXQaq/MVR82b4tWgoD4/vgzwcjd25mxcuCuX 2B3ZdhS7+8KU5C51wO62ybKutDBOo4clICQfJMorCQ3+s5vxGHXy5l+1NCyy5oAm/up1 LcCCLyevTsO0suLSI/alk2IkHqOLp/EICbIyjtMDc5rVtXYJ2/wxSCSU5GekO3bbb64Q WSePcl2Vh3peJJoLe2xAZ/hP51Gs32ybMWP8pquIwS3HW0DNGdkXFVBpsiz5H9QuAwfr T+uiko9rJubCMMSvA85YZwkxKJ5QMAkOEwXYrIiTAMlG/23wIg21tkLOOJdR4cyadZLp C+IA== X-Gm-Message-State: AOJu0Yz+5w8A5plcH8s6ufs3AKHWLMIQkus9bbNsMkZBoA7MJRgz9b2z rl+tsHvXNVqXqTnLmn1h0JgB5XnkYXw= X-Google-Smtp-Source: AGHT+IH0TXPTbJEY7Yd7+Ij6Oi+o2PgnMj9A9r3rI6o9tqqmo5gHJwea/U917RRRgwcjaFFMAv5w6w== X-Received: by 2002:a05:600c:3410:b0:404:6ed7:e75a with SMTP id y16-20020a05600c341000b004046ed7e75amr2339625wmp.9.1694721872514; Thu, 14 Sep 2023 13:04:32 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:32 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 20/23] bsd-user: Implement shm_unlink(2) and shmget(2) Date: Thu, 14 Sep 2023 23:02:39 +0300 Message-ID: <20230914200242.20148-21-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Warner Losh Reviewed-by: Richard Henderson --- 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 f8dc943c23..c362cc07a3 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 7404b0aa72..52cca2300f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -547,6 +547,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 Thu Sep 14 20:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=egITy+79; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpGD5gwMz1yhd for ; Fri, 15 Sep 2023 06:05:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa6-0003XC-4q; Thu, 14 Sep 2023 16:04:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsa2-0003NS-5T for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZo-0001dH-Fi for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:40 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40413ccdd4cso7371515e9.0 for ; Thu, 14 Sep 2023 13:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721874; x=1695326674; 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=gaDpwPGKdn8R1xLqNYgEvaWAh41f4zZe7AF+G8lPpzs=; b=egITy+79LiUQvV7Wa9X3UJTbOWbJ09R6BKMZamg4cd/d4Ho5m8pJcOg1Ll84+z0ja7 aE/HGKwwc5itD2WkTecmG2s6BZTXBMs1RVMkyV27RWd3xrF90WZ6ANdYZ5Zd32ajKWze QCFRBBgMYfT/BNz28z7SkHIssEVfu16Kz4BiKe/W2c25rAS733UZ3bf0a4UFcU8zg0QJ gD9E+txp3nxw2YWxesaD/tzVoazyWHtDTnbDivzdDX1v7bDIG4CtQWrBNwF6+/OiJ1m5 lzw0XQ/9CDIN8jcCXNsEcqPFfQBJ5GJGwvOmXKrIW/ztXTMZh9rdu0mnHwTRmoro56f4 0+mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721874; x=1695326674; 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=gaDpwPGKdn8R1xLqNYgEvaWAh41f4zZe7AF+G8lPpzs=; b=he9fmMmzx0LZdY4YPZHBJSJFYf9NopowXQbsVUeBfBpOIgA/8HFjZ2Jikm2b0jxYgz BTKoPQ7mkgA0zNxUh0aAwUFYg2m9Qj7/UDKENPHrsjui4U2VHzFOeRrKr4mrjjv7gqXX EXIybQMoU1Kzj7n/6OFs2/K7q3cPrXDfKly7vgZkAsjDUVIGV/MtrB9aphELnZl8yzB1 CoLnSQhMI3j2GMW9mJrcR7NFXbVHg+CaiXmGO/Q18AxWIH2E9ljIzJOV1z4KD5hjx2PX 9f41GjJkomNTaCZM9CBbq9lKBZZYZRn9j63LtZHr2LfrnOdbxyiq/QjERq2IuacjMjBX d3cQ== X-Gm-Message-State: AOJu0Yw95Qc4xQ6VRb1uOVR54eNa3KOjVSezjwYUBJKwi0+pxbi91Wyv 1wPZlgICALRekWxWAepFKJiNB+tyH+k= X-Google-Smtp-Source: AGHT+IEESf78nalxTLaWV/be9wmI8p39z8Vufg9B0PBS++9vEizu97b38oqCLKAlfsdww72MLTiSww== X-Received: by 2002:adf:f48d:0:b0:31f:a09e:e951 with SMTP id l13-20020adff48d000000b0031fa09ee951mr2099179wro.25.1694721873829; Thu, 14 Sep 2023 13:04:33 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:33 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 21/23] bsd-user: Implement shmctl(2) Date: Thu, 14 Sep 2023 23:02:40 +0300 Message-ID: <20230914200242.20148-22-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 c362cc07a3..b82f3eaa25 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 52cca2300f..35f94f51fc 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -555,6 +555,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 Thu Sep 14 20:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=BihUyFRg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpLk1Wfjz1yhd for ; Fri, 15 Sep 2023 06:09:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa8-0003co-D6; Thu, 14 Sep 2023 16:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgsa2-0003Nc-9B for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZq-0001dW-S0 for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:41 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-402d0eda361so15334375e9.0 for ; Thu, 14 Sep 2023 13:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721875; x=1695326675; 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=EaFw0wTyfZ4LUB79LFq5+yljy9XZWuOika9FAzUT6Fk=; b=BihUyFRgwhwVVTzUVo5qeMhQYJHXwEBbb9pNt0Dh14lyV8WoHhbyZSKuxBeGnQ+3d+ /zaK/5WDEZ2veMRbfkgQVULvHwmF031AQfa60/3NO9BmqwU3+X+gLNSEjZeMtkTOm2rp Z5FOyn9rlpOuap9hGGfuKPn38J3hMjSjOly6lE9njW34DzGeN6Vq3BLVMJAtSRHDXmT7 QWEa/GsK72sm+rqO9isQuXpm5gJJpCO6l4KA0Snj6XBbYcoL6aWx9a5R6ksH5A+CAW// d5GqOFbH88LBGwqHXVgSXP8Hx/jjGqUhuXGtGnQyXVHNeqz3tBNCZaPuKUrrd+bV2HVI 9JhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721875; x=1695326675; 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=EaFw0wTyfZ4LUB79LFq5+yljy9XZWuOika9FAzUT6Fk=; b=BwnUyN33VwPKuf93BJ1jOsscYXSRJwiy9YFRSwpzGpNe7Sr11WNo4uCN5pwhXAtN9c JMR4fZENuEbtAjaNIu02E590onZGwH2tzm4s/4DsWHYHQQV6weM5J0na6N/PJD9/ufhK nEAR+7HO0r9x8Yr7ykbMMPHjBruOwcs6gRSH8JRoE63qyqXJ0mBbdxw2NpqyrsQ+aON3 dEZ5e6NsKLlz4coxHwzHQvsufSqI9pO3KFJ8oDqfccwmbygpNBcO0KQDKbBjibD26+jH kOPSm3q9ORmP9nf2ys8U0P/FTI5c17FruYHG25YupZXog5TIz7WBtmsAt7SXVySJmbfT 1QRA== X-Gm-Message-State: AOJu0YwtbowSDBqsz0I5xuphsSjsR2CVgdSXKwroZTqKo1Um0g0oiQcU 0vwNV16RS05IHkPAFfumOw+PCZ6p2Sk= X-Google-Smtp-Source: AGHT+IHbs7yORKBvavyKIrvhZDyYq6WvGnvhzMdJe6lHAvskqqsg0JX9ZWL2Debk99l/Z14qVCj/0g== X-Received: by 2002:a7b:cb96:0:b0:402:98cd:a3e9 with SMTP id m22-20020a7bcb96000000b0040298cda3e9mr5471727wmi.32.1694721875127; Thu, 14 Sep 2023 13:04:35 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:34 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Stacey Son , Karim Taha Subject: [PATCH v4 22/23] bsd-user: Implement shmat(2) and shmdt(2) Date: Thu, 14 Sep 2023 23:02:41 +0300 Message-ID: <20230914200242.20148-23-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 b82f3eaa25..c512a4e375 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 35f94f51fc..fe0968773e 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -559,6 +559,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 8e148a2ea3..3ef11b2807 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 6724bb9f0a..e9499b8dac 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -234,6 +234,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 Thu Sep 14 20:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1834461 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=oEx3dN97; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RmpMZ5wgkz1ypL for ; Fri, 15 Sep 2023 06:10:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgsa7-0003cJ-PZ; Thu, 14 Sep 2023 16:04:55 -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 1qgsa2-0003Nb-92 for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:50 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgsZq-0001e8-SM for qemu-devel@nongnu.org; Thu, 14 Sep 2023 16:04:44 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40472f9db24so10299005e9.2 for ; Thu, 14 Sep 2023 13:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694721876; x=1695326676; 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=OJDoqCnf4TN8wQwqqwufdbynxXMjm684U/3NF9ubcCc=; b=oEx3dN97heX+5h6/5ljvKAMVp0n+8u+hjYGVEXgZnvHqyW7c1fh5M8pf5Fj4nb2iSz Q8TOHlVryh8LUzkh+/8fIRhROfaSiYh4XgD1HdnvKuMou9pEuc7EpBs5cPWdHainxNU2 X+lvMco47zq94KDZpFZnXGRBCZrGIeZOlsYUfyRTVnK7pPmT0tYGMpzMDjW1ADxcchUz ztIkuNCe38EIOTk0dNsu17aPslS0rKGRMGqkZZPw3xiFf4n6yeqLXd7axRU2MaAL4XIs z5R63JQdOA8cRIaayAaw/dVwvOQnGURbx23GoKAiGfATMXmOMEow58+jjQ8BROK56IcI VAFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694721876; x=1695326676; 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=OJDoqCnf4TN8wQwqqwufdbynxXMjm684U/3NF9ubcCc=; b=Gx5ZGo4+kziDGhrrMvDWsZLFWlwwyoNIpeyrvIjTH5cI+kTDLgD6zfzQBueyufNRpJ 07B15h8R9Srg9CehC5i3Z1S44mdeTwDc/zyRLJeJL9491pZUXttMcx+adZZwvPEw5Wx9 8xbtpy2DWNkXNRT1A5L3CdRY7epfYi6qiXs98KVyXiHqSkftKiKqcPYDyDC9sFkaCZwX 3QZghjH8/fRBHZl94IqLDGogcNWCVDgRUAunMcwSRNHKnLlB7gg2WImvf+sxOzJg2Q1n Huk7+XZhV/XBK+DbTHHjvTcY1PgZw1q1oy9aTdUjLaH5m78mdON8PwcWolpM0lt4ObGU a6Mw== X-Gm-Message-State: AOJu0YwN7Idj+Tta+paPZaGwu+HUA4DnsiSveZTLdCg12pX10SzyA3B8 +3rqlk7P+74Ipvi2oLcu6s+ZXec96l0= X-Google-Smtp-Source: AGHT+IEjzEJTBBQ+fr1/8SJAr6yEXRB+/C0fsW+aONBDBhoOy90B1LonJWPXQ0Z/zwRBDVj1XaIyCw== X-Received: by 2002:a05:600c:152:b0:401:b204:3b97 with SMTP id w18-20020a05600c015200b00401b2043b97mr5313268wmm.4.1694721876361; Thu, 14 Sep 2023 13:04:36 -0700 (PDT) Received: from karim.my.domain ([197.39.44.105]) by smtp.gmail.com with ESMTPSA id z7-20020a7bc7c7000000b00402bda974ddsm2851130wmk.6.2023.09.14.13.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:04:36 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Richard Henderson , Karim Taha Subject: [PATCH v4 23/23] bsd-user: Add stubs for vadvise(), sbrk() and sstk() Date: Thu, 14 Sep 2023 23:02:42 +0300 Message-ID: <20230914200242.20148-24-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914200242.20148-1-kariem.taha2.7@gmail.com> References: <20230914200242.20148-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Warner Losh The above system calls are not supported by qemu. Signed-off-by: Warner Losh Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- 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 c512a4e375..c3e72e3b86 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 fe0968773e..9647249e90 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -567,6 +567,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 */