| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 2 |  * This file handles the architecture dependent parts of process handling. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 |  * | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 4 |  *    Copyright IBM Corp. 1999,2009 | 
 | 5 |  *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>, | 
 | 6 |  *		 Hartmut Penner <hp@de.ibm.com>, | 
 | 7 |  *		 Denis Joseph Barrow, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  */ | 
 | 9 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/compiler.h> | 
 | 11 | #include <linux/cpu.h> | 
 | 12 | #include <linux/errno.h> | 
 | 13 | #include <linux/sched.h> | 
 | 14 | #include <linux/kernel.h> | 
 | 15 | #include <linux/mm.h> | 
| Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 16 | #include <linux/fs.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/smp.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/stddef.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/unistd.h> | 
 | 21 | #include <linux/ptrace.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/vmalloc.h> | 
 | 23 | #include <linux/user.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> | 
 | 25 | #include <linux/delay.h> | 
 | 26 | #include <linux/reboot.h> | 
 | 27 | #include <linux/init.h> | 
 | 28 | #include <linux/module.h> | 
 | 29 | #include <linux/notifier.h> | 
| Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 30 | #include <linux/tick.h> | 
| Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 31 | #include <linux/elfcore.h> | 
| Martin Schwidefsky | 6f43092 | 2008-12-31 15:11:40 +0100 | [diff] [blame] | 32 | #include <linux/kernel_stat.h> | 
| Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 33 | #include <linux/syscalls.h> | 
| Heiko Carstens | 3e86a8c | 2009-09-22 22:58:42 +0200 | [diff] [blame] | 34 | #include <linux/compat.h> | 
| Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 35 | #include <asm/compat.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/uaccess.h> | 
 | 37 | #include <asm/pgtable.h> | 
 | 38 | #include <asm/system.h> | 
 | 39 | #include <asm/io.h> | 
 | 40 | #include <asm/processor.h> | 
 | 41 | #include <asm/irq.h> | 
 | 42 | #include <asm/timer.h> | 
| Heiko Carstens | f5daba1 | 2009-03-26 15:24:01 +0100 | [diff] [blame] | 43 | #include <asm/nmi.h> | 
| Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 44 | #include "entry.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
| Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 46 | asmlinkage void ret_from_fork(void) asm ("ret_from_fork"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 |  | 
 | 48 | /* | 
 | 49 |  * Return saved PC of a blocked thread. used in kernel/sched. | 
 | 50 |  * resume in entry.S does not create a new stack frame, it | 
 | 51 |  * just stores the registers %r6-%r15 to the frame given by | 
 | 52 |  * schedule. We want to return the address of the caller of | 
 | 53 |  * schedule, so we have to walk the backchain one time to | 
 | 54 |  * find the frame schedule() store its return address. | 
 | 55 |  */ | 
 | 56 | unsigned long thread_saved_pc(struct task_struct *tsk) | 
 | 57 | { | 
| Heiko Carstens | eb33c19 | 2006-01-14 13:20:57 -0800 | [diff] [blame] | 58 | 	struct stack_frame *sf, *low, *high; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 |  | 
| Heiko Carstens | eb33c19 | 2006-01-14 13:20:57 -0800 | [diff] [blame] | 60 | 	if (!tsk || !task_stack_page(tsk)) | 
 | 61 | 		return 0; | 
 | 62 | 	low = task_stack_page(tsk); | 
 | 63 | 	high = (struct stack_frame *) task_pt_regs(tsk); | 
 | 64 | 	sf = (struct stack_frame *) (tsk->thread.ksp & PSW_ADDR_INSN); | 
 | 65 | 	if (sf <= low || sf > high) | 
 | 66 | 		return 0; | 
 | 67 | 	sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN); | 
 | 68 | 	if (sf <= low || sf > high) | 
 | 69 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | 	return sf->gprs[8]; | 
 | 71 | } | 
 | 72 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* | 
 | 74 |  * The idle loop on a S390... | 
 | 75 |  */ | 
