3 ms·
Does this handle the case where you try to parse a short string which is abutting the end of a page, and the next page is unmapped? The problem is you over-rea
by rwmj 3y ago
Does this handle the case where you try to parse a short string which is abutting the end of a page, and the next page is unmapped? The problem is you over-read and crash when you try to read the unmapped page. Looking at the code it doesn't seem to take account of that case. (On the other hand, maybe the AVX instructions don't do an actual read if the field is masked? In which case it would be fine.)
We had a similar case with some AVX-optimized string operation in glibc.
- anonymoushn 3y agoIt looks like the instructions handle this https://stackoverflow.com/questions/54497141/when-using-a-mask-register-with-avx-512-load-and-stores-is-a-fault-raised-for-i https://stackoverflow.com/questions/54497141/when-using-a-ma...
- Findecanor 3y agoYes. The bounds from the std::string are used to create a read-mask which is used in a masked load that does not fault on lanes outside the mask. If the length had been unknown (say, a C-style null-terminated string) then the code would have needed to be more complex. You would either have to find the length before-hand or done only aligned loads. BTW. ARM's SVE and RISC-V's Vector extension have special "first fault" load-instructions that make that case simpler: they instead modify the vector's mask/length to the lowest-numbered lane that would have faulted.