1254721Semaste/*
2254721SemasteCopyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
3254721SemastePermission is hereby granted, free of charge, to any person
4254721Semasteobtaining a copy of this software and associated documentation
5254721Semastefiles (the "Software"), to deal in the Software without
6254721Semasterestriction, including without limitation the rights to use,
7254721Semastecopy, modify, merge, publish, distribute, sublicense, and/or sell
8254721Semastecopies of the Software, and to permit persons to whom the
9254721SemasteSoftware is furnished to do so, subject to the following
10254721Semasteconditions:
11254721Semaste
12254721SemasteThe above copyright notice and this permission notice shall be
13254721Semasteincluded in all copies or substantial portions of the Software.
14254721Semaste
15254721SemasteTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16254721SemasteEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17254721SemasteOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18254721SemasteNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19254721SemasteHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20254721SemasteWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21254721SemasteFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22254721SemasteOTHER DEALINGS IN THE SOFTWARE.
23254721Semaste*/
24254721Semaste
25254721Semaste#ifndef __UWX_SELF_INCLUDED
26254721Semaste#define __UWX_SELF_INCLUDED 1
27254721Semaste
28254721Semaste#include <signal.h>
29254721Semaste
30254721Semaste#ifndef __UWX_INCLUDED
31254721Semaste#include "uwx.h"
32254721Semaste#endif /* __UWX_INCLUDED */
33254721Semaste
34254721Semaste#if defined(__cplusplus)
35254721Semaste#define __EXTERN_C extern "C"
36254721Semaste#else
37254721Semaste#define __EXTERN_C extern
38254721Semaste#endif
39254721Semaste
40254721Semastestruct uwx_self_info;
41254721Semaste
42254721Semaste__EXTERN_C struct uwx_self_info *uwx_self_init_info(struct uwx_env *env);
43254721Semaste
44254721Semaste__EXTERN_C int uwx_self_free_info(struct uwx_self_info *info);
45254721Semaste
46254721Semaste__EXTERN_C int uwx_self_init_context(struct uwx_env *env);
47254721Semaste
48254721Semaste__EXTERN_C int uwx_self_init_from_sigcontext(
49254721Semaste    struct uwx_env *env,
50254721Semaste    struct uwx_self_info *info,
51254721Semaste    ucontext_t *ucontext);
52254721Semaste
53254721Semaste__EXTERN_C int uwx_self_do_context_frame(
54254721Semaste    struct uwx_env *env,
55254721Semaste    struct uwx_self_info *info);
56254721Semaste
57254721Semaste__EXTERN_C int uwx_self_copyin(
58254721Semaste    int request,
59254721Semaste    char *loc,
60254721Semaste    uint64_t rem,
61254721Semaste    int len,
62254721Semaste    intptr_t tok);
63254721Semaste
64254721Semaste__EXTERN_C int uwx_self_lookupip(
65254721Semaste    int request,
66254721Semaste    uint64_t ip,
67254721Semaste    intptr_t tok,
68254721Semaste    uint64_t **resultp);
69254721Semaste
70254721Semaste#define UWX_SELF_ERR_BADABICONTEXT  (-101)
71254721Semaste
72254721Semaste#undef __EXTERN_C
73254721Semaste
74254721Semaste#if defined(__cplusplus)
75254721Semaste
76254721Semasteclass UnwindExpressSelf : public UnwindExpress {
77254721Semaste
78254721Semastepublic:
79254721Semaste
80254721Semaste    UnwindExpressSelf() {
81254721Semaste	info = uwx_self_init_info(env);
82254721Semaste	(void)uwx_register_callbacks(env, (intptr_t)info,
83254721Semaste				uwx_self_copyin, uwx_self_lookupip);
84254721Semaste    }
85254721Semaste
86254721Semaste    ~UnwindExpressSelf() {
87254721Semaste	if (info != 0)
88254721Semaste	    uwx_self_free_info(info);
89254721Semaste	info = 0;
90254721Semaste    }
91254721Semaste
92254721Semaste    int init_context() {
93254721Semaste	return uwx_self_init_context(env);
94254721Semaste    }
95254721Semaste
96254721Semaste    int init_context(ucontext_t *ucontext) {
97254721Semaste	return uwx_self_init_from_sigcontext(env, info, ucontext);
98254721Semaste    }
99254721Semaste
100254721Semaste    int do_context_frame() {
101254721Semaste	return uwx_self_do_context_frame(env, info);
102254721Semaste    }
103254721Semaste
104254721Semasteprotected:
105254721Semaste
106254721Semaste    struct uwx_self_info *info;
107254721Semaste
108254721Semaste};
109254721Semaste
110#endif /* __cplusplus */
111
112#endif /* __UWX_SELF_INCLUDED */
113