Ejemplo n.º 1
0
        private int HandleWriteRead(Thread current, UserPtr userBwr, ref Arch.ExceptionRegisters pt_regs)
        {
            var bwr = new binder_write_read();

            if (userBwr.Read(current, out bwr) != 0)
            {
                return(-ErrorCode.EFAULT);
            }

            if (bwr.write_size > 0 || bwr.read_size > 0)
            {
                var ret = HandleWriteRead(current, ref pt_regs, userBwr, bwr);
                if (ret < 0)
                {
                    bwr.read_consumed = 0;
                    if (userBwr.Write(current, ref bwr) != 0)
                    {
                        return(-ErrorCode.EFAULT);
                    }
                }
            }

            if (userBwr.Write(current, ref bwr) != 0)
            {
                return(-ErrorCode.EFAULT);
            }

            return(0);
        }
Ejemplo n.º 2
0
        internal int Ioctl(Thread current, ref Arch.ExceptionRegisters pt_regs, uint cmd, UserPtr userBuf)
        {
            switch (cmd)
            {
            case BINDER_WRITE_READ:
                return(HandleWriteRead(current, userBuf, ref pt_regs));

            case BINDER_VERSION:
                if (userBuf.Write(current, BINDER_CURRENT_PROTOCOL_VERSION) != 0)
                {
                    return(-ErrorCode.EINVAL);
                }

                return(0);

            case BINDER_SET_IDLE_TIMEOUT:
            case BINDER_SET_MAX_THREADS:
            case BINDER_SET_IDLE_PRIORITY:
            case BINDER_SET_CONTEXT_MGR:
            case BINDER_THREAD_EXIT:
                // skipping
                return(0);

            default:
                return(-ErrorCode.EINVAL);
            }
        }
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
        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.º 5
0
        private int HandleWriteRead(Thread current, UserPtr userBwr, ref Arch.ExceptionRegisters pt_regs)
        {
            var bwr = new binder_write_read();

            if (userBwr.Read(current, out bwr) != 0)
                return -ErrorCode.EFAULT;

            if (bwr.write_size > 0 || bwr.read_size > 0)
            {
                var ret = HandleWriteRead(current, ref pt_regs, userBwr, bwr);
                if (ret < 0)
                {
                    bwr.read_consumed = 0;
                    if (userBwr.Write(current, ref bwr) != 0)
                        return -ErrorCode.EFAULT;
                }
            }

            if (userBwr.Write(current, ref bwr) != 0)
                return -ErrorCode.EFAULT;

            return 0;
        }
Ejemplo n.º 6
0
        internal int Ioctl(Thread current, ref Arch.ExceptionRegisters pt_regs, uint cmd, UserPtr userBuf)
        {
            switch (cmd)
            {
                case BINDER_WRITE_READ:
                    return HandleWriteRead(current, userBuf, ref pt_regs);

                case BINDER_VERSION:
                    if (userBuf.Write(current, BINDER_CURRENT_PROTOCOL_VERSION) != 0)
                        return -ErrorCode.EINVAL;

                    return 0;

                case BINDER_SET_IDLE_TIMEOUT:
                case BINDER_SET_MAX_THREADS:
                case BINDER_SET_IDLE_PRIORITY:
                case BINDER_SET_CONTEXT_MGR:
                case BINDER_THREAD_EXIT:
                    // skipping
                    return 0;

                default:
                    return -ErrorCode.EINVAL;
            }
        }
Ejemplo n.º 7
0
        private int LinuxIoctl(Thread current, uint cmd, UserPtr arg1)
        {
            var msg_buf = Globals.LinuxIPCBuffer;
            int ret = 0;

            // marshal arguments
            switch (cmd)
            {
                case FileSystem.FIONREAD:
                    break;

                default:
                    return -ErrorCode.ENOTTY;
            }

            ret = Arch.IPCStubs.linux_sys_vfs_linux_ioctl(current.Parent.helperPid, LinuxFd, cmd, arg1.Value.ToInt32());

            if (ret < 0)
                return ret;

            // unmarshal if necessary
            if (cmd == FileSystem.FIONREAD)
            {
                if (arg1.Write(current, new Pointer(msg_buf.Location), sizeof(int)) != 0)
                    return -ErrorCode.EFAULT;
            }

            return ret;
        }