Commit Graph

707 Commits

Author SHA1 Message Date
Eitan Adler
6a762eb23e Remove undefined behavior from sranddev() and
srandomdev(). This doesn't actually work
with any modern C compiler:

In particular, both clang and modern gcc
verisons silently elide any xor operation
with 'junk'.

Approved by:	secteam
MFC after:	3 days
2012-10-09 14:25:14 +00:00
Andrey A. Chernov
542e13498f Optimize prev. commit for speed.
1) Don't iterate the loop from the environment array beginning each time,
iterate it under the last place we deactivate instead.
2) Call __rebuild_environ() not on each iteration but once, only at the end
of whole loop (of course, only in case if something is changed).

MFC after:      1 week
2012-10-03 04:46:58 +00:00
Andrey A. Chernov
2de80aea80 Using putenv() and later direct pointer contents modification it is possibe
to craft environment variables with similar names like that:
a=1
a=2
...
unsetenv("a") should remove them all to make later getenv("a") impossible.
Fix it to do so (this is GNU autoconf test #3 failure too).

PR:             172273
MFC after:      1 week
2012-10-02 17:44:08 +00:00
Jilles Tjoelker
05eb11cbc4 libc: Use O_CLOEXEC for various internal file descriptors.
This fixes a race condition where another thread may fork() before CLOEXEC
is set, unintentionally passing the descriptor to the child process.

This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still
leaves a race window so it should be fixed later.
2012-09-29 11:54:34 +00:00
Dag-Erling Smørgrav
d755552558 Slight stylification. 2012-09-28 13:50:37 +00:00
Ed Maste
6cbb6bbb77 According to a clarification at http://austingroupbugs.net/view.php?id=503
ptsname may set errno, so avoid saving and restoring errno across the
function.

PR:		standards/171572
2012-09-12 17:54:09 +00:00
Ed Maste
7877ed7ce3 Avoid mapping ENOENT to ENOTDIR for non-existent path components.
The ENOTDIR mapping was introduced in r235266 for kern/128933 based on
an interpretation of the somewhat ambiguous language in the POSIX realpath
specification.  The interpretation is inconsistent with Solaris and Linux,
a regression from 9.0, and does not appear to be permitted by the
description of ENOTDIR:

     20 ENOTDIR Not a directory.  A component of the specified pathname
             existed, but it was not a directory, when a directory was
             expected.

PR:		standards/171577
MFC after:	3 days
2012-09-12 17:05:39 +00:00
Dag-Erling Smørgrav
f7668359de Add the same warning to rand48(3) as to rand(3) and random(3).
MFC after:	3 days
2012-09-11 12:55:15 +00:00
Dag-Erling Smørgrav
cf949d1283 Bump dates.
Reminded by:	bz@
2012-09-04 22:03:16 +00:00
Dag-Erling Smørgrav
edab57e04e Add a prominent warning about these functions' unsuitability for
cryptographic purposes, and recommend using arc4random(3) instead.
2012-09-04 21:40:53 +00:00
Kevin Lo
8437339e10 Make 'junk' volatile so that compilers won't be tempted to optimize
Reviewed by:	ache
MFC after:	3 days
2012-08-17 01:05:56 +00:00
Sergey Kandaurov
f6a6151849 Update the 'C1x draft' reference to '.St -isoC-2011' mdoc macro.
Reviewed by:	theraven
MFC after:	1 week
2012-07-26 12:04:11 +00:00
Joel Dahl
af5b2c7853 Remove end of line whitespace. 2012-06-26 05:34:31 +00:00
Isabell Long
3f19323a07 Add more locale-specific functions to the relevant man pages and
Makefiles:
- libc/stdtime/strftime.3
- libc/stdtime/strptime.3
- libc/stdlib/strfmon.3

Reviewed by:	theraven
Approved by:	gabor (mentor)
2012-06-25 21:51:40 +00:00
Xin LI
1b74dc4a8b Switch from 4-clause to 2-clause BSD license. (OpenBSD r1.22)
No functional change.

Obtained from:	NetBSD via OpenBSD
2012-06-11 22:25:20 +00:00
Andrey A. Chernov
5f5a50728c 1) Although unpublished version of standard
http://austingroupbugs.net/view.php?id=385#c713
(Resolved state) recommend this way for the current standard (called
"earlier" in the text)

"However, earlier versions of this standard did not require this, and the
same example had to be written as:

    // buf was obtained by malloc(buflen)
    ret = write(fd, buf, buflen);
    if (ret < 0) {
        int save = errno;
        free(buf);
        errno = save;
        return ret;
    }
"

from feedback I have for previous commit it seems that many people prefer
to avoid mass code change needed for current standard compliance
and prefer to track unpublished standard instead, which requires now
that free() itself must save errno, not its usage code.

So, I back out "save errno across free()" part of previous commit,
and will fill PR for changing free() isntead.

2) Remove now unused serrno.

MFC after:      1 week
2012-06-05 16:16:33 +00:00
Andrey A. Chernov
96700463ec 1) IEEE Std 1003.1-2008, "errno" section, is explicit that
"The setting of errno after a successful call to a function is
unspecified unless the description of that function specifies that
errno shall not be modified."

