• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/console.h>
35 
36 #include <asm/cacheflush.h>
37 #include <asm/processor.h>
38 #include <asm/thread_notify.h>
39 #include <asm/stacktrace.h>
40 #include <asm/mach/time.h>
41 
42 #ifdef CONFIG_CC_STACKPROTECTOR
43 #include <linux/stackprotector.h>
44 unsigned long __stack_chk_guard __read_mostly;
45 EXPORT_SYMBOL(__stack_chk_guard);
46 #endif
47 
48 static const char *processor_modes[] = {
49   "USER_26", "FIQ_26" , "IRQ_26" , "SVC_26" , "UK4_26" , "UK5_26" , "UK6_26" , "UK7_26" ,
50   "UK8_26" , "UK9_26" , "UK10_26", "UK11_26", "UK12_26", "UK13_26", "UK14_26", "UK15_26",
51   "USER_32", "FIQ_32" , "IRQ_32" , "SVC_32" , "UK4_32" , "UK5_32" , "UK6_32" , "ABT_32" ,
52   "UK8_32" , "UK9_32" , "UK10_32", "UND_32" , "UK12_32", "UK13_32", "UK14_32", "SYS_32"
53 };
54 
55 static const char *isa_modes[] = {
56   "ARM" , "Thumb" , "Jazelle", "ThumbEE"
57 };
58 
59 extern void setup_mm_for_reboot(void);
60 
61 static volatile int hlt_counter;
62 
63 #ifdef CONFIG_SMP
arch_trigger_all_cpu_backtrace(void)64 void arch_trigger_all_cpu_backtrace(void)
65 {
66 	smp_send_all_cpu_backtrace();
67 }
68 #else
arch_trigger_all_cpu_backtrace(void)69 void arch_trigger_all_cpu_backtrace(void)
70 {
71 	dump_stack();
72 }
73 #endif
74 
disable_hlt(void)75 void disable_hlt(void)
76 {
77 	hlt_counter++;
78 }
79 
80 EXPORT_SYMBOL(disable_hlt);
81 
enable_hlt(void)82 void enable_hlt(void)
83 {
84 	hlt_counter--;
85 }
86 
87 EXPORT_SYMBOL(enable_hlt);
88 
nohlt_setup(char * __unused)89 static int __init nohlt_setup(char *__unused)
90 {
91 	hlt_counter = 1;
92 	return 1;
93 }
94 
hlt_setup(char * __unused)95 static int __init hlt_setup(char *__unused)
96 {
97 	hlt_counter = 0;
98 	return 1;
99 }
100 
101 __setup("nohlt", nohlt_setup);
102 __setup("hlt", hlt_setup);
103 
104 extern void call_with_stack(void (*fn)(void *), void *arg, void *sp);
105 typedef void (*phys_reset_t)(unsigned long);
106 
107 #ifdef CONFIG_ARM_FLUSH_CONSOLE_ON_RESTART
arm_machine_flush_console(void)108 void arm_machine_flush_console(void)
109 {
110 	printk("\n");
111 	pr_emerg("Restarting %s\n", linux_banner);
112 	if (console_trylock()) {
113 		console_unlock();
114 		return;
115 	}
116 
117 	mdelay(50);
118 
119 	local_irq_disable();
120 	if (!console_trylock())
121 		pr_emerg("arm_restart: Console was locked! Busting\n");
122 	else
123 		pr_emerg("arm_restart: Console was locked!\n");
124 	console_unlock();
125 }
126 #else
arm_machine_flush_console(void)127 void arm_machine_flush_console(void)
128 {
129 }
130 #endif
131 
132 /*
133  * A temporary stack to use for CPU reset. This is static so that we
134  * don't clobber it with the identity mapping. When running with this
135  * stack, any references to the current task *will not work* so you
136  * should really do as little as possible before jumping to your reset
137  * code.
138  */
139 static u64 soft_restart_stack[16];
140 
__soft_restart(void * addr)141 static void __soft_restart(void *addr)
142 {
143 	phys_reset_t phys_reset;
144 
145 	/* Take out a flat memory mapping. */
146 	setup_mm_for_reboot();
147 
148 	/* Clean and invalidate caches */
149 	flush_cache_all();
150 
151 	/* Turn off caching */
152 	cpu_proc_fin();
153 
154 	/* Push out any further dirty data, and ensure cache is empty */
155 	flush_cache_all();
156 
157 	/* Switch to the identity mapping. */
158 	phys_reset = (phys_reset_t)(unsigned long)virt_to_phys(cpu_reset);
159 	phys_reset((unsigned long)addr);
160 
161 	/* Should never get here. */
162 	BUG();
163 }
164 
soft_restart(unsigned long addr)165 void soft_restart(unsigned long addr)
166 {
167 	u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
168 
169 	/* Disable interrupts first */
170 	local_irq_disable();
171 	local_fiq_disable();
172 
173 	/* Disable the L2 if we're the last man standing. */
174 	if (num_online_cpus() == 1)
175 		outer_disable();
176 
177 	/* Change to the new stack and continue with the reset. */
178 	call_with_stack(__soft_restart, (void *)addr, (void *)stack);
179 
180 	/* Should never get here. */
181 	BUG();
182 }
183 
null_restart(char mode,const char * cmd)184 static void null_restart(char mode, const char *cmd)
185 {
186 }
187 
188 /*
189  * Function pointers to optional machine specific functions
190  */
191 void (*pm_power_off)(void);
192 EXPORT_SYMBOL(pm_power_off);
193 
194 void (*arm_pm_restart)(char str, const char *cmd) = null_restart;
195 EXPORT_SYMBOL_GPL(arm_pm_restart);
196 
do_nothing(void * unused)197 static void do_nothing(void *unused)
198 {
199 }
200 
201 /*
202  * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
203  * pm_idle and update to new pm_idle value. Required while changing pm_idle
204  * handler on SMP systems.
205  *
206  * Caller must have changed pm_idle to the new value before the call. Old
207  * pm_idle value will not be used by any CPU after the return of this function.
208  */
cpu_idle_wait(void)209 void cpu_idle_wait(void)
210 {
211 	smp_mb();
212 	/* kick all the CPUs so that they exit out of pm_idle */
213 	smp_call_function(do_nothing, NULL, 1);
214 }
215 EXPORT_SYMBOL_GPL(cpu_idle_wait);
216 
217 /*
218  * This is our default idle handler.
219  */
220 
221 void (*arm_pm_idle)(void);
222 
default_idle(void)223 static void default_idle(void)
224 {
225 	if (arm_pm_idle)
226 		arm_pm_idle();
227 	else
228 		cpu_do_idle();
229 	local_irq_enable();
230 }
231 
232 void (*pm_idle)(void) = default_idle;
233 EXPORT_SYMBOL(pm_idle);
234 
235 /*
236  * The idle thread, has rather strange semantics for calling pm_idle,
237  * but this is what x86 does and we need to do the same, so that
238  * things like cpuidle get called in the same way.  The only difference
239  * is that we always respect 'hlt_counter' to prevent low power idle.
240  */
cpu_idle(void)241 void cpu_idle(void)
242 {
243 	local_fiq_enable();
244 
245 	/* endless idle loop with no priority at all */
246 	while (1) {
247 		idle_notifier_call_chain(IDLE_START);
248 		tick_nohz_idle_enter();
249 		rcu_idle_enter();
250 		while (!need_resched()) {
251 #ifdef CONFIG_HOTPLUG_CPU
252 			if (cpu_is_offline(smp_processor_id()))
253 				cpu_die();
254 #endif
255 
256 			/*
257 			 * We need to disable interrupts here
258 			 * to ensure we don't miss a wakeup call.
259 			 */
260 			local_irq_disable();
261 #ifdef CONFIG_PL310_ERRATA_769419
262 			wmb();
263 #endif
264 			if (hlt_counter) {
265 				local_irq_enable();
266 				cpu_relax();
267 			} else if (!need_resched()) {
268 				stop_critical_timings();
269 				if (cpuidle_idle_call())
270 					pm_idle();
271 				start_critical_timings();
272 				/*
273 				 * pm_idle functions must always
274 				 * return with IRQs enabled.
275 				 */
276 				WARN_ON(irqs_disabled());
277 			} else
278 				local_irq_enable();
279 		}
280 		rcu_idle_exit();
281 		tick_nohz_idle_exit();
282 		idle_notifier_call_chain(IDLE_END);
283 		schedule_preempt_disabled();
284 	}
285 }
286 
287 static char reboot_mode = 'h';
288 
reboot_setup(char * str)289 int __init reboot_setup(char *str)
290 {
291 	reboot_mode = str[0];
292 	return 1;
293 }
294 
295 __setup("reboot=", reboot_setup);
296 
machine_shutdown(void)297 void machine_shutdown(void)
298 {
299 #ifdef CONFIG_SMP
300 	/*
301 	 * Disable preemption so we're guaranteed to
302 	 * run to power off or reboot and prevent
303 	 * the possibility of switching to another
304 	 * thread that might wind up blocking on
305 	 * one of the stopped CPUs.
306 	 */
307 	preempt_disable();
308 
309 	smp_send_stop();
310 #endif
311 }
312 
machine_halt(void)313 void machine_halt(void)
314 {
315 	machine_shutdown();
316 	local_irq_disable();
317 	while (1);
318 }
319 
machine_power_off(void)320 void machine_power_off(void)
321 {
322 	machine_shutdown();
323 	if (pm_power_off)
324 		pm_power_off();
325 }
326 
machine_restart(char * cmd)327 void machine_restart(char *cmd)
328 {
329 	machine_shutdown();
330 
331 	/* Flush the console to make sure all the relevant messages make it
332 	 * out to the console drivers */
333 	arm_machine_flush_console();
334 
335 	arm_pm_restart(reboot_mode, cmd);
336 
337 	/* Give a grace period for failure to restart of 1s */
338 	mdelay(1000);
339 
340 	/* Whoops - the platform was unable to reboot. Tell the user! */
341 	printk("Reboot failed -- System halted\n");
342 	local_irq_disable();
343 	while (1);
344 }
345 
346 /*
347  * dump a block of kernel memory from around the given address
348  */
show_data(unsigned long addr,int nbytes,const char * name)349 static void show_data(unsigned long addr, int nbytes, const char *name)
350 {
351 	int	i, j;
352 	int	nlines;
353 	u32	*p;
354 
355 	/*
356 	 * don't attempt to dump non-kernel addresses or
357 	 * values that are probably just small negative numbers
358 	 */
359 	if (addr < PAGE_OFFSET || addr > -256UL)
360 		return;
361 
362 	printk("\n%s: %#lx:\n", name, addr);
363 
364 	/*
365 	 * round address down to a 32 bit boundary
366 	 * and always dump a multiple of 32 bytes
367 	 */
368 	p = (u32 *)(addr & ~(sizeof(u32) - 1));
369 	nbytes += (addr & (sizeof(u32) - 1));
370 	nlines = (nbytes + 31) / 32;
371 
372 
373 	for (i = 0; i < nlines; i++) {
374 		/*
375 		 * just display low 16 bits of address to keep
376 		 * each line of the dump < 80 characters
377 		 */
378 		printk("%04lx ", (unsigned long)p & 0xffff);
379 		for (j = 0; j < 8; j++) {
380 			u32	data;
381 			if (probe_kernel_address(p, data)) {
382 				printk(" ********");
383 			} else {
384 				printk(" %08x", data);
385 			}
386 			++p;
387 		}
388 		printk("\n");
389 	}
390 }
391 
show_extra_register_data(struct pt_regs * regs,int nbytes)392 static void show_extra_register_data(struct pt_regs *regs, int nbytes)
393 {
394 	mm_segment_t fs;
395 
396 	fs = get_fs();
397 	set_fs(KERNEL_DS);
398 	show_data(regs->ARM_pc - nbytes, nbytes * 2, "PC");
399 	show_data(regs->ARM_lr - nbytes, nbytes * 2, "LR");
400 	show_data(regs->ARM_sp - nbytes, nbytes * 2, "SP");
401 	show_data(regs->ARM_ip - nbytes, nbytes * 2, "IP");
402 	show_data(regs->ARM_fp - nbytes, nbytes * 2, "FP");
403 	show_data(regs->ARM_r0 - nbytes, nbytes * 2, "R0");
404 	show_data(regs->ARM_r1 - nbytes, nbytes * 2, "R1");
405 	show_data(regs->ARM_r2 - nbytes, nbytes * 2, "R2");
406 	show_data(regs->ARM_r3 - nbytes, nbytes * 2, "R3");
407 	show_data(regs->ARM_r4 - nbytes, nbytes * 2, "R4");
408 	show_data(regs->ARM_r5 - nbytes, nbytes * 2, "R5");
409 	show_data(regs->ARM_r6 - nbytes, nbytes * 2, "R6");
410 	show_data(regs->ARM_r7 - nbytes, nbytes * 2, "R7");
411 	show_data(regs->ARM_r8 - nbytes, nbytes * 2, "R8");
412 	show_data(regs->ARM_r9 - nbytes, nbytes * 2, "R9");
413 	show_data(regs->ARM_r10 - nbytes, nbytes * 2, "R10");
414 	set_fs(fs);
415 }
416 
__show_regs(struct pt_regs * regs)417 void __show_regs(struct pt_regs *regs)
418 {
419 	unsigned long flags;
420 	char buf[64];
421 
422 	printk("CPU: %d    %s  (%s %.*s)\n",
423 		raw_smp_processor_id(), print_tainted(),
424 		init_utsname()->release,
425 		(int)strcspn(init_utsname()->version, " "),
426 		init_utsname()->version);
427 	print_symbol("PC is at %s\n", instruction_pointer(regs));
428 	print_symbol("LR is at %s\n", regs->ARM_lr);
429 	printk("pc : [<%08lx>]    lr : [<%08lx>]    psr: %08lx\n"
430 	       "sp : %08lx  ip : %08lx  fp : %08lx\n",
431 		regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
432 		regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
433 	printk("r10: %08lx  r9 : %08lx  r8 : %08lx\n",
434 		regs->ARM_r10, regs->ARM_r9,
435 		regs->ARM_r8);
436 	printk("r7 : %08lx  r6 : %08lx  r5 : %08lx  r4 : %08lx\n",
437 		regs->ARM_r7, regs->ARM_r6,
438 		regs->ARM_r5, regs->ARM_r4);
439 	printk("r3 : %08lx  r2 : %08lx  r1 : %08lx  r0 : %08lx\n",
440 		regs->ARM_r3, regs->ARM_r2,
441 		regs->ARM_r1, regs->ARM_r0);
442 
443 	flags = regs->ARM_cpsr;
444 	buf[0] = flags & PSR_N_BIT ? 'N' : 'n';
445 	buf[1] = flags & PSR_Z_BIT ? 'Z' : 'z';
446 	buf[2] = flags & PSR_C_BIT ? 'C' : 'c';
447 	buf[3] = flags & PSR_V_BIT ? 'V' : 'v';
448 	buf[4] = '\0';
449 
450 	printk("Flags: %s  IRQs o%s  FIQs o%s  Mode %s  ISA %s  Segment %s\n",
451 		buf, interrupts_enabled(regs) ? "n" : "ff",
452 		fast_interrupts_enabled(regs) ? "n" : "ff",
453 		processor_modes[processor_mode(regs)],
454 		isa_modes[isa_mode(regs)],
455 		get_fs() == get_ds() ? "kernel" : "user");
456 #ifdef CONFIG_CPU_CP15
457 	{
458 		unsigned int ctrl;
459 
460 		buf[0] = '\0';
461 #ifdef CONFIG_CPU_CP15_MMU
462 		{
463 			unsigned int transbase, dac;
464 			asm("mrc p15, 0, %0, c2, c0\n\t"
465 			    "mrc p15, 0, %1, c3, c0\n"
466 			    : "=r" (transbase), "=r" (dac));
467 			snprintf(buf, sizeof(buf), "  Table: %08x  DAC: %08x",
468 			  	transbase, dac);
469 		}
470 #endif
471 		asm("mrc p15, 0, %0, c1, c0\n" : "=r" (ctrl));
472 
473 		printk("Control: %08x%s\n", ctrl, buf);
474 	}
475 #endif
476 
477 	show_extra_register_data(regs, 128);
478 }
479 
show_regs(struct pt_regs * regs)480 void show_regs(struct pt_regs * regs)
481 {
482 	printk("\n");
483 	printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
484 	__show_regs(regs);
485 	dump_stack();
486 }
487 
488 ATOMIC_NOTIFIER_HEAD(thread_notify_head);
489 
490 EXPORT_SYMBOL_GPL(thread_notify_head);
491 
492 /*
493  * Free current thread data structures etc..
494  */
exit_thread(void)495 void exit_thread(void)
496 {
497 	thread_notify(THREAD_NOTIFY_EXIT, current_thread_info());
498 }
499 
flush_thread(void)500 void flush_thread(void)
501 {
502 	struct thread_info *thread = current_thread_info();
503 	struct task_struct *tsk = current;
504 
505 	flush_ptrace_hw_breakpoint(tsk);
506 
507 	memset(thread->used_cp, 0, sizeof(thread->used_cp));
508 	memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
509 	memset(&thread->fpstate, 0, sizeof(union fp_state));
510 
511 	thread_notify(THREAD_NOTIFY_FLUSH, thread);
512 }
513 
release_thread(struct task_struct * dead_task)514 void release_thread(struct task_struct *dead_task)
515 {
516 }
517 
518 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
519 
520 int
copy_thread(unsigned long clone_flags,unsigned long stack_start,unsigned long stk_sz,struct task_struct * p,struct pt_regs * regs)521 copy_thread(unsigned long clone_flags, unsigned long stack_start,
522 	    unsigned long stk_sz, struct task_struct *p, struct pt_regs *regs)
523 {
524 	struct thread_info *thread = task_thread_info(p);
525 	struct pt_regs *childregs = task_pt_regs(p);
526 
527 	*childregs = *regs;
528 	childregs->ARM_r0 = 0;
529 	childregs->ARM_sp = stack_start;
530 
531 	memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save));
532 	thread->cpu_context.sp = (unsigned long)childregs;
533 	thread->cpu_context.pc = (unsigned long)ret_from_fork;
534 
535 	clear_ptrace_hw_breakpoint(p);
536 
537 	if (clone_flags & CLONE_SETTLS)
538 		thread->tp_value = regs->ARM_r3;
539 
540 	thread_notify(THREAD_NOTIFY_COPY, thread);
541 
542 	return 0;
543 }
544 
545 /*
546  * Fill in the task's elfregs structure for a core dump.
547  */
dump_task_regs(struct task_struct * t,elf_gregset_t * elfregs)548 int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs)
549 {
550 	elf_core_copy_regs(elfregs, task_pt_regs(t));
551 	return 1;
552 }
553 
554 /*
555  * fill in the fpe structure for a core dump...
556  */
dump_fpu(struct pt_regs * regs,struct user_fp * fp)557 int dump_fpu (struct pt_regs *regs, struct user_fp *fp)
558 {
559 	struct thread_info *thread = current_thread_info();
560 	int used_math = thread->used_cp[1] | thread->used_cp[2];
561 
562 	if (used_math)
563 		memcpy(fp, &thread->fpstate.soft, sizeof (*fp));
564 
565 	return used_math != 0;
566 }
567 EXPORT_SYMBOL(dump_fpu);
568 
569 /*
570  * Shuffle the argument into the correct register before calling the
571  * thread function.  r4 is the thread argument, r5 is the pointer to
572  * the thread function, and r6 points to the exit function.
573  */
574 extern void kernel_thread_helper(void);
575 asm(	".pushsection .text\n"
576 "	.align\n"
577 "	.type	kernel_thread_helper, #function\n"
578 "kernel_thread_helper:\n"
579 #ifdef CONFIG_TRACE_IRQFLAGS
580 "	bl	trace_hardirqs_on\n"
581 #endif
582 "	msr	cpsr_c, r7\n"
583 "	mov	r0, r4\n"
584 "	mov	lr, r6\n"
585 "	mov	pc, r5\n"
586 "	.size	kernel_thread_helper, . - kernel_thread_helper\n"
587 "	.popsection");
588 
589 #ifdef CONFIG_ARM_UNWIND
590 extern void kernel_thread_exit(long code);
591 asm(	".pushsection .text\n"
592 "	.align\n"
593 "	.type	kernel_thread_exit, #function\n"
594 "kernel_thread_exit:\n"
595 "	.fnstart\n"
596 "	.cantunwind\n"
597 "	bl	do_exit\n"
598 "	nop\n"
599 "	.fnend\n"
600 "	.size	kernel_thread_exit, . - kernel_thread_exit\n"
601 "	.popsection");
602 #else
603 #define kernel_thread_exit	do_exit
604 #endif
605 
606 /*
607  * Create a kernel thread.
608  */
kernel_thread(int (* fn)(void *),void * arg,unsigned long flags)609 pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
610 {
611 	struct pt_regs regs;
612 
613 	memset(&regs, 0, sizeof(regs));
614 
615 	regs.ARM_r4 = (unsigned long)arg;
616 	regs.ARM_r5 = (unsigned long)fn;
617 	regs.ARM_r6 = (unsigned long)kernel_thread_exit;
618 	regs.ARM_r7 = SVC_MODE | PSR_ENDSTATE | PSR_ISETSTATE;
619 	regs.ARM_pc = (unsigned long)kernel_thread_helper;
620 	regs.ARM_cpsr = regs.ARM_r7 | PSR_I_BIT;
621 
622 	return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
623 }
624 EXPORT_SYMBOL(kernel_thread);
625 
get_wchan(struct task_struct * p)626 unsigned long get_wchan(struct task_struct *p)
627 {
628 	struct stackframe frame;
629 	int count = 0;
630 	if (!p || p == current || p->state == TASK_RUNNING)
631 		return 0;
632 
633 	frame.fp = thread_saved_fp(p);
634 	frame.sp = thread_saved_sp(p);
635 	frame.lr = 0;			/* recovered from the stack */
636 	frame.pc = thread_saved_pc(p);
637 	do {
638 		int ret = unwind_frame(&frame);
639 		if (ret < 0)
640 			return 0;
641 		if (!in_sched_functions(frame.pc))
642 			return frame.pc;
643 	} while (count ++ < 16);
644 	return 0;
645 }
646 
arch_randomize_brk(struct mm_struct * mm)647 unsigned long arch_randomize_brk(struct mm_struct *mm)
648 {
649 	unsigned long range_end = mm->brk + 0x02000000;
650 	return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
651 }
652 
653 #ifdef CONFIG_MMU
654 #ifdef CONFIG_KUSER_HELPERS
655 /*
656  * The vectors page is always readable from user space for the
657  * atomic helpers and the signal restart code. Insert it into the
658  * gate_vma so that it is visible through ptrace and /proc/<pid>/mem.
659  */
660 static struct vm_area_struct gate_vma;
661 
gate_vma_init(void)662 static int __init gate_vma_init(void)
663 {
664 	gate_vma.vm_start	= 0xffff0000;
665 	gate_vma.vm_end		= 0xffff0000 + PAGE_SIZE;
666 	gate_vma.vm_page_prot	= PAGE_READONLY_EXEC;
667 	gate_vma.vm_flags	= VM_READ | VM_EXEC |
668 				  VM_MAYREAD | VM_MAYEXEC;
669 	return 0;
670 }
671 arch_initcall(gate_vma_init);
672 
get_gate_vma(struct mm_struct * mm)673 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
674 {
675 	return &gate_vma;
676 }
677 
in_gate_area(struct mm_struct * mm,unsigned long addr)678 int in_gate_area(struct mm_struct *mm, unsigned long addr)
679 {
680 	return (addr >= gate_vma.vm_start) && (addr < gate_vma.vm_end);
681 }
682 
in_gate_area_no_mm(unsigned long addr)683 int in_gate_area_no_mm(unsigned long addr)
684 {
685 	return in_gate_area(NULL, addr);
686 }
687 #define is_gate_vma(vma)	((vma) == &gate_vma)
688 #else
689 #define is_gate_vma(vma)	0
690 #endif
691 
arch_vma_name(struct vm_area_struct * vma)692 const char *arch_vma_name(struct vm_area_struct *vma)
693 {
694 	return is_gate_vma(vma) ? "[vectors]" : NULL;
695 }
696 #endif
697