From patchwork Wed Jun 7 16:47:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeqi Fu X-Patchwork-Id: 1791828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=aRuXFbH2; dkim-atps=neutral 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 4QbtnF2GFnz20QH for ; Thu, 8 Jun 2023 02:57:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6wSr-0008Ci-19; Wed, 07 Jun 2023 12:56:53 -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 1q6wSp-0008CL-I2 for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:56:51 -0400 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6wSj-0001k1-J4 for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:56:51 -0400 Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-62884fa0e53so46043816d6.0 for ; Wed, 07 Jun 2023 09:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686157004; x=1688749004; 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=HWq+po+SDANNoW47p4QL7IvACAQogmmtb9TL/tLcPBU=; b=aRuXFbH2BdDozt/mll+og22h3lnOt6mo6YSk37w83d+wBqhcaGXxi2+2vyShnDYmOb WEB6N4q001Qk4lEMZWhClNB7nxEkobTbL14mo+IipkZpiUvvLaH4vOWT6UXI1eQGCH3S SGlCA7clQARh5aU/kPPXrUhZ8W8OxaUVSNb1vZNOvsdoSbi0WybfW87g6FaZWtMCI8pG jZDvQl+p0Fq5oDNJSTqB9UCnAEyus61RT6IqIfdofQsNNLx9ErcGp53STBISJVnPsmKm BHDtOTjkLLEC8FkBYdrB8yDwV81XaPqHlUpy5nB55Bawz7II3gp4N6mbHrbVUQ+MMtGu YRqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686157004; x=1688749004; 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=HWq+po+SDANNoW47p4QL7IvACAQogmmtb9TL/tLcPBU=; b=JBNwP48H6SiN7b1vgcc9FJTeyF0bjwqSoc75XykP6dSb7kd5q7GTpFieL/8ZVVVY4d XgIYKPLQNuSQ0a+Oe687Xnufk+RLQD1cJdSb+fVxxs8A5IRA4PkjXf7u/0qG3TFex9eC tgrxleeXFL99jRlu5y5VCWN9AjZNDvuC18ALOkYZuhD36WGDNkJxnJu1kdcFCBa7m3Mi ukNB2mJW7KlnjgQOu5eiEgiDiaR/l5gbPrBEZfFUxU0XXL5OuhKQtIUHEsC1sJn+BCTH Edh4H4igON3iDZ4HEZfuxaDL7mn3bGzYDagliIEJGgI8GcmF2ZQp8+iJOmWx2uyoU+CS pcCQ== X-Gm-Message-State: AC+VfDytwrffccfGpdwAjg1GDpe30OX+yQZhcSoGm++AFb5SXZDZenSg j53eUvmqhSjq1SP4DeWZ2pL3HGAHlNLen1OG+PY= X-Google-Smtp-Source: ACHHUZ7ioIFEGFtetFPNwci8sUmDsD7HPjZF2OWqZe0XecHOiip7QbddPmLFrg34pUFo0KcBYpNZXw== X-Received: by 2002:a17:90b:e15:b0:256:bc6c:cb5b with SMTP id ge21-20020a17090b0e1500b00256bc6ccb5bmr1874346pjb.33.1686156551355; Wed, 07 Jun 2023 09:49:11 -0700 (PDT) Received: from localhost.localdomain ([223.104.40.226]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b00250bf8495b3sm1671808pja.39.2023.06.07.09.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 09:49:11 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Paolo Bonzini , Thomas Huth , Riku Voipio , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC v2 1/6] build: Add configure options for native calls Date: Thu, 8 Jun 2023 00:47:45 +0800 Message-Id: <20230607164750.829586-2-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> References: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f29; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-qv1-xf29.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yeqi Fu --- Makefile | 4 +++ common-user/native/Makefile.include | 9 ++++++ common-user/native/Makefile.target | 22 +++++++++++++ configure | 50 +++++++++++++++++++++++++++++ docs/devel/build-system.rst | 4 +++ meson.build | 8 +++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 4 +++ 8 files changed, 103 insertions(+) create mode 100644 common-user/native/Makefile.include create mode 100644 common-user/native/Makefile.target diff --git a/Makefile b/Makefile index 3c7d67142f..923da109bf 100644 --- a/Makefile +++ b/Makefile @@ -185,6 +185,10 @@ SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) include $(SRC_PATH)/tests/Makefile.include +ifeq ($(CONFIG_USER_NATIVE),y) + include $(SRC_PATH)/common-user/native/Makefile.include +endif + all: recurse-all ROMS_RULES=$(foreach t, all clean distclean, $(addsuffix /$(t), $(ROMS))) diff --git a/common-user/native/Makefile.include b/common-user/native/Makefile.include new file mode 100644 index 0000000000..40d20bcd4c --- /dev/null +++ b/common-user/native/Makefile.include @@ -0,0 +1,9 @@ +.PHONY: build-native +build-native: $(NATIVE_TARGETS:%=build-native-library-%) +$(NATIVE_TARGETS:%=build-native-library-%): build-native-library-%: + $(call quiet-command, \ + $(MAKE) -C common-user/native/$* $(SUBDIR_MAKEFLAGS), \ + "BUILD","$* native library") +# endif + +all: build-native diff --git a/common-user/native/Makefile.target b/common-user/native/Makefile.target new file mode 100644 index 0000000000..1038367b37 --- /dev/null +++ b/common-user/native/Makefile.target @@ -0,0 +1,22 @@ +# -*- Mode: makefile -*- +# +# Library for native calls +# + +all: +-include ../config-host.mak +-include config-target.mak + +CFLAGS+=-I$(SRC_PATH)/include -O1 -fPIC -shared -fno-stack-protector +LDFLAGS+= + +SRC = $(SRC_PATH)/common-user/native/libnative.c +TARGET = libnative.so + +all: $(TARGET) + +$(TARGET): $(SRC) + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) + +clean: + rm -f $(TARGET) diff --git a/configure b/configure index 2a556d14c9..cc94d10c98 100755 --- a/configure +++ b/configure @@ -275,6 +275,7 @@ use_containers="yes" gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb") gdb_arches="" werror="" +user_native_call="disabled" # Don't accept a target_list environment variable. unset target_list @@ -787,6 +788,10 @@ for opt do ;; --disable-vfio-user-server) vfio_user_server="disabled" ;; + --enable-user-native-call) user_native_call="enabled" + ;; + --disable-user-native-call) user_native_call="disabled" + ;; # everything else has the same name in configure and meson --*) meson_option_parse "$opt" "$optarg" ;; @@ -1898,6 +1903,50 @@ if test "$tcg" = "enabled"; then fi ) +# common-user/native configuration +native_flag_i386="-DTARGET_I386" +native_flag_x86_64="-DTARGET_X86_64" +native_flag_mips="-DTARGET_MIPS" +native_flag_mips64="-DTARGET_MIPS64" +native_flag_arm="-DTARGET_ARM" +native_flag_aarch64="-DTARGET_AARCH64" + +(config_host_mak=common-user/native/config-host.mak +mkdir -p common-user/native +echo "# Automatically generated by configure - do not modify" > $config_host_mak +echo "SRC_PATH=$source_path" >> $config_host_mak +echo "HOST_CC=$host_cc" >> $config_host_mak + +native_targets= +for target in $target_list; do + arch=${target%%-*} + + case $target in + *-linux-user|*-bsd-user) + if probe_target_compiler $target || test -n "$container_image"; then + mkdir -p "common-user/native/$target" + config_target_mak=common-user/native/$target/config-target.mak + ln -sf "$source_path/common-user/native/Makefile.target" "common-user/native/$target/Makefile" + echo "# Automatically generated by configure - do not modify" > "$config_target_mak" + echo "TARGET_NAME=$arch" >> "$config_target_mak" + echo "TARGET=$target" >> "$config_target_mak" + eval "target_native_flag=\${native_flag_$target_arch}" + target_cflags="$target_cflags $target_native_flag" + write_target_makefile "build-native-library-$target" >> "$config_target_mak" + native_targets="$native_targets $target" + fi + ;; + esac +done + +# if native enabled +if test "$user_native_call" = "enabled"; then + echo "CONFIG_USER_NATIVE=y" >> config-host.mak + echo "NATIVE_TARGETS=$native_targets" >> config-host.mak + +fi +) + if test "$skip_meson" = no; then cross="config-meson.cross.new" meson_quote() { @@ -1980,6 +2029,7 @@ if test "$skip_meson" = no; then test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd" test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg" test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server" + test "$user_native_call" != auto && meson_option_add "-Duser_native_call=$user_native_call" run_meson() { NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path" } diff --git a/docs/devel/build-system.rst b/docs/devel/build-system.rst index 551c5a5ac0..05cfa8a21a 100644 --- a/docs/devel/build-system.rst +++ b/docs/devel/build-system.rst @@ -494,6 +494,10 @@ Built by configure: Configuration variables used to build the firmware and TCG tests, including paths to cross compilation toolchains. +``common-user/native/config-host.mak``, ``common-user/native/*/config-target.mak`` + Configuration variables used to build the native call libraries + including paths to cross compilation toolchains. + ``pyvenv`` A Python virtual environment that is used for all Python code running diff --git a/meson.build b/meson.build index 0a5cdefd4d..04e99a4f25 100644 --- a/meson.build +++ b/meson.build @@ -2012,6 +2012,11 @@ have_virtfs_proxy_helper = get_option('virtfs_proxy_helper') \ .require(libcap_ng.found(), error_message: 'the virtfs proxy helper requires libcap-ng') \ .allowed() +have_user_native_call = get_option('user_native_call') \ + .require(have_user, error_message: 'user_native_call requires user') \ + .require(targetos == 'linux', error_message: 'user_native_call requires Linux') \ + .allowed() + if get_option('block_drv_ro_whitelist') == '' config_host_data.set('CONFIG_BDRV_RO_WHITELIST', '') else @@ -2853,6 +2858,9 @@ foreach target : target_dirs error('Target @0@ is only available on a Linux host'.format(target)) endif config_target += { 'CONFIG_LINUX_USER': 'y' } + if have_user_native_call + config_target += { 'CONFIG_USER_NATIVE_CALL': 'y' } + endif elif target.endswith('bsd-user') if 'CONFIG_BSD' not in config_host if default_targets diff --git a/meson_options.txt b/meson_options.txt index 90237389e2..57035e02f5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -352,3 +352,5 @@ option('slirp_smbd', type : 'feature', value : 'auto', option('hexagon_idef_parser', type : 'boolean', value : true, description: 'use idef-parser to automatically generate TCG code for the Hexagon frontend') +option('user_native_call', type : 'feature', value : 'disabled', + description: 'native bypass for library calls in user mode only') diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 5714fd93d9..9eda1898d6 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -173,6 +173,8 @@ meson_options_help() { printf "%s\n" ' tpm TPM support' printf "%s\n" ' u2f U2F emulation support' printf "%s\n" ' usb-redir libusbredir support' + printf "%s\n" ' user-native-call' + printf "%s\n" ' native bypass for library calls in user mode only' printf "%s\n" ' vde vde network backend support' printf "%s\n" ' vdi vdi image format support' printf "%s\n" ' vduse-blk-export' @@ -472,6 +474,8 @@ _meson_option_parse() { --disable-u2f) printf "%s" -Du2f=disabled ;; --enable-usb-redir) printf "%s" -Dusb_redir=enabled ;; --disable-usb-redir) printf "%s" -Dusb_redir=disabled ;; + --enable-user-native-call) printf "%s" -Duser_native_call=enabled ;; + --disable-user-native-call) printf "%s" -Duser_native_call=disabled ;; --enable-vde) printf "%s" -Dvde=enabled ;; --disable-vde) printf "%s" -Dvde=disabled ;; --enable-vdi) printf "%s" -Dvdi=enabled ;; From patchwork Wed Jun 7 16:47:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeqi Fu X-Patchwork-Id: 1791829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=YjXdW8L5; dkim-atps=neutral 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 4QbtnG32h3z20QH for ; Thu, 8 Jun 2023 02:57:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6wTP-0000BX-6E; Wed, 07 Jun 2023 12:57:27 -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 1q6wTH-0008Ox-Ff for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:57:22 -0400 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6wTF-0001nO-Vs for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:57:19 -0400 Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-62b68ce199bso15270196d6.0 for ; Wed, 07 Jun 2023 09:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686157036; x=1688749036; 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=jcBYnv0Q5hRVAWcJGt6sLApFKby4ljDsg3FDGA0assE=; b=YjXdW8L52xbS5+33vJ8zDOqLQR8rRv8JlCdJhGj5W7mujpB976rx/ERORYbYrCvAiI lTtFmw/lG4L/DH0iBS2PPwHZbFFhtHeHWSV/hJx18DGXkcfNnyQcJvIRRwKeoT95WgcK T9/w9wSEg9EMMWh4znhsrMVaNASoh1znB5zucWiLosqvLpA5j0QUz3Q/GbRphqRyeE+2 2a7QRK3mATM+ScHq4yE7PIVHfgnO1NWE2NXgK+4Q4e8GuQJ72TIUDx+RZ55UrTMImgzW ft+PUm+sBoVadftyEH/f3H/2HvwstYgbzJMM8NS2oJ0LbzCRZ9i39UXI8EQ04Cre+81W 4Dkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686157036; x=1688749036; 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=jcBYnv0Q5hRVAWcJGt6sLApFKby4ljDsg3FDGA0assE=; b=LWWK2q6eZzTYWVuL2+0GQVsti8oW8WkzupWThwrA1uDtiYzfd/cK97z1Jp/8lToh3W /tLb/8IIyQYCp8GgUbcZDWZ2Jrj/5qce5z7RPNrwPYIpY0xtmpVTd9PwUEb3Zsb0i3bm u1xakIRxoR1V+mf2IpfS1DI1c68rKSD9lFZ2yaMqpj9OyA8zBOHkLC6NYyyZ3OQPbFGf cKj0sptEQzRc+npfj4fHA3NzhGMMDlz1XpgPwPCMCf75cG7XH49VipVX9wwPHeBnf1wS G0Dc5cYE5PhqlFHJPAIAym8pGmyVN3koWdp7WQGbKvQXv+RFRQpF8Eu4qh1W37pH9/gw mMcw== X-Gm-Message-State: AC+VfDyskfUosRkveNT9STN1kP3Gx5eIiah7PuBxpMWJX4FQircXMuig gxImp85pX2M3SWF1W/rGH2IpxTmWg7/eFWAQoQ8= X-Google-Smtp-Source: ACHHUZ6wnxTBDA3U/pbZxhcNpzhDRKmtk5lBOKLhP5JBCZ8xmnNW3293oFu9iOg36OofVLaEdy55nQ== X-Received: by 2002:a17:90b:918:b0:259:1a50:5719 with SMTP id bo24-20020a17090b091800b002591a505719mr2395504pjb.1.1686156555438; Wed, 07 Jun 2023 09:49:15 -0700 (PDT) Received: from localhost.localdomain ([223.104.40.226]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b00250bf8495b3sm1671808pja.39.2023.06.07.09.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 09:49:15 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Riku Voipio Subject: [RFC v2 2/6] Add the libnative library Date: Thu, 8 Jun 2023 00:47:46 +0800 Message-Id: <20230607164750.829586-3-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> References: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-qv1-xf36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yeqi Fu --- common-user/native/libnative.c | 65 ++++++++++++++++++++++++++++++++++ include/native/libnative.h | 11 ++++++ include/native/native-func.h | 11 ++++++ 3 files changed, 87 insertions(+) create mode 100644 common-user/native/libnative.c create mode 100644 include/native/libnative.h create mode 100644 include/native/native-func.h diff --git a/common-user/native/libnative.c b/common-user/native/libnative.c new file mode 100644 index 0000000000..d40e43c6fe --- /dev/null +++ b/common-user/native/libnative.c @@ -0,0 +1,65 @@ +#include +#include + +#include "native/libnative.h" +#include "native/native-func.h" + +#define STR_MACRO(str) #str +#define STR(num) STR_MACRO(num) + +#if defined(TARGET_I386) || defined(TARGET_X86_64) + +/* unused opcode */ +#define __PREFIX_INSTR \ + ".byte 0x0f,0xff;" + +#define NATIVE_CALL_EXPR(func) \ + __PREFIX_INSTR \ + ".word " STR(func) ";" : :: +#endif + +#if defined(TARGET_ARM) || defined(TARGET_AARCH64) + +/* unused syscall number */ +#define __PREFIX_INSTR \ + "svc 0xff;" + +#define NATIVE_CALL_EXPR(func) \ + __PREFIX_INSTR \ + ".word " STR(func) ";" : :: + +#endif + +#if defined(TARGET_MIPS) || defined(TARGET_MIPS64) + +/* unused bytes in syscall instructions */ +#define NATIVE_CALL_EXPR(func) \ + ".long " STR((0x1 << 24) + (func << 8) + 0xC) ";" : :: + +#endif + +void *memcpy(void *dest, const void *src, size_t n) +{ + __asm__ volatile(NATIVE_CALL_EXPR(NATIVE_MEMCPY)); +} + +int memcmp(const void *s1, const void *s2, size_t n) +{ + __asm__ volatile(NATIVE_CALL_EXPR(NATIVE_MEMCMP)); +} +void *memset(void *s, int c, size_t n) +{ + __asm__ volatile(NATIVE_CALL_EXPR(NATIVE_MEMSET)); +} +char *strcpy(char *dest, const char *src) +{ + __asm__ volatile(NATIVE_CALL_EXPR(NATIVE_STRCPY)); +} +int strcmp(const char *s1, const char *s2) +{ + __asm__ volatile(NATIVE_CALL_EXPR(NATIVE_STRCMP)); +} +char *strcat(char *dest, const char *src) +{ + __asm__ volatile(NATIVE_CALL_EXPR(NATIVE_STRCAT)); +} diff --git a/include/native/libnative.h b/include/native/libnative.h new file mode 100644 index 0000000000..d3c24f89f4 --- /dev/null +++ b/include/native/libnative.h @@ -0,0 +1,11 @@ +#ifndef __LIBNATIVE_H__ +#define __LIBNATIVE_H__ + +void *memcpy(void *dest, const void *src, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); +void *memset(void *s, int c, size_t n); +char *strcpy(char *dest, const char *src); +int strcmp(const char *s1, const char *s2); +char *strcat(char *dest, const char *src); + +#endif /* __LIBNATIVE_H__ */ diff --git a/include/native/native-func.h b/include/native/native-func.h new file mode 100644 index 0000000000..d48a8e547a --- /dev/null +++ b/include/native/native-func.h @@ -0,0 +1,11 @@ +#ifndef __NATIVE_FUNC_H__ +#define __NATIVE_FUNC_H__ + +#define NATIVE_MEMCPY 0x1001 +#define NATIVE_MEMCMP 0x1002 +#define NATIVE_MEMSET 0x1003 +#define NATIVE_STRCPY 0x1004 +#define NATIVE_STRCMP 0x1005 +#define NATIVE_STRCAT 0x1006 + +#endif From patchwork Wed Jun 7 16:47:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeqi Fu X-Patchwork-Id: 1791827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=FaNWxJrO; dkim-atps=neutral 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 4Qbtl81Bglz20X5 for ; Thu, 8 Jun 2023 02:55:48 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6wR4-0006w4-CD; Wed, 07 Jun 2023 12:55:02 -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 1q6wR3-0006vr-0q for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:55:01 -0400 Received: from mail-ot1-x331.google.com ([2607:f8b0: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 1q6wR1-0001OC-4j for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:55:00 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6af8b25fc72so5647852a34.3 for ; Wed, 07 Jun 2023 09:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686156897; x=1688748897; 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=xE+1wkxPO08MY6y0xennEQUWQ0JmYys5Y9jfkJj6VU8=; b=FaNWxJrO7iiN6V49wyWo6nK7O0LNNDSCYQ6jPs9z6MGp1sHBIWwMyX0q3GggyDi3As hZ16bOrp5YL3iNj/YQ3etBiJGoiYdehbnod659twlVBJjnOmXitjnyjwbim691M2DzVe i0dVnCey2xitfuvO2o2shli+JbacEEFnNBwovpYlxYMGp5imuPzOCYtocTZDlrhrkx4J 2nRtAhi5QupWQMimZkPU+SyMlX34gXZx2UZ//HfM/2G7kFBL5n0oaxKbdaw+No2CPnxc w0YQ3kfuiA5Z1OYYDIcGI8Z8ZWZPL4RN/exRnwtKKgYoUtLHwY3X99D9ksn1U28zrOzv vRBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686156897; x=1688748897; 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=xE+1wkxPO08MY6y0xennEQUWQ0JmYys5Y9jfkJj6VU8=; b=HTuxFkmM0WMDlqx9/RvebSsuh4Ajy/FwT63vjj3lJaREI9eJ+3eI5AhOZsqTD182y6 JEPRePP1bOOVJecU1BYehHG7cb91Vaoqxoyh8Cx+2dlElgumTYVi2q9T2LXmtn3WHr5h ALq8XWW7Suw5Xnb763ydTs2eYzKaXGv+V/F6ucGWdW1wkSsmi7LfjAjr+0kijYPCkWmQ acSTIbD9/iWEUu9pfDHdjxGJuuyzWqTPZigW4fmndYFkWJdNCAPBxA9tcTqlQnaY3usL YQtWL/asNQJlrsFSUvnn85WD6wXJHEsWqkq3sl95ujujLmxDESzY9dh4fMKYe5mFg1MZ +A7g== X-Gm-Message-State: AC+VfDzfhPbyv7WVWqzr4wvKQHkYeQxUaBpOP1/ki4F4OZUsKvzWFwjI 5VlANfhN2SFeeSOp7uwgofa/N1XS7kii0M5L/GM= X-Google-Smtp-Source: ACHHUZ4W9OGYH729372BZmTgVN5gV/GKXoqeqJwJzA22NFViqYV2VzybDmyX6hu6Bm53Wo02an34Fg== X-Received: by 2002:a92:cf4e:0:b0:331:105c:81f9 with SMTP id c14-20020a92cf4e000000b00331105c81f9mr9586543ilr.29.1686156559850; Wed, 07 Jun 2023 09:49:19 -0700 (PDT) Received: from localhost.localdomain ([223.104.40.226]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b00250bf8495b3sm1671808pja.39.2023.06.07.09.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 09:49:19 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Paolo Bonzini , Eduardo Habkost Subject: [RFC v2 3/6] target/i386: Add native library calls Date: Thu, 8 Jun 2023 00:47:47 +0800 Message-Id: <20230607164750.829586-4-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> References: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-ot1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yeqi Fu --- target/i386/helper.h | 6 +++ target/i386/tcg/translate.c | 20 +++++++++ target/i386/tcg/user/meson.build | 1 + target/i386/tcg/user/native_helper.c | 65 ++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 target/i386/tcg/user/native_helper.c diff --git a/target/i386/helper.h b/target/i386/helper.h index e627a93107..6c91655887 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -221,3 +221,9 @@ DEF_HELPER_3(rcrq, tl, env, tl, tl) #endif DEF_HELPER_1(rdrand, tl, env) + +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) +DEF_HELPER_1(native_memcpy, void, env) +DEF_HELPER_1(native_memcmp, void, env) +DEF_HELPER_1(native_memset, void, env) +#endif diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 91c9c0c478..eb0c1e9566 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -33,6 +33,7 @@ #include "helper-tcg.h" #include "exec/log.h" +#include "native/native-func.h" #define PREFIX_REPZ 0x01 #define PREFIX_REPNZ 0x02 @@ -6806,6 +6807,25 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) case 0x1d0 ... 0x1fe: disas_insn_new(s, cpu, b); break; + /* One unknown opcode for native call */ +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + case 0x1ff: + uint16_t sig = x86_lduw_code(env, s); + switch (sig) { + case NATIVE_MEMCPY: + gen_helper_native_memcpy(cpu_env); + break; + case NATIVE_MEMSET: + gen_helper_native_memset(cpu_env); + break; + case NATIVE_MEMCMP: + gen_helper_native_memcmp(cpu_env); + break; + default: + goto unknown_op; + } + break; +#endif default: goto unknown_op; } diff --git a/target/i386/tcg/user/meson.build b/target/i386/tcg/user/meson.build index 1df6bc4343..490808bd65 100644 --- a/target/i386/tcg/user/meson.build +++ b/target/i386/tcg/user/meson.build @@ -1,4 +1,5 @@ i386_user_ss.add(when: ['CONFIG_TCG', 'CONFIG_USER_ONLY'], if_true: files( 'excp_helper.c', 'seg_helper.c', + 'native_helper.c', )) diff --git a/target/i386/tcg/user/native_helper.c b/target/i386/tcg/user/native_helper.c new file mode 100644 index 0000000000..4a9b98eee2 --- /dev/null +++ b/target/i386/tcg/user/native_helper.c @@ -0,0 +1,65 @@ +/* + * native function call helpers + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/helper-proto.h" +#include "exec/exec-all.h" +#include "exec/cpu_ldst.h" +#include "tcg/helper-tcg.h" +#include "tcg/seg_helper.h" + +#ifdef TARGET_X86_64 +#define NATIVE_FN_W_3W() \ + target_ulong arg0, arg1, arg2; \ + arg0 = env->regs[R_EDI]; \ + arg1 = env->regs[R_ESI]; \ + arg2 = env->regs[R_EDX]; +#else +/* + * linux x86 has several calling conventions. The following implementation + * is for the most commonly used cdecl calling convention. + */ +#define NATIVE_FN_W_3W() \ + target_ulong arg0, arg1, arg2; \ + arg0 = *(target_ulong *)g2h(cs, env->regs[R_ESP] + 4); \ + arg1 = *(target_ulong *)g2h(cs, env->regs[R_ESP] + 8); \ + arg2 = *(target_ulong *)g2h(cs, env->regs[R_ESP] + 12); +#endif + +void helper_native_memcpy(CPUX86State *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + void *ret; + void *dest = g2h(cs, arg0); + void *src = g2h(cs, arg1); + size_t n = (size_t)arg2; + ret = memcpy(dest, src, n); + env->regs[R_EAX] = (target_ulong)h2g(ret); +} + +void helper_native_memcmp(CPUX86State *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + int ret; + void *s1 = g2h(cs, arg0); + void *s2 = g2h(cs, arg1); + size_t n = (size_t)arg2; + ret = memcmp(s1, s2, n); + env->regs[R_EAX] = ret; +} + +void helper_native_memset(CPUX86State *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + void *ret; + void *s = g2h(cs, arg0); + int c = (int)arg1; + size_t n = (size_t)arg2; + ret = memset(s, c, n); + env->regs[R_EAX] = (target_ulong)h2g(ret); +} From patchwork Wed Jun 7 16:47:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeqi Fu X-Patchwork-Id: 1791835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=INcgMRvO; dkim-atps=neutral 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 4QbtpK6LfJz20QH for ; Thu, 8 Jun 2023 02:58:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6wU0-0002Rt-9C; Wed, 07 Jun 2023 12:58:04 -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 1q6wTy-0002M4-R9 for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:58:02 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6wTw-0001rl-Tf for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:58:02 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6513e7e5d44so4459764b3a.0 for ; Wed, 07 Jun 2023 09:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686157079; x=1688749079; 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=fxJOHiP5GDTktQXf+aPVbhfyHKIATMyFdqs477VmHcY=; b=INcgMRvOHhwdyTC03bJcs7+wKs+WgKPCuwxd1JJyl4S4MhUc2v5J8wz1kOM7XwVQ/G gUmz0wjWm3fFBRahXJGCB0BUVcwUVoLAD+nAWazESwKUd6g8NsMVuuLdLtjvRbs9cvZT y1GJFwMcJkOArKcr8lLoJKCKB/oRQ78zBVyeERl141NpkVhDGqVcId14pBkWROO/QU5v q7sL/09zOTjqvg8ai8E7IXKV+u4Ic5V3Kb52asATCtiCHq6T3cMpU0dwGIZLKdWBm+q3 t8VdnSWCYxtmNaR50Vh++FCr1U6U9HE8vTktHRPrTl9yOWuukMGOwt6lOE/Yla2modMu 1vvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686157079; x=1688749079; 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=fxJOHiP5GDTktQXf+aPVbhfyHKIATMyFdqs477VmHcY=; b=MgKoGDv9vSqiwh/M/1PQu5UF+79oX4LTG4/PDFfPMOpv889xzSi6XFpExCx/8Sz6Qt O0liPFV0haHRrlJhCAxbfIMG8YT1j3t4C0MQoIrEGXh0owUzVvR3w3/olHGMzbh+8tN1 wtTRg5qCWB6bhGXRwWEzutivYQkzX1T4uoEalQJ4iwIZUl0W23r3AkQ/0yzWj8P4E0PM tGdf5WFzJKj8bxfOY4irI+VNdyZzMzr9ITladFhS+HCgt/3Ouw744aPl2qk/dczIDfkb I6gbQuWbp1RuCM2EHrObYBW3kBBLBMtFXuL5/L1hoRcVNba2uyRx98xjJwNgZzXvMd4F sgPA== X-Gm-Message-State: AC+VfDxqesC01ripjJpBQKh0VcfCnag3MS+IfKhJN5nzh8ELn93S7GdH HK2zsbaA7x7de8KWbGjw98i5iDClwC8kTXhzmuY= X-Google-Smtp-Source: ACHHUZ69ZuXes8fpHBsUFzWQz7XXTns2ApHVqrHlgpuYeeIe/ifr+Dkrqwi8MHUYsmH+SP4YePbRkg== X-Received: by 2002:a17:90b:185:b0:259:9667:722d with SMTP id t5-20020a17090b018500b002599667722dmr2511306pjs.31.1686156564938; Wed, 07 Jun 2023 09:49:24 -0700 (PDT) Received: from localhost.localdomain ([223.104.40.226]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b00250bf8495b3sm1671808pja.39.2023.06.07.09.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 09:49:24 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo Subject: [RFC v2 4/6] target/mips: Add native library calls Date: Thu, 8 Jun 2023 00:47:48 +0800 Message-Id: <20230607164750.829586-5-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> References: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yeqi Fu --- target/mips/helper.h | 6 ++++ target/mips/tcg/meson.build | 1 + target/mips/tcg/native_helper.c | 55 +++++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 20 +++++++++++- target/mips/tcg/translate.h | 12 +++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 target/mips/tcg/native_helper.c diff --git a/target/mips/helper.h b/target/mips/helper.h index de32d82e98..9fa949d78c 100644 --- a/target/mips/helper.h +++ b/target/mips/helper.h @@ -589,6 +589,12 @@ DEF_HELPER_FLAGS_3(dmthlip, 0, void, tl, tl, env) DEF_HELPER_FLAGS_3(wrdsp, 0, void, tl, tl, env) DEF_HELPER_FLAGS_2(rddsp, 0, tl, tl, env) +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) +DEF_HELPER_1(native_memcpy, void, env) +DEF_HELPER_1(native_memcmp, void, env) +DEF_HELPER_1(native_memset, void, env) +#endif + #ifndef CONFIG_USER_ONLY #include "tcg/sysemu_helper.h.inc" #endif /* !CONFIG_USER_ONLY */ diff --git a/target/mips/tcg/meson.build b/target/mips/tcg/meson.build index 7ee969ec8f..fb1ea64047 100644 --- a/target/mips/tcg/meson.build +++ b/target/mips/tcg/meson.build @@ -22,6 +22,7 @@ mips_ss.add(files( 'txx9_translate.c', 'vr54xx_helper.c', 'vr54xx_translate.c', + 'native_helper.c', )) mips_ss.add(when: 'TARGET_MIPS64', if_true: files( 'tx79_translate.c', diff --git a/target/mips/tcg/native_helper.c b/target/mips/tcg/native_helper.c new file mode 100644 index 0000000000..bfd9c92e17 --- /dev/null +++ b/target/mips/tcg/native_helper.c @@ -0,0 +1,55 @@ +/* + * native function call helpers + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/helper-proto.h" +#include "exec/exec-all.h" +#include "exec/cpu_ldst.h" + +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + +#define NATIVE_FN_W_3W() \ + target_ulong arg0, arg1, arg2; \ + arg0 = env->active_tc.gpr[4]; /*"a0"*/ \ + arg1 = env->active_tc.gpr[5]; /*"a1"*/ \ + arg2 = env->active_tc.gpr[6]; /*"a2"*/ + +void helper_native_memcpy(CPUMIPSState *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + void *ret; + void *dest = g2h(cs, arg0); + void *src = g2h(cs, arg1); + size_t n = (size_t)arg2; + ret = memcpy(dest, src, n); + env->active_tc.gpr[2] = (target_ulong)h2g(ret); +} + +void helper_native_memcmp(CPUMIPSState *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + int ret; + void *s1 = g2h(cs, arg0); + void *s2 = g2h(cs, arg1); + size_t n = (size_t)arg2; + ret = memcmp(s1, s2, n); + env->active_tc.gpr[2] = ret; +} + +void helper_native_memset(CPUMIPSState *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + void *ret; + void *s = g2h(cs, arg0); + int c = (int)arg1; + size_t n = (size_t)arg2; + ret = memset(s, c, n); + env->active_tc.gpr[2] = (target_ulong)h2g(ret); +} + +#endif diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index a6ca2e5a3b..d68ce6bc2f 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -36,6 +36,7 @@ #include "qemu/qemu-print.h" #include "fpu_helper.h" #include "translate.h" +#include "native/native-func.h" /* * Many sysemu-only helpers are not reachable for user-only. @@ -13591,7 +13592,24 @@ static void decode_opc_special(CPUMIPSState *env, DisasContext *ctx) gen_helper_pmon(cpu_env, tcg_constant_i32(sa)); #endif break; - case OPC_SYSCALL: + case OPC_SYSCALL: /* 00 00 00 0C */ + if (native_bypass() && ((((ctx->opcode) >> 24) & 0xff) == 0x1)) { + uint16_t sig = (ctx->opcode) >> 8 & 0xffff; + switch (sig) { + case NATIVE_MEMCPY: + gen_helper_native_memcpy(cpu_env); + break; + case NATIVE_MEMSET: + gen_helper_native_memset(cpu_env); + break; + case NATIVE_MEMCMP: + gen_helper_native_memcmp(cpu_env); + break; + default: + gen_reserved_instruction(ctx); + } + break; + } generate_exception_end(ctx, EXCP_SYSCALL); break; case OPC_BREAK: diff --git a/target/mips/tcg/translate.h b/target/mips/tcg/translate.h index 69f85841d2..f0112d88aa 100644 --- a/target/mips/tcg/translate.h +++ b/target/mips/tcg/translate.h @@ -237,3 +237,15 @@ static inline bool cpu_is_bigendian(DisasContext *ctx) } #endif + +/* + * Check if the native bypass feature is enabled. + */ +static inline bool native_bypass(void) +{ +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + return true; +#else + return false; +#endif +} From patchwork Wed Jun 7 16:47:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeqi Fu X-Patchwork-Id: 1791830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=AJhggkqd; dkim-atps=neutral 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 4QbtnM188Vz20QH for ; Thu, 8 Jun 2023 02:57:43 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6wTM-0008Vq-9R; Wed, 07 Jun 2023 12:57:25 -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 1q6wTB-0008Fx-AD; Wed, 07 Jun 2023 12:57:14 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6wT9-0001md-GB; Wed, 07 Jun 2023 12:57:13 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-650c8cb68aeso4203664b3a.3; Wed, 07 Jun 2023 09:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686157029; x=1688749029; 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=O3WaGEYLWcPiIzw6vB3RZqhbnQGY0LswNykwJliRoIg=; b=AJhggkqdcjz/eCrBDEl0P/iBfwNz19k38oWpeDv1C5JhNoPnraRvV0d90JCY4rnvu7 FgRa3eAKo7mbkoKOuzqloDdB0pJDm3dnlNZrGwGBcAHAmFt0kSRaXo2D7uORCCE3uRao i/88T70Oio0ce/UWkRrYNhT4Ylf3Hv7twl/ha07vX5er3TkvUNJ+q7Dxa3AIXOdxCbfu KUioTNsYP8AkhoRIrhSO85H7w2PZrgZR1eKrIlNbvdHaXpY70cUUkvREsFTR4X/bpX99 db+uNQVWWzRtqjm1jnEup7vqZvPElCDfhklts/q/nxip9Cum72jNeQdw8RlCNFaYiP17 VnXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686157029; x=1688749029; 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=O3WaGEYLWcPiIzw6vB3RZqhbnQGY0LswNykwJliRoIg=; b=KL8pl9BO6KD2fsxHptrlqOeIacbx0Io+cwKQuixWIXIzjttuvSJvxTNHWXC+NCP+Jk XtU+TxauPCJX5FEl1jSJC2S1rwIW4QqcvLlc/4+NG1yKBBIq363GWI+G7IjXR51s27c/ r0foWx7nhSQRmxU+I6WEQ972aJotBN4td/Fo1NJcRp1xjUNlPrXp+DxQQbkwXrTTLGxT XBSfIdfxQuWUcmw9iG3qUGxGVGH/IylESLAyfiZXZ6auFdoH/a/LeSpoBEQkFL5Z9KfC KEu7A1iCIN6U0jBV0ta/AaVnAX0Y7ORDUE2JC7aAH8S5QuM9ZCOauNLtuHXKOJPmDXcT IPeg== X-Gm-Message-State: AC+VfDzSk5SOxf3RuH2HHaWoYCWY0hAvAPyzwlJqUmr7Jabf5fOXWdxV uLZwpJyk5zLTHsuK9e6VRzE7n67tQI9e/ZOj6Vk= X-Google-Smtp-Source: ACHHUZ4hKpxnZf9pvcR+5WsqUFOIufUqlmCx6NIb0JCO3OX+ITK7s9LgZVri/XviOSo/UFP0ldRRFA== X-Received: by 2002:a17:90a:ca06:b0:259:ae4d:3377 with SMTP id x6-20020a17090aca0600b00259ae4d3377mr1730686pjt.27.1686156569266; Wed, 07 Jun 2023 09:49:29 -0700 (PDT) Received: from localhost.localdomain ([223.104.40.226]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b00250bf8495b3sm1671808pja.39.2023.06.07.09.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 09:49:28 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Peter Maydell , qemu-arm@nongnu.org (open list:ARM TCG CPUs) Subject: [RFC v2 5/6] target/arm: Add native library calls Date: Thu, 8 Jun 2023 00:47:49 +0800 Message-Id: <20230607164750.829586-6-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> References: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yeqi Fu --- target/arm/helper.c | 47 ++++++++++++++++++++++++++++++++++ target/arm/helper.h | 6 +++++ target/arm/tcg/translate-a64.c | 22 ++++++++++++++++ target/arm/tcg/translate.c | 25 +++++++++++++++++- target/arm/tcg/translate.h | 19 ++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 0b7fd2e7e6..03fbc3724b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -25,6 +25,7 @@ #include "sysemu/tcg.h" #include "qapi/error.h" #include "qemu/guest-random.h" +#include "exec/cpu_ldst.h" #ifdef CONFIG_TCG #include "semihosting/common-semi.h" #endif @@ -12045,3 +12046,49 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, } } #endif + +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + +#define NATIVE_FN_W_3W() \ + target_ulong arg0, arg1, arg2; \ + arg0 = env->regs[0]; \ + arg1 = env->regs[1]; \ + arg2 = env->regs[2]; + +void helper_native_memcpy(CPUARMState *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + void *ret; + void *dest = g2h(cs, arg0); + void *src = g2h(cs, arg1); + size_t n = (size_t)arg2; + ret = memcpy(dest, src, n); + env->regs[0] = (target_ulong)h2g(ret); +} + +void helper_native_memcmp(CPUARMState *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + int ret; + void *s1 = g2h(cs, arg0); + void *s2 = g2h(cs, arg1); + size_t n = (size_t)arg2; + ret = memcmp(s1, s2, n); + env->regs[0] = ret; +} + +void helper_native_memset(CPUARMState *env) +{ + CPUState *cs = env_cpu(env); + NATIVE_FN_W_3W(); + void *ret; + void *s = g2h(cs, arg0); + int c = (int)arg1; + size_t n = (size_t)arg2; + ret = memset(s, c, n); + env->regs[0] = (target_ulong)h2g(ret); +} + +#endif diff --git a/target/arm/helper.h b/target/arm/helper.h index 3335c2b10b..57144bf6fb 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -1038,6 +1038,12 @@ DEF_HELPER_FLAGS_5(gvec_uclamp_s, TCG_CALL_NO_RWG, DEF_HELPER_FLAGS_5(gvec_uclamp_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) +DEF_HELPER_1(native_memcpy, void, env) +DEF_HELPER_1(native_memcmp, void, env) +DEF_HELPER_1(native_memset, void, env) +#endif + #ifdef TARGET_AARCH64 #include "tcg/helper-a64.h" #include "tcg/helper-sve.h" diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index 741a608739..04421af6c6 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -35,6 +35,7 @@ #include "cpregs.h" #include "translate-a64.h" #include "qemu/atomic128.h" +#include "native/native-func.h" static TCGv_i64 cpu_X[32]; static TCGv_i64 cpu_pc; @@ -2291,6 +2292,9 @@ static void disas_exc(DisasContext *s, uint32_t insn) if (s->fgt_svc) { gen_exception_insn_el(s, 0, EXCP_UDEF, syndrome, 2); break; + } else if (native_bypass() && imm16 == 0xff) { + s->native_call_status = true; + break; } gen_ss_advance(s); gen_exception_insn(s, 4, EXCP_SWI, syndrome); @@ -14203,6 +14207,24 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) s->fp_access_checked = false; s->sve_access_checked = false; + if (native_bypass() && s->native_call_status) { + switch (insn) { + case NATIVE_MEMCPY: + gen_helper_native_memcpy(cpu_env); + break; + case NATIVE_MEMCMP: + gen_helper_native_memcmp(cpu_env); + break; + case NATIVE_MEMSET: + gen_helper_native_memset(cpu_env); + break; + default: + unallocated_encoding(s); + } + s->native_call_status = false; + return; + } + if (s->pstate_il) { /* * Illegal execution state. This has priority over BTI diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index 7468476724..83ce0f7437 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -34,7 +34,7 @@ #include "exec/helper-gen.h" #include "exec/log.h" #include "cpregs.h" - +#include "native/native-func.h" #define ENABLE_ARCH_4T arm_dc_feature(s, ARM_FEATURE_V4T) #define ENABLE_ARCH_5 arm_dc_feature(s, ARM_FEATURE_V5) @@ -58,6 +58,10 @@ TCGv_i32 cpu_CF, cpu_NF, cpu_VF, cpu_ZF; TCGv_i64 cpu_exclusive_addr; TCGv_i64 cpu_exclusive_val; +#if defined(CONFIG_USER_ONLY) && !defined(TARGET_AARCH64) \ + && defined(CONFIG_USER_NATIVE_CALL) +#endif + #include "exec/gen-icount.h" static const char * const regnames[] = @@ -8576,6 +8580,8 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) if (s->fgt_svc) { uint32_t syndrome = syn_aa32_svc(a->imm, s->thumb); gen_exception_insn_el(s, 0, EXCP_UDEF, syndrome, 2); + } else if (native_bypass() && a->imm == 0xff) { + s->native_call_status = true; } else { gen_update_pc(s, curr_insn_len(s)); s->svc_imm = a->imm; @@ -9372,6 +9378,23 @@ static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) insn = arm_ldl_code(env, &dc->base, pc, dc->sctlr_b); dc->insn = insn; dc->base.pc_next = pc + 4; + if (native_bypass() && dc->native_call_status) { + switch (insn) { + case NATIVE_MEMCPY: + gen_helper_native_memcpy(cpu_env); + break; + case NATIVE_MEMCMP: + gen_helper_native_memcmp(cpu_env); + break; + case NATIVE_MEMSET: + gen_helper_native_memset(cpu_env); + break; + default: + unallocated_encoding(dc); + } + dc->native_call_status = false; + return; + } disas_arm_insn(dc, insn); arm_post_translate_insn(dc); diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h index a9d1f4adc2..19c4f7af7f 100644 --- a/target/arm/tcg/translate.h +++ b/target/arm/tcg/translate.h @@ -149,6 +149,13 @@ typedef struct DisasContext { int c15_cpar; /* TCG op of the current insn_start. */ TCGOp *insn_start; + /* + * Indicate whether the next instruction is a native function call (true) + * or not (false). + */ +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + bool native_call_status; +#endif } DisasContext; typedef struct DisasCompare { @@ -657,3 +664,15 @@ static inline void gen_restore_rmode(TCGv_i32 old, TCGv_ptr fpst) } #endif /* TARGET_ARM_TRANSLATE_H */ + +/* + * Check if the native bypass feature is enabled. + */ +static inline bool native_bypass(void) +{ +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + return true; +#else + return false; +#endif +} From patchwork Wed Jun 7 16:47:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeqi Fu X-Patchwork-Id: 1791833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=a1i6bcHB; dkim-atps=neutral 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 4Qbtnm1Kcjz20QH for ; Thu, 8 Jun 2023 02:58:04 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6wTo-0001KK-6m; Wed, 07 Jun 2023 12:57:52 -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 1q6wTj-0001Dr-F5 for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:57:49 -0400 Received: from mail-yb1-xb2d.google.com ([2607:f8b0:4864:20::b2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6wTg-0001pJ-Tb for qemu-devel@nongnu.org; Wed, 07 Jun 2023 12:57:46 -0400 Received: by mail-yb1-xb2d.google.com with SMTP id 3f1490d57ef6-ba8cd61ee2dso1195274276.1 for ; Wed, 07 Jun 2023 09:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686157063; x=1688749063; 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=ruOmHOKIvXadvE8jXrAJUnNa6lotn9rQ25E1Fic8ZjU=; b=a1i6bcHBBf1iIA37q/wV0LZZwmsX6IL7V42P+z22zyO+6Pbbk+4lmrooSpSlrLIZCA mwNLsvU7t1d8VzMEz+04Tpm8SyXsCddrOoxcF/8Z09KDNJQFDe9D2QoRRR38GZMzD2T4 CRp7FSQwemcJV/QMdh0vQhFHj+XWHj7Y1LBSVyvuhJxGa08CgZ4FZl8M+u5TGuNDt2s1 9khY0mShtYpH1OjwdPlrzWzs3kUXxQARRqTtCTUwhCm9qQXzg7kw0V7FIRduLUQwof6o eM3tGIWl3KUp1fZyEXBjTtTuS1CrZJiczakFGwURAqFgy7cEZLEGWys3C33bhNNs0Qjb iWnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686157063; x=1688749063; 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=ruOmHOKIvXadvE8jXrAJUnNa6lotn9rQ25E1Fic8ZjU=; b=YZYQpY31FhHPtk4EtqAJpgKQnVWfRxj0r0hZxaQfCZhg3tMm4cyyk5tpYc7GDzA1vq MEclizM+Fpnn1yPcMc5SCKsI9/LEW9YFj21FJUJbfhrXk8GluDtif3m/yOH9xOZelF0n sR3XKZxOgTfK7Dhqzc6V9meYMSsdxyZHHAjKIn2Ke4IY7pP0mAeMmI//rkYolOuzTt4d 8HTKzhO4cBkNbymgj4opgxeQ5LRIQdTBv++90BEeSyIv1lVY70Cyd1kIkJ5mL6ur4cqb xPCWtMefL04Vi0HLSDxJCGDBzfW8vDPqk2gM8YYzdDFewXLz3SurxX9rinz9SnGweZvB hVlA== X-Gm-Message-State: AC+VfDwfvTOlRQrO+xrgSVH23DGvqPhjpJW9xSOAFNhBOSpuWOCZgZkM ePeJYZdXE4eA0pVGs5Y2JaFzsTOx8SmE0ZmJx+g= X-Google-Smtp-Source: ACHHUZ7Mh4Si2nhbjlq9k0Z/+l+JZW0lmWKMdldsfKNH9j1sjxjMr0mtgTGrd4mtBUG0OknNmPJhbA== X-Received: by 2002:a17:90b:8d7:b0:256:7866:8c06 with SMTP id ds23-20020a17090b08d700b0025678668c06mr17008900pjb.19.1686156573350; Wed, 07 Jun 2023 09:49:33 -0700 (PDT) Received: from localhost.localdomain ([223.104.40.226]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b00250bf8495b3sm1671808pja.39.2023.06.07.09.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 09:49:32 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Laurent Vivier Subject: [RFC v2 6/6] linux-user: Add '-native-bypass' option Date: Thu, 8 Jun 2023 00:47:50 +0800 Message-Id: <20230607164750.829586-7-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> References: <20230607164750.829586-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2d; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-yb1-xb2d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yeqi Fu --- include/qemu/envlist.h | 1 + linux-user/main.c | 23 +++++++++++++++++ util/envlist.c | 56 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/include/qemu/envlist.h b/include/qemu/envlist.h index 6006dfae44..865eb18e17 100644 --- a/include/qemu/envlist.h +++ b/include/qemu/envlist.h @@ -7,6 +7,7 @@ envlist_t *envlist_create(void); void envlist_free(envlist_t *); int envlist_setenv(envlist_t *, const char *); int envlist_unsetenv(envlist_t *, const char *); +int envlist_appendenv(envlist_t *, const char *, const char *); int envlist_parse_set(envlist_t *, const char *); int envlist_parse_unset(envlist_t *, const char *); char **envlist_to_environ(const envlist_t *, size_t *); diff --git a/linux-user/main.c b/linux-user/main.c index 5e6b2e1714..313c116b3b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -125,6 +125,8 @@ static void usage(int exitcode); static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; +static const char *native_lib; + #if !defined(TARGET_DEFAULT_STACK_SIZE) /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example @@ -293,6 +295,13 @@ static void handle_arg_set_env(const char *arg) free(r); } +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) +static void handle_arg_native_bypass(const char *arg) +{ + native_lib = arg; +} +#endif + static void handle_arg_unset_env(const char *arg) { char *r, *p, *token; @@ -522,6 +531,10 @@ static const struct qemu_argument arg_table[] = { "", "Generate a /tmp/perf-${pid}.map file for perf"}, {"jitdump", "QEMU_JITDUMP", false, handle_arg_jitdump, "", "Generate a jit-${pid}.dump file for perf"}, +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USER_NATIVE_CALL) + {"native-bypass", "QEMU_NATIVE_BYPASS", true, handle_arg_native_bypass, + "", "native bypass for library calls in user mode only."}, +#endif {NULL, NULL, false, NULL, NULL, NULL} }; @@ -826,6 +839,16 @@ int main(int argc, char **argv, char **envp) } } + /* Set the library for native bypass */ + if (native_lib != NULL) { + char *token = malloc(strlen(native_lib) + 12); + strcpy(token, "LD_PRELOAD="); + strcat(token, native_lib); + if (envlist_appendenv(envlist, token, ":") != 0) { + usage(EXIT_FAILURE); + } + } + target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist); diff --git a/util/envlist.c b/util/envlist.c index db937c0427..713d52497e 100644 --- a/util/envlist.c +++ b/util/envlist.c @@ -201,6 +201,62 @@ envlist_unsetenv(envlist_t *envlist, const char *env) return (0); } +/* + * Appends environment value to envlist. If the environment + * variable already exists, the new value is appended to the + * existing one. + * + * Returns 0 in success, errno otherwise. + */ +int +envlist_appendenv(envlist_t *envlist, const char *env, const char *separator) +{ + struct envlist_entry *entry = NULL; + const char *eq_sign; + size_t envname_len; + + if ((envlist == NULL) || (env == NULL)) { + return (EINVAL); + } + + /* find out first equals sign in given env */ + eq_sign = strchr(env, '='); + if (eq_sign == NULL) { + return (EINVAL); + } + envname_len = eq_sign - env + 1; + + /* + * If there already exists variable with given name, + * we append the new value to the existing one. + */ + for (entry = envlist->el_entries.lh_first; entry != NULL; + entry = entry->ev_link.le_next) { + if (strncmp(entry->ev_var, env, envname_len) == 0) { + break; + } + } + + if (entry != NULL) { + char *new_env_value = NULL; + size_t new_env_len = strlen(entry->ev_var) + strlen(eq_sign) + + strlen(separator) + 1; + new_env_value = g_malloc(new_env_len); + strcpy(new_env_value, entry->ev_var); + strcat(new_env_value, separator); + strcat(new_env_value, eq_sign + 1); + g_free((char *)entry->ev_var); + entry->ev_var = new_env_value; + } else { + envlist->el_count++; + entry = g_malloc(sizeof(*entry)); + entry->ev_var = g_strdup(env); + QLIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link); + } + + return (0); +} + /* * Returns given envlist as array of strings (in same form that * global variable environ is). Caller must free returned memory