Commit Graph

183 Commits

Author SHA1 Message Date
kib eb82d7086c Implement address space guards.
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-24 15:00:02 +02:00
glebius 99b9b925fe Listening sockets improvements.
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-24 15:00:02 +02:00
delphij ca3b7a988a Implement INHERIT_ZERO for minherit(2).
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-24 15:00:02 +02:00
imp 16636ede3c Renumber copyright clause 4
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-24 15:00:02 +02:00
ed@FreeBSD.org 08139e557b mprotect(): Change prototype to comply to POSIX.
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-24 15:00:02 +02:00
kib c3df6d5155 Implement process-shared locks support
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-24 15:00:02 +02:00
jhb 7cfc736e89 Add a new file operations hook for mmap
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-24 15:00:02 +02:00
jhb 60b466fbc2 Retire the unimplemented MAP_RENAME
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-24 15:00:02 +02:00
jhb 3d5043e2cb Add a new fo_fill_kinfo fileops method
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-24 15:00:02 +02:00
kib de24ef326d Add MAP_EXCL flag for mmap(2).
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-24 15:00:02 +02:00
jhb 472476a5a7 Add a mmap flag (MAP_32BIT) on 64-bit platforms
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-24 15:00:02 +02:00
kib e6a85661ce Implement read(2)/write(2) and neccessary lseek(2)
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-24 15:00:02 +02:00
Sebastian Huber 3bc64b88c3 RTEMS: Add __tls_get_addr() to crt0
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-20 13:54:22 +02:00
Sebastian Huber dedeea9965 RTEMS: Add aligned_alloc() to crt0
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-08 08:42:28 +02:00
Sebastian Huber 916ef5fb88 RTEMS: Unconditionally define _off_t to int64_t
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-20 06:53:21 +02:00
Jeff Johnston cd31fbb2ae Add nvptx port.
- From: Cesar Philippidis <cesar@codesourcery.com>
  Date: Tue, 10 Apr 2018 14:43:42 -0700
  Subject: [PATCH] nvptx port

  This port adds support for Nvidia GPU's, which are primarily used as
  offload accelerators in OpenACC and OpenMP.
2018-04-13 15:42:37 -04:00
Joel Sherrill 5b97e36239 rtems/.../dirent.h: Add alphasort() prototype 2018-03-13 09:11:47 -05:00
Sebastian Huber f641474cb2 RTEMS: Use int for _CLOCKID_T_
Linux and FreeBSD use int as well.  In addition, this fixes an Ada
incompatiblity problem on 64-bit targets.  See also GCC:

  gcc/ada/libgnarl/s-osinte__rtems.ads

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-03-06 11:40:16 +01:00
Jeff Johnston fffd2770db Bump release to 3.0.0 for yearly snapshot
- major release required due to removal of K&R support
2018-01-18 13:07:45 -05:00
Yaakov Selkowitz 67ee0cac4c ansification: remove _VOID
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17 11:47:20 -06:00
Yaakov Selkowitz e6321aa6a6 ansification: remove _PTR
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17 11:47:16 -06:00
Sebastian Huber dadc9e7e4a RTEMS: Add semaphore <sys/lock.h> functions
Declare semaphore try wait and post binary functions.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-30 07:00:45 +01:00
Sebastian Huber 5a2ab9d55e RTEMS: Timed wait by ticks <sys/lock.h> functions
Declare timed wait by ticks functions.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-30 07:00:45 +01:00
Sebastian Huber 186166f67a RTEMS: Add set/get name <sys/lock.h> functions
Add inline functions to set/get the name.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-30 07:00:45 +01:00
Sebastian Huber 6480987f3a RTEMS: Add missing __getreent() to crt0
Default implementation was removed for RTEMS by
b1a388799d.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-20 10:12:18 +01:00
Sebastian Huber 0e3e375377 RTEMS: Add missing functions to crt0
This helps to get some more features from libstdc++.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-20 08:53:30 +01:00
Sebastian Huber ce189d8afe RTEMS: Remove internal timecounter API
Change copyright.  Original BSD content moved to
<machine/_kernel_time.h>.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-26 08:47:21 +02:00
Sebastian Huber c165a27c01 RTEMS: Fix _PTHREAD_MUTEX_INITIALIZER
Add missing braces around initializer.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-13 08:07:13 +02:00
Sebastian Huber 3a79700c2d RTEMS: Make pthread_mutex_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber 55c5dda9b5 RTEMS: Make pthread_cond_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber d902eef093 RTEMS: Make pthread_rwlock_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber 9187bb23a0 RTEMS: Make pthread_barrier_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber 8253c240cb RTEMS: Make sem_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:12 +02:00
Sebastian Huber 4fef7312b3 RTEMS: Optimize pthread_once_t
Reduce size of pthread_once_t and make it zero-initialized.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:12 +02:00
Sebastian Huber 524eb4dc29 RTEMS: Use __uint64_t for _CLOCK_T_
This addresses:

