]> git.ipfire.org Git - thirdparty/man-pages.git/commit - man2/shmop.2
shmop.2: Note that return value of shmat() is page-aligned
authorYubin Ruan <ablacktshirt@gmail.com>
Mon, 9 Oct 2017 14:27:27 +0000 (22:27 +0800)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Mon, 9 Oct 2017 08:26:10 +0000 (10:26 +0200)
commitfe03cbd88e75b38f9246a1f269e530251f45217e
tree6ee180c643da82f8a43226cd9b6b9d256ab38600
parentb739c378ffb1f455f85a1e79ea7aa829cb638a41
shmop.2: Note that return value of shmat() is page-aligned

At the current man page for shmat(2)[1], there is no mentioning
whether the returned memory address of shmat(2) will be page size
aligned or not. As that is quite important to many applications(e.g.,
those that use locks heavily and would like to avoid some locks by
some atomic guarantees provided by the CPU), it would be great to
specify that for Linux.

I walked down the current implementation of shmat(2) in the latest
kernel src and found that shmat(2) does return a page size aligned
memory address:

SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)
 -> do_shmat(...)
 -> do_mmap_pgoff(...)
 -> do_mmap(...)
 -> get_unmapped_area(...)
 -> get_area(...) -> offset_in_page(addr)

there is a `offset_in_page(addr)' assertion at the end and if that is
true a -EINVAL would be returned, by which we can be sure that
shmat(2) will return a page size aligned memory address on success[2].

[1]: http://man7.org/linux/man-pages/man2/shmat.2.html
[2]: there is also a `offset_in_page(2)' in get_unmapped_area(...),
but that doesn't lead to -EINVAL...I am not sure whether the logic of
that code is right.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man2/shmop.2