akaros/kern/include/env.h
<<
>>
Prefs
   1/* See COPYRIGHT for copyright information. */
   2
   3#pragma once
   4/* Note that the old include/ros/env.h is merged into this file */
   5
   6#include <ros/memlayout.h>
   7#include <ros/syscall.h>
   8#include <ros/sysevent.h>
   9#include <ros/procinfo.h>
  10#include <error.h>
  11#include <ros/procdata.h>
  12#include <ros/procinfo.h>
  13#include <ros/resource.h>
  14#include <trap.h>
  15#include <ros/common.h>
  16#include <arch/arch.h>
  17#include <sys/queue.h>
  18#include <atomic.h>
  19#include <mm.h>
  20#include <schedule.h>
  21#include <devalarm.h>
  22#include <ns.h>
  23#include <arch/vmm/vmm.h>
  24#include <arch/pci.h>
  25
  26TAILQ_HEAD(vcore_tailq, vcore);
  27/* 'struct proc_list' declared in sched.h (not ideal...) */
  28
  29struct username {
  30        char name[128];
  31        spinlock_t name_lock;
  32};
  33void __set_username(struct username *u, char *name);
  34void set_username(struct username *u, char *name);
  35
  36#define PROC_PROGNAME_SZ 20
  37// TODO: clean this up.
  38struct proc {
  39        TAILQ_ENTRY(proc) proc_arsc_link;
  40        TAILQ_ENTRY(proc) sibling_link;
  41        spinlock_t proc_lock;
  42        struct user_context scp_ctx; /* context for an SCP. TODO: move to vc0 */
  43        struct username user;
  44
  45        /* This is effectively a (potentially short) version of argv[0].
  46         */
  47        char progname[PROC_PROGNAME_SZ];
  48
  49        /* This is the full path of the binary which the current proc structure
  50         * is tracking.
  51         */
  52        char *binary_path;
  53
  54        pid_t pid;
  55        /* Tempting to add a struct proc *parent, but we'd need to protect the
  56         * use of that reference from concurrent parent-death (letting init
  57         * inherit children, etc), which is basically what we do when we do
  58         * pid2proc.  If we do add *parent, it'll be a weak ref, and you'll need
  59         * to lock the child to kref_get or to remove the pointer. */
  60        pid_t ppid;             /* parent's pid, not a reference */
  61        struct proc_list children; /* protected by the proc lock for now */
  62        int exitcode;           /* exit() param or main() return value */
  63        struct cond_var child_wait; /* signal for dying or o/w waitable child */
  64        uint32_t state;                         // Status of the process
  65        struct kref p_kref;     /* Refcnt */
  66        uint32_t env_flags;
  67        /* Lists of vcores */
  68        struct vcore_tailq online_vcs;
  69        struct vcore_tailq bulk_preempted_vcs;
  70        struct vcore_tailq inactive_vcs;
  71        /* Scheduler mgmt (info, data, whatever) */
  72        struct sched_proc_data ksched_data;
  73
  74        /* The args_base pointer is a user pointer which points to the base of
  75         * the executable boot block (where args, environment, aux vectors, ...)
  76         * are stored.
  77         */
  78        void *args_base;
  79
  80        // Address space
  81        pgdir_t env_pgdir;              // Kernel virtual address of page dir
  82        physaddr_t env_cr3;             // Physical address of page dir
  83        spinlock_t vmr_lock;            /* Protects VMR tree (mem mgmt) */
  84        spinlock_t pte_lock;            /* Protects page tables (mem mgmt) */
  85        struct vmr_tailq vm_regions;
  86        int vmr_history;
  87
  88        // Per process info and data pages
  89        procinfo_t *procinfo;       // KVA of per-process shared info table (RO)
  90        procdata_t *procdata;       // KVA of per-process shared data table (RW)
  91
  92        // The backring pointers for processing asynchronous system calls from
  93        // the user Note this is the actual backring, not a pointer to it
  94        // somewhere else
  95        syscall_back_ring_t syscallbackring;
  96
  97        // The front ring pointers for pushing asynchronous system events out to
  98        // the user Note this is the actual frontring, not a pointer to it
  99        // somewhere else
 100        sysevent_front_ring_t syseventfrontring;
 101
 102        /* Filesystem info */
 103        int                     umask;
 104        struct fd_table         open_files;
 105        struct pgrp             *pgrp;
 106        struct chan             *slash;
 107        struct chan             *dot;
 108
 109
 110        /* UCQ hashlocks */
 111        struct hashlock         *ucq_hashlock;
 112        struct small_hashlock   ucq_hl_noref;   /* don't reference directly */
 113        /* For devalarm */
 114        struct proc_alarm_set   alarmset;
 115        struct cv_lookup_tailq  abortable_sleepers;
 116        spinlock_t              abort_list_lock;
 117
 118        /* VMMCP */
 119        struct vmm vmm;
 120
 121        struct strace           *strace;
 122        struct pcidev_tq        pci_devices; /* for device passthru */
 123        TAILQ_ENTRY(proc)       iommu_link;
 124};
 125
 126/* Til we remove all Env references */
 127#define Env proc
 128typedef struct proc env_t;
 129
 130/* Process Flags */
 131#define PROC_TRANSITION_TO_M    (1 << 0)
 132#define PROC_TRACED             (1 << 1)
 133
 134extern atomic_t num_envs;       // Number of envs
 135
 136int env_setup_vm(env_t *e);
 137void env_user_mem_free(env_t* e, void* start, size_t len);
 138void env_pagetable_free(env_t* e);
 139
 140typedef int (*mem_walk_callback_t)(env_t* e, pte_t pte, void* va, void* arg);
 141int env_user_mem_walk(env_t* e, void* start, size_t len,
 142                      mem_walk_callback_t callback, void* arg);
 143
 144static inline void set_traced_proc(struct proc *p, bool traced)
 145{
 146        if (traced)
 147                p->env_flags |= PROC_TRACED;
 148        else
 149                p->env_flags &= ~PROC_TRACED;
 150}
 151
 152static inline bool is_traced_proc(const struct proc *p)
 153{
 154        return (p->env_flags & PROC_TRACED) != 0;
 155}
 156