summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* MFC r303795:kib2016-08-204-1/+152
| | | | Add __cxa_thread_atexit(3) API implementation.
* Reflect error indication according to POSIX and what those functionsache2016-06-051-2/+2
| | | | currently do.
* Don't use fixup for C99 and up, the compiler result is already correct.ache2016-06-014-0/+8
| | | | | | Suggested by: bde MFC after: 1 week
* Micro optimize: C standard guarantees that right shift for unsigned valueache2016-05-291-1/+1
| | | | | | | fills left bits with zero, and we have exact 32bit unsigned value (uint32_t), so there is no reason to add "& 0x7fffffff" here. MFC after: 1 week
* 1) Unifdef USE_WEAK_SEEDING since it is too obsolete to support and makesache2016-05-291-41/+11
| | | | | | | | | | | | | reading hard. 2) Instead of doing range transformation in each and every function here, do it single time directly in do_rand(). One "mod" operation overhead is not a big deal, but the code looks nicer and possible future functions additions or PRNG change do not miss range transformations neither have unneeded ones. 3) Use POSIX argument types for visible functions (cosmetic). MFC after: 1 week
* 1) Unifdef USE_WEAK_SEEDING it is too obsolete to support and makes readingache2016-05-291-46/+14
| | | | | | | | | | | | | harder. 2) ACM paper require seed to be in [1, 2^31-2] range, so use the same range shifting as already done for rand(3). Also protect srandomdev() + TYPE_0 case (non default) from negative seeds. 3) Don't check for valid "type" range in setstate(), it is always valid as calculated. Instead add a check that rear pointer not exceeed end pointer. MFC after: 1 week
* Let l64a() properly null terminate its result.ed2016-05-261-22/+14
| | | | | | | | | | | | | | Though the buffer used by l64a() is initialized with null bytes, repetetive calls may end up having trailing garbage of previous invocations because we don't end up terminating the string. Instead of importing NetBSD's fix, use this opportunity to simplify this function dramatically, for example by just storing the Base64 character set in a string. There is also no need to do the bitmasking, as we can just use the proper integer type from <stdint.h>. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D6511
* 1) POSIX prohibits printing errors to stderr here and requireache2016-05-221-15/+10
| | | | | | | | | | | | | | | returning NULL: "Upon successful completion, initstate() and setstate() shall return a pointer to the previous state array; otherwise, a null pointer shall be returned. Although some implementations of random() have written messages to standard error, such implementations do not conform to POSIX.1-2008." 2) Move error detections earlier to prevent state modifying. MFC after: 1 week
* Update jemalloc to 4.2.0.jasone2016-05-131-1/+1
|
* libc: spelling fixes.pfg2016-04-302-3/+3
| | | | Mostly on comments.
* libc: do not include <sys/types.h> where <sys/param.h> was already includedavos2016-04-181-1/+0
| | | | | | According to style(9): > normally, include <sys/types.h> OR <sys/param.h>, but not both. (<sys/param.h> already includes <sys/types.h> when LOCORE is not defined).
* Fixed indentation, minor style.pluknet2016-04-181-12/+12
|
* Fix markup on "\n" in printf so it renders correctly.wblock2016-04-171-4/+4
| | | | | | PR: 208852 Submitted by: coder@tuxfamily.org MFC after: 1 week
* Update jemalloc to 4.1.0.jasone2016-02-292-2/+7
| | | | | | | | | | Add missing Symbol.map entry for __aligned_alloc. Add weak-->strong symbol binding for {malloc_stats_print,mallctl,mallctlnametomib,mallctlbymib} --> {__malloc_stats_print,__mallctl,__mallctlnametomib,__mallctlbymib}. These bindings complete the set necessary to allow applications to replace all malloc-related symbols.
* Add .NOMETA missed in r291320.bdrewery2016-01-201-1/+1
| | | | Sponsored by: EMC / Isilon Storage Division
* Remove an unneeded assignment of the return value.ed2016-01-141-1/+0
| | | | | | | tdelete() is supposed to return the address of the parent node that has been deleted. We already keep track of this node in the loop between lines 94-107. The GO_LEFT()/GO_RIGHT() macros are used later on as well, so we must make sure not to change it to something else.
* Replace implementation of hsearch() by one that scales.ed2015-12-277-185/+335
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Traditionally the hcreate() function creates a hash table that uses chaining, using a fixed user-provided size. The problem with this approach is that this often either wastes memory (table too big) or yields bad performance (table too small). For applications it may not always be easy to estimate the right hash table size. A fixed number only increases performance compared to a linked list by a constant factor. This problem can be solved easily by dynamically resizing the hash table. If the size of the hash table is at least doubled, this has no negative on the running time complexity. If a dynamically sized hash table is used, we can also switch to using open addressing instead of chaining, which has the advantage of just using a single allocation for the entire table, instead of allocating many small objects. Finally, a problem with the existing implementation is that its deterministic algorithm for hashing makes it possible to come up with fixed patterns to trigger an excessive number of collisions. We can easily solve this by using FNV-1a as a hashing algorithm in combination with a randomly generated offset basis. Measurements have shown that this implementation is about 20-25% faster than the existing implementation (even if the existing implementation is given an excessive number of buckets). Though it allocates more memory through malloc() than the old implementation (between 4-8 pointers per used entry instead of 3), process memory use is similar to the old implementation as if the estimated size was underestimated by a factor 10. This is due to the fact that malloc() needs to perform less bookkeeping. Reviewed by: jilles, pfg Obtained from: https://github.com/NuxiNL/cloudlibc Differential Revision: https://reviews.freebsd.org/D4644
* Let tsearch()/tdelete() use an AVL tree.ed2015-12-224-86/+473
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The existing implementations of POSIX tsearch() and tdelete() don't attempt to perform any balancing at all. Testing reveals that inserting 100k nodes into a tree sequentially takes approximately one minute on my system. Though most other BSDs also don't use any balanced tree internally, C libraries like glibc and musl do provide better implementations. glibc uses a red-black tree and musl uses an AVL tree. Red-black trees have the advantage over AVL trees that they only require O(1) rotations after insertion and deletion, but have the disadvantage that the tree has a maximum depth of 2*log2(n) instead of 1.44*log2(n). My take is that it's better to focus on having a lower maximum depth, for the reason that in the case of tsearch() the invocation of the comparator likely dominates the running time. This change replaces the tsearch() and tdelete() functions by versions that create an AVL tree. Compared to musl's implementation, this version is different in two different ways: - We don't keep track of heights; just balances. This is sufficient. This has the advantage that it reduces the number of nodes that are being accessed. Storing heights requires us to also access all of the siblings along the path. - Don't use any recursion at all. We know that the tree cannot 2^64 elements in size, so the height of the tree can never be larger than 96. Use a 128-bit bitmask to keep track of the path that is computed. This allows us to iterate over the same path twice, meaning we can apply rotations from top to bottom. Inserting 100k nodes into a tree now only takes 0.015 seconds. Insertion seems to be twice as fast as glibc, whereas deletion has about the same performance. Unlike glibc, it uses a fixed amount of memory. I also experimented with both recursive and iterative bottom-up implementations of the same algorithm. This iterative top-down version performs similar to the recursive bottom-up version in terms of speed and code size. For some reason, the iterative bottom-up algorithm was actually 30% faster for deletion, but has a quadratic memory complexity to keep track of all the parent pointers. Reviewed by: jilles Obtained from: https://github.com/NuxiNL/cloudlibc Differential Revision: https://reviews.freebsd.org/D4412
* META MODE: Don't create .meta files when symlinking sources into the obj ↵bdrewery2015-11-251-4/+4
| | | | | | | | | | | directory. Tracking these leads to situations where meta mode will consider the file to be out of date if /bin/sh or /bin/ln are newer than the source file. There's no reason for meta mode to do this as make is already handling the rebuild dependency fine. Sponsored by: EMC / Isilon Storage Division
* Use ANSI C prototypes. Eliminates -Wold-style-definition warnings.rodrigc2015-09-2012-51/+28
|
* Remove names from prototypesrodrigc2015-09-203-7/+7
|
* Add declarations to eliminate -Wmissing-prototypes warnings.rodrigc2015-09-203-0/+15
|
* Use ANSI C prototypes.rodrigc2015-09-143-45/+14
| | | | Eliminates gcc 4.9 warnings.
* Switch libc from using _sig{procmask,action,suspend} symbols, whichkib2015-08-292-12/+16
| | | | | | | | | | | | | | | | | | | | | | | | are aliases for the syscall stubs and are plt-interposed, to the libc-private aliases of internally interposed sigprocmask() etc. Since e.g. _sigaction is not interposed by libthr, calling signal() removes thr_sighandler() from the handler slot etc. The result was breaking signal semantic and rtld locking. The added __libc_sigprocmask and other symbols are hidden, they are not exported and cannot be called through PLT. The setjmp/longjmp functions for x86 were changed to use direct calls, and since PIC_PROLOGUE only needed for functional PLT indirection on i386, it is removed as well. The PowerPC bug of calling the syscall directly in the setjmp/longjmp implementation is kept as is. Reported by: Pete French <petefrench@ingresso.co.uk> Tested by: Michiel Boland <boland37@xs4all.nl> Reviewed by: jilles (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Add missing sdallocx updates and remove *allocm manpage links.jasone2015-08-182-5/+6
| | | | Submitted by: jbeich
* Update jemalloc to version 4.0.0.jasone2015-08-181-1/+2
|
* Document the fact that system(3) can easily be misused due to shell metadelphij2015-07-251-2/+14
| | | | | | | characters are honored. While I'm there also mention posix_spawn in the SEE ALSO section. MFC after: 2 weeks
* Fix major copy/paste and other style errors.pluknet2015-05-051-5/+10
|
* Apply the copyright the the same owners as the original malloc(3) where most ofbapt2015-05-011-2/+3
| | | | | | | | the text here comes from Reported by: many Discussed with: miod@OpenBSD.org Pointyhat to: bapt
* Import reallocarray(3) from OpenBSDbapt2015-05-014-2/+182
| | | | | | | | | Add a manpage for it, assign the copyright to the OpenBSD project on it since it is mostly copy/paste from OpenBSD manpage. style(9) fixes Differential Revision: https://reviews.freebsd.org/D2420 Reviewed by: kib
* qsort(3): small style(9) cleanups.pfg2015-03-051-10/+10
| | | | | Basically spaces vs. tabs. No functional change.
* qsort(3): enhance to handle 32-bit aligned data on 64-bit systemspfg2015-03-051-12/+21
| | | | | | | | | | | | | | Implement a small enhancement to the original qsort implementation: If the data is 32 bit aligned we can side-step the long type version and use int instead. The change brings a modest but significant improvement in 32 bit workloads. Relnotes: yes PR: 135718 Taken from: ache
* Adjust wording slightly to emphasize that random(3) should not be used forcperciva2015-02-251-3/+2
| | | | | | | | any applications which need unpredictable random numbers, not merely those which are cryptographic in nature. If you work for a lottery and you're using random(3) to select the winning numbers, please let me know.
* Update comment and NetBSD ID tag.pfg2015-02-061-3/+3
| | | | | The NetBSD revisions correspond to changes we have already done like __P() removal and ANSI-fication of definitions.
* tdelete(3): don't delete the node we are about to return.pfg2015-02-051-1/+2
| | | | | | CID: 272528 Obtained from: NetBSD (CVS rev. 1.4) MFC after: 2 weeks
* Fix known issues which blow up the process after dlopen("libthr.so")kib2015-01-033-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (or loading a dso linked to libthr.so into process which was not linked against threading library). - Remove libthr interposers of the libc functions, including __error(). Instead, functions calls are indirected through the interposing table, similar to how pthread stubs in libc are already done. Libc by default points either to syscall trampolines or to existing libc implementations. On libthr load, libthr rewrites the pointers to the cancellable implementations already in libthr. The interposition table is separate from pthreads stubs indirection table to not pull pthreads stubs into static binaries. - Postpone the malloc(3) internal mutexes initialization until libthr is loaded. This avoids recursion between calloc(3) and static pthread_mutex_t initialization. - Reinstall signal handlers with wrapper on libthr load. The _rtld_is_dlopened(3) is used to avoid useless calls to sigaction(2) when libthr is statically referenced from the main binary. In the process, fix openat(2), swapcontext(2) and setcontext(2) interposing. The libc symbols were exported at different versions than libthr interposers. Export both libc and libthr versions from libc now, with default set to the higher version from libthr. Remove unused and disconnected swapcontext(3) userspace implementation from libc/gen. No objections from: deischen Tested by: pho, antoine (exp-run) (previous versions) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Various mdoc fixes and a few EOL whitespace removals.brueffer2014-12-212-3/+3
| | | | Found with: mandoc -Tlint
* Fix quick_exit(3) manual page to match reality - the status was missing.trasz2014-12-131-2/+2
| | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation
* Use the __DECONST macro rather than hand rolling the same thing.brooks2014-10-241-5/+1
| | | | Sponsored by: DARPA, AFRL
* Add bsearch_b to the libc map and the stdlib header.pfg2014-09-011-0/+1
| | | | | | | | | | | | bsearch_b is the Apple blocks enabled version of bsearch(3). This was added to libc in Revision 264042 but the commit missed the declaration required to make use of it. While here move some other block-related functions to the BSD_VISIBLE block as these are non-standard. Phabric: D638 Reviewed by: theraven, wollman
* Minor style tweaks.pfg2014-08-131-7/+7
| | | | | Obtained from: OpenBSD (CVS rev. 1.7) MFC after: 3 days
* Fix hdestroy() compliance issue.pfg2014-07-211-1/+0
| | | | | | | | | | | | | | | | | | | The hcreate(3) implementation and related functions we inherited from NetBSD used to free() the key value, something that is not supported by the standard implementation. This would cause a segmentation fault when attempting to run the examples from the opengroup and linux manpages. NetBSD has added non-standard calls to provide the previous behaviour but hdestroy is not very commonly used so at this time it seems excessive to bring those to FreeBSD. Bump the __FreeBSD_version as this is an ABI change. Reference: http://bugs.dragonflybsd.org/issues/1398 MFC after: 2 weeks
* Update license.pfg2014-07-211-7/+2
| | | | | | NetBSD has removed the advertisement clause from this file. Obtained from: NetBSD (CVS rev. 1,8)
* Add re-entrant versions of the hash functions based on the GNU api.pfg2014-07-214-41/+153
| | | | | | | While testing this I found a conformance issue in hdestroy() that will be fixed in a subsequent commit. Obtained from: NetBSD (hcreate.c, CVS Rev. 1.7)
* libc/stdlib: Minor cleanups to code originating in NetBSDpfg2014-07-153-22/+14
| | | | | | | Mostly ANSIfication and typos. Obtained from: NetBSD MFC after: 5 days
* strfmon: reduce unnecessary snprintf.pfg2014-07-121-5/+3
| | | | | | | No need for the snprintf/asprintf dance; use fixed width formats. Obtained from: NetBSD (CVS rev. 1.8) MFC after: 1 week
* [mdoc] Fix previous change.pluknet2014-07-081-1/+1
|
* getopt(3): clarify GNU instead of NetBSD.pfg2014-07-041-1/+1
| | | | | | | | The manpage and the code for r267745 came from NetBSD but the option is inspired on GNU. Reported by: Ben Kaduk MFC after: 3 days
* use .Mt to mark up email addresses consistently (part4)bapt2014-06-232-3/+3
| | | | | PR: 191174 Submitted by: Franco Fichtner <franco at lastsummer.de>
* Merge intermediate OpenBSD v1.25 changes (almost identical to ours)ache2014-06-221-18/+12
| | | | | | to reduce diff and bump OpenBSD patch level to v1.26. MFC after: 2 weeks
OpenPOWER on IntegriCloud