003 File Manager
Current Path:
/usr/src/contrib/ntp/lib/isc
usr
/
src
/
contrib
/
ntp
/
lib
/
isc
/
📁
..
📄
Atffile
(90 B)
📁
alpha
📄
api
(129 B)
📄
app_api.c
(3.17 KB)
📄
assertions.c
(3.4 KB)
📄
backtrace-emptytbl.c
(1.33 KB)
📄
backtrace.c
(7.53 KB)
📄
base32.c
(9.64 KB)
📄
base64.c
(6.54 KB)
📄
bitstring.c
(3.41 KB)
📄
buffer.c
(10.11 KB)
📄
bufferlist.c
(1.71 KB)
📄
commandline.c
(6.84 KB)
📄
entropy.c
(29.08 KB)
📄
error.c
(2.91 KB)
📄
event.c
(2.47 KB)
📄
fsaccess.c
(2.7 KB)
📄
hash.c
(10.75 KB)
📄
heap.c
(6.47 KB)
📄
hex.c
(4.78 KB)
📄
hmacmd5.c
(3.77 KB)
📄
hmacsha.c
(15.6 KB)
📄
httpd.c
(26.31 KB)
📁
ia64
📁
include
📄
inet_aton.c
(6.4 KB)
📄
inet_ntop.c
(5.29 KB)
📄
inet_pton.c
(5.35 KB)
📄
iterated_hash.c
(1.44 KB)
📄
lex.c
(22.34 KB)
📄
lfsr.c
(3.6 KB)
📄
lib.c
(2.67 KB)
📄
log.c
(44.84 KB)
📄
md5.c
(8.57 KB)
📄
mem.c
(58.91 KB)
📄
mem_api.c
(6.58 KB)
📁
mips
📄
mutexblock.c
(1.54 KB)
📄
netaddr.c
(9.91 KB)
📄
netscope.c
(2.31 KB)
📁
nls
📁
noatomic
📁
nothreads
📄
ondestroy.c
(2.16 KB)
📄
parseint.c
(2.04 KB)
📄
portset.c
(3.43 KB)
📁
powerpc
📄
print.c
(12.16 KB)
📁
pthreads
📄
quota.c
(2.37 KB)
📄
radix.c
(16.77 KB)
📄
random.c
(2.61 KB)
📄
ratelimiter.c
(8.15 KB)
📄
refcount.c
(1.21 KB)
📄
region.c
(1.39 KB)
📄
result.c
(5.81 KB)
📄
rwlock.c
(22.19 KB)
📄
serial.c
(1.73 KB)
📄
sha1.c
(10.41 KB)
📄
sha2.c
(40.33 KB)
📄
sockaddr.c
(13.42 KB)
📄
socket_api.c
(5.57 KB)
📁
sparc64
📄
stats.c
(8.26 KB)
📄
string.c
(5.33 KB)
📄
strtoul.c
(4.23 KB)
📄
symtab.c
(7.21 KB)
📄
task.c
(45.62 KB)
📄
task_api.c
(5.62 KB)
📄
task_p.h
(1.27 KB)
📄
taskpool.c
(4.4 KB)
📁
tests
📄
timer.c
(26.04 KB)
📄
timer_api.c
(3.49 KB)
📄
timer_p.h
(1.13 KB)
📄
tsmemcmp.c
(2.04 KB)
📁
unix
📄
version.c
(1.11 KB)
📁
win32
📁
x86_32
📁
x86_64
Editing: backtrace.c
/* * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ /* $Id: backtrace.c,v 1.3 2009/09/02 23:48:02 tbox Exp $ */ /*! \file */ #include "config.h" #include <string.h> #include <stdlib.h> #ifdef HAVE_LIBCTRACE #include <execinfo.h> #endif #include <isc/backtrace.h> #include <isc/result.h> #include <isc/util.h> #ifdef ISC_PLATFORM_USEBACKTRACE /* * Getting a back trace of a running process is tricky and highly platform * dependent. Our current approach is as follows: * 1. If the system library supports the "backtrace()" function, use it. * 2. Otherwise, if the compiler is gcc and the architecture is x86_64 or IA64, * then use gcc's (hidden) Unwind_Backtrace() function. Note that this * function doesn't work for C programs on many other architectures. * 3. Otherwise, if the architecture x86 or x86_64, try to unwind the stack * frame following frame pointers. This assumes the executable binary * compiled with frame pointers; this is not always true for x86_64 (rather, * compiler optimizations often disable frame pointers). The validation * checks in getnextframeptr() hopefully rejects bogus values stored in * the RBP register in such a case. If the backtrace function itself crashes * due to this problem, the whole package should be rebuilt with * --disable-backtrace. */ #ifdef HAVE_LIBCTRACE #define BACKTRACE_LIBC #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__ia64__)) #define BACKTRACE_GCC #elif defined(__x86_64__) || defined(__i386__) #define BACKTRACE_X86STACK #else #define BACKTRACE_DISABLED #endif /* HAVE_LIBCTRACE */ #else /* !ISC_PLATFORM_USEBACKTRACE */ #define BACKTRACE_DISABLED #endif /* ISC_PLATFORM_USEBACKTRACE */ #ifdef BACKTRACE_LIBC isc_result_t isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { int n; /* * Validate the arguments: intentionally avoid using REQUIRE(). * See notes in backtrace.h. */ if (addrs == NULL || nframes == NULL) return (ISC_R_FAILURE); /* * backtrace(3) includes this function itself in the address array, * which should be eliminated from the returned sequence. */ n = backtrace(addrs, maxaddrs); if (n < 2) return (ISC_R_NOTFOUND); n--; memmove(addrs, &addrs[1], sizeof(void *) * n); *nframes = n; return (ISC_R_SUCCESS); } #elif defined(BACKTRACE_GCC) extern int _Unwind_Backtrace(void* fn, void* a); extern void* _Unwind_GetIP(void* ctx); typedef struct { void **result; int max_depth; int skip_count; int count; } trace_arg_t; static int btcallback(void *uc, void *opq) { trace_arg_t *arg = (trace_arg_t *)opq; if (arg->skip_count > 0) arg->skip_count--; else arg->result[arg->count++] = (void *)_Unwind_GetIP(uc); if (arg->count == arg->max_depth) return (5); /* _URC_END_OF_STACK */ return (0); /* _URC_NO_REASON */ } isc_result_t isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { trace_arg_t arg; /* Argument validation: see above. */ if (addrs == NULL || nframes == NULL) return (ISC_R_FAILURE); arg.skip_count = 1; arg.result = addrs; arg.max_depth = maxaddrs; arg.count = 0; _Unwind_Backtrace(btcallback, &arg); *nframes = arg.count; return (ISC_R_SUCCESS); } #elif defined(BACKTRACE_X86STACK) #ifdef __x86_64__ static unsigned long getrbp() { __asm("movq %rbp, %rax\n"); } #endif static void ** getnextframeptr(void **sp) { void **newsp = (void **)*sp; /* * Perform sanity check for the new frame pointer, derived from * google glog. This can actually be bogus depending on compiler. */ /* prohibit the stack frames from growing downwards */ if (newsp <= sp) return (NULL); /* A heuristics to reject "too large" frame: this actually happened. */ if ((char *)newsp - (char *)sp > 100000) return (NULL); /* * Not sure if other checks used in glog are needed at this moment. * For our purposes we don't have to consider non-contiguous frames, * for example. */ return (newsp); } isc_result_t isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { int i = 0; void **sp; /* Argument validation: see above. */ if (addrs == NULL || nframes == NULL) return (ISC_R_FAILURE); #ifdef __x86_64__ sp = (void **)getrbp(); if (sp == NULL) return (ISC_R_NOTFOUND); /* * sp is the frame ptr of this function itself due to the call to * getrbp(), so need to unwind one frame for consistency. */ sp = getnextframeptr(sp); #else /* * i386: the frame pointer is stored 2 words below the address for the * first argument. Note that the body of this function cannot be * inlined since it depends on the address of the function argument. */ sp = (void **)&addrs - 2; #endif while (sp != NULL && i < maxaddrs) { addrs[i++] = *(sp + 1); sp = getnextframeptr(sp); } *nframes = i; return (ISC_R_SUCCESS); } #elif defined(BACKTRACE_DISABLED) isc_result_t isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { /* Argument validation: see above. */ if (addrs == NULL || nframes == NULL) return (ISC_R_FAILURE); UNUSED(maxaddrs); return (ISC_R_NOTIMPLEMENTED); } #endif isc_result_t isc_backtrace_getsymbolfromindex(int idx, const void **addrp, const char **symbolp) { REQUIRE(addrp != NULL && *addrp == NULL); REQUIRE(symbolp != NULL && *symbolp == NULL); if (idx < 0 || idx >= isc__backtrace_nsymbols) return (ISC_R_RANGE); *addrp = isc__backtrace_symtable[idx].addr; *symbolp = isc__backtrace_symtable[idx].symbol; return (ISC_R_SUCCESS); } static int symtbl_compare(const void *addr, const void *entryarg) { const isc_backtrace_symmap_t *entry = entryarg; const isc_backtrace_symmap_t *end = &isc__backtrace_symtable[isc__backtrace_nsymbols - 1]; if (isc__backtrace_nsymbols == 1 || entry == end) { if (addr >= entry->addr) { /* * If addr is equal to or larger than that of the last * entry of the table, we cannot be sure if this is * within a valid range so we consider it valid. */ return (0); } return (-1); } /* entry + 1 is a valid entry from now on. */ if (addr < entry->addr) return (-1); else if (addr >= (entry + 1)->addr) return (1); return (0); } isc_result_t isc_backtrace_getsymbol(const void *addr, const char **symbolp, unsigned long *offsetp) { isc_result_t result = ISC_R_SUCCESS; isc_backtrace_symmap_t *found; /* * Validate the arguments: intentionally avoid using REQUIRE(). * See notes in backtrace.h. */ if (symbolp == NULL || *symbolp != NULL || offsetp == NULL) return (ISC_R_FAILURE); if (isc__backtrace_nsymbols < 1) return (ISC_R_NOTFOUND); /* * Search the table for the entry that meets: * entry.addr <= addr < next_entry.addr. */ found = bsearch(addr, isc__backtrace_symtable, isc__backtrace_nsymbols, sizeof(isc__backtrace_symtable[0]), symtbl_compare); if (found == NULL) result = ISC_R_NOTFOUND; else { *symbolp = found->symbol; *offsetp = (u_long)((const char *)addr - (char *)found->addr); } return (result); }
Upload File
Create Folder