Home | History | Annotate | Download | only in strace
      1 /*
      2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk (at) cs.few.eur.nl>
      3  * Copyright (c) 1993 Branko Lankester <branko (at) hacktic.nl>
      4  * Copyright (c) 1993-1996 Rick Sladkey <jrs (at) world.std.com>
      5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert (at) cistron.nl>
      6  * Copyright (c) 2002-2004 Roland McGrath <roland (at) redhat.com>
      7  * Copyright (c) 2010 Andreas Schwab <schwab (at) linux-m68k.org>
      8  * Copyright (c) 2014-2015 Dmitry V. Levin <ldv (at) altlinux.org>
      9  * Copyright (c) 2014-2017 The strace developers.
     10  * All rights reserved.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     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.
     22  *
     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.
     33  */
     34 
     35 #include "defs.h"
     36 
     37 #ifdef HAVE_STRUCT_USER_DESC
     38 
     39 # include <asm/ldt.h>
     40 
     41 void
     42 print_user_desc(struct tcb *const tcp, const kernel_ulong_t addr)
     43 {
     44 	struct user_desc desc;
     45 
     46 	if (umove_or_printaddr(tcp, addr, &desc))
     47 		return;
     48 
     49 	tprintf("{entry_number:%d, "
     50 		"base_addr:%#08x, "
     51 		"limit:%d, "
     52 		"seg_32bit:%d, "
     53 		"contents:%d, "
     54 		"read_exec_only:%d, "
     55 		"limit_in_pages:%d, "
     56 		"seg_not_present:%d, "
     57 		"useable:%d}",
     58 		desc.entry_number,
     59 		desc.base_addr,
     60 		desc.limit,
     61 		desc.seg_32bit,
     62 		desc.contents,
     63 		desc.read_exec_only,
     64 		desc.limit_in_pages,
     65 		desc.seg_not_present,
     66 		desc.useable);
     67 }
     68 
     69 SYS_FUNC(modify_ldt)
     70 {
     71 	tprintf("%" PRI_kld ", ", tcp->u_arg[0]);
     72 	if (tcp->u_arg[2] != sizeof(struct user_desc))
     73 		printaddr(tcp->u_arg[1]);
     74 	else
     75 		print_user_desc(tcp, tcp->u_arg[1]);
     76 	tprintf(", %" PRI_klu, tcp->u_arg[2]);
     77 
     78 	return RVAL_DECODED;
     79 }
     80 
     81 SYS_FUNC(set_thread_area)
     82 {
     83 	if (entering(tcp)) {
     84 		print_user_desc(tcp, tcp->u_arg[0]);
     85 	} else {
     86 		struct user_desc desc;
     87 
     88 		if (!verbose(tcp) || syserror(tcp) ||
     89 		    umove(tcp, tcp->u_arg[0], &desc) < 0) {
     90 			/* returned entry_number is not available */
     91 		} else {
     92 			static char outstr[32];
     93 
     94 			sprintf(outstr, "entry_number:%d", desc.entry_number);
     95 			tcp->auxstr = outstr;
     96 			return RVAL_STR;
     97 		}
     98 	}
     99 	return 0;
    100 }
    101 
    102 SYS_FUNC(get_thread_area)
    103 {
    104 	if (exiting(tcp))
    105 		print_user_desc(tcp, tcp->u_arg[0]);
    106 	return 0;
    107 }
    108 
    109 #endif /* HAVE_STRUCT_USER_DESC */
    110 
    111 #if defined(M68K) || defined(MIPS)
    112 SYS_FUNC(set_thread_area)
    113 {
    114 	printaddr(tcp->u_arg[0]);
    115 
    116 	return RVAL_DECODED;
    117 
    118 }
    119 #endif
    120 
    121 #if defined(M68K)
    122 SYS_FUNC(get_thread_area)
    123 {
    124 	return RVAL_DECODED | RVAL_HEX;
    125 }
    126 #endif
    127