Commit Graph

660 Commits

Author SHA1 Message Date
Augustin Cavalier e4104854c3 if_dl: Increase size of sdl_data from 20 to 46 bytes.
FreeBSD's is presently 46 bytes. CID 1422869 warns that it can get overrun
in if_attach() in copying if_xname which is IF_NAMESIZE bytes (32).

This breaks ABI, but BeOS did not have sockaddr_dl, it is only a modern-GCC
ABI break. Since most applications assume that sockaddr_dl is variable-length
and is null-terminated, as well as not used very often, hopefully this will
require relatively few rebuilds.
2018-06-20 21:26:21 -04:00
Leorize cedb0e1179 uchar: Introduce C11 uchar.h
Currently this implementation only supports UTF-32
2018-01-14 14:42:34 +00:00
Augustin Cavalier 8d4324628d syslog.h: Add LOG_NFACILITIES, LOG_FACMASK, LOG_FAC.
Not in the POSIX specification, but defined (not behind any guards)
in (at least) FreeBSD, NetBSD, glibc, and macOS.

Found by miqlas and myself while working on porting GNU inetutils.
2017-12-26 17:09:26 -05:00
Alexander von Gluck IV 1d3d336a97 libbsd: Move lutimes to bsd compat
* Rework be149e8ccf since lutimes isn't posix
2017-11-17 14:27:26 -06:00
Alexander von Gluck IV be149e8ccf libroot/posix: Add lutimes for better posix compatibility
* Didn't exist on BeOS, but exists most other places.
* Update times of a file, not following symbolic links.
2017-11-16 00:38:54 -06:00
Jérôme Duval 2976cf85a4 libroot.so: make first parameter of dladdr() const.
This follows up on a mail from 2011:
https://www.freelists.org/post/haiku-development/Changing-dladdr-to-take-const-void-for-first-parameter
2017-09-15 23:09:24 +02:00
Jérôme Duval ccd42320c4 libroot: add posix_spawn(). 2017-09-12 19:42:57 +02:00
Jessica Hamilton f995cdcc5f Revert "endian.h: add BSD extensions when _BSD_SOURCE is defined."
This reverts commit b8cfd96db1.
2017-09-11 07:06:52 +12:00
Jessica Hamilton b8cfd96db1 endian.h: add BSD extensions when _BSD_SOURCE is defined. 2017-09-10 07:37:32 +12:00
Jérôme Duval 26740b2889 POSIX: F_DUPFD_CLOEXEC support (POSIX.1-2008).
* fix #12187.
2017-08-24 17:54:50 +02:00
Jérôme Duval 6c9e01265b pthread_rwlock: use a mutex for process-private locks.
* instead of a benaphore.
* define PTHREAD_RWLOCK_INITIALIZER.
* adjust Init(), Destroy(), StructureLock() and StructureUnlock().
2017-07-27 18:33:53 +02:00
Joseph C, Hill 42123119d2 unistd.h: define _POSIX_BARRIERS
This constant was missing in unistd.h and some applications
use it to check for pthread barriers support.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

ticket : #13601
2017-07-14 09:38:41 +02:00
Augustin Cavalier 39efd913c1 Switch to a 64-bit time_t everywhere except 32-bit x86.
Thus, BeOS compatibility is preserved (and there is no risk of
breaking GCC5<->GCC2 interoperation on hybrid builds.)

