Пример #1
0
        public static int WriteAppInfo(int helper_pid, int length)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_WRITE_APP_INFO);
            SetMR(1, helper_pid);
            SetMR(2, length);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 3, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #2
0
        public static int Mkdir(int helper_pid, int mode)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_MKDIR);
            SetMR(1, helper_pid);
            SetMR(2, mode);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 3, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1));
        }
Пример #3
0
        public static int Ftruncate(int helper_pid, int fd, int length)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_VFS_FTRUNCATE);
            SetMR(1, helper_pid);
            SetMR(2, fd);
            SetMR(3, length);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 4, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1));
        }
Пример #4
0
        public static int Shutdown(int helper_pid, int sockfd, int how)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SHUTDOWN);
            SetMR(1, helper_pid);
            SetMR(2, sockfd);
            SetMR(3, how);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 4, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #5
0
        private static int IoctlImpl(int type, int helper_pid, int fd, uint cmd, int arg0)
        {
            SetMR(0, type);
            SetMR(1, helper_pid);
            SetMR(2, fd);
            SetMR(3, cmd);
            SetMR(4, arg0);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 5, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1));
        }
Пример #6
0
        public static int AccessAsync(int helper_pid, uint handle, Pointer filename, int mode)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_ACCESS_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(filename));
            SetMR(4, mode);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 5, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #7
0
        private static int BindOrConnectAsync(int type, int helper_pid, uint handle, Pointer buf, int sockfd, int addrlen)
        {
            SetMR(0, type);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, sockfd);
            SetMR(5, addrlen);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #8
0
        public static int SocketAsync(int helper_pid, uint handle, int domain, int type, int protocol)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SOCKET_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, domain);
            SetMR(4, type);
            SetMR(5, protocol);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #9
0
        public static int GetsockNameAsync(int helper_pid, uint handle, Pointer buf, int sockfd, int addrlen)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_GETSOCKNAME_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, sockfd);
            SetMR(5, addrlen);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #10
0
        public static int PollAsync(int helper_pid, uint handle, Pointer fds, int nfds, int timeout)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_POLL);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(fds));
            SetMR(4, nfds);
            SetMR(5, timeout);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #11
0
        public static int OpenAndGetSizeAsync(int helper_pid, uint handle, Pointer buf, int flags, int mode)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_OPEN_AND_GET_SIZE_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, flags);
            SetMR(5, mode);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #12
0
        public static int Fcntl64(int helper_pid, int fd, int cmd, int arg0)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_FCNTL64);
            SetMR(1, helper_pid);
            SetMR(2, fd);
            SetMR(3, cmd);
            SetMR(4, arg0);


            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 5, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1));
        }
Пример #13
0
        public static int linux_sys_futex_wake(int helper_pid, uint handle, int op, Pointer shadowAddr, uint bitset)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_FUTEX_WAKE);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, op);
            SetMR(4, shadowAddr.ToUInt32());
            SetMR(5, bitset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #14
0
        public static int ScatterWritePageAsync(int helper_pid, uint handle, Pointer buf, int fd, int page_count)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SFS_FLUSH_PAGES_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, fd);
            SetMR(4, page_count);
            SetMR(5, RelativeBufferPos(buf));

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #15
0
        private static int ReadWriteAsync(int op, int helper_pid, uint handle, Pointer buf, int fd, int count, uint pos)
        {
            SetMR(0, op);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, fd);
            SetMR(5, count);
            SetMR(6, pos);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 7, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #16
0
        public static uint linux_sys_alien_mmap2(int helper_pid, Pointer addr, int length, int prot, int flags, int fd, int pgoffset)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_ALIEN_MMAP2);
            SetMR(1, helper_pid);
            SetMR(2, addr.ToUInt32());
            SetMR(3, length);
            SetMR(4, prot);
            SetMR(5, flags);
            SetMR(6, fd);
            SetMR(7, pgoffset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 8, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? 0xffffffffU : (uint)GetMR(1));
        }
