MCPcopy Create free account
hub / github.com/ElementsProject/lightning / ptr_valid_batch

Function ptr_valid_batch

ccan/ccan/ptr_valid/ptr_valid.c:273–311  ·  view source on GitHub ↗

msync seems most well-defined test, but page could be mapped with * no permissions, and can't distiguish readonly from writable. */

Source from the content-addressed store, hash-verified

271/* msync seems most well-defined test, but page could be mapped with
272 * no permissions, and can't distiguish readonly from writable. */
273bool 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
313bool ptr_valid_batch_string(struct ptr_valid_batch *batch, const char *p)
314{

Callers 2

ptr_valid_batch_stringFunction · 0.70
ptr_validFunction · 0.70

Calls 2

check_with_mapsFunction · 0.85
check_with_childFunction · 0.85

Tested by

no test coverage detected