Commit Graph

75 Commits

Author SHA1 Message Date
Rich Felker 321f4fa906 add max_align_t definition for C11 and C++11
unfortunately this needs to be able to vary by arch, because of a huge
mess GCC made: the GCC definition, which became the ABI, depends on
quirks in GCC's definition of __alignof__, which does not match the
formal alignment of the type.

GCC's __alignof__ unexpectedly exposes the an implementation detail,
its "preferred alignment" for the type, rather than the formal/ABI
alignment of the type, which it only actually uses in structures. on
most archs the two values are the same, but on some (at least i386)
the preferred alignment is greater than the ABI alignment.

I considered using _Alignas(8) unconditionally, but on at least one
arch (or1k), the alignment of max_align_t with GCC's definition is
only 4 (even the "preferred alignment" for these types is only 4).
2014-08-20 17:20:14 -04:00
Rich Felker de7e99c585 make pointers used in robust list volatile
when manipulating the robust list, the order of stores matters,
because the code may be asynchronously interrupted by a fatal signal
and the kernel will then access the robust list in what is essentially
an async-signal context.

previously, aliasing considerations made it seem unlikely that a
compiler could reorder the stores, but proving that they could not be
reordered incorrectly would have been extremely difficult. instead
I've opted to make all the pointers used as part of the robust list,
including those in the robust list head and in the individual mutexes,
volatile.

in addition, the format of the robust list has been changed to point
back to the head at the end, rather than ending with a null pointer.
this is to match the documented kernel robust list ABI. the null
pointer, which was previously used, only worked because faults during
access terminate the robust list processing.
2014-08-17 00:46:26 -04:00
Szabolcs Nagy 002e8d84c5 add syscall numbers for the new renameat2 syscall
it's like rename but with flags eg. to allow atomic exchange of two files,
introduced in linux 3.15 commit 520c8b16505236fc82daa352e6c5e73cd9870cff
2014-07-20 18:42:21 +02:00
Szabolcs Nagy fd9571e20a add sched_{get,set}attr syscall numbers and SCHED_DEADLINE macro
linux 3.14 introduced sched_getattr and sched_setattr syscalls in
commit d50dde5a10f305253cbc3855307f608f8a3c5f73

and the related SCHED_DEADLINE scheduling policy in
commit aab03e05e8f7e26f51dee792beddcb5cca9215a5

but struct sched_attr "extended scheduling parameters data structure"
is not yet exported to userspace (necessary for using the syscalls)
so related uapi definitions are not added yet.
2014-05-30 13:06:51 -04:00
Rich Felker 468bc11ed0 fix missing SO_RCVBUFFORCE and SO_SNDBUFFORCE in mips socket.h 2014-04-30 14:47:06 -04:00
Szabolcs Nagy fcea534e57 fix RLIMIT_ constants for mips
The mips arch is special in that it uses different RLIMIT_
numbers than other archs, so allow bits/resource.h to override
the default RLIMIT_ numbers (empty on all archs except mips).
Reported by orc.
2014-04-15 19:17:52 -04:00
Rich Felker 9505bfbc40 fix signal.h breakage from moving stack_t to arch-specific bits
in the previous changes, I missed the fact that both the prototype of
the sigaltstack function and the definition of ucontext_t depend on
stack_t.
2014-03-18 23:27:45 -04:00
Rich Felker 12f37cdee5 fix mips stack_t
like almost everything on mips, this is gratuitously different.
2014-03-18 23:13:56 -04:00
Rich Felker bd5f221eaa move signal.h definition of stack_t to arch-specific bits
it's different at least on mips. mips version will be fixed in a
separate commit to show the change.
2014-03-18 23:12:40 -04:00
Rich Felker cee45f9cb2 fix size of mips jmp_buf
the excess space was unused and unintentional. this change does not
affect the ABI between applications and libc. while it does
theoretically affect linkage between third-party translation units
using jmp_buf as part of a structure, we've already changed jmp_buf at
least once on all archs, and problems were never observed, likely
because such usage would be very unusual. in any case it's best to get
things right now rather than making changes sometime during the 1.0.x
series or later.
2014-03-18 21:52:24 -04:00
Rich Felker d444064d5a remove useless and incorrect uc_regspace member from mips ucontext_t
this seems to have been copied erroneously from the arm version of the
file. it's fairly harmless but it's a mistake and better to fix now
than later.
2014-03-18 21:37:05 -04:00
Szabolcs Nagy 7673acd315 fix statfs struct on mips
The mips statfs struct layout is different than on other archs, so the
statfs, fstatfs, statvfs and fstatvfs APIs were broken on mips.
Now the ordering is fixed, the types are kept consistent with other archs.
2014-03-12 18:08:58 +01:00
Szabolcs Nagy 3ceb89ed3f fix semid_ds structure on mips
This used to be broken when all archs had the same semid_ds definition:
there is no padding around the time_t members on mips.
2014-03-12 11:46:17 +01:00
Rich Felker f6e2f7e13f move struct semid_ds to from shared sys/sem.h to bits
the definition was found to be incorrect at least for powerpc, and
fixing this cleanly requires making the definition arch-specific. this
will allow cleaning up the definition for other archs to make it more
specific, and reversing some of the ugliness (time_t hacks) introduced
with the x32 port.

