mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
Move ABRThandler func out of internal lib
This commit is contained in:
@ -16,10 +16,6 @@
|
|||||||
#include <stdlib.h> /* malloc, calloc, free */
|
#include <stdlib.h> /* malloc, calloc, free */
|
||||||
#include <string.h> /* memset */
|
#include <string.h> /* memset */
|
||||||
#include <stdio.h> /* fprintf(), stderr */
|
#include <stdio.h> /* fprintf(), stderr */
|
||||||
#include <signal.h> /* signal() */
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <execinfo.h> /* backtrace, backtrace_symbols, symbollist */
|
|
||||||
#endif
|
|
||||||
#include "error_private.h"
|
#include "error_private.h"
|
||||||
#include "zstd_internal.h"
|
#include "zstd_internal.h"
|
||||||
|
|
||||||
@ -90,64 +86,3 @@ void ZSTD_free(void* ptr, ZSTD_customMem customMem)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-*********************************************************
|
|
||||||
* Termination signal trapping (Print debug stack trace)
|
|
||||||
***********************************************************/
|
|
||||||
#define MAX_STACK_FRAMES 50
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#define START_STACK_FRAME 2
|
|
||||||
#elif defined __APPLE__
|
|
||||||
#define START_STACK_FRAME 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void ABRThandler(int sig)
|
|
||||||
{
|
|
||||||
const char* name;
|
|
||||||
void* addrlist[MAX_STACK_FRAMES + 1];
|
|
||||||
char** symbollist;
|
|
||||||
U32 addrlen, i;
|
|
||||||
|
|
||||||
switch (sig) {
|
|
||||||
case SIGABRT: name = "SIGABRT"; break;
|
|
||||||
case SIGFPE: name = "SIGFPE"; break;
|
|
||||||
case SIGILL: name = "SIGILL"; break;
|
|
||||||
case SIGINT: name = "SIGINT"; break;
|
|
||||||
case SIGSEGV: name = "SIGSEGV"; break;
|
|
||||||
default: name = "UNKNOWN"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
DISPLAY("Caught %s signal, printing stack:\n", name);
|
|
||||||
// Retrieve current stack addresses.
|
|
||||||
addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
|
|
||||||
if (addrlen == 0) {
|
|
||||||
DISPLAY("\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Create readable strings to each frame.
|
|
||||||
symbollist = backtrace_symbols(addrlist, addrlen);
|
|
||||||
// Print the stack trace, excluding calls handling the signal.
|
|
||||||
for (i = START_STACK_FRAME; i < addrlen; i++) {
|
|
||||||
DISPLAY("%s\n", symbollist[i]);
|
|
||||||
}
|
|
||||||
free(symbollist);
|
|
||||||
// Reset and raise the signal so default handler runs.
|
|
||||||
signal(sig, SIG_DFL);
|
|
||||||
raise(sig);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ZSTD_addAbortHandler()
|
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
|
||||||
signal(SIGABRT, ABRThandler);
|
|
||||||
signal(SIGFPE, ABRThandler);
|
|
||||||
signal(SIGILL, ABRThandler);
|
|
||||||
signal(SIGSEGV, ABRThandler);
|
|
||||||
signal(SIGBUS, ABRThandler);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
@ -206,9 +206,6 @@ void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
|
|||||||
void* ZSTD_calloc(size_t size, ZSTD_customMem customMem);
|
void* ZSTD_calloc(size_t size, ZSTD_customMem customMem);
|
||||||
void ZSTD_free(void* ptr, ZSTD_customMem customMem);
|
void ZSTD_free(void* ptr, ZSTD_customMem customMem);
|
||||||
|
|
||||||
/* custom crash signal handler */
|
|
||||||
void ZSTD_addAbortHandler(void);
|
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
||||||
{
|
{
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
#include <stdlib.h> /* malloc, free */
|
#include <stdlib.h> /* malloc, free */
|
||||||
#include <string.h> /* strcmp, strlen */
|
#include <string.h> /* strcmp, strlen */
|
||||||
#include <errno.h> /* errno */
|
#include <errno.h> /* errno */
|
||||||
|
#include <signal.h>
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <execinfo.h> /* backtrace, backtrace_symbols */
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined (_MSC_VER)
|
#if defined (_MSC_VER)
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
@ -124,8 +128,6 @@ static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER;
|
|||||||
/*-************************************
|
/*-************************************
|
||||||
* Signal (Ctrl-C trapping)
|
* Signal (Ctrl-C trapping)
|
||||||
**************************************/
|
**************************************/
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
static const char* g_artefact = NULL;
|
static const char* g_artefact = NULL;
|
||||||
static void INThandler(int sig)
|
static void INThandler(int sig)
|
||||||
{
|
{
|
||||||
@ -157,6 +159,59 @@ static void clearHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-*********************************************************
|
||||||
|
* Termination signal trapping (Print debug stack trace)
|
||||||
|
***********************************************************/
|
||||||
|
#define MAX_STACK_FRAMES 50
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
static void ABRThandler(int sig) {
|
||||||
|
const char* name;
|
||||||
|
void* addrlist[MAX_STACK_FRAMES + 1];
|
||||||
|
char** symbollist;
|
||||||
|
U32 addrlen, i;
|
||||||
|
|
||||||
|
switch (sig) {
|
||||||
|
case SIGABRT: name = "SIGABRT"; break;
|
||||||
|
case SIGFPE: name = "SIGFPE"; break;
|
||||||
|
case SIGILL: name = "SIGILL"; break;
|
||||||
|
case SIGINT: name = "SIGINT"; break;
|
||||||
|
case SIGSEGV: name = "SIGSEGV"; break;
|
||||||
|
default: name = "UNKNOWN";
|
||||||
|
}
|
||||||
|
|
||||||
|
DISPLAY("Caught %s signal, printing stack:\n", name);
|
||||||
|
// Retrieve current stack addresses.
|
||||||
|
addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
|
||||||
|
if (addrlen == 0) {
|
||||||
|
DISPLAY("\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Create readable strings to each frame.
|
||||||
|
symbollist = backtrace_symbols(addrlist, addrlen);
|
||||||
|
// Print the stack trace, excluding calls handling the signal.
|
||||||
|
for (i = ZSTD_START_SYMBOLLIST_FRAME; i < addrlen; i++) {
|
||||||
|
DISPLAY("%s\n", symbollist[i]);
|
||||||
|
}
|
||||||
|
free(symbollist);
|
||||||
|
// Reset and raise the signal so default handler runs.
|
||||||
|
signal(sig, SIG_DFL);
|
||||||
|
raise(sig);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void FIO_addAbortHandler()
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
signal(SIGABRT, ABRThandler);
|
||||||
|
signal(SIGFPE, ABRThandler);
|
||||||
|
signal(SIGILL, ABRThandler);
|
||||||
|
signal(SIGSEGV, ABRThandler);
|
||||||
|
signal(SIGBUS, ABRThandler);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-************************************************************
|
/*-************************************************************
|
||||||
* Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW
|
* Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
@ -95,6 +95,9 @@ int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles
|
|||||||
const char* dictFileName);
|
const char* dictFileName);
|
||||||
|
|
||||||
|
|
||||||
|
/* custom crash signal handler */
|
||||||
|
void FIO_addAbortHandler(void);
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -148,6 +148,17 @@ static __inline int IS_CONSOLE(FILE* stdStream) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ZSTD_START_SYMBOLLIST_FRAME
|
||||||
|
# ifdef __linux__
|
||||||
|
# define ZSTD_START_SYMBOLLIST_FRAME 2
|
||||||
|
# elif defined __APPLE__
|
||||||
|
# define ZSTD_START_SYMBOLLIST_FRAME 4
|
||||||
|
# else
|
||||||
|
# define ZSTD_START_SYMBOLLIST_FRAME 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */
|
||||||
#include "zstd.h" /* ZSTD_VERSION_STRING */
|
#include "zstd.h" /* ZSTD_VERSION_STRING */
|
||||||
#include "zstd_internal.h" /* ZSTD_addAbortHandler */
|
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
/*-************************************
|
||||||
|
Reference in New Issue
Block a user