2006-05-11 16:57:23 +02:00
|
|
|
/* This file handles the EXEC system call. It performs the work as follows:
|
|
|
|
* - see if the permissions allow the file to be executed
|
|
|
|
* - read the header and extract the sizes
|
|
|
|
* - fetch the initial args and environment from the user space
|
|
|
|
* - allocate the memory for the new process
|
|
|
|
* - copy the initial stack from PM to the process
|
|
|
|
* - read in the text and data segments and copy to the process
|
|
|
|
* - take care of setuid and setgid bits
|
|
|
|
* - fix up 'mproc' table
|
|
|
|
* - tell kernel about EXEC
|
|
|
|
* - save offset to initial argc (for ps)
|
|
|
|
*
|
|
|
|
* The entry points into this file are:
|
|
|
|
* pm_exec: perform the EXEC system call
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/endpoint.h>
|
|
|
|
#include <minix/com.h>
|
2006-11-27 15:21:43 +01:00
|
|
|
#include <minix/u64.h>
|
2006-05-11 16:57:23 +02:00
|
|
|
#include <a.out.h>
|
|
|
|
#include <signal.h>
|
2010-12-10 10:27:56 +01:00
|
|
|
#include <stdlib.h>
|
2006-05-11 16:57:23 +02:00
|
|
|
#include <string.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <dirent.h>
|
2010-12-10 10:27:56 +01:00
|
|
|
#include <sys/param.h>
|
2006-05-11 16:57:23 +02:00
|
|
|
#include "fproc.h"
|
2012-02-13 16:28:04 +01:00
|
|
|
#include "path.h"
|
2006-05-11 16:57:23 +02:00
|
|
|
#include "param.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
#include "vnode.h"
|
|
|
|
#include <minix/vfsif.h>
|
2012-04-03 15:52:25 +02:00
|
|
|
#include <machine/vmparam.h>
|
2010-12-10 10:27:56 +01:00
|
|
|
#include <assert.h>
|
2012-04-03 15:52:25 +02:00
|
|
|
#include <fcntl.h>
|
2010-12-10 10:27:56 +01:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
#define _KERNEL /* for ELF_AUX_ENTRIES */
|
|
|
|
#include <libexec.h>
|
|
|
|
|
2012-05-30 19:34:07 +02:00
|
|
|
/* fields only used by elf and in VFS */
|
|
|
|
struct vfs_exec_info {
|
|
|
|
struct exec_info args; /* libexec exec args */
|
|
|
|
struct vnode *vp; /* Exec file's vnode */
|
|
|
|
struct vmnt *vmp; /* Exec file's vmnt */
|
|
|
|
struct stat sb; /* Exec file's stat structure */
|
|
|
|
int userflags; /* exec() flags from userland */
|
|
|
|
int is_dyn; /* Dynamically linked executable */
|
|
|
|
int elf_main_fd; /* Dyn: FD of main program execuatble */
|
|
|
|
char execname[PATH_MAX]; /* Full executable invocation */
|
|
|
|
};
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void lock_exec(void);
|
|
|
|
static void unlock_exec(void);
|
2012-04-13 14:50:38 +02:00
|
|
|
static int patch_stack(struct vnode *vp, char stack[ARG_MAX],
|
|
|
|
size_t *stk_bytes, char path[PATH_MAX]);
|
2012-05-30 19:34:07 +02:00
|
|
|
static int is_script(struct vfs_exec_info *execi);
|
2012-04-13 14:50:38 +02:00
|
|
|
static int insert_arg(char stack[ARG_MAX], size_t *stk_bytes, char *arg,
|
|
|
|
int replace);
|
2012-03-25 20:25:53 +02:00
|
|
|
static void clo_exec(struct fproc *rfp);
|
2012-05-30 19:34:07 +02:00
|
|
|
static int stack_prepare_elf(struct vfs_exec_info *execi,
|
2012-04-18 16:32:38 +02:00
|
|
|
char *curstack, size_t *frame_len, vir_bytes *vsp, int *extrabase);
|
2012-05-30 19:34:07 +02:00
|
|
|
static int map_header(struct vfs_exec_info *execi);
|
|
|
|
static int read_seg(struct exec_info *execi, off_t off, off_t seg_addr, size_t seg_bytes);
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
#define PTRSIZE sizeof(char *) /* Size of pointers in argv[] and envp[]. */
|
|
|
|
|
2010-12-10 10:27:56 +01:00
|
|
|
/* Array of loaders for different object file formats */
|
2012-05-30 19:34:07 +02:00
|
|
|
typedef int (*exechook_t)(struct vfs_exec_info *execpackage);
|
|
|
|
typedef int (*stackhook_t)(struct vfs_exec_info *execi, char *curstack,
|
2012-04-18 16:32:38 +02:00
|
|
|
size_t *frame_len, vir_bytes *, int *extrabase);
|
2010-12-10 10:27:56 +01:00
|
|
|
struct exec_loaders {
|
2012-05-30 19:34:07 +02:00
|
|
|
libexec_exec_loadfunc_t load_object; /* load executable into memory */
|
2012-04-03 15:52:25 +02:00
|
|
|
stackhook_t setup_stack; /* prepare stack before argc and argv push */
|
2012-02-13 16:28:04 +01:00
|
|
|
};
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static const struct exec_loaders exec_loaders[] = {
|
2012-05-30 19:34:07 +02:00
|
|
|
{ libexec_load_elf, stack_prepare_elf },
|
2012-04-03 15:52:25 +02:00
|
|
|
{ NULL, NULL }
|
2010-12-10 10:27:56 +01:00
|
|
|
};
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* lock_exec *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void lock_exec(void)
|
2012-02-13 16:28:04 +01:00
|
|
|
{
|
|
|
|
struct fproc *org_fp;
|
|
|
|
struct worker_thread *org_self;
|
|
|
|
|
|
|
|
/* First try to get it right off the bat */
|
|
|
|
if (mutex_trylock(&exec_lock) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
org_fp = fp;
|
|
|
|
org_self = self;
|
|
|
|
|
|
|
|
if (mutex_lock(&exec_lock) != 0)
|
|
|
|
panic("Could not obtain lock on exec");
|
|
|
|
|
|
|
|
fp = org_fp;
|
|
|
|
self = org_self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* unlock_exec *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void unlock_exec(void)
|
2012-02-13 16:28:04 +01:00
|
|
|
{
|
|
|
|
if (mutex_unlock(&exec_lock) != 0)
|
|
|
|
panic("Could not release lock on exec");
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_read_vp *
|
|
|
|
*===========================================================================*/
|
2012-05-30 19:34:07 +02:00
|
|
|
static int get_read_vp(struct vfs_exec_info *execi,
|
|
|
|
char *fullpath, int copyprogname, int sugid, struct lookup *resolve, struct fproc *fp)
|
2012-04-03 15:52:25 +02:00
|
|
|
{
|
|
|
|
/* Make the executable that we want to exec() into the binary pointed
|
|
|
|
* to by 'fullpath.' This function fills in necessary details in the execi
|
|
|
|
* structure, such as opened vnode. It unlocks and releases the vnode if
|
|
|
|
* it was already there. This makes it easy to change the executable
|
|
|
|
* during the exec(), which is often necessary, by calling this function
|
|
|
|
* more than once. This is specifically necessary when we discover the
|
|
|
|
* executable is actually a script or a dynamically linked executable.
|
|
|
|
*/
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* Caller wants to switch vp to the file in 'fullpath.'
|
|
|
|
* unlock and put it first if there is any there.
|
|
|
|
*/
|
|
|
|
if(execi->vp) {
|
|
|
|
unlock_vnode(execi->vp);
|
|
|
|
put_vnode(execi->vp);
|
|
|
|
execi->vp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remember/overwrite the executable name if requested. */
|
|
|
|
if(copyprogname) {
|
|
|
|
char *cp = strrchr(fullpath, '/');
|
|
|
|
if(cp) cp++;
|
|
|
|
else cp = fullpath;
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(execi->args.progname, cp, sizeof(execi->args.progname));
|
2012-05-30 19:34:07 +02:00
|
|
|
execi->args.progname[sizeof(execi->args.progname)-1] = '\0';
|
2012-04-03 15:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open executable */
|
|
|
|
if ((execi->vp = eat_path(resolve, fp)) == NULL)
|
|
|
|
return err_code;
|
|
|
|
|
|
|
|
unlock_vmnt(execi->vmp);
|
|
|
|
|
2012-04-25 14:44:42 +02:00
|
|
|
if (!S_ISREG(execi->vp->v_mode))
|
2012-04-03 15:52:25 +02:00
|
|
|
return ENOEXEC;
|
|
|
|
else if ((r = forbidden(fp, execi->vp, X_BIT)) != OK)
|
|
|
|
return r;
|
|
|
|
else
|
|
|
|
r = req_stat(execi->vp->v_fs_e, execi->vp->v_inode_nr,
|
2012-04-18 15:44:33 +02:00
|
|
|
VFS_PROC_NR, (vir_bytes) &(execi->sb), 0);
|
2012-04-03 15:52:25 +02:00
|
|
|
|
|
|
|
if (r != OK) return r;
|
|
|
|
|
|
|
|
/* If caller wants us to, honour suid/guid mode bits. */
|
|
|
|
if (sugid) {
|
|
|
|
/* Deal with setuid/setgid executables */
|
|
|
|
if (execi->vp->v_mode & I_SET_UID_BIT) {
|
2012-05-30 19:34:07 +02:00
|
|
|
execi->args.new_uid = execi->vp->v_uid;
|
|
|
|
execi->args.allow_setuid = 1;
|
2012-04-03 15:52:25 +02:00
|
|
|
}
|
|
|
|
if (execi->vp->v_mode & I_SET_GID_BIT) {
|
2012-05-30 19:34:07 +02:00
|
|
|
execi->args.new_gid = execi->vp->v_gid;
|
|
|
|
execi->args.allow_setuid = 1;
|
2012-04-03 15:52:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in first chunk of file. */
|
|
|
|
if((r=map_header(execi)) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FAILCHECK(expr) if((r=(expr)) != OK) { goto pm_execfinal; } while(0)
|
|
|
|
#define Get_read_vp(e,f,p,s,rs,fp) do { \
|
|
|
|
r=get_read_vp(&e,f,p,s,rs,fp); if(r != OK) { FAILCHECK(r); } \
|
|
|
|
} while(0)
|
|
|
|
|
2006-05-11 16:57:23 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* pm_exec *
|
|
|
|
*===========================================================================*/
|
2012-04-13 14:50:38 +02:00
|
|
|
int pm_exec(endpoint_t proc_e, vir_bytes path, size_t path_len,
|
2012-04-03 15:52:25 +02:00
|
|
|
vir_bytes frame, size_t frame_len, vir_bytes *pc,
|
|
|
|
vir_bytes *newsp, int user_exec_flags)
|
2006-05-11 16:57:23 +02:00
|
|
|
{
|
|
|
|
/* Perform the execve(name, argv, envp) call. The user library builds a
|
|
|
|
* complete stack image, including pointers, args, environ, etc. The stack
|
2010-06-10 16:04:46 +02:00
|
|
|
* is copied to a buffer inside VFS, and then to the new core image.
|
2006-05-11 16:57:23 +02:00
|
|
|
*/
|
2012-04-03 15:52:25 +02:00
|
|
|
int r, slot;
|
2010-12-10 10:27:56 +01:00
|
|
|
vir_bytes vsp;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
struct fproc *rfp;
|
2012-04-03 15:52:25 +02:00
|
|
|
int extrabase = 0;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
static char mbuf[ARG_MAX]; /* buffer for stack and zeroes */
|
2012-05-30 19:34:07 +02:00
|
|
|
struct vfs_exec_info execi;
|
2010-12-10 10:27:56 +01:00
|
|
|
int i;
|
2012-04-03 15:52:25 +02:00
|
|
|
static char fullpath[PATH_MAX],
|
|
|
|
elf_interpreter[PATH_MAX],
|
|
|
|
finalexec[PATH_MAX];
|
2012-02-13 16:28:04 +01:00
|
|
|
struct lookup resolve;
|
2012-04-03 15:52:25 +02:00
|
|
|
stackhook_t makestack = NULL;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
lock_exec();
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* unset execi values are 0. */
|
|
|
|
memset(&execi, 0, sizeof(execi));
|
|
|
|
|
|
|
|
/* passed from exec() libc code */
|
|
|
|
execi.userflags = user_exec_flags;
|
No more intel/minix segments.
This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.
There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.
No static pre-allocated memory sizes exist any more.
Changes to booting:
. The pre_init.c leaves the kernel and modules exactly as
they were left by the bootloader in physical memory
. The kernel starts running using physical addressing,
loaded at a fixed location given in its linker script by the
bootloader. All code and data in this phase are linked to
this fixed low location.
. It makes a bootstrap pagetable to map itself to a
fixed high location (also in linker script) and jumps to
the high address. All code and data then use this high addressing.
. All code/data symbols linked at the low addresses is prefixed by
an objcopy step with __k_unpaged_*, so that that code cannot
reference highly-linked symbols (which aren't valid yet) or vice
versa (symbols that aren't valid any more).
. The two addressing modes are separated in the linker script by
collecting the unpaged_*.o objects and linking them with low
addresses, and linking the rest high. Some objects are linked
twice, once low and once high.
. The bootstrap phase passes a lot of information (e.g. free memory
list, physical location of the modules, etc.) using the kinfo
struct.
. After this bootstrap the low-linked part is freed.
. The kernel maps in VM into the bootstrap page table so that VM can
begin executing. Its first job is to make page tables for all other
boot processes. So VM runs before RS, and RS gets a fully dynamic,
VM-managed address space. VM gets its privilege info from RS as usual
but that happens after RS starts running.
. Both the kernel loading VM and VM organizing boot processes happen
using the libexec logic. This removes the last reason for VM to
still know much about exec() and vm/exec.c is gone.
Further Implementation:
. All segments are based at 0 and have a 4 GB limit.
. The kernel is mapped in at the top of the virtual address
space so as not to constrain the user processes.
. Processes do not use segments from the LDT at all; there are
no segments in the LDT any more, so no LLDT is needed.
. The Minix segments T/D/S are gone and so none of the
user-space or in-kernel copy functions use them. The copy
functions use a process endpoint of NONE to realize it's
a physical address, virtual otherwise.
. The umap call only makes sense to translate a virtual address
to a physical address now.
. Segments-related calls like newmap and alloc_segments are gone.
. All segments-related translation in VM is gone (vir2map etc).
. Initialization in VM is simpler as no moving around is necessary.
. VM and all other boot processes can be linked wherever they wish
and will be mapped in at the right location by the kernel and VM
respectively.
Other changes:
. The multiboot code is less special: it does not use mb_print
for its diagnostics any more but uses printf() as normal, saving
the output into the diagnostics buffer, only printing to the
screen using the direct print functions if a panic() occurs.
. The multiboot code uses the flexible 'free memory map list'
style to receive the list of free memory if available.
. The kernel determines the memory layout of the processes to
a degree: it tells VM where the kernel starts and ends and
where the kernel wants the top of the process to be. VM then
uses this entire range, i.e. the stack is right at the top,
and mmap()ped bits of memory are placed below that downwards,
and the break grows upwards.
Other Consequences:
. Every process gets its own page table as address spaces
can't be separated any more by segments.
. As all segments are 0-based, there is no distinction between
virtual and linear addresses, nor between userspace and
kernel addresses.
. Less work is done when context switching, leading to a net
performance increase. (8% faster on my machine for 'make servers'.)
. The layout and configuration of the GDT makes sysenter and syscall
possible.
2012-05-07 16:03:35 +02:00
|
|
|
execi.args.stack_high = kinfo.user_sp;
|
2012-05-30 19:34:07 +02:00
|
|
|
execi.args.stack_size = DEFAULT_STACK_LIMIT;
|
2012-04-03 15:52:25 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
okendpt(proc_e, &slot);
|
|
|
|
rfp = fp = &fproc[slot];
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &execi.vmp, &execi.vp);
|
2012-02-13 16:28:04 +01:00
|
|
|
resolve.l_vmnt_lock = VMNT_READ;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
|
|
|
/* Fetch the stack from the user before destroying the old core image. */
|
2012-04-03 15:52:25 +02:00
|
|
|
if (frame_len > ARG_MAX)
|
|
|
|
FAILCHECK(ENOMEM); /* stack too big */
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
r = sys_datacopy(proc_e, (vir_bytes) frame, SELF, (vir_bytes) mbuf,
|
2012-04-13 14:50:38 +02:00
|
|
|
(size_t) frame_len);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
if (r != OK) { /* can't fetch stack (e.g. bad virtual addr) */
|
2012-02-13 16:28:04 +01:00
|
|
|
printf("VFS: pm_exec: sys_datacopy failed\n");
|
2012-04-03 15:52:25 +02:00
|
|
|
FAILCHECK(r);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
/* The default is to keep the original user and group IDs */
|
2012-05-30 19:34:07 +02:00
|
|
|
execi.args.new_uid = rfp->fp_effuid;
|
|
|
|
execi.args.new_gid = rfp->fp_effgid;
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* Get the exec file name. */
|
|
|
|
FAILCHECK(fetch_name(path, path_len, fullpath));
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(finalexec, fullpath, PATH_MAX);
|
2012-04-03 15:52:25 +02:00
|
|
|
|
|
|
|
/* Get_read_vp will return an opened vn in execi.
|
|
|
|
* if necessary it releases the existing vp so we can
|
|
|
|
* switch after we find out what's inside the file.
|
|
|
|
* It reads the start of the file.
|
|
|
|
*/
|
|
|
|
Get_read_vp(execi, fullpath, 1, 1, &resolve, fp);
|
|
|
|
|
|
|
|
/* If this is a script (i.e. has a #!/interpreter line),
|
|
|
|
* retrieve the name of the interpreter and open that
|
|
|
|
* executable instead.
|
|
|
|
*/
|
|
|
|
if(is_script(&execi)) {
|
|
|
|
/* patch_stack will add interpreter name and
|
|
|
|
* args to stack and retrieve the new binary
|
|
|
|
* name into fullpath.
|
|
|
|
*/
|
2012-07-13 18:08:06 +02:00
|
|
|
FAILCHECK(fetch_name(path, path_len, fullpath));
|
2012-04-03 15:52:25 +02:00
|
|
|
FAILCHECK(patch_stack(execi.vp, mbuf, &frame_len, fullpath));
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(finalexec, fullpath, PATH_MAX);
|
2012-04-03 15:52:25 +02:00
|
|
|
Get_read_vp(execi, fullpath, 1, 0, &resolve, fp);
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* If this is a dynamically linked executable, retrieve
|
|
|
|
* the name of that interpreter in elf_interpreter and open that
|
|
|
|
* executable instead. But open the current executable in an
|
|
|
|
* fd for the current process.
|
|
|
|
*/
|
2012-05-30 19:34:07 +02:00
|
|
|
if(elf_has_interpreter(execi.args.hdr, execi.args.hdr_len,
|
2012-04-03 15:52:25 +02:00
|
|
|
elf_interpreter, sizeof(elf_interpreter))) {
|
|
|
|
/* Switch the executable vnode to the interpreter */
|
|
|
|
execi.is_dyn = 1;
|
|
|
|
|
|
|
|
/* The interpreter (loader) needs an fd to the main program,
|
|
|
|
* which is currently in finalexec
|
|
|
|
*/
|
|
|
|
if((r = execi.elf_main_fd = common_open(finalexec, O_RDONLY, 0)) < 0) {
|
|
|
|
printf("VFS: exec: dynamic: open main exec failed %s (%d)\n",
|
|
|
|
fullpath, r);
|
|
|
|
FAILCHECK(r);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
2010-12-10 10:27:56 +01:00
|
|
|
|
2012-08-10 18:27:23 +02:00
|
|
|
/* ld.so is linked at 0, but it can relocate itself; we
|
|
|
|
* want it higher to trap NULL pointer dereferences.
|
|
|
|
*/
|
|
|
|
execi.args.load_offset = 0x10000;
|
|
|
|
|
2012-04-18 16:32:38 +02:00
|
|
|
/* Remember it */
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(execi.execname, finalexec, PATH_MAX);
|
2012-04-18 16:32:38 +02:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* The executable we need to execute first (loader)
|
|
|
|
* is in elf_interpreter, and has to be in fullpath to
|
|
|
|
* be looked up
|
|
|
|
*/
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(fullpath, elf_interpreter, PATH_MAX);
|
2012-04-03 15:52:25 +02:00
|
|
|
Get_read_vp(execi, fullpath, 0, 0, &resolve, fp);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-06-06 19:05:28 +02:00
|
|
|
/* callback functions and data */
|
|
|
|
execi.args.copymem = read_seg;
|
|
|
|
execi.args.clearproc = libexec_clearproc_vm_procctl;
|
|
|
|
execi.args.clearmem = libexec_clear_sys_memset;
|
|
|
|
execi.args.allocmem_prealloc = libexec_alloc_mmap_prealloc;
|
|
|
|
execi.args.allocmem_ondemand = libexec_alloc_mmap_ondemand;
|
2012-05-30 19:34:07 +02:00
|
|
|
execi.args.opaque = &execi;
|
2012-06-06 19:05:28 +02:00
|
|
|
|
2012-05-30 19:34:07 +02:00
|
|
|
execi.args.proc_e = proc_e;
|
|
|
|
execi.args.frame_len = frame_len;
|
2013-02-04 01:49:48 +01:00
|
|
|
execi.args.filesize = execi.vp->v_size;
|
2010-12-10 10:27:56 +01:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
for (i = 0; exec_loaders[i].load_object != NULL; i++) {
|
2012-05-30 19:34:07 +02:00
|
|
|
r = (*exec_loaders[i].load_object)(&execi.args);
|
2010-12-10 10:27:56 +01:00
|
|
|
/* Loaded successfully, so no need to try other loaders */
|
2012-04-03 15:52:25 +02:00
|
|
|
if (r == OK) { makestack = exec_loaders[i].setup_stack; break; }
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
FAILCHECK(r);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2012-06-06 19:05:28 +02:00
|
|
|
/* Inform PM */
|
|
|
|
FAILCHECK(libexec_pm_newexec(proc_e, &execi.args));
|
|
|
|
|
2010-12-10 10:27:56 +01:00
|
|
|
/* Save off PC */
|
2012-05-30 19:34:07 +02:00
|
|
|
*pc = execi.args.pc;
|
2010-12-10 10:27:56 +01:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* call a stack-setup function if this executable type wants it */
|
2012-05-30 19:34:07 +02:00
|
|
|
vsp = execi.args.stack_high - frame_len;
|
2012-04-18 16:32:38 +02:00
|
|
|
if(makestack) FAILCHECK(makestack(&execi, mbuf, &frame_len, &vsp, &extrabase));
|
2012-04-03 15:52:25 +02:00
|
|
|
|
|
|
|
/* Patch up stack and copy it from VFS to new core image. */
|
2012-05-30 19:34:07 +02:00
|
|
|
libexec_patch_ptr(mbuf, vsp + extrabase);
|
2012-04-03 15:52:25 +02:00
|
|
|
FAILCHECK(sys_datacopy(SELF, (vir_bytes) mbuf, proc_e, (vir_bytes) vsp,
|
|
|
|
(phys_bytes)frame_len));
|
2012-05-30 19:34:07 +02:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* Return new stack pointer to caller */
|
|
|
|
*newsp = vsp;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
|
|
|
clo_exec(rfp);
|
|
|
|
|
2012-05-30 19:34:07 +02:00
|
|
|
if (execi.args.allow_setuid) {
|
2011-11-28 11:03:43 +01:00
|
|
|
/* If after loading the image we're still allowed to run with
|
2012-02-13 16:28:04 +01:00
|
|
|
* setuid or setgid, change credentials now */
|
2012-05-30 19:34:07 +02:00
|
|
|
rfp->fp_effuid = execi.args.new_uid;
|
|
|
|
rfp->fp_effgid = execi.args.new_gid;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* Remember the new name of the process */
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(rfp->fp_name, execi.args.progname, PROC_NAME_LEN);
|
2012-04-03 15:52:25 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
pm_execfinal:
|
2012-04-03 15:52:25 +02:00
|
|
|
if (execi.vp != NULL) {
|
|
|
|
unlock_vnode(execi.vp);
|
|
|
|
put_vnode(execi.vp);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
|
|
|
unlock_exec();
|
|
|
|
return(r);
|
2006-05-11 16:57:23 +02:00
|
|
|
}
|
|
|
|
|
2012-05-30 19:34:07 +02:00
|
|
|
static int stack_prepare_elf(struct vfs_exec_info *execi, char *frame, size_t *framelen,
|
2012-04-18 16:32:38 +02:00
|
|
|
vir_bytes *newsp, int *extrabase)
|
2012-04-03 15:52:25 +02:00
|
|
|
{
|
2012-04-18 16:32:38 +02:00
|
|
|
AuxInfo *a, *term;
|
2012-04-03 15:52:25 +02:00
|
|
|
Elf_Ehdr *elf_header;
|
|
|
|
int nulls;
|
|
|
|
char **mysp = (char **) frame,
|
|
|
|
**mysp_end = (char **) ((char *)frame + *framelen);
|
|
|
|
|
|
|
|
if(!execi->is_dyn)
|
|
|
|
return OK;
|
|
|
|
|
2012-05-30 19:34:07 +02:00
|
|
|
assert(execi->args.hdr_len >= sizeof(*elf_header));
|
|
|
|
elf_header = (Elf_Ehdr *) execi->args.hdr;
|
2012-04-03 15:52:25 +02:00
|
|
|
|
|
|
|
/* exec() promises stack space. Now find it. */
|
|
|
|
mysp++; /* skip argc */
|
|
|
|
|
|
|
|
/* find a terminating NULL entry twice: one for argv[], one for envp[]. */
|
|
|
|
for(nulls = 0; nulls < 2; nulls++) {
|
|
|
|
assert(mysp < mysp_end);
|
|
|
|
while(*mysp && mysp < mysp_end) mysp++; /* find terminating NULL */
|
|
|
|
if(mysp >= mysp_end) {
|
|
|
|
printf("VFS: malformed stack for exec()\n");
|
|
|
|
return ENOEXEC;
|
|
|
|
}
|
|
|
|
assert(!*mysp);
|
|
|
|
mysp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Userland provides a fully filled stack frame, with argc, argv, envp
|
|
|
|
* and then all the argv and envp strings; consistent with ELF ABI, except
|
|
|
|
* for a list of Aux vectors that should be between envp points and the
|
|
|
|
* start of the strings.
|
|
|
|
*
|
|
|
|
* It would take some very unpleasant hackery to insert the aux vectors before
|
|
|
|
* the strings, and correct all the pointers, so the exec code in libc makes
|
|
|
|
* space for us first and indicates the fact it did this with this flag.
|
|
|
|
*/
|
|
|
|
if(!(execi->userflags & PMEF_AUXVECTORSPACE)) {
|
|
|
|
char *f = (char *) mysp;
|
|
|
|
int remain;
|
|
|
|
vir_bytes extrabytes = sizeof(*a) * PMEF_AUXVECTORS;
|
|
|
|
|
|
|
|
/* Create extrabytes more space */
|
|
|
|
remain = *framelen - (int)(f - frame);
|
|
|
|
if(*framelen + extrabytes >= ARG_MAX)
|
|
|
|
return ENOMEM;
|
|
|
|
*framelen += extrabytes;
|
2012-04-18 16:32:38 +02:00
|
|
|
*newsp -= extrabytes;
|
2012-04-03 15:52:25 +02:00
|
|
|
*extrabase += extrabytes;
|
|
|
|
memmove(f+extrabytes, f, remain);
|
|
|
|
memset(f, 0, extrabytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ok, what mysp points to now we can use for the aux vectors. */
|
|
|
|
a = (AuxInfo *) mysp;
|
|
|
|
#define AUXINFO(type, value) \
|
|
|
|
{ assert((char *) a < (char *) mysp_end); a->a_type = type; a->a_v = value; a++; }
|
|
|
|
#if 0
|
|
|
|
AUXINFO(AT_PHENT, elf_header->e_phentsize);
|
|
|
|
AUXINFO(AT_PHNUM, elf_header->e_phnum);
|
|
|
|
#endif
|
2012-05-30 19:34:07 +02:00
|
|
|
AUXINFO(AT_BASE, execi->args.load_base);
|
|
|
|
AUXINFO(AT_ENTRY, execi->args.pc);
|
2012-04-03 15:52:25 +02:00
|
|
|
AUXINFO(AT_PAGESZ, PAGE_SIZE);
|
|
|
|
AUXINFO(AT_EXECFD, execi->elf_main_fd);
|
|
|
|
|
2012-04-18 16:32:38 +02:00
|
|
|
/* This is where we add the AT_NULL */
|
|
|
|
term = a;
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* Always terminate with AT_NULL */
|
|
|
|
AUXINFO(AT_NULL, 0);
|
|
|
|
|
2012-04-18 16:32:38 +02:00
|
|
|
/* Empty space starts here, if any. */
|
|
|
|
if((execi->userflags & PMEF_EXECNAMESPACE1)
|
|
|
|
&& strlen(execi->execname) < PMEF_EXECNAMELEN1) {
|
|
|
|
char *spacestart;
|
|
|
|
vir_bytes userp;
|
|
|
|
|
|
|
|
/* Make space for the real closing AT_NULL entry. */
|
|
|
|
AUXINFO(AT_NULL, 0);
|
|
|
|
|
|
|
|
/* Empty space starts here; we can put the name here. */
|
|
|
|
spacestart = (char *) a;
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(spacestart, execi->execname, PATH_MAX);
|
2012-04-18 16:32:38 +02:00
|
|
|
|
|
|
|
/* What will the address of the string for the user be */
|
|
|
|
userp = *newsp + (spacestart-frame);
|
|
|
|
|
|
|
|
/* Move back to where the AT_NULL is */
|
|
|
|
a = term;
|
|
|
|
AUXINFO(AT_SUN_EXECNAME, userp);
|
|
|
|
AUXINFO(AT_NULL, 0);
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* is_script *
|
|
|
|
*===========================================================================*/
|
2012-05-30 19:34:07 +02:00
|
|
|
static int is_script(struct vfs_exec_info *execi)
|
2006-05-11 16:57:23 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Is Interpreted script? */
|
2012-05-30 19:34:07 +02:00
|
|
|
assert(execi->args.hdr != NULL);
|
2006-05-11 16:57:23 +02:00
|
|
|
|
2012-05-30 19:34:07 +02:00
|
|
|
return(execi->args.hdr[0] == '#' && execi->args.hdr[1] == '!'
|
|
|
|
&& execi->args.hdr_len >= 2);
|
2006-05-11 16:57:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* patch_stack *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int patch_stack(vp, stack, stk_bytes, path)
|
2012-02-13 16:28:04 +01:00
|
|
|
struct vnode *vp; /* pointer for open script file */
|
|
|
|
char stack[ARG_MAX]; /* pointer to stack image within VFS */
|
2012-04-13 14:50:38 +02:00
|
|
|
size_t *stk_bytes; /* size of initial stack */
|
2012-02-13 16:28:04 +01:00
|
|
|
char path[PATH_MAX]; /* path to script file */
|
2006-05-11 16:57:23 +02:00
|
|
|
{
|
|
|
|
/* Patch the argument vector to include the path name of the script to be
|
|
|
|
* interpreted, and all strings on the #! line. Returns the path name of
|
|
|
|
* the interpreter.
|
|
|
|
*/
|
|
|
|
enum { INSERT=FALSE, REPLACE=TRUE };
|
2006-10-25 15:40:36 +02:00
|
|
|
int n, r;
|
2006-05-11 16:57:23 +02:00
|
|
|
off_t pos;
|
|
|
|
char *sp, *interp = NULL;
|
2007-08-07 14:52:47 +02:00
|
|
|
u64_t new_pos;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
unsigned int cum_io;
|
2006-10-25 15:40:36 +02:00
|
|
|
char buf[_MAX_BLOCK_SIZE];
|
2006-05-11 16:57:23 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Make 'path' the new argv[0]. */
|
|
|
|
if (!insert_arg(stack, stk_bytes, path, REPLACE)) return(ENOMEM);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
pos = 0; /* Read from the start of the file */
|
|
|
|
|
|
|
|
/* Issue request */
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
r = req_readwrite(vp->v_fs_e, vp->v_inode_nr, cvul64(pos), READING,
|
2012-02-13 16:28:04 +01:00
|
|
|
VFS_PROC_NR, buf, _MAX_BLOCK_SIZE, &new_pos, &cum_io);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
if (r != OK) return(r);
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
n = vp->v_size;
|
2007-08-07 14:52:47 +02:00
|
|
|
if (n > _MAX_BLOCK_SIZE)
|
|
|
|
n = _MAX_BLOCK_SIZE;
|
2006-10-25 15:40:36 +02:00
|
|
|
if (n < 2) return ENOEXEC;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
sp = &(buf[2]); /* just behind the #! */
|
2006-05-11 16:57:23 +02:00
|
|
|
n -= 2;
|
2006-10-25 15:40:36 +02:00
|
|
|
if (n > PATH_MAX) n = PATH_MAX;
|
2006-05-11 16:57:23 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Use the 'path' variable for temporary storage */
|
|
|
|
memcpy(path, sp, n);
|
2006-05-11 16:57:23 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
if ((sp = memchr(path, '\n', n)) == NULL) /* must be a proper line */
|
2006-05-11 16:57:23 +02:00
|
|
|
return(ENOEXEC);
|
|
|
|
|
|
|
|
/* Move sp backwards through script[], prepending each string to stack. */
|
|
|
|
for (;;) {
|
|
|
|
/* skip spaces behind argument. */
|
2012-02-13 16:28:04 +01:00
|
|
|
while (sp > path && (*--sp == ' ' || *sp == '\t')) {}
|
|
|
|
if (sp == path) break;
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
sp[1] = 0;
|
|
|
|
/* Move to the start of the argument. */
|
2012-02-13 16:28:04 +01:00
|
|
|
while (sp > path && sp[-1] != ' ' && sp[-1] != '\t') --sp;
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
interp = sp;
|
2010-12-15 15:43:59 +01:00
|
|
|
if (!insert_arg(stack, stk_bytes, sp, INSERT)) {
|
|
|
|
printf("VFS: patch_stack: insert_arg failed\n");
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
2006-05-11 16:57:23 +02:00
|
|
|
}
|
|
|
|
|
2011-12-20 16:20:32 +01:00
|
|
|
if(!interp)
|
|
|
|
return ENOEXEC;
|
|
|
|
|
2006-05-11 16:57:23 +02:00
|
|
|
/* Round *stk_bytes up to the size of a pointer for alignment contraints. */
|
|
|
|
*stk_bytes= ((*stk_bytes + PTRSIZE - 1) / PTRSIZE) * PTRSIZE;
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
if (interp != path)
|
|
|
|
memmove(path, interp, strlen(interp)+1);
|
2006-05-11 16:57:23 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* insert_arg *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int insert_arg(
|
2010-12-10 10:27:56 +01:00
|
|
|
char stack[ARG_MAX], /* pointer to stack image within PM */
|
2012-04-13 14:50:38 +02:00
|
|
|
size_t *stk_bytes, /* size of initial stack */
|
2010-12-10 10:27:56 +01:00
|
|
|
char *arg, /* argument to prepend/replace as new argv[0] */
|
|
|
|
int replace
|
|
|
|
)
|
2006-05-11 16:57:23 +02:00
|
|
|
{
|
|
|
|
/* Patch the stack so that arg will become argv[0]. Be careful, the stack may
|
|
|
|
* be filled with garbage, although it normally looks like this:
|
|
|
|
* nargs argv[0] ... argv[nargs-1] NULL envp[0] ... NULL
|
|
|
|
* followed by the strings "pointed" to by the argv[i] and the envp[i]. The
|
|
|
|
* pointers are really offsets from the start of stack.
|
|
|
|
* Return true iff the operation succeeded.
|
|
|
|
*/
|
2012-04-02 17:16:44 +02:00
|
|
|
int offset;
|
|
|
|
vir_bytes a0, a1;
|
2012-04-13 14:50:38 +02:00
|
|
|
size_t old_bytes = *stk_bytes;
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
/* Prepending arg adds at least one string and a zero byte. */
|
|
|
|
offset = strlen(arg) + 1;
|
|
|
|
|
|
|
|
a0 = (int) ((char **) stack)[1]; /* argv[0] */
|
|
|
|
if (a0 < 4 * PTRSIZE || a0 >= old_bytes) return(FALSE);
|
|
|
|
|
|
|
|
a1 = a0; /* a1 will point to the strings to be moved */
|
|
|
|
if (replace) {
|
|
|
|
/* Move a1 to the end of argv[0][] (argv[1] if nargs > 1). */
|
|
|
|
do {
|
|
|
|
if (a1 == old_bytes) return(FALSE);
|
|
|
|
--offset;
|
|
|
|
} while (stack[a1++] != 0);
|
|
|
|
} else {
|
|
|
|
offset += PTRSIZE; /* new argv[0] needs new pointer in argv[] */
|
|
|
|
a0 += PTRSIZE; /* location of new argv[0][]. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stack will grow by offset bytes (or shrink by -offset bytes) */
|
|
|
|
if ((*stk_bytes += offset) > ARG_MAX) return(FALSE);
|
|
|
|
|
|
|
|
/* Reposition the strings by offset bytes */
|
|
|
|
memmove(stack + a1 + offset, stack + a1, old_bytes - a1);
|
|
|
|
|
2012-07-13 18:08:06 +02:00
|
|
|
strlcpy(stack + a0, arg, PATH_MAX); /* Put arg in the new space. */
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
if (!replace) {
|
|
|
|
/* Make space for a new argv[0]. */
|
|
|
|
memmove(stack + 2 * PTRSIZE, stack + 1 * PTRSIZE, a0 - 2 * PTRSIZE);
|
|
|
|
|
|
|
|
((char **) stack)[0]++; /* nargs++; */
|
|
|
|
}
|
|
|
|
/* Now patch up argv[] and envp[] by offset. */
|
2012-05-30 19:34:07 +02:00
|
|
|
libexec_patch_ptr(stack, (vir_bytes) offset);
|
2006-05-11 16:57:23 +02:00
|
|
|
((char **) stack)[1] = (char *) a0; /* set argv[0] correctly */
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* read_seg *
|
|
|
|
*===========================================================================*/
|
2012-05-30 19:34:07 +02:00
|
|
|
static int read_seg(struct exec_info *execi, off_t off, off_t seg_addr, size_t seg_bytes)
|
2006-05-11 16:57:23 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The byte count on read is usually smaller than the segment count, because
|
|
|
|
* a segment is padded out to a click multiple, and the data segment is only
|
|
|
|
* partially initialized.
|
|
|
|
*/
|
2006-10-25 15:40:36 +02:00
|
|
|
int r;
|
2007-08-07 14:52:47 +02:00
|
|
|
u64_t new_pos;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
unsigned int cum_io;
|
2012-05-30 19:34:07 +02:00
|
|
|
struct vnode *vp = ((struct vfs_exec_info *) execi->opaque)->vp;
|
2010-12-10 10:27:56 +01:00
|
|
|
|
2006-05-11 16:57:23 +02:00
|
|
|
/* Make sure that the file is big enough */
|
2012-04-02 17:16:44 +02:00
|
|
|
if (off + seg_bytes > LONG_MAX) return(EIO);
|
|
|
|
if ((unsigned long) vp->v_size < off+seg_bytes) return(EIO);
|
2007-08-07 14:52:47 +02:00
|
|
|
|
No more intel/minix segments.
This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.
There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.
No static pre-allocated memory sizes exist any more.
Changes to booting:
. The pre_init.c leaves the kernel and modules exactly as
they were left by the bootloader in physical memory
. The kernel starts running using physical addressing,
loaded at a fixed location given in its linker script by the
bootloader. All code and data in this phase are linked to
this fixed low location.
. It makes a bootstrap pagetable to map itself to a
fixed high location (also in linker script) and jumps to
the high address. All code and data then use this high addressing.
. All code/data symbols linked at the low addresses is prefixed by
an objcopy step with __k_unpaged_*, so that that code cannot
reference highly-linked symbols (which aren't valid yet) or vice
versa (symbols that aren't valid any more).
. The two addressing modes are separated in the linker script by
collecting the unpaged_*.o objects and linking them with low
addresses, and linking the rest high. Some objects are linked
twice, once low and once high.
. The bootstrap phase passes a lot of information (e.g. free memory
list, physical location of the modules, etc.) using the kinfo
struct.
. After this bootstrap the low-linked part is freed.
. The kernel maps in VM into the bootstrap page table so that VM can
begin executing. Its first job is to make page tables for all other
boot processes. So VM runs before RS, and RS gets a fully dynamic,
VM-managed address space. VM gets its privilege info from RS as usual
but that happens after RS starts running.
. Both the kernel loading VM and VM organizing boot processes happen
using the libexec logic. This removes the last reason for VM to
still know much about exec() and vm/exec.c is gone.
Further Implementation:
. All segments are based at 0 and have a 4 GB limit.
. The kernel is mapped in at the top of the virtual address
space so as not to constrain the user processes.
. Processes do not use segments from the LDT at all; there are
no segments in the LDT any more, so no LLDT is needed.
. The Minix segments T/D/S are gone and so none of the
user-space or in-kernel copy functions use them. The copy
functions use a process endpoint of NONE to realize it's
a physical address, virtual otherwise.
. The umap call only makes sense to translate a virtual address
to a physical address now.
. Segments-related calls like newmap and alloc_segments are gone.
. All segments-related translation in VM is gone (vir2map etc).
. Initialization in VM is simpler as no moving around is necessary.
. VM and all other boot processes can be linked wherever they wish
and will be mapped in at the right location by the kernel and VM
respectively.
Other changes:
. The multiboot code is less special: it does not use mb_print
for its diagnostics any more but uses printf() as normal, saving
the output into the diagnostics buffer, only printing to the
screen using the direct print functions if a panic() occurs.
. The multiboot code uses the flexible 'free memory map list'
style to receive the list of free memory if available.
. The kernel determines the memory layout of the processes to
a degree: it tells VM where the kernel starts and ends and
where the kernel wants the top of the process to be. VM then
uses this entire range, i.e. the stack is right at the top,
and mmap()ped bits of memory are placed below that downwards,
and the break grows upwards.
Other Consequences:
. Every process gets its own page table as address spaces
can't be separated any more by segments.
. As all segments are 0-based, there is no distinction between
virtual and linear addresses, nor between userspace and
kernel addresses.
. Less work is done when context switching, leading to a net
performance increase. (8% faster on my machine for 'make servers'.)
. The layout and configuration of the GDT makes sysenter and syscall
possible.
2012-05-07 16:03:35 +02:00
|
|
|
if ((r = req_readwrite(vp->v_fs_e, vp->v_inode_nr, cvul64(off), READING,
|
|
|
|
execi->proc_e, (char*)seg_addr, seg_bytes,
|
|
|
|
&new_pos, &cum_io)) != OK) {
|
|
|
|
printf("VFS: read_seg: req_readwrite failed (data)\n");
|
|
|
|
return(r);
|
|
|
|
}
|
2012-02-13 16:28:04 +01:00
|
|
|
|
No more intel/minix segments.
This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.
There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.
No static pre-allocated memory sizes exist any more.
Changes to booting:
. The pre_init.c leaves the kernel and modules exactly as
they were left by the bootloader in physical memory
. The kernel starts running using physical addressing,
loaded at a fixed location given in its linker script by the
bootloader. All code and data in this phase are linked to
this fixed low location.
. It makes a bootstrap pagetable to map itself to a
fixed high location (also in linker script) and jumps to
the high address. All code and data then use this high addressing.
. All code/data symbols linked at the low addresses is prefixed by
an objcopy step with __k_unpaged_*, so that that code cannot
reference highly-linked symbols (which aren't valid yet) or vice
versa (symbols that aren't valid any more).
. The two addressing modes are separated in the linker script by
collecting the unpaged_*.o objects and linking them with low
addresses, and linking the rest high. Some objects are linked
twice, once low and once high.
. The bootstrap phase passes a lot of information (e.g. free memory
list, physical location of the modules, etc.) using the kinfo
struct.
. After this bootstrap the low-linked part is freed.
. The kernel maps in VM into the bootstrap page table so that VM can
begin executing. Its first job is to make page tables for all other
boot processes. So VM runs before RS, and RS gets a fully dynamic,
VM-managed address space. VM gets its privilege info from RS as usual
but that happens after RS starts running.
. Both the kernel loading VM and VM organizing boot processes happen
using the libexec logic. This removes the last reason for VM to
still know much about exec() and vm/exec.c is gone.
Further Implementation:
. All segments are based at 0 and have a 4 GB limit.
. The kernel is mapped in at the top of the virtual address
space so as not to constrain the user processes.
. Processes do not use segments from the LDT at all; there are
no segments in the LDT any more, so no LLDT is needed.
. The Minix segments T/D/S are gone and so none of the
user-space or in-kernel copy functions use them. The copy
functions use a process endpoint of NONE to realize it's
a physical address, virtual otherwise.
. The umap call only makes sense to translate a virtual address
to a physical address now.
. Segments-related calls like newmap and alloc_segments are gone.
. All segments-related translation in VM is gone (vir2map etc).
. Initialization in VM is simpler as no moving around is necessary.
. VM and all other boot processes can be linked wherever they wish
and will be mapped in at the right location by the kernel and VM
respectively.
Other changes:
. The multiboot code is less special: it does not use mb_print
for its diagnostics any more but uses printf() as normal, saving
the output into the diagnostics buffer, only printing to the
screen using the direct print functions if a panic() occurs.
. The multiboot code uses the flexible 'free memory map list'
style to receive the list of free memory if available.
. The kernel determines the memory layout of the processes to
a degree: it tells VM where the kernel starts and ends and
where the kernel wants the top of the process to be. VM then
uses this entire range, i.e. the stack is right at the top,
and mmap()ped bits of memory are placed below that downwards,
and the break grows upwards.
Other Consequences:
. Every process gets its own page table as address spaces
can't be separated any more by segments.
. As all segments are 0-based, there is no distinction between
virtual and linear addresses, nor between userspace and
kernel addresses.
. Less work is done when context switching, leading to a net
performance increase. (8% faster on my machine for 'make servers'.)
. The layout and configuration of the GDT makes sysenter and syscall
possible.
2012-05-07 16:03:35 +02:00
|
|
|
if (r == OK && cum_io != seg_bytes)
|
|
|
|
printf("VFS: read_seg segment has not been read properly\n");
|
2010-12-10 10:27:56 +01:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(r);
|
2006-05-11 16:57:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* clo_exec *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void clo_exec(struct fproc *rfp)
|
2006-05-11 16:57:23 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Files can be marked with the FD_CLOEXEC bit (in fp->fp_cloexec).
|
2006-05-11 16:57:23 +02:00
|
|
|
*/
|
2006-06-27 18:47:35 +02:00
|
|
|
int i;
|
2006-05-11 16:57:23 +02:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
/* Check the file desriptors one by one for presence of FD_CLOEXEC. */
|
|
|
|
for (i = 0; i < OPEN_MAX; i++)
|
|
|
|
if ( FD_ISSET(i, &rfp->fp_cloexec_set))
|
2006-06-27 18:47:35 +02:00
|
|
|
(void) close_fd(rfp, i);
|
2006-05-11 16:57:23 +02:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* map_header *
|
|
|
|
*===========================================================================*/
|
2012-05-30 19:34:07 +02:00
|
|
|
static int map_header(struct vfs_exec_info *execi)
|
2010-12-10 10:27:56 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
u64_t new_pos;
|
|
|
|
unsigned int cum_io;
|
|
|
|
off_t pos;
|
2012-04-03 15:52:25 +02:00
|
|
|
static char hdr[PAGE_SIZE]; /* Assume that header is not larger than a page */
|
2010-12-10 10:27:56 +01:00
|
|
|
|
|
|
|
pos = 0; /* Read from the start of the file */
|
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* How much is sensible to read */
|
2012-05-30 19:34:07 +02:00
|
|
|
execi->args.hdr_len = MIN(execi->vp->v_size, sizeof(hdr));
|
|
|
|
execi->args.hdr = hdr;
|
2012-04-03 15:52:25 +02:00
|
|
|
|
|
|
|
r = req_readwrite(execi->vp->v_fs_e, execi->vp->v_inode_nr,
|
|
|
|
cvul64(pos), READING, VFS_PROC_NR, hdr,
|
2012-05-30 19:34:07 +02:00
|
|
|
execi->args.hdr_len, &new_pos, &cum_io);
|
2010-12-15 15:43:59 +01:00
|
|
|
if (r != OK) {
|
|
|
|
printf("VFS: exec: map_header: req_readwrite failed\n");
|
|
|
|
return(r);
|
|
|
|
}
|
2010-12-10 10:27:56 +01:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|