ia64/xen-unstable

changeset 5942:f7abc6205e22

PDB: roll out changes to ptrace.c and traps.c
author ach61@arcadians.cl.cam.ac.uk
date Sun Jul 31 21:45:52 2005 +0000 (2005-07-31)
parents 55a5ad2f028d
children 90f2b122fc43
files linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Fri Jul 29 11:21:39 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Sun Jul 31 21:45:52 2005 +0000
     1.3 @@ -90,9 +90,7 @@ asmlinkage void machine_check(void);
     1.4  
     1.5  static int kstack_depth_to_print = 24;
     1.6  struct notifier_block *i386die_chain;
     1.7 -DEFINE_SPINLOCK(die_notifier_lock);
     1.8 -EXPORT_SYMBOL(die_notifier_lock);
     1.9 -EXPORT_SYMBOL(i386die_chain);
    1.10 +static DEFINE_SPINLOCK(die_notifier_lock);
    1.11  
    1.12  int register_die_notifier(struct notifier_block *nb)
    1.13  {
     2.1 --- a/linux-2.6-xen-sparse/kernel/ptrace.c	Fri Jul 29 11:21:39 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,391 +0,0 @@
     2.4 -/*
     2.5 - * linux/kernel/ptrace.c
     2.6 - *
     2.7 - * (C) Copyright 1999 Linus Torvalds
     2.8 - *
     2.9 - * Common interfaces for "ptrace()" which we do not want
    2.10 - * to continually duplicate across every architecture.
    2.11 - */
    2.12 -
    2.13 -#include <linux/module.h>
    2.14 -#include <linux/sched.h>
    2.15 -#include <linux/errno.h>
    2.16 -#include <linux/mm.h>
    2.17 -#include <linux/highmem.h>
    2.18 -#include <linux/pagemap.h>
    2.19 -#include <linux/smp_lock.h>
    2.20 -#include <linux/ptrace.h>
    2.21 -#include <linux/security.h>
    2.22 -#include <linux/signal.h>
    2.23 -
    2.24 -#include <asm/pgtable.h>
    2.25 -#include <asm/uaccess.h>
    2.26 -
    2.27 -/*
    2.28 - * ptrace a task: make the debugger its new parent and
    2.29 - * move it to the ptrace list.
    2.30 - *
    2.31 - * Must be called with the tasklist lock write-held.
    2.32 - */
    2.33 -void __ptrace_link(task_t *child, task_t *new_parent)
    2.34 -{
    2.35 -	if (!list_empty(&child->ptrace_list))
    2.36 -		BUG();
    2.37 -	if (child->parent == new_parent)
    2.38 -		return;
    2.39 -	list_add(&child->ptrace_list, &child->parent->ptrace_children);
    2.40 -	REMOVE_LINKS(child);
    2.41 -	child->parent = new_parent;
    2.42 -	SET_LINKS(child);
    2.43 -}
    2.44 - 
    2.45 -/*
    2.46 - * Turn a tracing stop into a normal stop now, since with no tracer there
    2.47 - * would be no way to wake it up with SIGCONT or SIGKILL.  If there was a
    2.48 - * signal sent that would resume the child, but didn't because it was in
    2.49 - * TASK_TRACED, resume it now.
    2.50 - * Requires that irqs be disabled.
    2.51 - */
    2.52 -void ptrace_untrace(task_t *child)
    2.53 -{
    2.54 -	spin_lock(&child->sighand->siglock);
    2.55 -	if (child->state == TASK_TRACED) {
    2.56 -		if (child->signal->flags & SIGNAL_STOP_STOPPED) {
    2.57 -			child->state = TASK_STOPPED;
    2.58 -		} else {
    2.59 -			signal_wake_up(child, 1);
    2.60 -		}
    2.61 -	}
    2.62 -	spin_unlock(&child->sighand->siglock);
    2.63 -}
    2.64 -
    2.65 -/*
    2.66 - * unptrace a task: move it back to its original parent and
    2.67 - * remove it from the ptrace list.
    2.68 - *
    2.69 - * Must be called with the tasklist lock write-held.
    2.70 - */
    2.71 -void __ptrace_unlink(task_t *child)
    2.72 -{
    2.73 -	if (!child->ptrace)
    2.74 -		BUG();
    2.75 -	child->ptrace = 0;
    2.76 -	if (!list_empty(&child->ptrace_list)) {
    2.77 -		list_del_init(&child->ptrace_list);
    2.78 -		REMOVE_LINKS(child);
    2.79 -		child->parent = child->real_parent;
    2.80 -		SET_LINKS(child);
    2.81 -	}
    2.82 -
    2.83 -	if (child->state == TASK_TRACED)
    2.84 -		ptrace_untrace(child);
    2.85 -}
    2.86 -
    2.87 -/*
    2.88 - * Check that we have indeed attached to the thing..
    2.89 - */
    2.90 -int ptrace_check_attach(struct task_struct *child, int kill)
    2.91 -{
    2.92 -	int ret = -ESRCH;
    2.93 -
    2.94 -	/*
    2.95 -	 * We take the read lock around doing both checks to close a
    2.96 -	 * possible race where someone else was tracing our child and
    2.97 -	 * detached between these two checks.  After this locked check,
    2.98 -	 * we are sure that this is our traced child and that can only
    2.99 -	 * be changed by us so it's not changing right after this.
   2.100 -	 */
   2.101 -	read_lock(&tasklist_lock);
   2.102 -	if ((child->ptrace & PT_PTRACED) && child->parent == current &&
   2.103 -	    (!(child->ptrace & PT_ATTACHED) || child->real_parent != current)
   2.104 -	    && child->signal != NULL) {
   2.105 -		ret = 0;
   2.106 -		spin_lock_irq(&child->sighand->siglock);
   2.107 -		if (child->state == TASK_STOPPED) {
   2.108 -			child->state = TASK_TRACED;
   2.109 -		} else if (child->state != TASK_TRACED && !kill) {
   2.110 -			ret = -ESRCH;
   2.111 -		}
   2.112 -		spin_unlock_irq(&child->sighand->siglock);
   2.113 -	}
   2.114 -	read_unlock(&tasklist_lock);
   2.115 -
   2.116 -	if (!ret && !kill) {
   2.117 -		wait_task_inactive(child);
   2.118 -	}
   2.119 -
   2.120 -	/* All systems go.. */
   2.121 -	return ret;
   2.122 -}
   2.123 -
   2.124 -int ptrace_attach(struct task_struct *task)
   2.125 -{
   2.126 -	int retval;
   2.127 -	task_lock(task);
   2.128 -	retval = -EPERM;
   2.129 -	if (task->pid <= 1)
   2.130 -		goto bad;
   2.131 -	if (task == current)
   2.132 -		goto bad;
   2.133 -	if (!task->mm)
   2.134 -		goto bad;
   2.135 -	if(((current->uid != task->euid) ||
   2.136 -	    (current->uid != task->suid) ||
   2.137 -	    (current->uid != task->uid) ||
   2.138 - 	    (current->gid != task->egid) ||
   2.139 - 	    (current->gid != task->sgid) ||
   2.140 - 	    (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
   2.141 -		goto bad;
   2.142 -	smp_rmb();
   2.143 -	if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE))
   2.144 -		goto bad;
   2.145 -	/* the same process cannot be attached many times */
   2.146 -	if (task->ptrace & PT_PTRACED)
   2.147 -		goto bad;
   2.148 -	retval = security_ptrace(current, task);
   2.149 -	if (retval)
   2.150 -		goto bad;
   2.151 -
   2.152 -	/* Go */
   2.153 -	task->ptrace |= PT_PTRACED | ((task->real_parent != current)
   2.154 -				      ? PT_ATTACHED : 0);
   2.155 -	if (capable(CAP_SYS_PTRACE))
   2.156 -		task->ptrace |= PT_PTRACE_CAP;
   2.157 -	task_unlock(task);
   2.158 -
   2.159 -	write_lock_irq(&tasklist_lock);
   2.160 -	__ptrace_link(task, current);
   2.161 -	write_unlock_irq(&tasklist_lock);
   2.162 -
   2.163 -	force_sig_specific(SIGSTOP, task);
   2.164 -	return 0;
   2.165 -
   2.166 -bad:
   2.167 -	task_unlock(task);
   2.168 -	return retval;
   2.169 -}
   2.170 -
   2.171 -int ptrace_detach(struct task_struct *child, unsigned int data)
   2.172 -{
   2.173 -	if (!valid_signal(data))
   2.174 -		return	-EIO;
   2.175 -
   2.176 -	/* Architecture-specific hardware disable .. */
   2.177 -	ptrace_disable(child);
   2.178 -
   2.179 -	/* .. re-parent .. */
   2.180 -	child->exit_code = data;
   2.181 -
   2.182 -	write_lock_irq(&tasklist_lock);
   2.183 -	__ptrace_unlink(child);
   2.184 -	/* .. and wake it up. */
   2.185 -	if (child->exit_state != EXIT_ZOMBIE)
   2.186 -		wake_up_process(child);
   2.187 -	write_unlock_irq(&tasklist_lock);
   2.188 -
   2.189 -	return 0;
   2.190 -}
   2.191 -
   2.192 -/*
   2.193 - * Access another process' address space.
   2.194 - * Source/target buffer must be kernel space, 
   2.195 - * Do not walk the page table directly, use get_user_pages
   2.196 - */
   2.197 -
   2.198 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
   2.199 -{
   2.200 -	struct mm_struct *mm;
   2.201 -	struct vm_area_struct *vma;
   2.202 -	struct page *page;
   2.203 -	void *old_buf = buf;
   2.204 -
   2.205 -	mm = get_task_mm(tsk);
   2.206 -	if (!mm)
   2.207 -		return 0;
   2.208 -
   2.209 -	down_read(&mm->mmap_sem);
   2.210 -	/* ignore errors, just check how much was sucessfully transfered */
   2.211 -	while (len) {
   2.212 -		int bytes, ret, offset;
   2.213 -		void *maddr;
   2.214 -
   2.215 -		ret = get_user_pages(tsk, mm, addr, 1,
   2.216 -				write, 1, &page, &vma);
   2.217 -		if (ret <= 0)
   2.218 -			break;
   2.219 -
   2.220 -		bytes = len;
   2.221 -		offset = addr & (PAGE_SIZE-1);
   2.222 -		if (bytes > PAGE_SIZE-offset)
   2.223 -			bytes = PAGE_SIZE-offset;
   2.224 -
   2.225 -		maddr = kmap(page);
   2.226 -		if (write) {
   2.227 -			copy_to_user_page(vma, page, addr,
   2.228 -					  maddr + offset, buf, bytes);
   2.229 -			set_page_dirty_lock(page);
   2.230 -		} else {
   2.231 -			copy_from_user_page(vma, page, addr,
   2.232 -					    buf, maddr + offset, bytes);
   2.233 -		}
   2.234 -		kunmap(page);
   2.235 -		page_cache_release(page);
   2.236 -		len -= bytes;
   2.237 -		buf += bytes;
   2.238 -		addr += bytes;
   2.239 -	}
   2.240 -	up_read(&mm->mmap_sem);
   2.241 -	mmput(mm);
   2.242 -	
   2.243 -	return buf - old_buf;
   2.244 -}
   2.245 -EXPORT_SYMBOL(access_process_vm);
   2.246 -
   2.247 -int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
   2.248 -{
   2.249 -	int copied = 0;
   2.250 -
   2.251 -	while (len > 0) {
   2.252 -		char buf[128];
   2.253 -		int this_len, retval;
   2.254 -
   2.255 -		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
   2.256 -		retval = access_process_vm(tsk, src, buf, this_len, 0);
   2.257 -		if (!retval) {
   2.258 -			if (copied)
   2.259 -				break;
   2.260 -			return -EIO;
   2.261 -		}
   2.262 -		if (copy_to_user(dst, buf, retval))
   2.263 -			return -EFAULT;
   2.264 -		copied += retval;
   2.265 -		src += retval;
   2.266 -		dst += retval;
   2.267 -		len -= retval;			
   2.268 -	}
   2.269 -	return copied;
   2.270 -}
   2.271 -
   2.272 -int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len)
   2.273 -{
   2.274 -	int copied = 0;
   2.275 -
   2.276 -	while (len > 0) {
   2.277 -		char buf[128];
   2.278 -		int this_len, retval;
   2.279 -
   2.280 -		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
   2.281 -		if (copy_from_user(buf, src, this_len))
   2.282 -			return -EFAULT;
   2.283 -		retval = access_process_vm(tsk, dst, buf, this_len, 1);
   2.284 -		if (!retval) {
   2.285 -			if (copied)
   2.286 -				break;
   2.287 -			return -EIO;
   2.288 -		}
   2.289 -		copied += retval;
   2.290 -		src += retval;
   2.291 -		dst += retval;
   2.292 -		len -= retval;			
   2.293 -	}
   2.294 -	return copied;
   2.295 -}
   2.296 -
   2.297 -static int ptrace_setoptions(struct task_struct *child, long data)
   2.298 -{
   2.299 -	child->ptrace &= ~PT_TRACE_MASK;
   2.300 -
   2.301 -	if (data & PTRACE_O_TRACESYSGOOD)
   2.302 -		child->ptrace |= PT_TRACESYSGOOD;
   2.303 -
   2.304 -	if (data & PTRACE_O_TRACEFORK)
   2.305 -		child->ptrace |= PT_TRACE_FORK;
   2.306 -
   2.307 -	if (data & PTRACE_O_TRACEVFORK)
   2.308 -		child->ptrace |= PT_TRACE_VFORK;
   2.309 -
   2.310 -	if (data & PTRACE_O_TRACECLONE)
   2.311 -		child->ptrace |= PT_TRACE_CLONE;
   2.312 -
   2.313 -	if (data & PTRACE_O_TRACEEXEC)
   2.314 -		child->ptrace |= PT_TRACE_EXEC;
   2.315 -
   2.316 -	if (data & PTRACE_O_TRACEVFORKDONE)
   2.317 -		child->ptrace |= PT_TRACE_VFORK_DONE;
   2.318 -
   2.319 -	if (data & PTRACE_O_TRACEEXIT)
   2.320 -		child->ptrace |= PT_TRACE_EXIT;
   2.321 -
   2.322 -	return (data & ~PTRACE_O_MASK) ? -EINVAL : 0;
   2.323 -}
   2.324 -
   2.325 -static int ptrace_getsiginfo(struct task_struct *child, siginfo_t __user * data)
   2.326 -{
   2.327 -	siginfo_t lastinfo;
   2.328 -	int error = -ESRCH;
   2.329 -
   2.330 -	read_lock(&tasklist_lock);
   2.331 -	if (likely(child->sighand != NULL)) {
   2.332 -		error = -EINVAL;
   2.333 -		spin_lock_irq(&child->sighand->siglock);
   2.334 -		if (likely(child->last_siginfo != NULL)) {
   2.335 -			lastinfo = *child->last_siginfo;
   2.336 -			error = 0;
   2.337 -		}
   2.338 -		spin_unlock_irq(&child->sighand->siglock);
   2.339 -	}
   2.340 -	read_unlock(&tasklist_lock);
   2.341 -	if (!error)
   2.342 -		return copy_siginfo_to_user(data, &lastinfo);
   2.343 -	return error;
   2.344 -}
   2.345 -
   2.346 -static int ptrace_setsiginfo(struct task_struct *child, siginfo_t __user * data)
   2.347 -{
   2.348 -	siginfo_t newinfo;
   2.349 -	int error = -ESRCH;
   2.350 -
   2.351 -	if (copy_from_user(&newinfo, data, sizeof (siginfo_t)))
   2.352 -		return -EFAULT;
   2.353 -
   2.354 -	read_lock(&tasklist_lock);
   2.355 -	if (likely(child->sighand != NULL)) {
   2.356 -		error = -EINVAL;
   2.357 -		spin_lock_irq(&child->sighand->siglock);
   2.358 -		if (likely(child->last_siginfo != NULL)) {
   2.359 -			*child->last_siginfo = newinfo;
   2.360 -			error = 0;
   2.361 -		}
   2.362 -		spin_unlock_irq(&child->sighand->siglock);
   2.363 -	}
   2.364 -	read_unlock(&tasklist_lock);
   2.365 -	return error;
   2.366 -}
   2.367 -
   2.368 -int ptrace_request(struct task_struct *child, long request,
   2.369 -		   long addr, long data)
   2.370 -{
   2.371 -	int ret = -EIO;
   2.372 -
   2.373 -	switch (request) {
   2.374 -#ifdef PTRACE_OLDSETOPTIONS
   2.375 -	case PTRACE_OLDSETOPTIONS:
   2.376 -#endif
   2.377 -	case PTRACE_SETOPTIONS:
   2.378 -		ret = ptrace_setoptions(child, data);
   2.379 -		break;
   2.380 -	case PTRACE_GETEVENTMSG:
   2.381 -		ret = put_user(child->ptrace_message, (unsigned long __user *) data);
   2.382 -		break;
   2.383 -	case PTRACE_GETSIGINFO:
   2.384 -		ret = ptrace_getsiginfo(child, (siginfo_t __user *) data);
   2.385 -		break;
   2.386 -	case PTRACE_SETSIGINFO:
   2.387 -		ret = ptrace_setsiginfo(child, (siginfo_t __user *) data);
   2.388 -		break;
   2.389 -	default:
   2.390 -		break;
   2.391 -	}
   2.392 -
   2.393 -	return ret;
   2.394 -}