Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public OpenFileCompletion(Thread current, GenericINode.INodeKind fileKind, ByteBufferRef buf, int flags, int mode)
     : base(current, Kind.OpenFileCompletionKind, buf)
 {
     this.fileKind = fileKind;
     this.flags = flags;
     this.mode = mode;
 }
Exemplo n.º 3
0
 public OpenFileCompletion(Thread current, GenericINode.INodeKind fileKind, ByteBufferRef buf, int flags, int mode)
     : base(current, Kind.OpenFileCompletionKind, buf)
 {
     this.fileKind = fileKind;
     this.flags    = flags;
     this.mode     = mode;
 }
Exemplo n.º 4
0
 public IOCompletion(Thread current, Type type, UserPtr userBuf, int len, File file, ByteBufferRef buf)
     : base(current, Kind.IOCompletionKind, buf)
 {
     this.type = type;
     this.userBuf = userBuf;
     this.len = len;
     this.posToUpdate = file;
 }
Exemplo n.º 5
0
        internal int WriteImpl(Thread current, ByteBufferRef buf, int len, ref uint pos)
        {
            for (var i = 0; i < len; ++i)
                Arch.Console.Write((char)buf[i]);

            Arch.Console.Flush();
            return len;
        }
Exemplo n.º 6
0
        internal int WriteImpl(Thread current, ByteBufferRef buf, int len, ref uint pos)
        {
            for (var i = 0; i < len; ++i)
            {
                Arch.Console.Write((char)buf[i]);
            }

            Arch.Console.Flush();
            return(len);
        }
Exemplo n.º 7
0
        public int ReadImpl(ByteBufferRef buffer, int offset, int count, ref uint pos)
        {
            var max_length = buffer.Length - offset > count ? count : buffer.Length - offset;
            if (max_length < 0)
            {
                pos = 0;
                return -ErrorCode.EINVAL;
            }

            int ret = IPCStubs.Read(helperPid, fd, new Pointer(buffer.Location + offset), count, ref pos);
            return ret;
        }
Exemplo n.º 8
0
        public static void Initialize(ref BootParam param)
        {
            LinuxMainMemoryStart = param.LinuxMainMemoryStart;
            LinuxMainMemorySize  = param.LinuxMainMemorySize;
            LinuxIPCBuffer       = new ByteBufferRef(param.SyncIPCBufferBase.ToIntPtr(), param.SyncIPCBufferSize);

            if (param.SyncIPCBufferSize < MinimumIPCBufferSize)
            {
                ArchDefinition.Panic();
            }

            LinuxServerTid = param.LinuxServerTid;
        }
Exemplo n.º 9
0
        public int ReadImpl(ByteBufferRef buffer, int offset, int count, ref uint pos)
        {
            var max_length = buffer.Length - offset > count ? count : buffer.Length - offset;

            if (max_length < 0)
            {
                pos = 0;
                return(-ErrorCode.EINVAL);
            }

            int ret = IPCStubs.Read(helperPid, fd, new Pointer(buffer.Location + offset), count, ref pos);

            return(ret);
        }
Exemplo n.º 10
0
        internal int ArchWrite(Thread current, ref ExceptionRegisters regs, ref ByteBufferRef buf, int len, uint pos, File file)
        {
            if (!Globals.CompletionQueueAllocator.Contains(buf))
            {
                Arch.Console.WriteLine("inode-write: unimplemented");
                Arch.ArchDefinition.Panic();
            }

            var iocp = IOCompletion.CreateWriteIOCP(current, file, buf);
            var r    = IPCStubs.WriteAsync(current.Parent.helperPid, current.impl._value.thread._value, new Pointer(buf.Location), fd, len, pos);

            if (r < 0)
            {
                iocp.Dispose();
                return(r);
            }

            Globals.CompletionQueue.Enqueue(iocp);
            current.SaveState(ref regs);
            current.AsyncReturn = true;
            // Take the buffer
            buf = ByteBufferRef.Empty;
            return(0);
        }
Exemplo n.º 11
0
 public BridgeCompletion(Thread current, ByteBufferRef buf)
     : base(current, Kind.BridgeCompletionKind, buf)
 {
 }
Exemplo n.º 12
0
 public BridgeCompletion(Thread current, ByteBufferRef buf)
     : base(current, Kind.BridgeCompletionKind, buf)
 {
 }
