Merge branch 'master' into net-dev
[akaros.git] / kern / include / env.h
1 /* See COPYRIGHT for copyright information. */
2
3 #ifndef ROS_KERN_ENV_H
4 #define ROS_KERN_ENV_H
5
6 #include <ros/env.h>
7 #include <ros/error.h>
8 #include <arch/arch.h>
9
10 extern env_t *COUNT(NENV) envs;         // All environments
11 extern atomic_t num_envs;               // Number of envs
12 extern env_t* NORACE curenvs[MAX_NUM_CPUS];
13
14 LIST_HEAD(env_list, Env);               // Declares 'struct env_list'
15 typedef struct env_list env_list_t;
16
17 void    env_init(void);
18 void    env_init_trapframe(env_t* e);
19 void    env_set_program_counter(env_t* e, uintptr_t pc);
20 void    env_push_ancillary_state(env_t* e);
21 void    env_pop_ancillary_state(env_t* e);
22 int     env_alloc(env_t **e, envid_t parent_id);
23 void    env_free(env_t *SAFE e);
24 void    env_user_mem_free(env_t* e);
25 error_t env_incref(env_t* e);
26 void    env_decref(env_t *SAFE e);
27 env_t*  env_create(uint8_t *COUNT(size) binary, size_t size);
28 void    (IN_HANDLER env_destroy)(env_t *SAFE e);        // Does not return if e == curenv
29 // Temporary scheduler function
30 void    schedule(void);
31
32 int     envid2env(envid_t envid, env_t **env_store, bool checkperm);
33 // The following three functions do not return
34 void    (IN_HANDLER env_run)(env_t *e) __attribute__((noreturn));
35 void    env_pop_tf(trapframe_t *tf) __attribute__((noreturn));
36
37
38 /* Helper handler for smp_call to dispatch jobs to other cores */
39 void run_env_handler(trapframe_t *tf, void* data);
40
41 #define ENV_CREATE(x)                   ({                                             \
42         extern uint8_t _binary_obj_user_apps_##x##_start[],                        \
43                 _binary_obj_user_apps_##x##_size[];                                    \
44         env_create(_binary_obj_user_apps_##x##_start,                              \
45                 (int)_binary_obj_user_apps_##x##_size);                                \
46 })
47
48 #endif // !ROS_KERN_ENV_H