mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Issue with fread() and unaligned readv()
@ 2021-03-15 21:39 Dominic Chen
  2021-03-15 21:51 ` Rich Felker
  0 siblings, 1 reply; 8+ messages in thread
From: Dominic Chen @ 2021-03-15 21:39 UTC (permalink / raw)
  To: musl

Not sure this counts as a problem in musl or the application, but I've 
been debugging a return error of EINVAL from `fread(&buf, 8, 16, f)`, 
where `f = fopen("/proc/self/pagemap", "r")`. Internally, musl converts 
this into a call to `readv(f->fd, iov, 2)`, where `iov = {{iov_base = 
buf, iov_len = 127}, {iov_base = f->buf, iov_len = 1024}}`. However, it 
turns out that the kernel VFS read implementation inside `pagemap_read` 
checks that both the file position and count are divisible by 
PM_ENTRY_BYTES (8 on x86_64), otherwise it rejects the read with EINVAL. 
In comparison, glibc's `_IO_file_xsgetn` does appear to try to maintain 
read alignment, although I haven't looked at it in detail.

Thanks,

Dominic


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-16 23:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 21:39 [musl] Issue with fread() and unaligned readv() Dominic Chen
2021-03-15 21:51 ` Rich Felker
2021-03-15 22:09   ` Alexander Monakov
2021-03-15 22:29     ` Rich Felker
2021-03-15 22:42       ` Alexander Monakov
2021-03-16  2:13         ` Rich Felker
2021-03-16  9:30           ` Alexander Monakov
2021-03-16 23:54             ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).