From nobody Tue Feb 10 16:22:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682054755; cv=none; d=zohomail.com; s=zohoarc; b=kEDMwfI/cUvIQD4v0Iv5Pwnpss28cC6hKvEHW98pg3Jnzzaoc/wfBMmHm6emvKBasfebMKBmJ3vByAQdsXHH+GT1FFF7Dhu/WBJwOpnFqU94bDNer3uGlyPrifQI0bCXYNxgy81rhxFol2o8JNd9/YAF10IkEJQk73dNzkFDRts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682054755; 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=3lQaR096+sc4caJncvJXkc2T1m9o0J7Vaiq2/oUFZec=; b=elxaBlDMMfJOHszA9TdMcD4SJEalCtnUc3pEqOtQ+43lOCb4xmdMj+78kSD4BT1KGug0zy6tEvUowX46LlNuDLt90HFl/m82BZxndVQJZ4gISFwFpO6z54c4zlw8LpBWbpsGFs9GYpHz8Cy/ipGwOy+m8NK0aGRdO0bJuMXYsBM= 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 1682054755868889.5208990486914; Thu, 20 Apr 2023 22:25:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppjFl-0003Vt-K4; Fri, 21 Apr 2023 01:24:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppjFj-0003U7-JU for qemu-devel@nongnu.org; Fri, 21 Apr 2023 01:24:11 -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 1ppjFh-0001fq-PV for qemu-devel@nongnu.org; Fri, 21 Apr 2023 01:24:11 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f17b967bfbso36710575e9.1 for ; Thu, 20 Apr 2023 22:24:09 -0700 (PDT) Received: from karim.my.domain ([197.39.145.151]) by smtp.gmail.com with ESMTPSA id t13-20020a7bc3cd000000b003f173c566b5sm3813475wmj.5.2023.04.20.22.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 22:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682054648; x=1684646648; 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=3lQaR096+sc4caJncvJXkc2T1m9o0J7Vaiq2/oUFZec=; b=eSiH+5hG5mvo0jKVzuLl3EWsG2cepZj3GpA0rUo2xjec4fFDrOaqELXKi7qkDnxMeF MslyyMXPxZ+N/t0NT3CyBLQxO9deC4Cr+4uDqL9a4Z23i1i2HqU65el7cAZivFKdmikQ twFkfzCYN/9SkuL1AN5ZaX5UUZYXCgY+lUK+B+FUITQyXY4Mond57mhTy3bryYcH3WG/ MqgCjFRrSYwWcAomZcYTE7pHRQ+/xHpQXsdvo0UzNWOgznW/DzCaqTh1jWjpYX+d+WZ7 QhszU9qyevGhW0RC6a4Va9mcJwMsobL2Y5maKYwMqntOJUKcjySh7Y3dI5mbw9/thdh/ 0+qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682054648; x=1684646648; 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=3lQaR096+sc4caJncvJXkc2T1m9o0J7Vaiq2/oUFZec=; b=YZXY0p3h1fYEl+28wRE9Q2ZElZ+LAg5ilWVZnKf80yjWNKb75YuDLPJwKJewQMfUVj jEt4KWXnOdhW19P3KI1YASFsQP9Zhfw9KCzfIonbqneiViHV94axhwFyxVjw3U6xLso4 opv3D2of9YpJhu9P1bWPoud+IbPv1m7rld0ecB4ReZrSQcBoCDCP4Vsv5IPs+87oOC4S UH995fyOaBPJggUIGvxdFRQlTS6PzoT6gyic4KnHdkWVTwcFP61sm2F+LFUuzuPt3U7L adBVo+YfKSPvtxvWc/aZ/ZPARPpW3crtZhtZ/3/lvUaTOipn6Dm6OfIWlLuezcSxhOtO BkMw== X-Gm-Message-State: AAQBX9fmfUCce2Y67qYkscl/AnisOrkFinOk/TrvQMTk+ZlxECB1eBgw qRh14Ue9cyr9WLZJSTQG4SI27lUE+54= X-Google-Smtp-Source: AKy350bzqovWwvK5WzoTUI4LJ8cRv0qCOSeuCZ6tH8/QfxPckuiWhpFIl0ipPKRbPlK7DeShLD2P0g== X-Received: by 2002:a7b:c8c4:0:b0:3ee:1084:aa79 with SMTP id f4-20020a7bc8c4000000b003ee1084aa79mr688209wml.20.1682054647722; Thu, 20 Apr 2023 22:24:07 -0700 (PDT) From: Karim Taha X-Google-Original-From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Stacey Son Subject: [PATCH 05/11] Signed-off-by: Karim Taha Date: Fri, 21 Apr 2023 07:22:49 +0200 Message-Id: <20230421052255.5603-6-krm.taha@outlook.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230421052255.5603-1-krm.taha@outlook.com> References: <20230421052255.5603-1-krm.taha@outlook.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::331; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682054758048100003 Content-Type: text/plain; charset="utf-8" From: Stacey Son add bsd-user/bsd-socket.c, which contains the actual definitions of the socket conversion functions. --- bsd-user/bsd-socket.c | 108 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 bsd-user/bsd-socket.c diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 0000000000..8a5e44444d --- /dev/null +++ b/bsd-user/bsd-socket.c @@ -0,0 +1,108 @@ +/* + * BSD socket system call related helpers + * + * 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 +#include +#include +#include + +#include "qemu.h" +#include "qemu-bsd.h" + +/* + * socket conversion + */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_a= ddr, + socklen_t len) +{ + const socklen_t unix_maxlen =3D sizeof(struct sockaddr_un); + sa_family_t sa_family; + struct target_sockaddr *target_saddr; + + target_saddr =3D lock_user(VERIFY_READ, target_addr, len, 1); + if (target_saddr =3D=3D 0) { + return -TARGET_EFAULT; + } + + sa_family =3D target_saddr->sa_family; + + /* + * Oops. The caller might send a incomplete sun_path; sun_path + * must be terminated by \0 (see the manual page), but unfortunately + * it is quite common to specify sockaddr_un length as + * "strlen(x->sun_path)" while it should be "strlen(...) + 1". We will + * fix that here if needed. + */ + if (target_saddr->sa_family =3D=3D AF_UNIX) { + if (len < unix_maxlen && len > 0) { + char *cp =3D (char *)target_saddr; + + if (cp[len - 1] && !cp[len]) { + len++; + } + } + if (len > unix_maxlen) { + len =3D unix_maxlen; + } + } + + memcpy(addr, target_saddr, len); + addr->sa_family =3D sa_family; /* type uint8_t */ + addr->sa_len =3D target_saddr->sa_len; /* type uint8_t */ + unlock_user(target_saddr, target_addr, 0); + + return 0; +} + +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *a= ddr, + socklen_t len) +{ + struct target_sockaddr *target_saddr; + + target_saddr =3D lock_user(VERIFY_WRITE, target_addr, len, 0); + if (target_saddr =3D=3D 0) { + return -TARGET_EFAULT; + } + memcpy(target_saddr, addr, len); + target_saddr->sa_family =3D addr->sa_family; /* type uint8_t */ + target_saddr->sa_len =3D addr->sa_len; /* type uint8_t */ + unlock_user(target_saddr, target_addr, len); + + return 0; +} + +abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, abi_ulong target_a= ddr, + socklen_t len) +{ + struct target_ip_mreqn *target_smreqn; + + target_smreqn =3D lock_user(VERIFY_READ, target_addr, len, 1); + if (target_smreqn =3D=3D 0) { + return -TARGET_EFAULT; + } + mreqn->imr_multiaddr.s_addr =3D target_smreqn->imr_multiaddr.s_addr; + mreqn->imr_address.s_addr =3D target_smreqn->imr_address.s_addr; + if (len =3D=3D sizeof(struct target_ip_mreqn)) { + mreqn->imr_ifindex =3D tswapal(target_smreqn->imr_ifindex); + } + unlock_user(target_smreqn, target_addr, 0); + + return 0; +} --=20 2.40.0