Commit 86e23fc
Avoids an unexpected crash with SIGBUS when trying to allocate a /dev/shm shared memory but there is not enough memory.
Indeed ftruncate doesn't ensure memory is properly allocated, it ony
changes the file size from the VFS point of view, but doesn't actually
allocate any memory. So ftruncate might work despite we have no memory
left, and later when trying to zero-memset the mmapped buffer, we might
actually get a SIGBUS signal crashing the whole process.
Instead, make sure we can allocate the whole shared memory using
posix_fallocate and gracefully handle allocation problems, without
crashing.
The chromium project faced a similar issue in the past:
https://bugs.chromium.org/p/chromium/issues/detail?id=951431
1 parent ef4a9a0 commit 86e23fc
1 file changed
+9
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 184 | + | |
| 185 | + | |
190 | 186 | | |
191 | 187 | | |
192 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
193 | 196 | | |
194 | 197 | | |
195 | 198 | | |
| |||
0 commit comments