xref: /openbmc/linux/arch/parisc/kernel/process.c (revision 4e950f6f0189f65f8bf069cf2272649ef418f5e4)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *    PARISC Architecture-dependent parts of process handling
31da177e4SLinus Torvalds  *    based on the work for i386
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *    Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
61da177e4SLinus Torvalds  *    Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
71da177e4SLinus Torvalds  *    Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
81da177e4SLinus Torvalds  *    Copyright (C) 2000 David Huggins-Daines <dhd with pobox.org>
91da177e4SLinus Torvalds  *    Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
101da177e4SLinus Torvalds  *    Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
111da177e4SLinus Torvalds  *    Copyright (C) 2000 David Kennedy <dkennedy with linuxcare.com>
12b2450cc1SCarlos O'Donell  *    Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>
131da177e4SLinus Torvalds  *    Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
141da177e4SLinus Torvalds  *    Copyright (C) 2001 Alan Modra <amodra at parisc-linux.org>
151da177e4SLinus Torvalds  *    Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
16a8f44e38SHelge Deller  *    Copyright (C) 2001-2007 Helge Deller <deller at parisc-linux.org>
171da177e4SLinus Torvalds  *    Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
181da177e4SLinus Torvalds  *
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  *    This program is free software; you can redistribute it and/or modify
211da177e4SLinus Torvalds  *    it under the terms of the GNU General Public License as published by
221da177e4SLinus Torvalds  *    the Free Software Foundation; either version 2 of the License, or
231da177e4SLinus Torvalds  *    (at your option) any later version.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  *    This program is distributed in the hope that it will be useful,
261da177e4SLinus Torvalds  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
271da177e4SLinus Torvalds  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
281da177e4SLinus Torvalds  *    GNU General Public License for more details.
291da177e4SLinus Torvalds  *
301da177e4SLinus Torvalds  *    You should have received a copy of the GNU General Public License
311da177e4SLinus Torvalds  *    along with this program; if not, write to the Free Software
321da177e4SLinus Torvalds  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
331da177e4SLinus Torvalds  */
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #include <stdarg.h>
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds #include <linux/elf.h>
381da177e4SLinus Torvalds #include <linux/errno.h>
391da177e4SLinus Torvalds #include <linux/kernel.h>
401da177e4SLinus Torvalds #include <linux/mm.h>
41*4e950f6fSAlexey Dobriyan #include <linux/fs.h>
421da177e4SLinus Torvalds #include <linux/module.h>
431da177e4SLinus Torvalds #include <linux/personality.h>
441da177e4SLinus Torvalds #include <linux/ptrace.h>
451da177e4SLinus Torvalds #include <linux/sched.h>
461da177e4SLinus Torvalds #include <linux/stddef.h>
471da177e4SLinus Torvalds #include <linux/unistd.h>
481da177e4SLinus Torvalds #include <linux/kallsyms.h>
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #include <asm/io.h>
510013a854SSam Ravnborg #include <asm/asm-offsets.h>
521da177e4SLinus Torvalds #include <asm/pdc.h>
531da177e4SLinus Torvalds #include <asm/pdc_chassis.h>
541da177e4SLinus Torvalds #include <asm/pgalloc.h>
551da177e4SLinus Torvalds #include <asm/uaccess.h>
561da177e4SLinus Torvalds #include <asm/unwind.h>
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds /*
591da177e4SLinus Torvalds  * The idle thread. There's no useful work to be
601da177e4SLinus Torvalds  * done, so just try to conserve power and have a
611da177e4SLinus Torvalds  * low exit latency (ie sit in a loop waiting for
621da177e4SLinus Torvalds  * somebody to say that they'd like to reschedule)
631da177e4SLinus Torvalds  */
641da177e4SLinus Torvalds void cpu_idle(void)
651da177e4SLinus Torvalds {
6664c7c8f8SNick Piggin 	set_thread_flag(TIF_POLLING_NRFLAG);
6764c7c8f8SNick Piggin 
681da177e4SLinus Torvalds 	/* endless idle loop with no priority at all */
691da177e4SLinus Torvalds 	while (1) {
701da177e4SLinus Torvalds 		while (!need_resched())
711da177e4SLinus Torvalds 			barrier();
725bfb5d69SNick Piggin 		preempt_enable_no_resched();
731da177e4SLinus Torvalds 		schedule();
745bfb5d69SNick Piggin 		preempt_disable();
751da177e4SLinus Torvalds 		check_pgt_cache();
761da177e4SLinus Torvalds 	}
771da177e4SLinus Torvalds }
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds 
8010992092SKyle McMartin #define COMMAND_GLOBAL  F_EXTEND(0xfffe0030)
811da177e4SLinus Torvalds #define CMD_RESET       5       /* reset any module */
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds /*
841da177e4SLinus Torvalds ** The Wright Brothers and Gecko systems have a H/W problem
851da177e4SLinus Torvalds ** (Lasi...'nuf said) may cause a broadcast reset to lockup
861da177e4SLinus Torvalds ** the system. An HVERSION dependent PDC call was developed
871da177e4SLinus Torvalds ** to perform a "safe", platform specific broadcast reset instead
881da177e4SLinus Torvalds ** of kludging up all the code.
891da177e4SLinus Torvalds **
901da177e4SLinus Torvalds ** Older machines which do not implement PDC_BROADCAST_RESET will
911da177e4SLinus Torvalds ** return (with an error) and the regular broadcast reset can be
921da177e4SLinus Torvalds ** issued. Obviously, if the PDC does implement PDC_BROADCAST_RESET
931da177e4SLinus Torvalds ** the PDC call will not return (the system will be reset).
941da177e4SLinus Torvalds */
951da177e4SLinus Torvalds void machine_restart(char *cmd)
961da177e4SLinus Torvalds {
971da177e4SLinus Torvalds #ifdef FASTBOOT_SELFTEST_SUPPORT
981da177e4SLinus Torvalds 	/*
991da177e4SLinus Torvalds 	 ** If user has modified the Firmware Selftest Bitmap,
1001da177e4SLinus Torvalds 	 ** run the tests specified in the bitmap after the
1011da177e4SLinus Torvalds 	 ** system is rebooted w/PDC_DO_RESET.
1021da177e4SLinus Torvalds 	 **
1031da177e4SLinus Torvalds 	 ** ftc_bitmap = 0x1AUL "Skip destructive memory tests"
1041da177e4SLinus Torvalds 	 **
1051da177e4SLinus Torvalds 	 ** Using "directed resets" at each processor with the MEM_TOC
1061da177e4SLinus Torvalds 	 ** vector cleared will also avoid running destructive
1071da177e4SLinus Torvalds 	 ** memory self tests. (Not implemented yet)
1081da177e4SLinus Torvalds 	 */
1091da177e4SLinus Torvalds 	if (ftc_bitmap) {
1101da177e4SLinus Torvalds 		pdc_do_firm_test_reset(ftc_bitmap);
1111da177e4SLinus Torvalds 	}
1121da177e4SLinus Torvalds #endif
1131da177e4SLinus Torvalds 	/* set up a new led state on systems shipped with a LED State panel */
1141da177e4SLinus Torvalds 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	/* "Normal" system reset */
1171da177e4SLinus Torvalds 	pdc_do_reset();
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds 	/* Nope...box should reset with just CMD_RESET now */
1201da177e4SLinus Torvalds 	gsc_writel(CMD_RESET, COMMAND_GLOBAL);
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds 	/* Wait for RESET to lay us to rest. */
1231da177e4SLinus Torvalds 	while (1) ;
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds }
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds void machine_halt(void)
1281da177e4SLinus Torvalds {
1291da177e4SLinus Torvalds 	/*
1301da177e4SLinus Torvalds 	** The LED/ChassisCodes are updated by the led_halt()
1311da177e4SLinus Torvalds 	** function, called by the reboot notifier chain.
1321da177e4SLinus Torvalds 	*/
1331da177e4SLinus Torvalds }
1341da177e4SLinus Torvalds 
13585509c00SKyle McMartin void (*chassis_power_off)(void);
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds /*
1381da177e4SLinus Torvalds  * This routine is called from sys_reboot to actually turn off the
1391da177e4SLinus Torvalds  * machine
1401da177e4SLinus Torvalds  */
1411da177e4SLinus Torvalds void machine_power_off(void)
1421da177e4SLinus Torvalds {
1431da177e4SLinus Torvalds 	/* If there is a registered power off handler, call it. */
14485509c00SKyle McMartin 	if (chassis_power_off)
14585509c00SKyle McMartin 		chassis_power_off();
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	/* Put the soft power button back under hardware control.
1481da177e4SLinus Torvalds 	 * If the user had already pressed the power button, the
1491da177e4SLinus Torvalds 	 * following call will immediately power off. */
1501da177e4SLinus Torvalds 	pdc_soft_power_button(0);
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds 	/* It seems we have no way to power the system off via
1551da177e4SLinus Torvalds 	 * software. The user has to press the button himself. */
1561da177e4SLinus Torvalds 
1571da177e4SLinus Torvalds 	printk(KERN_EMERG "System shut down completed.\n"
1581da177e4SLinus Torvalds 	       KERN_EMERG "Please power this system off now.");
1591da177e4SLinus Torvalds }
1601da177e4SLinus Torvalds 
16185509c00SKyle McMartin void (*pm_power_off)(void) = machine_power_off;
16285509c00SKyle McMartin EXPORT_SYMBOL(pm_power_off);
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds /*
1651da177e4SLinus Torvalds  * Create a kernel thread
1661da177e4SLinus Torvalds  */
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds extern pid_t __kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
1691da177e4SLinus Torvalds pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
1701da177e4SLinus Torvalds {
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds 	/*
1731da177e4SLinus Torvalds 	 * FIXME: Once we are sure we don't need any debug here,
1741da177e4SLinus Torvalds 	 *	  kernel_thread can become a #define.
1751da177e4SLinus Torvalds 	 */
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds 	return __kernel_thread(fn, arg, flags);
1781da177e4SLinus Torvalds }
1791da177e4SLinus Torvalds EXPORT_SYMBOL(kernel_thread);
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds /*
1821da177e4SLinus Torvalds  * Free current thread data structures etc..
1831da177e4SLinus Torvalds  */
1841da177e4SLinus Torvalds void exit_thread(void)
1851da177e4SLinus Torvalds {
1861da177e4SLinus Torvalds }
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds void flush_thread(void)
1891da177e4SLinus Torvalds {
1901da177e4SLinus Torvalds 	/* Only needs to handle fpu stuff or perf monitors.
1911da177e4SLinus Torvalds 	** REVISIT: several arches implement a "lazy fpu state".
1921da177e4SLinus Torvalds 	*/
1931da177e4SLinus Torvalds 	set_fs(USER_DS);
1941da177e4SLinus Torvalds }
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds void release_thread(struct task_struct *dead_task)
1971da177e4SLinus Torvalds {
1981da177e4SLinus Torvalds }
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /*
2011da177e4SLinus Torvalds  * Fill in the FPU structure for a core dump.
2021da177e4SLinus Torvalds  */
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds int dump_fpu (struct pt_regs * regs, elf_fpregset_t *r)
2051da177e4SLinus Torvalds {
2061da177e4SLinus Torvalds 	if (regs == NULL)
2071da177e4SLinus Torvalds 		return 0;
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds 	memcpy(r, regs->fr, sizeof *r);
2101da177e4SLinus Torvalds 	return 1;
2111da177e4SLinus Torvalds }
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds int dump_task_fpu (struct task_struct *tsk, elf_fpregset_t *r)
2141da177e4SLinus Torvalds {
2151da177e4SLinus Torvalds 	memcpy(r, tsk->thread.regs.fr, sizeof(*r));
2161da177e4SLinus Torvalds 	return 1;
2171da177e4SLinus Torvalds }
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds /* Note that "fork()" is implemented in terms of clone, with
2201da177e4SLinus Torvalds    parameters (SIGCHLD, regs->gr[30], regs). */
2211da177e4SLinus Torvalds int
2221da177e4SLinus Torvalds sys_clone(unsigned long clone_flags, unsigned long usp,
2231da177e4SLinus Torvalds 	  struct pt_regs *regs)
2241da177e4SLinus Torvalds {
225b2450cc1SCarlos O'Donell   	/* Arugments from userspace are:
226b2450cc1SCarlos O'Donell 	   r26 = Clone flags.
227b2450cc1SCarlos O'Donell 	   r25 = Child stack.
228b2450cc1SCarlos O'Donell 	   r24 = parent_tidptr.
229b2450cc1SCarlos O'Donell 	   r23 = Is the TLS storage descriptor
230b2450cc1SCarlos O'Donell 	   r22 = child_tidptr
231b2450cc1SCarlos O'Donell 
232b2450cc1SCarlos O'Donell 	   However, these last 3 args are only examined
233b2450cc1SCarlos O'Donell 	   if the proper flags are set. */
234b2450cc1SCarlos O'Donell 	int __user *child_tidptr;
235b2450cc1SCarlos O'Donell 	int __user *parent_tidptr;
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds 	/* usp must be word aligned.  This also prevents users from
2381da177e4SLinus Torvalds 	 * passing in the value 1 (which is the signal for a special
2391da177e4SLinus Torvalds 	 * return for a kernel thread) */
2401da177e4SLinus Torvalds 	usp = ALIGN(usp, 4);
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds 	/* A zero value for usp means use the current stack */
2431da177e4SLinus Torvalds 	if (usp == 0)
2441da177e4SLinus Torvalds 	  usp = regs->gr[30];
2451da177e4SLinus Torvalds 
246b2450cc1SCarlos O'Donell 	if (clone_flags & CLONE_PARENT_SETTID)
247b2450cc1SCarlos O'Donell 	  parent_tidptr = (int __user *)regs->gr[24];
248b2450cc1SCarlos O'Donell 	else
249b2450cc1SCarlos O'Donell 	  parent_tidptr = NULL;
250b2450cc1SCarlos O'Donell 
251b2450cc1SCarlos O'Donell 	if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID))
252b2450cc1SCarlos O'Donell 	  child_tidptr = (int __user *)regs->gr[22];
253b2450cc1SCarlos O'Donell 	else
254b2450cc1SCarlos O'Donell 	  child_tidptr = NULL;
255b2450cc1SCarlos O'Donell 
256b2450cc1SCarlos O'Donell 	return do_fork(clone_flags, usp, regs, 0, parent_tidptr, child_tidptr);
2571da177e4SLinus Torvalds }
2581da177e4SLinus Torvalds 
2591da177e4SLinus Torvalds int
2601da177e4SLinus Torvalds sys_vfork(struct pt_regs *regs)
2611da177e4SLinus Torvalds {
2621da177e4SLinus Torvalds 	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gr[30], regs, 0, NULL, NULL);
2631da177e4SLinus Torvalds }
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds int
2661da177e4SLinus Torvalds copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
2671da177e4SLinus Torvalds 	    unsigned long unused,	/* in ia64 this is "user_stack_size" */
2681da177e4SLinus Torvalds 	    struct task_struct * p, struct pt_regs * pregs)
2691da177e4SLinus Torvalds {
2701da177e4SLinus Torvalds 	struct pt_regs * cregs = &(p->thread.regs);
27140f1f0deSAl Viro 	void *stack = task_stack_page(p);
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds 	/* We have to use void * instead of a function pointer, because
2741da177e4SLinus Torvalds 	 * function pointers aren't a pointer to the function on 64-bit.
2751da177e4SLinus Torvalds 	 * Make them const so the compiler knows they live in .text */
2761da177e4SLinus Torvalds 	extern void * const ret_from_kernel_thread;
2771da177e4SLinus Torvalds 	extern void * const child_return;
2781da177e4SLinus Torvalds #ifdef CONFIG_HPUX
2791da177e4SLinus Torvalds 	extern void * const hpux_child_return;
2801da177e4SLinus Torvalds #endif
2811da177e4SLinus Torvalds 
2821da177e4SLinus Torvalds 	*cregs = *pregs;
2831da177e4SLinus Torvalds 
2841da177e4SLinus Torvalds 	/* Set the return value for the child.  Note that this is not
2851da177e4SLinus Torvalds            actually restored by the syscall exit path, but we put it
2861da177e4SLinus Torvalds            here for consistency in case of signals. */
2871da177e4SLinus Torvalds 	cregs->gr[28] = 0; /* child */
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds 	/*
2901da177e4SLinus Torvalds 	 * We need to differentiate between a user fork and a
2911da177e4SLinus Torvalds 	 * kernel fork. We can't use user_mode, because the
2921da177e4SLinus Torvalds 	 * the syscall path doesn't save iaoq. Right now
2931da177e4SLinus Torvalds 	 * We rely on the fact that kernel_thread passes
2941da177e4SLinus Torvalds 	 * in zero for usp.
2951da177e4SLinus Torvalds 	 */
2961da177e4SLinus Torvalds 	if (usp == 1) {
2971da177e4SLinus Torvalds 		/* kernel thread */
29840f1f0deSAl Viro 		cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN;
2991da177e4SLinus Torvalds 		/* Must exit via ret_from_kernel_thread in order
3001da177e4SLinus Torvalds 		 * to call schedule_tail()
3011da177e4SLinus Torvalds 		 */
3021da177e4SLinus Torvalds 		cregs->kpc = (unsigned long) &ret_from_kernel_thread;
3031da177e4SLinus Torvalds 		/*
3041da177e4SLinus Torvalds 		 * Copy function and argument to be called from
3051da177e4SLinus Torvalds 		 * ret_from_kernel_thread.
3061da177e4SLinus Torvalds 		 */
307a8f44e38SHelge Deller #ifdef CONFIG_64BIT
3081da177e4SLinus Torvalds 		cregs->gr[27] = pregs->gr[27];
3091da177e4SLinus Torvalds #endif
3101da177e4SLinus Torvalds 		cregs->gr[26] = pregs->gr[26];
3111da177e4SLinus Torvalds 		cregs->gr[25] = pregs->gr[25];
3121da177e4SLinus Torvalds 	} else {
3131da177e4SLinus Torvalds 		/* user thread */
3141da177e4SLinus Torvalds 		/*
3151da177e4SLinus Torvalds 		 * Note that the fork wrappers are responsible
3161da177e4SLinus Torvalds 		 * for setting gr[21].
3171da177e4SLinus Torvalds 		 */
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds 		/* Use same stack depth as parent */
32040f1f0deSAl Viro 		cregs->ksp = (unsigned long)stack
3211da177e4SLinus Torvalds 			+ (pregs->gr[21] & (THREAD_SIZE - 1));
3221da177e4SLinus Torvalds 		cregs->gr[30] = usp;
3231da177e4SLinus Torvalds 		if (p->personality == PER_HPUX) {
3241da177e4SLinus Torvalds #ifdef CONFIG_HPUX
3251da177e4SLinus Torvalds 			cregs->kpc = (unsigned long) &hpux_child_return;
3261da177e4SLinus Torvalds #else
3271da177e4SLinus Torvalds 			BUG();
3281da177e4SLinus Torvalds #endif
3291da177e4SLinus Torvalds 		} else {
3301da177e4SLinus Torvalds 			cregs->kpc = (unsigned long) &child_return;
3311da177e4SLinus Torvalds 		}
332b2450cc1SCarlos O'Donell 		/* Setup thread TLS area from the 4th parameter in clone */
333b2450cc1SCarlos O'Donell 		if (clone_flags & CLONE_SETTLS)
334b2450cc1SCarlos O'Donell 		  cregs->cr27 = pregs->gr[23];
335b2450cc1SCarlos O'Donell 
3361da177e4SLinus Torvalds 	}
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds 	return 0;
3391da177e4SLinus Torvalds }
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds unsigned long thread_saved_pc(struct task_struct *t)
3421da177e4SLinus Torvalds {
3431da177e4SLinus Torvalds 	return t->thread.regs.kpc;
3441da177e4SLinus Torvalds }
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds /*
3471da177e4SLinus Torvalds  * sys_execve() executes a new program.
3481da177e4SLinus Torvalds  */
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds asmlinkage int sys_execve(struct pt_regs *regs)
3511da177e4SLinus Torvalds {
3521da177e4SLinus Torvalds 	int error;
3531da177e4SLinus Torvalds 	char *filename;
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds 	filename = getname((const char __user *) regs->gr[26]);
3561da177e4SLinus Torvalds 	error = PTR_ERR(filename);
3571da177e4SLinus Torvalds 	if (IS_ERR(filename))
3581da177e4SLinus Torvalds 		goto out;
359c2c4798eSMatthew Wilcox 	error = do_execve(filename, (char __user * __user *) regs->gr[25],
360c2c4798eSMatthew Wilcox 		(char __user * __user *) regs->gr[24], regs);
3611da177e4SLinus Torvalds 	if (error == 0) {
3621da177e4SLinus Torvalds 		task_lock(current);
3631da177e4SLinus Torvalds 		current->ptrace &= ~PT_DTRACE;
3641da177e4SLinus Torvalds 		task_unlock(current);
3651da177e4SLinus Torvalds 	}
3661da177e4SLinus Torvalds 	putname(filename);
3671da177e4SLinus Torvalds out:
3681da177e4SLinus Torvalds 
3691da177e4SLinus Torvalds 	return error;
3701da177e4SLinus Torvalds }
3711da177e4SLinus Torvalds 
3723db03b4aSArnd Bergmann extern int __execve(const char *filename, char *const argv[],
3733db03b4aSArnd Bergmann 		char *const envp[], struct task_struct *task);
3743db03b4aSArnd Bergmann int kernel_execve(const char *filename, char *const argv[], char *const envp[])
3753db03b4aSArnd Bergmann {
3763db03b4aSArnd Bergmann 	return __execve(filename, argv, envp, current);
3773db03b4aSArnd Bergmann }
3783db03b4aSArnd Bergmann 
3791da177e4SLinus Torvalds unsigned long
3801da177e4SLinus Torvalds get_wchan(struct task_struct *p)
3811da177e4SLinus Torvalds {
3821da177e4SLinus Torvalds 	struct unwind_frame_info info;
3831da177e4SLinus Torvalds 	unsigned long ip;
3841da177e4SLinus Torvalds 	int count = 0;
385cc650a7aSKyle McMartin 
386cc650a7aSKyle McMartin 	if (!p || p == current || p->state == TASK_RUNNING)
387cc650a7aSKyle McMartin 		return 0;
388cc650a7aSKyle McMartin 
3891da177e4SLinus Torvalds 	/*
3901da177e4SLinus Torvalds 	 * These bracket the sleeping functions..
3911da177e4SLinus Torvalds 	 */
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds 	unwind_frame_init_from_blocked_task(&info, p);
3941da177e4SLinus Torvalds 	do {
3951da177e4SLinus Torvalds 		if (unwind_once(&info) < 0)
3961da177e4SLinus Torvalds 			return 0;
3971da177e4SLinus Torvalds 		ip = info.ip;
3981da177e4SLinus Torvalds 		if (!in_sched_functions(ip))
3991da177e4SLinus Torvalds 			return ip;
4001da177e4SLinus Torvalds 	} while (count++ < 16);
4011da177e4SLinus Torvalds 	return 0;
4021da177e4SLinus Torvalds }
403