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

Side by Side Diff: base/process_util_mac.mm

Issue 14749003: Stop overwriting errno in base::StringPrintf, StringAppendV, and StringToDouble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comment Created 7 years, 7 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
« no previous file with comments | « base/base.gyp ('k') | base/scoped_clear_errno.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/process_util.h" 5 #include "base/process_util.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <crt_externs.h> 8 #include <crt_externs.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <mach/mach.h> 10 #include <mach/mach.h>
(...skipping 14 matching lines...) Expand all
25 #include <string> 25 #include <string>
26 26
27 #include "base/debug/debugger.h" 27 #include "base/debug/debugger.h"
28 #include "base/file_util.h" 28 #include "base/file_util.h"
29 #include "base/hash_tables.h" 29 #include "base/hash_tables.h"
30 #include "base/lazy_instance.h" 30 #include "base/lazy_instance.h"
31 #include "base/logging.h" 31 #include "base/logging.h"
32 #include "base/mac/mac_util.h" 32 #include "base/mac/mac_util.h"
33 #include "base/mac/scoped_mach_port.h" 33 #include "base/mac/scoped_mach_port.h"
34 #include "base/posix/eintr_wrapper.h" 34 #include "base/posix/eintr_wrapper.h"
35 #include "base/scoped_clear_errno.h"
35 #include "base/string_util.h" 36 #include "base/string_util.h"
36 #include "base/sys_info.h" 37 #include "base/sys_info.h"
37 #include "third_party/apple_apsl/CFBase.h" 38 #include "third_party/apple_apsl/CFBase.h"
38 #include "third_party/apple_apsl/malloc.h" 39 #include "third_party/apple_apsl/malloc.h"
39 40
40 #if ARCH_CPU_32_BITS 41 #if ARCH_CPU_32_BITS
41 #include <dlfcn.h> 42 #include <dlfcn.h>
42 #include <mach-o/nlist.h> 43 #include <mach-o/nlist.h>
43 44
44 #include "base/threading/thread_local.h" 45 #include "base/threading/thread_local.h"
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 // nlist() returns addresses as offsets in the image, not the instruction 540 // nlist() returns addresses as offsets in the image, not the instruction
540 // pointer in memory. Use the known in-memory address of malloc() 541 // pointer in memory. Use the known in-memory address of malloc()
541 // to compute the offset for malloc_error_break(). 542 // to compute the offset for malloc_error_break().
542 uintptr_t reference_addr = reinterpret_cast<uintptr_t>(&malloc); 543 uintptr_t reference_addr = reinterpret_cast<uintptr_t>(&malloc);
543 reference_addr -= nl[1].n_value; 544 reference_addr -= nl[1].n_value;
544 reference_addr += nl[0].n_value; 545 reference_addr += nl[0].n_value;
545 546
546 return reinterpret_cast<malloc_error_break_t>(reference_addr); 547 return reinterpret_cast<malloc_error_break_t>(reference_addr);
547 } 548 }
548 549
549 // Simple scoper that saves the current value of errno, resets it to 0, and on
550 // destruction puts the old value back. This is so that CrMallocErrorBreak can
551 // safely test errno free from the effects of other routines.
552 class ScopedClearErrno {
553 public:
554 ScopedClearErrno() : old_errno_(errno) {
555 errno = 0;
556 }
557 ~ScopedClearErrno() {
558 if (errno == 0)
559 errno = old_errno_;
560 }
561
562 private:
563 int old_errno_;
564
565 DISALLOW_COPY_AND_ASSIGN(ScopedClearErrno);
566 };
567
568 // Combines ThreadLocalBoolean with AutoReset. It would be convenient 550 // Combines ThreadLocalBoolean with AutoReset. It would be convenient
569 // to compose ThreadLocalPointer<bool> with base::AutoReset<bool>, but that 551 // to compose ThreadLocalPointer<bool> with base::AutoReset<bool>, but that
570 // would require allocating some storage for the bool. 552 // would require allocating some storage for the bool.
571 class ThreadLocalBooleanAutoReset { 553 class ThreadLocalBooleanAutoReset {
572 public: 554 public:
573 ThreadLocalBooleanAutoReset(ThreadLocalBoolean* tlb, bool new_value) 555 ThreadLocalBooleanAutoReset(ThreadLocalBoolean* tlb, bool new_value)
574 : scoped_tlb_(tlb), 556 : scoped_tlb_(tlb),
575 original_value_(tlb->Get()) { 557 original_value_(tlb->Get()) {
576 scoped_tlb_->Set(new_value); 558 scoped_tlb_->Set(new_value);
577 } 559 }
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1324 }
1343 } 1325 }
1344 1326
1345 } // namespace 1327 } // namespace
1346 1328
1347 void EnsureProcessTerminated(ProcessHandle process) { 1329 void EnsureProcessTerminated(ProcessHandle process) {
1348 WaitForChildToDie(process, kWaitBeforeKillSeconds); 1330 WaitForChildToDie(process, kWaitBeforeKillSeconds);
1349 } 1331 }
1350 1332
1351 } // namespace base 1333 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/scoped_clear_errno.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698