1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <signal.h>
18 #include <stdio.h>
19 #include <sys/cdefs.h>
20 #include <unistd.h>
21 #include <memory>
22
action(int signo,siginfo_t * info __unused,void *)23 void action(int signo, siginfo_t* info __unused, void*) {
24 #ifdef __ANDROID__
25 if (signo == 11 && info->si_code == SEGV_MTEAERR) {
26 fprintf(stderr, "SEGV_MTEAERR\n");
27 _exit(0);
28 }
29
30 if (signo == 11 && info->si_code == SEGV_MTESERR) {
31 fprintf(stderr, "SEGV_MTESERR\n");
32 _exit(0);
33 }
34 #endif
35
36 fprintf(stderr, "signo %d\n", signo);
37 _exit(0);
38 }
39
main()40 __attribute__((optnone)) int main() {
41 struct sigaction sa = {};
42 sa.sa_sigaction = action;
43 sa.sa_flags = SA_SIGINFO;
44 sigaction(SIGSEGV, &sa, nullptr);
45
46 std::unique_ptr<int[]> p = std::make_unique<int[]>(4);
47 volatile int oob = p[-1];
48 (void)oob;
49
50 fprintf(stderr, "normal exit\n");
51 return 0;
52 }
53