Пример #17
0
        public static int linux_sys_binder_write_read_async(int helper_pid, uint handle, sys_binder_write_desc desc)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_BINDER_WRITE_READ);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(desc.write_buffer));
            SetMR(4, desc.buffer_size);
            SetMR(5, desc.bwr_write_size);
            SetMR(6, desc.patch_table_entries);
            SetMR(7, desc.patch_table_offset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 8, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #18
0
        public static int linux_sys_free_linux_pages(Pointer[] addresses)
        {
            Contract.Requires(addresses.Length + 2 <= MAX_MR);

            var len = addresses.Length;

            SetMR(0, (int)Type.EXPRESSOS_OP_FREE_LINUX_PAGE);
            SetMR(1, len);

            for (var i = 0; i < len; ++i)
            {
                Deserializer.WriteInt(addresses[i] - ArchGlobals.LinuxMainMemoryStart, ArchGlobals.LinuxIPCBuffer, i * sizeof(int));
            }

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 2, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
Пример #19
0
        public static int Sendto(int helper_pid, int sockfd, int len, int flags, int addrlen)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SENDTO);
            SetMR(1, helper_pid);
            SetMR(2, sockfd);
            SetMR(3, len);
            SetMR(4, flags);
            SetMR(5, addrlen);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
            {
                return(-1);
            }

            return(GetMR(1));
        }
Пример #20
0
        public static Pointer linux_sys_get_user_page(int helper_pid, uint faultType, Pointer shadowAddress)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_GET_USER_PAGE);
            SetMR(1, helper_pid);
            SetMR(2, faultType & L4FPage.L4_FPAGE_FAULT_WRITE);
            SetMR(3, shadowAddress.ToUInt32());

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 4, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
            {
                return(Pointer.Zero);
            }

            var relative_pos = GetMR(1);

            ArchDefinition.Assert(relative_pos < ArchGlobals.LinuxMainMemorySize);
            return(ArchGlobals.LinuxMainMemoryStart + relative_pos);
        }
Пример #21
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);
        }
Пример #22
0
        public static int Pipe(int helper_pid, out int read_pipe, out int write_pipe)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_PIPE);
            SetMR(1, helper_pid);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 2, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            var ret = GetMR(1);

            if (l4_stub_ipc_error(res) != 0 || ret < 0)
            {
                read_pipe  = 0;
                write_pipe = 0;
                return(-1);
            }
            else
            {
                read_pipe  = GetMR(2);
                write_pipe = GetMR(3);
            }
            return(ret);
        }
Пример #23
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);
        }
Пример #24
0
        public static int linux_sys_take_helper(out uint shadowBinderVMStart, out int workspace_fd, out uint workspace_size)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_TAKE_HELPER);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 1, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
            {
                shadowBinderVMStart = 0;
                workspace_fd        = 0;
                workspace_size      = 0;
                return(-1);
            }
            else
            {
                var pid = GetMR(1);
                shadowBinderVMStart = (uint)GetMR(2);
                workspace_fd        = GetMR(3);
                workspace_size      = (uint)GetMR(4);
                return(pid);
            }
        }
Пример #25
0
        public static int linux_sys_free_linux_pages(Pointer[] addresses)
        {
            Contract.Requires(addresses.Length + 2 <= MAX_MR);

            var len = addresses.Length;

            SetMR(0, (int)Type.EXPRESSOS_OP_FREE_LINUX_PAGE);
            SetMR(1, len);

            for (var i = 0; i < len; ++i)
                Deserializer.WriteInt(addresses[i] - ArchGlobals.LinuxMainMemoryStart, ArchGlobals.LinuxIPCBuffer, i * sizeof(int));

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 2, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #26
0
        public static Pointer linux_sys_get_user_page(int helper_pid, uint faultType, Pointer shadowAddress)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_GET_USER_PAGE);
            SetMR(1, helper_pid);
            SetMR(2, faultType & L4FPage.L4_FPAGE_FAULT_WRITE);
            SetMR(3, shadowAddress.ToUInt32());

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 4, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
                return Pointer.Zero;

            var relative_pos = GetMR(1);
            ArchDefinition.Assert(relative_pos < ArchGlobals.LinuxMainMemorySize);
            return ArchGlobals.LinuxMainMemoryStart + relative_pos;
        }
