10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51618Srie * Common Development and Distribution License (the "License").
61618Srie * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211618Srie
220Sstevel@tonic-gate /*
23*12449SRod.Evans@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
268598SRod.Evans@Sun.COM #include <string.h>
278598SRod.Evans@Sun.COM #include <dlfcn.h>
288598SRod.Evans@Sun.COM #include <stdio.h>
298598SRod.Evans@Sun.COM #include <debug.h>
308598SRod.Evans@Sun.COM #include "_rtld.h"
318598SRod.Evans@Sun.COM #include "_elf.h"
32*12449SRod.Evans@Sun.COM #include "_inline_gen.h"
338598SRod.Evans@Sun.COM #include "msg.h"
340Sstevel@tonic-gate
350Sstevel@tonic-gate
360Sstevel@tonic-gate static Dl_amd64_unwindinfo *
getunwind_core(Lm_list * lml,void * pc,Dl_amd64_unwindinfo * unwindinfo)376746Srie getunwind_core(Lm_list *lml, void *pc, Dl_amd64_unwindinfo *unwindinfo)
380Sstevel@tonic-gate {
396746Srie Rt_map *lmp;
406746Srie
410Sstevel@tonic-gate /*
421618Srie * Validate the version information.
430Sstevel@tonic-gate */
440Sstevel@tonic-gate if (unwindinfo == NULL) {
454192Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_ARG_ILLVAL));
460Sstevel@tonic-gate return (0);
470Sstevel@tonic-gate }
480Sstevel@tonic-gate if ((unwindinfo->dlui_version < DLUI_VERS_1) ||
490Sstevel@tonic-gate (unwindinfo->dlui_version > DLUI_VERS_CURRENT)) {
504192Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_UNW_BADVERS),
514192Srie unwindinfo->dlui_version, DLUI_VERS_CURRENT);
520Sstevel@tonic-gate return (0);
530Sstevel@tonic-gate }
541618Srie
550Sstevel@tonic-gate /*
561618Srie * Clean out the structure.
570Sstevel@tonic-gate */
580Sstevel@tonic-gate unwindinfo->dlui_flags = 0;
590Sstevel@tonic-gate unwindinfo->dlui_objname = 0;
600Sstevel@tonic-gate unwindinfo->dlui_unwindstart = 0;
610Sstevel@tonic-gate unwindinfo->dlui_unwindend = 0;
620Sstevel@tonic-gate unwindinfo->dlui_segstart = 0;
630Sstevel@tonic-gate unwindinfo->dlui_segend = 0;
640Sstevel@tonic-gate
656746Srie /*
666746Srie * Identify the link-map associated with the exception "pc". Note,
676746Srie * the "pc" might not correspond to a link-map (as can happen with a
686746Srie * "pc" fabricated by a debugger such as dbx). In this case, the
696746Srie * unwind data buffer will be filled with flags set to indicate an
706746Srie * unknown caller.
716746Srie */
726746Srie lmp = _caller(pc, CL_NONE);
736746Srie
741995Srie if (lmp) {
758598SRod.Evans@Sun.COM mmapobj_result_t *mpp;
761618Srie
770Sstevel@tonic-gate /*
788598SRod.Evans@Sun.COM * Determine the associated segment.
790Sstevel@tonic-gate */
808598SRod.Evans@Sun.COM if ((mpp = find_segment(pc, lmp)) == NULL)
818598SRod.Evans@Sun.COM return (0);
821618Srie
838598SRod.Evans@Sun.COM unwindinfo->dlui_objname = (char *)PATHNAME(lmp);
848598SRod.Evans@Sun.COM unwindinfo->dlui_segstart = mpp->mr_addr;
858598SRod.Evans@Sun.COM unwindinfo->dlui_segend = mpp->mr_addr + mpp->mr_msize;
868598SRod.Evans@Sun.COM
878598SRod.Evans@Sun.COM if (PTUNWIND(lmp) && (mpp->mr_addr)) {
880Sstevel@tonic-gate uintptr_t base;
891618Srie
901995Srie if (FLAGS(lmp) & FLG_RT_FIXED)
910Sstevel@tonic-gate base = 0;
920Sstevel@tonic-gate else
931995Srie base = ADDR(lmp);
941618Srie
950Sstevel@tonic-gate unwindinfo->dlui_unwindstart =
961995Srie (void *)(PTUNWIND(lmp)->p_vaddr + base);
970Sstevel@tonic-gate unwindinfo->dlui_unwindend =
981995Srie (void *)(PTUNWIND(lmp)->p_vaddr +
991995Srie PTUNWIND(lmp)->p_memsz + base);
1001618Srie
1018598SRod.Evans@Sun.COM } else if (mpp->mr_addr)
1020Sstevel@tonic-gate unwindinfo->dlui_flags |= DLUI_FLG_NOUNWIND;
1031618Srie else
1040Sstevel@tonic-gate unwindinfo->dlui_flags |=
1050Sstevel@tonic-gate DLUI_FLG_NOUNWIND | DLUI_FLG_NOOBJ;
1060Sstevel@tonic-gate } else {
1070Sstevel@tonic-gate /*
1081618Srie * No object found.
1090Sstevel@tonic-gate */
1100Sstevel@tonic-gate unwindinfo->dlui_flags = DLUI_FLG_NOOBJ | DLUI_FLG_NOUNWIND;
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate return (unwindinfo);
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate
1156812Sraf #pragma weak _dlamd64getunwind = dlamd64getunwind
1160Sstevel@tonic-gate
1171618Srie Dl_amd64_unwindinfo *
dlamd64getunwind(void * pc,Dl_amd64_unwindinfo * unwindinfo)1186812Sraf dlamd64getunwind(void *pc, Dl_amd64_unwindinfo *unwindinfo)
1191618Srie {
1201995Srie Rt_map *lmp;
1214192Srie Lm_list *lml;
1226515Sraf int entry = enter(0);
1230Sstevel@tonic-gate
1246746Srie lmp = _caller(caller(), CL_EXECDEF);
1256746Srie lml = LIST(lmp);
1260Sstevel@tonic-gate
1276746Srie unwindinfo = getunwind_core(lml, pc, unwindinfo);
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate if (entry)
1306515Sraf leave(lml, 0);
1310Sstevel@tonic-gate return (unwindinfo);
1320Sstevel@tonic-gate }
133