Process management work, yield syscall
[akaros.git] / 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 <arch/x86.h>
7 #include <ros/env.h>
8 #include <ros/error.h>
9
10 extern env_t *COUNT(NENV) envs;         // All environments
11 extern uint32_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 int             env_alloc(env_t **e, envid_t parent_id);
19 void    env_free(env_t *SAFE e);
20 error_t env_incref(env_t* e);
21 void    env_decref(env_t *SAFE e);
22 env_t*  env_create(uint8_t *COUNT(size) binary, size_t size);
23 void    (IN_HANDLER env_destroy)(env_t *SAFE e);        // Does not return if e == curenv
24 // Temporary scheduler function
25 void    schedule(void);
26
27 int     envid2env(envid_t envid, env_t **env_store, bool checkperm);
28 // The following three functions do not return
29 void    (IN_HANDLER env_run)(env_t *e) __attribute__((noreturn));
30 void    env_pop_tf(trapframe_t *tf) __attribute__((noreturn));
31 void    env_pop_tf_sysexit(trapframe_t *tf) __attribute__((noreturn));
32
33
34 /* Helper handler for smp_call to dispatch jobs to other cores */
35 void run_env_handler(trapframe_t *tf, void* data);
36
37 #define ENV_CREATE(x)                   ({                                             \
38         extern uint8_t _binary_obj_user_apps_##x##_start[],                        \
39                 _binary_obj_user_apps_##x##_size[];                                    \
40         env_create(_binary_obj_user_apps_##x##_start,                              \
41                 (int)_binary_obj_user_apps_##x##_size);                                \
42 })
43
44 #endif // !ROS_KERN_ENV_H