sync with OpenBSD -current

This commit is contained in:
purplerain 2024-01-16 16:00:24 +00:00
parent 34a3d7e18a
commit ee68147dcd
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
30 changed files with 722 additions and 211 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_map.c,v 1.319 2023/08/02 09:19:47 mpi Exp $ */
/* $OpenBSD: uvm_map.c,v 1.320 2024/01/16 19:05:01 deraadt Exp $ */
/* $NetBSD: uvm_map.c,v 1.86 2000/11/27 08:40:03 chs Exp $ */
/*
@ -3407,7 +3407,8 @@ uvmspace_exec(struct proc *p, vaddr_t start, vaddr_t end)
* when a process execs another program image.
*/
vm_map_lock(map);
vm_map_modflags(map, 0, VM_MAP_WIREFUTURE|VM_MAP_SYSCALL_ONCE);
vm_map_modflags(map, 0, VM_MAP_WIREFUTURE |
VM_MAP_SYSCALL_ONCE | VM_MAP_PINSYSCALL_ONCE);
/*
* now unmap the old program
@ -3944,7 +3945,8 @@ uvmspace_fork(struct process *pr)
new_map, new_entry->start, new_entry->end);
}
}
new_map->flags |= old_map->flags & VM_MAP_SYSCALL_ONCE;
new_map->flags |= old_map->flags &
(VM_MAP_SYSCALL_ONCE | VM_MAP_PINSYSCALL_ONCE);
#ifdef PMAP_CHECK_COPYIN
if (PMAP_CHECK_COPYIN) {
memcpy(&new_map->check_copyin, &old_map->check_copyin,

View file

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_map.h,v 1.87 2023/08/02 09:19:47 mpi Exp $ */
/* $OpenBSD: uvm_map.h,v 1.88 2024/01/16 19:05:01 deraadt Exp $ */
/* $NetBSD: uvm_map.h,v 1.24 2001/02/18 21:19:08 chs Exp $ */
/*
@ -329,6 +329,7 @@ struct vm_map {
#define VM_MAP_GUARDPAGES 0x20 /* rw: add guard pgs to map */
#define VM_MAP_ISVMSPACE 0x40 /* ro: map is a vmspace */
#define VM_MAP_SYSCALL_ONCE 0x80 /* rw: libc syscall registered */
#define VM_MAP_PINSYSCALL_ONCE 0x100 /* rw: pinsyscall done */
/* Number of kernel maps and entries to statically allocate */
#define MAX_KMAPENT 1024 /* Sufficient to make it to the scheduler. */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_mmap.c,v 1.183 2023/12/07 13:59:05 deraadt Exp $ */
/* $OpenBSD: uvm_mmap.c,v 1.184 2024/01/16 19:05:01 deraadt Exp $ */
/* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */
/*
@ -644,13 +644,65 @@ sys_pinsyscall(struct proc *p, void *v, register_t *retval)
return (0);
}
/*
* sys_pinsyscalls
/*
* sys_pinsyscalls. The caller is required to normalize base,len
* to the minimum .text region, and adjust pintable offsets relative
* to that base.
*/
int
sys_pinsyscalls(struct proc *p, void *v, register_t *retval)
{
/* STUB until other parts are ready */
struct sys_pinsyscalls_args /* {
syscallarg(void *) base;
syscallarg(size_t) len;
syscallarg(u_int *) pins;
syscallarg(int) npins;
} */ *uap = v;
struct process *pr = p->p_p;
int npins, error = 0, i;
vaddr_t base;
size_t len;
u_int *pins;
if (pr->ps_libcpin.pn_start ||
(pr->ps_vmspace->vm_map.flags & VM_MAP_PINSYSCALL_ONCE))
return (EPERM);
base = (vaddr_t)SCARG(uap, base);
len = (vsize_t)SCARG(uap, len);
if (base > SIZE_MAX - len)
return (EINVAL); /* disallow wrap-around. */
/* XXX MP unlock */
npins = SCARG(uap, npins);
if (npins < 1 || npins > SYS_MAXSYSCALL)
return (E2BIG);
pins = malloc(npins * sizeof(u_int), M_PINSYSCALL, M_WAITOK|M_ZERO);
if (pins == NULL)
return (ENOMEM);
error = copyin(SCARG(uap, pins), pins, npins * sizeof(u_int));
if (error)
goto err;
/* Range-check pintable offsets */
for (i = 0; i < npins; i++) {
if (pins[i] == (u_int)-1 || pins[i] == 0)
continue;
if (pins[i] > SCARG(uap, len)) {
error = ERANGE;
break;
}
}
if (error) {
err:
free(pins, M_PINSYSCALL, npins * sizeof(u_int));
return (error);
}
pr->ps_libcpin.pn_start = base;
pr->ps_libcpin.pn_end = base + len;
pr->ps_libcpin.pn_pins = pins;
pr->ps_libcpin.pn_npins = npins;
pr->ps_flags |= PS_LIBCPIN;
return (0);
}