aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc
AgeCommit message (Collapse)AuthorFilesLines
2018-08-24Implement address space guards.kib1-0/+1
Guard, requested by the MAP_GUARD mmap(2) flag, prevents the reuse of the allocated address space, but does not allow instantiation of the pages in the range. It is useful for more explicit support for usual two-stage reserve then commit allocators, since it prevents accidental instantiation of the mapping, e.g. by mprotect(2). Use guards to reimplement stack grow code. Explicitely track stack grow area with the guard, including the stack guard page. On stack grow, trivial shift of the guard map entry and stack map entry limits makes the stack expansion. Move the code to detect stack grow and call vm_map_growstack(), from vm_fault() into vm_map_lookup(). As result, it is impossible to get random mapping to occur in the stack grow area, or to overlap the stack guard page. Enable stack guard page by default. Reviewed by: alc, markj Man page update reviewed by: alc, bjk, emaste, markj, pho Tested by: pho, Qualys Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D11306 (man pages)
2018-08-24Listening sockets improvements.glebius1-6/+10
o Separate fields of struct socket that belong to listening from fields that belong to normal dataflow, and unionize them. This shrinks the structure a bit. - Take out selinfo's from the socket buffers into the socket. The first reason is to support braindamaged scenario when a socket is added to kevent(2) and then listen(2) is cast on it. The second reason is that there is future plan to make socket buffers pluggable, so that for a dataflow socket a socket buffer can be changed, and in this case we also want to keep same selinfos through the lifetime of a socket. - Remove struct struct so_accf. Since now listening stuff no longer affects struct socket size, just move its fields into listening part of the union. - Provide sol_upcall field and enforce that so_upcall_set() may be called only on a dataflow socket, which has buffers, and for listening sockets provide solisten_upcall_set(). o Remove ACCEPT_LOCK() global. - Add a mutex to socket, to be used instead of socket buffer lock to lock fields of struct socket that don't belong to a socket buffer. - Allow to acquire two socket locks, but the first one must belong to a listening socket. - Make soref()/sorele() to use atomic(9). This allows in some situations to do soref() without owning socket lock. There is place for improvement here, it is possible to make sorele() also to lock optionally. - Most protocols aren't touched by this change, except UNIX local sockets. See below for more information. o Reduce copy-and-paste in kernel modules that accept connections from listening sockets: provide function solisten_dequeue(), and use it in the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4), infiniband, rpc. o UNIX local sockets. - Removal of ACCEPT_LOCK() global uncovered several races in the UNIX local sockets. Most races exist around spawning a new socket, when we are connecting to a local listening socket. To cover them, we need to hold locks on both PCBs when spawning a third one. This means holding them across sonewconn(). This creates a LOR between pcb locks and unp_list_lock. - To fix the new LOR, abandon the global unp_list_lock in favor of global unp_link_lock. Indeed, separating these two locks didn't provide us any extra parralelism in the UNIX sockets. - Now call into uipc_attach() may happen with unp_link_lock hold if, we are accepting, or without unp_link_lock in case if we are just creating a socket. - Another problem in UNIX sockets is that uipc_close() basicly did nothing for a listening socket. The vnode remained opened for connections. This is fixed by removing vnode in uipc_close(). Maybe the right way would be to do it for all sockets (not only listening), simply move the vnode teardown from uipc_detach() to uipc_close()? Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D9770
2018-08-24Implement INHERIT_ZERO for minherit(2).delphij1-0/+1
INHERIT_ZERO is an OpenBSD feature. When a page is marked as such, it would be zeroed upon fork(). This would be used in new arc4random(3) functions. PR: 182610 Reviewed by: kib (earlier version) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D427
2018-08-24Renumber copyright clause 4imp1-1/+1
Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96
2018-08-24mprotect(): Change prototype to comply to POSIX.ed@FreeBSD.org1-1/+1
Our mprotect() function seems to take a "const void *" address to the pages whose permissions need to be adjusted. POSIX uses "void *". Simply stick to the POSIX one to prevent us from writing unportable code. PR: 211423 (exp-run) Tested by: antoine@ (Thanks!)
2018-08-24Implement process-shared locks supportkib1-0/+7
for libthr.so.3, without breaking the ABI. Special value is stored in the lock pointer to indicate shared lock, and offline page in the shared memory is allocated to store the actual lock. Reviewed by: vangyzen (previous version) Discussed with: deischen, emaste, jhb, rwatson, Martin Simmons <martin@lispworks.com> Tested by: pho Sponsored by: The FreeBSD Foundation
2018-08-24Add a new file operations hook for mmapjhb1-2/+0
operations. File type-specific logic is now placed in the mmap hook implementation rather than requiring it to be placed in sys/vm/vm_mmap.c. This hook allows new file types to support mmap() as well as potentially allowing mmap() for existing file types that do not currently support any mapping. The vm_mmap() function is now split up into two functions. A new vm_mmap_object() function handles the "back half" of vm_mmap() and accepts a referenced VM object to map rather than a (handle, handle_type) tuple. vm_mmap() is now reduced to converting a (handle, handle_type) tuple to a a VM object and then calling vm_mmap_object() to handle the actual mapping. The vm_mmap() function remains for use by other parts of the kernel (e.g. device drivers and exec) but now only supports mapping vnodes, character devices, and anonymous memory. The mmap() system call invokes vm_mmap_object() directly with a NULL object for anonymous mappings. For mappings using a file descriptor, the descriptors fo_mmap() hook is invoked instead. The fo_mmap() hook is responsible for performing type-specific checks and adjustments to arguments as well as possibly modifying mapping parameters such as flags or the object offset. The fo_mmap() hook routines then call vm_mmap_object() to handle the actual mapping. The fo_mmap() hook is optional. If it is not set, then fo_mmap() will fail with ENODEV. A fo_mmap() hook is implemented for regular files, character devices, and shared memory objects (created via shm_open()). While here, consistently use the VM_PROT_* constants for the vm_prot_t type for the 'prot' variable passed to vm_mmap() and vm_mmap_object() as well as the vm_mmap_vnode() and vm_mmap_cdev() helper routines. Previously some places were using the mmap()-specific PROT_* constants instead. While this happens to work because PROT_xx == VM_PROT_xx, using VM_PROT_* is more correct. Differential Revision: https://reviews.freebsd.org/D2658 Reviewed by: alc (glanced over), kib MFC after: 1 month Sponsored by: Chelsio
2018-08-24Retire the unimplemented MAP_RENAMEjhb1-2/+2
and MAP_NORESERVE flags to mmap(2). Older binaries are still permitted to use these flags. PR: 193961 (exp-run in ports) Differential Revision: https://reviews.freebsd.org/D848 Reviewed by: kib
2018-08-24Add a new fo_fill_kinfo fileops methodjhb1-1/+0
to add type-specific information to struct kinfo_file. - Move the various fill_*_info() methods out of kern_descrip.c and into the various file type implementations. - Rework the support for kinfo_ofile to generate a suitable kinfo_file object for each file and then convert that to a kinfo_ofile structure rather than keeping a second, different set of code that directly manipulates type-specific file information. - Remove the shm_path() and ksem_info() layering violations. Differential Revision: https://reviews.freebsd.org/D775 Reviewed by: kib, glebius (earlier version)
2018-08-24Add MAP_EXCL flag for mmap(2).kib1-0/+1
It should be combined with MAP_FIXED, and prevents the request from deleting existing mappings in the region, failing instead. Reviewed by: alc Discussed with: jhb Tested by: markj, pho (previous version, as part of the bigger patch) Sponsored by: The FreeBSD Foundation MFC after: 1 week
2018-08-24Add a mmap flag (MAP_32BIT) on 64-bit platformsjhb1-0/+3
to request that a mapping use an address in the first 2GB of the process's address space. This flag should have the same semantics as the same flag on Linux. To facilitate this, add a new parameter to vm_map_find() that specifies an optional maximum virtual address. While here, fix several callers of vm_map_find() to use a VMFS_* constant for the findspace argument instead of TRUE and FALSE. Reviewed by: alc Approved by: re (kib)
2018-08-24Implement read(2)/write(2) and neccessary lseek(2)kib1-0/+7
for posix shmfd. Add MAC framework entries for posix shm read and write. Do not allow implicit extension of the underlying memory segment past the limit set by ftruncate(2) by either of the syscalls. Read and write returns short i/o, lseek(2) fails with EINVAL when resulting offset does not fit into the limit. Discussed with: alc Tested by: pho Sponsored by: The FreeBSD Foundation
2018-08-24Add __nl_item to <sys/_types.h> and use itSebastian Huber2-4/+4
Add __nl_item to <sys/_types.h> for FreeBSD compatibility. Use it in <langinfo.h> and the Cygwin <nl_types.h>. Make the enum __nl_item in <langinfo.h> anonymous. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-20RTEMS: Add __tls_get_addr() to crt0Sebastian Huber1-1/+2
Add __tls_get_addr() for all targets to crt0. This is not only used on ARM. In particular, it is used on RISC-V. This helps to adequately support the GCC libgomp. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de
2018-08-16Fix strtof ("-nan") returns positive NaNMasamichi Hosoda1-2/+2
strtof ("-nan") returned positive NaN instead of negative NaN. strtod ("-nan") and strtold ("-nan") return negative NaN. Linux glibc has been fixed that strto{f|d|ld} ("-nan") returns negative NaN. https://sourceware.org/bugzilla/show_bug.cgi?id=23007 This commit makes strtof preserves the negative sign bit when parsing "-nan" like glibc.
2018-08-16Remove unused NaN's integer representation definitionsMasamichi Hosoda6-93/+8
By previous commit, strto{d|ld} ("nan") does not use the definition of NaN. There is no other function that uses the definitions. This commit remove the definitions.
2018-08-16Fix strtod ("nan") and strtold ("nan") returns wrong negative NaNMasamichi Hosoda2-9/+2
The definition of qNaN for x86_64 and i386 was wrong. strto{d|ld} ("nan") returned wrong negative NaN instead of correct positive NaN since it used the wrong definition. On the other hand, strtof ("nan") returns correct positive NaN since it uses nanf ("") instead of the wrong definition. This commit makes strto{d|ld} ("nan") uses {nan|nanl} ("") like strtof ("nan") using. So strto{d|ld} ("nan") returns positive NaN.
2018-08-13Added Restriction on base valueAditya Upadhyay1-0/+4
2018-08-08newlib: strftime: fix over-enthusiastic fix from 0283642f35ceCorinna Vinschen1-1/+2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: don't check malloc/free pointerCorinna Vinschen2-17/+2
use preprocessor check for MALLOC_PROVIDED instead Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: fix various gcc warningsCorinna Vinschen6-14/+17
* unused variables * potentially used uninitialized * suggested bracketing * misleading indentation Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: wordexp: drop dangerous fprintfCorinna Vinschen1-2/+2
wordexp uses fprintf in a dangerous way. It uses an unchecked input string as format string, rather than as parameter to a %s. Replace fprintf with fputs. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: newlocale: fix typo rendering ctype_ptr invalidCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: strftime: fix gcc warning on __ctlocCorinna Vinschen1-5/+3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08RTEMS: Add aligned_alloc() to crt0Sebastian Huber1-1/+3
This is necessary to build the latest GCC 7 branch. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85904 Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-07Declare GNU-specific sched_getcpu()Sebastian Huber1-0/+4
This is a glibc extension. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30RISC-V: Do not use _init/_finiSebastian Huber2-0/+8
Introduce new host configuration variable "have_init_fini" which is set to "yes" by default. Override it for RISC-V to "no". Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30Add attributes to allocator functionsSebastian Huber1-4/+5
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30FreeBSD compat. __alloc_size(), __alloc_align()Sebastian Huber2-5/+5
Restore FreeBSD compatibility for __alloc_size() and __alloc_align(). This is a follow-up to commit e494b560350cabef94126a4478096aae89ae35a0. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30Define a new __alloc_size2 attribute to complement the exiting support.pfg1-0/+2
At least on GCC7 calling __alloc_size(x) twice is not equivalent to calling using the attribute once with two arguments. The later is the documented use in GCC documentation so add a new alloc_size(n, x) alternative to cover for the few places where it is used: basically: calloc(3), reallocarray(3) and mallocarray(9). Submitted by: Mark Millard MFC after: 3 days Reference: http://docs.freebsd.org/cgi/mid.cgi?F227842D-6BE2-4680-82E7-07906AF61CD7
2018-07-30Remove lint support from system headers and MD x86 headers.kib1-15/+3
Reviewed by: dim, jhb Discussed with: imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D13156
2018-07-30sys: further adoption of SPDX licensing ID tags.pfg1-0/+2
Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point.
2018-07-30Make _Static_assert() work with GCC in older C++ standards.ed@FreeBSD.org1-1/+1
GCC only activates C11 keywords in C mode, not C++ mode. This means that when targeting an older C++ standard, we cannot fall back to using _Static_assert(). In this case, do define _Static_assert() as a macro that uses a typedef'ed array. Discussed in: r322875 commit thread Reported by: Mark MIllard MFC after: 1 month
2018-07-30ctype: Avoid GCC note in towctrans_l.cSebastian Huber1-2/+2
The previous version genenerated the following GCC note: towctrans_l.c:44:1: note: offset of packed bit-field 'diff' has changed in GCC 4.4 caseconv_table [] = { ^~~~~~~~~~~~~~ Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30ctype: Fix integer type for caseconv_entry::deltaSebastian Huber1-1/+1
The commit 46ba1675c457324b0eeef4670a09101ef3f34c50 accidently changed a bit-field from signed to unsigned. The caseconv_entry::delta must be a signed integer, see also "newlib/libc/ctype/caseconv.t". Unfortunately, a standard GCC/Newlib build is done without -Wsign-conversion. Using this warning option would have helped to avoid this bug: caseconv.t:2:22: warning: unsigned conversion from 'int' to 'unsigned int:17' changes value from '-32' to '131040' [-Wsign-conversion] {0x0061, 25, TOUP, -32}, Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30Fix comparison between two character arraysJordi Sanfeliu1-1/+1
Hello, The member 'id' in the 'utmp' struct is not a numeric but a character array, hence the strncmp() function is needed to compare two members.
2018-07-25Cygwin: define _POSIX_ASYNCHRONOUS_IOYaakov Selkowitz1-1/+1
This feature is now available as of the recent AIO commits. Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-07-20ctype: Fix bitfield types on 16-bit targetsnewlib-snapshot-20180720Sebastian Huber2-6/+8
This prevents errors like this: newlib/libc/ctype/categories.c:6:3: error: width of 'first' exceeds its type unsigned int first: 24; ^ Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-20RTEMS: Unconditionally define _off_t to int64_tSebastian Huber1-4/+0
Exotic RTEMS targets can define this back to int32_t as an exception if there are good reasons. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-17Print sign of NaN values to nano-vfprintf.Kumar Gala1-0/+2
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-13Fix to stop a fall-through in a switch statementJordi Sanfeliu1-0/+1
The following fixes a fall-through that prevented from reading the next entry in the UTMP file and terminated the program with an abort().
2018-07-13strcmp.S: Improve performance for misaligned stringsSiddhesh Poyarekar1-11/+40
Replace the simple byte-wise compare in the misaligned case with a dword compare with page boundary checks in place. For simplicity I've chosen a 4K page boundary so that we don't have to query the actual page size on the system. This results in up to 3x improvement in performance in the unaligned case on falkor and about 2.5x improvement on mustang as measured using bench-strcmp in glibc.
2018-07-13memcmp.S: optimize for medium to large sizesSiddhesh Poyarekar1-44/+100
This improved memcmp provides a fast path for compares up to 16 bytes and then compares 16 bytes at a time, thus optimizing loads from both sources. The glibc memcmp microbenchmark retains performance (with an error of ~1ns) for smaller compare sizes and reduces up to 31% of execution time for compares up to 4K on the APM Mustang. On Qualcomm Falkor this improves to almost 48%, i.e. it is almost 2x improvement for sizes of 2K and above.
2018-07-13Improve strncmp for mutually misaligned inputsSiddhesh Poyarekar1-17/+79
The mutually misaligned inputs on aarch64 are compared with a simple byte copy, which is not very efficient. Enhance the comparison similar to strcmp by loading a double-word at a time. The peak performance improvement (i.e. 4k maxlen comparisons) due to this on the strncmp microbenchmark in glibc is as follows: falkor: 3.5x (up to 72% time reduction) cortex-a73: 3.5x (up to 71% time reduction) cortex-a53: 3.5x (up to 71% time reduction) All mutually misaligned inputs from 16 bytes maxlen onwards show upwards of 15% improvement and there is no measurable effect on the performance of aligned/mutually aligned inputs.
2018-07-06Move __HAVE_FAST_FMA to math_config.hSzabolcs Nagy1-23/+0
Define it consistently with other HAVE_* macros that only affect code using math_config.h. This is also closer to the Arm Optimized Routines code.
2018-07-05Fix newlib functions perror()/psignal() not to use writev().Takashi Yano2-37/+39
This fix is for some platforms which do not have writev(). *perror.c: Use _write_r() instead of writev(). *psignal.c: Use write() insetad of writev(). Revise commit: d4f4e7ae1be1bcf8c021f2b0865aafc16b338aa3
2018-07-04Fix a bug of perror()/psignal() that changes the orientation of stderr.Takashi Yano2-8/+54
* perror.c: Fix the problem that perror() changes the orientation of stderr to byte-oriented mode if stderr is not oriented yet. * psignal.c: Ditto.
2018-06-27newlib: enable new math functions on CygwinCorinna Vinschen1-0/+4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-27New log implementationSzabolcs Nagy1-0/+23
The new implementations are provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.519 ULP with inlined fma and fma contraction. It uses a 2 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1703 bytes. The w_log.c wrapper is disabled since error handling is inline in the new code. New __HAVE_FAST_FMA and __HAVE_FAST_FMA_DEFAULT feature macros were added to enable selecting between the code path that uses fma and the one that does not. Targets supposed to set __HAVE_FAST_FMA_DEFAULT if they have single instruction fma and the compiler can actually inline it (gcc has __FP_FAST_FMA macro but that does not guarantee inlining with -fno-builtin-fma). Improvements on Cortex-A72: latency: 1.9x thruput: 2.3x
2018-06-26Fix Unicode table.Takashi Yano2-26/+16
* (mkcategories): Fix a bug that outputs incorrect Unicode category table for code point ranges. * (categories.t): Rebuild it using the bug-fixed mkcategories. This fixes the problem reported in the following post. https://cygwin.com/ml/cygwin/2018-06/msg00248.html