this first commit simply copies the existing definition to each arch
without any changes. this is intentional, to make it easier to review
changes made on a per-arch basis.
2014-03-11 15:27:13 -04:00
Szabolcs Nagy e5bb165bed mips: add mips-sf subarch support (soft-float)
Userspace emulated floating-point (gcc -msoft-float) is not compatible
with the default mips abi (assumes an FPU or in kernel emulation of it).
Soft vs hard float abi should not be mixed, __mips_soft_float is checked
in musl's configure script and there is no runtime check. The -sf subarch
does not save/restore floating-point registers in setjmp/longjmp and only
provides dummy fenv implementation.
2014-02-24 23:16:29 +01:00
rofl0r 0f169cbb79 sys/shm.h: move arch specific structs to bits/ 2014-02-23 11:07:18 +01:00
Rich Felker a627eb3586 fix namespace violations in termios.h, at least mostly
the fix should be complete on archs that use the generic definitions
(i386, arm, x86_64, microblaze), but mips and powerpc have not been
checked thoroughly and may need more fixes.
2014-01-08 19:20:55 -05:00
Szabolcs Nagy f7d348ec39 add O_TMPFILE flag, new in linux 3.11
definition in linux:
 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
where __O_TMPFILE and O_DIRECTORY are arch specific
2013-11-23 23:47:48 +00:00
Rich Felker 326e5c2e27 fix the nominal type of LDBL_* limits on archs with ld64
previously these macros wrongly had type double rather than long
double. I see no way an application could detect the error in C99, but
C11's _Generic can trivially detect it.

at the same time, even though these archs do not have excess
precision, the number of decimal places used to represent these
constants has been increased to 21 to be consistent with the decimal
representations used for the DBL_* macros.
2013-11-20 18:28:18 -05:00
Rich Felker 97789d3e5d remove duplicate lines from mips bits/syscall.h 2013-09-26 14:11:18 -04:00
Szabolcs Nagy b20760c023 support configurable page size on mips, powerpc and microblaze
PAGE_SIZE was hardcoded to 4096, which is historically what most
systems use, but on several archs it is a kernel config parameter,
user space can only know it at execution time from the aux vector.

PAGE_SIZE and PAGESIZE are not defined on archs where page size is
a runtime parameter, applications should use sysconf(_SC_PAGE_SIZE)
to query it. Internally libc code defines PAGE_SIZE to libc.page_size,
which is set to aux[AT_PAGESZ] in __init_libc and early in __dynlink
as well. (Note that libc.page_size can be accessed without GOT, ie.
before relocations are done)

Some fpathconf settings are hardcoded to 4096, these should be actually
queried from the filesystem using statfs.
2013-09-15 02:00:32 +00:00
Rich Felker 9b35ed3fef fix mips sysv ipc bits headers
msg.h was wrong for big-endian (wrong endiannness padding).
shm.h was just plain wrong (mips is not supposed to have padding).

