Removed the tf_to_run from the vcoremap
[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
15 /* Not necessary to expose all of this, but it doesn't hurt, and is convenient
16  * for the kernel. */
17 struct vcore {
18         uint32_t                        pcoreid;
19         bool                            valid;
20         bool                            preempt_served;
21         uint64_t                        preempt_pending;
22 };
23
24 struct pcore {
25         uint32_t                        vcoreid;
26         bool                            valid;
27 };
28
29 typedef struct procinfo {
30         pid_t pid;
31         pid_t ppid;
32         size_t max_harts;
33         uint64_t tsc_freq;
34         void* heap_bottom;
35         char* argp[PROCINFO_MAX_ARGP];
36         char argbuf[PROCINFO_ARGBUF_SIZE];
37         /* glibc relies on stuff above this point.  if you change it, you need to
38          * rebuild glibc. */
39         struct vcore            vcoremap[MAX_NUM_CPUS];
40         uint32_t                        num_vcores;
41         struct pcore            pcoremap[MAX_NUM_CPUS];
42         seq_ctr_t                       coremap_seqctr;
43 } procinfo_t;
44 #define PROCINFO_NUM_PAGES  ((sizeof(procinfo_t)-1)/PGSIZE + 1) 
45
46 static int
47 procinfo_pack_args(procinfo_t* p, char* const* argv, char* const* envp)
48 {
49         int nargv = 0, nenvp = 0;
50         if(argv) while(argv[nargv]) nargv++;
51         if(envp) while(envp[nenvp]) nenvp++;
52
53         if(nargv+nenvp+2 > PROCINFO_MAX_ARGP)
54                 return -1;
55
56         int pos = 0;
57         for(int i = 0; i < nargv; i++)
58         {
59                 int len = strlen(argv[i])+1;
60                 if(pos+len > PROCINFO_ARGBUF_SIZE)
61                         return -1;
62                 p->argp[i] = ((procinfo_t*)UINFO)->argbuf+pos;
63                 memcpy(p->argbuf+pos,argv[i],len);
64                 pos += len;
65         }
66         p->argp[nargv] = 0;
67
68         for(int i = 0; i < nenvp; i++)
69         {
70                 int len = strlen(envp[i])+1;
71                 if(pos+len > PROCINFO_ARGBUF_SIZE)
72                         return -1;
73                 p->argp[nargv+1+i] = ((procinfo_t*)UINFO)->argbuf+pos;
74                 memcpy(p->argbuf+pos,envp[i],len);
75                 pos += len;
76         }
77         p->argp[nargv+nenvp+1] = 0;
78         
79         return 0;
80 }
81
82 // this is how user programs access the procinfo page
83 #ifndef ROS_KERNEL
84 # define __procinfo (*(procinfo_t*)UINFO)
85 #endif
86
87 #endif // !ROS_PROCDATA_H