linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* shmat(2) returns page size aligned memory address
@ 2017-10-08 15:37 Yubin Ruan
  2017-10-08 15:39 ` Yubin Ruan
  2017-10-09 14:27 ` [PATCH] " Yubin Ruan
  0 siblings, 2 replies; 4+ messages in thread
From: Yubin Ruan @ 2017-10-08 15:37 UTC (permalink / raw)
  To: linux-man, Michael Kerrisk (man-pages),
	linux-mm-u79uwXL29TY76Z2rM5mHXA

Hi Michael,
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].

I will create a patch later if that is acceptable.

Thanks,
Yubin

[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.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-10-09 14:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-08 15:37 shmat(2) returns page size aligned memory address Yubin Ruan
2017-10-08 15:39 ` Yubin Ruan
2017-10-09 14:27 ` [PATCH] " Yubin Ruan
2017-10-09  8:28   ` Michael Kerrisk (man-opages)

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).