Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1015)

Unified Diff: sandbox/linux/seccomp/mutex.h

Issue 3225010: Pull seccomp-sandbox in via DEPS rather than using an in-tree copy... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/linux/seccomp/munmap.cc ('k') | sandbox/linux/seccomp/open.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/seccomp/mutex.h
===================================================================
--- sandbox/linux/seccomp/mutex.h (revision 57969)
+++ sandbox/linux/seccomp/mutex.h (working copy)
@@ -1,153 +0,0 @@
-// Copyright (c) 2010 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 MUTEX_H__
-#define MUTEX_H__
-
-#include "sandbox_impl.h"
-
-namespace playground {
-
-class Mutex {
- public:
- typedef int mutex_t;
-
- enum { kInitValue = 0 };
-
- static void initMutex(mutex_t* mutex) {
- // Mutex is unlocked, and nobody is waiting for it
- *mutex = kInitValue;
- }
-
- static void unlockMutex(mutex_t* mutex) {
- char status;
- #if defined(__x86_64__) || defined(__i386__)
- asm volatile(
- "lock; addl %2, %0\n"
- "setz %1"
- : "=m"(*mutex), "=qm"(status)
- : "ir"(0x80000000), "m"(*mutex));
- #else
- #error Unsupported target platform
- #endif
- if (status) {
- // Mutex is zero now. No other waiters. So, we can return.
- return;
- }
- // We unlocked the mutex, but still need to wake up other waiters.
- Sandbox::SysCalls sys;
- sys.futex(mutex, FUTEX_WAKE, 1, NULL);
- }
-
- static bool lockMutex(mutex_t* mutex, int timeout = 0) {
- bool rc = true;
- // Increment mutex to add ourselves to the list of waiters
- #if defined(__x86_64__) || defined(__i386__)
- asm volatile(
- "lock; incl %0\n"
- : "=m"(*mutex)
- : "m"(*mutex));
- #else
- #error Unsupported target platform
- #endif
- for (;;) {
- // Atomically check whether the mutex is available and if so, acquire it
- char status;
- #if defined(__x86_64__) || defined(__i386__)
- asm volatile(
- "lock; btsl %3, %1\n"
- "setc %0"
- : "=q"(status), "=m"(*mutex)
- : "m"(*mutex), "ir"(31));
- #else
- #error Unsupported target platform
- #endif
- if (!status) {
- done:
- // If the mutex was available, remove ourselves from list of waiters
- #if defined(__x86_64__) || defined(__i386__)
- asm volatile(
- "lock; decl %0\n"
- : "=m"(*mutex)
- : "m"(*mutex));
- #else
- #error Unsupported target platform
- #endif
- return rc;
- }
- int value = *mutex;
- if (value >= 0) {
- // Mutex has just become available, no need to call kernel
- continue;
- }
- Sandbox::SysCalls sys;
- Sandbox::SysCalls::kernel_timespec tm;
- if (timeout) {
- tm.tv_sec = timeout / 1000;
- tm.tv_nsec = (timeout % 1000) * 1000 * 1000;
- } else {
- tm.tv_sec = 0;
- tm.tv_nsec = 0;
- }
- if (NOINTR_SYS(sys.futex(mutex, FUTEX_WAIT, value, &tm)) &&
- sys.my_errno == ETIMEDOUT) {
- rc = false;
- goto done;
- }
- }
- }
-
- static bool waitForUnlock(mutex_t* mutex, int timeout = 0) {
- bool rc = true;
- // Increment mutex to add ourselves to the list of waiters
- #if defined(__x86_64__) || defined(__i386__)
- asm volatile(
- "lock; incl %0\n"
- : "=m"(*mutex)
- : "m"(*mutex));
- #else
- #error Unsupported target platform
- #endif
- Sandbox::SysCalls sys;
- for (;;) {
- mutex_t value = *mutex;
- if (value >= 0) {
- done:
- // Mutex was not locked. Remove ourselves from list of waiters, notify
- // any other waiters (if any), and return.
- #if defined(__x86_64__) || defined(__i386__)
- asm volatile(
- "lock; decl %0\n"
- : "=m"(*mutex)
- : "m"(*mutex));
- #else
- #error Unsupported target platform
- #endif
- NOINTR_SYS(sys.futex(mutex, FUTEX_WAKE, 1, 0));
- return rc;
- }
-
- // Wait for mutex to become unlocked
- Sandbox::SysCalls::kernel_timespec tm;
- if (timeout) {
- tm.tv_sec = timeout / 1000;
- tm.tv_nsec = (timeout % 1000) * 1000 * 1000;
- } else {
- tm.tv_sec = 0;
- tm.tv_nsec = 0;
- }
-
- if (NOINTR_SYS(sys.futex(mutex, FUTEX_WAIT, value, &tm)) &&
- sys.my_errno == ETIMEDOUT) {
- rc = false;
- goto done;
- }
- }
- }
-
-};
-
-} // namespace
-
-#endif // MUTEX_H__
« no previous file with comments | « sandbox/linux/seccomp/munmap.cc ('k') | sandbox/linux/seccomp/open.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698