Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78da39fa authored by Bernhard Rosenkraenzer's avatar Bernhard Rosenkraenzer Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Add on_exit implementation

on_exit() is only available in new versions of glibc.
It is not implemented in Bionic and will lead to linking errors when
compiling for Android.

Implement a wrapper for on_exit using atexit.

The implementation for on_exit is the one sent by Bernhard Rosenkraenzer in
https://lkml.org/lkml/2012/8/23/316

. The configuration part from the Makefile
is different than the one from the original patch.

Signed-off-by: default avatarBernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
Signed-off-by: default avatarIrina Tirdea <irina.tirdea@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Irina Tirdea <irina.tirdea@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1349678613-7045-2-git-send-email-irina.tirdea@gmail.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 355afe81
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -753,6 +753,12 @@ ifndef NO_STRLCPY
	endif
endif

ifndef NO_ON_EXIT
	ifeq ($(call try-cc,$(SOURCE_ON_EXIT),),y)
		BASIC_CFLAGS += -DHAVE_ON_EXIT
	endif
endif

ifndef NO_BACKTRACE
       ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y)
               BASIC_CFLAGS += -DBACKTRACE_SUPPORT
+32 −0
Original line number Diff line number Diff line
@@ -31,6 +31,38 @@
#include <sched.h>
#include <sys/mman.h>

#ifndef HAVE_ON_EXIT
#ifndef ATEXIT_MAX
#define ATEXIT_MAX 32
#endif
static int __on_exit_count = 0;
typedef void (*on_exit_func_t) (int, void *);
static on_exit_func_t __on_exit_funcs[ATEXIT_MAX];
static void *__on_exit_args[ATEXIT_MAX];
static int __exitcode = 0;
static void __handle_on_exit_funcs(void);
static int on_exit(on_exit_func_t function, void *arg);
#define exit(x) (exit)(__exitcode = (x))

static int on_exit(on_exit_func_t function, void *arg)
{
	if (__on_exit_count == ATEXIT_MAX)
		return -ENOMEM;
	else if (__on_exit_count == 0)
		atexit(__handle_on_exit_funcs);
	__on_exit_funcs[__on_exit_count] = function;
	__on_exit_args[__on_exit_count++] = arg;
	return 0;
}

static void __handle_on_exit_funcs(void)
{
	int i;
	for (i = 0; i < __on_exit_count; i++)
		__on_exit_funcs[i] (__exitcode, __on_exit_args[i]);
}
#endif

enum write_mode_t {
	WRITE_FORCE,
	WRITE_APPEND
+10 −1
Original line number Diff line number Diff line
@@ -204,3 +204,12 @@ int main(void)
}
endef
endif

define SOURCE_ON_EXIT
#include <stdio.h>

int main(void)
{
	return on_exit(NULL, NULL);
}
endef