mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Dominic Chen <d.c.ddcc@gmail.com>
To: musl@lists.openwall.com
Subject: [musl] Issue with fread() and unaligned readv()
Date: Mon, 15 Mar 2021 17:39:43 -0400	[thread overview]
Message-ID: <50e56e3e-d448-c568-b3d8-fbab98939ff8@gmail.com> (raw)

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


             reply	other threads:[~2021-03-15 21:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 21:39 Dominic Chen [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50e56e3e-d448-c568-b3d8-fbab98939ff8@gmail.com \
    --to=d.c.ddcc@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).