2 static char RCSId
[] = "$Id: ldtlib.c,v 1.2 1993/07/04 04:04:21 root Exp root $";
3 static char Copyright
[] = "Copyright Robert J. Amstadt, 1993";
11 #include <linux/unistd.h>
12 #include <linux/head.h>
13 #include <linux/ldt.h>
15 _syscall3(int, modify_ldt
, int, func
, void *, ptr
, unsigned long, bytecount
)
17 #if defined(__NetBSD__) || defined(__FreeBSD__)
18 #include <machine/segments.h>
20 extern int i386_get_ldt(int, union descriptor
*, int);
21 extern int i386_set_ldt(int, union descriptor
*, int);
23 struct segment_descriptor
*
24 make_sd(unsigned base
, unsigned limit
, int contents
, int read_exec_only
, int seg32
, int inpgs
)
28 d
[0] = ((base
& 0x0000ffff) << 16) |
30 d
[1] = (base
& 0xff000000) |
31 ((base
& 0x00ff0000)>>16) |
34 ((read_exec_only
^ 1) << 9) |
39 return ((struct segment_descriptor
*)d
);
47 return modify_ldt(0, buffer
, 32 * sizeof(struct modify_ldt_ldt_s
));
49 #if defined(__NetBSD__) || defined(__FreeBSD__)
50 return i386_get_ldt(0, (union descriptor
*)buffer
, 32);
55 set_ldt_entry(int entry
, unsigned long base
, unsigned int limit
,
56 int seg_32bit_flag
, int contents
, int read_only_flag
,
57 int limit_in_pages_flag
)
60 struct modify_ldt_ldt_s ldt_info
;
62 ldt_info
.entry_number
= entry
;
63 ldt_info
.base_addr
= base
;
64 ldt_info
.limit
= limit
;
65 ldt_info
.seg_32bit
= seg_32bit_flag
;
66 ldt_info
.contents
= contents
;
67 ldt_info
.read_exec_only
= read_only_flag
;
68 ldt_info
.limit_in_pages
= limit_in_pages_flag
;
70 ldt_info
.seg_not_present
= 0;
73 return modify_ldt(1, &ldt_info
, sizeof(ldt_info
));
75 #if defined(__NetBSD__) || defined(__FreeBSD__)
76 struct segment_descriptor
*sd
;
80 printf("set_ldt_entry: entry=%x base=%x limit=%x%s %s-bit contents=%d %s\n",
81 entry
, base
, limit
, limit_in_pages_flag
?"-pages":"",
82 seg_32bit_flag
?"32":"16",
83 contents
, read_only_flag
?"read-only":"");
86 sd
= make_sd(base
, limit
, contents
, read_only_flag
, seg_32bit_flag
, limit_in_pages_flag
);
87 ret
= i386_set_ldt(entry
, (union descriptor
*)sd
, 1);
89 perror("i386_set_ldt");
91 "Did you reconfigure the kernel with \"options USER_LDT\"?\n");
99 #endif /* ifndef WINELIB */