3 #include <asm/ptrace.h>
5 #include <lib/base/eerror.h>
6 #include <lib/base/smartptr.h>
7 #include <lib/gdi/grc.h>
8 #include <lib/gdi/gfbdc.h>
10 /************************************************/
12 #define CRASH_EMAILADDR "crashlog@dream-multimedia-tv.de"
14 #define RINGBUFFER_SIZE 16384
15 static char ringbuffer[RINGBUFFER_SIZE];
16 static int ringbuffer_head;
18 static void addToLogbuffer(const char *data, int len)
22 int remaining = RINGBUFFER_SIZE - ringbuffer_head;
27 memcpy(ringbuffer + ringbuffer_head, data, remaining);
30 ringbuffer_head += remaining;
31 if (ringbuffer_head >= RINGBUFFER_SIZE)
36 static std::string getLogBuffer()
38 int begin = ringbuffer_head;
39 while (ringbuffer[begin] == 0)
42 if (begin == RINGBUFFER_SIZE)
44 if (begin == ringbuffer_head)
47 if (begin < ringbuffer_head)
48 return std::string(ringbuffer + begin, ringbuffer_head - begin);
51 return std::string(ringbuffer + begin, RINGBUFFER_SIZE - begin) + std::string(ringbuffer, ringbuffer_head);
55 static void addToLogbuffer(int level, const std::string &log)
57 addToLogbuffer(log.c_str(), log.size());
61 extern std::string getLogBuffer();
66 sprintf(logfile, "/media/hdd/enigma2_crash_%u.log", (unsigned int)time(0));
67 FILE *f = fopen(logfile, "wb");
69 std::string lines = getLogBuffer();
74 fprintf(f, "enigma2 crashed on %s", ctime(&t));
75 fprintf(f, "please email this file to " CRASH_EMAILADDR "\n");
76 std::string buffer = getLogBuffer();
77 fwrite(buffer.c_str(), buffer.size(), 1, f);
82 gFBDC::getInstance(my_dc);
86 p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
87 p.setBackgroundColor(gRGB(0x0000C0));
88 p.setForegroundColor(gRGB(0xFFFFFF));
90 ePtr<gFont> font = new gFont("Regular", 20);
94 eRect usable_area = eRect(100, 70, my_dc->size().width() - 200, 100);
96 p.renderText(usable_area,
97 "We are really sorry. Something happened "
98 "which should not have happened, and "
99 "resulted in a crash. If you want to help "
100 "us in improving this situation, please send "
101 "the logfile created in /hdd/ to " CRASH_EMAILADDR ".", gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);
103 usable_area = eRect(100, 170, my_dc->size().width() - 200, my_dc->size().height() - 20);
107 size_t start = std::string::npos + 1;
110 start = lines.rfind('\n', start - 1);
111 if (start == std::string::npos)
118 font = new gFont("Regular", 14);
121 p.renderText(usable_area,
122 lines.substr(start), gPainter::RT_HALIGN_LEFT);
128 #if defined(__MIPSEL__)
129 void oops(const mcontext_t &context, int dumpcode)
131 eDebug("PC: %08lx, vaddr: %08lx", (unsigned long)context.pc, (unsigned long)context.badvaddr);
134 #warning "no oops support!"
136 #define NO_OOPS_SUPPORT
139 void handleFatalSignal(int signum, siginfo_t *si, void *ctx)
141 ucontext_t *uc = (ucontext_t*)ctx;
142 eDebug("KILLED BY signal %d", signum);
143 #ifndef NO_OOPS_SUPPORT
144 oops(uc->uc_mcontext, signum == SIGSEGV);
150 void bsodCatchSignals()
152 struct sigaction act;
153 act.sa_handler = SIG_DFL;
154 act.sa_sigaction = handleFatalSignal;
156 if (sigemptyset(&act.sa_mask) == -1)
157 perror("sigemptyset");
159 /* start handling segfaults etc. */
160 sigaction(SIGSEGV, &act, 0);
161 sigaction(SIGILL, &act, 0);
162 sigaction(SIGBUS, &act, 0);
167 logOutput.connect(addToLogbuffer);