Return bool from reset_alarm_* apis.
[akaros.git] / kern / src / frontend.c
index 17e5c17..75f85c9 100644 (file)
@@ -21,7 +21,7 @@ volatile int magic_mem[10];
 void
 frontend_proc_init(struct proc *SAFE p)
 {
-#ifdef __CONFIG_APPSERVER__
+#ifdef CONFIG_APPSERVER
        pid_t parent_id = p->ppid, id = p->pid;
        int32_t errno;
        if(frontend_syscall(parent_id,APPSERVER_SYSCALL_proc_init,id,0,0,0,&errno))
@@ -32,104 +32,13 @@ frontend_proc_init(struct proc *SAFE p)
 void
 frontend_proc_free(struct proc *SAFE p)
 {
-#ifdef __CONFIG_APPSERVER__
+#ifdef CONFIG_APPSERVER
        int32_t errno;
        if(frontend_syscall(0,APPSERVER_SYSCALL_proc_free,p->pid,0,0,0,&errno))
                panic("Front-end server couldn't free process!");
 #endif
 }
 
-void* user_memdup(struct proc* p, const void* va, int len)
-{
-       void* kva = NULL;
-       if(len < 0 || (kva = kmalloc(len,0)) == NULL)
-               return ERR_PTR(-ENOMEM);
-       if(memcpy_from_user(p,kva,va,len))
-       {
-               kfree(kva);
-               return ERR_PTR(-EINVAL);
-       }
-
-       return kva;
-}
-
-void* user_memdup_errno(struct proc* p, const void* va, int len)
-{
-       void* kva = user_memdup(p,va,len);
-       if(IS_ERR(kva))
-       {
-               set_errno(current_tf,-PTR_ERR(kva));
-               return NULL;
-       }
-       return kva;
-}
-
-void user_memdup_free(struct proc* p, void* va)
-{
-       kfree(va);
-}
-
-char* user_strdup(struct proc* p, const char* va0, int max)
-{
-       max++;
-       char* kbuf = (char*)kmalloc(PGSIZE,0);
-       if(kbuf == NULL)
-               return ERR_PTR(-ENOMEM);
-
-       int pos = 0, len = 0;
-       const char* va = va0;
-       while(max > 0 && len == 0)
-       {
-               int thislen = MIN(PGSIZE-(uintptr_t)va%PGSIZE,max);
-               if(memcpy_from_user(p,kbuf,va,thislen))
-               {
-                       kfree(kbuf);
-                       return ERR_PTR(-EINVAL);
-               }
-
-               const char* nullterm = memchr(kbuf,0,thislen);
-               if(nullterm)
-                       len = pos+(nullterm-kbuf)+1;
-
-               pos += thislen;
-               va += thislen;
-               max -= thislen;
-       }
-
-       kfree(kbuf);
-       return len ? user_memdup(p,va0,len) : ERR_PTR(-EINVAL);
-}
-
-char* user_strdup_errno(struct proc* p, const char* va, int max)
-{
-       void* kva = user_strdup(p,va,max);
-       if(IS_ERR(kva))
-       {
-               set_errno(current_tf,-PTR_ERR(kva));
-               return NULL;
-       }
-       return kva;
-}
-
-int memcpy_to_user_errno(struct proc* p, void* dst, const void* src,
-                                int len)
-{
-       if(memcpy_to_user(p,dst,src,len))
-       {
-               set_errno(current_tf,EINVAL);
-               return -1;
-       }
-       return 0;
-}
-
-void* kmalloc_errno(int len)
-{
-       void* kva = NULL;
-       if(len < 0 || (kva = kmalloc(len,0)) == NULL)
-               set_errno(current_tf,ENOMEM);
-       return kva;
-}
-
 struct kmem_cache* struct_file_cache;
 void file_init()
 {
@@ -227,7 +136,7 @@ int frontend_syscall_errno(struct proc* p, int n, int a0, int a1, int a2, int a3
 {
        int errno, ret = frontend_syscall(p->pid,n,a0,a1,a2,a3,&errno);
        if(errno && p)
-               set_errno(current_tf,errno);
+               set_errno(errno);
        return ret;
 }
 
@@ -235,7 +144,7 @@ int32_t frontend_syscall(pid_t pid, int32_t syscall_num,
                          uint32_t arg0, uint32_t arg1, 
                          uint32_t arg2, uint32_t arg3, int32_t* errno)
 {
-#ifndef __CONFIG_APPSERVER__
+#ifndef CONFIG_APPSERVER
        warn("No appserver support, requested syscall %d for proc %d", syscall_num,
             pid);
        if(errno)
@@ -243,7 +152,7 @@ int32_t frontend_syscall(pid_t pid, int32_t syscall_num,
        return -1;
 #endif
 
-#ifdef __i386__
+#ifdef CONFIG_X86
        if (!irq_is_enabled())
                warn("IRQ is disabled in frontend_syscall %d for proc %d\n", syscall_num, pid);
 #endif
@@ -279,21 +188,21 @@ int32_t frontend_syscall(pid_t pid, int32_t syscall_num,
        return ret;
 }
 
-void __diediedie(trapframe_t* tf, uint32_t srcid, uint32_t code, uint32_t a1, uint32_t a2)
+void __diediedie(uint32_t srcid, uint32_t code, uint32_t a1, uint32_t a2)
 {
        int32_t errno;
        frontend_syscall(0,APPSERVER_SYSCALL_exit,(int)code,0,0,0,&errno);
        while(1);
 }
 
-void appserver_die(int code)
+void appserver_die(uintptr_t code)
 {
        int i;
        for(i = 0; i < num_cpus; i++)
                if(i != core_id())
-                       while(send_kernel_message(i,(amr_t)&__diediedie,(void*)code,0,0,
+                       while(send_kernel_message(i, (amr_t)&__diediedie, code, 0, 0,
                                                  KMSG_IMMEDIATE));
 
        // just in case.
-       __diediedie(0,0,code,0,0);
+       __diediedie(0, code, 0, 0);
 }