This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 260
/
shim_process.h
81 lines (63 loc) · 2.44 KB
/
shim_process.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2020 Intel Corporation
* Borys Popławski <[email protected]>
*/
#ifndef _SHIM_PROCESS_H
#define _SHIM_PROCESS_H
#include <stdbool.h>
#include "list.h"
#include "pal.h"
#include "shim_fs.h"
#include "shim_handle.h"
#include "shim_lock.h"
#include "shim_types.h"
DEFINE_LIST(shim_child_process);
DEFINE_LISTP(shim_child_process);
struct shim_child_process {
IDTYPE pid;
IDTYPE vmid;
int child_termination_signal;
/* These 3 fields are set when the child terminates. */
int exit_code;
int term_signal;
IDTYPE uid;
LIST_TYPE(shim_child_process) list;
};
struct shim_process {
/* These 2 fields are constant and can safely be read without any locks held. */
IDTYPE pid;
IDTYPE ppid;
/* This field should be accessed atomically, so no lock needed. */
IDTYPE pgid;
/* Currently all threads share filesystem information. For more info check `CLONE_FS` flag in
* `clone.c`. Protected by `fs_lock`. */
struct shim_dentry* root;
struct shim_dentry* cwd;
mode_t umask;
/* Handle to the executable file. Protected by `fs_lock`. */
struct shim_handle* exec;
/* Threads waiting for some child to exit. Protected by `children_lock`. */
struct shim_thread_queue* wait_queue;
/* List of child processes that are still running. Protected by `children_lock`. */
LISTP_TYPE(shim_child_process) children;
/* List of already exited children. Protected by `children_lock`. */
LISTP_TYPE(shim_child_process) zombies;
struct shim_lock children_lock;
struct shim_lock fs_lock;
};
extern struct shim_process g_process;
int init_process(void);
/* Allocates a new child process structure, initializing all fields. */
struct shim_child_process* create_child_process(void);
/* Frees `child` with all acompanying resources. */
void destroy_child_process(struct shim_child_process* child);
/* Adds `child` to `g_process` children list. */
void add_child_process(struct shim_child_process* child);
/*
* These 2 functions mark a child as exited, moving it from `children` list to `zombies` list
* and generate a child-termination signal (if needed).
* Return `true` if the child was found, `false` otherwise.
*/
bool mark_child_exited_by_vmid(IDTYPE vmid, IDTYPE uid, int exit_code, int signal);
bool mark_child_exited_by_pid(IDTYPE pid, IDTYPE uid, int exit_code, int signal);
#endif // _SHIM_PROCESS_H