Gos-freebsd.c revision 8a75ba971a295ce7e6b7b73b90272fb9c04e5b2f
1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2002-2003 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4 5This file is part of libunwind. 6 7Permission is hereby granted, free of charge, to any person obtaining 8a copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, sublicense, and/or sell copies of the Software, and to 12permit persons to whom the Software is furnished to do so, subject to 13the following conditions: 14 15The above copyright notice and this permission notice shall be 16included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26#include "unwind_i.h" 27 28PROTECTED int 29unw_is_signal_frame (unw_cursor_t *cursor) 30{ 31#if defined __linux__ 32 struct cursor *c = (struct cursor *) cursor; 33 unw_word_t w0, w1, ip; 34 unw_addr_space_t as; 35 unw_accessors_t *a; 36 void *arg; 37 int ret; 38 39 as = c->dwarf.as; 40 a = unw_get_accessors (as); 41 arg = c->dwarf.as_arg; 42 43 /* Check if EIP points at sigreturn() sequence. On Linux, this is: 44 45 __restore: 46 0x58 pop %eax 47 0xb8 0x77 0x00 0x00 0x00 movl 0x77,%eax 48 0xcd 0x80 int 0x80 49 50 without SA_SIGINFO, and 51 52 __restore_rt: 53 0xb8 0xad 0x00 0x00 0x00 movl 0x80,%eax 54 0xcd 0x80 int 0x80 55 0x90 nop 56 57 if SA_SIGINFO is specified. 58 */ 59 ip = c->dwarf.ip; 60 if ((ret = (*a->access_mem) (as, ip, &w0, 0, arg)) < 0 61 || (ret = (*a->access_mem) (as, ip + 4, &w1, 0, arg)) < 0) 62 return ret; 63 ret = X86_SCF_NONE; 64 if (w0 == 0x0077b858 && w1 == 0x80cd0000) 65 ret = X86_SCF_LINUX_SIGFRAME; 66 else if (w0 == 0x0000adb8 && w1 == 0x9080cd00) 67 ret = X86_SCF_LINUX_RT_SIGFRAME; 68 Debug (16, "returning %d\n", ret); 69 return ret; 70#elif defined __FreeBSD__ 71 struct cursor *c = (struct cursor *) cursor; 72 unw_word_t w0, w1, w2, w3, w4, w5, ip; 73 unw_addr_space_t as; 74 unw_accessors_t *a; 75 void *arg; 76 int ret; 77 78 as = c->dwarf.as; 79 a = unw_get_accessors (as); 80 arg = c->dwarf.as_arg; 81 82 /* Check if EIP points at sigreturn() sequence. It can be: 83sigcode+4: from amd64 freebsd32 environment 848d 44 24 20 lea 0x20(%esp),%eax 8550 push %eax 86b8 a1 01 00 00 mov $0x1a1,%ea 8750 push %eax 88cd 80 int $0x80 89 90sigcode+4: from real i386 918d 44 24 20 lea 0x20(%esp),%eax 9250 push %eax 93f7 40 54 00 02 00 testl $0x20000,0x54(%eax) 9475 03 jne sigcode+21 958e 68 14 mov 0x14(%eax),%gs 96b8 a1 01 00 00 mov $0x1a1,%eax 9750 push %eax 98cd 80 int $0x80 99 100freebsd4_sigcode+4: 101XXX 102osigcode: 103XXX 104 */ 105 ip = c->dwarf.ip; 106 ret = X86_SCF_NONE; 107 if ((*a->access_mem) (as, ip, &w0, 0, arg) < 0 || 108 (*a->access_mem) (as, ip + 4, &w1, 0, arg) < 0 || 109 (*a->access_mem) (as, ip + 8, &w2, 0, arg) < 0 || 110 (*a->access_mem) (as, ip + 12, &w3, 0, arg) < 0) 111 return ret; 112 if (w0 == 0x2024448d && w1 == 0x01a1b850 && w2 == 0xcd500000 && 113 (w3 & 0xff) == 0x80) 114 ret = X86_SCF_FREEBSD_SIGFRAME; 115 else { 116 if ((*a->access_mem) (as, ip + 16, &w4, 0, arg) < 0 || 117 (*a->access_mem) (as, ip + 20, &w5, 0, arg) < 0) 118 return ret; 119 if (w0 == 0x2024448d && w1 == 0x5440f750 && w2 == 0x75000200 && 120 w3 == 0x14688e03 && w4 == 0x0001a1b8 && w5 == 0x80cd5000) 121 ret = X86_SCF_FREEBSD_SIGFRAME; 122 } 123 Debug (16, "returning %d\n", ret); 124 return (ret); 125#else 126#error Port me 127#endif 128 return -UNW_ENOINFO; 129} 130