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";
9 #include <linux/unistd.h>
10 #include <linux/head.h>
11 #include <linux/ldt.h>
13 _syscall3(int, modify_ldt
, int, func
, void *, ptr
, unsigned long, bytecount
)
15 #if defined(__NetBSD__) || defined(__FreeBSD__)
16 #include <machine/segments.h>
18 extern int i386_get_ldt(int, union descriptor
*, int);
19 extern int i386_set_ldt(int, union descriptor
*, int);
21 struct segment_descriptor
*
22 make_sd(unsigned base
, unsigned limit
, int contents
, int read_exec_only
, int seg32
, int inpgs
)
26 d
[0] = ((base
& 0x0000ffff) << 16) |
28 d
[1] = (base
& 0xff000000) |
29 ((base
& 0x00ff0000)>>16) |
32 ((read_exec_only
^ 1) << 9) |
37 return ((struct segment_descriptor
*)d
);
45 return modify_ldt(0, buffer
, 32 * sizeof(struct modify_ldt_ldt_s
));
47 #if defined(__NetBSD__) || defined(__FreeBSD__)
48 return i386_get_ldt(0, (union descriptor
*)buffer
, 32);
53 set_ldt_entry(int entry
, unsigned long base
, unsigned int limit
,
54 int seg_32bit_flag
, int contents
, int read_only_flag
,
55 int limit_in_pages_flag
)
58 struct modify_ldt_ldt_s ldt_info
;
60 ldt_info
.entry_number
= entry
;
61 ldt_info
.base_addr
= base
;
62 ldt_info
.limit
= limit
;
63 ldt_info
.seg_32bit
= seg_32bit_flag
;
64 ldt_info
.contents
= contents
;
65 ldt_info
.read_exec_only
= read_only_flag
;
66 ldt_info
.limit_in_pages
= limit_in_pages_flag
;
68 ldt_info
.seg_not_present
= 0;
71 return modify_ldt(1, &ldt_info
, sizeof(ldt_info
));
73 #if defined(__NetBSD__) || defined(__FreeBSD__)
74 struct segment_descriptor
*sd
;
78 printf("set_ldt_entry: entry=%x base=%x limit=%x%s %s-bit contents=%d %s\n",
79 entry
, base
, limit
, limit_in_pages_flag
?"-pages":"",
80 seg_32bit_flag
?"32":"16",
81 contents
, read_only_flag
?"read-only":"");
84 sd
= make_sd(base
, limit
, contents
, read_only_flag
, seg_32bit_flag
, limit_in_pages_flag
);
85 ret
= i386_set_ldt(entry
, (union descriptor
*)sd
, 1);
87 perror("i386_set_ldt");
89 "Did you reconfigure the kernel with \"options USER_LDT\"?\n");
97 #endif /* ifndef WINELIB */