blob: dc755b0b9db8e6a6728ac82d1c1fc943909b9659 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#include "linux/config.h"
7#include "linux/slab.h"
8#include "asm/uaccess.h"
9#include "asm/ptrace.h"
10#include "choose-mode.h"
11#include "kern.h"
12
13#ifdef CONFIG_MODE_TT
14extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
15
16/* XXX this needs copy_to_user and copy_from_user */
17
18int sys_modify_ldt_tt(int func, void __user *ptr, unsigned long bytecount)
19{
20 if (!access_ok(VERIFY_READ, ptr, bytecount))
21 return -EFAULT;
22
23 return modify_ldt(func, ptr, bytecount);
24}
25#endif
26
27#ifdef CONFIG_MODE_SKAS
Jeff Dikeea66e8a2005-05-05 16:15:30 -070028extern int userspace_pid[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include "skas_ptrace.h"
31
32int sys_modify_ldt_skas(int func, void __user *ptr, unsigned long bytecount)
33{
34 struct ptrace_ldt ldt;
35 void *buf;
36 int res, n;
37
38 buf = kmalloc(bytecount, GFP_KERNEL);
39 if(buf == NULL)
40 return(-ENOMEM);
41
42 res = 0;
43
44 switch(func){
45 case 1:
46 case 0x11:
47 res = copy_from_user(buf, ptr, bytecount);
48 break;
49 }
50
51 if(res != 0){
52 res = -EFAULT;
53 goto out;
54 }
55
56 ldt = ((struct ptrace_ldt) { .func = func,
57 .ptr = buf,
58 .bytecount = bytecount });
Jeff Dikeea66e8a2005-05-05 16:15:30 -070059#warning Need to look up userspace_pid by cpu
60 res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if(res < 0)
62 goto out;
63
64 switch(func){
65 case 0:
66 case 2:
67 n = res;
68 res = copy_to_user(ptr, buf, n);
69 if(res != 0)
70 res = -EFAULT;
71 else
72 res = n;
73 break;
74 }
75
76 out:
77 kfree(buf);
78 return(res);
79}
80#endif
81
82int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
83{
84 return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
85 ptr, bytecount));
86}
87
88
89
90/*
91 * Overrides for Emacs so that we follow Linus's tabbing style.
92 * Emacs will notice this stuff at the end of the file and automatically
93 * adjust the settings for this buffer only. This must remain at the end
94 * of the file.
95 * ---------------------------------------------------------------------------
96 * Local variables:
97 * c-file-style: "linux"
98 * End:
99 */