Commit Graph

651 Commits

Author SHA1 Message Date
jruoho
ef40c024f6 Move the examples to where they belong, in EXAMPLES. 2010-05-03 05:11:34 +00:00
jruoho
26e9ae259a Split the implementation details of malloc(3) to a separate jemalloc(3)
manual page. This way malloc(3) can follow the standard terse format used
elsewhere in the libc, while additional details can be added to jemalloc(3).

Note HISTORY and AUTHORS in jemalloc(3), and add some reading material to
SEE ALSO.
2010-05-03 05:01:53 +00:00
jruoho
a80a543b80 Add more markup. 2010-05-03 03:47:51 +00:00
jruoho
280488d6bc Note that the return type sould arguably be intmax_t instead of long long. 2010-05-01 08:35:52 +00:00
jruoho
061351141b Remove the (incorrect) note about inconsistent return values. Name the exit
code as EXIT_FAILURE instead of integer 1.
2010-05-01 08:30:00 +00:00
jruoho
413ef23a32 Add more bugs. Namely, besides the return values that are confusing, no
function in a modern standard C library, exposed by <stdlib.h>, should be as
easy to (buffer) overflow as strsuftollx(3).

In addition, improvements to wording and markup.
2010-05-01 08:12:30 +00:00
jruoho
4519228649 Improvements to wording and markup.
In addition, list more bugs and caveats. Namely, the NetBSD implementation
(like the FreeBSD one where this was ported to) requires that the comparison
keys are allocated dynamically, and that hdestroy() will try to free(3) each
key. This obviously severely limits the portability, given that other
implementations (for example, the Linux one) make no such assumptions. Both
approaches are legitimate, and thus the real bug is in the ambiguity of the
standard.
2010-05-01 06:18:03 +00:00
jruoho
a293ac8fcc Rewrite the HISTORY section. 2010-04-30 10:24:02 +00:00
jruoho
eecb0b5e2c Put the period outside the quotation marks. 2010-04-30 10:09:23 +00:00
jruoho
cb375ee477 Add STANDARDS and CAVEATS. The latter notes the ambiguity of tdelete() when
deleting the root node.
2010-04-30 10:06:52 +00:00
jruoho
42e4725801 Also: in the example EOVERFLOW is probably better than ENOMEM. 2010-04-30 07:16:35 +00:00
jruoho
67e69a6bf8 As err(3) instructs, use EXIT_FAILURE in the example. 2010-04-30 07:14:15 +00:00
jruoho
75d4d306c5 Steal the "malloc() vs. calloc()" -idiom from the OpenBSD's malloc(3).
While it may be debated how useful this is, good idiomatic usage examples
are exactly the kind of thing one would hope to see more in manual pages.
2010-04-30 07:00:51 +00:00
joerg
1c3412fa2f Use .In for header files instead of .Ar Pa and variations. 2010-03-22 19:30:53 +00:00
jruoho
ab524958e3 Emphasize imaxint_t. 2010-03-21 13:39:51 +00:00
joerg
ec66a10c91 Namespace protection for mi_vector_hash. 2010-03-19 18:11:30 +00:00
enami
3df6d33667 Fix race condition on reallocation of huge category.
We need to remove the old region before mremap() since if it relesae the
old region, other thread may map it for the same huge category allocation
and insert it to the tree before we acquire a lock after mremap().

