From nobody Thu Nov 28 11:00:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694234140; cv=none; d=zohomail.com; s=zohoarc; b=aV1ACjeQb9y1Z5Kg8Tgs+gkB75/m76G7ZVOeEvgokDaJY0zsW83ohhzJgdaWRcmOXXOrBxCU8bvAb99XYbJmGrJq+5aNlnd3SFQVVvfanjC9VlcKml/MJ7Hyzj+/e2iMQaoy5Z1l9sQ4OfnWlis8yQu/PZRhha7MlUfrbRnl0nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694234140; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hvIIhsiuBvf1kndCBMcjJtgubDA4YhP3ZHmk+jfqh6c=; b=PcywkdsJCSJmSqlUczcsHZyKMiEceaKFnnzofNbIn/+O64Upl+N/OokEM8vRkWPh4to0dPRhh3p2r3aOQXXDbQ0erPsWRkwi0cwIqBSefu+r9/yKdtVW1nqAP5Yg8Z4mm31zuM1dUwCyeLqsn1L7hcLZOJTb5yyvoxFe3oPQjq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694234140388408.4185605065936; Fri, 8 Sep 2023 21:35:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qepfz-0001Aw-PH; Sat, 09 Sep 2023 00:34:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qepfu-0001AJ-RN for qemu-devel@nongnu.org; Sat, 09 Sep 2023 00:34:28 -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 1qepfX-00030M-Df for qemu-devel@nongnu.org; Sat, 09 Sep 2023 00:34:26 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-400a087b0bfso28349795e9.2 for ; Fri, 08 Sep 2023 21:34:02 -0700 (PDT) Received: from karim.my.domain ([197.39.120.250]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0031981c500aasm3615102wrp.25.2023.09.08.21.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 21:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694234041; x=1694838841; 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=hvIIhsiuBvf1kndCBMcjJtgubDA4YhP3ZHmk+jfqh6c=; b=A3ObypMhVqpGOoE92M5Wd8u8gLA/A/qok3ZRJdvqaVkfkZDi8SZjlk06vI0KH8Xr6o puPFRJ/2n9NtUAODQ0OkxpmMnAXIcNxQdqrdvXGgbcePAD8I2BTrTOVZaJr7GFKITNnq FW6SZJvTgIUKXGp8eakJdtcIDVxzeq2F489SbxCaCnwZ19C6rPWkSCIRzkRqx8E2Bpyy 2nX0aDtulu6+sDkX8K52XvM+gw36HNFvO/MUk6DztCuRLqZY4hqo+aPuUGwA8K0XQBE7 zn8s4lOEqzvLklbVQBN6GKUwSLik9mXheFWwp8Xla4By6PhY9GXxaOkeZplhxv3urxOQ H9Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694234041; x=1694838841; 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=hvIIhsiuBvf1kndCBMcjJtgubDA4YhP3ZHmk+jfqh6c=; b=ZMTi9VDefZZfxCO9SZkFManT9XJgiTIX2K53ktLeK0k+LGFJKb7NlSDgyE6kNwnCBe X9dx5YRVQttgEAQU3fv4GOYcNGoEmUpj9b4bu/UdEYCLFhIgoyL8j+Zdec2uYaOvZaP7 JlEt3GY7nBQeV6wmQsvBCJG/G7Kko0/nQ0UmlEus2TEl0mBdwZRYeopd49QI3FYeOPCL oNWl5iCZqclxcWk0mwo2txwxmYGd0BmSHumQEkCoaEH5aQhcFO0cqX6CMdWGTdkxb+7D 1fjjVS0+ACjs+oblhh+oj1Uhq6nDx9ZVY7Q+TEikWns2hj4YqueVIw7+3t2o58CilAHS TnOw== X-Gm-Message-State: AOJu0YwUUzFiAELRrfifMHENfQs75BdqyTKDLZfIoy7Yg1SQAZQ5Ycy/ VjNsQ1UjUPl4Q2SAOmanDL7y74sGiTU= X-Google-Smtp-Source: AGHT+IErZsCrUGciBlUi7O337nWE78kz1j/ssxA2xX4XLYI9hheG8o059gqnoodtVQiSmYbkvqWeUA== X-Received: by 2002:a05:600c:3b8d:b0:403:31a:77b9 with SMTP id n13-20020a05600c3b8d00b00403031a77b9mr444107wms.37.1694234040953; Fri, 08 Sep 2023 21:34:00 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Stacey Son , Karim Taha Subject: [PATCH v2 22/23] bsd-user: Implement shmat(2) and shmdt(2) Date: Thu, 7 Sep 2023 09:43:01 +0200 Message-ID: <20230907074302.79234-23-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230907074302.79234-1-kariem.taha2.7@gmail.com> References: <20230907074302.79234-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_24_48=1.34, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694234141511100001 Content-Type: text/plain; charset="utf-8" From: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Karim Taha --- bsd-user/bsd-mem.h | 76 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++ 2 files changed, 84 insertions(+) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index dd506b8a15..c01b009326 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -337,4 +337,80 @@ static inline abi_long do_bsd_shmctl(abi_long shmid, a= bi_long cmd, return ret; } =20 +/* shmat(2) */ +static inline abi_long do_bsd_shmat(int shmid, abi_ulong shmaddr, int shmf= lg) +{ + abi_ulong raddr; + abi_long ret; + void *host_raddr; + struct shmid_ds shm_info; + int i; + + /* Find out the length of the shared memory segment. */ + ret =3D 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; + } + + mmap_lock(); + + if (shmaddr) { + host_raddr =3D shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); + } else { + abi_ulong mmap_start; + + mmap_start =3D mmap_find_vma(0, shm_info.shm_segsz); + + if (mmap_start =3D=3D -1) { + errno =3D ENOMEM; + host_raddr =3D (void *)-1; + } else { + host_raddr =3D shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + } + + if (host_raddr =3D=3D (void *)-1) { + mmap_unlock(); + return get_errno((long)host_raddr); + } + raddr =3D h2g((unsigned long)host_raddr); + + page_set_flags(raddr, raddr + shm_info.shm_segsz, + PAGE_VALID | PAGE_READ | ((shmflg & SHM_RDONLY) ? 0 : PAGE_WRITE)); + + for (i =3D 0; i < N_BSD_SHM_REGIONS; i++) { + if (bsd_shm_regions[i].start =3D=3D 0) { + bsd_shm_regions[i].start =3D raddr; + bsd_shm_regions[i].size =3D shm_info.shm_segsz; + break; + } + } + + mmap_unlock(); + return raddr; +} + +/* shmdt(2) */ +static inline abi_long do_bsd_shmdt(abi_ulong shmaddr) +{ + int i; + + for (i =3D 0; i < N_BSD_SHM_REGIONS; ++i) { + if (bsd_shm_regions[i].start =3D=3D shmaddr) { + bsd_shm_regions[i].start =3D 0; + page_set_flags(shmaddr, + shmaddr + bsd_shm_regions[i].size, 0); + break; + } + } + + return get_errno(shmdt(g2h_untagged(shmaddr))); +} + #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 =3D do_bsd_shmctl(arg1, arg2, arg3); break; =20 + case TARGET_FREEBSD_NR_shmat: /* shmat(2) */ + ret =3D do_bsd_shmat(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_shmdt: /* shmdt(2) */ + ret =3D do_bsd_shmdt(arg1); + break; + /* * Misc */ --=20 2.42.0