Chromium Code Reviews| 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> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 Key key; | 45 Key key; |
| 46 // Actual FD. | 46 // Actual FD. |
| 47 int fd; | 47 int fd; |
| 48 // Optional region, defaults to kWholeFile. | 48 // Optional region, defaults to kWholeFile. |
| 49 base::MemoryMappedFile::Region region; | 49 base::MemoryMappedFile::Region region; |
| 50 }; | 50 }; |
| 51 typedef std::vector<Descriptor> Mapping; | 51 typedef std::vector<Descriptor> Mapping; |
| 52 | 52 |
| 53 // Often we want a canonical descriptor for a given Key. In this case, we add | 53 // Often we want a canonical descriptor for a given Key. In this case, we add |
| 54 // the following constant to the key value: | 54 // the following constant to the key value: |
| 55 #if !defined(OS_ANDROID) | |
| 56 static const int kBaseDescriptor = 3; // 0, 1, 2 are already taken. | 55 static const int kBaseDescriptor = 3; // 0, 1, 2 are already taken. |
| 57 #else | |
| 58 // 3 used by __android_log_write(). | |
| 59 // 4 used by... something important on Android M. | |
| 60 // 5 used by... something important on Android L... on low-end devices. | |
| 61 // TODO(amistry): An Android, this mechanism is only used for tests since the | |
| 62 // content child launcher spawns a process by creating a new Activity using | |
| 63 // the Android APIs. For tests, come up with a way that doesn't require using | |
| 64 // a pre-defined fd. | |
| 65 static const int kBaseDescriptor = 6; | |
| 66 #endif | |
| 67 | 56 |
| 68 // Return the singleton instance of GlobalDescriptors. | 57 // Return the singleton instance of GlobalDescriptors. |
| 69 static GlobalDescriptors* GetInstance(); | 58 static GlobalDescriptors* GetInstance(); |
| 70 | 59 |
| 71 // Get a descriptor given a key. It is a fatal error if the key is not known. | 60 // Get a descriptor given a key. It is a fatal error if the key is not known. |
| 72 int Get(Key key) const; | 61 int Get(Key key) const; |
| 73 | 62 |
| 74 // Get a descriptor given a key. Returns -1 on error. | 63 // Get a descriptor given a key. Returns -1 on error. |
| 75 int MaybeGet(Key key) const; | 64 int MaybeGet(Key key) const; |
| 76 | 65 |
| 77 // Get a region given a key. It is a fatal error if the key is not known. | 66 // Get a region given a key. It is a fatal error if the key is not known. |
| 78 base::MemoryMappedFile::Region GetRegion(Key key) const; | 67 base::MemoryMappedFile::Region GetRegion(Key key) const; |
| 79 | 68 |
| 80 // Set the descriptor for the given |key|. This sets the region associated | 69 // Set the descriptor for the given |key|. This sets the region associated |
| 81 // with |key| to kWholeFile. | 70 // with |key| to kWholeFile. |
| 82 void Set(Key key, int fd); | 71 void Set(Key key, int fd); |
| 83 | 72 |
| 84 // Set the descriptor and |region| for the given |key|. | 73 // Set the descriptor and |region| for the given |key|. |
| 85 void Set(Key key, int fd, base::MemoryMappedFile::Region region); | 74 void Set(Key key, int fd, base::MemoryMappedFile::Region region); |
| 86 | 75 |
| 76 // Generates a random key and uses it to set the descriptor. | |
|
Robert Sesek
2016/12/20 20:44:34
This seems like it could be confusing unless Regis
Jay Civelli
2016/12/20 23:07:26
What I don't like about the kBaseDescriptor+N appr
Robert Sesek
2016/12/21 19:26:07
I agree that this could start to become a problem
Jay Civelli
2016/12/21 22:26:22
Sounds good, now using a fixed key.
I will try to
| |
| 77 Key Register(int fd); | |
| 78 | |
| 87 void Reset(const Mapping& mapping); | 79 void Reset(const Mapping& mapping); |
| 88 | 80 |
| 89 private: | 81 private: |
| 90 friend struct DefaultSingletonTraits<GlobalDescriptors>; | 82 friend struct DefaultSingletonTraits<GlobalDescriptors>; |
| 91 GlobalDescriptors(); | 83 GlobalDescriptors(); |
| 92 ~GlobalDescriptors(); | 84 ~GlobalDescriptors(); |
| 93 | 85 |
| 94 Mapping descriptors_; | 86 Mapping descriptors_; |
| 95 }; | 87 }; |
| 96 | 88 |
| 97 } // namespace base | 89 } // namespace base |
| 98 | 90 |
| 99 #endif // BASE_POSIX_GLOBAL_DESCRIPTORS_H_ | 91 #endif // BASE_POSIX_GLOBAL_DESCRIPTORS_H_ |
| OLD | NEW |