-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshift0personality.c
56 lines (50 loc) · 1.75 KB
/
shift0personality.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Personality functions for proper stack unwinding.
* shift0personality.c
*
* Copyright (c) 2011, Marek Materzok <[email protected]>
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* The software is provided 'as is', without any warranty.
*/
#include <stdlib.h>
#include <stdio.h>
#include "unwind.h"
#include "shift0.h"
extern int marker;
extern void* stacks[];
int32_t runcont_dirty(struct cont *fun, int32_t val);
_Unwind_Reason_Code
__reset_personality(int version, _Unwind_Action actions,
_Unwind_Exception_Class exception_class,
struct _Unwind_Exception *ue_header,
struct _Unwind_Context *context)
{
if (actions & _UA_SEARCH_PHASE)
return _URC_CONTINUE_UNWIND;
if (actions & _UA_CLEANUP_PHASE) {
free(stacks[--marker]);
return _URC_CONTINUE_UNWIND;
}
abort();
}
_Unwind_Reason_Code
__runcont_personality(int version, _Unwind_Action actions,
_Unwind_Exception_Class exception_class,
struct _Unwind_Exception *ue_header,
struct _Unwind_Context *context)
{
if (actions & _UA_SEARCH_PHASE)
return _URC_CONTINUE_UNWIND;
if (actions & _UA_CLEANUP_PHASE) {
void** base = (void**)_Unwind_GetGR(context,5);
struct cont* c = (struct cont*)*(base+2);
*((int32_t (**)(struct cont*, int32_t)) c) = runcont_dirty;
return _URC_CONTINUE_UNWIND;
}
abort();
}