| Adrian Bunk | cdb0452 | 2006-03-24 03:15:57 -0800 | [diff] [blame] | 76 | static void default_idle(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | 	/* CPU is going idle. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #ifdef CONFIG_HOTPLUG_CPU | 
| Heiko Carstens | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 80 | 	if (cpu_is_offline(smp_processor_id())) { | 
| Heiko Carstens | 1fca251 | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 81 | 		preempt_enable_no_resched(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | 		cpu_die(); | 
| Heiko Carstens | 1fca251 | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 83 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #endif | 
| Heiko Carstens | 6931be0 | 2010-10-25 16:10:12 +0200 | [diff] [blame] | 85 | 	local_irq_disable(); | 
 | 86 | 	if (need_resched()) { | 
 | 87 | 		local_irq_enable(); | 
 | 88 | 		return; | 
 | 89 | 	} | 
| Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 90 | 	local_mcck_disable(); | 
 | 91 | 	if (test_thread_flag(TIF_MCCK_PENDING)) { | 
 | 92 | 		local_mcck_enable(); | 
 | 93 | 		local_irq_enable(); | 
 | 94 | 		s390_handle_mcck(); | 
 | 95 | 		return; | 
 | 96 | 	} | 
| Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 97 | 	trace_hardirqs_on(); | 
| Heiko Carstens | 632448f | 2008-11-14 18:18:04 +0100 | [diff] [blame] | 98 | 	/* Don't trace preempt off for idle. */ | 
 | 99 | 	stop_critical_timings(); | 
| Martin Schwidefsky | 9cfb9b3 | 2008-12-31 15:11:41 +0100 | [diff] [blame] | 100 | 	/* Stop virtual timer and halt the cpu. */ | 
 | 101 | 	vtime_stop_cpu(); | 
 | 102 | 	/* Reenable preemption tracer. */ | 
| Heiko Carstens | 632448f | 2008-11-14 18:18:04 +0100 | [diff] [blame] | 103 | 	start_critical_timings(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } | 
 | 105 |  | 
 | 106 | void cpu_idle(void) | 
 | 107 | { | 
| Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 108 | 	for (;;) { | 
| Thomas Gleixner | e338125 | 2008-07-19 09:33:21 +0200 | [diff] [blame] | 109 | 		tick_nohz_stop_sched_tick(1); | 
| Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 110 | 		while (!need_resched()) | 
 | 111 | 			default_idle(); | 
| Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 112 | 		tick_nohz_restart_sched_tick(); | 
| Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 113 | 		preempt_enable_no_resched(); | 
 | 114 | 		schedule(); | 
 | 115 | 		preempt_disable(); | 
 | 116 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } | 
 | 118 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | extern void kernel_thread_starter(void); | 
 | 120 |  | 
| Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 121 | asm( | 
 | 122 | 	".align 4\n" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 	"kernel_thread_starter:\n" | 
 | 124 | 	"    la    2,0(10)\n" | 
 | 125 | 	"    basr  14,9\n" | 
 | 126 | 	"    la    2,0\n" | 
 | 127 | 	"    br    11\n"); | 
 | 128 |  | 
 | 129 | int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) | 
 | 130 | { | 
 | 131 | 	struct pt_regs regs; | 
 | 132 |  | 
 | 133 | 	memset(®s, 0, sizeof(regs)); | 
| Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 134 | 	regs.psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | 	regs.psw.addr = (unsigned long) kernel_thread_starter | PSW_ADDR_AMODE; | 
 | 136 | 	regs.gprs[9] = (unsigned long) fn; | 
 | 137 | 	regs.gprs[10] = (unsigned long) arg; | 
 | 138 | 	regs.gprs[11] = (unsigned long) do_exit; | 
 | 139 | 	regs.orig_gpr2 = -1; | 
 | 140 |  | 
 | 141 | 	/* Ok, create the new process.. */ | 
 | 142 | 	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, | 
 | 143 | 		       0, ®s, 0, NULL, NULL); | 
 | 144 | } | 
| Heiko Carstens | 1485c5c | 2009-03-26 15:24:04 +0100 | [diff] [blame] | 145 | EXPORT_SYMBOL(kernel_thread); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
 | 147 | /* | 
 | 148 |  * Free current thread data structures etc.. | 
 | 149 |  */ | 
 | 150 | void exit_thread(void) | 
 | 151 | { | 
 | 152 | } | 
 | 153 |  | 
 | 154 | void flush_thread(void) | 
 | 155 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } | 
 | 157 |  | 
 | 158 | void release_thread(struct task_struct *dead_task) | 
 | 159 | { | 
 | 160 | } | 
 | 161 |  | 