Fixes PR/42876.
2010-03-04 22:48:31 +00:00
roy
7ffeaa6526 Include nbtool_config.h as we need to be part of the terminfo toolchain. 2010-02-04 10:27:08 +00:00
pooka
5f6578a865 tyop de fix 2009-12-02 12:50:27 +00:00
pooka
304d27696e Document that strtouq can return UQUAD_MAX. 2009-12-02 12:45:35 +00:00
enami
8f4cd2bee8 Retain old variables when failed to allocate memory. 2009-12-02 09:34:51 +00:00
wiz
567e675c3f Mention that it is included in IEEE Std 1003.1-2008. 2009-11-17 15:02:08 +00:00
wiz
2e7202c574 Mention that getsubopt is an XSI extension for IEEE Std 1003.1, 2004 Edition. Bump date. 2009-11-17 14:52:21 +00:00
snj
550147bd6a Remove 3rd and 4th clauses in christos' license. OK christos. 2009-10-21 01:07:44 +00:00
joerg
be403b3398 Fix header to include. From Kristaps Dzonsons. 2009-10-19 22:38:56 +00:00
pooka
50efcfca57 When converting the locking path of mutex+counter to a real recursive
mutex, it's a good idea to convert the unlock path too so that the
recursive mutex gets released as many times as it was locked.
Fixes pthread + cxa deadlock.
2009-10-08 16:33:45 +00:00
dsl
602976fff6 Ansify functions and remove __P/ 2009-09-05 08:53:06 +00:00
dsl
11bcd8ad6a The 'table' of character weights is allowed to be NULL.
The SETUP define sorts it out (in the slowest and nastiest possible way!)
Broken by rev 1.12 almost 10 years ago!
2009-08-21 20:49:50 +00:00
dsl
10ad5ffa71 Add the 'abs', 'div' and 'erand48' sources to stdlib/Makefile.inc.
Change the arch files only include the .S files.
This adds imaxdiv() to some archs where it was missing.
2009-07-31 20:39:59 +00:00
wiz
fa52b0ad23 Bump date for previous. 2009-07-23 13:37:34 +00:00
dholland
3cfdfcef43 Clarify the description of the errno behavior, based on the recent
thread in tech-userlevel.
2009-07-23 02:54:27 +00:00
joerg
ed9dacacc0 Add HISTORY. 2009-07-21 12:40:52 +00:00
joerg
d6e219476b Add a fast, platform independent hash function to libc.
The algorithm used is the Jenkins hash.  The name (mi_vector_hash)
reflects the nature of the hash function.
Add glue for libc ATF tests and include a test case to make sure that
(mis)alignment and endianess are handled correctly.

Bump libc minor to 169.
2009-07-20 17:03:36 +00:00
pooka
c6181c7b2f Re-add explanation of how to correctly use realloc. 2009-07-20 12:10:03 +00:00
yamt
99122f39e6 qsort: remove the "switch to insertion sort" optimization because it
causes catastrophic performance for certain inputs.
2009-06-01 06:37:40 +00:00
wiz
f6b43a0c43 Markup improvements. No need to mark up numbers as defined values, math
did the definition for us ages ago. Make HTML-ready.
2009-05-21 09:13:35 +00:00
christos
fd67370208 mention that these functions return 0 and set errno to ERANGE on invalid base. 2009-05-20 22:01:34 +00:00
wiz
5dd21e58d5 Grammar fix. 2009-05-18 09:00:02 +00:00
wiz
7d88f2f54f Revert parts of v1.25 (jemalloc):
Re-add RCS Id, remove superfluous .Pp, join line, comment out limits(1) xref.
2009-05-13 23:02:11 +00:00
joerg
71c479831e Fix markup. 2009-04-11 16:13:49 +00:00
joerg
cc420b6c04 ANSIfy. Remove conditionals around __RCSID. 2009-03-20 14:05:54 +00:00
joerg
cc5989d71d ANSIfy. Remove conditional macros around __RCSID. 2009-03-20 13:56:57 +00:00
joerg
9df66b68e0 Explicitly mark : as literal, use Pq. 2009-03-12 12:51:29 +00:00
joerg
edc0d6c151 Fix prologue. 2009-03-10 23:37:01 +00:00
lukem
9d1671f467 Fix sign-compare issues 2009-02-12 03:34:33 +00:00
lukem
19b046886f fix sign-compare issue 2009-02-12 03:12:36 +00:00
lukem
2360d0845a Apply some of FreeBSD libc/stdlib/malloc.c rev 1.162
to fix sign-compare issues.
2009-02-12 03:11:01 +00:00
lukem
957ba389e8 sign-compare fix 2009-01-30 23:46:03 +00:00
lukem
8a09e86085 sign-compare fix 2009-01-30 23:35:35 +00:00
ad
c984f259af Make threaded programs die correctly:
kill(getpid(), SIGFOO) -> raise(SIGFOO)
2009-01-30 23:21:02 +00:00
christos
461a86f9bd merge christos-time_t 2009-01-11 02:45:45 +00:00
ad
c6555ead19 Our qsort() is inappropriate for kernel use because it makes recursive
calls. Replace it with a kheapsort() function in kernel. Pointed out
by tron@.
2008-11-16 16:15:58 +00:00
ad
e5c4df967a Make qsort() available in libkern. 2008-11-16 15:01:26 +00:00
christos
035a506da3 use the right variable in memcpy. 2008-11-01 00:54:47 +00:00
christos
e34e014482 make __findenv return the offset for the new entry to be inserted when
the string is not found, to avoid an additional scan of the environ array
in setenv.
2008-10-31 17:46:04 +00:00
mrg
2f0d0e12bf define and use LIBCDIR in terms of .CURDIR. fixes compat/lib/libc build. 2008-10-26 07:43:07 +00:00
joerg
3ae583451f Prepare use of strtoull, strtoumax and strtoimax in tools/compat by
including nbtool_config.h.
2008-09-10 18:08:58 +00:00
christos
40d6ddde20 system(NULL) should return if the command interpreter is there or not.
Andy Shevchenko
2008-08-27 06:45:02 +00:00
drochner
14744ddade fix range of strtouq(), from Henning Petersen per PR lib/39399 2008-08-26 12:21:24 +00:00
joerg
245e086321 Unify the implementation of strto{l,ul,ll,ull,imax,umax,q,uq} into one
version for signed and one version for unsigned data types.

