note a leak that needs fixing eventually
[trinity.git] / syscalls / modify_ldt.c
blobb33e4de3d65c83c278a741bc5c3f788b02ebc177
1 #include "arch.h"
3 #ifdef X86
4 /*
5 * asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
6 */
7 #include <stdlib.h>
8 #include <sys/types.h>
9 #define __ASSEMBLY__ 1
10 #include <asm/ldt.h>
11 #include "sanitise.h"
12 #include "shm.h"
14 #define ALLOCSIZE LDT_ENTRIES * LDT_ENTRY_SIZE
16 static void sanitise_modify_ldt(int childno)
18 void *ldt;
19 //struct user_desc *desc;
21 shm->scratch[childno] = 0;
22 switch (shm->syscall[childno].a1) {
23 case 0:
24 /* read the ldt into the memory pointed to by ptr.
25 The number of bytes read is the smaller of bytecount and the actual size of the ldt. */
26 ldt = malloc(ALLOCSIZE);
27 shm->scratch[childno] = (unsigned long) ldt;
28 if (ldt == NULL)
29 return;
30 shm->syscall[childno].a3 = ALLOCSIZE;
31 break;
33 case 1:
34 /* modify one ldt entry.
35 * ptr points to a user_desc structure
36 * bytecount must equal the size of this structure. */
39 unsigned int entry_number;
40 unsigned long base_addr;
41 unsigned int limit;
42 unsigned int seg_32bit:1;
43 unsigned int contents:2;
44 unsigned int read_exec_only:1;
45 unsigned int limit_in_pages:1;
46 unsigned int seg_not_present:1;
47 unsigned int useable:1;
49 break;
50 default:
51 break;
55 static void post_modify_ldt(int childno)
57 void *ptr;
59 ptr = (void *) shm->scratch[childno];
61 if (ptr != NULL)
62 free(ptr);
64 shm->scratch[childno] = 0;
67 struct syscallentry syscall_modify_ldt = {
68 .name = "modify_ldt",
69 .num_args = 3,
70 .arg1name = "func",
71 .arg1type = ARG_OP,
72 .arg1list = {
73 .num = 2,
74 .values = { 0, 1 },
76 .arg2name = "ptr",
77 .arg3name = "bytecount",
78 .sanitise = sanitise_modify_ldt,
79 .post = post_modify_ldt,
81 #endif