https://devel.rtems.org/ticket/2135

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-08-25 14:25:42 +02:00
Sebastian Huber a3617d7bde Synchronize RTEMS <sys/bitset.h> with FreeBSD
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-07-12 08:04:45 +02:00
Sebastian Huber 1d49ce4d6b Synchronize RTEMS <sys/bitset.h> with FreeBSD
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-07-10 07:18:10 +02:00
Sebastian Huber 0fbd27dd1e Remove FreeBSD specifics from RTEMS <arpa/inet.h>
For whatever reason FreeBSD renames several functions provided by
<arpa/inet.h> and uses weak references to provide the standard function
names.  This causes problems on targets lacking proper support for weak
references.  We do not need this function renaming on RTEMS.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-12 08:41:24 +02:00
Sebastian Huber e9085e0ccd Fix RTEMS ioctl() declaration
Using uint32_t for ioctl_command_t does not work well on 64-bit targets.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:20 +02:00
Sebastian Huber dc93d7adff Update FreeBSD revision of RTEMS <sys/bitset.h>
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:20 +02:00
Sebastian Huber fd5d052d40 Fix some RTEMS CPUSET(9) macros
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:19 +02:00
Sebastian Huber c29f5b219d Fix RTEMS CPU_EQUAL_S()
According to the FreeBSD man page BIT_CMP() returns true in case the two
sets are NOT equal.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:19 +02:00
Sebastian Huber d70983ea1b Add de-facto standard <sys/ioctl.h> for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:42:08 -04:00
Sebastian Huber fa88e93d3d Add some POSIX header files for RTEMS
Add the POSIX header files

  * arpa/inet.h
  * net/if.h
  * netdb.h
  * netinet/in.h
  * netinet/tcp.h
  * sys/socket.h
  * sys/syslog.h
  * sys/uio.h
  * sys/un.h
  * syslog.h
  * termios.h

and their dependencies for RTEMS.  The origin of these files is the
latest FreeBSD.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:41:33 -04:00
Sebastian Huber 0b915d6be0 FreeBSD compatibility for RTEMS <sys/cpuset.h>
Make the RTEMS <sys/cpuset.h> compatible with the latest FreeBSD
version.

Fix the CPU_COPY() parameter order, see also:

https://devel.rtems.org/ticket/3023

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:36:27 -04:00
Sebastian Huber 764eda728f Add __bitcount*() to RTEMS <machine/types.h>
Use a dedicated header file <machine/_bitcount.h> to avoid cyclic header
dependencies in future changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:35:38 -04:00
Sebastian Huber 0008601042 Increase MSIZE for RTEMS
Increase the MSIZE for RTEMS to be in line with the latest FreeBSD
version.  The legacy network stack of RTEMS will provides its own
definition.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:33:59 -04:00
Sebastian Huber 2efb117047 FreeBSD compatibility for RTEMS <sys/param.h>
Update the RTEMS <machine/param.h> and <sys/param.h> to be compatible
with the latest FreeBSD version.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:33:40 -04:00
Sebastian Huber 15b59a15b4 Add generic <machine/_align.h> for RTEMS
It uses __BIGGEST_ALIGNMENT__ which is available in recent GCC and
LLVM/clang.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:33:02 -04:00
Joel Sherrill 6e3a2037eb rtems/crt0.c: getentropy() stub did not return a value.
Coverity Scan ID: 175342
2017-03-15 12:04:28 -05:00