1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include <stdio.h>
8 :
9 : #include "native_client/src/include/nacl_macros.h"
10 : #include "native_client/src/shared/platform/nacl_exit.h"
11 : #include "native_client/src/shared/platform/nacl_log.h"
12 : #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h"
13 : #include "native_client/src/trusted/service_runtime/nacl_error_gio.h"
14 :
15 : struct NaClApp;
16 :
17 : static struct NaClErrorGio g_NaCl_log_gio;
18 : static void (*g_NaCl_log_abort_fn)(void *state,
19 : char *buf, size_t buf_bytes) = NULL;
20 : static void *g_NaCl_log_abort_state = NULL;
21 :
22 : static void NaClReportLogMessages(void) {
23 5 : char log_data[NACL_ERROR_GIO_MAX_BYTES];
24 5 : size_t log_data_bytes;
25 :
26 5 : if (NULL != g_NaCl_log_abort_fn) {
27 : /*
28 : * Copy the last NACL_ERROR_GIO_MAX_BYTES of log output to the
29 : * calling thread's stack, so that breakpad will pick it up.
30 : */
31 5 : log_data_bytes = NaClErrorGioGetOutput(&g_NaCl_log_gio,
32 : log_data,
33 : NACL_ARRAY_SIZE(log_data));
34 5 : (*g_NaCl_log_abort_fn)(g_NaCl_log_abort_state,
35 : log_data, log_data_bytes);
36 5 : }
37 5 : NaClAbort();
38 5 : }
39 :
40 266 : void NaClErrorLogHookInit(void (*hook)(void *state,
41 : char *buf,
42 : size_t buf_bytes),
43 266 : void *state) {
44 266 : NaClLog(2, "NaClErrorLogHookInit: entered\n");
45 266 : if (!NaClErrorGioCtor(&g_NaCl_log_gio, NaClLogGetGio())) {
46 0 : fprintf(stderr, "sel_main_chrome: log reporting setup failed\n");
47 0 : NaClAbort();
48 0 : }
49 :
50 266 : g_NaCl_log_abort_fn = hook;
51 266 : g_NaCl_log_abort_state = state;
52 :
53 266 : NaClLogSetGio((struct Gio *) &g_NaCl_log_gio);
54 :
55 266 : NaClLogSetAbortBehavior(NaClReportLogMessages);
56 266 : }
|