From 0dfaaed890e7a4c707b6ea514758e42ac55574d6 Mon Sep 17 00:00:00 2001 From: Bernhard Rosenkraenzer Date: Thu, 22 Nov 2012 15:13:45 +0100 Subject: perf: Allow building for Android Signed-off-by: Bernhard Rosenkraenzer --- tools/perf/compat-android.h | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tools/perf/compat-android.h (limited to 'tools/perf/compat-android.h') diff --git a/tools/perf/compat-android.h b/tools/perf/compat-android.h new file mode 100644 index 000000000000..b8fb93679329 --- /dev/null +++ b/tools/perf/compat-android.h @@ -0,0 +1,106 @@ +/* Android compatibility header + * Provides missing bits in Bionic on Android, ignored + * on regular Linux. + * + * Written by Bernhard.Rosenkranzer@linaro.org + * + * Released into the public domain. Do with this file + * whatever you want. + */ +#ifdef ANDROID +/* Bionic has its own idea about ALIGN, and kills other definitions. + * Done outside the multiple-inclusion wrapper to make sure we + * can override Bionic's ALIGN by simply including compat-android.h + * again after including Bionic headers. + */ +#undef ALIGN +#undef __ALIGN_MASK +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) + +#ifndef _COMPAT_ANDROID_H_ +#define _COMPAT_ANDROID_H_ 1 +#include +#include +#include /* for PAGE_SIZE */ +#include /* for winsize */ + +#ifndef __WORDSIZE +#include +#define __WORDSIZE _BITSIZE +#endif + +#ifndef roundup +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#endif + +#ifndef __force +#define __force +#endif + +#ifndef __le32 +#define __le32 uint32_t +#endif + +/* Assorted functions that are missing from Bionic */ +/* Android prior to 4.2 lacks psignal(). + * What we're doing here is fairly evil - but necessary since + * Bionic doesn't export any version identifier or the likes. + * We do know that 4.2 is the version introducing psignal() and + * also KLOG_CONSOLE_OFF -- completely unrelated, but something + * we can check for... + */ +#include +#ifndef KLOG_CONSOLE_OFF +static void psignal(int sig, const char *s) +{ + if(sig >= 0 && sig < NSIG) { + if(s) + fprintf(stderr, "%s: %s\n", s, sys_siglist[sig]); + else + fprintf(stderr, "%s\n", sys_siglist[sig]); + } else { + if(s) + fprintf(stderr, "%s: invalid signal\n", s); + else + fputs("invalid signal\n", stderr); + } +} +#endif + +static ssize_t getline(char **lineptr, size_t *n, FILE *stream) +{ + size_t ret = 0; + + if (!lineptr || !n || !stream) + return -1; + + if(!*lineptr) { + *n = 128; + *lineptr = (char*)malloc(*n); + if(!*lineptr) + return -1; + } + + while(!feof(stream) && !ferror(stream)) { + int c; + if(ret == *n) { + *n += 128; + *lineptr = (char*)realloc(*lineptr, *n); + if(!*lineptr) { + *n = 0; + return -1; + } + } + c = fgetc(stream); + if(c == EOF) + break; + *lineptr[ret++] = c; + if(c == '\n') + break; + } + *lineptr[ret] = 0; + return ret; +} +#endif +#endif -- cgit v1.2.3 From 5ed310e9182a313eee6bf3268bc960719390527f Mon Sep 17 00:00:00 2001 From: Bernhard Rosenkraenzer Date: Fri, 7 Dec 2012 14:20:14 +0100 Subject: Fix perf build on Android again The kernel header shuffling in recent builds broke building perf again -- add workarounds. Signed-off-by: Bernhard Rosenkraenzer --- tools/perf/compat-android.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tools/perf/compat-android.h') diff --git a/tools/perf/compat-android.h b/tools/perf/compat-android.h index b8fb93679329..fce9573d257b 100644 --- a/tools/perf/compat-android.h +++ b/tools/perf/compat-android.h @@ -20,13 +20,35 @@ #ifndef _COMPAT_ANDROID_H_ #define _COMPAT_ANDROID_H_ 1 +/* Stuff Bionic assumes to be present, but that doesn't exist + * anymore after the uabi kernel header reorg + */ +#include +#include +typedef unsigned short __kernel_nlink_t; +typedef intptr_t phys_addr_t; +#include +typedef uint32_t u32; +typedef uint64_t u64; +#ifndef CONFIG_DRAM_BASEUL +#ifdef CONFIG_DRAM_BASE +#define CONFIG_DRAM_BASEUL UL(CONFIG_DRAM_BASE) +#else +#define CONFIG_DRAM_BASEUL 0 +#endif +#endif +#define __deprecated +#include + +#undef BITS_PER_LONG /* Something seems to define this incorrectly */ +#define BITS_PER_LONG _BITSIZE + #include #include #include /* for PAGE_SIZE */ #include /* for winsize */ #ifndef __WORDSIZE -#include #define __WORDSIZE _BITSIZE #endif @@ -42,6 +64,11 @@ #define __le32 uint32_t #endif +#ifndef FD_SET +#define FD_SET(fd, fdsetp) (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] |= (1<<((fd) & 31))) +#define FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof (*(fd_set *)(fdsetp)))) +#endif + /* Assorted functions that are missing from Bionic */ /* Android prior to 4.2 lacks psignal(). * What we're doing here is fairly evil - but necessary since -- cgit v1.2.3 From 6b1eb436faf028476752bf4ecd68bf85044db59f Mon Sep 17 00:00:00 2001 From: Bernhard Rosenkraenzer Date: Fri, 21 Dec 2012 18:20:15 +0400 Subject: perf: get rid of the include The include seems to cause trouble in some arm64 configs. Also make libtraceevent to see Bionic -isystem flags passed to us. Signed-off-by: Bernhard Rosenkraenzer --- tools/perf/compat-android.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/compat-android.h') diff --git a/tools/perf/compat-android.h b/tools/perf/compat-android.h index fce9573d257b..b76adae27738 100644 --- a/tools/perf/compat-android.h +++ b/tools/perf/compat-android.h @@ -38,8 +38,8 @@ typedef uint64_t u64; #endif #endif #define __deprecated -#include +#include #undef BITS_PER_LONG /* Something seems to define this incorrectly */ #define BITS_PER_LONG _BITSIZE -- cgit v1.2.3