both changes were tested using libc-test on qemu-system-mips.
2013-09-14 14:44:03 -04:00
Rich Felker 7c440977db fix _NSIG and SIGRTMAX on mips
a mips signal mask contains 128 bits, enough for signals 1 through
128. however, the exit status obtained from the wait-family functions
only has room for values up to 127. reportedly signal 128 was causing
kernelspace bugs, so it was removed from the kernel recently; even
without that issue, however, it was impossible to support it correctly
in userspace.

at the same time, the bug was masked on musl by SIGRTMAX incorrectly
yielding 64 on mips, rather than the "correct" value of 128. now that
the _NSIG issue is fixed, SIGRTMAX can be fixed at the same time,
exposing the full range of signals for application use.

note that the (nonstandardized) libc _NSIG value is actually one
greater than the max signal number, and also one greater than the
kernel headers' idea of _NSIG. this is the reason for the discrepency
with the recent kernel changes. since reducing _NSIG by one brought it
down from 129 to 128, rather than from 128 to 127, _NSIG/8, used
widely in the musl sources, is unchanged.
2013-08-10 23:39:43 -04:00
Rich Felker 9693501c15 change jmp_buf to share an underlying type and struct tag with sigjmp_buf
this is necessary to meet the C++ ABI target. alternatives were
considered to avoid the size increase for non-sig jmp_buf objects, but
they seemed to have worse properties. moreover, the relative size
increase is only extreme on x86[_64]; one way of interpreting this is
that, if the size increase from this patch makes jmp_buf use too much
memory, then the program was already using too much memory when built
for non-x86 archs.
2013-07-24 02:17:02 -04:00
Rich Felker 3f08154ac4 remove SIG_ATOMIC_MIN/MAX from stdint bits headers
i386 was done with the big commit but I missed the others
2013-07-22 17:02:03 -04:00
Rich Felker 1c6cace0bf fix regression in size of nlink_t (broken stat struct) on x86_64
rather than moving nlink_t back to the arch-specific file, I've added
a macro _Reg defined to the canonical type for register-size values on
the arch. this is not the same as _Addr for (not-yet-supported)
32-on-64 pseudo-archs like x32 and mips n32, so a new macro was
needed.
2013-07-22 15:45:28 -04:00
Rich Felker c4dd0c98ba change wint_t to unsigned
aside from the obvious C++ ABI purpose for this change, it also brings
musl into alignment with the compiler's idea of the definition of
wint_t (use in -Wformat), and makes the situation less awkward on ARM,
where wchar_t is unsigned.

internal code using wint_t and WEOF was checked against this change,
and while a few cases of storing WEOF into wchar_t were found, they
all seem to operate properly with the natural conversion from unsigned
to signed.
2013-07-22 13:05:41 -04:00
Rich Felker 9448b0513e refactor headers, especially alltypes.h, and improve C++ ABI compat
the arch-specific bits/alltypes.h.sh has been replaced with a generic
alltypes.h.in and minimal arch-specific bits/alltypes.h.in.

this commit is intended to have no functional changes except:
- exposing additional symbols that POSIX allows but does not require
- changing the C++ name mangling for some types
- fixing the signedness of blksize_t on powerpc (POSIX requires signed)
- fixing the limit macros for sig_atomic_t on x86_64
- making dev_t an unsigned type (ABI matching goal, and more logical)

in addition, some types that were wrongly defined with long on 32-bit
archs were changed to int, and vice versa; this change is
non-functional except for the possibility of making pointer types
mismatch, and only affects programs that were using them incorrectly,
and only at build-time, not runtime.

the following changes were made in the interest of moving
non-arch-specific types out of the alltypes system and into the
headers they're associated with, and also will tend to improve
application compatibility:
- netdb.h now includes netinet/in.h (for socklen_t and uint32_t)
- netinet/in.h now includes sys/socket.h and inttypes.h
- sys/resource.h now includes sys/time.h (for struct timeval)
- sys/wait.h now includes signal.h (for siginfo_t)
- langinfo.h now includes nl_types.h (for nl_item)

