|
From: Nicholas N. <nj...@ca...> - 2004-02-14 23:04:47
|
On Sat, 14 Feb 2004, Tom Hughes wrote: > > AIUI, the fdsets are bit arrays, with 1024 bits, each bit representing an > > fd; if bit N is set in an array, select will watch fd N appropriately. > > The first arg, n, is the highest N for which a bit is set, plus one. > > Therefore, select() will read at least n bits in each array. Thus, the > > a1/8 is close, but not quite right; it's not rounding up to allow for any > > unused bits at the end of the read bytes. For example, most of the time n > > will be less than 8, in which case the length passed to pre_mem_read will > > be zero! I think it needs to be (a1+7)/8. > > The problem with rounding up instead of down is that it may cause > false positives because there is no guarantee that all the bits in > the final byte will be defined - if I pass 3 as the first argument > that I only have to fill in the first three bits of the first byte > and the others may be undefined as the kernel won't pay any attention > to them. > > The problem is that although valgrind tracks definedness at the bit > level the interface that the syscall stuff uses to check it only works > at byte granularity. Right, I hadn't thought of that. However, I'm still in favour of rounding up. In general, what does pre_mem_read indicate -- bytes that are read, or bytes that are used? I favour the former. It seems to me the right approach is to smarten Memcheck to be aware of this case. Failing that, being conservative and saying the whole byte is read seems better to me, since I'd rather a false positive than a false negative. N |