msync seems most well-defined test, but page could be mapped with * no permissions, and can't distiguish readonly from writable. */
| 271 | /* msync seems most well-defined test, but page could be mapped with |
| 272 | * no permissions, and can't distiguish readonly from writable. */ |
| 273 | bool ptr_valid_batch(struct ptr_valid_batch *batch, |
| 274 | const void *p, size_t alignment, size_t size, bool write) |
| 275 | { |
| 276 | char *start, *end; |
| 277 | bool ret; |
| 278 | |
| 279 | if ((intptr_t)p & (alignment - 1)) { |
| 280 | errno = EFAULT; |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | start = (void *)((intptr_t)p & ~(getpagesize() - 1)); |
| 285 | end = (void *)(((intptr_t)p + size - 1) & ~(getpagesize() - 1)); |
| 286 | |
| 287 | /* We cache single page hits. */ |
| 288 | if (start == end) { |
| 289 | if (batch->last && batch->last == start |
| 290 | && batch->last_write == write) { |
| 291 | if (!batch->last_ok) |
| 292 | errno = EFAULT; |
| 293 | return batch->last_ok; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if (batch->num_maps) |
| 298 | ret = check_with_maps(batch, p, size, write); |
| 299 | else |
| 300 | ret = check_with_child(batch, p, size, write); |
| 301 | |
| 302 | if (start == end) { |
| 303 | batch->last = start; |
| 304 | batch->last_ok = ret; |
| 305 | batch->last_write = write; |
| 306 | } |
| 307 | |
| 308 | if (!ret) |
| 309 | errno = EFAULT; |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | bool ptr_valid_batch_string(struct ptr_valid_batch *batch, const char *p) |
| 314 | { |
no test coverage detected