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

Side by Side Diff: util/mach/mach_message_server.cc

Issue 779633004: MachMessageServer: scribble over memory allocations in debug mode (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 6 years 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
« no previous file with comments | « util/mach/exc_client_variants_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/mach/mach_message_server.h" 15 #include "util/mach/mach_message_server.h"
16 16
17 #include <string.h>
18
17 #include <limits> 19 #include <limits>
18 20
19 #include "base/logging.h" 21 #include "base/logging.h"
20 #include "base/mac/mach_logging.h" 22 #include "base/mac/mach_logging.h"
21 #include "base/mac/scoped_mach_vm.h" 23 #include "base/mac/scoped_mach_vm.h"
22 #include "util/mach/mach_message.h" 24 #include "util/mach/mach_message.h"
23 25
24 namespace crashpad { 26 namespace crashpad {
25 27
26 namespace { 28 namespace {
(...skipping 14 matching lines...) Expand all
41 //! available. 43 //! available.
42 //! 44 //!
43 //! If the existing buffer is a different size, it will be reallocated without 45 //! If the existing buffer is a different size, it will be reallocated without
44 //! copying any of the old buffer’s contents to the new buffer. The contents 46 //! copying any of the old buffer’s contents to the new buffer. The contents
45 //! of the buffer are unspecified after this call, even if no reallocation is 47 //! of the buffer are unspecified after this call, even if no reallocation is
46 //! performed. 48 //! performed.
47 kern_return_t Reallocate(vm_size_t size) { 49 kern_return_t Reallocate(vm_size_t size) {
48 // This test uses == instead of > so that a large reallocation to receive a 50 // This test uses == instead of > so that a large reallocation to receive a
49 // large message doesn’t cause permanent memory bloat for the duration of 51 // large message doesn’t cause permanent memory bloat for the duration of
50 // a MachMessageServer::Run() loop. 52 // a MachMessageServer::Run() loop.
51 if (size == vm_.size()) { 53 if (size != vm_.size()) {
52 return KERN_SUCCESS; 54 // reset() first, so that two allocations don’t exist simultaneously.
55 vm_.reset();
56
57 if (size) {
58 vm_address_t address;
59 kern_return_t kr =
60 vm_allocate(mach_task_self(),
61 &address,
62 size,
63 VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG));
64 if (kr != KERN_SUCCESS) {
65 return kr;
66 }
67
68 vm_.reset(address, size);
69 }
53 } 70 }
54 71
55 // reset() first, so that two allocations don’t exist simultaneously. 72 #if !defined(NDEBUG)
56 vm_.reset(); 73 // Regardless of whether the allocation was changed, scribble over the
57 74 // memory to make sure that nothing relies on zero-initialization or stale
58 if (size) { 75 // contents.
59 vm_address_t address; 76 memset(Header(), 0x66, size);
60 kern_return_t kr = 77 #endif
61 vm_allocate(mach_task_self(),
62 &address,
63 size,
64 VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG));
65 if (kr != KERN_SUCCESS) {
66 return kr;
67 }
68
69 vm_.reset(address, size);
70 }
71 78
72 return KERN_SUCCESS; 79 return KERN_SUCCESS;
73 } 80 }
74 81
75 private: 82 private:
76 base::mac::ScopedMachVM vm_; 83 base::mac::ScopedMachVM vm_;
77 84
78 DISALLOW_COPY_AND_ASSIGN(MachMessageBuffer); 85 DISALLOW_COPY_AND_ASSIGN(MachMessageBuffer);
79 }; 86 };
80 87
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 278 }
272 return kr; 279 return kr;
273 } 280 }
274 } 281 }
275 } while (persistent == kPersistent || retry); 282 } while (persistent == kPersistent || retry);
276 283
277 return kr; 284 return kr;
278 } 285 }
279 286
280 } // namespace crashpad 287 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/exc_client_variants_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698