comparison libdha/kernelhelper/dhahelper.c @ 4479:423ce4451ca8

tested and fixed on 2.2.x, more comments
author alex
date Sat, 02 Feb 2002 17:35:53 +0000
parents 2d28c737ed13
children 0165fc26bd12
comparison
equal deleted inserted replaced
4478:38d3954edb48 4479:423ce4451ca8
2 Direct Hardware Access kernel helper 2 Direct Hardware Access kernel helper
3 3
4 (C) 2002 Alex Beregszaszi <alex@naxine.org> 4 (C) 2002 Alex Beregszaszi <alex@naxine.org>
5 5
6 Accessing hardware from userspace as USER (no root needed!) 6 Accessing hardware from userspace as USER (no root needed!)
7 7
8 WARNING! 8 Tested on 2.2.x (2.2.19) and 2.4.x (2.4.3,2.4.17).
9 Don't use this on a production system! Use only at home, on a 9
10 "single-user" Unix system. 10 License: GPL
11
12 WARNING! THIS MODULE VIOLATES SEVERAL SECURITY LINES! DON'T USE IT
13 ON PRODUCTION SYSTEMS, ONLY AT HOME, ON A "SINGLE-USER" SYSTEM.
14 NO WARRANTY!
11 15
12 Tech: 16 Tech:
13 Communication between userspace and kernelspace is going trought 17 Communication between userspace and kernelspace goes over character
14 character device using ioctl. 18 device using ioctl.
15 19
16 Usage: 20 Usage:
17 mknod -m 666 /dev/dhahelper c 180 0 21 mknod -m 666 /dev/dhahelper c 180 0
18 22
19 Also you can change the major number, setting the "dhahelper_major" 23 Also you can change the major number, setting the "dhahelper_major"
20 module parameter, the default is 180, specified in dhahelper.h. 24 module parameter, the default is 180, specified in dhahelper.h.
21 25
22 Note: do not use other than minor==0, the module forbids it. 26 Note: do not use other than minor==0, the module forbids it.
23 27
24 TODO: 28 TODO:
25 * do memory mappin without fops:mmap 29 * do memory mapping without fops:mmap
26 * implement unmap memory 30 * implement unmap memory
27 * select (request?) a "valid" major number 31 * select (request?) a "valid" major number (from Linux project? ;)
28 * make security 32 * make security
29 * is pci handling needed? (libdha does this with lowlevel port funcs) 33 * is pci handling needed? (libdha does this with lowlevel port funcs)
30 * test on older kernels (2.0.x (?) and 2.2.x) 34 * is mttr handling needed?
35 * test on older kernels (2.0.x (?))
31 */ 36 */
32 37
33 #ifndef MODULE 38 #ifndef MODULE
34 #define MODULE 39 #define MODULE
35 #endif 40 #endif
37 #ifndef __KERNEL__ 42 #ifndef __KERNEL__
38 #define __KERNEL__ 43 #define __KERNEL__
39 #endif 44 #endif
40 45
41 #include <linux/config.h> 46 #include <linux/config.h>
47
48 #ifdef CONFIG_MODVERSION
49 #define MODVERSION
50 #include <linux/modversions.h>
51 #endif
52
42 #include <linux/version.h> 53 #include <linux/version.h>
43 #include <linux/module.h> 54 #include <linux/module.h>
44 #include <linux/types.h> 55 #include <linux/types.h>
45 #include <linux/kernel.h> 56 #include <linux/kernel.h>
46 #include <linux/sched.h> 57 #include <linux/sched.h>
68 #include <linux/unistd.h> 79 #include <linux/unistd.h>
69 80
70 #include "dhahelper.h" 81 #include "dhahelper.h"
71 82
72 MODULE_AUTHOR("Alex Beregszaszi <alex@naxine.org>"); 83 MODULE_AUTHOR("Alex Beregszaszi <alex@naxine.org>");
84 MODULE_DESCRIPTION("Provides userspace access to hardware (security violation!)");
73 #ifdef MODULE_LICENSE 85 #ifdef MODULE_LICENSE
74 MODULE_LICENSE("GPL"); /* modulelicensesh*t */ 86 MODULE_LICENSE("GPL");
75 #endif 87 #endif
76 88
77 static int dhahelper_major = DEFAULT_MAJOR; 89 static int dhahelper_major = DEFAULT_MAJOR;
78 MODULE_PARM(dhahelper_major, "i"); 90 MODULE_PARM(dhahelper_major, "i");
91 MODULE_PARM_DESC(dhahelper_major, "Major number of dhahelper characterdevice");
79 92
80 /* 0 = silent */ 93 /* 0 = silent */
81 /* 1 = report errors (default) */ 94 /* 1 = report errors (default) */
82 /* 2 = debug */ 95 /* 2 = debug */
83 static int dhahelper_verbosity = 1; 96 static int dhahelper_verbosity = 1;
84 MODULE_PARM(dhahelper_verbosity, "i"); 97 MODULE_PARM(dhahelper_verbosity, "i");
98 MODULE_PARM_DESC(dhahelper_verbosity, "Level of verbosity (0 = silent, 1 = only errors, 2 = debug)");
85 99
86 static dhahelper_memory_t last_mem_request; 100 static dhahelper_memory_t last_mem_request;
87 101
88 102
89 static int dhahelper_open(struct inode *inode, struct file *file) 103 static int dhahelper_open(struct inode *inode, struct file *file)
223 237
224 switch(mem.operation) 238 switch(mem.operation)
225 { 239 {
226 case MEMORY_OP_MAP: 240 case MEMORY_OP_MAP:
227 { 241 {
242 #if 1
228 memcpy(&last_mem_request, &mem, sizeof(dhahelper_memory_t)); 243 memcpy(&last_mem_request, &mem, sizeof(dhahelper_memory_t));
244 #else
245 mem.ret = do_mmap(file, mem.start, mem.size, PROT_READ|PROT_WRITE,
246 MAP_SHARED, mem.offset);
247 #endif
229 248
230 break; 249 break;
231 } 250 }
232 case MEMORY_OP_UNMAP: 251 case MEMORY_OP_UNMAP:
233 break; 252 break;
304 open: dhahelper_open, 323 open: dhahelper_open,
305 release: dhahelper_release 324 release: dhahelper_release
306 }; 325 };
307 #endif 326 #endif
308 327
328 #if KERNEL_VERSION < KERNEL_VERSION(2,4,0)
329 int init_module(void)
330 #else
309 static int __init init_dhahelper(void) 331 static int __init init_dhahelper(void)
332 #endif
310 { 333 {
311 printk(KERN_INFO "Direct Hardware Access kernel helper (C) Alex Beregszaszi\n"); 334 printk(KERN_INFO "Direct Hardware Access kernel helper (C) Alex Beregszaszi\n");
312 335
313 if(register_chrdev(dhahelper_major, "dhahelper", &dhahelper_fops)) 336 if(register_chrdev(dhahelper_major, "dhahelper", &dhahelper_fops))
314 { 337 {
319 } 342 }
320 343
321 return(0); 344 return(0);
322 } 345 }
323 346
347 #if KERNEL_VERSION < KERNEL_VERSION(2,4,0)
348 void cleanup_module(void)
349 #else
324 static void __exit exit_dhahelper(void) 350 static void __exit exit_dhahelper(void)
351 #endif
325 { 352 {
326 unregister_chrdev(dhahelper_major, "dhahelper"); 353 unregister_chrdev(dhahelper_major, "dhahelper");
327 } 354 }
328 355
329 EXPORT_NO_SYMBOLS; 356 EXPORT_NO_SYMBOLS;
330 357
358 #if KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
331 module_init(init_dhahelper); 359 module_init(init_dhahelper);
332 module_exit(exit_dhahelper); 360 module_exit(exit_dhahelper);
361 #endif