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

Side by Side Diff: base/process_util_linux.cc

Issue 7670025: [Mac] Implement base::EnableTerminationOnHeapCorruption() by overriding malloc_error_break(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <ctype.h> 7 #include <ctype.h>
8 #include <dirent.h> 8 #include <dirent.h>
9 #include <dlfcn.h> 9 #include <dlfcn.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 711
712 int posix_memalign(void** ptr, size_t alignment, size_t size) { 712 int posix_memalign(void** ptr, size_t alignment, size_t size) {
713 // This will use the safe version of memalign, above. 713 // This will use the safe version of memalign, above.
714 *ptr = memalign(alignment, size); 714 *ptr = memalign(alignment, size);
715 return 0; 715 return 0;
716 } 716 }
717 717
718 #endif // !defined(USE_TCMALLOC) 718 #endif // !defined(USE_TCMALLOC)
719 } // extern C 719 } // extern C
720 720
721 void EnableTerminationOnHeapCorruption() {
722 // On POSIX, there nothing to do AFAIK.
Mark Mentovai 2011/08/17 16:44:55 This comment should now say Linux, not POSIX.
723 }
724
721 void EnableTerminationOnOutOfMemory() { 725 void EnableTerminationOnOutOfMemory() {
722 #if defined(OS_ANDROID) 726 #if defined(OS_ANDROID)
723 // Android doesn't support setting a new handler. 727 // Android doesn't support setting a new handler.
724 DLOG(WARNING) << "Not feasible."; 728 DLOG(WARNING) << "Not feasible.";
725 #else 729 #else
726 // Set the new-out of memory handler. 730 // Set the new-out of memory handler.
727 std::set_new_handler(&OnNoMemory); 731 std::set_new_handler(&OnNoMemory);
728 // If we're using glibc's allocator, the above functions will override 732 // If we're using glibc's allocator, the above functions will override
729 // malloc and friends and make them die on out of memory. 733 // malloc and friends and make them die on out of memory.
730 #endif 734 #endif
731 } 735 }
732 736
733 bool AdjustOOMScore(ProcessId process, int score) { 737 bool AdjustOOMScore(ProcessId process, int score) {
734 if (score < 0 || score > 15) 738 if (score < 0 || score > 15)
735 return false; 739 return false;
736 740
737 FilePath oom_adj("/proc"); 741 FilePath oom_adj("/proc");
738 oom_adj = oom_adj.Append(base::Int64ToString(process)); 742 oom_adj = oom_adj.Append(base::Int64ToString(process));
739 oom_adj = oom_adj.AppendASCII("oom_adj"); 743 oom_adj = oom_adj.AppendASCII("oom_adj");
740 744
741 if (!file_util::PathExists(oom_adj)) 745 if (!file_util::PathExists(oom_adj))
742 return false; 746 return false;
743 747
744 std::string score_str = base::IntToString(score); 748 std::string score_str = base::IntToString(score);
745 return (static_cast<int>(score_str.length()) == 749 return (static_cast<int>(score_str.length()) ==
746 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); 750 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length()));
747 } 751 }
748 752
749 } // namespace base 753 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/process_util_mac.mm » ('j') | base/process_util_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698