Add a check for supported bases and set errno (userland) or panic
(kernel, libsa) otherwise.

Make strto{ll,ull,imax,umax} normal symbols and just keep the underscore
versions as strong alias.

Obtained from DragonFly, based on the wide char version from Citrus.
Reviewed by christos@
2008-08-20 12:42:26 +00:00
matt
cac8e44915 Add C99 functions imaxabs and imaxdiv. 2008-08-04 21:29:27 +00:00
lukem
8897ce05a0 Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
2008-07-21 12:05:43 +00:00
ad
380c3da007 Split choose_arena() back out into inline and non-inline portions. 2008-06-23 10:46:25 +00:00
ad
88261d4ead Check to see if MALLOC_OPTIONS is actually set in the environment before
doing issetugid().
2008-06-05 00:16:34 +00:00
martin
11a6dbe728 Convert TNF licenses to new 2 clause variant 2008-04-30 13:10:46 +00:00
martin
ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
christos
23b2e3cd80 Fix another integer overflow issue discovered by Maksymilian Arciemowicz.
On top of this, limit the range of getnumber to 0x00ffffff to make sure
that adding two of them does not cause an integer overflow.
2008-03-27 21:50:30 +00:00
christos
00f5c7fe8d Avoid integer overflow; reported by Maksymilian Arciemowicz. 2008-03-18 18:16:08 +00:00
rmind
1c7eae5598 Use size_t to avoid overflow when sorting large arrays. While here, ANSIfy.
Obtained from FreeBSD (das@).
2008-03-11 18:04:59 +00:00
ad
91224074af Redo the CPU-based arena selection slightly differently. With the latest
libpthread and kernel, this mysteriously works without a problem.
2008-03-08 13:17:13 +00:00
christos
908cf676a4 mention RANDOM_MAX 2008-02-28 16:16:35 +00:00
xtraeme
c3e906d7a0 There's no need to do the mutex_trylock dance anymore in __cxa_finalize(),
just using mutex_lock() is enough.
2008-02-25 14:35:54 +00:00
xtraeme
1b5143aa5d Add a comment for __libc_atexit_init() missed in previous that was
available in the original patch.
2008-02-25 14:15:10 +00:00
xtraeme
95157b046e Make the atexit mutex recursive and initialize it in __libc_init()
as suggested by ad@, based on the patch provided by Sverre Froyen
in lib/37654.

