Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2511796pxm; Mon, 28 Feb 2022 00:01:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhnW9JvFdluEoYPdz7n3uueRaXHLsPqhtGwkvgVi1PsS0kFkeeVcG8YgvU4MMbD6GPyN+F X-Received: by 2002:a05:6402:170e:b0:40b:657:ac3f with SMTP id y14-20020a056402170e00b0040b0657ac3fmr18064276edu.354.1646035304914; Mon, 28 Feb 2022 00:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646035304; cv=none; d=google.com; s=arc-20160816; b=qzZWmRgWU6J0eSi1wmzFfpwW1mi0TRy7Cu7/VEgTvfznre9LyThOlRdTf+H6OV6F17 PfPKqFtxvfffdkgeRAjhuMMVn+it1C4UiOh+qLMFY5TSYomfY2ZDw/bWk5yLphaEtP4y s6kz2aPbYDYBVZJkZxEwjuvY3zihzi1JXXp+vNmgfjP11e/ggjArAoX/fb87wRttJLSt S+Ro/fkR8Xusiw4unGIPI2Gl7Xyde+noSFH+IYHvwX+cid83fldEe2u0r5VKUIjfwyYq FRYcSps53HX7+v4CUg3d/bl6EOXZvRWnM527EnLdWI3qPGH6D1rD8EaJPt/IZd+9bPoA aMAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G0vHndsYIwxsCxrzUVl3MipITvEzTE0kTJNUEH+5X6s=; b=aL3l4Yj68v13Z24Iq/BvTUtNa+wx835KySJ3Hq3ePeo7saN2/jKfD8qu3cy29j1La1 uFbvcByy/ur5ysebUAC8BE7TXPQsc/OurEpWtL/9rxBUHyOkV2JQZYCMTE9iQnS1VgTp eDKuttuZ8Zj9AIvJO5AywrSlh3SiHksFXDnceLkXPI2y11UKAbrS7ZUYEiOMzZ7/4MP4 e/0gbTHNidKXFod5d9zSdFhALh/Qw9XM1YyAB+USSj8GmYCBx+CxYCp3V54p2b0E+lyS 3sbs1X7dnX6uW895ZbURp7ovMqvS+PTMjQeNw+5Wt8GoSYdPPoe56tXzDJl6wpnpg5Jn bJ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YDAYdpoE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a170906388600b006b525f14817si5821918ejd.310.2022.02.28.00.01.23; Mon, 28 Feb 2022 00:01:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YDAYdpoE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbiB0Qb1 (ORCPT + 99 others); Sun, 27 Feb 2022 11:31:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231747AbiB0Qa7 (ORCPT ); Sun, 27 Feb 2022 11:30:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D0756E4E8; Sun, 27 Feb 2022 08:30:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A0ED060F46; Sun, 27 Feb 2022 16:30:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3352DC36AE3; Sun, 27 Feb 2022 16:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645979415; bh=gubBLeOVUNo5+99AzAl7peBszEat/rDlyHt7rNu08Ko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDAYdpoEX57ZxLLkc2CxaD98rHA/p9P5JGxnR1HADbTnyqJuqNsWVxv8xXTKMbufQ VEV61yvsiyBiBjuuBuxw/yX6FWc9CQ9ctAiLqU11tNVf6Egx2adamScPGZXaXGBHFH 6uzYi7LC04qepdJNdlA8VlOF/BzKxIxJRtw8Hz3Qxj3M296yjg49wfhpzE9Ea5orZn l58eg70IhmDHNc9B8SzcWRiIpdUQBIuIYW/zu0RP+g49DGOLYYGPSSpnHjTNJsMEME 3z+GNfAMoXZBt5t0iDC1RA9WBCm+JuyZd+4vh+bsK9n7vvnuoTlBBCikgyJkelbakw 3Nvse/EVit/CA== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de, anup@brainfault.org, gregkh@linuxfoundation.org, liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, hch@lst.de Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-csky@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, Guo Ren Subject: [PATCH V7 14/20] riscv: compat: Add elf.h implementation Date: Mon, 28 Feb 2022 00:28:25 +0800 Message-Id: <20220227162831.674483-15-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220227162831.674483-1-guoren@kernel.org> References: <20220227162831.674483-1-guoren@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guo Ren Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann --- arch/riscv/include/asm/elf.h | 46 +++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index f53c40026c7a..aee40040917b 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -8,6 +8,8 @@ #ifndef _ASM_RISCV_ELF_H #define _ASM_RISCV_ELF_H +#include +#include #include #include #include @@ -18,11 +20,13 @@ */ #define ELF_ARCH EM_RISCV +#ifndef ELF_CLASS #ifdef CONFIG_64BIT #define ELF_CLASS ELFCLASS64 #else #define ELF_CLASS ELFCLASS32 #endif +#endif #define ELF_DATA ELFDATA2LSB @@ -31,6 +35,13 @@ */ #define elf_check_arch(x) ((x)->e_machine == EM_RISCV) +/* + * Use the same code with elf_check_arch, because elf32_hdr & + * elf64_hdr e_machine's offset are different. The checker is + * a little bit simple compare to other architectures. + */ +#define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV) + #define CORE_DUMP_USE_REGSET #define ELF_EXEC_PAGESIZE (PAGE_SIZE) @@ -43,8 +54,14 @@ #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2) #ifdef CONFIG_64BIT +#ifdef CONFIG_COMPAT +#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \ + 0x7ff >> (PAGE_SHIFT - 12) : \ + 0x3ffff >> (PAGE_SHIFT - 12)) +#else #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) #endif +#endif /* * This yields a mask that user programs can use to figure out what * instruction set this CPU supports. This could be done in user space, @@ -60,11 +77,19 @@ extern unsigned long elf_hwcap; */ #define ELF_PLATFORM (NULL) +#define COMPAT_ELF_PLATFORM (NULL) + #ifdef CONFIG_MMU #define ARCH_DLINFO \ do { \ + /* \ + * Note that we add ulong after elf_addr_t because \ + * casting current->mm->context.vdso triggers a cast \ + * warning of cast from pointer to integer for \ + * COMPAT ELFCLASS32. \ + */ \ NEW_AUX_ENT(AT_SYSINFO_EHDR, \ - (elf_addr_t)current->mm->context.vdso); \ + (elf_addr_t)(ulong)current->mm->context.vdso); \ NEW_AUX_ENT(AT_L1I_CACHESIZE, \ get_cache_size(1, CACHE_TYPE_INST)); \ NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \ @@ -90,4 +115,23 @@ do { \ *(struct user_regs_struct *)regs; \ } while (0); +#ifdef CONFIG_COMPAT + +#define SET_PERSONALITY(ex) \ +do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ + set_thread_flag(TIF_32BIT); \ + else \ + clear_thread_flag(TIF_32BIT); \ + if (personality(current->personality) != PER_LINUX32) \ + set_personality(PER_LINUX | \ + (current->personality & (~PER_MASK))); \ +} while (0) + +#define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2) + +/* rv32 registers */ +typedef compat_ulong_t compat_elf_greg_t; +typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG]; + +#endif /* CONFIG_COMPAT */ #endif /* _ASM_RISCV_ELF_H */ -- 2.25.1