Get rid of sa->narg. It serves no purpose; use sa->callp->sy_narg instead.

Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D26458
This commit is contained in:
Edward Tomasz Napierala 2020-09-27 18:47:06 +00:00
parent c4390e6da6
commit 1e2521ffae
29 changed files with 50 additions and 73 deletions

View File

@ -999,15 +999,15 @@ cpu_fetch_syscall_args_fallback(struct thread *td, struct syscall_args *sa)
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
KASSERT(sa->narg <= nitems(sa->args), ("Too many syscall arguments!"));
KASSERT(sa->callp->sy_narg <= nitems(sa->args),
("Too many syscall arguments!"));
argp = &frame->tf_rdi;
argp += reg;
memcpy(sa->args, argp, sizeof(sa->args[0]) * NARGREGS);
if (sa->narg > regcnt) {
if (sa->callp->sy_narg > regcnt) {
params = (caddr_t)frame->tf_rsp + sizeof(register_t);
error = copyin(params, &sa->args[regcnt],
(sa->narg - regcnt) * sizeof(sa->args[0]));
(sa->callp->sy_narg - regcnt) * sizeof(sa->args[0]));
if (__predict_false(error != 0))
return (error);
}
@ -1037,10 +1037,10 @@ cpu_fetch_syscall_args(struct thread *td)
return (cpu_fetch_syscall_args_fallback(td, sa));
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
KASSERT(sa->narg <= nitems(sa->args), ("Too many syscall arguments!"));
KASSERT(sa->callp->sy_narg <= nitems(sa->args),
("Too many syscall arguments!"));
if (__predict_false(sa->narg > NARGREGS))
if (__predict_false(sa->callp->sy_narg > NARGREGS))
return (cpu_fetch_syscall_args_fallback(td, sa));
memcpy(sa->args, &frame->tf_rdi, sizeof(sa->args[0]) * NARGREGS);

View File

@ -104,7 +104,6 @@ cloudabi32_fetch_syscall_args(struct thread *td)
if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL)
return (ENOSYS);
sa->callp = &cloudabi32_sysent[sa->code];
sa->narg = sa->callp->sy_narg;
/*
* Fetch system call arguments.
@ -117,7 +116,7 @@ cloudabi32_fetch_syscall_args(struct thread *td)
* implementation used by 64-bit processes.
*/
error = copyin((void *)frame->tf_rcx, sa->args,
sa->narg * sizeof(sa->args[0]));
sa->callp->sy_narg * sizeof(sa->args[0]));
if (error != 0)
return (error);

View File

@ -101,7 +101,6 @@ cloudabi64_fetch_syscall_args(struct thread *td)
if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL)
return (ENOSYS);
sa->callp = &cloudabi64_sysent[sa->code];
sa->narg = sa->callp->sy_narg;
/* Fetch system call arguments. */
sa->args[0] = frame->tf_rdi;

View File

@ -180,15 +180,14 @@ ia32_fetch_syscall_args(struct thread *td)
sa->callp = &p->p_sysent->sv_table[0];
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
if (params != NULL && sa->narg != 0)
if (params != NULL && sa->callp->sy_narg != 0)
error = copyin(params, (caddr_t)args,
(u_int)(sa->narg * sizeof(int)));
(u_int)(sa->callp->sy_narg * sizeof(int)));
else
error = 0;
for (i = 0; i < sa->narg; i++)
for (i = 0; i < sa->callp->sy_narg; i++)
sa->args[i] = args[i];
if (error == 0) {

View File

@ -94,7 +94,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[8];
int narg;
};
#ifdef _KERNEL

View File

@ -198,7 +198,6 @@ linux_fetch_syscall_args(struct thread *td)
sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1];
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
td->td_retval[0] = 0;
return (0);

View File

@ -662,7 +662,6 @@ linux32_fetch_syscall_args(struct thread *td)
sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1];
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
td->td_retval[0] = 0;
td->td_retval[1] = frame->tf_rdx;

View File

