Re: Linux Syscalls, POSIX Functions and other generic Library Functions.
- From: Joe Pfeiffer <pfeiffer@xxxxxxxxxxx>
- Date: 28 Jul 2006 20:12:31 -0600
fabio de francesco <cancella.fabiomdf@xxxxxxxxxxxxxxxx> writes:
mprotect(2) has an EFAULT error that is not present in mprotect(P). The
second has an EAGAIN that is not present in the first one.
You should expect the version in Chapter 2 to be correct (as other
posters have pointed out, the man pages may have errors -- just like
any other documentation. But until you have reason to think a page is
wrong, assume it's right).
Anyway this is not the point of my question. I simply would like to know
which of the two APIs is invoked when you write "mprotect(<parameters>)" in
a C program. Is the syscall invoked, perhaps through a C library wrapper
that doesn't modify any behaviour of the syscall as it is exported from the
kernel, or instead is the POSIX library invoked?
I suppose I should more clearly show what I mean. Sorry again for my
English...
My doubts come out from some API's manual pages. I don't understand why some
of them clearly state that the _syscallX() macro must be used to invoke the
syscall while other manual pages don't. See the following example from the
synopsis of mmap2(2) manual page:
#include <sys/mman.h>
#include <syscall.h>
#include <errno.h>
_syscall6(void *, mmap2, void *, start, size_t, length,
int, prot, int, flags, int, fd, off_t, pgoffset)
void * mmap2(void *start, size_t length, int prot,
int flags, int fd, off_t pgoffset);
I think that it clearly states that in order to call the mmap2(2) syscall
you must use the _syscall6 macro because libC doesn't provide any wrapper
(or maybe that any hypothetical library corresponding function provides a
different behaviour than the original system call)
Right. And the man page also says, in essence, "don't use this
call". It's documented because it is a system call, but since it's
not part of the C library you shouldn't use it unless you've got a
really compelling reason involving doing something *very*
Linux-specific. I'll note that there are calls that get this warning
that you may indeed need to use in a program, such as iopl() if you're
doing user-level access to devices. That's a compelling reason to use
a call in spite of non-portability; mmapping with a page count instead
of a byte count isn't.
Instead the synopsis of mprotect(2) manual page is simply:
#include <sys/mman.h>
int mprotect(const void *addr, size_t len, int prot);
There is no reference to any needed _syscallX. It seems it states that in
order to invoke the mprotect(2) syscall there is no need of the _syscall
macro. So again, my simple question is: what API is the C/C++
statement "mprotect(addr, len, prot)" calling? syscall mprotect(2) or
library's POSIX function mprotect(P)?
Again, correct. And you should expect the version in chapter 2 to be
correct. I do feel like I need to point out that when the chap. 2
version says
CONFORMING TO
SVr4, POSIX.1b (formerly POSIX.4). SVr4 defines an additional
error code EAGAIN. The SVr4 error conditions don't map neatly
onto Linux's. POSIX says that mprotect() can be used only on
regions of memory obtained from mmap(2).
it really isn't much of an inference that Linux doesn't support
POSIX's EAGAIN on this call, either.
--
Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605
Department of Computer Science FAX -- (505) 646-1002
New Mexico State University http://www.cs.nmsu.edu/~pfeiffer
.
- References:
- Linux Syscalls, POSIX Functions and other generic Library Functions.
- From: fabio de francesco
- Re: Linux Syscalls, POSIX Functions and other generic Library Functions.
- From: jasen
- Re: Linux Syscalls, POSIX Functions and other generic Library Functions.
- From: fabio de francesco
- Linux Syscalls, POSIX Functions and other generic Library Functions.
- Prev by Date: Re: Linux Syscalls, POSIX Functions and other generic Library Functions.
- Next by Date: GTK About Dialog Crash
- Previous by thread: Re: Linux Syscalls, POSIX Functions and other generic Library Functions.
- Next by thread: Shared Object vs IPC
- Index(es):
Relevant Pages
|