Reviewed by ad@ and jmcneill@.
2008-02-25 14:06:13 +00:00
christos
ed13fe5855 fix posix_memalign; we are not going to support alignments > pagesize in
this implementation.
2008-02-03 22:56:53 +00:00
macallan
f53566168d make this compile again 2007-12-12 17:56:10 +00:00
simonb
179bda4711 Fix twalk()s 3rd argument name so that it matches rest of manpage and
the source code.
2007-12-07 07:33:13 +00:00
christos
b831a8ada2 move decls for _malloc_{pre,post}fork() to extern.h 2007-12-04 17:45:07 +00:00
christos
86ef91b80e - use a non localized version of strerror_r.
- kill localized declarations and let namespace.h do its work.
2007-12-04 17:43:51 +00:00
ad
8b96cb8a97 Back out the per-cpu arena changes. With this, ld.so magically stops
loading libc/libpthread twice -- which does not make sense, because it
has its own private malloc().
2007-12-01 22:44:44 +00:00
dsl
b3dec55727 Fix the other half of the 'store int as a thread specific pointer'/ 2007-11-30 17:44:38 +00:00
christos
e09a2e99e8 converting a pointer to unsigned is bad; use uintptr_t. 2007-11-30 17:09:22 +00:00
ad
49dcd767c3 Make the allocation arenas per-CPU in the most optimistic case, but
continue to 'stripe' by thread in case of contention.
2007-11-29 18:46:13 +00:00
christos
f6cecc05cf Sync phk malloc.c with the latest one from FreeBSD. This gives us the
same api as jemalloc by:

    - adding posix_memalign()
    - moving calloc in the same file
    - renaming malloc_options -> _malloc_options
2007-11-28 21:55:14 +00:00
ad
95182011ed Enable posix_memalign(). 2007-11-19 14:48:41 +00:00
christos
0405bf4cb9 always compile getopt_long. some ifdef reduction. more to come. 2007-11-09 03:29:20 +00:00
christos
b3b90d7485 Revert previous. This mess of ifdefs needs to be killed. 2007-11-06 22:08:51 +00:00
christos
9df03145fa move the test to replace getopt higher up, before we need to include anything. 2007-11-06 19:13:16 +00:00
skrll
29353f93e2 Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.
2007-10-30 17:19:59 +00:00
reed
b72da12b34 Add HISTORY: The strtof() and strtold() functions appeared in NetBSD
4.0.
2007-10-24 13:42:10 +00:00
simonb
46de085339 Revert the CSE parts of the previous change. "run" is calculated with
a different value for "pageind" each time through the loop, so we can't
precalculate it.

Fixes awk core dump issues on powerpc 405.
2007-10-22 04:16:48 +00:00
christos
8de47c09e3 - do some CSE.
- pass lint
2007-10-19 19:28:57 +00:00
yamt
b79fded28d use mremap for huge -> huge realloc.
fix PR/31425 (Nicolas Joly) and possibly PR/36175 (Brian de Alwis).
2007-10-16 15:12:16 +00:00
yamt
89aa62f9b2 we don't have reallocf. 2007-10-15 11:18:44 +00:00
yamt
687cd24ebe make lint happy. 2007-10-15 10:30:56 +00:00
yamt
1277f9b0a0 malloc_print_stats: print huge_allocated correctly. it's already in bytes. 2007-10-15 10:28:10 +00:00
yamt
14bfffc9db use MAP_ALIGNED. 2007-10-15 00:05:00 +00:00
ad
3465d8db6f Add defs for hppa. From he@. 2007-10-09 00:59:52 +00:00
he
7ed9cc8edd On sparc64, both __sparc__ and __sparc64__ is defined. Avoid redefinition
of size constants for sparc64.

