Vcore list initialization. (XCC)
[akaros.git] / kern / include / ros / procinfo.h
1 /* See COPYRIGHT for copyright information. */
2
3 #ifndef ROS_PROCINFO_H
4 #define ROS_PROCINFO_H
5
6 #include <ros/memlayout.h>
7 #include <ros/common.h>
8 #include <ros/atomic.h>
9 #include <ros/arch/arch.h>
10
11 #define PROCINFO_MAX_ARGP 32
12 #define PROCINFO_ARGBUF_SIZE 3072
13
14 #ifdef ROS_KERNEL
15 #include <sys/queue.h>
16 #endif /* ROS_KERNEL */
17
18 /* Not necessary to expose all of this, but it doesn't hurt, and is convenient
19  * for the kernel.  Need to do some acrobatics for the TAILQ_ENTRY. */
20 struct vcore;
21 struct vcore {
22 #ifdef ROS_KERNEL
23         TAILQ_ENTRY(vcore)      list;
24 #else /* userspace */
25         void                            *dummy_ptr1;
26         void                            *dummy_ptr2;
27 #endif /* ROS_KERNEL */
28         uint32_t                        pcoreid;
29         bool                            valid;
30         bool                            preempt_served;
31         uint64_t                        preempt_pending;
32 };
33
34 struct pcore {
35         uint32_t                        vcoreid;
36         bool                            valid;
37 };
38
39 typedef struct procinfo {
40         pid_t pid;
41         pid_t ppid;
42         size_t max_vcores;
43         uint64_t tsc_freq;
44         void* heap_bottom;
45         char* argp[PROCINFO_MAX_ARGP];
46         char argbuf[PROCINFO_ARGBUF_SIZE];
47         /* glibc relies on stuff above this point.  if you change it, you need to
48          * rebuild glibc. */
49         struct vcore            vcoremap[MAX_NUM_CPUS];
50         uint32_t                        num_vcores;
51         struct pcore            pcoremap[MAX_NUM_CPUS];
52         seq_ctr_t                       coremap_seqctr;
53 } procinfo_t;
54 #define PROCINFO_NUM_PAGES  ((sizeof(procinfo_t)-1)/PGSIZE + 1) 
55
56 static int
57 procinfo_pack_args(procinfo_t* p, char* const* argv, char* const* envp)
58 {
59         int nargv = 0, nenvp = 0;
60         if(argv) while(argv[nargv]) nargv++;
61         if(envp) while(envp[nenvp]) nenvp++;
62
63         if(nargv+nenvp+2 > PROCINFO_MAX_ARGP)
64                 return -1;
65
66         int pos = 0;
67         for(int i = 0; i < nargv; i++)
68         {
69                 int len = strlen(argv[i])+1;
70                 if(pos+len > PROCINFO_ARGBUF_SIZE)
71                         return -1;
72                 p->argp[i] = ((procinfo_t*)UINFO)->argbuf+pos;
73                 memcpy(p->argbuf+pos,argv[i],len);
74                 pos += len;
75         }
76         p->argp[nargv] = 0;
77
78         for(int i = 0; i < nenvp; i++)
79         {
80                 int len = strlen(envp[i])+1;
81                 if(pos+len > PROCINFO_ARGBUF_SIZE)
82                         return -1;
83                 p->argp[nargv+1+i] = ((procinfo_t*)UINFO)->argbuf+pos;
84                 memcpy(p->argbuf+pos,envp[i],len);
85                 pos += len;
86         }
87         p->argp[nargv+nenvp+1] = 0;
88         
89         return 0;
90 }
91
92 // this is how user programs access the procinfo page
93 #ifndef ROS_KERNEL
94 # define __procinfo (*(procinfo_t*)UINFO)
95 #endif
96
97 #endif // !ROS_PROCDATA_H