Discussion:
[musl] Why musl define PAGE_SIZE
Yuxin Ren
2015-09-11 19:28:52 UTC
Permalink
Hi ,

I found in the bits/limits.h file, musl defines PAGE_SIZE macro .
I think this macro is always defined by operating system, not libc.

Why does musl define this marco?

Thanks a lot.
Yuxin
Isaac Dunham
2015-09-11 19:44:02 UTC
Permalink
Post by Yuxin Ren
Hi,
I found in the bits/limits.h file, musl defines PAGE_SIZE macro .
I think this macro is always defined by operating system, not libc.
Why does musl define this marco?
It's required to be in limits.h, which has to be provided by libc for a
full implementation.
Hypothetically, we could get it from the Linux headers.
But the Linux headers can and sometimes do introduce definitions and
structs that violate the header namespaces, resulting in collisions
(ie, kernel header defines struct foo, application defines struct foo
without including any headers that *should* define it, application fails
to compile.)

HTH,
Isaac Dunham
Yuxin Ren
2015-09-11 19:53:38 UTC
Permalink
But I do not think other libcs define PAGE_SIZE, such as glibc or diet-libc.
Is that true?

Thanks
Post by Isaac Dunham
Post by Yuxin Ren
Hi,
I found in the bits/limits.h file, musl defines PAGE_SIZE macro .
I think this macro is always defined by operating system, not libc.
Why does musl define this marco?
It's required to be in limits.h, which has to be provided by libc for a
full implementation.
Hypothetically, we could get it from the Linux headers.
But the Linux headers can and sometimes do introduce definitions and
structs that violate the header namespaces, resulting in collisions
(ie, kernel header defines struct foo, application defines struct foo
without including any headers that *should* define it, application fails
to compile.)
HTH,
Isaac Dunham
Rich Felker
2015-09-11 20:10:11 UTC
Permalink
Post by Isaac Dunham
Post by Yuxin Ren
Hi,
I found in the bits/limits.h file, musl defines PAGE_SIZE macro .
I think this macro is always defined by operating system, not libc.
Why does musl define this marco?
It's required to be in limits.h, which has to be provided by libc for a
full implementation.
It's not required. Lack of a definition means you have to query the
value at runtime with sysconf(_SC_PAGESIZE). But failure to provide a
value on platforms where it is constant just gratuitously pessimizes
programs that need to know page size.

Rich

Rich Felker
2015-09-11 20:01:11 UTC
Permalink
Post by Yuxin Ren
Hi ,
I found in the bits/limits.h file, musl defines PAGE_SIZE macro .
I think this macro is always defined by operating system, not libc.
Why does musl define this marco?
The page size, and whether it's a constant or variable, is part of the
target ABI. musl provides the PAGE_SIZE macro on targets where it's
constant because it may be useful to applications that want to
optimize for the case where a fixed page size is known. This is no
different from providing definitions reflecting other parts of the ABI
like type definitions or macro constants for communicating with system
interfaces.

Rich
Loading...