This code still produces many, many lint warnings due to "may loose accuracy"
when mixing long/int, and also warnings related to <<.
2007-10-07 21:45:18 +00:00
ad
81e619b9a4 Update for jemalloc. 2007-10-06 01:09:48 +00:00
ad
9b64888c5d Use jemalloc as the default allocator unless USE_JEMALLOC=no. 2007-10-06 01:09:07 +00:00
ad
e7a9e46b7e Port to NetBSD. Note: posix_memalign() is here, but it's not exported
via the headers yet.
2007-10-05 23:42:23 +00:00
ad
8a475bcba1 Pull in jemalloc from FreeBSD:
FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp
2007-10-05 23:39:58 +00:00
kristerw
3a6ef3e3c1 Keep track of atexit functions that are added while processing
atexit functions, to ensure that the new functions will be called.
2007-08-08 01:05:34 +00:00
kristerw
af220472c9 Ensure that the struct atexit_handler has been removed from the list
of pending atexit handlers before the structure is reused.  This prevents
__cxa_finalize from going into an infinite loop when an atexit handler
register a new atexit handler as in:

   #include <stdlib.h>

   void two(void) {
   }

   void one(void) {
           atexit(two);
   }

   int main(void) {
           atexit(one);
           return 0;
   }
2007-08-08 00:51:18 +00:00
wiz
e3d3393d01 Add xref to shquote(3), suggested by joerg. Bump date. 2007-08-02 23:45:10 +00:00
ginsbach
15b661abe9 Fix several end cases:
o If a long option looks like an ambiguous abbreviation of two or more long
  options, but all the possible interpretations would return the same
  value, then just return that value without complaining that it's
  ambiguous.

o If a long option could be interpreted either as an exact match for one
  long option, or as an abbreviation for one or more other long options,
  then treat it as the exact match.

These changes align NetBSD's getopt_long(3) with the current behavior of
GNU getopt_long(3), the de facto standard, and FreeBSD's getopt_long(3).
2007-07-05 16:05:40 +00:00
ginsbach
a3ae2738c9 Document that getopt_long(3) can and will accept unique abbreviated long
option names.  This feature has been present since getopt_long(3) was first
released in NetBSD 1.5.  This is also standard GNU getopt_long(3) behavior.
2007-07-02 17:56:17 +00:00
lukem
2d50a59010 Use IEC 60027-2 prefixes for 2^n based prefixes. 2007-04-12 06:50:39 +00:00
christos
cdcb070b9c remove bogus (void)&var; From Anon Ymous 2006-12-18 00:40:14 +00:00
elad
8e60b8367c PR/34984: Denis Lagno: minor problems with tsearch.3 2006-11-26 13:10:54 +00:00
christos
3d98aa3f4b fix spelling of accidentally; from Zapher 2006-11-24 19:37:02 +00:00
elad
25c47f2333 PR/34602: sushant: Bug in malloc implementation contains dead code in
free_pages()

