Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linux/linux_misc.c
Show First 20 Lines • Show All 982 Lines • ▼ Show 20 Lines | error = kern_utimesat(td, dfd, fname, UIO_SYSSPACE, | ||||
tvp, UIO_SYSSPACE); | tvp, UIO_SYSSPACE); | ||||
LFREEPATH(fname); | LFREEPATH(fname); | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
#endif | #endif | ||||
static int | static int | ||||
linux_common_wait(struct thread *td, int pid, int *statusp, | linux_common_wait(struct thread *td, idtype_t idtype, int id, int *statusp, | ||||
int options, struct __wrusage *wrup) | int options, void *rup, l_siginfo_t *infop) | ||||
{ | { | ||||
siginfo_t siginfo; | l_siginfo_t *lsi; | ||||
idtype_t idtype; | siginfo_t *info; | ||||
id_t id; | struct __wrusage *wru; | ||||
int error, status, tmpstat; | int error, status, tmpstat, sig; | ||||
if (pid == WAIT_ANY) { | if (rup != NULL) | ||||
idtype = P_ALL; | wru = malloc(sizeof(*wru), M_LINUX, M_WAITOK | M_ZERO); | ||||
id = 0; | info = malloc(sizeof(*info), M_LINUX, M_WAITOK | M_ZERO); | ||||
} else if (pid < 0) { | error = kern_wait6(td, idtype, id, | ||||
idtype = P_PGID; | &status, options, rup != NULL ? wru : NULL, info); | ||||
id = (id_t)-pid; | |||||
} else { | |||||
idtype = P_PID; | |||||
id = (id_t)pid; | |||||
} | |||||
/* | if (error == 0 && statusp) { | ||||
* For backward compatibility we implicitly add flags WEXITED | |||||
* and WTRAPPED here. | |||||
*/ | |||||
options |= WEXITED | WTRAPPED; | |||||
error = kern_wait6(td, idtype, id, &status, options, wrup, &siginfo); | |||||
if (error) | |||||
return (error); | |||||
if (statusp) { | |||||
tmpstat = status & 0xffff; | tmpstat = status & 0xffff; | ||||
kib: What is the point of mallocing them? The structures are not that large to not fit into stack… | |||||
if (WIFSIGNALED(tmpstat)) { | if (WIFSIGNALED(tmpstat)) { | ||||
tmpstat = (tmpstat & 0xffffff80) | | tmpstat = (tmpstat & 0xffffff80) | | ||||
bsd_to_linux_signal(WTERMSIG(tmpstat)); | bsd_to_linux_signal(WTERMSIG(tmpstat)); | ||||
} else if (WIFSTOPPED(tmpstat)) { | } else if (WIFSTOPPED(tmpstat)) { | ||||
tmpstat = (tmpstat & 0xffff00ff) | | tmpstat = (tmpstat & 0xffff00ff) | | ||||
(bsd_to_linux_signal(WSTOPSIG(tmpstat)) << 8); | (bsd_to_linux_signal(WSTOPSIG(tmpstat)) << 8); | ||||
#if defined(__amd64__) && !defined(COMPAT_LINUX32) | #if defined(__amd64__) && !defined(COMPAT_LINUX32) | ||||
if (WSTOPSIG(status) == SIGTRAP) { | if (WSTOPSIG(status) == SIGTRAP) { | ||||
tmpstat = linux_ptrace_status(td, | tmpstat = linux_ptrace_status(td, | ||||
siginfo.si_pid, tmpstat); | info->si_pid, tmpstat); | ||||
} | } | ||||
#endif | #endif | ||||
} else if (WIFCONTINUED(tmpstat)) { | } else if (WIFCONTINUED(tmpstat)) { | ||||
tmpstat = 0xffff; | tmpstat = 0xffff; | ||||
} | } | ||||
error = copyout(&tmpstat, statusp, sizeof(int)); | error = copyout(&tmpstat, statusp, sizeof(int)); | ||||
} | } | ||||
if (error == 0 && rup != NULL) | |||||
error = linux_copyout_rusage(&wru->wru_self, rup); | |||||
if (error == 0 && infop != NULL && td->td_retval[0] != 0) { | |||||
lsi = malloc(sizeof(*lsi), M_LINUX, M_WAITOK | M_ZERO); | |||||
Not Done Inline ActionsSame question about mallocing this one. kib: Same question about mallocing this one. | |||||
sig = bsd_to_linux_signal(info->si_signo); | |||||
siginfo_to_lsiginfo(info, lsi, sig); | |||||
error = copyout(lsi, infop, sizeof(*lsi)); | |||||
free(lsi, M_LINUX); | |||||
} | |||||
if (rup != NULL) | |||||
free(wru, M_LINUX); | |||||
free(info, M_LINUX); | |||||
return (error); | return (error); | ||||
} | } | ||||
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) | #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) | ||||
int | int | ||||
linux_waitpid(struct thread *td, struct linux_waitpid_args *args) | linux_waitpid(struct thread *td, struct linux_waitpid_args *args) | ||||
{ | { | ||||
struct linux_wait4_args wait4_args; | struct linux_wait4_args wait4_args; | ||||
wait4_args.pid = args->pid; | wait4_args.pid = args->pid; | ||||
wait4_args.status = args->status; | wait4_args.status = args->status; | ||||
wait4_args.options = args->options; | wait4_args.options = args->options; | ||||
wait4_args.rusage = NULL; | wait4_args.rusage = NULL; | ||||
return (linux_wait4(td, &wait4_args)); | return (linux_wait4(td, &wait4_args)); | ||||
} | } | ||||
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | ||||
int | int | ||||
linux_wait4(struct thread *td, struct linux_wait4_args *args) | linux_wait4(struct thread *td, struct linux_wait4_args *args) | ||||
{ | { | ||||
int error, options; | int options, id, idtype; | ||||
struct __wrusage wru, *wrup; | |||||
if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG | | if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG | | ||||
LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL)) | LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL)) | ||||
return (EINVAL); | return (EINVAL); | ||||
options = WEXITED; | options = 0; | ||||
linux_to_bsd_waitopts(args->options, &options); | linux_to_bsd_waitopts(args->options, &options); | ||||
/* | |||||
* For backward compatibility we implicitly add flags WEXITED | |||||
* and WTRAPPED here. | |||||
*/ | |||||
options |= WEXITED | WTRAPPED; | |||||
if (args->rusage != NULL) | if (args->pid == WAIT_ANY) { | ||||
wrup = &wru; | idtype = P_ALL; | ||||
else | id = 0; | ||||
wrup = NULL; | } else if (args->pid < 0) { | ||||
error = linux_common_wait(td, args->pid, args->status, options, wrup); | idtype = P_PGID; | ||||
if (error != 0) | id = (id_t)-args->pid; | ||||
return (error); | } else { | ||||
if (args->rusage != NULL) | idtype = P_PID; | ||||
error = linux_copyout_rusage(&wru.wru_self, args->rusage); | id = (id_t)args->pid; | ||||
return (error); | |||||
} | } | ||||
return (linux_common_wait(td, idtype, id, args->status, options, | |||||
args->rusage, NULL)); | |||||
} | |||||
int | int | ||||
linux_waitid(struct thread *td, struct linux_waitid_args *args) | linux_waitid(struct thread *td, struct linux_waitid_args *args) | ||||
{ | { | ||||
int status, options, sig; | |||||
struct __wrusage wru; | |||||
siginfo_t siginfo; | |||||
l_siginfo_t lsi; | |||||
idtype_t idtype; | idtype_t idtype; | ||||
struct proc *p; | int error, options; | ||||
int error; | |||||
options = 0; | options = 0; | ||||
linux_to_bsd_waitopts(args->options, &options); | linux_to_bsd_waitopts(args->options, &options); | ||||
if (options & ~(WNOHANG | WNOWAIT | WEXITED | WUNTRACED | WCONTINUED)) | if (options & ~(WNOHANG | WNOWAIT | WEXITED | WUNTRACED | WCONTINUED)) | ||||
return (EINVAL); | return (EINVAL); | ||||
if (!(options & (WEXITED | WUNTRACED | WCONTINUED))) | if (!(options & (WEXITED | WUNTRACED | WCONTINUED))) | ||||
return (EINVAL); | return (EINVAL); | ||||
Show All 11 Lines | case LINUX_P_PGID: | ||||
if (args->id <= 0) | if (args->id <= 0) | ||||
return (EINVAL); | return (EINVAL); | ||||
idtype = P_PGID; | idtype = P_PGID; | ||||
break; | break; | ||||
default: | default: | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
error = kern_wait6(td, idtype, args->id, &status, options, | error = linux_common_wait(td, idtype, args->id, NULL, options, | ||||
&wru, &siginfo); | args->rusage, args->info); | ||||
if (error != 0) | |||||
return (error); | |||||
if (args->rusage != NULL) { | |||||
error = linux_copyout_rusage(&wru.wru_children, | |||||
args->rusage); | |||||
if (error != 0) | |||||
return (error); | |||||
} | |||||
if (args->info != NULL) { | |||||
p = td->td_proc; | |||||
bzero(&lsi, sizeof(lsi)); | |||||
if (td->td_retval[0] != 0) { | |||||
sig = bsd_to_linux_signal(siginfo.si_signo); | |||||
siginfo_to_lsiginfo(&siginfo, &lsi, sig); | |||||
} | |||||
error = copyout(&lsi, args->info, sizeof(lsi)); | |||||
} | |||||
td->td_retval[0] = 0; | td->td_retval[0] = 0; | ||||
return (error); | return (error); | ||||
} | } | ||||
#ifdef LINUX_LEGACY_SYSCALLS | #ifdef LINUX_LEGACY_SYSCALLS | ||||
int | int | ||||
linux_mknod(struct thread *td, struct linux_mknod_args *args) | linux_mknod(struct thread *td, struct linux_mknod_args *args) | ||||
▲ Show 20 Lines • Show All 1,739 Lines • Show Last 20 Lines |
What is the point of mallocing them? The structures are not that large to not fit into stack for top-level.