* All things processes! As we move away from the old envs to processes,
* we'll move things into here that are designed for multicore processes. */
-#ifndef ROS_KERN_PROCESS_H
-#define ROS_KERN_PROCESS_H
+#pragma once
#include <ros/common.h>
#include <ros/event.h>
* a while. Possibly even using its local APIC timer.
* - A process in an _M state will be informed about changes to its state, e.g.,
* will have a handler run in the event of a page fault
+ *
+ * DYING vs. DYING_ABORT:
+ * - DYING is the initial stage when a process is dying, but before all of its
+ * syscalls should abort. At this point, we start closing FDs and blocking
+ * certain new operations.
+ * - DYING_ABORT is after all FDs were closed and all outstanding syscalls are
+ * aborted.
*/
#define PROC_CREATED 0x01
#define PROC_RUNNING_S 0x04
#define PROC_WAITING 0x08 // can split out to INT and UINT
#define PROC_DYING 0x10
-#define PROC_RUNNABLE_M 0x20
-#define PROC_RUNNING_M 0x40
-
-#define procstate2str(state) ((state)==PROC_CREATED ? "CREATED" : \
- (state)==PROC_RUNNABLE_S ? "RUNNABLE_S" : \
- (state)==PROC_RUNNING_S ? "RUNNING_S" : \
- (state)==PROC_WAITING ? "WAITING" : \
- (state)==PROC_DYING ? "DYING" : \
- (state)==PROC_RUNNABLE_M ? "RUNNABLE_M" : \
- (state)==PROC_RUNNING_M ? "RUNNING_M" : \
- "UNKNOWN")
+#define PROC_DYING_ABORT 0x20
+#define PROC_RUNNABLE_M 0x40
+#define PROC_RUNNING_M 0x80
+
+#define procstate2str(state) ((state) == PROC_CREATED ? "CREATED" : \
+ (state) == PROC_RUNNABLE_S ? "RUNNABLE_S" : \
+ (state) == PROC_RUNNING_S ? "RUNNING_S" : \
+ (state) == PROC_WAITING ? "WAITING" : \
+ (state) == PROC_DYING ? "DYING" : \
+ (state) == PROC_DYING_ABORT ? "DYING_ABORT" : \
+ (state) == PROC_RUNNABLE_M ? "RUNNABLE_M" : \
+ (state) == PROC_RUNNING_M ? "RUNNING_M" : \
+ "UNKNOWN")
+
+#define DEFAULT_PROGNAME ""
#include <env.h>
+static bool proc_is_dying(struct proc *p)
+{
+ return (p->state == PROC_DYING) || (p->state == PROC_DYING_ABORT);
+}
+
+struct process_set {
+ size_t num_processes;
+ size_t size;
+ struct proc **procs;
+};
+
/* Can use a htable iterator to iterate through all active procs */
extern struct hashtable *pid_hash;
extern spinlock_t pid_hash_lock;
/* Initialization */
void proc_init(void);
+void proc_set_username(struct proc *p, char *name);
+void proc_inherit_parent_username(struct proc *child, struct proc *parent);
+void proc_set_progname(struct proc *p, char *name);
+void proc_replace_binary_path(struct proc *p, char *path);
+void proc_init_procinfo(struct proc* p);
+void proc_init_procdata(struct proc* p);
/* Process management: */
-error_t proc_alloc(struct proc **pp, struct proc *parent);
+struct proc *pid_nth(unsigned int n);
+error_t proc_alloc(struct proc **pp, struct proc *parent, int flags);
void __proc_ready(struct proc *p);
struct proc *proc_create(struct file *prog, char **argv, char **envp);
-int __proc_set_state(struct proc *p, uint32_t state) WRITES(p->state);
+int __proc_set_state(struct proc *p, uint32_t state);
struct proc *pid2proc(pid_t pid);
-bool proc_controls(struct proc *SAFE actor, struct proc *SAFE target);
+bool proc_controls(struct proc *actor, struct proc *target);
void proc_incref(struct proc *p, unsigned int val);
void proc_decref(struct proc *p);
void proc_run_s(struct proc *p);
void __proc_run_m(struct proc *p);
+void __proc_startcore(struct proc *p, struct user_context *ctx);
void proc_restartcore(void);
void proc_destroy(struct proc *p);
void proc_signal_parent(struct proc *child);
int __proc_disown_child(struct proc *parent, struct proc *child);
int proc_change_to_m(struct proc *p);
-void __proc_save_context_s(struct proc *p, struct user_context *ctx);
-void proc_yield(struct proc *SAFE p, bool being_nice);
+void __proc_save_fpu_s(struct proc *p);
+void __proc_save_context_s(struct proc *p);
+void proc_yield(struct proc *p, bool being_nice);
void proc_notify(struct proc *p, uint32_t vcoreid);
void proc_wakeup(struct proc *p);
bool __proc_is_mcp(struct proc *p);
+bool proc_is_vcctx_ready(struct proc *p);
int proc_change_to_vcore(struct proc *p, uint32_t new_vcoreid,
bool enable_my_notif);
+void proc_get_set(struct process_set *pset);
+void proc_free_set(struct process_set *pset);
/* Vcoremap info: */
uint32_t proc_get_vcoreid(struct proc *p);
*
* These are internal functions. Error checking is to catch bugs, and you
* shouldn't call these functions with parameters you are not sure about (like
- * an invalid corelist).
+ * an invalid corelist).
*
* WARNING: YOU MUST HOLD THE PROC_LOCK BEFORE CALLING THESE! */
/* Gives process p the additional num cores listed in corelist */
/* Takes all cores, returns the count, fills in pc_arr with their pcoreid */
uint32_t __proc_take_allcores(struct proc *p, uint32_t *pc_arr, bool preempt);
-/* Exposed for kern/src/resource.c for now */
+/* Exposed for now for convenience */
void __map_vcore(struct proc *p, uint32_t vcoreid, uint32_t pcoreid);
void __unmap_vcore(struct proc *p, uint32_t vcoreid);
+void vcore_account_online(struct proc *p, uint32_t vcoreid);
+void vcore_account_offline(struct proc *p, uint32_t vcoreid);
+uint64_t vcore_account_gettotal(struct proc *p, uint32_t vcoreid);
/* Preemption management. Some of these will change */
void __proc_preempt_warn(struct proc *p, uint32_t vcoreid, uint64_t when);
void proc_preempt_all(struct proc *p, uint64_t usec);
/* Current / cr3 / context management */
-struct proc *switch_to(struct proc *new_p);
-void switch_back(struct proc *new_p, struct proc *old_proc);
+uintptr_t switch_to(struct proc *new_p);
+void switch_back(struct proc *new_p, uintptr_t old_ret);
void abandon_core(void);
void clear_owning_proc(uint32_t coreid);
void proc_tlbshootdown(struct proc *p, uintptr_t start, uintptr_t end);
/* Arch Specific */
void proc_pop_ctx(struct user_context *ctx) __attribute__((noreturn));
void proc_init_ctx(struct user_context *ctx, uint32_t vcoreid, uintptr_t entryp,
- uintptr_t stack_top);
+ uintptr_t stack_top, uintptr_t tls_desc);
void proc_secure_ctx(struct user_context *ctx);
void __abandon_core(void);
+void __clear_owning_proc(uint32_t coreid);
/* Degubbing */
void print_allpids(void);
-void print_proc_info(pid_t pid);
-
-#endif /* !ROS_KERN_PROCESS_H */
+void print_proc_info(pid_t pid, int verbosity);