@ -120,12 +120,12 @@ cpu_fetch_syscall_args(struct thread *td)
sa->callp = &p->p_sysent->sv_table[0];
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
error = 0;
memcpy(sa->args, ap, sa->nap * sizeof(register_t));
if (sa->narg > sa->nap) {
if (sa->callp->sy_narg > sa->nap) {
error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
sa->nap, (sa->narg - sa->nap) * sizeof(register_t));
sa->nap, (sa->callp->sy_narg - sa->nap) *
sizeof(register_t));
}
if (error == 0) {
td->td_retval[0] = 0;

View File

@ -81,16 +81,15 @@ cloudabi32_fetch_syscall_args(struct thread *td)
if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL)
return (ENOSYS);
sa->callp = &cloudabi32_sysent[sa->code];
sa->narg = sa->callp->sy_narg;
/* Fetch system call arguments from registers and the stack. */
sa->args[0] = frame->tf_r0;
sa->args[1] = frame->tf_r1;
sa->args[2] = frame->tf_r2;
sa->args[3] = frame->tf_r3;
if (sa->narg > 4) {
if (sa->callp->sy_narg > 4) {
error = copyin((void *)td->td_frame->tf_usr_sp, &sa->args[4],
(sa->narg - 4) * sizeof(register_t));
(sa->callp->sy_narg - 4) * sizeof(register_t));
if (error != 0)
return (error);
}

View File

@ -82,7 +82,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[MAXARGS];
int narg;
u_int nap;
} __aligned(8);

View File

@ -156,7 +156,7 @@ freebsd32_fetch_syscall_args(struct thread *td)
struct proc *p;
register_t *ap;
struct syscall_args *sa;
int error, i, nap;
int error, i, nap, narg;
unsigned int args[4];
nap = 4;
@ -181,15 +181,15 @@ freebsd32_fetch_syscall_args(struct thread *td)
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
narg = sa->callp->sy_narg;
for (i = 0; i < nap; i++)
sa->args[i] = ap[i];
if (sa->narg > nap) {
if ((sa->narg - nap) > nitems(args))
if (narg > nap) {
if (narg - nap > nitems(args))
panic("Too many system call arguiments");
error = copyin((void *)td->td_frame->tf_x[13], args,
(sa->narg - nap) * sizeof(int));
for (i = 0; i < (sa->narg - nap); i++)
(narg - nap) * sizeof(int));
for (i = 0; i < (narg - nap); i++)
sa->args[i + nap] = args[i];
}

View File

@ -127,7 +127,7 @@ cpu_fetch_syscall_args(struct thread *td)
struct syscall_args *sa;
int nap;
nap = 8;
nap = MAXARGS;
p = td->td_proc;
ap = td->td_frame->tf_x;
sa = &td->td_sa;
@ -144,10 +144,9 @@ cpu_fetch_syscall_args(struct thread *td)
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
memcpy(sa->args, ap, nap * sizeof(register_t));
if (sa->narg > nap)
panic("ARM64TODO: Could we have more than 8 args?");
if (sa->callp->sy_narg > nap)
panic("ARM64TODO: Could we have more than %d args?", MAXARGS);
td->td_retval[0] = 0;
td->td_retval[1] = 0;

View File

@ -78,7 +78,6 @@ cloudabi32_fetch_syscall_args(struct thread *td)
if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL)
return (ENOSYS);
sa->callp = &cloudabi32_sysent[sa->code];
sa->narg = sa->callp->sy_narg;
/*
* Fetch system call arguments.
@ -91,7 +90,7 @@ cloudabi32_fetch_syscall_args(struct thread *td)
* implementation used by 64-bit processes.
*/
error = copyin((void *)frame->tf_x[2], sa->args,
sa->narg * sizeof(sa->args[0]));
sa->callp->sy_narg * sizeof(sa->args[0]));
if (error != 0)
return (error);

View File

@ -81,7 +81,6 @@ cloudabi64_fetch_syscall_args(struct thread *td)
if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL)
return (ENOSYS);
sa->callp = &cloudabi64_sysent[sa->code];
sa->narg = sa->callp->sy_narg;
/* Fetch system call arguments. */
for (i = 0; i < MAXARGS; i++)

View File

@ -51,7 +51,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[MAXARGS];
int narg;
};
#ifdef _KERNEL

View File

@ -126,10 +126,9 @@ linux_fetch_syscall_args(struct thread *td)
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
if (sa->narg > 8)
panic("ARM64TODO: Could we have more than 8 args?");
memcpy(sa->args, ap, 8 * sizeof(register_t));
if (sa->callp->sy_narg > MAXARGS)
panic("ARM64TODO: Could we have more than %d args?", MAXARGS);
memcpy(sa->args, ap, MAXARGS * sizeof(register_t));
td->td_retval[0] = 0;
return (0);

