зеркало из https://github.com/mozilla/gecko-dev.git
Bug 799805 - Avoid using bionic's fork(), r=cjones a=blocking-basecamp
This commit is contained in:
Родитель
737506938c
Коммит
9f640e7eb3
|
@ -7140,7 +7140,10 @@ if test "$OS_TARGET" = Android; 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,--wrap=raise,--wrap=PR_GetEnv,--wrap=PR_SetEnv"
|
||||
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl--wrap=PR_GetEnv,--wrap=PR_SetEnv"
|
||||
if test -z "$gonkdir"; then
|
||||
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork,--wrap=raise"
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -19,8 +22,25 @@ struct AtForkFuncs {
|
|||
};
|
||||
static std::vector<AtForkFuncs> atfork;
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "cpuacct.h"
|
||||
#define WRAP(x) x
|
||||
|
||||
extern "C" NS_EXPORT int
|
||||
__wrap_pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
|
||||
timer_create(clockid_t, struct sigevent*, timer_t*)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR, "BionicGlue", "timer_create not supported!");
|
||||
abort();
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else
|
||||
#define cpuacct_add(x)
|
||||
#define WRAP(x) __wrap_##x
|
||||
#endif
|
||||
|
||||
extern "C" NS_EXPORT int
|
||||
WRAP(pthread_atfork)(void (*prepare)(void), void (*parent)(void), void (*child)(void))
|
||||
{
|
||||
AtForkFuncs funcs;
|
||||
funcs.prepare = prepare;
|
||||
|
@ -30,8 +50,10 @@ __wrap_pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" pid_t __fork(void);
|
||||
|
||||
extern "C" NS_EXPORT pid_t
|
||||
__wrap_fork(void)
|
||||
WRAP(fork)(void)
|
||||
{
|
||||
pid_t pid;
|
||||
for (std::vector<AtForkFuncs>::reverse_iterator it = atfork.rbegin();
|
||||
|
@ -39,8 +61,9 @@ __wrap_fork(void)
|
|||
if (it->prepare)
|
||||
it->prepare();
|
||||
|
||||
switch ((pid = fork())) {
|
||||
switch ((pid = __fork())) {
|
||||
case 0:
|
||||
cpuacct_add(getuid());
|
||||
for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
|
||||
it < atfork.end(); ++it)
|
||||
if (it->child)
|
||||
|
@ -56,7 +79,7 @@ __wrap_fork(void)
|
|||
}
|
||||
|
||||
extern "C" NS_EXPORT int
|
||||
__wrap_raise(int sig)
|
||||
WRAP(raise)(int sig)
|
||||
{
|
||||
return pthread_kill(pthread_self(), sig);
|
||||
}
|
||||
|
|
|
@ -61,8 +61,6 @@ EXTRA_DSO_LDOPTS += $(MOZ_ZLIB_LIBS)
|
|||
endif
|
||||
|
||||
ifeq (Android,$(OS_TARGET))
|
||||
# To properly wrap jemalloc's pthread_atfork call.
|
||||
EXTRA_DSO_LDOPTS += -Wl,--wrap=pthread_atfork
|
||||
CPPSRCS += BionicGlue.cpp
|
||||
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,$(DEPTH)/other-licenses/android)
|
||||
endif
|
||||
|
@ -71,6 +69,12 @@ ifeq (android, $(MOZ_WIDGET_TOOLKIT))
|
|||
# Add Android specific code
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_ZLIB_LIBS)
|
||||
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,../android)
|
||||
# To properly wrap jemalloc's pthread_atfork call.
|
||||
EXTRA_DSO_LDOPTS += -Wl,--wrap=pthread_atfork
|
||||
endif
|
||||
|
||||
ifeq (gonk, $(MOZ_WIDGET_TOOLKIT))
|
||||
CSRCS += cpuacct.c
|
||||
endif
|
||||
|
||||
ifdef MOZ_LINKER
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "cpuacct.h"
|
||||
|
||||
int cpuacct_add(uid_t uid)
|
||||
{
|
||||
int count;
|
||||
int fd;
|
||||
char buf[80];
|
||||
|
||||
count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid);
|
||||
fd = open(buf, O_RDWR|O_CREAT|O_TRUNC|O_SYNC);
|
||||
if (fd < 0) {
|
||||
/* Note: sizeof("tasks") returns 6, which includes the NULL char */
|
||||
buf[count - sizeof("tasks")] = 0;
|
||||
if (mkdir(buf, 0775) < 0)
|
||||
return -errno;
|
||||
|
||||
/* Note: sizeof("tasks") returns 6, which includes the NULL char */
|
||||
buf[count - sizeof("tasks")] = '/';
|
||||
fd = open(buf, O_RDWR|O_CREAT|O_TRUNC|O_SYNC);
|
||||
}
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
write(fd, "0", 2);
|
||||
if (close(fd))
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BIONIC_CPUACCT_H
|
||||
#define _BIONIC_CPUACCT_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern int cpuacct_add(uid_t uid);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _BIONIC_CPUACCT_H */
|
Загрузка…
Ссылка в новой задаче