-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Description
Clang's #embed implementation doesn't behave properly when applied to a device:
int per_build_entropy[] = {
#embed "/dev/random" limit(1024)
};Instead it treats devices as being empty -- in the above case, this leads to the array being initialized with zeroes! This is probably because we're using the st_size field produced by stat, but that only lists the size of the file if applied to a regular file:
st_sizeThis field gives the size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.
While we try to detect this case and use stream IO instead of mmap, we only do so when we weren't given a MapSize, which in this case we presumably will be due to the limit(1024). And the code that handles the case where we have no MapSize does not handle the case where we're opening a device rather than a regular file. Perhaps shouldUseMmap should return false unless it's operating on a regular file?