Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1367905pxm; Thu, 24 Feb 2022 01:32:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrYj7czLqeKip6T+atX/TyLGF2vYCFmm3o232NDtMgzptyrtn+GbsVLG1OZsGynHVx2uUo X-Received: by 2002:a17:902:b616:b0:14d:be7f:717e with SMTP id b22-20020a170902b61600b0014dbe7f717emr1835039pls.149.1645695149484; Thu, 24 Feb 2022 01:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645695149; cv=none; d=google.com; s=arc-20160816; b=URrbvU9SCgMZcFCQFVJMmppdpq34MWbBD8/sOBl1fI3nTKfbJu9phoRcPRg1GHEf0b +lzMCnaI78CNa3P3HQZoGgNSu3AuUwxl6zPJ5p+1qfikU6MCIMLOgR6gr3MRRs/xfprm t+SeYYKXGB6pcdCjWB20O8p6nwHMKeK1Si4KvguuJjsh54ncE2dVnbBWaG0O0XhSyhDn 5lQkTnhogDWxDgdsm9fNxgrqT5ZpTtlyqt5YeXxNSMjxyJ4YwrtTxC6W6pN4Odr6EUTk n1dK4Cd5LUtrQEwHtrbSCdWnkZKRmzKPsXO80v//WdraxVwXGBGNu+jQbPwuo9n/cLtO AlYA== 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=MSETAgvQQw2EKqjW/mwbCy0357kFTvq3ujjjafwdSOzwjkpaTpmnxaxtlzHuMqtOoy BHMk5bI10lcJw1qjAlusTHH/Nd5f4Y5gc9xGEWckI7wpnMuchbQChxTpKPtUOWxJYqST /EQ8TzJ4e2w4i26QIf0wkywV0BTQPvJdsYekGSlSb/L0cA/5FSg71ATXavtnS4w9sXR6 l0jcxOr4HOuMu3D4ymVUCVa8FbSZ5O7i89xfzinvpB8RnW6ibhtkSAbAsb6XjHjM4JYH itKxamAai79RGror0NaikI5/B0s+Zx1IgOp3bTkM+4MCaGFffMXIVps59Y1hZ/mnD8MD szUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=njppeVKe; 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 mh9si476105pjb.54.2022.02.24.01.32.10; Thu, 24 Feb 2022 01:32:29 -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=njppeVKe; 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 S232414AbiBXI7s (ORCPT + 99 others); Thu, 24 Feb 2022 03:59:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232416AbiBXI51 (ORCPT ); Thu, 24 Feb 2022 03:57:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4411F1AF0E; Thu, 24 Feb 2022 00:56:41 -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 EF8E561B0F; Thu, 24 Feb 2022 08:56:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DD34C340F4; Thu, 24 Feb 2022 08:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645693000; bh=gubBLeOVUNo5+99AzAl7peBszEat/rDlyHt7rNu08Ko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njppeVKevW46+S0W7484DuVadG4pgrBe6pw58BQY4AxyQWFMRD/iA4qgPjbMpf6f2 4eRv9pcKrYNfGlK129MagP1GOEfzAhsdzIvrNqPWc6/XX8jGwRRY+LBUl26cPMWCgX kfcvyygNhnbciNOX8n0C+DFkVY6OMJMW2hogWhe43MSEY6y+baFlFPbxowsti1SyXn JYk/1Knofme6ZoImNfkYqUC8IuCwplnFVmHRhbq3mruX61yV6e5RuMZK/sK6uUrZPf AWN1UiqpzNYcgn32ddx19GkLoKaXz+1UK87w8oFJXcrdb03QJ2OwzySN8MpF2Otzj+ kbJVtGSijxO3w== 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 V6 14/20] riscv: compat: Add elf.h implementation Date: Thu, 24 Feb 2022 16:54:04 +0800 Message-Id: <20220224085410.399351-15-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224085410.399351-1-guoren@kernel.org> References: <20220224085410.399351-1-guoren@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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