However, free() in IEEE Std 1003.1-2008 does not mention its interaction
with errno, so MAY modify it after successful call
(it depends on particular free() implementation, OS-specific, etc.).

So, save errno across free() calls to make code portable and
POSIX-conformant.

2) Remove unused serrno assignment.

MFC after:      1 week
2012-06-04 21:34:49 +00:00
Glen Barber
a3fb6da9ba General mdoc(7) and typo fixes.
PR:		167734
Submitted by:	Nobuyuki Koganemaru (kogane!jp.freebsd.org)
MFC after:	3 days
2012-05-11 20:06:46 +00:00
Konstantin Belousov
fdbe55fccb According to SUSv4, realpath(3) must fail if
[ENOENT]  A component of file_name does not name an existing file or
    file_name points to an empty string.
[ENOTDIR] A component of the path prefix is not a directory, or the
    file_name argument contains at least one non- <slash> character
    and ends with one or more trailing <slash> characters and the last
    pathname component names an existing file that is neither a
    directory nor a symbolic link to a directory.
Add checks for the listed conditions, and set errno accordingly.

Update the realpath(3) manpage to mention SUS behaviour. Remove the
requirement to include sys/param.h before stdlib.h.

PR:	    128933
MFC after:  3 weeks
2012-05-11 11:29:08 +00:00
Jason Evans
a4bd5210d5 Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,
prior to 3.0.0 release) as contrib/jemalloc, and integrate it into libc.
The code being imported by this commit diverged from
lib/libc/stdlib/malloc.c in March 2010, which means that a portion of
the jemalloc 1.0.0 ChangeLog entries are relevant, as are the entries
for all subsequent releases.
2012-04-17 07:22:14 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Ed Schouten
9e16bab42a Add aligned_alloc(3).
The C11 folks reinvented the wheel by introducing an aligned version of
malloc(3) called aligned_alloc(3), instead of posix_memalign(3). Instead
of returning the allocation by reference, it returns the address, just
like malloc(3).

Reviewed by:	jasone@
2012-01-09 06:36:28 +00:00
Ed Schouten
75c73b662a Properly sort functions by name. 2012-01-08 12:04:22 +00:00
Glen Barber
bd45f5676d Add missing opening and closing brackets in getopt_long.3 and getsubopt.3
to make the examples reflect reality more closely.

MFC after:	1 week
X-MFC-After:	9.0-RELEASE
2011-12-26 03:14:37 +00:00
Dimitry Andric
e7ac9483a9 Since clang does not support the tls_model attribute used in malloc.c
yet (see LLVM PR 9788), and warns about it, rub it out for now.  When
clang grows support for this attribute, I will revert this again.

MFC after:	1 week
2011-12-15 20:40:11 +00:00
David Chisnall
4fb4550854 Small style(9) improvements.
Approved by:	dim (mentor)
2011-12-15 11:16:41 +00:00
David Chisnall
af8065219d Some fixes to the man pages for [at_]quick_exit(3)
Reviewed by:    pluknet
Approved by:    dim (mentor)
2011-12-07 21:02:35 +00:00
David Chisnall
e86328cbfb style(9) cleanups.
Approved by:	brooks (mentor)
2011-12-07 16:12:54 +00:00
David Chisnall
0a31efe016 Implement quick_exit() / at_quick_exit() from C++11 / C1x. Also add a
__noreturn macro and modify the other exiting functions to use it.

The __noreturn macro, unlike __dead2, must be used BEFORE the function.
This is in line with the C and C++ specifications that place _Noreturn (c1x)
and [[noreturn]] (C++11) in front of the functions.  As with __dead2, this
macro falls back to using the GCC attribute.

Unfortunately, clang currently sets the same value for the C version macro
in C99 and C1x modes, so these functions are hidden by default.  At some
point before 10.0, I need to go through the headers and clean up the C1x /
C++11 visibility.

Reviewed by:	brooks (mentor)
2011-12-07 15:25:48 +00:00
David Chisnall
3c87aa1d3d Implement xlocale APIs from Darwin, mainly for use by libc++. This adds a
load of _l suffixed versions of various standard library functions that use
the global locale, making them take an explicit locale parameter.  Also
adds support for per-thread locales.  This work was funded by the FreeBSD
Foundation.

Please test any code you have that uses the C standard locale functions!

Reviewed by:    das (gdtoa changes)
Approved by:    dim (mentor)
2011-11-20 14:45:42 +00:00
Ed Schouten
24a92ae013 Fix a warning emitted by Clang.
The size passed to strlcat() must depend on the input length, not the
output length. Because the input and output buffers are equal in size,
the resulting binary does not change at all.
2011-11-04 19:56:34 +00:00
Dimitry Andric
8bd9dc088e Fix building of 32-bit compat libraries on amd64 with clang, and using
-g, by reverting r219139.  The LLVM PR referenced in that revision was
fixed in the mean time, and we imported a clang snapshot soon
afterwards, so the temporary workaround of disabling clang's integrated
assembler is no longer needed.

