Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/memory/shared_memory_helper.h" | 5 #include "base/memory/shared_memory_helper.h" |
| 6 | 6 |
| 7 #if defined(OS_CHROMEOS) | |
| 8 #include <sys/resource.h> | |
| 9 #include <sys/time.h> | |
| 10 | |
| 11 #include "base/debug/alias.h" | |
| 12 #endif // defined(OS_CHROMEOS) | |
| 13 | |
| 7 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 8 | 15 |
| 9 namespace base { | 16 namespace base { |
| 10 | 17 |
| 11 struct ScopedPathUnlinkerTraits { | 18 struct ScopedPathUnlinkerTraits { |
| 12 static const FilePath* InvalidValue() { return nullptr; } | 19 static const FilePath* InvalidValue() { return nullptr; } |
| 13 | 20 |
| 14 static void Free(const FilePath* path) { | 21 static void Free(const FilePath* path) { |
| 15 if (unlink(path->value().c_str())) | 22 if (unlink(path->value().c_str())) |
| 16 PLOG(WARNING) << "unlink"; | 23 PLOG(WARNING) << "unlink"; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 NOTREACHED(); | 90 NOTREACHED(); |
| 84 if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) { | 91 if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) { |
| 85 LOG(ERROR) << "writable and read-only inodes don't match; bailing"; | 92 LOG(ERROR) << "writable and read-only inodes don't match; bailing"; |
| 86 return false; | 93 return false; |
| 87 } | 94 } |
| 88 } | 95 } |
| 89 | 96 |
| 90 *mapped_file = HANDLE_EINTR(dup(fileno(fp.get()))); | 97 *mapped_file = HANDLE_EINTR(dup(fileno(fp.get()))); |
| 91 if (*mapped_file == -1) { | 98 if (*mapped_file == -1) { |
| 92 NOTREACHED() << "Call to dup failed, errno=" << errno; | 99 NOTREACHED() << "Call to dup failed, errno=" << errno; |
| 100 | |
| 101 #if defined(OS_CHROMEOS) | |
| 102 if (errno == EMFILE) { | |
| 103 // We're out of file descriptors and are probably about to crash somewhere | |
| 104 // else in Chrome anyway. Let's collect what FD information we can and | |
| 105 // crash. | |
| 106 // Added for debugging crbug.com/733718 | |
| 107 int original_fd_limit = 16384; | |
|
Daniel Erat
2017/06/29 22:23:24
should this be updated below when the getrlimit()
teravest
2017/06/29 22:37:05
I believe it is, at line 110. I don't force it up
Daniel Erat
2017/06/29 22:41:26
whoops, my mistake
| |
| 108 struct rlimit rlim; | |
| 109 if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { | |
| 110 original_fd_limit = rlim.rlim_cur; | |
| 111 if (rlim.rlim_max > rlim.rlim_cur) { | |
| 112 // Increase fd limit so breakpad has a chance to write a minidump. | |
| 113 rlim.rlim_cur = rlim.rlim_max; | |
| 114 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) { | |
| 115 PLOG(ERROR) << "setrlimit() failed"; | |
| 116 } | |
| 117 } | |
| 118 } else { | |
| 119 PLOG(ERROR) << "getrlimit() failed"; | |
| 120 } | |
| 121 | |
| 122 const char kFileDataMarker[] = "FDATA"; | |
| 123 char buf[PATH_MAX]; | |
| 124 char fd_path[PATH_MAX]; | |
| 125 char crash_buffer[32 * 1024]; | |
|
Daniel Erat
2017/06/29 22:23:24
i think you can avoid the next memset by using "=
teravest
2017/06/29 22:37:05
cool, done.
| |
| 126 char* crash_ptr = crash_buffer; | |
| 127 memset(crash_buffer, 0, arraysize(crash_buffer)); | |
| 128 base::debug::Alias(crash_buffer); | |
| 129 | |
| 130 // Put a marker at the start of our data so we can confirm where it | |
| 131 // begins. | |
| 132 crash_ptr = strncpy(crash_ptr, kFileDataMarker, strlen(kFileDataMarker)); | |
| 133 for (int i = original_fd_limit; i >= 0; --i) { | |
| 134 memset(buf, 0, arraysize(buf)); | |
| 135 memset(fd_path, 0, arraysize(fd_path)); | |
| 136 snprintf(fd_path, arraysize(fd_path) - 1, "/proc/self/fd/%d", i); | |
| 137 ssize_t count = readlink(fd_path, buf, arraysize(buf) - 1); | |
| 138 if (count < 0) { | |
| 139 PLOG(ERROR) << "readlink failed for: " << fd_path; | |
| 140 continue; | |
| 141 } | |
| 142 | |
| 143 if (crash_ptr + count + 1 < crash_buffer + arraysize(crash_buffer)) { | |
| 144 crash_ptr = strncpy(crash_ptr, buf, count + 1); | |
| 145 } | |
| 146 LOG(ERROR) << i << ": " << buf; | |
| 147 } | |
| 148 LOG(FATAL) << "Logged for file descriptor exhaustion, crashing now"; | |
| 149 } | |
| 150 #endif // defined(OS_CHROMEOS) | |
| 93 } | 151 } |
| 94 *readonly_mapped_file = readonly_fd.release(); | 152 *readonly_mapped_file = readonly_fd.release(); |
| 95 | 153 |
| 96 return true; | 154 return true; |
| 97 } | 155 } |
| 98 #endif // !defined(OS_ANDROID) | 156 #endif // !defined(OS_ANDROID) |
| 99 | 157 |
| 100 } // namespace base | 158 } // namespace base |
| OLD | NEW |