syscallarg_t: Add a type for system call arguments
This more clearly differentiates system call arguments from integer registers and return values. On current architectures it has no effect, but on architectures where pointers are not integers (CHERI) and may not even share registers (CHERI-MIPS) it is necessiary to differentiate between system call arguments (syscallarg_t) and integer register values (register_t). Obtained from: CheriBSD Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D33780
This commit is contained in:
parent
cd8796cee0
commit
b1ad6a9000
@ -1011,7 +1011,7 @@ cpu_fetch_syscall_args_fallback(struct thread *td, struct syscall_args *sa)
|
|||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
struct trapframe *frame;
|
struct trapframe *frame;
|
||||||
register_t *argp;
|
syscallarg_t *argp;
|
||||||
caddr_t params;
|
caddr_t params;
|
||||||
int reg, regcnt, error;
|
int reg, regcnt, error;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ int
|
|||||||
cpu_fetch_syscall_args(struct thread *td)
|
cpu_fetch_syscall_args(struct thread *td)
|
||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
register_t *ap;
|
syscallarg_t *ap;
|
||||||
struct syscall_args *sa;
|
struct syscall_args *sa;
|
||||||
u_int nap;
|
u_int nap;
|
||||||
int error;
|
int error;
|
||||||
@ -124,10 +124,10 @@ cpu_fetch_syscall_args(struct thread *td)
|
|||||||
else
|
else
|
||||||
sa->callp = &p->p_sysent->sv_table[sa->code];
|
sa->callp = &p->p_sysent->sv_table[sa->code];
|
||||||
error = 0;
|
error = 0;
|
||||||
memcpy(sa->args, ap, nap * sizeof(register_t));
|
memcpy(sa->args, ap, nap * sizeof(*sa->args));
|
||||||
if (sa->callp->sy_narg > nap) {
|
if (sa->callp->sy_narg > nap) {
|
||||||
error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
|
error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
|
||||||
nap, (sa->callp->sy_narg - nap) * sizeof(register_t));
|
nap, (sa->callp->sy_narg - nap) * sizeof(*sa->args));
|
||||||
}
|
}
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
td->td_retval[0] = 0;
|
td->td_retval[0] = 0;
|
||||||
|
@ -134,7 +134,7 @@ int
|
|||||||
cpu_fetch_syscall_args(struct thread *td)
|
cpu_fetch_syscall_args(struct thread *td)
|
||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
register_t *ap, *dst_ap;
|
syscallarg_t *ap, *dst_ap;
|
||||||
struct syscall_args *sa;
|
struct syscall_args *sa;
|
||||||
|
|
||||||
p = td->td_proc;
|
p = td->td_proc;
|
||||||
@ -159,7 +159,7 @@ cpu_fetch_syscall_args(struct thread *td)
|
|||||||
KASSERT(sa->callp->sy_narg <= nitems(sa->args),
|
KASSERT(sa->callp->sy_narg <= nitems(sa->args),
|
||||||
("Syscall %d takes too many arguments", sa->code));
|
("Syscall %d takes too many arguments", sa->code));
|
||||||
|
|
||||||
memcpy(dst_ap, ap, (nitems(sa->args) - 1) * sizeof(register_t));
|
memcpy(dst_ap, ap, (nitems(sa->args) - 1) * sizeof(*dst_ap));
|
||||||
|
|
||||||
td->td_retval[0] = 0;
|
td->td_retval[0] = 0;
|
||||||
td->td_retval[1] = 0;
|
td->td_retval[1] = 0;
|
||||||
|
@ -524,7 +524,7 @@ ktr_get_tracevp(struct proc *p, bool ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ktrsyscall(int code, int narg, register_t args[])
|
ktrsyscall(int code, int narg, syscallarg_t args[])
|
||||||
{
|
{
|
||||||
struct ktr_request *req;
|
struct ktr_request *req;
|
||||||
struct ktr_syscall *ktp;
|
struct ktr_syscall *ktp;
|
||||||
|
@ -596,7 +596,7 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap)
|
|||||||
struct fpreg fpreg;
|
struct fpreg fpreg;
|
||||||
struct reg reg;
|
struct reg reg;
|
||||||
struct iovec vec;
|
struct iovec vec;
|
||||||
char args[sizeof(td->td_sa.args)];
|
syscallarg_t args[nitems(td->td_sa.args)];
|
||||||
struct ptrace_sc_ret psr;
|
struct ptrace_sc_ret psr;
|
||||||
int ptevents;
|
int ptevents;
|
||||||
} r;
|
} r;
|
||||||
@ -1143,7 +1143,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
|
|||||||
/* See the explanation in linux_ptrace_get_syscall_info(). */
|
/* See the explanation in linux_ptrace_get_syscall_info(). */
|
||||||
bcopy(td2->td_sa.args, addr, SV_PROC_ABI(td->td_proc) ==
|
bcopy(td2->td_sa.args, addr, SV_PROC_ABI(td->td_proc) ==
|
||||||
SV_ABI_LINUX ? sizeof(td2->td_sa.args) :
|
SV_ABI_LINUX ? sizeof(td2->td_sa.args) :
|
||||||
td2->td_sa.callp->sy_narg * sizeof(register_t));
|
td2->td_sa.callp->sy_narg * sizeof(syscallarg_t));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PT_GET_SC_RET:
|
case PT_GET_SC_RET:
|
||||||
|
@ -94,7 +94,7 @@ int
|
|||||||
cpu_fetch_syscall_args(struct thread *td)
|
cpu_fetch_syscall_args(struct thread *td)
|
||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
register_t *ap, *dst_ap;
|
syscallarg_t *ap, *dst_ap;
|
||||||
struct syscall_args *sa;
|
struct syscall_args *sa;
|
||||||
|
|
||||||
p = td->td_proc;
|
p = td->td_proc;
|
||||||
@ -119,7 +119,7 @@ cpu_fetch_syscall_args(struct thread *td)
|
|||||||
KASSERT(sa->callp->sy_narg <= nitems(sa->args),
|
KASSERT(sa->callp->sy_narg <= nitems(sa->args),
|
||||||
("Syscall %d takes too many arguments", sa->code));
|
("Syscall %d takes too many arguments", sa->code));
|
||||||
|
|
||||||
memcpy(dst_ap, ap, (NARGREG - 1) * sizeof(register_t));
|
memcpy(dst_ap, ap, (NARGREG - 1) * sizeof(*dst_ap));
|
||||||
|
|
||||||
td->td_retval[0] = 0;
|
td->td_retval[0] = 0;
|
||||||
td->td_retval[1] = 0;
|
td->td_retval[1] = 0;
|
||||||
|
@ -284,7 +284,7 @@ void ktrpsig(int, sig_t, sigset_t *, int);
|
|||||||
void ktrfault(vm_offset_t, int);
|
void ktrfault(vm_offset_t, int);
|
||||||
void ktrfaultend(int);
|
void ktrfaultend(int);
|
||||||
void ktrgenio(int, enum uio_rw, struct uio *, int);
|
void ktrgenio(int, enum uio_rw, struct uio *, int);
|
||||||
void ktrsyscall(int, int narg, register_t args[]);
|
void ktrsyscall(int, int narg, syscallarg_t args[]);
|
||||||
void ktrsysctl(int *name, u_int namelen);
|
void ktrsysctl(int *name, u_int namelen);
|
||||||
void ktrsysret(int, int, register_t);
|
void ktrsysret(int, int, register_t);
|
||||||
void ktrprocctor(struct proc *);
|
void ktrprocctor(struct proc *);
|
||||||
|
@ -357,7 +357,7 @@ struct thread {
|
|||||||
} td_state; /* (t) thread state */
|
} td_state; /* (t) thread state */
|
||||||
/* Note: td_state must be accessed using TD_{GET,SET}_STATE(). */
|
/* Note: td_state must be accessed using TD_{GET,SET}_STATE(). */
|
||||||
union {
|
union {
|
||||||
register_t tdu_retval[2];
|
syscallarg_t tdu_retval[2];
|
||||||
off_t tdu_off;
|
off_t tdu_off;
|
||||||
} td_uretoff; /* (k) Syscall aux returns. */
|
} td_uretoff; /* (k) Syscall aux returns. */
|
||||||
#define td_retval td_uretoff.tdu_retval
|
#define td_retval td_uretoff.tdu_retval
|
||||||
|
@ -162,7 +162,7 @@ struct ptrace_lwpinfo32 {
|
|||||||
|
|
||||||
/* Argument structure for PT_GET_SC_RET. */
|
/* Argument structure for PT_GET_SC_RET. */
|
||||||
struct ptrace_sc_ret {
|
struct ptrace_sc_ret {
|
||||||
register_t sr_retval[2]; /* Only valid if sr_error == 0. */
|
syscallarg_t sr_retval[2]; /* Only valid if sr_error == 0. */
|
||||||
int sr_error;
|
int sr_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -270,6 +270,8 @@ typedef __vm_size_t vm_size_t;
|
|||||||
|
|
||||||
typedef __rman_res_t rman_res_t;
|
typedef __rman_res_t rman_res_t;
|
||||||
|
|
||||||
|
typedef __register_t syscallarg_t;
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
typedef int boolean_t;
|
typedef int boolean_t;
|
||||||
typedef struct _device *device_t;
|
typedef struct _device *device_t;
|
||||||
|
@ -860,7 +860,7 @@ local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
|
|||||||
write_line("sysarg", "};\n")
|
write_line("sysarg", "};\n")
|
||||||
else
|
else
|
||||||
write_line("sysarg", string.format(
|
write_line("sysarg", string.format(
|
||||||
"struct %s {\n\tregister_t dummy;\n};\n", argalias))
|
"struct %s {\n\tsyscallarg_t dummy;\n};\n", argalias))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -986,7 +986,7 @@ local function handle_compat(sysnum, thr_flag, flags, sysflags, rettype,
|
|||||||
write_line(out, "};\n")
|
write_line(out, "};\n")
|
||||||
elseif flags & nargflags == 0 then
|
elseif flags & nargflags == 0 then
|
||||||
write_line("sysarg", string.format(
|
write_line("sysarg", string.format(
|
||||||
"struct %s {\n\tregister_t dummy;\n};\n", argalias))
|
"struct %s {\n\tsyscallarg_t dummy;\n};\n", argalias))
|
||||||
end
|
end
|
||||||
if flags & dprotoflags == 0 then
|
if flags & dprotoflags == 0 then
|
||||||
write_line(outdcl, string.format(
|
write_line(outdcl, string.format(
|
||||||
@ -1439,8 +1439,8 @@ struct proc;
|
|||||||
|
|
||||||
struct thread;
|
struct thread;
|
||||||
|
|
||||||
#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
|
#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \
|
||||||
0 : sizeof(register_t) - sizeof(t))
|
0 : sizeof(syscallarg_t) - sizeof(t))
|
||||||
|
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
#define PADL_(t) 0
|
#define PADL_(t) 0
|
||||||
@ -1530,7 +1530,7 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
|
|||||||
process_sysfile(sysfile)
|
process_sysfile(sysfile)
|
||||||
|
|
||||||
write_line("sysinc",
|
write_line("sysinc",
|
||||||
"\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n")
|
"\n#define AS(name) (sizeof(struct name) / sizeof(syscallarg_t))\n")
|
||||||
|
|
||||||
for _, v in pairs(compat_options) do
|
for _, v in pairs(compat_options) do
|
||||||
if v["count"] > 0 then
|
if v["count"] > 0 then
|
||||||
|
@ -420,7 +420,7 @@ kern_mmap(struct thread *td, const struct mmap_req *mrp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
td->td_retval[0] = (register_t) (addr + pageoff);
|
td->td_retval[0] = addr + pageoff;
|
||||||
done:
|
done:
|
||||||
if (fp)
|
if (fp)
|
||||||
fdrop(fp, td);
|
fdrop(fp, td);
|
||||||
|
@ -561,7 +561,7 @@ exit_syscall(struct trussinfo *info, struct ptrace_lwpinfo *pl)
|
|||||||
*/
|
*/
|
||||||
if (psr.sr_error != 0) {
|
if (psr.sr_error != 0) {
|
||||||
asprintf(&temp, "0x%lx",
|
asprintf(&temp, "0x%lx",
|
||||||
t->cs.args[sc->decode.args[i].offset]);
|
(long)t->cs.args[sc->decode.args[i].offset]);
|
||||||
} else {
|
} else {
|
||||||
temp = print_arg(&sc->decode.args[i],
|
temp = print_arg(&sc->decode.args[i],
|
||||||
t->cs.args, psr.sr_retval, info);
|
t->cs.args, psr.sr_retval, info);
|
||||||
|
@ -228,7 +228,7 @@ struct syscall {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct syscall *get_syscall(struct threadinfo *, u_int, u_int);
|
struct syscall *get_syscall(struct threadinfo *, u_int, u_int);
|
||||||
char *print_arg(struct syscall_arg *, unsigned long *, register_t *,
|
char *print_arg(struct syscall_arg *, syscallarg_t *, syscallarg_t *,
|
||||||
struct trussinfo *);
|
struct trussinfo *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -252,8 +252,8 @@ char *print_arg(struct syscall_arg *, unsigned long *, register_t *,
|
|||||||
#define LINUX_SENDMSG 16
|
#define LINUX_SENDMSG 16
|
||||||
#define LINUX_RECVMSG 17
|
#define LINUX_RECVMSG 17
|
||||||
|
|
||||||
#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
|
#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \
|
||||||
0 : sizeof(register_t) - sizeof(t))
|
0 : sizeof(syscallarg_t) - sizeof(t))
|
||||||
|
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
#define PADL_(t) 0
|
#define PADL_(t) 0
|
||||||
@ -272,5 +272,5 @@ struct linux_socketcall_args {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void print_syscall(struct trussinfo *);
|
void print_syscall(struct trussinfo *);
|
||||||
void print_syscall_ret(struct trussinfo *, int, register_t *);
|
void print_syscall_ret(struct trussinfo *, int, syscallarg_t *);
|
||||||
void print_summary(struct trussinfo *trussinfo);
|
void print_summary(struct trussinfo *trussinfo);
|
||||||
|
@ -1558,7 +1558,7 @@ user_ptr32_to_psaddr(int32_t user_pointer)
|
|||||||
* an array of all of the system call arguments.
|
* an array of all of the system call arguments.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
print_arg(struct syscall_arg *sc, unsigned long *args, register_t *retval,
|
print_arg(struct syscall_arg *sc, syscallarg_t *args, syscallarg_t *retval,
|
||||||
struct trussinfo *trussinfo)
|
struct trussinfo *trussinfo)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -1592,10 +1592,10 @@ print_arg(struct syscall_arg *sc, unsigned long *args, register_t *retval,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LongHex:
|
case LongHex:
|
||||||
fprintf(fp, "0x%lx", args[sc->offset]);
|
fprintf(fp, "0x%lx", (long)args[sc->offset]);
|
||||||
break;
|
break;
|
||||||
case Long:
|
case Long:
|
||||||
fprintf(fp, "%ld", args[sc->offset]);
|
fprintf(fp, "%ld", (long)args[sc->offset]);
|
||||||
break;
|
break;
|
||||||
case Sizet:
|
case Sizet:
|
||||||
fprintf(fp, "%zu", (size_t)args[sc->offset]);
|
fprintf(fp, "%zu", (size_t)args[sc->offset]);
|
||||||
@ -2734,7 +2734,7 @@ print_syscall(struct trussinfo *trussinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
print_syscall_ret(struct trussinfo *trussinfo, int error, register_t *retval)
|
print_syscall_ret(struct trussinfo *trussinfo, int error, syscallarg_t *retval)
|
||||||
{
|
{
|
||||||
struct timespec timediff;
|
struct timespec timediff;
|
||||||
struct threadinfo *t;
|
struct threadinfo *t;
|
||||||
|
@ -81,7 +81,7 @@ struct current_syscall {
|
|||||||
struct syscall *sc;
|
struct syscall *sc;
|
||||||
unsigned int number;
|
unsigned int number;
|
||||||
unsigned int nargs;
|
unsigned int nargs;
|
||||||
unsigned long args[10];
|
syscallarg_t args[10];
|
||||||
char *s_args[10]; /* the printable arguments */
|
char *s_args[10]; /* the printable arguments */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user