Suppressing SIGBUS signals
Suppressing SIGBUS signals
Posted Jun 27, 2021 17:17 UTC (Sun) by NYKevin (subscriber, #129325)In reply to: Suppressing SIGBUS signals by roc
Parent article: Suppressing SIGBUS signals
I don't think it is semantically possible to avoid making a copy. The length of the mmap is equal to the length on disk, and because Linux went with the no-mandatory-file-locking model, that length can change at any time, regardless of whether you're using Rust, C, or a magnetic needle and a steady hand. If you want to end up with a "safe" object, you need it to not get suddenly truncated/zero-filled while you're halfway through processing it.
Making a copy also resolves issues of the form "What if someone decides to scribble all over the file without changing its length, while I'm halfway through processing it?" More generally, this falls into the "validate, then process" model of doing things - you can't validate something if it can change out from under you!