Better HN
topnewbestaskshowjobs
Log inSign up

oomo

2 karma · joined Nov 23, 2020 (6y ago) · 1 submissions

Submissions

comment 6y ago · link · parent

Leaving this here as comments on that blog seem broken. TL;DR: access(2) is a bit more lightweight than write(2) for this purpose.

Consider the following (from memory, untested):

word_t peek(word_t addr, int success) { word_t ret; errno = 0; access(addr, F_OK); if (success) success = (errno != EFAULT); if (errno != EFAULT) ret = *addr; return ret; }

I first learnt about this trick in http://www.gcu-squad.org/2005/08/non-ce-n-est-pas-sale%21/