2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2002-2004 Roland McGrath <roland@redhat.com>
7 * Copyright (c) 2010 Andreas Schwab <schwab@linux-m68k.org>
8 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
9 * Copyright (c) 2014-2018 The strace developers.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #ifdef HAVE_STRUCT_USER_DESC
41 # include "print_fields.h"
45 print_user_desc(struct tcb *const tcp, const kernel_ulong_t addr,
46 enum user_desc_print_filter filter)
48 struct user_desc desc;
49 unsigned *entry_number = get_tcb_priv_data(tcp);
52 case USER_DESC_ENTERING:
53 if (umove_or_printaddr(tcp, addr, &desc.entry_number))
58 case USER_DESC_EXITING:
59 if (!addr || !verbose(tcp))
61 if (syserror(tcp) || umove(tcp, addr, &desc)) {
71 if (umove_or_printaddr(tcp, addr, &desc))
77 if (filter & USER_DESC_ENTERING) {
78 PRINT_FIELD_ID("{", desc, entry_number);
81 * If we don't print the whole structure now, let's save it for
84 if (filter == USER_DESC_ENTERING) {
85 entry_number = xmalloc(sizeof(*entry_number));
87 *entry_number = desc.entry_number;
88 set_tcb_priv_data(tcp, entry_number, free);
92 if (filter & USER_DESC_EXITING) {
94 * It should be the same in case of get_thread_area, but we can
97 if (filter == USER_DESC_EXITING) {
99 if (*entry_number != desc.entry_number) {
100 if ((int) desc.entry_number == -1)
108 * This is really strange. If we are here, it
109 * means that we failed on entering but somehow
110 * succeeded on exiting.
112 PRINT_FIELD_ID(" => {", desc, entry_number);
116 PRINT_FIELD_0X(", ", desc, base_addr);
117 PRINT_FIELD_0X(", ", desc, limit);
118 PRINT_FIELD_U_CAST(", ", desc, seg_32bit, unsigned int);
119 PRINT_FIELD_U_CAST(", ", desc, contents, unsigned int);
120 PRINT_FIELD_U_CAST(", ", desc, read_exec_only, unsigned int);
121 PRINT_FIELD_U_CAST(", ", desc, limit_in_pages, unsigned int);
122 PRINT_FIELD_U_CAST(", ", desc, seg_not_present, unsigned int);
123 PRINT_FIELD_U_CAST(", ", desc, useable, unsigned int);
125 # ifdef HAVE_STRUCT_USER_DESC_LM
126 /* lm is totally ignored for 32-bit processes */
127 if (current_klongsize == 8)
128 PRINT_FIELD_U_CAST(", ", desc, lm, unsigned int);
129 # endif /* HAVE_STRUCT_USER_DESC_LM */
138 tprintf("%d, ", (int) tcp->u_arg[0]);
139 if (tcp->u_arg[2] != sizeof(struct user_desc))
140 printaddr(tcp->u_arg[1]);
142 print_user_desc(tcp, tcp->u_arg[1], USER_DESC_BOTH);
143 tprintf(", %" PRI_klu, tcp->u_arg[2]);
149 * For some reason ("tht ABI for sys_modify_ldt() expects
150 * 'int'"), modify_ldt clips higher bits on x86_64.
153 if (syserror(tcp) || (kernel_ulong_t) tcp->u_rval < 0xfffff000)
156 tcp->u_error = -(unsigned int) tcp->u_rval;
161 SYS_FUNC(set_thread_area)
164 print_user_desc(tcp, tcp->u_arg[0], USER_DESC_BOTH);
166 struct user_desc desc;
168 if (!verbose(tcp) || syserror(tcp) ||
169 umove(tcp, tcp->u_arg[0], &desc) < 0) {
170 /* returned entry_number is not available */
172 static char outstr[32];
174 xsprintf(outstr, "entry_number=%u", desc.entry_number);
175 tcp->auxstr = outstr;
182 SYS_FUNC(get_thread_area)
184 print_user_desc(tcp, tcp->u_arg[0],
185 entering(tcp) ? USER_DESC_ENTERING : USER_DESC_EXITING);
189 #endif /* HAVE_STRUCT_USER_DESC */
191 #if defined(M68K) || defined(MIPS)
192 SYS_FUNC(set_thread_area)
194 printaddr(tcp->u_arg[0]);
202 SYS_FUNC(get_thread_area)
204 return RVAL_DECODED | RVAL_HEX;