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