Пример #27
0
        public static int Open(int helper_pid, int flags, int mode)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_OPEN);
            SetMR(1, helper_pid);
            SetMR(2, flags);
            SetMR(3, mode);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 4, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1);
        }
Пример #28
0
        public static int Pipe(int helper_pid, out int read_pipe, out int write_pipe)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_PIPE);
            SetMR(1, helper_pid);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 2, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            var ret = GetMR(1);

            if (l4_stub_ipc_error(res) != 0 || ret < 0)
            {
                read_pipe = 0;
                write_pipe = 0;
                return -1;
            }
            else
            {
                read_pipe = GetMR(2);
                write_pipe = GetMR(3);
            }
            return ret;
        }
Пример #29
0
        public static int Read(int helper_pid, int fd, Pointer buf, int count, ref uint pos)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_VFS_READ);
            SetMR(1, helper_pid);
            SetMR(2, fd);
            SetMR(3, count);
            SetMR(4, pos);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 5, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
                return -1;

            var readBytes = GetMR(1);
            var new_pos = GetMR(2);

            if (readBytes > ArchGlobals.LinuxIPCBuffer.Length)
                return -1;

            var src = ArchGlobals.LinuxIPCBuffer.Slice(0, readBytes);
            var b = new ByteBufferRef(buf.ToIntPtr(), count);
            b.CopyFrom(0, src);
            pos = (uint)new_pos;
            return readBytes;
        }
Пример #30
0
        public static int Sendto(int helper_pid, int sockfd, int len, int flags, int addrlen)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SENDTO);
            SetMR(1, helper_pid);
            SetMR(2, sockfd);
            SetMR(3, len);
            SetMR(4, flags);
            SetMR(5, addrlen);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
                return -1;

            return GetMR(1);
        }
Пример #31
0
        public static int AccessAsync(int helper_pid, uint handle, Pointer filename, int mode)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_ACCESS_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(filename));
            SetMR(4, mode);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 5, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #32
0
        public static uint linux_sys_alien_mmap2(int helper_pid, Pointer addr, int length, int prot, int flags, int fd, int pgoffset)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_ALIEN_MMAP2);
            SetMR(1, helper_pid);
            SetMR(2, addr.ToUInt32());
            SetMR(3, length);
            SetMR(4, prot);
            SetMR(5, flags);
            SetMR(6, fd);
            SetMR(7, pgoffset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 8, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? 0xffffffffU : (uint)GetMR(1);
        }
Пример #33
0
 internal static extern Msgtag l4api_ipc_call(L4Handle dest, Pointer utcb, Msgtag tag, Timeout timeout);
Пример #34
0
 internal static extern int l4api_ipc_error(Msgtag tag, Pointer utcb);
Пример #35
0
 internal static extern Msgtag l4api_ipc_call(L4Handle dest, Pointer utcb, Msgtag tag, Timeout timeout);
Пример #36
0
 public static extern Msgtag l4api_ipc_send_and_wait(L4Handle dest, Pointer utcb, Msgtag tag, out L4Handle src, Timeout timeout);
Пример #37
0
        public static int Close(int helper_pid, int fd)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_CLOSE);
            SetMR(1, helper_pid);
            SetMR(2, fd);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 3, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1);
        }
Пример #38
0
        public static int linux_sys_clock_gettime(int clk_id)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_CLOCK_GETTIME);
            SetMR(1, clk_id);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 2, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1);
        }
Пример #39
0
 public static extern Msgtag l4api_ipc_send(L4Handle dest, Pointer utcb, Msgtag tag, Timeout timeout);
