Ejemplo n.º 1
0
        internal static int OpenAndReturnLinuxFd(int helperPid, ASCIIString fileName, int flag, int mode)
        {
            Globals.LinuxIPCBuffer.CopyFrom(0, fileName.GetByteString());
            var fd = IPCStubs.Open(helperPid, flag, mode);

            return(fd);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public int ArchFStat64(Thread current, UserPtr buf)
        {
            var ret = IPCStubs.linux_sys_fstat64(current.Parent.helperPid, Fd);

            if (ret < 0)
            {
                return(ret);
            }

            if (buf.Write(current, new Pointer(Globals.LinuxIPCBuffer.Location), GenericINode.SIZE_OF_STAT64) != 0)
            {
                return(-ErrorCode.EFAULT);
            }

            return(0);
        }
Ejemplo n.º 4
0
        internal static OpenFileCompletion OpenAndGetSizeAsync(Thread current, byte[] filename, int flags, int mode)
        {
            ArchDefinition.Assert(filename[filename.Length - 1] == 0);
            var buf = Globals.AllocateAlignedCompletionBuffer(filename.Length);

            if (!buf.isValid)
            {
                return(null);
            }

            buf.CopyFrom(0, filename);

            var completion = new OpenFileCompletion(current, GenericINode.INodeKind.ArchINodeKind, buf, flags, mode);

            IPCStubs.OpenAndGetSizeAsync(current.Parent.helperPid, current.impl._value.thread._value, new Pointer(completion.buf.Location), flags, mode);
            return(completion);
        }
Ejemplo n.º 5
0
        internal int ftruncate(Thread current, int length)
        {
            if (length < 0)
            {
                return(-ErrorCode.EINVAL);
            }

            var ret = IPCStubs.Ftruncate(current.Parent.helperPid, Fd, length);

            if (ret < 0)
            {
                return(ret);
            }

            ArchInodeSize = (uint)length;

            return(0);
        }
Ejemplo n.º 6
0
        public static ArchINode Open(int helperPid, ASCIIString fileName, int flag, int mode, out ErrorCode ec)
        {
            var fd = OpenAndReturnLinuxFd(helperPid, fileName, flag, mode);

            if (fd < 0)
            {
                ec.Code = -fd;
                return(null);
            }

            var ret = IPCStubs.linux_sys_fstat64(helperPid, fd);

            uint size = 0;

            if (ret >= 0)
            {
                size = (uint)FileSystem.GetSizeFromStat64(Globals.LinuxIPCBuffer);
            }

            ec.Code = ErrorCode.NoError;
            return(new ArchINode(fd, size, helperPid));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        internal int ArchRead(Thread current, ref ExceptionRegisters regs, UserPtr userBuf, int len, uint pos, File file)
        {
            var buf = Globals.AllocateAlignedCompletionBuffer(len);

            if (!buf.isValid)
            {
                return(-ErrorCode.ENOMEM);
            }

            var iocp = IOCompletion.CreateReadIOCP(current, userBuf, len, file, buf);

            var r = IPCStubs.ReadAsync(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;
            return(0);
        }
Ejemplo n.º 9
0
 public void Close()
 {
     IPCStubs.Close(helperPid, fd);
 }