summaryrefslogtreecommitdiffstats
path: root/base/global_descriptors_posix.h
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 17:36:55 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 17:36:55 +0000
commitcc8f146d34a3b13cd80d8b3530fd76445774b1c6 (patch)
tree65ddd346a7b468f716f0022507112ec7215a17f7 /base/global_descriptors_posix.h
parent9ab7d838fba71523a32d1b1e50e5d9a1c20815b2 (diff)
downloadchromium_src-cc8f146d34a3b13cd80d8b3530fd76445774b1c6.zip
chromium_src-cc8f146d34a3b13cd80d8b3530fd76445774b1c6.tar.gz
chromium_src-cc8f146d34a3b13cd80d8b3530fd76445774b1c6.tar.bz2
Linux: refactor zygote support
http://code.google.com/p/chromium/wiki/LinuxZygote * Move Chrome specific bits out of base * Move away from the idea of reserved file descriptors (which don't really work with zygotes) * Load resources before forking renderers (means that we don't need communication between the zygote process and the renderers) * Make sure that gdb works against the browser again * Make sure that we have different ASLR between the renderers and the browser. http://codereview.chromium.org/119335 (This is a reland. First landed in r18109, reverted in r18112.) git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/global_descriptors_posix.h')
-rw-r--r--base/global_descriptors_posix.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/base/global_descriptors_posix.h b/base/global_descriptors_posix.h
new file mode 100644
index 0000000..f606a82
--- /dev/null
+++ b/base/global_descriptors_posix.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2009 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 BASE_GLOBAL_DESCRIPTORS_POSIX_H_
+#define BASE_GLOBAL_DESCRIPTORS_POSIX_H_
+
+#include "build/build_config.h"
+
+#include <vector>
+#include <utility>
+
+#include <stdint.h>
+
+#include "base/singleton.h"
+
+namespace base {
+
+// It's common practice to install file descriptors into well known slot
+// numbers before execing a child; stdin, stdout and stderr are ubiqutous
+// examples.
+//
+// However, when using a zygote model, this becomes troublesome. Since the
+// descriptors which need to be in these slots generally aren't known, any code
+// could open a resource and take one of the reserved descriptors. Simply
+// overwriting the slot isn't a viable solution.
+//
+// We could try to fill the reserved slots as soon as possible, but this is a
+// fragile solution since global constructors etc are able to open files.
+//
+// Instead, we retreat from the idea of installing descriptors in specific
+// slots and add a layer of indirection in the form of this singleton object.
+// It maps from an abstract key to a descriptor. If independent modules each
+// need to define keys, then values should be chosen randomly so as not to
+// collide.
+class GlobalDescriptors {
+ public:
+ typedef uint32_t Key;
+ // Often we want a canonical descriptor for a given Key. In this case, we add
+ // the following constant to the key value:
+ static const int kBaseDescriptor = 3; // 0, 1, 2 are already taken.
+
+ // Get a descriptor given a key. It is a fatal error if the key is not known.
+ int Get(Key key) const;
+ // Get a descriptor give a key. Returns -1 on error.
+ int MaybeGet(Key key) const;
+
+ typedef std::vector<std::pair<Key, int> > Mapping;
+
+ // Set the descriptor for the given key.
+ void Set(Key key, int fd);
+
+ void Reset(const Mapping& mapping) {
+ descriptors_ = mapping;
+ }
+
+ private:
+ GlobalDescriptors() { }
+ friend struct DefaultSingletonTraits<GlobalDescriptors>;
+
+ Mapping descriptors_;
+};
+
+} // namespace base
+
+#endif // BASE_GLOBAL_DESCRIPTORS_POSIX_H_