Пример #40
0
        private static int HandleMessage(L4Handle src, ref Msgtag tag, ref ExceptionRegisters pt_regs, ref MessageRegisters mr)
        {
            Thread thr;

            if (tag.Label == Msgtag.L4_PROTO_PAGE_FAULT || IsLinuxSyscall(tag, ref pt_regs))
            {
                thr = Globals.Threads.Lookup(src);
                if (thr == null)
                {
                    Console.Write("HandleMessage: Unknown thread ");
                    Console.Write(src._value);
                    Console.Write(" tag=");
                    Console.Write(tag.raw);
                    Console.WriteLine();
                    return(REPLY_DEFERRED);
                }

                thr.AsyncReturn = false;
                if (tag.Label == Msgtag.L4_PROTO_PAGE_FAULT)
                {
                    return(HandlePageFault(src, thr, ref tag, ref mr));
                }
                else
                {
                    return(HandleSyscall(src, thr, ref tag, ref pt_regs));
                }
            }
            else if (tag.Label == (int)Arch.IPCStubs.IPCTag.EXPRESSOS_IPC)
            {
                HandleAsyncCall(ref mr);
                return(REPLY_DEFERRED);
            }
            else if (tag.Label == (int)Arch.IPCStubs.IPCTag.EXPRESSOS_IPC_CMD)
            {
                switch ((IPCCommand)mr.mr0)
                {
                case IPCCommand.EXPRESSOS_CMD_DUMP_PROFILE:
                    SyscallProfiler.Dump();
                    break;

                case IPCCommand.EXPRESSOS_CMD_ENABLE_PROFILER:
                    SyscallProfiler.Enable = true;
                    break;

                case IPCCommand.EXPRESSOS_CMD_DISABLE_PROFILER:
                    SyscallProfiler.Enable = false;
                    break;

                case IPCCommand.EXPRESSOS_CMD_FLUSH_CONSOLE:
                    Console.Flush();
                    break;
                }
                return(REPLY_DEFERRED);
            }
            else
            {
                Console.Write("Unhandled exception tag=");
                Console.Write(tag.raw);
                Console.Write(" exc_trapno=");
                Console.Write(pt_regs.trapno);
                Console.Write(" err=");
                Console.Write(pt_regs.err);
                Console.Write(" eip=");
                Console.Write(pt_regs.ip);
                Console.Write(" sp=");
                Console.Write(pt_regs.sp);
                Console.WriteLine();
            }
            return(REPLY_DEFERRED);
        }
Пример #41
0
        public static int Shutdown(int helper_pid, int sockfd, int how)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SHUTDOWN);
            SetMR(1, helper_pid);
            SetMR(2, sockfd);
            SetMR(3, how);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 4, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #42
0
        private static int SockoptAsync(int type, int helper_pid, uint handle, Pointer buf, int sockfd, int level, int optname, int optlen)
        {
            SetMR(0, type);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, sockfd);
            SetMR(5, level);
            SetMR(6, optname);
            SetMR(7, optlen);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 8, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #43
0
        public static int ScatterWritePageAsync(int helper_pid, uint handle, Pointer buf, int fd, int page_count)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SFS_FLUSH_PAGES_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, fd);
            SetMR(4, page_count);
            SetMR(5, RelativeBufferPos(buf));

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #44
0
 private static Msgtag l4_stub_ipc_call(L4Handle dest, Msgtag tag, Timeout timeout)
 {
     return(NativeMethods.l4api_ipc_call(dest, NativeMethods.l4api_utcb(), tag, timeout));
 }
Пример #45
0
        public static int PollAsync(int helper_pid, uint handle, Pointer fds, int nfds, int timeout)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_POLL);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(fds));
            SetMR(4, nfds);
            SetMR(5, timeout);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #46
0
        private static int ReadWriteAsync(int op, int helper_pid, uint handle, Pointer buf, int fd, int count, uint pos)
        {
            SetMR(0, op);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, fd);
            SetMR(5, count);
            SetMR(6, pos);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 7, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #47
