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";
10 /* #define DEBUG_LDT /* */
11 /* #undef DEBUG_LDT /* */
15 #include <linux/unistd.h>
16 #include <linux/head.h>
17 #include <linux/ldt.h>
19 _syscall3(int, modify_ldt
, int, func
, void *, ptr
, unsigned long, bytecount
)
21 #if defined(__NetBSD__) || defined(__FreeBSD__)
22 #include <machine/segments.h>
24 extern int i386_get_ldt(int, union descriptor
*, int);
25 extern int i386_set_ldt(int, union descriptor
*, int);
27 struct segment_descriptor
*
28 make_sd(unsigned base
, unsigned limit
, int contents
, int read_exec_only
, int seg32
, int inpgs
)
32 d
[0] = ((base
& 0x0000ffff) << 16) |
34 d
[1] = (base
& 0xff000000) |
35 ((base
& 0x00ff0000)>>16) |
38 ((read_exec_only
^ 1) << 9) |
43 return ((struct segment_descriptor
*)d
);
51 return modify_ldt(0, buffer
, 32 * sizeof(struct modify_ldt_ldt_s
));
53 #if defined(__NetBSD__) || defined(__FreeBSD__)
54 return i386_get_ldt(0, (union descriptor
*)buffer
, 32);
59 set_ldt_entry(int entry
, unsigned long base
, unsigned int limit
,
60 int seg_32bit_flag
, int contents
, int read_only_flag
,
61 int limit_in_pages_flag
)
64 struct modify_ldt_ldt_s ldt_info
;
66 ldt_info
.entry_number
= entry
;
67 ldt_info
.base_addr
= base
;
68 ldt_info
.limit
= limit
;
69 ldt_info
.seg_32bit
= seg_32bit_flag
;
70 ldt_info
.contents
= contents
;
71 ldt_info
.read_exec_only
= read_only_flag
;
72 ldt_info
.limit_in_pages
= limit_in_pages_flag
;
74 ldt_info
.seg_not_present
= 0;
77 return modify_ldt(1, &ldt_info
, sizeof(ldt_info
));
79 #if defined(__NetBSD__) || defined(__FreeBSD__)
80 struct segment_descriptor
*sd
;
84 "set_ldt_entry: entry=%x base=%x limit=%x%s %s-bit contents=%d %s\n",
85 entry
, base
, limit
, limit_in_pages_flag
?"-pages":"",
86 seg_32bit_flag
?"32":"16",
87 contents
, read_only_flag
?"read-only":"");
89 sd
= make_sd(base
, limit
, contents
, read_only_flag
, seg_32bit_flag
, limit_in_pages_flag
);
90 ret
= i386_set_ldt(entry
, (union descriptor
*)sd
, 1);
92 perror("i386_set_ldt");
94 "Did you reconfigure the kernel with \"options USER_LDT\"?\n");
102 #endif /* ifndef WINELIB */