summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAnestis Bechtsoudis <anestis@census-labs.com>2015-08-06 10:31:36 +0300
committerAnestis Bechtsoudis <anestis@census-labs.com>2015-08-06 10:31:36 +0300
commitcfc39fb203a5e14915dee874957487935554d23b (patch)
tree55377d578fdb32faea092ab84749238954b7996f /android
parentc1f6faa662c286db4e6908db202176130f6b1fb9 (diff)
downloadhonggfuzz-cfc39fb203a5e14915dee874957487935554d23b.tar.gz
Implement Android Linux PTRACE support
* Fork upstream libunwind and cross-compile with Android NDK * libunwind is also used for proc symbol resolve instead of bfd * Replace BDF lib with capstone for disassembling actions * Engineer build & patch scripts to support Android ARM, ARM64, x86, x86_64 * Rename linux/ptrace.* to linux/ptrace_utils.* since it conflicts with Android platform includes for ptrace API * Wrap register & instruction sizes under macros to reflect sizes for supported CPU arch (makes debugging easier) * Add / Implement missing definitions / functions for Android * Improve Android build process
Diffstat (limited to 'android')
-rw-r--r--android/Android.mk93
1 files changed, 89 insertions, 4 deletions
diff --git a/android/Android.mk b/android/Android.mk
index d1b60905..b11f09b7 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -14,18 +14,103 @@
# limitations under the License.
LOCAL_PATH := $(abspath $(call my-dir)/..)
+
+# Enable Linux ptrace inesead of POSIX by default
+ANDROID_WITH_PTRACE ?= true
+
+ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi armeabi-v7a))
+ ARCH_ABI := arm
+ UNW_ARCH := arm
+else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86))
+ ARCH_ABI := x86
+ UNW_ARCH := x86
+ # TODO: Remove this when x86 testing is completed
+ $(info $(APP_ABI) Android not fully tested yet (consider providing feedback if tested))
+else ifeq ($(APP_ABI),$(filter $(APP_ABI),arm64-v8a))
+ ARCH_ABI := arm64
+ UNW_ARCH := aarch64
+ # TODO: Remove this when arm64 testing is completed
+ $(info $(APP_ABI) Android not fully tested yet (consider providing feedback if tested))
+else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86_64))
+ ARCH_ABI := x86_64
+ UNW_ARCH := x86_64
+ $(error $(APP_ABI) Android not supported (issues with libunwind))
+else
+ # ndk-build will have already failed, so just in case
+ $(error Unknown APP_API '$(APP_ABI)')
+endif
+
+ifeq ($(ANDROID_WITH_PTRACE),true)
+ # Upstream libunwind compiled from sources with Android NDK toolchain
+ LIBUNWIND_A := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(UNW_ARCH).a
+ ifeq ("$(wildcard $(LIBUNWIND_A))","")
+ $(error libunwind-$(UNW_ARCH). is missing. Please execute \
+ 'third_party/android/scripts/compile-libunwind.sh third_party/android/libunwind $(ARCH_ABI)')
+ endif
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := libunwind
+ LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind.a
+ LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
+ include $(PREBUILT_STATIC_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := libunwind-arch
+ LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(UNW_ARCH).a
+ LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
+ include $(PREBUILT_STATIC_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := libunwind-ptrace
+ LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-ptrace.a
+ LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
+ include $(PREBUILT_STATIC_LIBRARY)
+
+ LOCAL_MODULE := libunwind-dwarf-generic
+ LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-dwarf-generic.a
+ LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
+ include $(PREBUILT_STATIC_LIBRARY)
+
+ # Upstream capstone compiled from sources with Android NDK toolchain
+ LIBCAPSTONE_A := third_party/android/capstone/$(ARCH_ABI)/libcapstone.a
+ ifeq ("$(wildcard $(LIBCAPSTONE_A))","")
+ $(error libunwind-$(UNW_ARCH). is missing. Please execute \
+ 'third_party/android/scripts/compile-capstone.sh third_party/android/capstone $(ARCH_ABI)')
+ endif
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := libcapstone
+ LOCAL_SRC_FILES := $(LIBCAPSTONE_A)
+ LOCAL_EXPORT_C_INCLUDES := third_party/android/capstone/include
+ include $(PREBUILT_STATIC_LIBRARY)
+endif
+
+# Main honggfuzz module
include $(CLEAR_VARS)
LOCAL_MODULE := honggfuzz
LOCAL_SRC_FILES := honggfuzz.c log.c files.c fuzz.c report.c mangle.c util.c
LOCAL_CFLAGS := -std=c11 -I. \
-D_GNU_SOURCE \
- -Wall -Wextra -Wno-initializer-overrides -Wno-override-init -Wno-unknown-warning-option -Werror \
- -funroll-loops -O2
+ -Wall -Wextra -Wno-initializer-overrides -Wno-override-init \
+ -Wno-unknown-warning-option -Werror -funroll-loops -O2
LOCAL_LDFLAGS := -lm
-ARCH_SRCS := $(wildcard posix/*.c)
-ARCH = POSIX
+ifeq ($(ANDROID_WITH_PTRACE),true)
+ LOCAL_C_INCLUDES := third_party/android/libunwind/include third_party/android/capstone/include
+ LOCAL_STATIC_LIBRARIES := libunwind libunwind-arch libunwind-ptrace libunwind-dwarf-generic libcapstone
+ LOCAL_CFLAGS += -D__HF_USE_CAPSTONE__
+ ARCH_SRCS := linux/arch.c linux/ptrace_utils.c linux/perf.c linux/unwind.c
+ ARCH := LINUX
+ $(info $(shell (echo "********************************************************************")))
+ $(info $(shell (echo "Android PTRACE build: Will prevent debuggerd from processing crashes")))
+ $(info $(shell (echo "********************************************************************")))
+else
+ ARCH_SRCS := posix/arch.c
+ ARCH := POSIX
+ $(info $(shell (echo "********************************************************************")))
+ $(info $(shell (echo "Android POSIX build: Will allow debuggerd to process crashes")))
+ $(info $(shell (echo "********************************************************************")))
+endif
LOCAL_SRC_FILES += $(ARCH_SRCS)
LOCAL_CFLAGS += -D_HF_ARCH_${ARCH}