11 volatile int magic_mem[10];
14 frontend_proc_init(struct proc *p)
16 #ifdef CONFIG_APPSERVER
17 pid_t parent_id = p->ppid, id = p->pid;
19 if(frontend_syscall(parent_id,APPSERVER_SYSCALL_proc_init,id,0,0,0,&errno))
20 panic("Front-end server couldn't initialize new process!");
25 frontend_proc_free(struct proc *p)
27 #ifdef CONFIG_APPSERVER
29 if(frontend_syscall(0,APPSERVER_SYSCALL_proc_free,p->pid,0,0,0,&errno))
30 panic("Front-end server couldn't free process!");
34 struct kmem_cache* struct_file_cache;
37 struct_file_cache = kmem_cache_create("struct_file",
38 sizeof(struct file), 8, 0, 0, 0);
41 /* will zero anything in the page after the EOF */
42 error_t file_read_page(struct file* f, physaddr_t pa, size_t pgoff)
44 int ret = frontend_syscall(0,APPSERVER_SYSCALL_pread,f->fd,pa,PGSIZE,
47 memset(KADDR(pa)+ret,0,PGSIZE-ret);
51 struct file* file_open_from_fd(struct proc* p, int fd)
53 struct file* f = NULL;
54 if(!(f = kmem_cache_alloc(struct_file_cache,0)))
57 f->fd = frontend_syscall(p->pid,APPSERVER_SYSCALL_kdup,fd,0,0,0,NULL);
60 kmem_cache_free(struct_file_cache,f);
64 spinlock_init(&f->lock);
71 struct file* file_open(const char* path, int oflag, int mode)
73 struct file* f = NULL;
74 // although path is a kernel pointer, it may be below KERNBASE.
76 char* malloced = NULL;
77 if((uintptr_t)path < KERNBASE)
79 size_t len = strlen(path)+1;
80 malloced = kmalloc(len,0);
83 path = memcpy(malloced,path,len);
86 if(!(f = kmem_cache_alloc(struct_file_cache,0)))
89 f->fd = frontend_syscall(0,APPSERVER_SYSCALL_open,PADDR(path),
93 kmem_cache_free(struct_file_cache,f);
97 spinlock_init(&f->lock);
106 void file_incref(struct file* f)
110 spin_unlock(&f->lock);
113 void file_decref(struct file* f)
115 // if you decref too many times, you'll clobber memory :(
119 int ret = frontend_syscall(0,APPSERVER_SYSCALL_close,f->fd,0,0,0,NULL);
121 kmem_cache_free(struct_file_cache,f);
124 spin_unlock(&f->lock);
127 int frontend_syscall_errno(struct proc* p, int n, int a0, int a1, int a2, int a3)
129 int errno, ret = frontend_syscall(p->pid,n,a0,a1,a2,a3,&errno);
135 int32_t frontend_syscall(pid_t pid, int32_t syscall_num,
136 uint32_t arg0, uint32_t arg1,
137 uint32_t arg2, uint32_t arg3, int32_t* errno)
139 #ifndef CONFIG_APPSERVER
140 warn("No appserver support, requested syscall %d for proc %d", syscall_num,
148 if (!irq_is_enabled())
149 warn("IRQ is disabled in frontend_syscall %d for proc %d\n", syscall_num, pid);
152 static spinlock_t lock = SPINLOCK_INITIALIZER;
155 // only one frontend request at a time.
156 // interrupts could try to do frontend requests,
157 // which would deadlock, so disable them
160 // write syscall into magic memory
162 magic_mem[1] = syscall_num;
170 // wait for front-end response
171 while(magic_mem[7] == 0)
176 *errno = magic_mem[2];
183 void __diediedie(uint32_t srcid, uint32_t code, uint32_t a1, uint32_t a2)
186 frontend_syscall(0,APPSERVER_SYSCALL_exit,(int)code,0,0,0,&errno);
190 void appserver_die(uintptr_t code)
193 for(i = 0; i < num_cores; i++)
195 while(send_kernel_message(i, (amr_t)&__diediedie, code, 0, 0,
199 __diediedie(0, code, 0, 0);