fix: ensure inlining
[lunaix-os.git] / lunaix-os / kernel / process / task_attr.c
1 #include <lunaix/fs/taskfs.h>
2
3 void
4 __read_pending_sig(struct twimap* map)
5 {
6     struct proc_info* proc = twimap_data(map, struct proc_info*);
7     twimap_printf(map, "%bb", proc->sig_pending);
8 }
9
10 void
11 __read_masked_sig(struct twimap* map)
12 {
13     struct proc_info* proc = twimap_data(map, struct proc_info*);
14     twimap_printf(map, "%bb", proc->sig_mask);
15 }
16
17 void
18 __read_parent(struct twimap* map)
19 {
20     struct proc_info* proc = twimap_data(map, struct proc_info*);
21     twimap_printf(map, "%d", proc->parent->pid);
22 }
23
24 void
25 __read_ctimestamp(struct twimap* map)
26 {
27     struct proc_info* proc = twimap_data(map, struct proc_info*);
28     twimap_printf(map, "%d", proc->created);
29 }
30
31 void
32 __read_pgid(struct twimap* map)
33 {
34     struct proc_info* proc = twimap_data(map, struct proc_info*);
35     twimap_printf(map, "%d", proc->pgid);
36 }
37
38 void
39 __read_children(struct twimap* map)
40 {
41     struct llist_header* proc_list = twimap_index(map, struct llist_header*);
42     struct proc_info* proc =
43       container_of(proc_list, struct proc_info, siblings);
44     if (!proc)
45         return;
46     twimap_printf(map, "%d ", proc->pid);
47 }
48
49 int
50 __next_children(struct twimap* map)
51 {
52     struct llist_header* proc = twimap_index(map, struct llist_header*);
53     struct proc_info* current = twimap_data(map, struct proc_info*);
54     if (!proc)
55         return 0;
56     map->index = proc->next;
57     if (map->index == &current->children) {
58         return 0;
59     }
60     return 1;
61 }
62
63 void
64 __reset_children(struct twimap* map)
65 {
66     struct proc_info* proc = twimap_data(map, struct proc_info*);
67     if (llist_empty(&proc->children)) {
68         map->index = 0;
69         return;
70     }
71     map->index = proc->children.next;
72 }
73
74 void
75 export_task_attr()
76 {
77     struct twimap* map;
78     map = twimap_create(NULL);
79     map->read = __read_pending_sig;
80     taskfs_export_attr("sig_pending", map);
81
82     map = twimap_create(NULL);
83     map->read = __read_masked_sig;
84     taskfs_export_attr("sig_masked", map);
85
86     map = twimap_create(NULL);
87     map->read = __read_parent;
88     taskfs_export_attr("parent", map);
89
90     map = twimap_create(NULL);
91     map->read = __read_ctimestamp;
92     taskfs_export_attr("created", map);
93
94     map = twimap_create(NULL);
95     map->read = __read_pgid;
96     taskfs_export_attr("pgid", map);
97
98     map = twimap_create(NULL);
99     map->read = __read_children;
100     map->go_next = __next_children;
101     map->reset = __reset_children;
102     taskfs_export_attr("children", map);
103 }