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

Unified Diff: sandbox/linux/services/broker_process.h

Issue 11557025: Linux sandbox: add a new low-level broker process mechanism. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
Index: sandbox/linux/services/broker_process.h
diff --git a/sandbox/linux/services/broker_process.h b/sandbox/linux/services/broker_process.h
new file mode 100644
index 0000000000000000000000000000000000000000..0cf7cfd6f4887b30dcde490a9c00752b38f5db88
--- /dev/null
+++ b/sandbox/linux/services/broker_process.h
@@ -0,0 +1,60 @@
+#ifndef SANDBOX_LINUX_SERVICES_OPEN_BROKER_H_
+#define SANDBOX_LINUX_SERVICES_OPEN_BROKER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/process.h"
+
+namespace sandbox {
+
+// Create a new "broker" process to which we can send requests via an IPC
+// channel.
+// This is a low level IPC mechanism that is suitable to be called from a
+// signal handler.
+// A process would typically create a broker process before entering
+// sandboxing.
+// 1. BrokerProcess open_broker(file_whitelist);
+// 2. CHECK(open_broker.Init(NULL));
+// 3. Enable sandbox.
+// 4. Use open_broker.Open() to open files.
+class BrokerProcess {
+ public:
+ static const int kMaxMessageLength = 4096;
+ static const int kCommandOpen = 'O';
+
+ // allowed_file_names is a white list of files that can be opened later via
+ // the Open() API.
+ explicit BrokerProcess(const std::vector<std::string>& allowed_file_names);
+ // The constructor below should be reserved for unit tests.
+ BrokerProcess(const std::vector<std::string>& allowed_file_names,
+ bool fast_check_in_client);
+ ~BrokerProcess();
+ // Will initialize the broker process. There should be no threads at this
+ // point, since we need to fork().
+ // sandbox_callback should be NULL as this feature is not implemented yet.
+ bool Init(void* sandbox_callback);
+
+ // Can be used in lieu of open(). Will be async signal safe.
+ // The implementation only supports O_RDONLY for now.
Jorge Lucangeli Obes 2012/12/13 02:14:54 I need to check if the /dev/dri/card0 thing libva
jln (very slow on Chromium) 2012/12/13 02:33:14 Ok. It's trivial to add support for RD_WRITE anywa
Jorge Lucangeli Obes (Google) 2012/12/13 04:28:52 Confirmed libva is opening /dev/dri/card0 O_RDWR.
+ // It's similar to the open() system call and will return -errno.
+ int Open(const char* pathname, int flags) const;
+
+ int broker_pid() const { return broker_pid_; }
+
+ private:
+ BrokerProcess();
+ bool initialized_; // Whether we've been through Init() yet.
+ bool is_child_; // Whether we're the child (broker process).
+ bool fast_check_in_client_; // Whether to forward a request that we know
+ // will be denied to the broker.
+ pid_t broker_pid_; // The PID of the broker (child).
+ std::vector<std::string> allowed_file_names_;
+ int ipc_socketpair_; // Our communication channel to parent or child.
+ DISALLOW_COPY_AND_ASSIGN(BrokerProcess);
+};
+
+} // namespace sandbox
+
+#endif // SANDBOX_LINUX_SERVICES_OPEN_BROKER_H_

Powered by Google App Engine
This is Rietveld 408576698