Exemplo n.º 13
0
 internal BinderCompletion(Thread current, UserPtr userBwrBuf, sys_binder_write_desc desc, ByteBufferRef buf)
     : base(current, Kind.BinderCompletionKind, buf)
 {
     this.userBwrBuf = userBwrBuf;
     this.desc = desc;
 }
Exemplo n.º 14
0
 internal static IOCompletion CreateWriteIOCP(Thread current, File file, ByteBufferRef buf)
 {
     return(new IOCompletion(current, Type.Write, UserPtr.Zero, 0, file, buf));
 }
Exemplo n.º 15
0
 internal static IOCompletion CreateReadIOCP(Thread current, UserPtr userBuf, int len, File file, ByteBufferRef buf)
 {
     return(new IOCompletion(current, Type.Read, userBuf, len, file, buf));
 }
Exemplo n.º 16
0
 public IOCompletion(Thread current, Type type, UserPtr userBuf, int len, File file, ByteBufferRef buf)
     : base(current, Kind.IOCompletionKind, buf)
 {
     this.type        = type;
     this.userBuf     = userBuf;
     this.len         = len;
     this.posToUpdate = file;
 }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
 internal static IOCompletion CreateWriteIOCP(Thread current, File file, ByteBufferRef buf)
 {
     return new IOCompletion(current, Type.Write, UserPtr.Zero, 0, file, buf);
 }
Exemplo n.º 19
0
 internal static IOCompletion CreateReadIOCP(Thread current, UserPtr userBuf, int len, File file, ByteBufferRef buf)
 {
     return new IOCompletion(current, Type.Read, userBuf, len, file, buf);
 }
Exemplo n.º 20
0
 public int Read(ByteBufferRef buffer, int offset, int count, ref uint pos)
 {
     switch (kind)
     {
         case INodeKind.ArchINodeKind:
             return ArchINode.ReadImpl(buffer, offset, count, ref pos);
     }
     return -ErrorCode.EINVAL;
 }
Exemplo n.º 21
0
 internal BinderCompletion(Thread current, UserPtr userBwrBuf, sys_binder_write_desc desc, ByteBufferRef buf)
     : base(current, Kind.BinderCompletionKind, buf)
 {
     this.userBwrBuf = userBwrBuf;
     this.desc       = desc;
 }
Exemplo n.º 22
0
        /*
         * Write a segment buffer.
         *
         * The buffer itself is passed as a reference, because some inode might take the ownership
         * of the buffer and put it as a part of its completion. In this case the buf is set to empty
         */
        internal int Write(Thread current, ref Arch.ExceptionRegisters regs, ref ByteBufferRef buf, int len, uint pos, File file)
        {
            switch (kind)
            {
                case INodeKind.ConsoleINodeKind:
                    {
                        uint dummy = 0;
                        return ConsoleINode.WriteImpl(current, buf, len, ref dummy);
                    }
                case INodeKind.ArchINodeKind:
                case INodeKind.SocketINodeKind:
                    return ArchINode.ArchWrite(current, ref regs, ref buf, len, pos, file);

                case INodeKind.SecureFSINodeKind:
                    return SFSINode.SFSWrite(current, ref regs, buf, len, pos, file);
            }
            return -ErrorCode.EINVAL;
        }
Exemplo n.º 23
0
        internal int ArchWrite(Thread current, ref ExceptionRegisters regs, ref ByteBufferRef buf, int len, uint pos, File file)
        {
            if (!Globals.CompletionQueueAllocator.Contains(buf))
            {
                Arch.Console.WriteLine("inode-write: unimplemented");
                Arch.ArchDefinition.Panic();
            }

            var iocp = IOCompletion.CreateWriteIOCP(current, file, buf);
            var r = IPCStubs.WriteAsync(current.Parent.helperPid, current.impl._value.thread._value, new Pointer(buf.Location), fd, len, pos);

            if (r < 0)
            {
                iocp.Dispose();
                return r;
            }

            Globals.CompletionQueue.Enqueue(iocp);
            current.SaveState(ref regs);
            current.AsyncReturn = true;
            // Take the buffer
            buf = ByteBufferRef.Empty;
            return 0;
        }