for the types in stdint.h:
- types which are of no interest to other headers were moved out of
  the alltypes system.
- fast types for 8- and 64-bit are hard-coded (at least for now); only
  the 16- and 32-bit ones have reason to vary by arch.

and the following types have been changed for C++ ABI purposes;
- mbstate_t now has a struct tag, __mbstate_t
- FILE's struct tag has been changed to _IO_FILE
- DIR's struct tag has been changed to __dirstream
- locale_t's struct tag has been changed to __locale_struct
- pthread_t is defined as unsigned long in C++ mode only
- fpos_t now has a struct tag, _G_fpos64_t
- fsid_t's struct tag has been changed to __fsid_t
- idtype_t has been made an enum type (also required by POSIX)
- nl_catd has been changed from long to void *
- siginfo_t's struct tag has been removed
- sigset_t's has been given a struct tag, __sigset_t
- stack_t has been given a struct tag, sigaltstack
- suseconds_t has been changed to long on 32-bit archs
- [u]intptr_t have been changed from long to int rank on 32-bit archs
- dev_t has been made unsigned

summary of tests that have been performed against these changes:
- nsz's libc-test (diff -u before and after)
- C++ ABI check symbol dump (diff -u before, after, glibc)
- grepped for __NEED, made sure types needed are still in alltypes
- built gcc 3.4.6
2013-07-22 11:22:36 -04:00
Rich Felker 648c3b4e18 change uid_t, gid_t, and id_t to unsigned types
this change is both to fix one of the remaining type (and thus C++
ABI) mismatches with glibc/LSB and to allow use of the full range of
uid and gid values, if so desired.

passwd/group access functions were not prepared to deal with unsigned
values, so they too have been fixed with this commit.
2013-07-19 01:34:28 -04:00
Rich Felker a3e2f3c2b1 respect iso c namespace in stdio.h and wchar.h regarding va_list
despite declaring functions that take arguments of type va_list, these
headers are not permitted by the c standard to expose the definition
of va_list, so an alias for the type must be used. the name
__isoc_va_list was chosen to convey that the purpose of this alternate
name is for iso c conformance, and to avoid the multitude of names
which gcc mangles with its hideous "fixincludes" monstrosity, leading
to serious header breakage if these "fixes" are run.
2013-06-25 22:26:20 -04:00
Rich Felker d926565355 Merge remote-tracking branch 'nsz/review' 2013-05-26 18:22:12 -04:00
Szabolcs Nagy 41c34d188a fix ioctl _IOR, _IOW, etc macros to avoid signed overflow (2<<30) 2013-05-26 15:49:08 +00:00
Rich Felker 5e642b5a23 change underlying type of clock_t to be uniform and match ABI
previously we were using an unsigned type on 32-bit systems so that
subtraction would be well-defined when it wrapped, but since wrapping
is non-conforming anyway (when clock() overflows, it has to return -1)
the only use of unsigned would be to buy a little bit more time before
overflow. this does not seem worth having the type vary per-arch
(which leads to more arch-specific bugs) or disagree with the ABI musl
(mostly) follows.
2013-05-23 20:38:51 -04:00
Rich Felker 22730d6560 add FLT_TRUE_MIN, etc. macros from C11
there was some question as to how many decimal places to use, since
one decimal place is always sufficient to identify the smallest
denormal uniquely. for now, I'm following the example in the C
standard which is consistent with the other min/max macros we already
had in place.
2013-05-17 18:38:42 -04:00
Rich Felker f77bab5933 fix type issues in stdint.h so underlying types of 64-bit types match ABI 2013-04-04 20:09:50 -04:00
Rich Felker c7af271000 eliminate bits/wchar.h
the preprocessor can reliably determine the signedness of wchar_t.
L'\0' is used for 0 in the expressions so that, if the underlying type
of wchar_t is long rather than int, the promoted type of the
expression will match the type of wchar_t.
2013-04-04 19:57:23 -04:00
rofl0r 47cf4919fc re-add useconds_t
this type was removed back in 5243e5f160 ,
because it was removed from the XSI specs.
however some apps use it.
since it's in the POSIX reserved namespace, we can expose it
unconditionally.
2013-04-02 04:58:14 +02:00
Szabolcs Nagy 8d3ee05754 add syscall numbers for the new kcmp and finit_module syscalls
and remove syscall todos from microblaze
2013-04-01 18:02:32 +00:00
Szabolcs Nagy ca2300d9ac add the new SO_REUSEPORT socket option to mips and powerpc
SO_REUSEPORT implementation was merged in the linux kernel commit
c617f398edd4db2b8567a28e899a88f8f574798d 2013-01-23
2013-04-01 17:54:39 +00:00
Rich Felker da1442c9a8 fix types for wctype_t and wctrans_t
wctype_t was incorrectly "int" rather than "long" on x86_64. not only
is this an ABI incompatibility; it's also a major design flaw if we
ever wanted wctype_t to be implemented as a pointer, which would be
necessary if locales support custom character classes, since int is
too small to store a converted pointer. this commit fixes wctype_t to
be unsigned long on all archs, matching the LSB ABI; this change does
not matter for C code, but for C++ it affects mangling.

