aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/amd64/machdep.c2
-rw-r--r--sys/amd64/cloudabi32/cloudabi32_sysvec.c12
-rw-r--r--sys/amd64/cloudabi64/cloudabi64_sysvec.c7
-rw-r--r--sys/amd64/ia32/ia32_signal.c2
-rw-r--r--sys/amd64/linux/linux_sysvec.c69
-rw-r--r--sys/amd64/linux32/linux32_sysvec.c66
-rw-r--r--sys/arm/arm/machdep.c2
-rw-r--r--sys/arm/cloudabi32/cloudabi32_sysvec.c2
-rw-r--r--sys/arm64/arm64/elf32_machdep.c2
-rw-r--r--sys/arm64/arm64/machdep.c2
-rw-r--r--sys/arm64/cloudabi32/cloudabi32_sysvec.c2
-rw-r--r--sys/arm64/cloudabi64/cloudabi64_sysvec.c2
-rw-r--r--sys/arm64/linux/linux_sysvec.c65
-rw-r--r--sys/compat/cloudabi32/cloudabi32_module.c22
-rw-r--r--sys/compat/cloudabi32/cloudabi32_util.h4
-rw-r--r--sys/compat/cloudabi64/cloudabi64_module.c22
-rw-r--r--sys/compat/cloudabi64/cloudabi64_util.h4
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c32
-rw-r--r--sys/compat/freebsd32/freebsd32_util.h2
-rw-r--r--sys/compat/ia32/ia32_signal.h2
-rw-r--r--sys/i386/cloudabi32/cloudabi32_sysvec.c12
-rw-r--r--sys/i386/i386/machdep.c2
-rw-r--r--sys/i386/linux/linux_sysvec.c104
-rw-r--r--sys/kern/imgact_aout.c10
-rw-r--r--sys/kern/imgact_elf.c10
-rw-r--r--sys/kern/kern_exec.c36
-rw-r--r--sys/mips/mips/freebsd32_machdep.c6
-rw-r--r--sys/mips/mips/pm_machdep.c2
-rw-r--r--sys/powerpc/include/reg.h2
-rw-r--r--sys/powerpc/powerpc/elf64_machdep.c4
-rw-r--r--sys/powerpc/powerpc/exec_machdep.c4
-rw-r--r--sys/riscv/riscv/machdep.c2
-rw-r--r--sys/sparc64/sparc64/machdep.c4
-rw-r--r--sys/sys/imgact.h4
-rw-r--r--sys/sys/imgact_elf.h6
-rw-r--r--sys/sys/sysent.h12
36 files changed, 292 insertions, 251 deletions
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 6483fb84d85e..c39bd189f8cc 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -577,7 +577,7 @@ freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
* Reset registers to default values on exec.
*/
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *regs;
struct pcb *pcb;
diff --git a/sys/amd64/cloudabi32/cloudabi32_sysvec.c b/sys/amd64/cloudabi32/cloudabi32_sysvec.c
index 810f319a02e3..5d21426e3ee9 100644
--- a/sys/amd64/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/amd64/cloudabi32/cloudabi32_sysvec.c
@@ -53,7 +53,7 @@ extern struct sysent cloudabi32_sysent[];
extern unsigned long ia32_maxssiz;
static int
-cloudabi32_fixup_tcb(register_t **stack_base, struct image_params *imgp)
+cloudabi32_fixup_tcb(uintptr_t *stack_base, struct image_params *imgp)
{
int error;
uint32_t args[2];
@@ -73,16 +73,16 @@ cloudabi32_fixup_tcb(register_t **stack_base, struct image_params *imgp)
* refer to the auxiliary vector, which is stored right after
* the TCB.
*/
- args[0] = (uintptr_t)*stack_base;
- args[1] = (uintptr_t)*stack_base +
+ args[0] = *stack_base;
+ args[1] = *stack_base +
roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t));
- *stack_base -= howmany(sizeof(args), sizeof(register_t));
- return (copyout(args, *stack_base, sizeof(args)));
+ *stack_base -= roundup2(sizeof(args), sizeof(register_t));
+ return (copyout(args, (void *)*stack_base, sizeof(args)));
}
static void
cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp,
- unsigned long stack)
+ uintptr_t stack)
{
ia32_setregs(td, imgp, stack);
diff --git a/sys/amd64/cloudabi64/cloudabi64_sysvec.c b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
index e7e92ca92812..c12ca58d9d35 100644
--- a/sys/amd64/cloudabi64/cloudabi64_sysvec.c
+++ b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
@@ -48,7 +48,7 @@ extern const char *cloudabi64_syscallnames[];
extern struct sysent cloudabi64_sysent[];
static int
-cloudabi64_fixup_tcb(register_t **stack_base, struct image_params *imgp)
+cloudabi64_fixup_tcb(uintptr_t *stack_base, struct image_params *imgp)
{
int error;
register_t tcbptr;
@@ -64,12 +64,13 @@ cloudabi64_fixup_tcb(register_t **stack_base, struct image_params *imgp)
* containing a pointer to the TCB. %fs base will point to this.
*/
tcbptr = (register_t)*stack_base;
- return (copyout(&tcbptr, --*stack_base, sizeof(tcbptr)));
+ *stack_base -= sizeof(tcbptr);
+ return (copyout(&tcbptr, (void *)*stack_base, sizeof(tcbptr)));
}
static void
cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp,
- unsigned long stack)
+ uintptr_t stack)
{
struct trapframe *regs;
diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c
index 90c9d8de6ed5..4e32434797a1 100644
--- a/sys/amd64/ia32/ia32_signal.c
+++ b/sys/amd64/ia32/ia32_signal.c
@@ -936,7 +936,7 @@ freebsd32_sigreturn(td, uap)
* Clear registers on exec
*/
void
-ia32_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+ia32_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *regs;
struct pcb *pcb;
diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index 303203226136..efdd6f36d2b2 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -97,8 +97,8 @@ extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
static int linux_copyout_strings(struct image_params *imgp,
- register_t **stack_base);
-static int linux_fixup_elf(register_t **stack_base,
+ uintptr_t *stack_base);
+static int linux_fixup_elf(uintptr_t *stack_base,
struct image_params *iparams);
static bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
static void linux_vdso_install(void *param);
@@ -106,7 +106,7 @@ static void linux_vdso_deinstall(void *param);
static void linux_set_syscall_retval(struct thread *td, int error);
static int linux_fetch_syscall_args(struct thread *td);
static void linux_exec_setregs(struct thread *td, struct image_params *imgp,
- u_long stack);
+ uintptr_t stack);
static int linux_vsyscall(struct thread *td);
#define LINUX_T_UNKNOWN 255
@@ -224,7 +224,7 @@ linux_set_syscall_retval(struct thread *td, int error)
}
static int
-linux_copyout_auxargs(struct image_params *imgp, u_long *base)
+linux_copyout_auxargs(struct image_params *imgp, uintptr_t *base)
{
Elf_Auxargs *args;
Elf_Auxinfo *argarray, *pos;
@@ -274,7 +274,7 @@ linux_copyout_auxargs(struct image_params *imgp, u_long *base)
}
static int
-linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
+linux_fixup_elf(uintptr_t *stack_base, struct image_params *imgp)
{
Elf_Addr *base;
@@ -283,7 +283,7 @@ linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
if (suword(base, (uint64_t)imgp->args->argc) == -1)
return (EFAULT);
- *stack_base = (register_t *)base;
+ *stack_base = (uintptr_t)base;
return (0);
}
@@ -293,11 +293,12 @@ linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
* as the initial stack pointer.
*/
static int
-linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
+linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
int argc, envc, error;
char **vectp;
- char *stringp, *destp;
+ char *stringp;
+ uintptr_t destp, ustringp;
struct ps_strings *arginfo;
char canary[LINUX_AT_RANDOM_LEN];
size_t execpath_len;
@@ -311,43 +312,45 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
p = imgp->proc;
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
- destp = (caddr_t)arginfo - SPARE_USRSPACE -
- roundup(sizeof(canary), sizeof(char *)) -
- roundup(execpath_len, sizeof(char *)) -
- roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *));
+ destp = (uintptr_t)arginfo;
if (execpath_len != 0) {
- imgp->execpathp = (uintptr_t)arginfo - execpath_len;
- error = copyout(imgp->execpath, (void *)imgp->execpathp,
- execpath_len);
+ destp -= execpath_len;
+ destp = rounddown2(destp, sizeof(void *));
+ imgp->execpathp = destp;
+ error = copyout(imgp->execpath, (void *)destp, execpath_len);
if (error != 0)
return (error);
}
/* Prepare the canary for SSP. */
arc4rand(canary, sizeof(canary), 0);
- imgp->canary = (uintptr_t)arginfo -
- roundup(execpath_len, sizeof(char *)) -
- roundup(sizeof(canary), sizeof(char *));
- error = copyout(canary, (void *)imgp->canary, sizeof(canary));
+ destp -= roundup(sizeof(canary), sizeof(void *));
+ imgp->canary = destp;
+ error = copyout(canary, (void *)destp, sizeof(canary));
if (error != 0)
return (error);
- vectp = (char **)destp;
+ /* Allocate room for the argument and environment strings. */
+ destp -= ARG_MAX - imgp->args->stringspace;
+ destp = rounddown2(destp, sizeof(void *));
+ ustringp = destp;
/*
* Starting with 2.24, glibc depends on a 16-byte stack alignment.
* One "long argc" will be prepended later.
*/
- vectp = (char **)((((uintptr_t)vectp + 8) & ~0xF) - 8);
+ if (destp % 16 == 0)
+ destp -= 8;
if (imgp->auxargs) {
- error = imgp->sysent->sv_copyout_auxargs(imgp,
- (u_long *)&vectp);
+ error = imgp->sysent->sv_copyout_auxargs(imgp, &destp);
if (error != 0)
return (error);
}
+ vectp = (char **)destp;
+
/*
* Allocate room for the argv[] and env vectors including the
* terminating NULL pointers.
@@ -355,14 +358,15 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
/* vectp also becomes our initial stack base. */
- *stack_base = (register_t *)vectp;
+ *stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
envc = imgp->args->envc;
/* Copy out strings - arguments and environment. */
- error = copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
+ error = copyout(stringp, (void *)ustringp,
+ ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
@@ -373,11 +377,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in argument portion of vector table. */
for (; argc > 0; --argc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* A null vector table pointer separates the argp's from the envp's. */
@@ -390,11 +394,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in environment portion of vector table. */
for (; envc > 0; --envc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* The end of the vector table is a null pointer. */
@@ -408,7 +412,8 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
* Reset registers to default values on exec.
*/
static void
-linux_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+linux_exec_setregs(struct thread *td, struct image_params *imgp,
+ uintptr_t stack)
{
struct trapframe *regs;
struct pcb *pcb;
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index ba87152d7a9a..a08372b66add 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -101,13 +101,13 @@ extern struct sysent linux32_sysent[LINUX32_SYS_MAXSYSCALL];
SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
-static int linux_fixup_elf(register_t **stack_base,
+static int linux_fixup_elf(uintptr_t *stack_base,
struct image_params *iparams);
static int linux_copyout_strings(struct image_params *imgp,
- register_t **stack_base);
+ uintptr_t *stack_base);
static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
static void linux_exec_setregs(struct thread *td,
- struct image_params *imgp, u_long stack);
+ struct image_params *imgp, uintptr_t stack);
static void linux32_fixlimit(struct rlimit *rl, int which);
static bool linux32_trans_osrel(const Elf_Note *note, int32_t *osrel);
static void linux_vdso_install(void *param);
@@ -246,7 +246,7 @@ linux_copyout_auxargs(struct image_params *imgp, u_long *base)
}
static int
-linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
+linux_fixup_elf(uintptr_t *stack_base, struct image_params *imgp)
{
Elf32_Addr *base;
@@ -254,7 +254,7 @@ linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
base--;
if (suword32(base, (uint32_t)imgp->args->argc) == -1)
return (EFAULT);
- *stack_base = (register_t *)base;
+ *stack_base = (uintptr_t)base;
return (0);
}
@@ -677,7 +677,8 @@ linux32_fetch_syscall_args(struct thread *td)
* XXX copied from ia32_signal.c.
*/
static void
-linux_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+linux_exec_setregs(struct thread *td, struct image_params *imgp,
+ uintptr_t stack)
{
struct trapframe *regs = td->td_frame;
struct pcb *pcb = td->td_pcb;
@@ -721,11 +722,12 @@ linux_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
* XXX copied from ia32_sysvec.c.
*/
static int
-linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
+linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
int argc, envc, error;
u_int32_t *vectp;
- char *stringp, *destp;
+ char *stringp;
+ uintptr_t destp, ustringp;
struct linux32_ps_strings *arginfo;
char canary[LINUX_AT_RANDOM_LEN];
size_t execpath_len;
@@ -737,36 +739,38 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
execpath_len = 0;
arginfo = (struct linux32_ps_strings *)LINUX32_PS_STRINGS;
- destp = (caddr_t)arginfo - SPARE_USRSPACE -
- roundup(sizeof(canary), sizeof(char *)) -
- roundup(execpath_len, sizeof(char *)) -
- roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *));
+ destp = (uintptr_t)arginfo;
if (execpath_len != 0) {
- imgp->execpathp = (uintptr_t)arginfo - execpath_len;
- error = copyout(imgp->execpath, (void *)imgp->execpathp,
- execpath_len);
+ destp -= execpath_len;
+ destp = rounddown2(destp, sizeof(void *));
+ imgp->execpathp = destp;
+ error = copyout(imgp->execpath, (void *)destp, execpath_len);
if (error != 0)
return (error);
}
/* Prepare the canary for SSP. */
arc4rand(canary, sizeof(canary), 0);
- imgp->canary = (uintptr_t)arginfo -
- roundup(execpath_len, sizeof(char *)) -
- roundup(sizeof(canary), sizeof(char *));
- error = copyout(canary, (void *)imgp->canary, sizeof(canary));
+ destp -= roundup(sizeof(canary), sizeof(void *));
+ imgp->canary = destp;
+ error = copyout(canary, (void *)destp, sizeof(canary));
if (error != 0)
return (error);
- vectp = (uint32_t *)destp;
+ /* Allocate room for the argument and environment strings. */
+ destp -= ARG_MAX - imgp->args->stringspace;
+ destp = rounddown2(destp, sizeof(void *));
+ ustringp = destp;
+
if (imgp->auxargs) {
- error = imgp->sysent->sv_copyout_auxargs(imgp,
- (u_long *)&vectp);
+ error = imgp->sysent->sv_copyout_auxargs(imgp, &destp);
if (error != 0)
return (error);
}
+ vectp = (uint32_t *)destp;
+
/*
* Allocate room for the argv[] and env vectors including the
* terminating NULL pointers.
@@ -774,13 +778,15 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
/* vectp also becomes our initial stack base. */
- *stack_base = (register_t *)vectp;
+ *stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
envc = imgp->args->envc;
+
/* Copy out strings - arguments and environment. */
- error = copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
+ error = copyout(stringp, (void *)ustringp,
+ ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
@@ -791,11 +797,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in argument portion of vector table. */
for (; argc > 0; --argc) {
- if (suword32(vectp++, (uint32_t)(intptr_t)destp) != 0)
+ if (suword32(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* A null vector table pointer separates the argp's from the envp's. */
@@ -808,11 +814,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in environment portion of vector table. */
for (; envc > 0; --envc) {
- if (suword32(vectp++, (uint32_t)(intptr_t)destp) != 0)
+ if (suword32(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* The end of the vector table is a null pointer. */
diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c
index d4c2380fedc8..6ca2be913ceb 100644
--- a/sys/arm/arm/machdep.c
+++ b/sys/arm/arm/machdep.c
@@ -412,7 +412,7 @@ spinlock_exit(void)
* Clear registers on exec
*/
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *tf = td->td_frame;
diff --git a/sys/arm/cloudabi32/cloudabi32_sysvec.c b/sys/arm/cloudabi32/cloudabi32_sysvec.c
index 2b4c2d5916d6..26845fdbde46 100644
--- a/sys/arm/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/arm/cloudabi32/cloudabi32_sysvec.c
@@ -49,7 +49,7 @@ extern struct sysent cloudabi32_sysent[];
static void
cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp,
- unsigned long stack)
+ uintptr_t stack)
{
struct trapframe *regs;
diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c
index 4467ec492f1c..55d9e40c3792 100644
--- a/sys/arm64/arm64/elf32_machdep.c
+++ b/sys/arm64/arm64/elf32_machdep.c
@@ -232,7 +232,7 @@ freebsd32_set_syscall_retval(struct thread *td, int error)
static void
freebsd32_setregs(struct thread *td, struct image_params *imgp,
- u_long stack)
+ uintptr_t stack)
{
struct trapframe *tf = td->td_frame;
diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 84cd9921c7dd..b4282d0ab78a 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -436,7 +436,7 @@ ptrace_clear_single_step(struct thread *td)
}
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *tf = td->td_frame;
diff --git a/sys/arm64/cloudabi32/cloudabi32_sysvec.c b/sys/arm64/cloudabi32/cloudabi32_sysvec.c
index 4df712e01b04..96d9432ff368 100644
--- a/sys/arm64/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/arm64/cloudabi32/cloudabi32_sysvec.c
@@ -49,7 +49,7 @@ extern struct sysent cloudabi32_sysent[];
static void
cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp,
- unsigned long stack)
+ uintptr_t stack)
{
struct trapframe *regs;
diff --git a/sys/arm64/cloudabi64/cloudabi64_sysvec.c b/sys/arm64/cloudabi64/cloudabi64_sysvec.c
index acacbacc1513..a493774551cf 100644
--- a/sys/arm64/cloudabi64/cloudabi64_sysvec.c
+++ b/sys/arm64/cloudabi64/cloudabi64_sysvec.c
@@ -49,7 +49,7 @@ extern struct sysent cloudabi64_sysent[];
static void
cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp,
- unsigned long stack)
+ uintptr_t stack)
{
struct trapframe *regs;
diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c
index 43d7a9bb0b41..9e322c9a35b8 100644
--- a/sys/arm64/linux/linux_sysvec.c
+++ b/sys/arm64/linux/linux_sysvec.c
@@ -70,8 +70,8 @@ extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
static int linux_copyout_strings(struct image_params *imgp,
- register_t **stack_base);
-static int linux_elf_fixup(register_t **stack_base,
+ uintptr_t *stack_base);
+static int linux_elf_fixup(uintptr_t *stack_base,
struct image_params *iparams);
static bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
static void linux_vdso_install(const void *param);
@@ -79,7 +79,7 @@ static void linux_vdso_deinstall(const void *param);
static void linux_set_syscall_retval(struct thread *td, int error);
static int linux_fetch_syscall_args(struct thread *td);
static void linux_exec_setregs(struct thread *td, struct image_params *imgp,
- u_long stack);
+ uintptr_t stack);
static int linux_vsyscall(struct thread *td);
/* DTrace init */
@@ -143,7 +143,7 @@ linux_set_syscall_retval(struct thread *td, int error)
}
static int
-linux_copyout_auxargs(struct image_params *imgp, u_long *base)
+linux_copyout_auxargs(struct image_params *imgp, uintptr_t *base)
{
Elf_Auxargs *args;
Elf_Auxinfo *argarray, *pos;
@@ -198,7 +198,7 @@ linux_copyout_auxargs(struct image_params *imgp, u_long *base)
}
static int
-linux_elf_fixup(register_t **stack_base, struct image_params *imgp)
+linux_elf_fixup(uintptr_t *stack_base, struct image_params *imgp)
{
LIN_SDT_PROBE0(sysvec, linux_elf_fixup, todo);
@@ -213,10 +213,11 @@ linux_elf_fixup(register_t **stack_base, struct image_params *imgp)
* LINUXTODO: deduplicate against other linuxulator archs
*/
static int
-linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
+linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
char **vectp;
- char *stringp, *destp;
+ char *stringp;
+ uintptr_t *destp, *ustringp;
struct ps_strings *arginfo;
char canary[LINUX_AT_RANDOM_LEN];
size_t execpath_len;
@@ -231,36 +232,38 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
p = imgp->proc;
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
- destp = (caddr_t)arginfo - SPARE_USRSPACE -
- roundup(sizeof(canary), sizeof(char *)) -
- roundup(execpath_len, sizeof(char *)) -
- roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *));
+ destp = (uintptr_t)arginfo;
if (execpath_len != 0) {
- imgp->execpathp = (uintptr_t)arginfo - execpath_len;
- error = copyout(imgp->execpath, (void *)imgp->execpathp,
- execpath_len);
+ destp -= execpath_len;
+ destp = rounddown2(destp, sizeof(void *));
+ imgp->execpathp = destp;
+ error = copyout(imgp->execpath, (void *)destp, execpath_len);
if (error != 0)
return (error);
}
/* Prepare the canary for SSP. */
arc4rand(canary, sizeof(canary), 0);
- imgp->canary = (uintptr_t)arginfo -
- roundup(execpath_len, sizeof(char *)) -
- roundup(sizeof(canary), sizeof(char *));
- error = copyout(canary, (void *)imgp->canary, sizeof(canary));
+ destp -= roundup(sizeof(canary), sizeof(void *));
+ imgp->canary = destp;
+ error = copyout(canary, (void *)destp, sizeof(canary));
if (error != 0)
return (error);
- vectp = (char **)destp;
+ /* Allocate room for the argument and environment strings. */
+ destp -= ARG_MAX - imgp->args->stringspace;
+ destp = rounddown2(destp, sizeof(void *));
+ ustringp = destp;
+
if (imgp->auxargs) {
- error = imgp->sysent->sv_copyout_auxargs(imgp,
- (u_long *)&vectp);
+ error = imgp->sysent->sv_copyout_auxargs(imgp, &destp);
if (error != 0)
return (error);
}
+ vectp = (char **)destp;
+
/*
* Allocate room for argc and the argv[] and env vectors including the
* terminating NULL pointers.
@@ -269,14 +272,15 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
vectp = (char **)STACKALIGN(vectp);
/* vectp also becomes our initial stack base. */
- *stack_base = (register_t *)vectp;
+ *stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
envc = imgp->args->envc;
/* Copy out strings - arguments and environment. */
- error = copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
+ error = copyout(stringp, (void *)ustringp,
+ ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
@@ -290,11 +294,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in argument portion of vector table. */
for (; argc > 0; --argc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* A null vector table pointer separates the argp's from the envp's. */
@@ -307,11 +311,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in environment portion of vector table. */
for (; envc > 0; --envc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* The end of the vector table is a null pointer. */
@@ -325,7 +329,8 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
* Reset registers to default values on exec.
*/
static void
-linux_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+linux_exec_setregs(struct thread *td, struct image_params *imgp,
+ uintptr_t stack)
{
struct trapframe *regs = td->td_frame;
diff --git a/sys/compat/cloudabi32/cloudabi32_module.c b/sys/compat/cloudabi32/cloudabi32_module.c
index 9170e49eda30..3463101193a5 100644
--- a/sys/compat/cloudabi32/cloudabi32_module.c
+++ b/sys/compat/cloudabi32/cloudabi32_module.c
@@ -46,7 +46,7 @@ extern char _binary_cloudabi32_vdso_o_start[];
extern char _binary_cloudabi32_vdso_o_end[];
int
-cloudabi32_copyout_strings(struct image_params *imgp, register_t **stack_base)
+cloudabi32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
struct image_args *args;
uintptr_t begin;
@@ -56,12 +56,12 @@ cloudabi32_copyout_strings(struct image_params *imgp, register_t **stack_base)
args = imgp->args;
len = exec_args_get_begin_envv(args) - args->begin_argv;
begin = rounddown2(imgp->sysent->sv_usrstack - len, sizeof(register_t));
- *stack_base = (register_t *)begin;
+ *stack_base = begin;
return (copyout(args->begin_argv, (void *)begin, len));
}
int
-cloudabi32_fixup(register_t **stack_base, struct image_params *imgp)
+cloudabi32_fixup(uintptr_t *stack_base, struct image_params *imgp)
{
char canarybuf[64], pidbuf[16];
Elf32_Auxargs *args;
@@ -79,12 +79,12 @@ cloudabi32_fixup(register_t **stack_base, struct image_params *imgp)
td = curthread;
td->td_proc->p_osrel = __FreeBSD_version;
- argdata = *stack_base;
+ argdata = (void *)*stack_base;
/* Store canary for stack smashing protection. */
arc4rand(canarybuf, sizeof(canarybuf), 0);
- *stack_base -= howmany(sizeof(canarybuf), sizeof(register_t));
- canary = *stack_base;
+ *stack_base -= roundup(sizeof(canarybuf), sizeof(register_t));
+ canary = (void *)*stack_base;
error = copyout(canarybuf, canary, sizeof(canarybuf));
if (error != 0)
return (error);
@@ -97,8 +97,8 @@ cloudabi32_fixup(register_t **stack_base, struct image_params *imgp)
arc4rand(pidbuf, sizeof(pidbuf), 0);
pidbuf[6] = (pidbuf[6] & 0x0f) | 0x40;
pidbuf[8] = (pidbuf[8] & 0x3f) | 0x80;
- *stack_base -= howmany(sizeof(pidbuf), sizeof(register_t));
- pid = *stack_base;
+ *stack_base -= roundup(sizeof(pidbuf), sizeof(register_t));
+ pid = (void *)*stack_base;
error = copyout(pidbuf, pid, sizeof(pidbuf));
if (error != 0)
return (error);
@@ -135,13 +135,13 @@ cloudabi32_fixup(register_t **stack_base, struct image_params *imgp)
#undef PTR
{ .a_type = CLOUDABI_AT_NULL },
};
- *stack_base -= howmany(sizeof(auxv), sizeof(register_t));
- error = copyout(auxv, *stack_base, sizeof(auxv));
+ *stack_base -= roundup(sizeof(auxv), sizeof(register_t));
+ error = copyout(auxv, (void *)*stack_base, sizeof(auxv));
if (error != 0)
return (error);
/* Reserve space for storing the TCB. */
- *stack_base -= howmany(sizeof(cloudabi32_tcb_t), sizeof(register_t));
+ *stack_base -= roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t));
return (0);
}
diff --git a/sys/compat/cloudabi32/cloudabi32_util.h b/sys/compat/cloudabi32/cloudabi32_util.h
index 1661854a30f8..917356468311 100644
--- a/sys/compat/cloudabi32/cloudabi32_util.h
+++ b/sys/compat/cloudabi32/cloudabi32_util.h
@@ -42,8 +42,8 @@ extern Elf32_Brandinfo cloudabi32_brand;
#define TO_PTR(x) ((void *)(uintptr_t)(x))
/* Stack initialization during process execution. */
-int cloudabi32_copyout_strings(struct image_params *, register_t **);
-int cloudabi32_fixup(register_t **, struct image_params *);
+int cloudabi32_copyout_strings(struct image_params *, uintptr_t *);
+int cloudabi32_fixup(uintptr_t *, struct image_params *);
int cloudabi32_thread_setregs(struct thread *,
const cloudabi32_threadattr_t *, uint32_t);
diff --git a/sys/compat/cloudabi64/cloudabi64_module.c b/sys/compat/cloudabi64/cloudabi64_module.c
index 7459b026d8ec..ed0c85b4aba5 100644
--- a/sys/compat/cloudabi64/cloudabi64_module.c
+++ b/sys/compat/cloudabi64/cloudabi64_module.c
@@ -46,7 +46,7 @@ extern char _binary_cloudabi64_vdso_o_start[];
extern char _binary_cloudabi64_vdso_o_end[];
int
-cloudabi64_copyout_strings(struct image_params *imgp, register_t **stack_base)
+cloudabi64_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
struct image_args *args;
uintptr_t begin;
@@ -56,12 +56,12 @@ cloudabi64_copyout_strings(struct image_params *imgp, register_t **stack_base)
args = imgp->args;
len = exec_args_get_begin_envv(args) - args->begin_argv;
begin = rounddown2(imgp->sysent->sv_usrstack - len, sizeof(register_t));
- *stack_base = (register_t *)begin;
+ *stack_base = begin;
return (copyout(args->begin_argv, (void *)begin, len));
}
int
-cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
+cloudabi64_fixup(uintptr_t *stack_base, struct image_params *imgp)
{
char canarybuf[64], pidbuf[16];
Elf64_Auxargs *args;
@@ -79,12 +79,12 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
td = curthread;
td->td_proc->p_osrel = __FreeBSD_version;
- argdata = *stack_base;
+ argdata = (void *)*stack_base;
/* Store canary for stack smashing protection. */
arc4rand(canarybuf, sizeof(canarybuf), 0);
- *stack_base -= howmany(sizeof(canarybuf), sizeof(register_t));
- canary = *stack_base;
+ *stack_base -= roundup(sizeof(canarybuf), sizeof(register_t));
+ canary = (void *)*stack_base;
error = copyout(canarybuf, canary, sizeof(canarybuf));
if (error != 0)
return (error);
@@ -97,8 +97,8 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
arc4rand(pidbuf, sizeof(pidbuf), 0);
pidbuf[6] = (pidbuf[6] & 0x0f) | 0x40;
pidbuf[8] = (pidbuf[8] & 0x3f) | 0x80;
- *stack_base -= howmany(sizeof(pidbuf), sizeof(register_t));
- pid = *stack_base;
+ *stack_base -= roundup(sizeof(pidbuf), sizeof(register_t));
+ pid = (void *)*stack_base;
error = copyout(pidbuf, pid, sizeof(pidbuf));
if (error != 0)
return (error);
@@ -135,13 +135,13 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
#undef PTR
{ .a_type = CLOUDABI_AT_NULL },
};
- *stack_base -= howmany(sizeof(auxv), sizeof(register_t));
- error = copyout(auxv, *stack_base, sizeof(auxv));
+ *stack_base -= roundup(sizeof(auxv), sizeof(register_t));
+ error = copyout(auxv, (void *)*stack_base, sizeof(auxv));
if (error != 0)
return (error);
/* Reserve space for storing the TCB. */
- *stack_base -= howmany(sizeof(cloudabi64_tcb_t), sizeof(register_t));
+ *stack_base -= roundup(sizeof(cloudabi64_tcb_t), sizeof(register_t));
return (0);
}
diff --git a/sys/compat/cloudabi64/cloudabi64_util.h b/sys/compat/cloudabi64/cloudabi64_util.h
index 59e93b37b1b6..27088392c75a 100644
--- a/sys/compat/cloudabi64/cloudabi64_util.h
+++ b/sys/compat/cloudabi64/cloudabi64_util.h
@@ -42,8 +42,8 @@ extern Elf64_Brandinfo cloudabi64_brand;
#define TO_PTR(x) ((void *)(uintptr_t)(x))
/* Stack initialization during process execution. */
-int cloudabi64_copyout_strings(struct image_params *, register_t **);
-int cloudabi64_fixup(register_t **, struct image_params *);
+int cloudabi64_copyout_strings(struct image_params *, uintptr_t *);
+int cloudabi64_fixup(uintptr_t *, struct image_params *);
int cloudabi64_thread_setregs(struct thread *,
const cloudabi64_threadattr_t *, uint64_t);
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 395e4e4a3668..d7fda7834ff7 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -3120,12 +3120,12 @@ syscall32_helper_unregister(struct syscall_helper_data *sd)
}
int
-freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base)
+freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
int argc, envc, i;
u_int32_t *vectp;
char *stringp;
- uintptr_t destp;
+ uintptr_t destp, ustringp;
struct freebsd32_ps_strings *arginfo;
char canary[sizeof(long) * 8];
int32_t pagesizes32[MAXPAGESIZES];
@@ -3195,20 +3195,24 @@ freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base)
return (error);
imgp->pagesizeslen = sizeof(pagesizes32);
+ /*
+ * Allocate room for the argument and environment strings.
+ */
destp -= ARG_MAX - imgp->args->stringspace;
destp = rounddown2(destp, sizeof(uint32_t));
+ ustringp = destp;
- vectp = (uint32_t *)destp;
if (imgp->sysent->sv_stackgap != NULL)
- imgp->sysent->sv_stackgap(imgp, (u_long *)&vectp);
+ imgp->sysent->sv_stackgap(imgp, &destp);
if (imgp->auxargs) {
- error = imgp->sysent->sv_copyout_auxargs(imgp,
- (u_long *)&vectp);
+ error = imgp->sysent->sv_copyout_auxargs(imgp, &destp);
if (error != 0)
return (error);
}
+ vectp = (uint32_t *)destp;
+
/*
* Allocate room for the argv[] and env vectors including the
* terminating NULL pointers.
@@ -3218,7 +3222,7 @@ freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base)
/*
* vectp also becomes our initial stack base
*/
- *stack_base = (register_t *)vectp;
+ *stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
@@ -3226,7 +3230,7 @@ freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base)
/*
* Copy out strings - arguments and environment.
*/
- error = copyout(stringp, (void *)destp,
+ error = copyout(stringp, (void *)ustringp,
ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
@@ -3242,11 +3246,11 @@ freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base)
* Fill in argument portion of vector table.
*/
for (; argc > 0; --argc) {
- if (suword32(vectp++, (u_int32_t)(intptr_t)destp) != 0)
+ if (suword32(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* a null vector table pointer separates the argp's from the envp's */
@@ -3261,11 +3265,11 @@ freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base)
* Fill in environment portion of vector table.
*/
for (; envc > 0; --envc) {
- if (suword32(vectp++, (u_int32_t)(intptr_t)destp) != 0)
+ if (suword32(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* end of vector table is a null pointer */
diff --git a/sys/compat/freebsd32/freebsd32_util.h b/sys/compat/freebsd32/freebsd32_util.h
index 4da7c7029b6b..a66038d4d36a 100644
--- a/sys/compat/freebsd32/freebsd32_util.h
+++ b/sys/compat/freebsd32/freebsd32_util.h
@@ -113,7 +113,7 @@ int syscall32_helper_unregister(struct syscall_helper_data *sd);
struct iovec32;
struct rusage32;
int freebsd32_copyout_strings(struct image_params *imgp,
- register_t **stack_base);
+ uintptr_t *stack_base);
int freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
struct iovec **iov, int error);
void freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
diff --git a/sys/compat/ia32/ia32_signal.h b/sys/compat/ia32/ia32_signal.h
index ec8702971ef0..3546363122c6 100644
--- a/sys/compat/ia32/ia32_signal.h
+++ b/sys/compat/ia32/ia32_signal.h
@@ -206,7 +206,7 @@ extern int sz_ia32_osigcode;
extern int sz_lcall_tramp;
void ia32_sendsig(sig_t, struct ksiginfo *, sigset_t *);
void ia32_setregs(struct thread *td, struct image_params *imgp,
- u_long stack);
+ uintptr_t stack);
int setup_lcall_gate(void);
#endif
diff --git a/sys/i386/cloudabi32/cloudabi32_sysvec.c b/sys/i386/cloudabi32/cloudabi32_sysvec.c
index 31035a121f01..76cab063501d 100644
--- a/sys/i386/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/i386/cloudabi32/cloudabi32_sysvec.c
@@ -48,7 +48,7 @@ extern const char *cloudabi32_syscallnames[];
extern struct sysent cloudabi32_sysent[];
static int
-cloudabi32_fixup_tcb(register_t **stack_base, struct image_params *imgp)
+cloudabi32_fixup_tcb(uintptr_t *stack_base, struct image_params *imgp)
{
int error;
uint32_t args[2];
@@ -68,16 +68,16 @@ cloudabi32_fixup_tcb(register_t **stack_base, struct image_params *imgp)
* refer to the auxiliary vector, which is stored right after
* the TCB.
*/
- args[0] = (uintptr_t)*stack_base;
- args[1] = (uintptr_t)*stack_base +
+ args[0] = *stack_base;
+ args[1] = *stack_base +
roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t));
- *stack_base -= howmany(sizeof(args), sizeof(register_t));
- return (copyout(args, *stack_base, sizeof(args)));
+ *stack_base -= roundup(sizeof(args), sizeof(register_t));
+ return (copyout(args, (void *)*stack_base, sizeof(args)));
}
static void
cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp,
- unsigned long stack)
+ uintptr_t stack)
{
exec_setregs(td, imgp, stack);
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index 77ab78b526a1..60ebb3a3510e 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -1124,7 +1124,7 @@ setup_priv_lcall_gate(struct proc *p)
* Reset registers to default values on exec.
*/
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *regs;
struct pcb *pcb;
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 787fb83c534b..e067e1f82123 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -88,15 +88,15 @@ extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
-static int linux_fixup(register_t **stack_base,
+static int linux_fixup(uintptr_t *stack_base,
struct image_params *iparams);
-static int linux_fixup_elf(register_t **stack_base,
+static int linux_fixup_elf(uintptr_t *stack_base,
struct image_params *iparams);
static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
static void linux_exec_setregs(struct thread *td,
- struct image_params *imgp, u_long stack);
+ struct image_params *imgp, uintptr_t stack);
static int linux_copyout_strings(struct image_params *imgp,
- register_t **stack_base);
+ uintptr_t *stack_base);
static bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
static void linux_vdso_install(void *param);
static void linux_vdso_deinstall(void *param);
@@ -174,23 +174,25 @@ linux_translate_traps(int signal, int trap_code)
}
static int
-linux_fixup(register_t **stack_base, struct image_params *imgp)
+linux_fixup(uintptr_t *stack_base, struct image_params *imgp)
{
- register_t *argv, *envp;
-
- argv = *stack_base;
- envp = *stack_base + (imgp->args->argc + 1);
- (*stack_base)--;
- suword(*stack_base, (intptr_t)(void *)envp);
- (*stack_base)--;
- suword(*stack_base, (intptr_t)(void *)argv);
- (*stack_base)--;
- suword(*stack_base, imgp->args->argc);
+ register_t *base, *argv, *envp;
+
+ base = (register_t *)*stack_base;
+ argv = base;
+ envp = base + (imgp->args->argc + 1);
+ base--;
+ suword(base, (intptr_t)envp);
+ base--;
+ suword(base, (intptr_t)argv);
+ base--;
+ suword(base, imgp->args->argc);
+ *stack_base = (uintptr_t)base;
return (0);
}
static int
-linux_copyout_auxargs(struct image_params *imgp, u_long *base)
+linux_copyout_auxargs(struct image_params *imgp, uintptr_t *base)
{
struct proc *p;
Elf32_Auxargs *args;
@@ -255,12 +257,15 @@ linux_copyout_auxargs(struct image_params *imgp, u_long *base)
}
static int
-linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
+linux_fixup_elf(uintptr_t *stack_base, struct image_params *imgp)
{
+ register_t *base;
- (*stack_base)--;
- if (suword(*stack_base, (register_t)imgp->args->argc) == -1)
+ base = (register_t *)*stack_base;
+ base--;
+ if (suword(base, (register_t)imgp->args->argc) == -1)
return (EFAULT);
+ *stack_base = (uintptr_t)base;
return (0);
}
@@ -268,11 +273,12 @@ linux_fixup_elf(register_t **stack_base, struct image_params *imgp)
* Copied from kern/kern_exec.c
*/
static int
-linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
+linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
int argc, envc, error;
char **vectp;
- char *stringp, *destp;
+ char *stringp;
+ uintptr_t destp, ustringp;
struct ps_strings *arginfo;
char canary[LINUX_AT_RANDOM_LEN];
size_t execpath_len;
@@ -285,43 +291,45 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
else
execpath_len = 0;
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
- destp = (caddr_t)arginfo - SPARE_USRSPACE - linux_szplatform -
- roundup(sizeof(canary), sizeof(char *)) -
- roundup(execpath_len, sizeof(char *)) -
- roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *));
+ destp = (uintptr_t)arginfo;
/* Install LINUX_PLATFORM. */
- error = copyout(linux_kplatform, ((caddr_t)arginfo - linux_szplatform),
- linux_szplatform);
+ destp -= linux_szplatform;
+ destp = rounddown2(destp, sizeof(void *));
+ error = copyout(linux_kplatform, (void *)destp, linux_szplatform);
if (error != 0)
return (error);
if (execpath_len != 0) {
- imgp->execpathp = (uintptr_t)arginfo -
- linux_szplatform - execpath_len;
- error = copyout(imgp->execpath, (void *)imgp->execpathp,
- execpath_len);
+ destp -= execpath_len;
+ destp = rounddown2(destp, sizeof(void *));
+ imgp->execpathp = destp;
+ error = copyout(imgp->execpath, (void *)destp, execpath_len);
if (error != 0)
return (error);
}
/* Prepare the canary for SSP. */
arc4rand(canary, sizeof(canary), 0);
- imgp->canary = (uintptr_t)arginfo - linux_szplatform -
- roundup(execpath_len, sizeof(char *)) -
- roundup(sizeof(canary), sizeof(char *));
- error = copyout(canary, (void *)imgp->canary, sizeof(canary));
+ destp -= roundup(sizeof(canary), sizeof(void *));
+ imgp->canary = destp;
+ error = copyout(canary, (void *)destp, sizeof(canary));
if (error != 0)
return (error);
- vectp = (char **)destp;
+ /* Allocate room for the argument and environment strings. */
+ destp -= ARG_MAX - imgp->args->stringspace;
+ destp = rounddown2(destp, sizeof(void *));
+ ustringp = destp;
+
if (imgp->auxargs) {
- error = imgp->sysent->sv_copyout_auxargs(imgp,
- (u_long *)&vectp);
+ error = imgp->sysent->sv_copyout_auxargs(imgp, &destp);
if (error != 0)
return (error);
}
+ vectp = (char **)destp;
+
/*
* Allocate room for the argv[] and env vectors including the
* terminating NULL pointers.
@@ -329,14 +337,15 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
/* vectp also becomes our initial stack base. */
- *stack_base = (register_t *)vectp;
+ *stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
envc = imgp->args->envc;
/* Copy out strings - arguments and environment. */
- error = copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
+ error = copyout(stringp, (void *)ustringp,
+ ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
@@ -347,11 +356,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in argument portion of vector table. */
for (; argc > 0; --argc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* A null vector table pointer separates the argp's from the envp's. */
@@ -364,11 +373,11 @@ linux_copyout_strings(struct image_params *imgp, register_t **stack_base)
/* Fill in environment portion of vector table. */
for (; envc > 0; --envc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* The end of the vector table is a null pointer. */
@@ -781,7 +790,8 @@ linux_fetch_syscall_args(struct thread *td)
* override the exec_setregs default(s) here.
*/
static void
-linux_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+linux_exec_setregs(struct thread *td, struct image_params *imgp,
+ uintptr_t stack)
{
struct pcb *pcb = td->td_pcb;
diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c
index 0ca39b69d908..fa72a1952b30 100644
--- a/sys/kern/imgact_aout.c
+++ b/sys/kern/imgact_aout.c
@@ -65,7 +65,7 @@ __FBSDID("$FreeBSD$");
#endif
static int exec_aout_imgact(struct image_params *imgp);
-static int aout_fixup(register_t **stack_base, struct image_params *imgp);
+static int aout_fixup(uintptr_t *stack_base, struct image_params *imgp);
#define AOUT32_USRSTACK 0xbfc00000
@@ -147,11 +147,13 @@ struct sysentvec aout_sysvec = {
#endif
static int
-aout_fixup(register_t **stack_base, struct image_params *imgp)
+aout_fixup(uintptr_t *stack_base, struct image_params *imgp)
{
- *(char **)stack_base -= sizeof(uint32_t);
- return (suword32(*stack_base, imgp->args->argc));
+ *stack_base -= sizeof(uint32_t);
+ if (suword32((void *)*stack_base, imgp->args->argc) != 0)
+ return (EFAULT);
+ return (0);
}
static int
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 77b2960d1859..ebd3a45e5ba4 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -1324,7 +1324,7 @@ ret:
#define suword __CONCAT(suword, __ELF_WORD_SIZE)
int
-__elfN(freebsd_copyout_auxargs)(struct image_params *imgp, u_long *base)
+__elfN(freebsd_copyout_auxargs)(struct image_params *imgp, uintptr_t *base)
{
Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs;
Elf_Auxinfo *argarray, *pos;
@@ -1382,7 +1382,7 @@ __elfN(freebsd_copyout_auxargs)(struct image_params *imgp, u_long *base)
}
int
-__elfN(freebsd_fixup)(register_t **stack_base, struct image_params *imgp)
+__elfN(freebsd_fixup)(uintptr_t *stack_base, struct image_params *imgp)
{
Elf_Addr *base;
@@ -1390,7 +1390,7 @@ __elfN(freebsd_fixup)(register_t **stack_base, struct image_params *imgp)
base--;
if (suword(base, imgp->args->argc) == -1)
return (EFAULT);
- *stack_base = (register_t *)base;
+ *stack_base = (uintptr_t)base;
return (0);
}
@@ -2750,9 +2750,9 @@ __elfN(untrans_prot)(vm_prot_t prot)
}
void
-__elfN(stackgap)(struct image_params *imgp, u_long *stack_base)
+__elfN(stackgap)(struct image_params *imgp, uintptr_t *stack_base)
{
- u_long range, rbase, gap;
+ uintptr_t range, rbase, gap;
int pct;
if ((imgp->map_flags & MAP_ASLR) == 0)
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index d8377674a712..e2611ba6f944 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -360,7 +360,7 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p)
struct nameidata nd;
struct ucred *oldcred;
struct uidinfo *euip = NULL;
- register_t *stack_base;
+ uintptr_t stack_base;
struct image_params image_params, *imgp;
struct vattr attr;
int (*img_first)(struct image_params *);
@@ -868,7 +868,7 @@ interpret:
#endif
/* Set values passed into the program in registers. */
- (*p->p_sysent->sv_setregs)(td, imgp, (u_long)(uintptr_t)stack_base);
+ (*p->p_sysent->sv_setregs)(td, imgp, stack_base);
vfs_mark_atime(imgp->vp, td->td_ucred);
@@ -1574,12 +1574,12 @@ exec_args_get_begin_envv(struct image_args *args)
* as the initial stack pointer.
*/
int
-exec_copyout_strings(struct image_params *imgp, register_t **stack_base)
+exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
int argc, envc;
char **vectp;
char *stringp;
- uintptr_t destp;
+ uintptr_t destp, ustringp;
struct ps_strings *arginfo;
struct proc *p;
size_t execpath_len;
@@ -1650,20 +1650,24 @@ exec_copyout_strings(struct image_params *imgp, register_t **stack_base)
return (error);
imgp->pagesizeslen = szps;
+ /*
+ * Allocate room for the argument and environment strings.
+ */
destp -= ARG_MAX - imgp->args->stringspace;
destp = rounddown2(destp, sizeof(void *));
+ ustringp = destp;
- vectp = (char **)destp;
if (imgp->sysent->sv_stackgap != NULL)
- imgp->sysent->sv_stackgap(imgp, (u_long *)&vectp);
+ imgp->sysent->sv_stackgap(imgp, &destp);
if (imgp->auxargs) {
- error = imgp->sysent->sv_copyout_auxargs(imgp,
- (u_long *)&vectp);
+ error = imgp->sysent->sv_copyout_auxargs(imgp, &destp);
if (error != 0)
return (error);
}
+ vectp = (char **)destp;
+
/*
* Allocate room for the argv[] and env vectors including the
* terminating NULL pointers.
@@ -1673,7 +1677,7 @@ exec_copyout_strings(struct image_params *imgp, register_t **stack_base)
/*
* vectp also becomes our initial stack base
*/
- *stack_base = (register_t *)vectp;
+ *stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
@@ -1682,7 +1686,7 @@ exec_copyout_strings(struct image_params *imgp, register_t **stack_base)
/*
* Copy out strings - arguments and environment.
*/
- error = copyout(stringp, (void *)destp,
+ error = copyout(stringp, (void *)ustringp,
ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
@@ -1698,11 +1702,11 @@ exec_copyout_strings(struct image_params *imgp, register_t **stack_base)
* Fill in argument portion of vector table.
*/
for (; argc > 0; --argc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* a null vector table pointer separates the argp's from the envp's */
@@ -1717,11 +1721,11 @@ exec_copyout_strings(struct image_params *imgp, register_t **stack_base)
* Fill in environment portion of vector table.
*/
for (; envc > 0; --envc) {
- if (suword(vectp++, (long)(intptr_t)destp) != 0)
+ if (suword(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
- destp++;
- destp++;
+ ustringp++;
+ ustringp++;
}
/* end of vector table is a null pointer */
diff --git a/sys/mips/mips/freebsd32_machdep.c b/sys/mips/mips/freebsd32_machdep.c
index 4e02002af0be..c3ba6a8f24f3 100644
--- a/sys/mips/mips/freebsd32_machdep.c
+++ b/sys/mips/mips/freebsd32_machdep.c
@@ -68,7 +68,8 @@
#include <compat/freebsd32/freebsd32_util.h>
#include <compat/freebsd32/freebsd32_proto.h>
-static void freebsd32_exec_setregs(struct thread *, struct image_params *, u_long);
+static void freebsd32_exec_setregs(struct thread *, struct image_params *,
+ uintptr_t);
static int get_mcontext32(struct thread *, mcontext32_t *, int);
static int set_mcontext32(struct thread *, mcontext32_t *);
static void freebsd32_sendsig(sig_t, ksiginfo_t *, sigset_t *);
@@ -126,7 +127,8 @@ SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST,
&freebsd_brand_info);
static void
-freebsd32_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+freebsd32_exec_setregs(struct thread *td, struct image_params *imgp,
+ uintptr_t stack)
{
exec_setregs(td, imgp, stack);
diff --git a/sys/mips/mips/pm_machdep.c b/sys/mips/mips/pm_machdep.c
index 11a1da0ff383..606269456e0a 100644
--- a/sys/mips/mips/pm_machdep.c
+++ b/sys/mips/mips/pm_machdep.c
@@ -410,7 +410,7 @@ set_fpregs(struct thread *td, struct fpreg *fpregs)
* code by the MIPS elf abi).
*/
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
bzero((caddr_t)td->td_frame, sizeof(struct trapframe));
diff --git a/sys/powerpc/include/reg.h b/sys/powerpc/include/reg.h
index 32413566042e..a824792b0f12 100644
--- a/sys/powerpc/include/reg.h
+++ b/sys/powerpc/include/reg.h
@@ -73,7 +73,7 @@ struct image_params;
int fill_regs32(struct thread *, struct reg32 *);
int set_regs32(struct thread *, struct reg32 *);
-void ppc32_setregs(struct thread *, struct image_params *, u_long);
+void ppc32_setregs(struct thread *, struct image_params *, uintptr_t);
#define fill_fpregs32(td, reg) fill_fpregs(td,(struct fpreg *)reg)
#define set_fpregs32(td, reg) set_fpregs(td,(struct fpreg *)reg)
diff --git a/sys/powerpc/powerpc/elf64_machdep.c b/sys/powerpc/powerpc/elf64_machdep.c
index 703bd8d40453..dd850beafc11 100644
--- a/sys/powerpc/powerpc/elf64_machdep.c
+++ b/sys/powerpc/powerpc/elf64_machdep.c
@@ -53,7 +53,7 @@
#include <machine/md_var.h>
static void exec_setregs_funcdesc(struct thread *td, struct image_params *imgp,
- u_long stack);
+ uintptr_t stack);
struct sysentvec elf64_freebsd_sysvec_v1 = {
.sv_size = SYS_MAXSYSCALL,
@@ -207,7 +207,7 @@ ppc64_elfv2_header_match(struct image_params *params)
static void
exec_setregs_funcdesc(struct thread *td, struct image_params *imgp,
- u_long stack)
+ uintptr_t stack)
{
struct trapframe *tf;
register_t entry_desc[3];
diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c
index 1339fb48f913..8bbb7b38d7f0 100644
--- a/sys/powerpc/powerpc/exec_machdep.c
+++ b/sys/powerpc/powerpc/exec_machdep.c
@@ -539,7 +539,7 @@ cleanup_power_extras(struct thread *td)
* Set set up registers on exec.
*/
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *tf;
register_t argc;
@@ -585,7 +585,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
#ifdef COMPAT_FREEBSD32
void
-ppc32_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+ppc32_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *tf;
uint32_t argc;
diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c
index 63a5fb4ddd49..38b5fef316b9 100644
--- a/sys/riscv/riscv/machdep.c
+++ b/sys/riscv/riscv/machdep.c
@@ -297,7 +297,7 @@ ptrace_clear_single_step(struct thread *td)
}
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *tf;
struct pcb *pcb;
diff --git a/sys/sparc64/sparc64/machdep.c b/sys/sparc64/sparc64/machdep.c
index be4d8d644f15..e0f6313c294e 100644
--- a/sys/sparc64/sparc64/machdep.c
+++ b/sys/sparc64/sparc64/machdep.c
@@ -978,12 +978,12 @@ ptrace_clear_single_step(struct thread *td)
}
void
-exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
+exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
{
struct trapframe *tf;
struct pcb *pcb;
struct proc *p;
- u_long sp;
+ uintptr_t sp;
/* XXX no cpu_exec */
p = td->td_proc;
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index e9597086f7c1..c3709858ced8 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -110,10 +110,10 @@ int exec_args_adjust_args(struct image_args *args, size_t consume,
ssize_t extend);
char *exec_args_get_begin_envv(struct image_args *args);
int exec_check_permissions(struct image_params *);
-int exec_copyout_strings(struct image_params *, register_t **);
+int exec_copyout_strings(struct image_params *, uintptr_t *);
void exec_free_args(struct image_args *);
int exec_new_vmspace(struct image_params *, struct sysentvec *);
-void exec_setregs(struct thread *, struct image_params *, u_long);
+void exec_setregs(struct thread *, struct image_params *, uintptr_t);
int exec_shell_imgact(struct image_params *);
int exec_copyin_args(struct image_args *, const char *, enum uio_seg,
char **, char **);
diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h
index d56fd943f929..babb232964cc 100644
--- a/sys/sys/imgact_elf.h
+++ b/sys/sys/imgact_elf.h
@@ -95,11 +95,11 @@ __ElfType(Brandinfo);
int __elfN(brand_inuse)(Elf_Brandinfo *entry);
int __elfN(insert_brand_entry)(Elf_Brandinfo *entry);
int __elfN(remove_brand_entry)(Elf_Brandinfo *entry);
-int __elfN(freebsd_fixup)(register_t **, struct image_params *);
+int __elfN(freebsd_fixup)(uintptr_t *, struct image_params *);
int __elfN(coredump)(struct thread *, struct vnode *, off_t, int);
size_t __elfN(populate_note)(int, void *, void *, size_t, void **);
-void __elfN(stackgap)(struct image_params *, u_long *);
-int __elfN(freebsd_copyout_auxargs)(struct image_params *, u_long *);
+void __elfN(stackgap)(struct image_params *, uintptr_t *);
+int __elfN(freebsd_copyout_auxargs)(struct image_params *, uintptr_t *);
/* Machine specific function to dump per-thread information. */
void __elfN(dump_thread)(struct thread *, void *, size_t *);
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index cc3924ded7d8..9ed77fd09bea 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -99,7 +99,7 @@ struct sysentvec {
const int *sv_errtbl; /* errno translation table */
int (*sv_transtrap)(int, int);
/* translate trap-to-signal mapping */
- int (*sv_fixup)(register_t **, struct image_params *);
+ int (*sv_fixup)(uintptr_t *, struct image_params *);
/* stack fixup function */
void (*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *);
/* send signal */
@@ -109,17 +109,19 @@ struct sysentvec {
int (*sv_coredump)(struct thread *, struct vnode *, off_t, int);
/* function to dump core, or NULL */
int (*sv_imgact_try)(struct image_params *);
- void (*sv_stackgap)(struct image_params *, u_long *);
- int (*sv_copyout_auxargs)(struct image_params *, u_long *);
+ void (*sv_stackgap)(struct image_params *, uintptr_t *);
+ int (*sv_copyout_auxargs)(struct image_params *,
+ uintptr_t *);
int sv_minsigstksz; /* minimum signal stack size */
vm_offset_t sv_minuser; /* VM_MIN_ADDRESS */
vm_offset_t sv_maxuser; /* VM_MAXUSER_ADDRESS */
vm_offset_t sv_usrstack; /* USRSTACK */
vm_offset_t sv_psstrings; /* PS_STRINGS */
int sv_stackprot; /* vm protection for stack */
- int (*sv_copyout_strings)(struct image_params *, register_t **);
+ int (*sv_copyout_strings)(struct image_params *,
+ uintptr_t *);
void (*sv_setregs)(struct thread *, struct image_params *,
- u_long);
+ uintptr_t);
void (*sv_fixlimit)(struct rlimit *, int);
u_long *sv_maxssiz;
u_int sv_flags;