View File

@ -99,11 +99,10 @@ cloudabi32_fetch_syscall_args(struct thread *td)
if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL)
return (ENOSYS);
sa->callp = &cloudabi32_sysent[sa->code];
sa->narg = sa->callp->sy_narg;
/* Fetch system call arguments from the stack. */
error = copyin((void *)(frame->tf_esp + 4), sa->args,
sa->narg * sizeof(sa->args[0]));
sa->callp->sy_narg * sizeof(sa->args[0]));
if (error != 0)
return (error);

View File

@ -1084,11 +1084,10 @@ cpu_fetch_syscall_args(struct thread *td)
sa->callp = &p->p_sysent->sv_table[0];
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
if (params != NULL && sa->narg != 0)
if (params != NULL && sa->callp->sy_narg != 0)
error = copyin(params, (caddr_t)sa->args,
(u_int)(sa->narg * sizeof(uint32_t)));
(u_int)(sa->callp->sy_narg * sizeof(uint32_t)));
else
error = 0;

View File

@ -66,7 +66,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[8];
int narg;
};
#ifdef _KERNEL

View File

@ -784,7 +784,6 @@ linux_fetch_syscall_args(struct thread *td)
sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1];
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
td->td_retval[0] = 0;
td->td_retval[1] = frame->tf_edx;

View File

