1#include "defs.h"
2
3#if defined I386 || defined X86_64 || defined X32
4
5# include <asm/ldt.h>
6
7void
8print_user_desc(struct tcb *tcp, long addr)
9{
10	struct user_desc desc;
11
12	if (umove(tcp, addr, &desc) < 0) {
13		tprintf("%lx", addr);
14		return;
15	}
16
17	if (!verbose(tcp)) {
18		tprintf("{entry_number:%d, ...}", desc.entry_number);
19		return;
20	}
21
22	tprintf("{entry_number:%d, "
23		"base_addr:%#08x, "
24		"limit:%d, "
25		"seg_32bit:%d, "
26		"contents:%d, "
27		"read_exec_only:%d, "
28		"limit_in_pages:%d, "
29		"seg_not_present:%d, "
30		"useable:%d}",
31		desc.entry_number,
32		desc.base_addr,
33		desc.limit,
34		desc.seg_32bit,
35		desc.contents,
36		desc.read_exec_only,
37		desc.limit_in_pages,
38		desc.seg_not_present,
39		desc.useable);
40}
41
42int
43sys_modify_ldt(struct tcb *tcp)
44{
45	if (entering(tcp)) {
46		tprintf("%ld, ", tcp->u_arg[0]);
47		if (tcp->u_arg[1] == 0
48		    || tcp->u_arg[2] != sizeof(struct user_desc)) {
49			tprintf("%lx", tcp->u_arg[1]);
50		} else {
51			print_user_desc(tcp, tcp->u_arg[1]);
52		}
53		tprintf(", %lu", tcp->u_arg[2]);
54	}
55	return 0;
56}
57
58int
59sys_set_thread_area(struct tcb *tcp)
60{
61	if (entering(tcp)) {
62		print_user_desc(tcp, tcp->u_arg[0]);
63	} else {
64		struct user_desc desc;
65
66		if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &desc) < 0) {
67			/* returned entry_number is not available */
68		} else {
69			static char outstr[32];
70
71			sprintf(outstr, "entry_number:%d", desc.entry_number);
72			tcp->auxstr = outstr;
73			return RVAL_STR;
74		}
75	}
76	return 0;
77}
78
79int
80sys_get_thread_area(struct tcb *tcp)
81{
82	if (exiting(tcp)) {
83		if (syserror(tcp))
84			tprintf("%lx", tcp->u_arg[0]);
85		else
86			print_user_desc(tcp, tcp->u_arg[0]);
87	}
88	return 0;
89}
90
91#endif /* I386 || X86_64 || X32 */
92
93#if defined(M68K) || defined(MIPS)
94int
95sys_set_thread_area(struct tcb *tcp)
96{
97	if (entering(tcp))
98		tprintf("%#lx", tcp->u_arg[0]);
99	return 0;
100
101}
102#endif
103
104#if defined(M68K)
105int
106sys_get_thread_area(struct tcb *tcp)
107{
108	return RVAL_HEX;
109}
110#endif
111