This commit only makes the actual change, the build fixes are
in the next commit.
2017-06-06 17:38:17 -04:00
Adrien Destugues 36576214eb Remove __STDC_FORMAT/CONSTANT_MACROS
These were added in C99 to avoid interferring with C++, but then C++11
caught up with inttypes/h/stdint.h and removed the need for the macros.
They have disappeared from C11 as a result, and also from current glibc
implementation (https://sourceware.org/bugzilla/show_bug.cgi?id=15366)

So it seems reasonably safe to do the same, and it will save people
having to enable access to these macros explicitly when writing C++.
2017-06-04 17:29:29 +02:00
Augustin Cavalier b70a58f95a pthread.h: Remove PTHREAD_RWLOCK_INITIALIZER macro.
This reverts commit 17286dc70a.

As discussed on the mailing list. As it turns out, this was less
than half of an actual implementation of this macro, and there's
technically no way to implement it without introducing (theoretical)
race conditions, in the current design anyway.
2017-05-29 10:54:41 -04:00
Joseph C, Hill 17286dc70a pthread.h: Add PTHREAD_RWLOCK_INITIALIZER macro.
Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
Fixes #8798. One tiny style fix by me (adding spaces around braces).
2017-05-27 12:46:47 -04:00
Jérôme Duval 41458d977a limits.h: define PIPE_BUF. 2017-04-19 17:52:28 +02:00
Jérôme Duval 00796434c6 limits.h: bump _POSIX_SEM_NSEMS_MAX to 256.
128 was too low for Python3.
2017-04-16 13:49:41 +02:00
Adrien Destugues 56403b6373 limits.h: define PAGE_SIZE only if XSI is requested
limits.h is part of the C standard, but POSIX and XSI extend it with
various defines. We should not add these unless the application requests
support for them.

In this case, PAGE_SIZE should only be defined if XSI support is
requested by defining _XOPEN_SOURCE. Note that PAGESIZE (plain POSIX for
the same thing) and B_PAGE_SIZE are alternatives that remain available.
2017-04-13 21:14:41 +02:00
Jérôme Duval 85566e032d posix: add _POSIX_SEM_NSEMS_MAX.
* have _SC__SEM_NSEMS_MAX return _POSIX_SEM_NSEMS_MAX, a per team limit
instead of the global limit.
2017-02-21 20:17:16 +01:00
Jérôme Duval 0bec83a85a pthread: add const for pthread_mutex*_get*()
according to the spec. Fixes #13324.
* code style clean up.
2017-02-21 20:05:02 +01:00
Andrew Aldridge a735975461 Sync atheros813x with FreeBSD
Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #12328.
Fixed a style error (2 lines between functions).
2017-01-22 09:20:01 +01:00
Dmytro Shynkevych 0e0f49e799 libroot: Implemented pthread barriers
This is an implementation of pthread barriers pursuant to the relevant specification.

Barriers are essentially a special case of conditional variables,
such that all threads waiting on one are woken up when the number of
waiters reaches a number provided at the initialization of the barrier.
In view of that, this implementation mimics the implementation of pthread_cond,
except it is more specialized and self-contained.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2016-12-30 11:32:04 +01:00
Jérôme Duval e25f993385 complex.h: add a C++ guard. 2016-10-05 09:18:42 +02:00
Adrien Destugues 6980817672 Remove pthread.h include from netdb.h
- It is not needed in the .h, and makes gawk build fail.
2016-08-27 09:04:22 +02:00
François Revol 47a20cd6d1 M68K: turn #warnings into comments in public headers
The warnings made those headers and those including them not detectable
by libiberty's configure because of the way it checked for them.

This fixes the gcc build.
2016-07-20 20:26:29 +02:00
Adrien Destugues 93ea83e53d Allow custom baud rates for FTDI serial ports
- Termios: cf{get,set}{i,o}speed can handle arbitrary speed values.
- The value is stored in the appropriate fields of the termios structure
  in this case. The old constants (stored in the flags) are preserved
  for BeOS binary compatibility.
- Adjust the FTDI FT232* driver to accept custom rates, by replacing the
  hardcoded regster values with a function that will compute it
  according to FTDI documentation (confirmed giving the same values for
  the existing baudrates).
2016-02-27 19:08:53 +01:00
Augustin Cavalier 6984b8554c Revert "libroot: Undefine constants for unsupported POSIX features"
This reverts commit 7aebec8db1.
As per the discussion on the mailing list.
2015-12-21 12:16:33 -05:00
Simon South 7aebec8db1 libroot: Undefine constants for unsupported POSIX features
Haiku does not yet support certain features related to POSIX threads.
Constants used to test for the presence of these features should
therefore be left undefined, according to the POSIX spec, but are
currently set to -1. This can cause software built on Haiku to
incorrectly detect the presence of these features.

* unistd.h: Undefine _POSIX_THREAD_ATTR_STACKADDR,
  _POSIX_THREAD_PRIORITY_SCHEDULING feature constants.
* conf.cpp: __sysconf: Return -1 for unsupported features.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2015-12-21 11:09:34 -05:00
Simon South dbf060a3f7 libroot: Add brk() and sbrk().
This commit replaces the placeholder implementation of sbrk(), which
operated on a process' heap, with real implementations of brk() and
sbrk() that adjust a process' program break.

* unistd.h: Add standard definitions of brk() and sbrk(); include
  stdint.h for intptr_t.
* thread.cpp: Recognize RLIMIT_AS and RLIMIT_DATA resource limits
  (both currently unlimited); order limit identifiers alphabetically.
* arch-specific.cpp: Remove sbrk_hook().
* malloc_debug_api.cpp: Remove sbrk_hook().
* unistd/Jamfile: Build brk.c instead of sbrk.c.
* unistd/brk.c: Add.
* unistd/sbrk.c: Delete (placeholder implementation).
* libroot_stubs.c: Remove sbrk_hook().
* libroot_stubs_legacy.c: Remove sbrk_hook().
* src/tests/.../posix/Jamfile: Build brk_test.c.
* brk_test.c: Add (simple unit test that demonstrates behaviour of
  sbrk()).

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2015-11-22 17:59:22 +01:00
Adrien Destugues 75d1eb3a59 assert.h: reintroduce headers guard for function declarations.
The POSIX standard requires us to allow assert.h to be included multiple
times with differnt values of NDEBUG. So we can't have a global header
guard on the files. However, we must also make sure that we don't
declare functions multiple times in that case. Re-introduce an header
guard on the part of the file where we declare functions, only.

Fixes lots of warnings when building Netsurf.
2015-08-29 23:14:03 +02:00
Axel Dörfler 34671d601a Added execvpe().
* This closes #12114 again; while not POSIX, it's just a line away.
* Removed exect() from the header -- not sure where this came from.
  but I can't find anything about it on the net.
* Consolidated use of asterisk style in exec.cpp.
2015-07-23 13:30:30 +02:00
Jérôme Duval a83446983d libroot: added a complex.h header based on ...
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/complex.h.html
* added missing parts from glibc.
* x86_64 was already complete, x86 was missing a few functions.
* should help with #12202, provided that the gcc4 buildtools are rebuilt.
2015-07-10 22:39:21 +02:00
Adrien Destugues 50440c4220 Remove gethostbyname_r and gethostbyaddr_r from headers
* They were not in BeOS.
* They are also not in netresolv, they are deprecated and getaddrinfo
should be used.
2015-06-17 21:30:02 +02:00
Adrien Destugues 8d2aee6bc8 libbind: integrate "netresolv" patches from NetBSD.
libbind development was transferred to the NetBSD project at
http://wiki.netbsd.org/individual-software-releases/netresolv/

There isn't an official release yet, but they provide a set of patches
against the latest libbind release.

* Remove all files we don't use
* Merge the changes to the remaining files
* Add some new files we need
* Move getifaddrs implementation to libnetwork (instead of libbnetapi)
so it can be used by netresolv.

Fixes #8293 : netresolv uses getifaddrs to determine if there is a local
IPv6 address. If there is not, it will not return AAAA records.
2015-06-14 15:47:03 +02:00
Jérôme Duval 0dc6b011fe malloc: implement malloc_usable_size().
* Fix #12132
2015-06-13 14:29:11 +02:00
Adrien Destugues 4b2d018be4 Implement MSG_NOSIGNAL
* Part of latest POSIX specification, this prevents send() on a closed
socket to raise a SIGPIPE signal (but EPIPE is returned).
2015-06-10 17:39:53 +02:00
Hamish Morrison d6d439f3f7 Reimplement unnamed POSIX semaphores using user_mutex
* Fixes sharing semantics, so non-shared semaphores in non-shared
  memory do not become shared after a fork.
* Adds two new system calls: _user_mutex_sem_acquire/release(),
  which reuse the user_mutex address-hashed wait mechanism.
* Named semaphores continue to use traditional sem_id semaphores.
2015-05-24 14:03:40 +01:00
François Revol 54656b39c6 stdio.h: declare fcloseall() GNU extension
Since libroot already exports it and I've found some code using it.
2015-05-08 23:46:15 +02:00
Hamish Morrison 10b4fed24f Add support for pthread_condattr_get/setclock()
* Allows use of either CLOCK_REALTIME or CLOCK_MONOTONIC as the time
  base for pthread_cond_timedwait().
2015-05-02 20:55:57 +01:00
Jessica Hamilton c7ad68f08c assert.h: add comments explaining the omission of include guards 2015-04-17 07:03:40 +12:00
Jessica Hamilton 9f17027980 assert.h: remove include guards
* including assert.h multiple times with NDEBUG varying is
  perfectly legal, and required by POSIX.
2015-04-16 23:03:40 +12:00
Michael Lotz 9bf9ee3806 Whitespace and style cleanup only. 2015-04-12 18:50:01 +02:00
Michael Lotz ec0190adb0 malloc_debug: Implement allocation dump on exit in guarded heap.
When enabled (using heap_debug_dump_allocations_on_exit(true) or
MALLOC_DEBUG=e) this causes a dump of all remaining allocations when
libroot_debug is unloaded. It uses terminate_after to be called as
late as possible.

When combined with alloc stack traces this makes for a nice if a bit
crude leak checker. Note that a lot of allocations usually remain
even at that stage due to statically, lazyly and globally allocated
stuff from the various system libraries where it isn't necessarily
worth the overhead to free them when the program terminates anyway.
2015-04-10 17:04:28 +02:00
Michael Lotz 158e20e60e malloc_debug: Implement alloc/free stack traces in guarded heap.
When configured to do so (using heap_debug_set_stack_trace_depth(depth)
or MALLOC_DEBUG=s<depth>) the guarded heap now captures stack traces on
alloc and free.

A crash due to hitting a guard page or an already freed page now dumps
these stack traces. In the case of use-after-free one can therefore see
both where the allocation was done and where it was freed.

Note that there is a hardcoded maximum stack trace depth of 50 and that
the alloc stack trace takes away space from the free stack trace which
uses up the rest of that maximum.
2015-04-10 16:28:42 +02:00
Michael Lotz 121655e9ee malloc_debug: Add default alignment option.
This allows for something similar as was implemented in 217f090 but
makes it optional and configurable.

The MALLOC_DEBUG environment variable now can take "a<size>" to set
the default alignment to the specified size. Note that not all
alignments may be supported depending on the heap implementation.
2015-04-04 22:55:57 +02:00
Michael Lotz a05bfeb4a9 Whitespace cleanup only. 2015-04-04 22:55:56 +02:00
Jérôme Duval 4a9c56f6c7 x86_64: fenv.c needs __weak_reference()
* the weak symbol feenableexcept wasn't available.
2015-03-27 20:16:57 +01:00
Timothy Gu d1dc9cf655 stdint.h: use correct type for INT64_MAX (#11647)
int64_t is signed. Although it does not make a difference by itself, because
INT64_MAX is still a valid number for uint64_t (UL), the later INT64_MIN
declaration depends on INT64_MAX, and therefore got implicitly casted to
unsigned type.

This fixes the following program on a x86_64 system:

	#include <stdint.h>

	int main() {
		int64_t test = 5;
		if (test < INT64_MIN)
			return 1;
		return 0;
	}

This is a regression since commit 1d13a609 ("stdint.h: define [U]INT64[MAX|MIN]
with [U]L on x86_64").

Signed-off-by: Jerome Duval <jerome.duval@gmail.com>
2014-12-20 10:06:21 +01:00
Puck Meerburg a5f30beaad Fix #7008: Add a64l and l64a from glibc, and add some missing definitions in wchar.h and stdlib.h
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2014-12-14 18:06:09 +01:00