1/*
2Copyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
3Permission is hereby granted, free of charge, to any person
4obtaining a copy of this software and associated documentation
5files (the "Software"), to deal in the Software without
6restriction, including without limitation the rights to use,
7copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the
9Software is furnished to do so, subject to the following
10conditions:
11
12The above copyright notice and this permission notice shall be
13included in all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#ifndef __UWX_SELF_INCLUDED
26#define __UWX_SELF_INCLUDED 1
27
28#include <signal.h>
29
30#ifndef __UWX_INCLUDED
31#include "uwx.h"
32#endif /* __UWX_INCLUDED */
33
34#if defined(__cplusplus)
35#define __EXTERN_C extern "C"
36#else
37#define __EXTERN_C extern
38#endif
39
40struct uwx_self_info;
41
42__EXTERN_C struct uwx_self_info *uwx_self_init_info(struct uwx_env *env);
43
44__EXTERN_C int uwx_self_free_info(struct uwx_self_info *info);
45
46__EXTERN_C int uwx_self_init_context(struct uwx_env *env);
47
48__EXTERN_C int uwx_self_init_from_sigcontext(
49    struct uwx_env *env,
50    struct uwx_self_info *info,
51    ucontext_t *ucontext);
52
53__EXTERN_C int uwx_self_do_context_frame(
54    struct uwx_env *env,
55    struct uwx_self_info *info);
56
57__EXTERN_C int uwx_self_copyin(
58    int request,
59    char *loc,
60    uint64_t rem,
61    int len,
62    intptr_t tok);
63
64__EXTERN_C int uwx_self_lookupip(
65    int request,
66    uint64_t ip,
67    intptr_t tok,
68    uint64_t **resultp);
69
70#define UWX_SELF_ERR_BADABICONTEXT  (-101)
71
72#undef __EXTERN_C
73
74#if defined(__cplusplus)
75
76class UnwindExpressSelf : public UnwindExpress {
77
78public:
79
80    UnwindExpressSelf() {
81	info = uwx_self_init_info(env);
82	(void)uwx_register_callbacks(env, (intptr_t)info,
83				uwx_self_copyin, uwx_self_lookupip);
84    }
85
86    ~UnwindExpressSelf() {
87	if (info != 0)
88	    uwx_self_free_info(info);
89	info = 0;
90    }
91
92    int init_context() {
93	return uwx_self_init_context(env);
94    }
95
96    int init_context(ucontext_t *ucontext) {
97	return uwx_self_init_from_sigcontext(env, info, ucontext);
98    }
99
100    int do_context_frame() {
101	return uwx_self_do_context_frame(env, info);
102    }
103
104protected:
105
106    struct uwx_self_info *info;
107
108};
109
110#endif /* __cplusplus */
111
112#endif /* __UWX_SELF_INCLUDED */
113