Changeset View
Changeset View
Standalone View
Standalone View
head/sys/compat/linux/linux_emul.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* | * | ||||
* Copyright (c) 1994-1996 Søren Schmidt | |||||
* Copyright (c) 2006 Roman Divacky | * Copyright (c) 2006 Roman Divacky | ||||
* Copyright (c) 2013 Dmitry Chagin | * Copyright (c) 2013 Dmitry Chagin | ||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
Show All 15 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/fcntl.h> | |||||
#include <sys/imgact.h> | #include <sys/imgact.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/ktr.h> | #include <sys/ktr.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/sx.h> | #include <sys/sx.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/syscallsubr.h> | #include <sys/syscallsubr.h> | ||||
#include <sys/sysent.h> | #include <sys/sysent.h> | ||||
#include <compat/linux/linux_emul.h> | #include <compat/linux/linux_emul.h> | ||||
#include <compat/linux/linux_misc.h> | #include <compat/linux/linux_misc.h> | ||||
#include <compat/linux/linux_persona.h> | #include <compat/linux/linux_persona.h> | ||||
#include <compat/linux/linux_util.h> | #include <compat/linux/linux_util.h> | ||||
#if BYTE_ORDER == LITTLE_ENDIAN | |||||
#define SHELLMAGIC 0x2123 /* #! */ | |||||
#else | |||||
#define SHELLMAGIC 0x2321 | |||||
#endif | |||||
/* | /* | ||||
* This returns reference to the thread emuldata entry (if found) | * This returns reference to the thread emuldata entry (if found) | ||||
* | * | ||||
* Hold PROC_LOCK when referencing emuldata from other threads. | * Hold PROC_LOCK when referencing emuldata from other threads. | ||||
*/ | */ | ||||
struct linux_emuldata * | struct linux_emuldata * | ||||
em_find(struct thread *td) | em_find(struct thread *td) | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | linux_proc_exit(void *arg __unused, struct proc *p) | ||||
if (pem->epoll != NULL) { | if (pem->epoll != NULL) { | ||||
emd = pem->epoll; | emd = pem->epoll; | ||||
pem->epoll = NULL; | pem->epoll = NULL; | ||||
free(emd, M_EPOLL); | free(emd, M_EPOLL); | ||||
} | } | ||||
sx_destroy(&pem->pem_sx); | sx_destroy(&pem->pem_sx); | ||||
free(pem, M_LINUX); | free(pem, M_LINUX); | ||||
} | |||||
/* | |||||
* If a Linux binary is exec'ing something, try this image activator | |||||
* first. We override standard shell script execution in order to | |||||
* be able to modify the interpreter path. We only do this if a Linux | |||||
* binary is doing the exec, so we do not create an EXEC module for it. | |||||
*/ | |||||
int | |||||
linux_exec_imgact_try(struct image_params *imgp) | |||||
{ | |||||
const char *head = (const char *)imgp->image_header; | |||||
char *rpath; | |||||
int error = -1; | |||||
/* | |||||
* The interpreter for shell scripts run from a Linux binary needs | |||||
* to be located in /compat/linux if possible in order to recursively | |||||
* maintain Linux path emulation. | |||||
*/ | |||||
if (((const short *)head)[0] == SHELLMAGIC) { | |||||
/* | |||||
* Run our normal shell image activator. If it succeeds attempt | |||||
* to use the alternate path for the interpreter. If an | |||||
* alternate path is found, use our stringspace to store it. | |||||
*/ | |||||
if ((error = exec_shell_imgact(imgp)) == 0) { | |||||
linux_emul_convpath(FIRST_THREAD_IN_PROC(imgp->proc), | |||||
imgp->interpreter_name, UIO_SYSSPACE, &rpath, 0, | |||||
AT_FDCWD); | |||||
if (rpath != NULL) | |||||
imgp->args->fname_buf = | |||||
imgp->interpreter_name = rpath; | |||||
} | |||||
} | |||||
return (error); | |||||
} | } | ||||
int | int | ||||
linux_common_execve(struct thread *td, struct image_args *eargs) | linux_common_execve(struct thread *td, struct image_args *eargs) | ||||
{ | { | ||||
struct linux_pemuldata *pem; | struct linux_pemuldata *pem; | ||||
struct epoll_emuldata *emd; | struct epoll_emuldata *emd; | ||||
struct vmspace *oldvmspace; | struct vmspace *oldvmspace; | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |