Пример #1
0
        private static int HandleSyscall(L4Handle src, Thread thr, ref Msgtag pt_tag, ref ExceptionRegisters pt_regs)
        {
            /*
             * Make a copy of the registers, as other IPC calls can override
             * the same area.
             */
            ExceptionRegisters exc = pt_regs;
            var scno = exc.eax;

            SyscallProfiler.EnterSyscall(scno);
            var ret = SyscallDispatcher.Dispatch(thr, ref exc);

            if (thr.AsyncReturn)
            {
                return(REPLY_DEFERRED);
            }

            ArchAPI.ReturnFromSyscall(src, ref exc, ret);
            SyscallProfiler.ExitSyscall(scno);

            return(REPLY_DEFERRED);
        }
Пример #2
0
        private static int HandlePageFault(L4Handle src, Thread thr, ref Msgtag tag, ref MessageRegisters mr)
        {
            uint pfa;
            uint pc;
            uint faultType;

            ArchAPI.GetPageFaultInfo(ref mr, out pfa, out pc, out faultType);

            Pointer physicalPage;
            uint    permssion;

            Pager.HandlePageFault(thr.Parent, faultType, new Pointer(pfa), new Pointer(pc), out physicalPage, out permssion);

            if (thr.AsyncReturn)
            {
                return(REPLY_DEFERRED);
            }

            if (physicalPage == Pointer.Zero)
            {
                // We got an error, don't reply
                // thr.Parent.Space.Regions.DumpAll();
                Console.Write("Unhandled page fault ");
                Console.Write(pfa);
                Console.Write("@");
                Console.Write(pc);
                Console.Write(" thr=");
                Console.Write(thr.Tid);
                Console.WriteLine();

                thr.Parent.Space.DumpAll();

                return(REPLY_DEFERRED);
            }

            ArchAPI.ReturnFromPageFault(src, out tag, ref mr, pfa, physicalPage, permssion);
            return(REPLY_IMMEDIATELY);
        }
