summaryrefslogtreecommitdiffstats
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
* Use intptr_t note ptrdiff_t when storing flags in the bottom bits ofbrooks2016-01-292-6/+6
| | | | | | | pointers. Obtained from: CheriBSD (e3a69027cc5a384431156d61c90d4304387a9b9d) Sponsored by: DARPA, AFRL
* Replace nslexer.l->nslexer.c custom rule with a -D CFLAG.bdrewery2016-01-271-8/+3
| | | | | | | | | | | This avoids reproducing the lex logic which had dependencies set wrong and used an intermediate file for modifying the YY_BUF_SIZE. This has only been possible since flex 2.5.37 was imported in r250873, which uses #ifndef YY_BUF_SIZE. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division
* nslexer.c does not depend on nsparser.h.bdrewery2016-01-271-1/+1
| | | | | | | | | | nslexer.o depends on nsparser.h, which is already added by bsd.lib.mk and .depend. This reverts r237402. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division
* Remove excess whitespacebdrewery2016-01-271-1/+1
|
* Restore flushing of output for revoke(2) again. Document revoke()'skib2016-01-261-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | intended behaviour in its man page. Simplify tty_drain() to match. Don't call ttydevsw methods in tty_flush() if the device is gone since we now sometimes call it then. The flushing was supposed to be implemented by passing the FNONBLOCK flag to VOP_CLOSE() for revoke(). The tty driver is one of the few that can block in close and was one of the fewer that knew about this. This almost worked in FreeBSD-1 and similarly in Net/2. These versions only almost worked because there was and is considerable confusion between IO_NDELAY and FNONBLOCK (aka O_NONBLOCK). IO_NDELAY is only valid for VOP_READ() and VOP_WRITE(). For other VOPs it has the same value as O_SHLOCK. But since vfs_subr.c and tty.c consistently used the wrong flag and the O_SHLOCK flag is rarely set, this mostly worked. It also gave the feature than applications could get the non-blocking close by abusing O_SHLOCK. This was first broken then fixed in 1995. I changed only the tty driver to use FNONBLOCK, as a hack to get non-blocking via the normal flag FNONBLOCK for last closes. I didn't know about revoke()'s use of IO_NDELAY or change it to be consistent, so revoke() was broken. Then I changed revoke() to match. This was next broken in 1997 then fixed in 1998. Importing Lite2 made the flags inconsistent again by undoing the fix only in vfs_subr.c. This was next broken in 2008 by replacing everything in tty.c and not checking any flags in last close. Other bugs in draining limited the resulting unbounded waits to drain in some cases. It is now possible to fix this better using the new FREVOKE flag. Just restore flushing for revoke() for now. Don't restore or undo any hacks for ordinary last closes yet. But remove dead code in the 1-second relative timeout (r272789). This did extra work to extend the buggy draining for revoke() for as long as possible. The 1-second timeout made this not very long by usually flushing after 1 second. Submitted by: bde MFC after: 2 weeks
* Replace .CURDIR with SRCTOP to respect LIBC_SRCTOP feature.bdrewery2016-01-251-5/+5
|
* sctp_sendx() needs to provide the assoc_id back.tuexen2016-01-241-2/+7
| | | | MFC after: 3 days
* Fix bug in the readpassphrase(3) function, which can be exposedsobomax2016-01-241-8/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | by application closing its stdin (i.e. STDIN_FILENO) prior to calling readpassphrase WITHOUT setting RPP_STDIN. What happens then is that the readpassphrase would open /dev/tty, and since file descriptors are reused, the call would return first unused fd, which is 0 which is also STDIN_FILENO. Then due to the usage of "input != STDIN_FILENO" in the code to do its logic, that would result in noecho flags not set on that file descriptor, which was original issue I've been trying to fix. In addition to that, the readpassphrase() would leak file descriptor on its way out, so fix that one as well. This problem can be tested with: $ ssh-add - < /tmp/myprivate.key The password will not be hidden as it should and ktrace will show: 53326 ssh-add CALL open(0x80142443c,0x100002<O_RDWR|O_CLOEXEC>,<unused>0x165f030) 53326 ssh-add NAMI "/dev/tty" 53326 ssh-add RET open 0 53326 ssh-add CALL sigprocmask(SIG_SETMASK,0x802eb1324,0x7fffffffd5e0) 53326 ssh-add RET sigprocmask 0 53326 ssh-add CALL sigaction(SIGALRM,0x7fffffffd630,0x7fffffffd610) Instead of: 57690 ssh-add CALL open(0x80142443c,0x100002<O_RDWR|O_CLOEXEC>,<unused>0x165f030) 57690 ssh-add NAMI "/dev/tty" 57690 ssh-add RET open 4 57690 ssh-add CALL ioctl(0x4,TIOCGETA,0x7fffffffd860) 57690 ssh-add RET ioctl 0 57690 ssh-add CALL ioctl(0x4,TIOCSETAF,0x7fffffffd680) 57690 ssh-add RET ioctl 0 57690 ssh-add CALL sigprocmask(SIG_SETMASK,0x802eb1324,0x7fffffffd620) 57690 ssh-add RET sigprocmask 0 57690 ssh-add CALL sigaction(SIGALRM,0x7fffffffd670,0x7fffffffd650) For the case when the key is read from the file. Technically this can also be workaround'ed at the application side by not closing the STDIN_FILENO in the first place, but readpassphrase(3) doesn't need to make any assumptions about that. Plus the file descriptor leak confirms that this is an oversight, rather than a deliberate behaviour. MFC after: 1 week
* sctp_sendv() needs to fill in the association id on return.tuexen2016-01-241-0/+7
| | | | MFC after: 3 days
* Add a standards compliance note for strtok_r as suggested by cpercival.wblock2016-01-221-1/+6
| | | | | Reviewed by: cpercival MFC after: 1 week
* sem: Don't free nameinfo that is still in list when open() fails.jilles2016-01-221-1/+3
| | | | | | | | | | This bug could be reproduced easily by calling sem_open() with O_CREAT | O_EXCL on a semaphore that is already open in the process. The struct sem_nameinfo would be freed while still in sem_list and later calls to sem_open() or sem_close() could access freed memory. PR: 206396 MFC after: 5 days
* Replace the last non-optional use of sbrk() in the tree with mmap().brooks2016-01-211-11/+4
| | | | | | | | | | All gmon want's is a region of memory without the overhead of malloc(). Just mapping some pages with mmap is an easy way to accomplish this. Approved by: jhb, cem, emaste Obtained from: CheriBSD (bf33e1e70b368ababde74aa3ac70d108c8a52c69) Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D5005
* Fix the implementations of PSEUDO_NOERROR and PSEUDO.brooks2016-01-211-7/+21
| | | | | | | | | | | | The PSEUDO* macros should not declare <syscall>, only _<syscall> and __sys_<syscall>. This was causing the interposing C wrappers to be ignored due to link order. Reviewed by: kib Obtained from: CheriBSD (4e8e13c90fc6a80e1520de44a6864cfd78b3b56d) MFC after: 1 week Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D4097
* Add .NOMETA missed in r291320.bdrewery2016-01-201-1/+1
| | | | Sponsored by: EMC / Isilon Storage Division
* mdoc: sort Xrjoel2016-01-181-1/+1
|
* Fix compilation on MIPS (typo introduced in r294227).br2016-01-181-1/+1
|
* utimensat(2): Correct description of [EINVAL] error.jilles2016-01-171-3/+6
| | | | MFC after: 4 days
* Bring in initial libc and libstand support for RISC-V.br2016-01-1728-11/+1399
| | | | | | | Reviewed by: andrew, emaste, kib Sponsored by: DARPA, AFRL Sponsored by: HEIF5 Differential Revision: https://reviews.freebsd.org/D4943
* 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.
* - Add the 'restrict' type qualifier to match function prototype.kevlo2016-01-141-4/+3
| | | | - Remove sys/types.h.
* Avoid reading pass the end of the source buffer when it is not NULbrooks2016-01-131-1/+1
| | | | | | | | | | | terminated. If this buffer is adjacent to an unmapped page or a version of C with bounds checked is used this may result in a crash. PR: 206178 Submitted by: Alexander Cherepanov <cherepan@mccme.ru> MFC after: 1 week
* Avoid reading pass the end of the source buffer when it is not NULbrooks2016-01-131-1/+1
| | | | | | | | | | | terminated. If this buffer is adjacent to an unmapped page or a version of C with bounds checked is used this may result in a crash. PR: 206177 Submitted by: Alexander Cherepanov <cherepan@mccme.ru> MFC after: 1 week
* Update futimens/utimensat for MFC to stable/10:jilles2016-01-123-4/+10
| | | | | | | | | | * Fix __FreeBSD_version check. * Update history section in man page. An MFC of this commit to stable/10 will allow using the new system calls instead of the fallback. MFC after: 3 days
* Fix a mismerge from NetBSD in r162194 with `xdr_rpcb_entry_list_ptr(..)`ngie2016-01-121-2/+2
| | | | | | | | | | | This fixes the potential NULL pointer dereference properly, and also fixes memory leaks encountered in the process of iterating through `*rp`. MFC after: 1 week Found by: Valgrind Reported by: Dan Roberts <dan.roberts@isilon.com> Submitted by: Miles Ohlrich <miles.ohlrich@isilon.com> Sponsored by: EMC / Isilon Storage Division
* Similar to r293704, fix theoretical leak of netconfig(3) resources inngie2016-01-111-2/+2
| | | | | | | | | | | __rpcbind_is_up(..) if getnetconfig(3) is partly successful in allocating resources, but not completely successful by moving the endnetconfig(3) call up before we return from the function if nconf == NULL. MFC after: 1 week Reported by: Coverity Submitted by: Miles Ohlrich <miles.ohlrich@isilon.com> Sponsored by: EMC / Isilon Storage Division
* Fix theoretical leak of netconfig(3) resources in svcunix_create(..)ngie2016-01-111-1/+1
| | | | | | | | | | | | | In the event that the getconfig(3) call in svcunix_create is partly successful, some of the netconfig(3) resources allocated might be leaked if the call returns NULL as endnetconfig(3) wasn't called explicitly in that case. Ensure that the resources are fully cleaned up by going to the `done` label, which will call endnetconfig(3) for us. MFC after: 1 week Reported by: Coverity Submitted by: Miles Ohlrich <miles.ohlrich@isilon.com> Sponsored by: EMC / Isilon Storage Division
* New sendfile(2) syscall. A joint effort of NGINX and Netflix from 2013 andglebius2016-01-081-32/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | up to now. The new sendfile is the code that Netflix uses to send their multiple tens of gigabits of data per second. The new implementation features asynchronous I/O, when I/O operations are launched, but not awaited to be complete. An explanation of why such behavior is beneficial compared to old one is going to be too long for a commit message, so we will skip it here. Additional features of new syscall are extra flags, which provide an application more control over data sent. The SF_NOCACHE flag tells kernel that data shouldn't be cached after it was sent. The SF_READAHEAD() macro allows to specify readahead size in pages. The new syscalls is a drop in replacement. No modifications are required to applications. One can take nginx binary for stable/10 and run it successfully on head. Although SF_NODISKIO lost its original sense, as now sendfile doesn't block, and now means something completely different (tm), using the new sendfile the old way is absolutely safe. Celebrates: Netflix global launch! Sponsored by: Nginx, Inc. Sponsored by: Netflix Relnotes: yes
* Add sbin and /usr/local directories to _PATH_DEFPATH.jilles2016-01-052-4/+4
| | | | | | | | | | | | | | | | | Set _PATH_DEFPATH to /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin. This is the path in the default class in the default /etc/login.conf, excluding ~/bin which would not be expanded properly in a string constant. For normal logins, _PATH_DEFPATH is overridden by /etc/login.conf, ~/.login_conf or shell startup files. _PATH_DEFPATH is still used as a default by execlp(), execvp(), posix_spawnp() and sh if PATH is not set, and by cron. Especially the latter is a common trap (most recently in PR 204813). PR: 204813 Reviewed by: secteam (delphij), alfred
* Use __alignof__ instead of assuming int64_t to get the rightimp2015-12-301-10/+1
| | | | | | alignment. Differential Revision: https://reviews.freebsd.org/D4708
* Document the recently added support for ptrace(2) LWP events.jhb2015-12-301-1/+38
|
* The FILE structure has a mbstate_t in it. This structure needs to beimp2015-12-271-2/+14
| | | | | | | | | | aligned on a int64_t boundary. However, when we allocate the array of these structures, we use ALIGNBYTES which defaults to sizeof(int) on arm, i386 and others. The i386 stuff can handle unaligned accesses seemlessly. However, arm cannot. Take this into account when creating the array of FILEs, and add some comments about why. Differential Revision: https://reviews.freebsd.org/D4708
* Verify that tv_sec value specified in settimeofday() and clock_settime()dchagin2015-12-272-2/+8
| | | | | | | | | | | | | | (CLOCK_REALTIME case) system calls is non negative. This commit hides a kernel panic in atrtc_settime() as the clock_ts_to_ct() does not properly convert negative tv_sec. ps. in my opinion clock_ts_to_ct() should be rewritten to properly handle negative tv_sec values. Differential Revision: https://reviews.freebsd.org/D4714 Reviewed by: kib MFC after: 1 week
* 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
* Make libxnet.so a symlink to libc.so. This makes `-lxnet` a no-op, ascperciva2015-12-251-0/+1
| | | | | | | | | POSIX requires for the c99 compiler. (In fact, our c99(1) already ignores -lxnet; but our make(1) doesn't set ${CC} correctly, and our cc(1) treats xnet like any other library.) Reviewed by: kib
* Remove _gethostbynisname() and _gethostbynisaddr(). These functionsume2015-12-252-57/+0
| | | | | | used to be called from getipnodebyname(). MFC after: 1 week
* Do not compile ARMv6 instructions on ARMv4/v5. Although clang is finekib2015-12-241-0/+7
| | | | | | | | with mrrc, gcc is not. The disabled code is not executed on ARMv4 anyway. Reported and reviewed by: ian Sponsored by: The FreeBSD Foundation
* Increase the timeout for resolv_test from the default (300 seconds) tongie2015-12-232-4/+13
| | | | | | | | | | | | | | 450 seconds This is required on slower network connections, and on older releases (stable/10 seems to be slower as far as name resolution goes.. not sure why yet). Remove an outdated comment in the Makefile from when I was working on this code over a year ago on github MFC after: 1 week Sponsored by: EMC / Isilon Storage Division
* Support a.out format in nlist only on i386emaste2015-12-221-2/+2
| | | | | | | | | i386 is the only current FreeBSD architecture that ever used a.out format. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D4687
* Let tsearch()/tdelete() use an AVL tree.ed2015-12-226-86/+605
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* We don't need to use a temporary buffer, here.ume2015-12-221-7/+3
| | | | MFC after: 1 week
* Use _map_v4v6_address().ume2015-12-211-4/+3
| | | | MFC after: 1 week
* Simplify _map_v4v6_address().ume2015-12-211-7/+3
| | | | | Suggested by: hrs MFC after: 1 week
* If we end up following a CNAME chain that does not findume2015-12-211-1/+6
| | | | | | | | any data return that instead of internal error. PR: 156684 Obtained from: NetBSD MFC after: 1 week
* libc: Use namespace.h in a few more files.jilles2015-12-204-11/+19
| | | | | libc now no longer calls fstat(), socketpair() and wait(), only the underscore-prefixed versions (_waitpid() instead of wait()).
* addrinfo.ai_family is an address family, not a protocol family.ume2015-12-201-8/+8
| | | | | PR: 162434 MFC after: 1 week
* clock_gettime(2),gettimeofday(2): Remove [EFAULT] error.jilles2015-12-202-8/+2
| | | | | | | | | | | Depending on system configuration and parameters, clock_gettime() and gettimeofday() may not be system calls. If so, passing an invalid pointer will cause a signal and not an [EFAULT] error. From a standards perspective, this is OK since passing an invalid pointer is undefined behaviour. MFC after: 1 week
* Fix lockf(3) cancellation behaviour.kib2015-12-201-3/+8
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Use _map_v4v6_address().ume2015-12-181-4/+3
| | | | | Suggested by: hrs MFC after: 1 week
* Add AI_V4MAPPED and AI_ALL support for getaddrinfo(3).ume2015-12-182-28/+174
| | | | | PR: 198092 MFC after: 1 week
* Iterate down lib/libc/tests/nss...ngie2015-12-161-0/+1
| | | | | | MFC after: 1 week X-MFC with: r292323 Sponsored by: EMC / Isilon Storage Division
OpenPOWER on IntegriCloud