Skip to content

Commit

Permalink
Linux Sandbox: get everything to compile on Android.
Browse files Browse the repository at this point in the history
We define our own android_arm_ucontext.h file since
signal.h doesn't define ucontext_t on Android.

BUG=166704
NOTRY=true


Review URL: https://chromiumcodereview.appspot.com/11618010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174070 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jln@chromium.org committed Dec 20, 2012
1 parent 082261b commit 1bf4155
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
11 changes: 5 additions & 6 deletions sandbox/linux/sandbox_linux.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
['OS == "android"', {
'sources/': [
['include', '^linux/'],
# TODO(jln): some files don't yet even compile on Android.
# crbug.com/166704
['exclude', 'errorcode_unittest\\.cc$'],
['exclude', 'sandbox_bpf\\.cc$'],
['exclude', 'sandbox_bpf_unittest\\.cc$'],
['exclude', 'syscall_unittest\\.cc$'],
],
}],
],
Expand Down Expand Up @@ -101,6 +95,11 @@
'seccomp-bpf/syscall_unittest.cc',
],
}],
['OS == "android" and gtest_target_type == "shared_library"', {
'dependencies': [
'../testing/android/native_test.gyp:native_test_native_code',
]
}],
],
},
{
Expand Down
12 changes: 11 additions & 1 deletion sandbox/linux/seccomp-bpf/sandbox_bpf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <signal.h>
#include <sys/prctl.h>
#include <sys/syscall.h>

#ifndef SECCOMP_BPF_STANDALONE
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
Expand All @@ -13,6 +17,11 @@
#include "sandbox/linux/seccomp-bpf/syscall_iterator.h"
#include "sandbox/linux/seccomp-bpf/verifier.h"

// Android's signal.h doesn't define ucontext etc.
#if defined(OS_ANDROID) && defined(__arm__)
#include "sandbox/linux/services/android_arm_ucontext.h"
#endif

namespace {

void WriteFailedStderrSetupMessage(int out_fd) {
Expand Down Expand Up @@ -40,7 +49,8 @@ void WriteFailedStderrSetupMessage(int out_fd) {
// way to mark a signal as allocated. So, the potential for collision is
// possibly even worse.
bool GetIsInSigHandler(const ucontext_t *ctx) {
return sigismember(&ctx->uc_sigmask, SIGBUS);
// Note: on Android, sigismember does not take a pointer to const.
return sigismember(const_cast<sigset_t*>(&ctx->uc_sigmask), SIGBUS);
}

void SetIsInSigHandler() {
Expand Down
4 changes: 4 additions & 0 deletions sandbox/linux/seccomp-bpf/sandbox_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
#endif

// For prctl.h
#ifndef PR_SET_SECCOMP
#define PR_SET_SECCOMP 22
#define PR_GET_SECCOMP 21
#endif
#ifndef PR_SET_NO_NEW_PRIVS
#define PR_SET_NO_NEW_PRIVS 38
#define PR_GET_NO_NEW_PRIVS 39
Expand Down
6 changes: 6 additions & 0 deletions sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include "sandbox/linux/services/linux_syscalls.h"
#include "testing/gtest/include/gtest/gtest.h"

// Workaround for Android's prctl.h file.
#if !defined(PR_CAPBSET_READ)
#define PR_CAPBSET_READ 23
#define PR_CAPBSET_DROP 24
#endif

using namespace playground2;
using sandbox::BrokerProcess;

Expand Down
21 changes: 21 additions & 0 deletions sandbox/linux/services/android_arm_ucontext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SANDBOX_LINUX_SERVICES_ANDROID_ARM_UCONTEXT_H_
#define SANDBOX_LINUX_SERVICES_ANDROID_ARM_UCONTEXT_H_
typedef long int greg_t;
typedef unsigned long sigset_t;
typedef struct ucontext {
unsigned long uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
struct sigcontext uc_mcontext;
sigset_t uc_sigmask;
/* Allow for uc_sigmask growth. Glibc uses a 1024-bit sigset_t. */
int __not_used[32 - (sizeof (sigset_t) / sizeof (int))];
/* Last for extensibility. Eight byte aligned because some
coprocessors require eight byte alignment. */
unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
} ucontext_t;
#endif // SANDBOX_LINUX_SERVICES_ANDROID_ARM_UCONTEXT_H_

0 comments on commit 1bf4155

Please sign in to comment.