the same issue applied to wctrans_t. glibc/LSB defines this type as
const __int32_t *, but since no such definition is visible, I've just
expanded the definition, int, everywhere.

it would be nice if these types (which don't vary by arch) could be in
wctype.h, but the OB XSI requirement in POSIX that wchar.h expose some
types and functions from wctype.h precludes doing so. glibc works
around this with some hideous hacks, but trying to duplicate that
would go against the intent of musl's headers.
2013-03-04 19:22:14 -05:00
Szabolcs Nagy 000806cde6 add missing mmap options and madvices to bits/mman.h based on linux headers 2013-01-12 19:42:39 +01:00
Szabolcs Nagy 73bb048951 add missing F_GETOWNER_UIDS flag to bits/fcntl.h 2013-01-12 19:42:39 +01:00
rofl0r 7e0d4fce41 add more arch-specific MAP_ macros to bits/mman.h
these are also needed by qemu.
2012-12-06 16:57:22 +01:00
rofl0r 0e10f74006 add MAP_NORESERVE to bits/mman.h
this is needed for qemu, and since it differs for each arch
it can't be circumvented easily by using a macro in CFLAGS.
2012-12-06 01:26:51 +01:00
Rich Felker a8da6c2f28 fixup mcontext stuff to expost gregset_t/fpregset_t as appropriate 2012-11-25 23:04:23 -05:00
Rich Felker 4b75f4ed8d make sys/procfs.h mostly work on most archs
these structures are purely for use by trace/debug tools and tools
working with core files. the definition of fpregset_t, which was
previously here, has been removed because it was wrong; fpregset_t
should be the type used in mcontext_t, not the type used in
ptrace/core stuff.
2012-11-25 22:28:18 -05:00
Rich Felker 4acc95e497 begin sys/user.h and sys/reg.h fixes for ports
aside from microblaze, these should be roughly correct for all archs
now. some misc junk macros and typedefs are missing, which should
probably be added for max compatibility with trace/debug tools.
2012-11-23 20:05:43 -05:00
Rich Felker 144dc4f479 fix termios constants on mips 2012-11-23 17:23:38 -05:00
Rich Felker c72fc23843 sigcontext/mcontext cleanup for arch-specific bits
with these changes, the members/types of mcontext_t and related stuff
should closely match the glibc definitions. unlike glibc, however, the
definitions here avoid using typedefs as much as possible and work
directly with the underlying types, to minimize namespace pollution
from signal.h in the default (_BSD_SOURCE) profile.

this is a first step in improving compatibility with applications
which poke at context/register information -- mainly debuggers, trace
utilities, etc. additional definitions in ucontext.h and other headers
may be needed later.

if feature test macros are used to request a conforming namespace,
mcontext_t is replaced with an opaque structure of the equivalent size
and alignment; conforming programs cannot examine its contents anyway.
2012-11-23 14:35:25 -05:00
Rich Felker 7538708f8b fix up leftover, incorrect NSIG definitions in arch-specific signal.h 2012-11-23 12:20:53 -05:00