From 4cc04990b1ff8cfe1f3c0983457bccc6a4fca9a8 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Fri, 23 Mar 2012 00:40:14 -0700 Subject: [PATCH] add mozglue support for gonk (bug 738559, r=glandium) --- Makefile.in | 5 ++++ configure.in | 10 +++----- mozglue/Makefile.in | 4 +++ mozglue/build/Makefile.in | 7 ++++++ mozglue/gonk/GonkGlue.cpp | 53 +++++++++++++++++++++++++++++++++++++++ mozglue/gonk/Makefile.in | 29 +++++++++++++++++++++ 6 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 mozglue/gonk/GonkGlue.cpp create mode 100644 mozglue/gonk/Makefile.in diff --git a/Makefile.in b/Makefile.in index bc9007e2840..767a0bf2bd3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -72,6 +72,11 @@ tier_base_dirs += \ other-licenses/skia-npapi \ $(NULL) endif +ifeq (gonk,$(MOZ_WIDGET_TOOLKIT)) +tier_base_dirs += \ + other-licenses/android \ + $(NULL) +endif ifdef MOZ_MEMORY tier_base_dirs += memory/jemalloc diff --git a/configure.in b/configure.in index fa6642ec187..8847436f6ec 100644 --- a/configure.in +++ b/configure.in @@ -7235,13 +7235,11 @@ dnl We need to wrap dlopen and related functions on Android because we use dnl our own linker. if test "$OS_TARGET" = Android; then WRAP_LDFLAGS="${WRAP_LDFLAGS} -L$_objdir/dist/lib -lmozglue" - if test "$MOZ_WIDGET_TOOLKIT" = android; then - if test -n "$MOZ_OLD_LINKER"; then - WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=dlopen,--wrap=dlclose,--wrap=dlerror,--wrap=dlsym,--wrap=dladdr" - fi - WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=getaddrinfo,--wrap=freeaddrinfo,--wrap=gai_strerror" - WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork" + if test -n "$MOZ_OLD_LINKER"; then + WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=dlopen,--wrap=dlclose,--wrap=dlerror,--wrap=dlsym,--wrap=dladdr" fi + WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=getaddrinfo,--wrap=freeaddrinfo,--wrap=gai_strerror" + WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork" fi dnl ======================================================== diff --git a/mozglue/Makefile.in b/mozglue/Makefile.in index 81d95d4a3f2..e1b88095ecc 100644 --- a/mozglue/Makefile.in +++ b/mozglue/Makefile.in @@ -52,6 +52,10 @@ ifeq (android,$(MOZ_WIDGET_TOOLKIT)) DIRS += android endif +ifeq (gonk,$(MOZ_WIDGET_TOOLKIT)) +DIRS += gonk +endif + DIRS += build TEST_DIRS = tests diff --git a/mozglue/build/Makefile.in b/mozglue/build/Makefile.in index 21aef235bf6..847f0111881 100644 --- a/mozglue/build/Makefile.in +++ b/mozglue/build/Makefile.in @@ -92,6 +92,13 @@ SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,$(DEPTH)/other-license SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,../android) endif +ifeq (gonk, $(MOZ_WIDGET_TOOLKIT)) +# To properly wrap jemalloc's pthread_atfork call. +EXTRA_DSO_LDOPTS += -Wl,--wrap=pthread_atfork +SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,$(DEPTH)/other-licenses/android) +SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,gonk,../gonk) +endif + ifdef MOZ_LINKER # Add custom dynamic linker SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,linker,../linker) diff --git a/mozglue/gonk/GonkGlue.cpp b/mozglue/gonk/GonkGlue.cpp new file mode 100644 index 00000000000..434fd9fd63c --- /dev/null +++ b/mozglue/gonk/GonkGlue.cpp @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include + +#define NS_EXPORT __attribute__ ((visibility("default"))) + +/* Android doesn't have pthread_atfork(), so we need to use our own. */ +struct AtForkFuncs { + void (*prepare)(void); + void (*parent)(void); + void (*child)(void); +}; +static std::vector atfork; + +extern "C" NS_EXPORT int +__wrap_pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) +{ + AtForkFuncs funcs; + funcs.prepare = prepare; + funcs.parent = parent; + funcs.child = child; + atfork.push_back(funcs); + return 0; +} + +extern "C" NS_EXPORT pid_t +__wrap_fork(void) +{ + pid_t pid; + for (std::vector::reverse_iterator it = atfork.rbegin(); + it < atfork.rend(); ++it) + if (it->prepare) + it->prepare(); + + switch ((pid = fork())) { + case 0: + for (std::vector::iterator it = atfork.begin(); + it < atfork.end(); ++it) + if (it->child) + it->child(); + break; + default: + for (std::vector::iterator it = atfork.begin(); + it < atfork.end(); ++it) + if (it->parent) + it->parent(); + } + return pid; +} diff --git a/mozglue/gonk/Makefile.in b/mozglue/gonk/Makefile.in new file mode 100644 index 00000000000..3a6c8442241 --- /dev/null +++ b/mozglue/gonk/Makefile.in @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = gonk +LIBRARY_NAME = gonk +FORCE_STATIC_LIB = 1 +STL_FLAGS= + +DEFINES += \ + -DANDROID_PACKAGE_NAME='"$(ANDROID_PACKAGE_NAME)"' \ + $(NULL) + +CPPSRCS = \ + GonkGlue.cpp \ + $(NULL) + +LOCAL_INCLUDES += -I$(DEPTH)/build +LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build + +include $(topsrcdir)/config/rules.mk