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

Side by Side Diff: base/memory/shared_memory.h

Issue 27265002: Implement SharedMemory::NewAnonymousReadOnly(contents). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix signedness on Mac Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_MEMORY_SHARED_MEMORY_H_ 5 #ifndef BASE_MEMORY_SHARED_MEMORY_H_
6 #define BASE_MEMORY_SHARED_MEMORY_H_ 6 #define BASE_MEMORY_SHARED_MEMORY_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <string> 10 #include <string>
11 11
12 #if defined(OS_POSIX) 12 #if defined(OS_POSIX)
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <sys/types.h> 14 #include <sys/types.h>
15 #include <semaphore.h> 15 #include <semaphore.h>
16 #endif 16 #endif
17 17
18 #include "base/base_export.h" 18 #include "base/base_export.h"
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/memory/scoped_ptr.h"
20 #include "base/process/process_handle.h" 21 #include "base/process/process_handle.h"
21 22
22 #if defined(OS_POSIX) 23 #if defined(OS_POSIX)
23 #include "base/file_descriptor_posix.h" 24 #include "base/file_descriptor_posix.h"
24 #endif 25 #endif
25 26
26 namespace base { 27 namespace base {
27 28
28 class FilePath; 29 class FilePath;
29 30
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 #if defined(OS_WIN) 75 #if defined(OS_WIN)
75 // Similar to the default constructor, except that this allows for 76 // Similar to the default constructor, except that this allows for
76 // calling Lock() to acquire the named mutex before either Create or Open 77 // calling Lock() to acquire the named mutex before either Create or Open
77 // are called on Windows. 78 // are called on Windows.
78 explicit SharedMemory(const std::wstring& name); 79 explicit SharedMemory(const std::wstring& name);
79 #endif 80 #endif
80 81
81 // Create a new SharedMemory object from an existing, open 82 // Create a new SharedMemory object from an existing, open
82 // shared memory file. 83 // shared memory file.
84 //
85 // WARNING: This does not reduce the OS-level permissions on the handle; it
86 // only affects how the SharedMemory will be mmapped. TODO(jln,jyasskin):
87 // remove this overload or DCHECK that read_only matches the permissions of
88 // the handle.
83 SharedMemory(SharedMemoryHandle handle, bool read_only); 89 SharedMemory(SharedMemoryHandle handle, bool read_only);
84 90
85 // Create a new SharedMemory object from an existing, open 91 // Create a new SharedMemory object from an existing, open
86 // shared memory file that was created by a remote process and not shared 92 // shared memory file that was created by a remote process and not shared
87 // to the current process. 93 // to the current process.
88 SharedMemory(SharedMemoryHandle handle, bool read_only, 94 SharedMemory(SharedMemoryHandle handle, bool read_only,
89 ProcessHandle process); 95 ProcessHandle process);
90 96
91 // Closes any open files. 97 // Closes any open files.
92 ~SharedMemory(); 98 ~SharedMemory();
93 99
94 // Return true iff the given handle is valid (i.e. not the distingished 100 // Return true iff the given handle is valid (i.e. not the distingished
95 // invalid value; NULL for a HANDLE and -1 for a file descriptor) 101 // invalid value; NULL for a HANDLE and -1 for a file descriptor)
96 static bool IsHandleValid(const SharedMemoryHandle& handle); 102 static bool IsHandleValid(const SharedMemoryHandle& handle);
97 103
98 // Returns invalid handle (see comment above for exact definition). 104 // Returns invalid handle (see comment above for exact definition).
99 static SharedMemoryHandle NULLHandle(); 105 static SharedMemoryHandle NULLHandle();
100 106
101 // Closes a shared memory handle. 107 // Closes a shared memory handle.
102 static void CloseHandle(const SharedMemoryHandle& handle); 108 static void CloseHandle(const SharedMemoryHandle& handle);
103 109
104 // Returns the maximum number of handles that can be open at once per process. 110 // Returns the maximum number of handles that can be open at once per process.
105 static size_t GetHandleLimit(); 111 static size_t GetHandleLimit();
106 112
113 // Returns a new, read-only, unmapped SharedMemory with |contents| written
114 // into it. Use this to send data to untrusted processes. Returns NULL if
115 // creation fails.
116 static scoped_ptr<SharedMemory> NewAnonymousReadOnly(StringPiece contents);
117
107 // Creates a shared memory object as described by the options struct. 118 // Creates a shared memory object as described by the options struct.
108 // Returns true on success and false on failure. 119 // Returns true on success and false on failure.
109 bool Create(const SharedMemoryCreateOptions& options); 120 bool Create(const SharedMemoryCreateOptions& options);
110 121
111 // Creates and maps an anonymous shared memory segment of size size. 122 // Creates and maps an anonymous shared memory segment of size size.
112 // Returns true on success and false on failure. 123 // Returns true on success and false on failure.
113 bool CreateAndMapAnonymous(size_t size); 124 bool CreateAndMapAnonymous(size_t size);
114 125
115 // Creates an anonymous shared memory segment of size size. 126 // Creates an anonymous shared memory segment of size size.
116 // Returns true on success and false on failure. 127 // Returns true on success and false on failure.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 283 }
273 284
274 private: 285 private:
275 SharedMemory* shared_memory_; 286 SharedMemory* shared_memory_;
276 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock); 287 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock);
277 }; 288 };
278 289
279 } // namespace base 290 } // namespace base
280 291
281 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 292 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/shared_memory_posix.cc » ('j') | base/memory/shared_memory_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698