Applied patch from Mindaugas <unex at linija org> (in #NetBSD-code), thanks
2006-10-08 16:25:15 +00:00
thorpej
82fd1ebbaa - Move strtoll.c and strtoull.c from libc/stdlib to common/libc/stdlib.
- Add strtoll.c and strtoull.c to libkern.
2006-10-08 03:14:55 +00:00
elad
a35b07a2ca Correctly recover signal state if failed trying to set it.
Patch from David A. Holland in #NetBSD-code, thanks!
2006-10-07 22:16:19 +00:00
wiz
ec15e07b4a Switch from 4-clause to 2-clause BSD license.
Ok dillo@, board@.
2006-10-04 17:29:42 +00:00
mjl
d072c175eb s,floride,fluoride, 2006-06-28 06:25:15 +00:00
wiz
20862d8c44 Bump date for previous. 2006-04-24 21:54:37 +00:00
liamjfoy
14a07a0706 - add a missing ;
- use 'size' instead of 'nsize', makes more sense

ok christos@
2006-04-24 20:46:23 +00:00
thorpej
7d3d66c90e Move strtoumax.c from libc/stdlib to common/libc/stdlib and include it
in libkern.  Required for new code coming soon.
2006-04-22 15:33:33 +00:00
drochner
273bf6508d correct multiplicand in pseudorandom generation 2006-03-31 11:43:54 +00:00
drochner
04293de9bb switch byteorder of seed to match previous (and documented) behaviour 2006-03-31 11:42:31 +00:00
kleink
c66ffccfbe Xref rnd(4). 2006-03-24 16:14:42 +00:00
drochner
f81322cf18 build erand48_ieee754.c on everything but vax 2006-03-22 22:03:58 +00:00
drochner
7a2af2aba0 Rewrite erand48() to put the random bits into the mantissa by simple
bitshifts instead of calling ldexp() three times.
(for ieee doubles only -- vax can't use it, so the old version
needs to stay around)
This removes the dependency on ldexp() which also didn't participate in
the usual __RENAME game, thus lead to confusion.
In addition, this version is almost 3 times as fast for me.
2006-03-22 21:06:03 +00:00
drochner
e89a43e9fd <math.h> is just needed for the ldexp() call in erand48() -
remove unnecessary dependency
2006-03-22 20:52:16 +00:00
christos
3040914cf6 Coverity CID 1560: Don't leak memory when multiple currency symbols are present 2006-03-19 01:50:49 +00:00
christos
7ac9949871 Coverity CID 2528: Don't delete the node we are about to return. 2006-03-19 01:12:08 +00:00
wiz
929e506267 Use more macros. 2006-03-15 20:08:24 +00:00
kleink
bc89c06cbf Add strtof(3) and strtold(3); welcome libc 12.137. 2006-03-15 17:35:17 +00:00
wiz
5d1e8b2745 Fix some typos. 2006-02-25 02:28:55 +00:00
kleink
3cd8501c1e Drop in gdtoa as a replacement for dtoa, strtod() from stdlib/strtod.c. 2006-01-25 15:43:01 +00:00
christos
6eaa70365b Kill _Exit; breaks build on cygwin and this implementation "is not exactly
equivalent to calling _exit".
2006-01-20 22:02:07 +00:00
perry
46359204cf __inline__ -> inline 2005-12-24 21:42:02 +00:00
perry
4e11af46bc Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete. 2005-12-24 21:11:15 +00:00
christos
e5548b402a Use reach-over sources from common/lib/libc 2005-12-20 19:31:47 +00:00
christos
bea4991aaa Older gcc does not support #ifdef inside macro expansion. 2005-12-04 17:57:25 +00:00
yamt
e301b762a1 redo the previous; constify rather than making a string writable. 2005-12-02 14:19:43 +00:00
yamt
a6a060b04b note that "argv" is not really const. 2005-12-02 14:11:01 +00:00
yamt
9de32b7fa1 don't make internal functions pretend to take a const argument. 2005-12-02 14:08:51 +00:00
christos
03256c6e55 WARNS=4 2005-11-29 03:11:58 +00:00
wiz
72a37764e0 Punctuation nits; grammar fix. 2005-09-26 10:54:46 +00:00
christos
cc85a7cfd9 add getenv_r and ttyname_r 2005-09-25 20:08:01 +00:00
christos
5b84b3983f compat core reorg. 2005-09-13 01:44:08 +00:00
christos
86741d79ab - Fix the remaining indr_references so that they define lint symbols.
- Add an internal symbol for strerror_r (thanks klaus for noticing)
- Remove internal __strerror
2005-07-30 15:21:20 +00:00
christos
fce61e5249 revert previous, my include files were out of day. 2005-07-16 17:32:09 +00:00
christos
b5626a3a22 Fix prototype inconsistency, discovered by lint2 fixes. 2005-07-16 17:15:46 +00:00
wiz
2c8c6850a4 Remove superfluous Pp, sort sections. 2005-07-12 08:28:42 +00:00
wiz
d2aabe58d4 Remove superfluous Pp. 2005-07-12 08:28:27 +00:00
drochner
e0d7e15c44 tolerate NULL pointers at some places 2005-07-06 17:17:15 +00:00