Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  arch/um/kernel/elf_aux.c
0004  *
0005  *  Scan the Elf auxiliary vector provided by the host to extract
0006  *  information about vsyscall-page, etc.
0007  *
0008  *  Copyright (C) 2004 Fujitsu Siemens Computers GmbH
0009  *  Author: Bodo Stroesser (bodo.stroesser@fujitsu-siemens.com)
0010  */
0011 #include <elf.h>
0012 #include <stddef.h>
0013 #include <init.h>
0014 #include <elf_user.h>
0015 #include <mem_user.h>
0016 
0017 typedef Elf32_auxv_t elf_auxv_t;
0018 
0019 /* These are initialized very early in boot and never changed */
0020 char * elf_aux_platform;
0021 extern long elf_aux_hwcap;
0022 unsigned long vsyscall_ehdr;
0023 unsigned long vsyscall_end;
0024 unsigned long __kernel_vsyscall;
0025 
0026 __init void scan_elf_aux( char **envp)
0027 {
0028     long page_size = 0;
0029     elf_auxv_t * auxv;
0030 
0031     while ( *envp++ != NULL) ;
0032 
0033     for ( auxv = (elf_auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) {
0034         switch ( auxv->a_type ) {
0035             case AT_SYSINFO:
0036                 __kernel_vsyscall = auxv->a_un.a_val;
0037                 /* See if the page is under TASK_SIZE */
0038                 if (__kernel_vsyscall < (unsigned long) envp)
0039                     __kernel_vsyscall = 0;
0040                 break;
0041             case AT_SYSINFO_EHDR:
0042                 vsyscall_ehdr = auxv->a_un.a_val;
0043                 /* See if the page is under TASK_SIZE */
0044                 if (vsyscall_ehdr < (unsigned long) envp)
0045                     vsyscall_ehdr = 0;
0046                 break;
0047             case AT_HWCAP:
0048                 elf_aux_hwcap = auxv->a_un.a_val;
0049                 break;
0050             case AT_PLATFORM:
0051                                 /* elf.h removed the pointer elements from
0052                                  * a_un, so we have to use a_val, which is
0053                                  * all that's left.
0054                                  */
0055                 elf_aux_platform =
0056                     (char *) (long) auxv->a_un.a_val;
0057                 break;
0058             case AT_PAGESZ:
0059                 page_size = auxv->a_un.a_val;
0060                 break;
0061         }
0062     }
0063     if ( ! __kernel_vsyscall || ! vsyscall_ehdr ||
0064          ! elf_aux_hwcap || ! elf_aux_platform ||
0065          ! page_size || (vsyscall_ehdr % page_size) ) {
0066         __kernel_vsyscall = 0;
0067         vsyscall_ehdr = 0;
0068         elf_aux_hwcap = 0;
0069         elf_aux_platform = "i586";
0070     }
0071     else {
0072         vsyscall_end = vsyscall_ehdr + page_size;
0073     }
0074 }