LCOV - code coverage report
Current view: top level - arch/arm/kernel - process.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 64 209 30.6 %
Date: 2014-04-16 Functions: 16 33 48.5 %
Branches: 30 79 38.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  *  linux/arch/arm/kernel/process.c
       3                 :            :  *
       4                 :            :  *  Copyright (C) 1996-2000 Russell King - Converted to ARM.
       5                 :            :  *  Original Copyright (C) 1995  Linus Torvalds
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License version 2 as
       9                 :            :  * published by the Free Software Foundation.
      10                 :            :  */
      11                 :            : #include <stdarg.h>
      12                 :            : 
      13                 :            : #include <linux/export.h>
      14                 :            : #include <linux/sched.h>
      15                 :            : #include <linux/kernel.h>
      16                 :            : #include <linux/mm.h>
      17                 :            : #include <linux/stddef.h>
      18                 :            : #include <linux/unistd.h>
      19                 :            : #include <linux/user.h>
      20                 :            : #include <linux/delay.h>
      21                 :            : #include <linux/reboot.h>
      22                 :            : #include <linux/interrupt.h>
      23                 :            : #include <linux/kallsyms.h>
      24                 :            : #include <linux/init.h>
      25                 :            : #include <linux/cpu.h>
      26                 :            : #include <linux/elfcore.h>
      27                 :            : #include <linux/pm.h>
      28                 :            : #include <linux/tick.h>
      29                 :            : #include <linux/utsname.h>
      30                 :            : #include <linux/uaccess.h>
      31                 :            : #include <linux/random.h>
      32                 :            : #include <linux/hw_breakpoint.h>
      33                 :            : #include <linux/cpuidle.h>
      34                 :            : #include <linux/leds.h>
      35                 :            : #include <linux/reboot.h>
      36                 :            : #include <linux/console.h>
      37                 :            : 
      38                 :            : #include <asm/cacheflush.h>
      39                 :            : #include <asm/idmap.h>
      40                 :            : #include <asm/processor.h>
      41                 :            : #include <asm/thread_notify.h>
      42                 :            : #include <asm/stacktrace.h>
      43                 :            : #include <asm/mach/time.h>
      44                 :            : #include <asm/tls.h>
      45                 :            : 
      46                 :            : #ifdef CONFIG_CC_STACKPROTECTOR
      47                 :            : #include <linux/stackprotector.h>
      48                 :            : unsigned long __stack_chk_guard __read_mostly;
      49                 :            : EXPORT_SYMBOL(__stack_chk_guard);
      50                 :            : #endif
      51                 :            : 
      52                 :            : static const char *processor_modes[] = {
      53                 :            :   "USER_26", "FIQ_26" , "IRQ_26" , "SVC_26" , "UK4_26" , "UK5_26" , "UK6_26" , "UK7_26" ,
      54                 :            :   "UK8_26" , "UK9_26" , "UK10_26", "UK11_26", "UK12_26", "UK13_26", "UK14_26", "UK15_26",
      55                 :            :   "USER_32", "FIQ_32" , "IRQ_32" , "SVC_32" , "UK4_32" , "UK5_32" , "UK6_32" , "ABT_32" ,
      56                 :            :   "UK8_32" , "UK9_32" , "UK10_32", "UND_32" , "UK12_32", "UK13_32", "UK14_32", "SYS_32"
      57                 :            : };
      58                 :            : 
      59                 :            : static const char *isa_modes[] = {
      60                 :            :   "ARM" , "Thumb" , "Jazelle", "ThumbEE"
      61                 :            : };
      62                 :            : 
      63                 :            : #ifdef CONFIG_SMP
      64                 :          0 : void arch_trigger_all_cpu_backtrace(void)
      65                 :            : {
      66                 :          0 :         smp_send_all_cpu_backtrace();
      67                 :          0 : }
      68                 :            : #else
      69                 :            : void arch_trigger_all_cpu_backtrace(void)
      70                 :            : {
      71                 :            :         dump_stack();
      72                 :            : }
      73                 :            : #endif
      74                 :            : 
      75                 :            : extern void call_with_stack(void (*fn)(void *), void *arg, void *sp);
      76                 :            : typedef void (*phys_reset_t)(unsigned long);
      77                 :            : 
      78                 :            : #ifdef CONFIG_ARM_FLUSH_CONSOLE_ON_RESTART
      79                 :            : void arm_machine_flush_console(void)
      80                 :            : {
      81                 :            :         printk("\n");
      82                 :            :         pr_emerg("Restarting %s\n", linux_banner);
      83                 :            :         if (console_trylock()) {
      84                 :            :                 console_unlock();
      85                 :            :                 return;
      86                 :            :         }
      87                 :            : 
      88                 :            :         mdelay(50);
      89                 :            : 
      90                 :            :         local_irq_disable();
      91                 :            :         if (!console_trylock())
      92                 :            :                 pr_emerg("arm_restart: Console was locked! Busting\n");
      93                 :            :         else
      94                 :            :                 pr_emerg("arm_restart: Console was locked!\n");
      95                 :            :         console_unlock();
      96                 :            : }
      97                 :            : #else
      98                 :          0 : void arm_machine_flush_console(void)
      99                 :            : {
     100                 :          0 : }
     101                 :            : #endif
     102                 :            : 
     103                 :            : /*
     104                 :            :  * A temporary stack to use for CPU reset. This is static so that we
     105                 :            :  * don't clobber it with the identity mapping. When running with this
     106                 :            :  * stack, any references to the current task *will not work* so you
     107                 :            :  * should really do as little as possible before jumping to your reset
     108                 :            :  * code.
     109                 :            :  */
     110                 :            : static u64 soft_restart_stack[16];
     111                 :            : 
     112                 :          0 : static void __soft_restart(void *addr)
     113                 :            : {
     114                 :            :         phys_reset_t phys_reset;
     115                 :            : 
     116                 :            :         /* Take out a flat memory mapping. */
     117                 :          0 :         setup_mm_for_reboot();
     118                 :            : 
     119                 :            :         /* Clean and invalidate caches */
     120                 :          0 :         flush_cache_all();
     121                 :            : 
     122                 :            :         /* Turn off caching */
     123                 :          0 :         cpu_proc_fin();
     124                 :            : 
     125                 :            :         /* Push out any further dirty data, and ensure cache is empty */
     126                 :          0 :         flush_cache_all();
     127                 :            : 
     128                 :            :         /* Switch to the identity mapping. */
     129                 :          0 :         phys_reset = (phys_reset_t)(unsigned long)virt_to_phys(cpu_reset);
     130                 :          0 :         phys_reset((unsigned long)addr);
     131                 :            : 
     132                 :            :         /* Should never get here. */
     133                 :          0 :         BUG();
     134                 :            : }
     135                 :            : 
     136                 :          0 : void soft_restart(unsigned long addr)
     137                 :            : {
     138                 :            :         u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
     139                 :            : 
     140                 :            :         /* Disable interrupts first */
     141                 :            :         local_irq_disable();
     142                 :          0 :         local_fiq_disable();
     143                 :            : 
     144                 :            :         /* Disable the L2 if we're the last man standing. */
     145         [ #  # ]:          0 :         if (num_online_cpus() == 1)
     146                 :            :                 outer_disable();
     147                 :            : 
     148                 :            :         /* Change to the new stack and continue with the reset. */
     149                 :          0 :         call_with_stack(__soft_restart, (void *)addr, (void *)stack);
     150                 :            : 
     151                 :            :         /* Should never get here. */
     152                 :          0 :         BUG();
     153                 :            : }
     154                 :            : 
     155                 :          0 : static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
     156                 :            : {
     157                 :          0 : }
     158                 :            : 
     159                 :            : /*
     160                 :            :  * Function pointers to optional machine specific functions
     161                 :            :  */
     162                 :            : void (*pm_power_off)(void);
     163                 :            : EXPORT_SYMBOL(pm_power_off);
     164                 :            : 
     165                 :            : void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd) = null_restart;
     166                 :            : EXPORT_SYMBOL_GPL(arm_pm_restart);
     167                 :            : 
     168                 :            : /*
     169                 :            :  * This is our default idle handler.
     170                 :            :  */
     171                 :            : 
     172                 :            : void (*arm_pm_idle)(void);
     173                 :            : 
     174                 :          0 : static void default_idle(void)
     175                 :            : {
     176         [ #  # ]:          0 :         if (arm_pm_idle)
     177                 :          0 :                 arm_pm_idle();
     178                 :            :         else
     179                 :          0 :                 cpu_do_idle();
     180                 :            :         local_irq_enable();
     181                 :          0 : }
     182                 :            : 
     183                 :          0 : void arch_cpu_idle_prepare(void)
     184                 :            : {
     185                 :         81 :         local_fiq_enable();
     186                 :         81 : }
     187                 :            : 
     188                 :          0 : void arch_cpu_idle_enter(void)
     189                 :            : {
     190                 :    8658538 :         idle_notifier_call_chain(IDLE_START);
     191                 :    8539469 :         ledtrig_cpu(CPU_LED_IDLE_START);
     192                 :            : #ifdef CONFIG_PL310_ERRATA_769419
     193                 :            :         wmb();
     194                 :            : #endif
     195                 :    8667666 : }
     196                 :            : 
     197                 :          0 : void arch_cpu_idle_exit(void)
     198                 :            : {
     199                 :    8669912 :         ledtrig_cpu(CPU_LED_IDLE_END);
     200                 :    8655378 :         idle_notifier_call_chain(IDLE_END);
     201                 :    8645076 : }
     202                 :            : 
     203                 :            : #ifdef CONFIG_HOTPLUG_CPU
     204                 :          0 : void arch_cpu_idle_dead(void)
     205                 :            : {
     206                 :         78 :         cpu_die();
     207                 :          0 : }
     208                 :            : #endif
     209                 :            : 
     210                 :            : /*
     211                 :            :  * Called from the core idle loop.
     212                 :            :  */
     213                 :          0 : void arch_cpu_idle(void)
     214                 :            : {
     215         [ -  + ]:    8630799 :         if (cpuidle_idle_call())
     216                 :          0 :                 default_idle();
     217                 :      12727 : }
     218                 :            : 
     219                 :            : /*
     220                 :            :  * Called by kexec, immediately prior to machine_kexec().
     221                 :            :  *
     222                 :            :  * This must completely disable all secondary CPUs; simply causing those CPUs
     223                 :            :  * to execute e.g. a RAM-based pin loop is not sufficient. This allows the
     224                 :            :  * kexec'd kernel to use any and all RAM as it sees fit, without having to
     225                 :            :  * avoid any code or data used by any SW CPU pin loop. The CPU hotplug
     226                 :            :  * functionality embodied in disable_nonboot_cpus() to achieve this.
     227                 :            :  */
     228                 :          0 : void machine_shutdown(void)
     229                 :            : {
     230                 :            : #ifdef CONFIG_SMP
     231                 :            :         /*
     232                 :            :          * Disable preemption so we're guaranteed to
     233                 :            :          * run to power off or reboot and prevent
     234                 :            :          * the possibility of switching to another
     235                 :            :          * thread that might wind up blocking on
     236                 :            :          * one of the stopped CPUs.
     237                 :            :          */
     238                 :          0 :         preempt_disable();
     239                 :            : #endif
     240                 :          0 :         disable_nonboot_cpus();
     241                 :          0 : }
     242                 :            : 
     243                 :            : /*
     244                 :            :  * Halting simply requires that the secondary CPUs stop performing any
     245                 :            :  * activity (executing tasks, handling interrupts). smp_send_stop()
     246                 :            :  * achieves this.
     247                 :            :  */
     248                 :          0 : void machine_halt(void)
     249                 :            : {
     250                 :            :         local_irq_disable();
     251                 :          0 :         smp_send_stop();
     252                 :            : 
     253                 :            :         local_irq_disable();
     254                 :          0 :         while (1);
     255                 :            : }
     256                 :            : 
     257                 :            : /*
     258                 :            :  * Power-off simply requires that the secondary CPUs stop performing any
     259                 :            :  * activity (executing tasks, handling interrupts). smp_send_stop()
     260                 :            :  * achieves this. When the system power is turned off, it will take all CPUs
     261                 :            :  * with it.
     262                 :            :  */
     263                 :          0 : void machine_power_off(void)
     264                 :            : {
     265                 :            :         local_irq_disable();
     266                 :          0 :         smp_send_stop();
     267                 :            : 
     268         [ #  # ]:          0 :         if (pm_power_off)
     269                 :          0 :                 pm_power_off();
     270                 :          0 : }
     271                 :            : 
     272                 :            : /*
     273                 :            :  * Restart requires that the secondary CPUs stop performing any activity
     274                 :            :  * while the primary CPU resets the system. Systems with a single CPU can
     275                 :            :  * use soft_restart() as their machine descriptor's .restart hook, since that
     276                 :            :  * will cause the only available CPU to reset. Systems with multiple CPUs must
     277                 :            :  * provide a HW restart implementation, to ensure that all CPUs reset at once.
     278                 :            :  * This is required so that any code running after reset on the primary CPU
     279                 :            :  * doesn't have to co-ordinate with other CPUs to ensure they aren't still
     280                 :            :  * executing pre-reset code, and using RAM that the primary CPU's code wishes
     281                 :            :  * to use. Implementing such co-ordination would be essentially impossible.
     282                 :            :  */
     283                 :          0 : void machine_restart(char *cmd)
     284                 :            : {
     285                 :            :         local_irq_disable();
     286                 :          0 :         smp_send_stop();
     287                 :            : 
     288                 :            :         /* Flush the console to make sure all the relevant messages make it
     289                 :            :          * out to the console drivers */
     290                 :            :         arm_machine_flush_console();
     291                 :            : 
     292                 :          0 :         arm_pm_restart(reboot_mode, cmd);
     293                 :            : 
     294                 :            :         /* Give a grace period for failure to restart of 1s */
     295         [ #  # ]:          0 :         mdelay(1000);
     296                 :            : 
     297                 :            :         /* Whoops - the platform was unable to reboot. Tell the user! */
     298                 :          0 :         printk("Reboot failed -- System halted\n");
     299                 :            :         local_irq_disable();
     300                 :          0 :         while (1);
     301                 :            : }
     302                 :            : 
     303                 :            : /*
     304                 :            :  * dump a block of kernel memory from around the given address
     305                 :            :  */
     306                 :          0 : static void show_data(unsigned long addr, int nbytes, const char *name)
     307                 :            : {
     308                 :            :         int     i, j;
     309                 :            :         int     nlines;
     310                 :            :         u32     *p;
     311                 :            : 
     312                 :            :         /*
     313                 :            :          * don't attempt to dump non-kernel addresses or
     314                 :            :          * values that are probably just small negative numbers
     315                 :            :          */
     316         [ #  # ]:          0 :         if (addr < PAGE_OFFSET || addr > -256UL)
     317                 :          0 :                 return;
     318                 :            : 
     319                 :          0 :         printk("\n%s: %#lx:\n", name, addr);
     320                 :            : 
     321                 :            :         /*
     322                 :            :          * round address down to a 32 bit boundary
     323                 :            :          * and always dump a multiple of 32 bytes
     324                 :            :          */
     325                 :          0 :         p = (u32 *)(addr & ~(sizeof(u32) - 1));
     326                 :          0 :         nbytes += (addr & (sizeof(u32) - 1));
     327                 :          0 :         nlines = (nbytes + 31) / 32;
     328                 :            : 
     329                 :            : 
     330         [ #  # ]:          0 :         for (i = 0; i < nlines; i++) {
     331                 :            :                 /*
     332                 :            :                  * just display low 16 bits of address to keep
     333                 :            :                  * each line of the dump < 80 characters
     334                 :            :                  */
     335                 :          0 :                 printk("%04lx ", (unsigned long)p & 0xffff);
     336         [ #  # ]:          0 :                 for (j = 0; j < 8; j++) {
     337                 :            :                         u32     data;
     338         [ #  # ]:          0 :                         if (probe_kernel_address(p, data)) {
     339                 :          0 :                                 printk(" ********");
     340                 :            :                         } else {
     341                 :          0 :                                 printk(" %08x", data);
     342                 :            :                         }
     343                 :          0 :                         ++p;
     344                 :            :                 }
     345                 :          0 :                 printk("\n");
     346                 :            :         }
     347                 :            : }
     348                 :            : 
     349                 :          0 : static void show_extra_register_data(struct pt_regs *regs, int nbytes)
     350                 :            : {
     351                 :            :         mm_segment_t fs;
     352                 :            : 
     353                 :          0 :         fs = get_fs();
     354                 :            :         set_fs(KERNEL_DS);
     355                 :          0 :         show_data(regs->ARM_pc - nbytes, nbytes * 2, "PC");
     356                 :          0 :         show_data(regs->ARM_lr - nbytes, nbytes * 2, "LR");
     357                 :          0 :         show_data(regs->ARM_sp - nbytes, nbytes * 2, "SP");
     358                 :          0 :         show_data(regs->ARM_ip - nbytes, nbytes * 2, "IP");
     359                 :          0 :         show_data(regs->ARM_fp - nbytes, nbytes * 2, "FP");
     360                 :          0 :         show_data(regs->ARM_r0 - nbytes, nbytes * 2, "R0");
     361                 :          0 :         show_data(regs->ARM_r1 - nbytes, nbytes * 2, "R1");
     362                 :          0 :         show_data(regs->ARM_r2 - nbytes, nbytes * 2, "R2");
     363                 :          0 :         show_data(regs->ARM_r3 - nbytes, nbytes * 2, "R3");
     364                 :          0 :         show_data(regs->ARM_r4 - nbytes, nbytes * 2, "R4");
     365                 :          0 :         show_data(regs->ARM_r5 - nbytes, nbytes * 2, "R5");
     366                 :          0 :         show_data(regs->ARM_r6 - nbytes, nbytes * 2, "R6");
     367                 :          0 :         show_data(regs->ARM_r7 - nbytes, nbytes * 2, "R7");
     368                 :          0 :         show_data(regs->ARM_r8 - nbytes, nbytes * 2, "R8");
     369                 :          0 :         show_data(regs->ARM_r9 - nbytes, nbytes * 2, "R9");
     370                 :          0 :         show_data(regs->ARM_r10 - nbytes, nbytes * 2, "R10");
     371                 :            :         set_fs(fs);
     372                 :          0 : }
     373                 :            : 
     374                 :          0 : void __show_regs(struct pt_regs *regs)
     375                 :            : {
     376                 :            :         unsigned long flags;
     377                 :            :         char buf[64];
     378                 :            : 
     379                 :          0 :         show_regs_print_info(KERN_DEFAULT);
     380                 :            : 
     381                 :          0 :         print_symbol("PC is at %s\n", instruction_pointer(regs));
     382                 :          0 :         print_symbol("LR is at %s\n", regs->ARM_lr);
     383                 :          0 :         printk("pc : [<%08lx>]    lr : [<%08lx>]    psr: %08lx\n"
     384                 :            :                "sp : %08lx  ip : %08lx  fp : %08lx\n",
     385                 :            :                 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
     386                 :            :                 regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
     387                 :          0 :         printk("r10: %08lx  r9 : %08lx  r8 : %08lx\n",
     388                 :            :                 regs->ARM_r10, regs->ARM_r9,
     389                 :            :                 regs->ARM_r8);
     390                 :          0 :         printk("r7 : %08lx  r6 : %08lx  r5 : %08lx  r4 : %08lx\n",
     391                 :            :                 regs->ARM_r7, regs->ARM_r6,
     392                 :            :                 regs->ARM_r5, regs->ARM_r4);
     393                 :          0 :         printk("r3 : %08lx  r2 : %08lx  r1 : %08lx  r0 : %08lx\n",
     394                 :            :                 regs->ARM_r3, regs->ARM_r2,
     395                 :            :                 regs->ARM_r1, regs->ARM_r0);
     396                 :            : 
     397                 :          0 :         flags = regs->ARM_cpsr;
     398         [ #  # ]:          0 :         buf[0] = flags & PSR_N_BIT ? 'N' : 'n';
     399         [ #  # ]:          0 :         buf[1] = flags & PSR_Z_BIT ? 'Z' : 'z';
     400         [ #  # ]:          0 :         buf[2] = flags & PSR_C_BIT ? 'C' : 'c';
     401         [ #  # ]:          0 :         buf[3] = flags & PSR_V_BIT ? 'V' : 'v';
     402                 :          0 :         buf[4] = '\0';
     403                 :            : 
     404 [ #  # ][ #  # ]:          0 :         printk("Flags: %s  IRQs o%s  FIQs o%s  Mode %s  ISA %s  Segment %s\n",
                 [ #  # ]
     405                 :          0 :                 buf, interrupts_enabled(regs) ? "n" : "ff",
     406                 :          0 :                 fast_interrupts_enabled(regs) ? "n" : "ff",
     407                 :          0 :                 processor_modes[processor_mode(regs)],
     408                 :          0 :                 isa_modes[isa_mode(regs)],
     409                 :          0 :                 get_fs() == get_ds() ? "kernel" : "user");
     410                 :            : #ifdef CONFIG_CPU_CP15
     411                 :            :         {
     412                 :            :                 unsigned int ctrl;
     413                 :            : 
     414                 :          0 :                 buf[0] = '\0';
     415                 :            : #ifdef CONFIG_CPU_CP15_MMU
     416                 :            :                 {
     417                 :            :                         unsigned int transbase, dac;
     418                 :          0 :                         asm("mrc p15, 0, %0, c2, c0\n\t"
     419                 :            :                             "mrc p15, 0, %1, c3, c0\n"
     420                 :            :                             : "=r" (transbase), "=r" (dac));
     421                 :          0 :                         snprintf(buf, sizeof(buf), "  Table: %08x  DAC: %08x",
     422                 :            :                                 transbase, dac);
     423                 :            :                 }
     424                 :            : #endif
     425                 :          0 :                 asm("mrc p15, 0, %0, c1, c0\n" : "=r" (ctrl));
     426                 :            : 
     427                 :          0 :                 printk("Control: %08x%s\n", ctrl, buf);
     428                 :            :         }
     429                 :            : #endif
     430                 :            : 
     431                 :          0 :         show_extra_register_data(regs, 128);
     432                 :          0 : }
     433                 :            : 
     434                 :          0 : void show_regs(struct pt_regs * regs)
     435                 :            : {
     436                 :          0 :         printk("\n");
     437                 :          0 :         __show_regs(regs);
     438                 :          0 :         dump_stack();
     439                 :          0 : }
     440                 :            : 
     441                 :            : ATOMIC_NOTIFIER_HEAD(thread_notify_head);
     442                 :            : 
     443                 :            : EXPORT_SYMBOL_GPL(thread_notify_head);
     444                 :            : 
     445                 :            : /*
     446                 :            :  * Free current thread data structures etc..
     447                 :            :  */
     448                 :          0 : void exit_thread(void)
     449                 :            : {
     450                 :            :         thread_notify(THREAD_NOTIFY_EXIT, current_thread_info());
     451                 :    1104222 : }
     452                 :            : 
     453                 :          0 : void flush_thread(void)
     454                 :            : {
     455                 :            :         struct thread_info *thread = current_thread_info();
     456                 :      27246 :         struct task_struct *tsk = current;
     457                 :            : 
     458                 :      27246 :         flush_ptrace_hw_breakpoint(tsk);
     459                 :            : 
     460                 :      27246 :         memset(thread->used_cp, 0, sizeof(thread->used_cp));
     461                 :      27246 :         memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
     462                 :      27245 :         memset(&thread->fpstate, 0, sizeof(union fp_state));
     463                 :            : 
     464                 :            :         thread_notify(THREAD_NOTIFY_FLUSH, thread);
     465                 :      27245 : }
     466                 :            : 
     467                 :          0 : void release_thread(struct task_struct *dead_task)
     468                 :            : {
     469                 :    1104228 : }
     470                 :            : 
     471                 :            : asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
     472                 :            : 
     473                 :            : int
     474                 :          0 : copy_thread(unsigned long clone_flags, unsigned long stack_start,
     475                 :            :             unsigned long stk_sz, struct task_struct *p)
     476                 :            : {
     477                 :    1104222 :         struct thread_info *thread = task_thread_info(p);
     478                 :    1104222 :         struct pt_regs *childregs = task_pt_regs(p);
     479                 :            : 
     480                 :    1104222 :         memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save));
     481                 :            : 
     482         [ +  + ]:    1104222 :         if (likely(!(p->flags & PF_KTHREAD))) {
     483                 :    1103772 :                 *childregs = *current_pt_regs();
     484                 :    1103772 :                 childregs->ARM_r0 = 0;
     485         [ +  + ]:    1103772 :                 if (stack_start)
     486                 :       2260 :                         childregs->ARM_sp = stack_start;
     487                 :            :         } else {
     488                 :        450 :                 memset(childregs, 0, sizeof(struct pt_regs));
     489                 :        450 :                 thread->cpu_context.r4 = stk_sz;
     490                 :        450 :                 thread->cpu_context.r5 = stack_start;
     491                 :        450 :                 childregs->ARM_cpsr = SVC_MODE;
     492                 :            :         }
     493                 :    1104222 :         thread->cpu_context.pc = (unsigned long)ret_from_fork;
     494                 :    1104222 :         thread->cpu_context.sp = (unsigned long)childregs;
     495                 :            : 
     496                 :    1104222 :         clear_ptrace_hw_breakpoint(p);
     497                 :            : 
     498         [ +  + ]:    1104223 :         if (clone_flags & CLONE_SETTLS)
     499                 :       2248 :                 thread->tp_value[0] = childregs->ARM_r3;
     500                 :    1104223 :         thread->tp_value[1] = get_tpuser();
     501                 :            : 
     502                 :            :         thread_notify(THREAD_NOTIFY_COPY, thread);
     503                 :            : 
     504                 :    1104221 :         return 0;
     505                 :            : }
     506                 :            : 
     507                 :            : /*
     508                 :            :  * Fill in the task's elfregs structure for a core dump.
     509                 :            :  */
     510                 :          0 : int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs)
     511                 :            : {
     512                 :          0 :         elf_core_copy_regs(elfregs, task_pt_regs(t));
     513                 :          0 :         return 1;
     514                 :            : }
     515                 :            : 
     516                 :            : /*
     517                 :            :  * fill in the fpe structure for a core dump...
     518                 :            :  */
     519                 :          0 : int dump_fpu (struct pt_regs *regs, struct user_fp *fp)
     520                 :            : {
     521                 :            :         struct thread_info *thread = current_thread_info();
     522                 :          0 :         int used_math = thread->used_cp[1] | thread->used_cp[2];
     523                 :            : 
     524         [ #  # ]:          0 :         if (used_math)
     525                 :          0 :                 memcpy(fp, &thread->fpstate.soft, sizeof (*fp));
     526                 :            : 
     527                 :          0 :         return used_math != 0;
     528                 :            : }
     529                 :            : EXPORT_SYMBOL(dump_fpu);
     530                 :            : 
     531                 :          0 : unsigned long get_wchan(struct task_struct *p)
     532                 :            : {
     533                 :            :         struct stackframe frame;
     534                 :            :         unsigned long stack_page;
     535                 :            :         int count = 0;
     536 [ +  - ][ +  + ]:      24517 :         if (!p || p == current || p->state == TASK_RUNNING)
                 [ +  + ]
     537                 :            :                 return 0;
     538                 :            : 
     539                 :      23414 :         frame.fp = thread_saved_fp(p);
     540                 :      23414 :         frame.sp = thread_saved_sp(p);
     541                 :      23414 :         frame.lr = 0;                   /* recovered from the stack */
     542                 :      23414 :         frame.pc = thread_saved_pc(p);
     543                 :      23414 :         stack_page = (unsigned long)task_stack_page(p);
     544                 :            :         do {
     545 [ +  - ][ +  - ]:      23414 :                 if (frame.sp < stack_page ||
     546         [ -  + ]:      23414 :                     frame.sp >= stack_page + THREAD_SIZE ||
     547                 :      23414 :                     unwind_frame(&frame) < 0)
     548                 :            :                         return 0;
     549         [ #  # ]:          0 :                 if (!in_sched_functions(frame.pc))
     550                 :          0 :                         return frame.pc;
     551         [ #  # ]:          0 :         } while (count ++ < 16);
     552                 :            :         return 0;
     553                 :            : }
     554                 :            : 
     555                 :          0 : unsigned long arch_randomize_brk(struct mm_struct *mm)
     556                 :            : {
     557                 :      27246 :         unsigned long range_end = mm->brk + 0x02000000;
     558         [ -  + ]:      27246 :         return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
     559                 :            : }
     560                 :            : 
     561                 :            : #ifdef CONFIG_MMU
     562                 :            : #ifdef CONFIG_KUSER_HELPERS
     563                 :            : /*
     564                 :            :  * The vectors page is always readable from user space for the
     565                 :            :  * atomic helpers. Insert it into the gate_vma so that it is visible
     566                 :            :  * through ptrace and /proc/<pid>/mem.
     567                 :            :  */
     568                 :            : static struct vm_area_struct gate_vma = {
     569                 :            :         .vm_start       = 0xffff0000,
     570                 :            :         .vm_end         = 0xffff0000 + PAGE_SIZE,
     571                 :            :         .vm_flags       = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC,
     572                 :            : };
     573                 :            : 
     574                 :          0 : static int __init gate_vma_init(void)
     575                 :            : {
     576                 :          0 :         gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
     577                 :          0 :         return 0;
     578                 :            : }
     579                 :            : arch_initcall(gate_vma_init);
     580                 :            : 
     581                 :          0 : struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
     582                 :            : {
     583                 :     942678 :         return &gate_vma;
     584                 :            : }
     585                 :            : 
     586                 :          0 : int in_gate_area(struct mm_struct *mm, unsigned long addr)
     587                 :            : {
     588 [ +  + ][ +  - ]:         45 :         return (addr >= gate_vma.vm_start) && (addr < gate_vma.vm_end);
         [ +  + ][ -  + ]
     589                 :            : }
     590                 :            : 
     591                 :          0 : int in_gate_area_no_mm(unsigned long addr)
     592                 :            : {
     593                 :          0 :         return in_gate_area(NULL, addr);
     594                 :            : }
     595                 :            : #define is_gate_vma(vma)        ((vma) == &gate_vma)
     596                 :            : #else
     597                 :            : #define is_gate_vma(vma)        0
     598                 :            : #endif
     599                 :            : 
     600                 :          0 : const char *arch_vma_name(struct vm_area_struct *vma)
     601                 :            : {
     602    [ + ][ +  - ]:       3004 :         return is_gate_vma(vma) ? "[vectors]" :
     603         [ +  + ]:       2766 :                 (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
     604                 :            :                  "[sigpage]" : NULL;
     605                 :            : }
     606                 :            : 
     607                 :            : static struct page *signal_page;
     608                 :            : extern struct page *get_signal_page(void);
     609                 :            : 
     610                 :          0 : int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
     611                 :            : {
     612                 :      27246 :         struct mm_struct *mm = current->mm;
     613                 :            :         unsigned long addr;
     614                 :            :         int ret;
     615                 :            : 
     616         [ -  + ]:      27246 :         if (!signal_page)
     617                 :          0 :                 signal_page = get_signal_page();
     618         [ +  - ]:      27246 :         if (!signal_page)
     619                 :            :                 return -ENOMEM;
     620                 :            : 
     621                 :      27246 :         down_write(&mm->mmap_sem);
     622                 :      27246 :         addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
     623         [ -  + ]:      27246 :         if (IS_ERR_VALUE(addr)) {
     624                 :          0 :                 ret = addr;
     625                 :          0 :                 goto up_fail;
     626                 :            :         }
     627                 :            : 
     628                 :      27246 :         ret = install_special_mapping(mm, addr, PAGE_SIZE,
     629                 :            :                 VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
     630                 :            :                 &signal_page);
     631                 :            : 
     632         [ +  - ]:      27246 :         if (ret == 0)
     633                 :      27246 :                 mm->context.sigpage = addr;
     634                 :            : 
     635                 :            :  up_fail:
     636                 :      27246 :         up_write(&mm->mmap_sem);
     637                 :      27246 :         return ret;
     638                 :            : }
     639                 :            : #endif

Generated by: LCOV version 1.9