0
        public static int OpenAndReadPagesAsync(int helper_pid, uint handle, Pointer buf, int npages, int flags, int mode)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_OPEN_AND_READ_PAGES_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, npages);
            SetMR(5, flags);
            SetMR(6, mode);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 7, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #48
0
 private static int l4_stub_ipc_error(Msgtag tag)
 {
     return NativeMethods.l4api_ipc_error(tag, NativeMethods.l4api_utcb());
 }
Пример #49
0
        public static int linux_sys_take_helper(out uint shadowBinderVMStart, out int workspace_fd, out uint workspace_size)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_TAKE_HELPER);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 1, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
            {
                shadowBinderVMStart = 0;
                workspace_fd = 0;
                workspace_size = 0;
                return -1;
            }
            else
            {
                var pid = GetMR(1);
                shadowBinderVMStart = (uint)GetMR(2);
                workspace_fd = GetMR(3);
                workspace_size = (uint)GetMR(4);
                return pid;
            }
        }
Пример #50
0
 private static Msgtag l4_stub_ipc_call(L4Handle dest, Msgtag tag, Timeout timeout)
 {
     return NativeMethods.l4api_ipc_call(dest, NativeMethods.l4api_utcb(), tag, timeout);
 }
Пример #51
0
        public static int linux_sys_futex_wake(int helper_pid, uint handle, int op, Pointer shadowAddr, uint bitset)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_FUTEX_WAKE);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, op);
            SetMR(4, shadowAddr.ToUInt32());
            SetMR(5, bitset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #52
0
 private static int l4_stub_ipc_error(Msgtag tag)
 {
     return(NativeMethods.l4api_ipc_error(tag, NativeMethods.l4api_utcb()));
 }
Пример #53
0
        private static int IoctlImpl(int type, int helper_pid, int fd, uint cmd, int arg0)
        {
            SetMR(0, type);
            SetMR(1, helper_pid);
            SetMR(2, fd);
            SetMR(3, cmd);
            SetMR(4, arg0);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 5, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : GetMR(1);
        }
Пример #54
0
        public static int WriteAppInfo(int helper_pid, int length)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_WRITE_APP_INFO);
            SetMR(1, helper_pid);
            SetMR(2, length);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 3, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #55
0
        public static int linux_sys_binder_write_read_async(int helper_pid, uint handle, sys_binder_write_desc desc)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_BINDER_WRITE_READ);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(desc.write_buffer));
            SetMR(4, desc.buffer_size);
            SetMR(5, desc.bwr_write_size);
            SetMR(6, desc.patch_table_entries);
            SetMR(7, desc.patch_table_offset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 8, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #56
0
        public static int SocketAsync(int helper_pid, uint handle, int domain, int type, int protocol)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_SOCKET_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, domain);
            SetMR(4, type);
            SetMR(5, protocol);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Пример #57
0
 public static extern Msgtag l4api_ipc_send_and_wait(L4Handle dest, Pointer utcb, Msgtag tag, out L4Handle src, Timeout timeout);
Пример #58
0
        private static int StatCombined(int type, int helper_pid, uint length)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_STAT_COMBINED);
            SetMR(1, helper_pid);
            SetMR(2, type);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 3, 0, 0);
            var res = l4_stub_ipc_call(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            if (l4_stub_ipc_error(res) != 0)
                return -1;

            var stat_size = GetMR(2);

            /* API mismatch here */
            if (stat_size != length)
                return -1;

            var ret = GetMR(1);
            return ret;
        }
Пример #59
0
 internal static extern int l4api_ipc_error(Msgtag tag, Pointer utcb);
Пример #60
0
        public static int GetsockNameAsync(int helper_pid, uint handle, Pointer buf, int sockfd, int addrlen)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_GETSOCKNAME_ASYNC);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, RelativeBufferPos(buf));
            SetMR(4, sockfd);
            SetMR(5, addrlen);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 6, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }