diff options
author | Ed Schouten <ed@FreeBSD.org> | 2015-10-22 09:07:53 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2015-10-22 09:07:53 +0000 |
commit | b78ef4bd86f5fbc328996350735aa6586cd1bc35 (patch) | |
tree | e5c6fe17118c05c548cf2fbc3ab609e172a23a04 /sys/amd64/cloudabi64/cloudabi64_sysvec.c | |
parent | 68dd37f7b4a25066319c2701a6eceb675efce713 (diff) | |
download | src-b78ef4bd86f5fbc328996350735aa6586cd1bc35.tar.gz src-b78ef4bd86f5fbc328996350735aa6586cd1bc35.zip |
Refactoring: move out generic bits from cloudabi64_sysvec.c.
In order to make it easier to support CloudABI on ARM64, move out all of
the bits from the AMD64 cloudabi_sysvec.c into a new file
cloudabi_module.c that would otherwise remain identical. This reduces
the AMD64 specific code to just ~160 lines.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D3974
Notes
Notes:
svn path=/head/; revision=289747
Diffstat (limited to 'sys/amd64/cloudabi64/cloudabi64_sysvec.c')
-rw-r--r-- | sys/amd64/cloudabi64/cloudabi64_sysvec.c | 119 |
1 files changed, 2 insertions, 117 deletions
diff --git a/sys/amd64/cloudabi64/cloudabi64_sysvec.c b/sys/amd64/cloudabi64/cloudabi64_sysvec.c index 89540edf6f1d..e6e680bb512d 100644 --- a/sys/amd64/cloudabi64/cloudabi64_sysvec.c +++ b/sys/amd64/cloudabi64/cloudabi64_sysvec.c @@ -27,107 +27,26 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> -#include <sys/exec.h> -#include <sys/imgact.h> -#include <sys/imgact_elf.h> #include <sys/kernel.h> -#include <sys/module.h> #include <sys/proc.h> -#include <sys/smp.h> -#include <sys/sysctl.h> #include <sys/sysent.h> -#include <sys/systm.h> -#include <vm/pmap.h> #include <vm/vm.h> +#include <vm/pmap.h> #include <machine/frame.h> #include <machine/pcb.h> #include <machine/pmap.h> -#include <machine/psl.h> #include <machine/vmparam.h> #include <compat/cloudabi/cloudabi_util.h> #include <compat/cloudabi64/cloudabi64_syscall.h> -#include <compat/cloudabi64/cloudabi64_syscalldefs.h> #include <compat/cloudabi64/cloudabi64_util.h> extern const char *cloudabi64_syscallnames[]; extern struct sysent cloudabi64_sysent[]; -static register_t * -cloudabi64_copyout_strings(struct image_params *imgp) -{ - uintptr_t begin; - size_t len; - - /* Copy out program arguments. */ - len = imgp->args->begin_envv - imgp->args->begin_argv; - begin = rounddown2(USRSTACK - len, sizeof(register_t)); - copyout(imgp->args->begin_argv, (void *)begin, len); - return ((register_t *)begin); -} - -static int -cloudabi64_fixup(register_t **stack_base, struct image_params *imgp) -{ - char canarybuf[64]; - Elf64_Auxargs *args; - struct thread *td; - void *argdata, *canary; - size_t argdatalen; - int error; - - /* - * CloudABI executables do not store the FreeBSD OS release - * number in their header. Set the OS release number to the - * latest version of FreeBSD, so that system calls behave as if - * called natively. - */ - td = curthread; - td->td_proc->p_osrel = __FreeBSD_version; - - /* Store canary for stack smashing protection. */ - argdata = *stack_base; - arc4rand(canarybuf, sizeof(canarybuf), 0); - *stack_base -= howmany(sizeof(canarybuf), sizeof(register_t)); - canary = *stack_base; - error = copyout(canarybuf, canary, sizeof(canarybuf)); - if (error != 0) - return (error); - - /* - * Compute length of program arguments. As the argument data is - * binary safe, we had to add a trailing null byte in - * exec_copyin_data_fds(). Undo this by reducing the length. - */ - args = (Elf64_Auxargs *)imgp->auxargs; - argdatalen = imgp->args->begin_envv - imgp->args->begin_argv; - if (argdatalen > 0) - --argdatalen; - - /* Write out an auxiliary vector. */ - cloudabi64_auxv_t auxv[] = { -#define VAL(type, val) { .a_type = (type), .a_val = (val) } -#define PTR(type, ptr) { .a_type = (type), .a_ptr = (uintptr_t)(ptr) } - PTR(CLOUDABI_AT_ARGDATA, argdata), - VAL(CLOUDABI_AT_ARGDATALEN, argdatalen), - PTR(CLOUDABI_AT_CANARY, canary), - VAL(CLOUDABI_AT_CANARYLEN, sizeof(canarybuf)), - VAL(CLOUDABI_AT_NCPUS, mp_ncpus), - VAL(CLOUDABI_AT_PAGESZ, args->pagesz), - PTR(CLOUDABI_AT_PHDR, args->phdr), - VAL(CLOUDABI_AT_PHNUM, args->phnum), - VAL(CLOUDABI_AT_TID, td->td_tid), -#undef VAL -#undef PTR - { .a_type = CLOUDABI_AT_NULL }, - }; - *stack_base -= howmany(sizeof(auxv), sizeof(register_t)); - return (copyout(auxv, *stack_base, sizeof(auxv))); -} - static int cloudabi64_fetch_syscall_args(struct thread *td, struct syscall_args *sa) { @@ -234,43 +153,9 @@ static struct sysentvec cloudabi64_elf_sysvec = { INIT_SYSENTVEC(elf_sysvec, &cloudabi64_elf_sysvec); -static Elf64_Brandinfo cloudabi64_brand = { +Elf64_Brandinfo cloudabi64_brand = { .brand = ELFOSABI_CLOUDABI, .machine = EM_X86_64, .sysvec = &cloudabi64_elf_sysvec, .compat_3_brand = "CloudABI", }; - -static int -cloudabi64_modevent(module_t mod, int type, void *data) -{ - - switch (type) { - case MOD_LOAD: - if (elf64_insert_brand_entry(&cloudabi64_brand) < 0) { - printf("Failed to add CloudABI ELF brand handler\n"); - return (EINVAL); - } - return (0); - case MOD_UNLOAD: - if (elf64_brand_inuse(&cloudabi64_brand)) - return (EBUSY); - if (elf64_remove_brand_entry(&cloudabi64_brand) < 0) { - printf("Failed to remove CloudABI ELF brand handler\n"); - return (EINVAL); - } - return (0); - default: - return (EOPNOTSUPP); - } -} - -static moduledata_t cloudabi64_module = { - "cloudabi64", - cloudabi64_modevent, - NULL -}; - -DECLARE_MODULE_TIED(cloudabi64, cloudabi64_module, SI_SUB_EXEC, SI_ORDER_ANY); -MODULE_DEPEND(cloudabi64, cloudabi, 1, 1, 1); -FEATURE(cloudabi64, "CloudABI 64bit support"); |