summaryrefslogtreecommitdiffstats
path: root/chrome/nacl
diff options
context:
space:
mode:
authorbsy@google.com <bsy@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 02:33:01 +0000
committerbsy@google.com <bsy@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 02:33:01 +0000
commit0254e732d24ffff09130277ece0f89b56ca1aaca (patch)
treed89901181d4b9a4c6d639f94cc7f8c964d810e0e /chrome/nacl
parent9d6828bb5af876b28346c49a0bf0c9b3e0e05661 (diff)
downloadchromium_src-0254e732d24ffff09130277ece0f89b56ca1aaca.zip
chromium_src-0254e732d24ffff09130277ece0f89b56ca1aaca.tar.gz
chromium_src-0254e732d24ffff09130277ece0f89b56ca1aaca.tar.bz2
Set up NaClChromeMainArgs number_of_cores member so apps can size threadpools
appropriately The outer sandbox on Linux and OSX was preventing sysconf(_SC_NPROCESSORS_ONLN) from succeeding, so that NaCl applications that need the number of processors/cores to, e.g., figure out the appropriate size for threadpools were getting a bogus value (-1 when using newlib and 1 when using glibc). This is a reland of r195198 (https://chromiumcodereview.appspot.com/14238013) which was reverted because of a test failure on an XP bot. Having built (on Win7) and moved the filesystem to an XP laptop to verify that no test failure occurs, and bradn having helped to verify on a bot (VM configured similarly to chrome's build waterfall bots), we suspect that the original test failure was a bot issue (test timed out!). TEST= browser_tests --gtest_filter=*ysconf* BUG= 176522 Review URL: https://chromiumcodereview.appspot.com/16047003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204389 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/nacl')
-rw-r--r--chrome/nacl/nacl_helper_linux.cc12
-rw-r--r--chrome/nacl/nacl_listener.cc8
-rw-r--r--chrome/nacl/nacl_listener.h13
-rw-r--r--chrome/nacl/nacl_main.cc9
4 files changed, 38 insertions, 4 deletions
diff --git a/chrome/nacl/nacl_helper_linux.cc b/chrome/nacl/nacl_helper_linux.cc
index f8f32c4..5c56285 100644
--- a/chrome/nacl/nacl_helper_linux.cc
+++ b/chrome/nacl/nacl_helper_linux.cc
@@ -40,7 +40,8 @@ namespace {
// if (!child) {
// Note: this code doesn't attempt to support the SECCOMP sandbox.
void BecomeNaClLoader(const std::vector<int>& child_fds,
- size_t prereserved_sandbox_size) {
+ size_t prereserved_sandbox_size,
+ int number_of_cores) {
VLOG(1) << "NaCl loader: setting up IPC descriptor";
// don't need zygote FD any more
if (HANDLE_EINTR(close(kNaClZygoteDescriptor)) != 0)
@@ -51,6 +52,7 @@ void BecomeNaClLoader(const std::vector<int>& child_fds,
base::MessageLoopForIO main_message_loop;
NaClListener listener;
listener.set_prereserved_sandbox_size(prereserved_sandbox_size);
+ listener.set_number_of_cores(number_of_cores);
listener.Listen();
_exit(0);
}
@@ -58,7 +60,8 @@ void BecomeNaClLoader(const std::vector<int>& child_fds,
// Some of this code was lifted from
// content/browser/zygote_main_linux.cc:ForkWithRealPid()
void HandleForkRequest(const std::vector<int>& child_fds,
- size_t prereserved_sandbox_size) {
+ size_t prereserved_sandbox_size,
+ int number_of_cores) {
VLOG(1) << "nacl_helper: forking";
pid_t childpid = fork();
if (childpid < 0) {
@@ -96,7 +99,7 @@ void HandleForkRequest(const std::vector<int>& child_fds,
if (HANDLE_EINTR(close(child_fds[kNaClParentFDIndex])) != 0)
LOG(ERROR) << "close(child_fds[kNaClParentFDIndex]) failed";
if (validack) {
- BecomeNaClLoader(child_fds, prereserved_sandbox_size);
+ BecomeNaClLoader(child_fds, prereserved_sandbox_size, number_of_cores);
} else {
LOG(ERROR) << "Failed to synch with zygote";
}
@@ -234,6 +237,7 @@ int main(int argc, char* argv[]) {
#endif
std::vector<int> empty; // for SendMsg() calls
size_t prereserved_sandbox_size = CheckReservedAtZero();
+ int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN);
CheckRDebug(argv[0]);
@@ -270,7 +274,7 @@ int main(int argc, char* argv[]) {
} else if (msglen == sizeof(kNaClForkRequest) - 1 &&
memcmp(buf, kNaClForkRequest, msglen) == 0) {
if (kNaClParentFDIndex + 1 == fds.size()) {
- HandleForkRequest(fds, prereserved_sandbox_size);
+ HandleForkRequest(fds, prereserved_sandbox_size, number_of_cores);
continue; // fork succeeded. Note: child does not return
} else {
LOG(ERROR) << "nacl_helper: unexpected number of fds, got "
diff --git a/chrome/nacl/nacl_listener.cc b/chrome/nacl/nacl_listener.cc
index e771496..ac03a31 100644
--- a/chrome/nacl/nacl_listener.cc
+++ b/chrome/nacl/nacl_listener.cc
@@ -7,6 +7,10 @@
#include <errno.h>
#include <stdlib.h>
+#if defined(OS_POSIX)
+#include <unistd.h>
+#endif
+
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -174,6 +178,9 @@ NaClListener::NaClListener() : shutdown_event_(true, false),
#if defined(OS_LINUX)
prereserved_sandbox_size_(0),
#endif
+#if defined(OS_POSIX)
+ number_of_cores_(-1), // unknown/error
+#endif
main_loop_(NULL) {
io_thread_.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
@@ -260,6 +267,7 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) {
LOG(ERROR) << "Failed to dup() the urandom FD";
return;
}
+ args->number_of_cores = number_of_cores_;
args->create_memory_object_func = CreateMemoryObject;
# if defined(OS_MACOSX)
CHECK(handles.size() >= 1);
diff --git a/chrome/nacl/nacl_listener.h b/chrome/nacl/nacl_listener.h
index 2936eee..a6cec25 100644
--- a/chrome/nacl/nacl_listener.h
+++ b/chrome/nacl/nacl_listener.h
@@ -34,6 +34,11 @@ class NaClListener : public IPC::Listener {
prereserved_sandbox_size_ = prereserved_sandbox_size;
}
#endif
+#if defined(OS_POSIX)
+ void set_number_of_cores(int number_of_cores) {
+ number_of_cores_ = number_of_cores;
+ }
+#endif
private:
void OnStart(const nacl::NaClStartParams& params);
@@ -51,6 +56,14 @@ class NaClListener : public IPC::Listener {
#if defined(OS_LINUX)
size_t prereserved_sandbox_size_;
#endif
+#if defined(OS_POSIX)
+ // The outer sandbox on Linux and OSX prevents
+ // sysconf(_SC_NPROCESSORS) from working; in Windows, there are no
+ // problems with invoking GetSystemInfo. Therefore, only in
+ // OS_POSIX do we need to supply the number of cores into the
+ // NaClChromeMainArgs object.
+ int number_of_cores_;
+#endif
// Used to identify what thread we're on.
base::MessageLoop* main_loop_;
diff --git a/chrome/nacl/nacl_main.cc b/chrome/nacl/nacl_main.cc
index fa4835e..112a9c4 100644
--- a/chrome/nacl/nacl_main.cc
+++ b/chrome/nacl/nacl_main.cc
@@ -33,6 +33,12 @@ int NaClMain(const content::MainFunctionParams& parameters) {
bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox);
platform.InitSandboxTests(no_sandbox);
+#if defined(OS_POSIX)
+ // The number of cores must be obtained before the invocation of
+ // platform.EnableSandbox(), so cannot simply be inlined below.
+ int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+
if (!no_sandbox) {
platform.EnableSandbox();
}
@@ -40,6 +46,9 @@ int NaClMain(const content::MainFunctionParams& parameters) {
if (sandbox_test_result) {
NaClListener listener;
+#if defined(OS_POSIX)
+ listener.set_number_of_cores(number_of_cores);
+#endif
listener.Listen();
} else {
// This indirectly prevents the test-harness-success-cookie from being set,