| Alexey Dobriyan | 6f2c55b | 2009-04-02 16:56:59 -0700 | [diff] [blame] | 162 | int copy_thread(unsigned long clone_flags, unsigned long new_stackp, | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 163 | 		unsigned long unused, | 
 | 164 | 		struct task_struct *p, struct pt_regs *regs) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { | 
| Heiko Carstens | 5168ce2 | 2009-03-26 15:23:53 +0100 | [diff] [blame] | 166 | 	struct thread_info *ti; | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 167 | 	struct fake_frame | 
 | 168 | 	{ | 
 | 169 | 		struct stack_frame sf; | 
 | 170 | 		struct pt_regs childregs; | 
 | 171 | 	} *frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 |  | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 173 | 	frame = container_of(task_pt_regs(p), struct fake_frame, childregs); | 
 | 174 | 	p->thread.ksp = (unsigned long) frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | 	/* Store access registers to kernel stack of new process. */ | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 176 | 	frame->childregs = *regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | 	frame->childregs.gprs[2] = 0;	/* child returns 0 on fork. */ | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 178 | 	frame->childregs.gprs[15] = new_stackp; | 
 | 179 | 	frame->sf.back_chain = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 |  | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 181 | 	/* new return point is ret_from_fork */ | 
 | 182 | 	frame->sf.gprs[8] = (unsigned long) ret_from_fork; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 184 | 	/* fake return stack for resume(), don't go back to schedule */ | 
 | 185 | 	frame->sf.gprs[9] = (unsigned long) frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 |  | 
 | 187 | 	/* Save access registers to new thread structure. */ | 
 | 188 | 	save_access_regs(&p->thread.acrs[0]); | 
 | 189 |  | 
| Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 190 | #ifndef CONFIG_64BIT | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 191 | 	/* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | 	 * save fprs to current->thread.fp_regs to merge them with | 
 | 193 | 	 * the emulated registers and then copy the result to the child. | 
 | 194 | 	 */ | 
 | 195 | 	save_fp_regs(¤t->thread.fp_regs); | 
 | 196 | 	memcpy(&p->thread.fp_regs, ¤t->thread.fp_regs, | 
 | 197 | 	       sizeof(s390_fp_regs)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | 	/* Set a new TLS ?  */ | 
 | 199 | 	if (clone_flags & CLONE_SETTLS) | 
 | 200 | 		p->thread.acrs[0] = regs->gprs[6]; | 
| Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 201 | #else /* CONFIG_64BIT */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | 	/* Save the fpu registers to new thread structure. */ | 
 | 203 | 	save_fp_regs(&p->thread.fp_regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | 	/* Set a new TLS ?  */ | 
 | 205 | 	if (clone_flags & CLONE_SETTLS) { | 
| Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 206 | 		if (is_compat_task()) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | 			p->thread.acrs[0] = (unsigned int) regs->gprs[6]; | 
 | 208 | 		} else { | 
 | 209 | 			p->thread.acrs[0] = (unsigned int)(regs->gprs[6] >> 32); | 
 | 210 | 			p->thread.acrs[1] = (unsigned int) regs->gprs[6]; | 
 | 211 | 		} | 
 | 212 | 	} | 
| Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 213 | #endif /* CONFIG_64BIT */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | 	/* start new process with ar4 pointing to the correct address space */ | 
 | 215 | 	p->thread.mm_segment = get_fs(); | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 216 | 	/* Don't copy debug registers */ | 
 | 217 | 	memset(&p->thread.per_info, 0, sizeof(p->thread.per_info)); | 
| Martin Schwidefsky | f8d5faf | 2010-01-13 20:44:26 +0100 | [diff] [blame] | 218 | 	clear_tsk_thread_flag(p, TIF_SINGLE_STEP); | 
| Heiko Carstens | 5168ce2 | 2009-03-26 15:23:53 +0100 | [diff] [blame] | 219 | 	/* Initialize per thread user and system timer values */ | 
 | 220 | 	ti = task_thread_info(p); | 
 | 221 | 	ti->user_timer = 0; | 
 | 222 | 	ti->system_timer = 0; | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 223 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } | 
 | 225 |  | 
| Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 226 | SYSCALL_DEFINE0(fork) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 228 | 	struct pt_regs *regs = task_pt_regs(current); | 
 | 229 | 	return do_fork(SIGCHLD, regs->gprs[15], regs, 0, NULL, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } | 
 | 231 |  | 
| Heiko Carstens | 2d70ca2 | 2009-09-22 22:58:41 +0200 | [diff] [blame] | 232 | SYSCALL_DEFINE4(clone, unsigned long, newsp, unsigned long, clone_flags, | 
 | 233 | 		int __user *, parent_tidptr, int __user *, child_tidptr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 235 | 	struct pt_regs *regs = task_pt_regs(current); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 |  | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 237 | 	if (!newsp) | 
 | 238 | 		newsp = regs->gprs[15]; | 
 | 239 | 	return do_fork(clone_flags, newsp, regs, 0, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | 		       parent_tidptr, child_tidptr); | 
 | 241 | } | 
 | 242 |  | 
 | 243 | /* | 
 | 244 |  * This is trivial, and on the face of it looks like it | 
 | 245 |  * could equally well be done in user mode. | 
 | 246 |  * | 
 | 247 |  * Not so, for quite unobvious reasons - register pressure. | 
 | 248 |  * In user mode vfork() cannot have a stack frame, and if | 
 | 249 |  * done by calling the "clone()" system call directly, you | 
 | 250 |  * do not have enough call-clobbered registers to hold all | 
 | 251 |  * the information you need. | 
 | 252 |  */ | 
| Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 253 | SYSCALL_DEFINE0(vfork) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 255 | 	struct pt_regs *regs = task_pt_regs(current); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | 	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 257 | 		       regs->gprs[15], regs, 0, NULL, NULL); | 
 | 258 | } | 
 | 259 |  | 
 | 260 | asmlinkage void execve_tail(void) | 
 | 261 | { | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 262 | 	current->thread.fp_regs.fpc = 0; | 
 | 263 | 	if (MACHINE_HAS_IEEE) | 
 | 264 | 		asm volatile("sfpc %0,%0" : : "d" (0)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } | 
 | 266 |  | 
 | 267 | /* | 
 | 268 |  * sys_execve() executes a new program. | 
 | 269 |  */ | 
| David Howells | d762746 | 2010-08-17 23:52:56 +0100 | [diff] [blame] | 270 | SYSCALL_DEFINE3(execve, const char __user *, name, | 
 | 271 | 		const char __user *const __user *, argv, | 
 | 272 | 		const char __user *const __user *, envp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 274 | 	struct pt_regs *regs = task_pt_regs(current); | 
 | 275 | 	char *filename; | 
| Heiko Carstens | 3e86a8c | 2009-09-22 22:58:42 +0200 | [diff] [blame] | 276 | 	long rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 |  | 
| Heiko Carstens | 3e86a8c | 2009-09-22 22:58:42 +0200 | [diff] [blame] | 278 | 	filename = getname(name); | 
 | 279 | 	rc = PTR_ERR(filename); | 
 | 280 | 	if (IS_ERR(filename)) | 
 | 281 | 		return rc; | 
 | 282 | 	rc = do_execve(filename, argv, envp, regs); | 
 | 283 | 	if (rc) | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 284 | 		goto out; | 
| Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 285 | 	execve_tail(); | 
| Heiko Carstens | 3e86a8c | 2009-09-22 22:58:42 +0200 | [diff] [blame] | 286 | 	rc = regs->gprs[2]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | out: | 
| Heiko Carstens | 3e86a8c | 2009-09-22 22:58:42 +0200 | [diff] [blame] | 288 | 	putname(filename); | 
 | 289 | 	return rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } | 
 | 291 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /* | 
 | 293 |  * fill in the FPU structure for a core dump. | 
 | 294 |  */ | 
 | 295 | int dump_fpu (struct pt_regs * regs, s390_fp_regs *fpregs) | 
 | 296 | { | 
| Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 297 | #ifndef CONFIG_64BIT | 
| Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 298 | 	/* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | 	 * save fprs to current->thread.fp_regs to merge them with | 
 | 300 | 	 * the emulated registers and then copy the result to the dump. | 
 | 301 | 	 */ | 
 | 302 | 	save_fp_regs(¤t->thread.fp_regs); | 
 | 303 | 	memcpy(fpregs, ¤t->thread.fp_regs, sizeof(s390_fp_regs)); | 
| Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 304 | #else /* CONFIG_64BIT */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | 	save_fp_regs(fpregs); | 
| Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 306 | #endif /* CONFIG_64BIT */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 	return 1; | 
 | 308 | } | 
| Heiko Carstens | 1485c5c | 2009-03-26 15:24:04 +0100 | [diff] [blame] | 309 | EXPORT_SYMBOL(dump_fpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | unsigned long get_wchan(struct task_struct *p) | 
 | 312 | { | 
 | 313 | 	struct stack_frame *sf, *low, *high; | 
 | 314 | 	unsigned long return_address; | 
 | 315 | 	int count; | 
 | 316 |  | 
| Al Viro | 30af712 | 2006-01-12 01:05:50 -0800 | [diff] [blame] | 317 | 	if (!p || p == current || p->state == TASK_RUNNING || !task_stack_page(p)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | 		return 0; | 
| Al Viro | 30af712 | 2006-01-12 01:05:50 -0800 | [diff] [blame] | 319 | 	low = task_stack_page(p); | 
 | 320 | 	high = (struct stack_frame *) task_pt_regs(p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | 	sf = (struct stack_frame *) (p->thread.ksp & PSW_ADDR_INSN); | 
 | 322 | 	if (sf <= low || sf > high) | 
 | 323 | 		return 0; | 
 | 324 | 	for (count = 0; count < 16; count++) { | 
 | 325 | 		sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN); | 
 | 326 | 		if (sf <= low || sf > high) | 
 | 327 | 			return 0; | 
 | 328 | 		return_address = sf->gprs[8] & PSW_ADDR_INSN; | 
 | 329 | 		if (!in_sched_functions(return_address)) | 
 | 330 | 			return return_address; | 
 | 331 | 	} | 
 | 332 | 	return 0; | 
 | 333 | } |