|
2 | 2 | * File: errcode.cpp (Formerly error.c)
|
3 | 3 | * Description: Generic error handler function
|
4 | 4 | * Author: Ray Smith
|
5 |
| - * Created: Tue May 1 16:28:39 BST 1990 |
6 | 5 | *
|
7 | 6 | * (C) Copyright 1989, Hewlett-Packard Ltd.
|
8 | 7 | ** Licensed under the Apache License, Version 2.0 (the "License");
|
|
18 | 17 | **********************************************************************/
|
19 | 18 |
|
20 | 19 | #include "globaloc.h"
|
21 |
| -#include <csignal> |
22 |
| -#ifdef __linux__ |
23 |
| -#include <sys/syscall.h> // For SYS_gettid. |
24 |
| -#include <unistd.h> // For syscall itself. |
25 |
| -#endif |
26 | 20 | #include "allheaders.h"
|
27 | 21 | #include "errcode.h"
|
28 | 22 | #include "tprintf.h"
|
29 | 23 |
|
30 |
| -// Size of thread-id array of pixes to keep in case of crash. |
31 |
| -const int kMaxNumThreadPixes = 32768; |
32 |
| - |
33 |
| -static Pix* global_crash_pixes[kMaxNumThreadPixes]; |
34 |
| - |
35 |
| -void SavePixForCrash(int resolution, Pix* pix) { |
36 |
| -#ifdef __linux__ |
37 |
| -#ifndef ANDROID |
38 |
| - int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes; |
39 |
| -#else |
40 |
| - int thread_id = gettid() % kMaxNumThreadPixes; |
41 |
| -#endif |
42 |
| - pixDestroy(&global_crash_pixes[thread_id]); |
43 |
| - if (pix != nullptr) { |
44 |
| - Pix* clone = pixClone(pix); |
45 |
| - pixSetXRes(clone, resolution); |
46 |
| - pixSetYRes(clone, resolution); |
47 |
| - global_crash_pixes[thread_id] = clone; |
48 |
| - } |
49 |
| -#endif |
50 |
| -} |
51 |
| - |
52 |
| -// CALL ONLY from a signal handler! Writes a crash image to stderr. |
53 |
| -void signal_exit(int signal_code) { |
54 |
| - tprintf("Received signal %d!\n", signal_code); |
55 |
| -#ifdef __linux__ |
56 |
| -#ifndef ANDROID |
57 |
| - int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes; |
58 |
| -#else |
59 |
| - int thread_id = gettid() % kMaxNumThreadPixes; |
60 |
| -#endif |
61 |
| - if (global_crash_pixes[thread_id] != nullptr) { |
62 |
| - fprintf(stderr, "Crash caused by image with resolution %d\n", |
63 |
| - pixGetYRes(global_crash_pixes[thread_id])); |
64 |
| - fprintf(stderr, "<Cut here>\n"); |
65 |
| - pixWriteStreamPng(stderr, global_crash_pixes[thread_id], 0.0); |
66 |
| - fprintf(stderr, "\n<End cut>\n"); |
67 |
| - } |
68 |
| - // Raise an uncaught signal, so as to get a useful stack trace. |
69 |
| - raise(SIGILL); |
70 |
| -#else |
71 |
| - abort(); |
72 |
| -#endif |
73 |
| -} |
74 |
| - |
75 |
| -void err_exit() { |
76 |
| - ASSERT_HOST("Fatal error encountered!" == nullptr); |
77 |
| -} |
78 |
| - |
79 | 24 | // TODO: remove empty function?
|
80 | 25 | void set_global_loc_code(int loc_code) {
|
81 | 26 | // global_loc_code = loc_code;
|
|
0 commit comments