| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_POSIX_GLOBAL_DESCRIPTORS_H_ | 5 #ifndef BASE_POSIX_GLOBAL_DESCRIPTORS_H_ |
| 6 #define BASE_POSIX_GLOBAL_DESCRIPTORS_H_ | 6 #define BASE_POSIX_GLOBAL_DESCRIPTORS_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 | 14 |
| 15 #include "base/files/memory_mapped_file.h" | 15 #include "base/files/memory_mapped_file.h" |
| 16 #include "base/files/scoped_file.h" |
| 16 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 | 20 |
| 20 // It's common practice to install file descriptors into well known slot | 21 // It's common practice to install file descriptors into well known slot |
| 21 // numbers before execing a child; stdin, stdout and stderr are ubiqutous | 22 // numbers before execing a child; stdin, stdout and stderr are ubiqutous |
| 22 // examples. | 23 // examples. |
| 23 // | 24 // |
| 24 // However, when using a zygote model, this becomes troublesome. Since the | 25 // However, when using a zygote model, this becomes troublesome. Since the |
| 25 // descriptors which need to be in these slots generally aren't known, any code | 26 // descriptors which need to be in these slots generally aren't known, any code |
| (...skipping 30 matching lines...) Expand all Loading... |
| 56 | 57 |
| 57 // Return the singleton instance of GlobalDescriptors. | 58 // Return the singleton instance of GlobalDescriptors. |
| 58 static GlobalDescriptors* GetInstance(); | 59 static GlobalDescriptors* GetInstance(); |
| 59 | 60 |
| 60 // Get a descriptor given a key. It is a fatal error if the key is not known. | 61 // Get a descriptor given a key. It is a fatal error if the key is not known. |
| 61 int Get(Key key) const; | 62 int Get(Key key) const; |
| 62 | 63 |
| 63 // Get a descriptor given a key. Returns -1 on error. | 64 // Get a descriptor given a key. Returns -1 on error. |
| 64 int MaybeGet(Key key) const; | 65 int MaybeGet(Key key) const; |
| 65 | 66 |
| 67 // Returns a descriptor given a key and removes it from this class mappings. |
| 68 // Also populates |region| if it's not null. |
| 69 // It is a fatal error if the key is not known. |
| 70 base::ScopedFD TakeFD(Key key, base::MemoryMappedFile::Region* region); |
| 71 |
| 66 // Get a region given a key. It is a fatal error if the key is not known. | 72 // Get a region given a key. It is a fatal error if the key is not known. |
| 67 base::MemoryMappedFile::Region GetRegion(Key key) const; | 73 base::MemoryMappedFile::Region GetRegion(Key key) const; |
| 68 | 74 |
| 69 // Set the descriptor for the given |key|. This sets the region associated | 75 // Set the descriptor for the given |key|. This sets the region associated |
| 70 // with |key| to kWholeFile. | 76 // with |key| to kWholeFile. |
| 71 void Set(Key key, int fd); | 77 void Set(Key key, int fd); |
| 72 | 78 |
| 73 // Set the descriptor and |region| for the given |key|. | 79 // Set the descriptor and |region| for the given |key|. |
| 74 void Set(Key key, int fd, base::MemoryMappedFile::Region region); | 80 void Set(Key key, int fd, base::MemoryMappedFile::Region region); |
| 75 | 81 |
| 76 void Reset(const Mapping& mapping); | 82 void Reset(const Mapping& mapping); |
| 77 | 83 |
| 78 private: | 84 private: |
| 79 friend struct DefaultSingletonTraits<GlobalDescriptors>; | 85 friend struct DefaultSingletonTraits<GlobalDescriptors>; |
| 80 GlobalDescriptors(); | 86 GlobalDescriptors(); |
| 81 ~GlobalDescriptors(); | 87 ~GlobalDescriptors(); |
| 82 | 88 |
| 83 Mapping descriptors_; | 89 Mapping descriptors_; |
| 84 }; | 90 }; |
| 85 | 91 |
| 86 } // namespace base | 92 } // namespace base |
| 87 | 93 |
| 88 #endif // BASE_POSIX_GLOBAL_DESCRIPTORS_H_ | 94 #endif // BASE_POSIX_GLOBAL_DESCRIPTORS_H_ |
| OLD | NEW |