-
Notifications
You must be signed in to change notification settings - Fork 517
/
Copy pathbadAltHandler.m
81 lines (68 loc) · 2.52 KB
/
badAltHandler.m
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* TEST_CONFIG OS=macosx ARCH=x86_64
TEST_CRASHES
TEST_RUN_OUTPUT
objc\[\d+\]: objc_removeExceptionHandler\(\) called with unknown alt handler; this is probably a bug in multithreaded AppKit use. Set environment variable OBJC_DEBUG_ALT_HANDLERS=YES or break in objc_alt_handler_error\(\) to debug.
objc\[\d+\]: objc_removeExceptionHandler\(\) called with unknown alt handler; this is probably a bug in multithreaded AppKit use.
objc\[\d+\]: HALTED
END
*/
#include "test.h"
#include <objc/objc-exception.h>
/*
rdar://6888838
Mail installs an alt handler on one thread and deletes it on another.
This confuses the alt handler machinery, which halts the process.
*/
uintptr_t Token;
void handler(id unused __unused, void *context __unused)
{
}
int main()
{
#if __clang__ && __cplusplus
// alt handlers need the objc personality
// catch (id) workaround forces the objc personality
@try {
testwarn("rdar://9183014 clang uses wrong exception personality");
} @catch (id e __unused) {
}
#endif
@try {
// Install 4 alt handlers
uintptr_t t1, t2, t3, t4;
t1 = objc_addExceptionHandler(&handler, NULL);
t2 = objc_addExceptionHandler(&handler, NULL);
t3 = objc_addExceptionHandler(&handler, NULL);
t4 = objc_addExceptionHandler(&handler, NULL);
// Remove 3 of them.
objc_removeExceptionHandler(t1);
objc_removeExceptionHandler(t2);
objc_removeExceptionHandler(t3);
// Create an alt handler on another thread
// that collides with one of the removed handlers
testonthread(^{
@try {
Token = objc_addExceptionHandler(&handler, NULL);
} @catch (...) {
}
});
// Incorrectly remove the other thread's handler
objc_removeExceptionHandler(Token);
// Remove the 4th handler
objc_removeExceptionHandler(t4);
// Install 8 more handlers.
// If the other thread's handler was not ignored,
// this will fail.
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
objc_addExceptionHandler(&handler, NULL);
} @catch (...) {
}
// This should have crashed earlier.
fail(__FILE__);
}