1115013Smarcel/* 2160157SmarcelCopyright (c) 2003-2006 Hewlett-Packard Development Company, L.P. 3121642SmarcelPermission is hereby granted, free of charge, to any person 4121642Smarcelobtaining a copy of this software and associated documentation 5121642Smarcelfiles (the "Software"), to deal in the Software without 6121642Smarcelrestriction, including without limitation the rights to use, 7121642Smarcelcopy, modify, merge, publish, distribute, sublicense, and/or sell 8121642Smarcelcopies of the Software, and to permit persons to whom the 9121642SmarcelSoftware is furnished to do so, subject to the following 10121642Smarcelconditions: 11115013Smarcel 12121642SmarcelThe above copyright notice and this permission notice shall be 13121642Smarcelincluded in all copies or substantial portions of the Software. 14121642Smarcel 15121642SmarcelTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16121642SmarcelEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17121642SmarcelOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18121642SmarcelNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19121642SmarcelHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20121642SmarcelWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21121642SmarcelFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22121642SmarcelOTHER DEALINGS IN THE SOFTWARE. 23121642Smarcel*/ 24121642Smarcel 25129059Smarcel#ifndef __UWX_SELF_INCLUDED 26129059Smarcel#define __UWX_SELF_INCLUDED 1 27129059Smarcel 28115013Smarcel#include <signal.h> 29129059Smarcel 30129059Smarcel#ifndef __UWX_INCLUDED 31129059Smarcel#include "uwx.h" 32129059Smarcel#endif /* __UWX_INCLUDED */ 33129059Smarcel 34129059Smarcel#if defined(__cplusplus) 35129059Smarcel#define __EXTERN_C extern "C" 36129059Smarcel#else 37129059Smarcel#define __EXTERN_C extern 38115013Smarcel#endif 39115013Smarcel 40115013Smarcelstruct uwx_self_info; 41115013Smarcel 42129059Smarcel__EXTERN_C struct uwx_self_info *uwx_self_init_info(struct uwx_env *env); 43115013Smarcel 44129059Smarcel__EXTERN_C int uwx_self_free_info(struct uwx_self_info *info); 45115013Smarcel 46129059Smarcel__EXTERN_C int uwx_self_init_context(struct uwx_env *env); 47115013Smarcel 48129059Smarcel__EXTERN_C int uwx_self_init_from_sigcontext( 49115013Smarcel struct uwx_env *env, 50115013Smarcel struct uwx_self_info *info, 51115013Smarcel ucontext_t *ucontext); 52115013Smarcel 53129059Smarcel__EXTERN_C int uwx_self_do_context_frame( 54115013Smarcel struct uwx_env *env, 55115013Smarcel struct uwx_self_info *info); 56115013Smarcel 57129059Smarcel__EXTERN_C int uwx_self_copyin( 58115013Smarcel int request, 59115013Smarcel char *loc, 60115013Smarcel uint64_t rem, 61115013Smarcel int len, 62115013Smarcel intptr_t tok); 63115013Smarcel 64129059Smarcel__EXTERN_C int uwx_self_lookupip( 65115013Smarcel int request, 66115013Smarcel uint64_t ip, 67115013Smarcel intptr_t tok, 68115013Smarcel uint64_t **resultp); 69115013Smarcel 70115013Smarcel#define UWX_SELF_ERR_BADABICONTEXT (-101) 71129059Smarcel 72129059Smarcel#undef __EXTERN_C 73129059Smarcel 74129059Smarcel#if defined(__cplusplus) 75129059Smarcel 76129059Smarcelclass UnwindExpressSelf : public UnwindExpress { 77129059Smarcel 78129059Smarcelpublic: 79129059Smarcel 80129059Smarcel UnwindExpressSelf() { 81129059Smarcel info = uwx_self_init_info(env); 82129059Smarcel (void)uwx_register_callbacks(env, (intptr_t)info, 83129059Smarcel uwx_self_copyin, uwx_self_lookupip); 84129059Smarcel } 85129059Smarcel 86129059Smarcel ~UnwindExpressSelf() { 87129059Smarcel if (info != 0) 88129059Smarcel uwx_self_free_info(info); 89129059Smarcel info = 0; 90129059Smarcel } 91129059Smarcel 92129059Smarcel int init_context() { 93129059Smarcel return uwx_self_init_context(env); 94129059Smarcel } 95129059Smarcel 96129059Smarcel int init_context(ucontext_t *ucontext) { 97129059Smarcel return uwx_self_init_from_sigcontext(env, info, ucontext); 98129059Smarcel } 99129059Smarcel 100129059Smarcel int do_context_frame() { 101129059Smarcel return uwx_self_do_context_frame(env, info); 102129059Smarcel } 103129059Smarcel 104129059Smarcelprotected: 105129059Smarcel 106129059Smarcel struct uwx_self_info *info; 107129059Smarcel 108129059Smarcel}; 109129059Smarcel 110129059Smarcel#endif /* __cplusplus */ 111129059Smarcel 112129059Smarcel#endif /* __UWX_SELF_INCLUDED */ 113