Пример #3
0
        internal static int Dispatch(Thread current, ref ExceptionRegisters regs)
        {
            int scno, arg0, arg1, arg2, arg3, arg4, arg5;

            ArchAPI.GetSyscallParameters(regs, out scno, out arg0, out arg1, out arg2, out arg3, out arg4, out arg5);

            current.AsyncReturn = false;

            int retval = 0;

            switch (scno)
            {
            case __NR_exit:
                Console.Write("Thread ");
                Console.Write(current.Tid);
                Console.WriteLine(" Exited");
                current.Exit();
                current.AsyncReturn = true;
                break;

            case __NR_read:
                retval = FileSystem.Read(current, ref regs, arg0, new UserPtr(arg1), arg2);
                break;

            case __NR_write:
                retval = FileSystem.Write(current, ref regs, arg0, new UserPtr(arg1), arg2);
                break;

            case __NR_open:
                retval = FileSystem.Open(current, ref regs, new UserPtr(arg0), arg1, arg2);
                break;

            case __NR_close:
                retval = FileSystem.Close(current, arg0);
                break;

            case __NR_unlink:
                retval = FileSystem.Unlink(current, new UserPtr(arg0));
                break;

            case __NR_lseek:
                retval = FileSystem.Lseek(current, arg0, arg1, arg2);
                break;

            case __NR_getpid:
                retval = ExpressOS.Kernel.Misc.Getpid(current);
                break;

            case __NR_access:
                retval = FileSystem.Access(current, ref regs, new UserPtr(arg0), arg1);
                break;

            case __NR_mkdir:
                retval = FileSystem.Mkdir(current, new UserPtr(arg0), arg1);
                break;

            case __NR_clone:
                retval = ExpressOS.Kernel.Exec.Clone(current, (uint)arg0, new UserPtr(arg1), new UserPtr(arg2), new UserPtr(arg3), ref regs);
                break;

            case __NR_mprotect:
                retval = ExpressOS.Kernel.Memory.mprotect(current, new UserPtr(arg0), arg1, arg2);
                break;

            case __NR__newselect:
                retval = ExpressOS.Kernel.Net.Select(current, ref regs, arg0, new UserPtr(arg1), new UserPtr(arg2), new UserPtr(arg3), new UserPtr(arg4));
                break;

            case __NR_writev:
                retval = FileSystem.Writev(current, ref regs, arg0, new UserPtr(arg1), arg2);
                break;

            case __NR_uname:
                retval = ExpressOS.Kernel.Misc.UName(current, new UserPtr(arg0));
                break;

            case __NR_fcntl64:
                retval = FileSystem.Fcntl64(current, arg0, arg1, arg2);
                break;

            case __NR_gettid:
                retval = ExpressOS.Kernel.Misc.Gettid(current);
                break;

            case __NR_dup:
                retval = FileSystem.Dup(current, arg0);
                break;

            case __NR_pipe:
                retval = FileSystem.Pipe(current, new UserPtr(arg0));
                break;

            case __NR_brk:
                retval = (int)ExpressOS.Kernel.Memory.Brk(current, (uint)arg0);
                break;

            case __NR_ioctl:
                retval = FileSystem.Ioctl(current, ref regs, arg0, arg1, arg2);
                break;

            case __NR_setgid32:
            case __NR_setuid32:
            case __NR_flock:
            case __NR_sigaction:
            case __NR_sigprocmask:
            case __NR_sched_setscheduler:
            case __NR_setpriority:
            case __NR_fsync:

                //Console.Write("Mock syscall ");
                //Console.Write(scno);
                //Console.WriteLine();

                retval = 0;
                break;

            case __NR_futex:
                retval = ExpressOS.Kernel.Futex.DoFutex(current, ref regs, new UserPtr(arg0), arg1, arg2, new UserPtr(arg3), new UserPtr(arg4), (uint)arg5);
                break;

            case __NR_dup2:
                retval = FileSystem.Dup2(current, arg0, arg1);
                break;

            case __NR_gettimeofday:
                retval = ExpressOS.Kernel.Misc.Gettimeofday(current, new UserPtr(arg0));
                break;

            case __NR_munmap:
                retval = ExpressOS.Kernel.Memory.munmap(current, new UserPtr(arg0), arg1);
                break;

            case __NR_ftruncate:
                retval = FileSystem.ftruncate(current, arg0, arg1);
                break;

            case __NR_socketcall:
                retval = ExpressOS.Kernel.Net.socketcall(current, ref regs, arg0, new UserPtr(arg1));
                break;

            case __NR_getpriority:
                retval = ExpressOS.Kernel.Misc.Getpriority(current, arg0, arg1);
                break;

            case __NR_pread64:
                retval = FileSystem.Pread64(current, ref regs, arg0, new UserPtr(arg1), arg2, (uint)arg3);
                break;

            case __NR_getcwd:
                retval = FileSystem.Getcwd(current, new UserPtr(arg0), arg1);
                break;

            case __NR_mmap2:
                retval = ExpressOS.Kernel.Memory.mmap2(current, new UserPtr(arg0), arg1, arg2, arg3, arg4, arg5);
                break;

            case __NR_stat64:
                retval = FileSystem.Stat64(current, new UserPtr(arg0), new UserPtr(arg1));
                break;

            case __NR_fstat64:
                retval = FileSystem.FStat64(current, arg0, new UserPtr(arg1));
                break;

            case __NR_lstat64:
                retval = FileSystem.LStat64(current, new UserPtr(arg0), new UserPtr(arg1));
                break;

            case __NR_getuid32:
            case __NR_geteuid32:
                retval = ExpressOS.Kernel.Misc.Getuid32(current);
                break;

            case __NR_madvise:
                retval = ExpressOS.Kernel.Memory.madvise(current, (uint)arg0, arg1, arg2);
                break;

            case __NR_nanosleep:
                retval = ExpressOS.Kernel.Misc.Nanosleep(current, ref regs, new UserPtr(arg0), new UserPtr(arg1));
                break;

            case __NR_sched_yield:
                retval = ExpressOS.Kernel.Misc.Yield(current, ref regs);
                break;

            case __NR_poll:
                retval = ExpressOS.Kernel.Net.Poll(current, ref regs, new UserPtr(arg0), arg1, arg2);
                break;

            case __NR_set_thread_area:
                retval = ExpressOS.Kernel.TLS.SetThreadArea(current, new UserPtr(arg0));
                break;

            case __NR_clock_gettime:
                retval = ExpressOS.Kernel.Misc.ClockGetTime(current, arg0, new UserPtr(arg1));
                break;

            case __NR_exit_group:
                Console.WriteLine("Process exited");
                Console.Flush();

                //Misc.DumpStackTrace(current, new UserPtr(pt_regs->ebp));
                //current.Parent.Space.Regions.DumpAll();
                current.AsyncReturn = true;
                break;

            case __NR_vbinder:
                retval = ExpressOS.Kernel.VBinder.Dispatch(current, ref regs, arg0, arg1, arg2, arg3);
                break;

            default:
                Console.Write("Unknown syscall ");
                Console.Write(scno);
                Console.Write('@');
                Console.Write(regs.ip);
                Console.Write(" tid=");
                Console.Write(current.Tid);
                Console.WriteLine();
                retval = -ErrorCode.ENOSYS;
                break;
            }

            return(retval);
        }