@ -82,7 +82,7 @@ _Static_assert(offsetof(struct thread, td_flags) == 0xfc,
"struct thread KBI td_flags");
_Static_assert(offsetof(struct thread, td_pflags) == 0x104,
"struct thread KBI td_pflags");
_Static_assert(offsetof(struct thread, td_frame) == 0x4a8,
_Static_assert(offsetof(struct thread, td_frame) == 0x4a0,
"struct thread KBI td_frame");
_Static_assert(offsetof(struct thread, td_emuldata) == 0x6b0,
"struct thread KBI td_emuldata");
@ -102,9 +102,9 @@ _Static_assert(offsetof(struct thread, td_flags) == 0x98,
"struct thread KBI td_flags");
_Static_assert(offsetof(struct thread, td_pflags) == 0xa0,
"struct thread KBI td_pflags");
_Static_assert(offsetof(struct thread, td_frame) == 0x304,
_Static_assert(offsetof(struct thread, td_frame) == 0x300,
"struct thread KBI td_frame");
_Static_assert(offsetof(struct thread, td_emuldata) == 0x348,
_Static_assert(offsetof(struct thread, td_emuldata) == 0x344,
"struct thread KBI td_emuldata");
_Static_assert(offsetof(struct proc, p_flag) == 0x68,
"struct proc KBI p_flag");

View File

@ -79,7 +79,7 @@ syscallenter(struct thread *td)
error = (p->p_sysent->sv_fetch_syscall_args)(td);
#ifdef KTRACE
if (KTRPOINT(td, KTR_SYSCALL))
ktrsyscall(sa->code, sa->narg, sa->args);
ktrsyscall(sa->code, sa->callp->sy_narg, sa->args);
#endif
KTR_START4(KTR_SYSC, "syscall", syscallname(p, sa->code),
(uintptr_t)td, "pid:%d", td->td_proc->p_pid, "arg0:%p", sa->args[0],
@ -104,7 +104,7 @@ syscallenter(struct thread *td)
error = (p->p_sysent->sv_fetch_syscall_args)(td);
#ifdef KTRACE
if (KTRPOINT(td, KTR_SYSCALL))
ktrsyscall(sa->code, sa->narg, sa->args);
ktrsyscall(sa->code, sa->callp->sy_narg, sa->args);
#endif
if (error != 0) {
td->td_errno = error;

View File

@ -925,7 +925,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
break;
}
bzero(addr, sizeof(td2->td_sa.args));
bcopy(td2->td_sa.args, addr, td2->td_sa.narg *
bcopy(td2->td_sa.args, addr, td2->td_sa.callp->sy_narg *
sizeof(register_t));
break;
@ -1246,7 +1246,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
strcpy(pl->pl_tdname, td2->td_name);
if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) != 0) {
pl->pl_syscall_code = td2->td_sa.code;
pl->pl_syscall_narg = td2->td_sa.narg;
pl->pl_syscall_narg = td2->td_sa.callp->sy_narg;
} else {
pl->pl_syscall_code = 0;
pl->pl_syscall_narg = 0;

View File

@ -85,7 +85,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[8];
int narg;
struct trapframe *trapframe;
};

View File

@ -448,9 +448,7 @@ cpu_fetch_syscall_args(struct thread *td)
else
sa->callp = &se->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
if (sa->narg > nsaved) {
if (sa->callp->sy_narg > nsaved) {
#if defined(__mips_n32) || defined(__mips_n64)
/*
* XXX
@ -462,7 +460,7 @@ cpu_fetch_syscall_args(struct thread *td)
if (!SV_PROC_FLAG(td->td_proc, SV_ILP32))
#endif
printf("SYSCALL #%u pid:%u, narg (%u) > nsaved (%u).\n",
sa->code, td->td_proc->p_pid, sa->narg, nsaved);
sa->code, td->td_proc->p_pid, sa->callp->sy_narg, nsaved);
#endif
#if (defined(__mips_n32) || defined(__mips_n64)) && defined(COMPAT_FREEBSD32)
if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
@ -470,7 +468,7 @@ cpu_fetch_syscall_args(struct thread *td)
int32_t arg;
error = 0; /* XXX GCC is awful. */
for (i = nsaved; i < sa->narg; i++) {
for (i = nsaved; i < sa->callp->sy_narg; i++) {
error = copyin((caddr_t)(intptr_t)(locr0->sp +
(4 + (i - nsaved)) * sizeof(int32_t)),
(caddr_t)&arg, sizeof arg);
@ -482,7 +480,7 @@ cpu_fetch_syscall_args(struct thread *td)
#endif
error = copyin((caddr_t)(intptr_t)(locr0->sp +
4 * sizeof(register_t)), (caddr_t)&sa->args[nsaved],
(u_int)(sa->narg - nsaved) * sizeof(register_t));
(u_int)(sa->callp->sy_narg - nsaved) * sizeof(register_t));
if (error != 0) {
locr0->v0 = error;
locr0->a3 = 1;

View File

@ -63,7 +63,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[10];
int narg;
};
#ifdef _KERNEL

View File

@ -639,7 +639,7 @@ cpu_fetch_syscall_args(struct thread *td)
struct syscall_args *sa;
caddr_t params;
size_t argsz;
int error, n, i;
int error, n, narg, i;
p = td->td_proc;
frame = td->td_frame;
@ -680,7 +680,7 @@ cpu_fetch_syscall_args(struct thread *td)
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
narg = sa->callp->sy_narg;
if (SV_PROC_FLAG(p, SV_ILP32)) {
argsz = sizeof(uint32_t);
@ -695,17 +695,17 @@ cpu_fetch_syscall_args(struct thread *td)
sa->args[i] = ((u_register_t *)(params))[i];
}
if (sa->narg > n)
if (narg > n)
error = copyin(MOREARGS(frame->fixreg[1]), sa->args + n,
(sa->narg - n) * argsz);
(narg - n) * argsz);
else
error = 0;
#ifdef __powerpc64__
if (SV_PROC_FLAG(p, SV_ILP32) && sa->narg > n) {
if (SV_PROC_FLAG(p, SV_ILP32) && narg > n) {
/* Expand the size of arguments copied from the stack */
for (i = sa->narg; i >= n; i--)
for (i = narg; i >= n; i--)
sa->args[i] = ((uint32_t *)(&sa->args[n]))[i-n];
}
#endif

View File

@ -50,7 +50,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[MAXARGS];
int narg;
};
#endif /* !_MACHINE_PROC_H_ */

View File

@ -117,9 +117,8 @@ cpu_fetch_syscall_args(struct thread *td)
else
sa->callp = &p->p_sysent->sv_table[sa->code];
sa->narg = sa->callp->sy_narg;
memcpy(sa->args, ap, nap * sizeof(register_t));
if (sa->narg > nap)
if (sa->callp->sy_narg > nap)
panic("TODO: Could we have more then %d args?", NARGREG);
td->td_retval[0] = 0;