diff options
author | cevans@chromium.org <cevans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 02:16:24 +0000 |
---|---|---|
committer | cevans@chromium.org <cevans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 02:16:24 +0000 |
commit | 374f1a835278298311bb922faf84161f7c2851dd (patch) | |
tree | f95a04524f17ab74bd68ba7c0d135e433dffb5fc /base/shared_memory.h | |
parent | 0064b506bd144f919de894d5d09266153a57ded3 (diff) | |
download | chromium_src-374f1a835278298311bb922faf84161f7c2851dd.zip chromium_src-374f1a835278298311bb922faf84161f7c2851dd.tar.gz chromium_src-374f1a835278298311bb922faf84161f7c2851dd.tar.bz2 |
The correct type for the size of a chunk of memory is size_t.
By using uint32, we have bugs on 64-bit platforms: callers passing in a size_t, will have their size truncated, potentially allocating a smaller
chunk than requested. There are a few places this happens, including on the
receiving ends of IPCs(!)
However, coversely, other callers of the API might directly assign the
memory chunk's length to uint32, leading to a different possible truncation
problem. This is guaraded against by limiting operations internally to
std::numeric_limits<uint32_t> in size for now.
There's some minor cascade effects that make the CL look larger than it is.
BUG=164678
Review URL: https://codereview.chromium.org/11446048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175987 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory.h')
-rw-r--r-- | base/shared_memory.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h index 1f8237e..4eefdbb 100644 --- a/base/shared_memory.h +++ b/base/shared_memory.h @@ -53,7 +53,7 @@ struct SharedMemoryCreateOptions { // Size of the shared memory object to be created. // When opening an existing object, this has no effect. - uint32 size; + size_t size; // If true, and the shared memory already exists, Create() will open the // existing shared memory and ignore the size parameter. If false, @@ -107,11 +107,11 @@ class BASE_EXPORT SharedMemory { // Creates and maps an anonymous shared memory segment of size size. // Returns true on success and false on failure. - bool CreateAndMapAnonymous(uint32 size); + bool CreateAndMapAnonymous(size_t size); // Creates an anonymous shared memory segment of size size. // Returns true on success and false on failure. - bool CreateAnonymous(uint32 size) { + bool CreateAnonymous(size_t size) { SharedMemoryCreateOptions options; options.size = size; return Create(options); @@ -123,7 +123,7 @@ class BASE_EXPORT SharedMemory { // If open_existing is false, shared memory must not exist. // size is the size of the block to be created. // Returns true on success, false on failure. - bool CreateNamed(const std::string& name, bool open_existing, uint32 size) { + bool CreateNamed(const std::string& name, bool open_existing, size_t size) { SharedMemoryCreateOptions options; options.name = &name; options.open_existing = open_existing; @@ -144,7 +144,7 @@ class BASE_EXPORT SharedMemory { // Returns true on success, false otherwise. The memory address // is accessed via the memory() accessor. The mapped address is guaranteed to // have an alignment of at least MAP_MINIMUM_ALIGNMENT. - bool Map(uint32 bytes); + bool Map(size_t bytes); enum { MAP_MINIMUM_ALIGNMENT = 32 }; // Unmaps the shared memory from the caller's address space. @@ -160,7 +160,7 @@ class BASE_EXPORT SharedMemory { // Deprecated method, please keep track of the size yourself if you created // it. // http://crbug.com/60821 - uint32 created_size() const { return created_size_; } + size_t created_size() const { return created_size_; } // Gets a pointer to the opened memory space if it has been // Mapped via Map(). Returns NULL if it is not mapped. @@ -239,12 +239,12 @@ class BASE_EXPORT SharedMemory { HANDLE mapped_file_; #elif defined(OS_POSIX) int mapped_file_; - uint32 mapped_size_; + size_t mapped_size_; ino_t inode_; #endif void* memory_; bool read_only_; - uint32 created_size_; + size_t created_size_; #if !defined(OS_POSIX) SharedMemoryLock lock_; #endif |