In this particular case, using e.g. DEBUG_FLAGS=-g causes clang to
output certain directives into assembly that our version of GNU as
chokes on.

Reported by:	dougb
Approved by:	re (kib)
2011-07-18 20:07:29 +00:00
Ed Schouten
1d9a9b79d0 Fix whitespace inconsistencies in libc in files copyrighted by me. 2011-06-26 18:27:17 +00:00
Marius Strobl
1e01d8915a Change sparc64 to use the initial exec TLS model, too. This avoids random
assertion failures in _malloc_thread_cleanup().
2011-06-21 19:15:23 +00:00
Marcel Moolenaar
a8d044f390 Don't add sigwait.c to MISRCS here when sigwait.c lives under ../sys and
it's already added to SRCS there.
2011-03-17 04:30:43 +00:00
Marius Strobl
77ccab511d Now that TLS generally is available on sparc64 since r219534 turn on
support for it. Note that while sparc64 also supports the static TLS
model and thus tls_model("initial-exec"), using the default model
turned out to yield slightly better buildstone performance.
2011-03-11 21:35:38 +00:00
Ryan Stone
f88f24de4d Correct a typo in the malloc(3) manpage. Malloc options are set in the
MALLOC_OPTIONS environment variable, not JEMALLOC_OPTIONS.

Reviewed by:	jasone
Approved by:	emaste (mentor)
2011-03-07 15:19:17 +00:00
Dimitry Andric
6882fd36bf Put in a temporary workaround for ctfmerge hanging on processing
kernel.debug (or possibly other files), when WITH_CTF is active.

This is caused by a bug in clang's integrated assembler, causing malloc
to sometimes hang during initialization in statically linked executables
that use threading, such as the copy of ctfmerge that is built during
the bootstrap stage of buildworld.  The bug has been submitted upstream:

  http://llvm.org/bugs/show_bug.cgi?id=9352

Note that you might have to rebuild and install libc first, to get your
kernel build to finish, because the ctfmerge binary built during
bootstrap is linked with your base system's copy of libc.a, which might
already contain a bad copy of malloc.o.
2011-03-01 17:15:44 +00:00
Konstantin Belousov
4e738f5a8d Fix some style(9) issues.
Do not use strlcpy() where simple assignment is enough.

Noted by:	bde (long time ago)
MFC after:	1 week
2011-01-08 11:04:30 +00:00
Benedict Reuschling
a10502a58b Revert to r214147, errno is not clobbered as originally
thought.
2010-10-22 08:51:49 +00:00
Benedict Reuschling
a8af8b783a Document strtonum()s behavior of setting errno to 0 when no error is found.
PR:             docs/143330
Submitted by:   Efstratios Karatzas (gpf dot kira at gmail dot com)
Discussed with: ru@
MFC after:      7 days
2010-10-21 18:30:48 +00:00
Benedict Reuschling
e9e38bc2e7 Sync with OpenBSD rev. 1.13:
strtonum does not require limits.h

Obtained from:  OpenBSD
Discussed with: ru@
MFC after:      5 days
2010-10-21 18:21:19 +00:00
Ulrich Spörlein
0d9deed52c mdoc: drop redundant .Pp and .LP calls
They have no effect when coming in pairs, or before .Bl/.Bd
2010-10-08 12:40:16 +00:00
Konstantin Belousov
3ac535965a Missed space.
Submitted by:	brueffer
MFC after:	1 week
2010-10-06 09:24:33 +00:00
Konstantin Belousov
866dcc9462 Add cross-references to lrand48(3) and arc4random(3) from rand(3)
and random(3).

Submitted by:	Valentin Nechayev <netch netch kiev ua>
MFC after:	1 week
2010-10-06 09:05:47 +00:00
Rebecca Cran
5512804bb8 Revert changes of 'assure' to 'ensure' made in r211936.
Approved by: rrs (mentor)
2010-09-11 10:49:56 +00:00
David Xu
83c9e0893f Because POSIX does not allow EINTR to be returned from sigwait(),
add a wrapper for it in libc and rework the code in libthr, the
system call still can return EINTR, we keep this feature.

Discussed on: thread
Reviewed by:  jilles
2010-09-10 01:47:37 +00:00
Rebecca Cran
e7f8dd75b3 Fix incorrect usage of 'assure' and 'insure'.
Approved by: rrs (mentor)
2010-08-28 16:32:01 +00:00
Konstantin Belousov
3eaca8526c Do not call __pthread_cxa_finalize with invalid struct dl_phdr_info.
Reported and tested by:	Fabian Keil <freebsd-listen fabiankeil de>
MFC after:	17 days
2010-08-27 19:57:17 +00:00
Warner Losh
2c0959ae6b Powerpc is special here. powerpc and powerpc64 use different ABIs, so
their implementations aren't in the same files.  Introduce LIBC_ARCH
and use that in preference to MACHINE_CPUARCH.  Tested by amd64 and
powerpc64 builds (thanks nathanw@)
2010-08-24 20:54:43 +00:00