Ejemplo n.º 1
0
        private static int UnmarshalDataEntries(Thread current, ByteBufferRef buf, ref sys_binder_write_desc desc)
        {
            var cursor = desc.read_consumed;
            var i      = 0;

            while (i < desc.patch_table_entries && cursor < buf.Length)
            {
                if (cursor + 2 * sizeof(uint) > buf.Length)
                {
                    return(-1);
                }

                var offset = Deserializer.ReadUInt(buf, cursor);
                cursor += sizeof(uint);
                var length = (int)Deserializer.ReadUInt(buf, cursor);
                cursor += sizeof(int);

                if (cursor + length > buf.Length)
                {
                    return(-1);
                }

                //Arch.Console.Write("UnmarshalDataEntries: offset=");
                //Arch.Console.Write(offset);
                //Arch.Console.Write(" length=");
                //Arch.Console.Write(length);
                //Arch.Console.WriteLine();

                //BinderIPCMarshaler.DumpBuf(marshaledPtr, length);
                var b = buf.Slice(cursor, length);

                if (b.Length + offset > current.Parent.binderVMSize)
                {
                    return(-1);
                }

                Contract.Assert(offset + b.Length <= current.Parent.binderVMSize);
                if ((current.Parent.binderVMStart + offset).Write(current, b) != 0)
                {
                    return(-1);
                }

                cursor += length;
                i++;
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static int UnmarshalReadBuffer(Thread thr, ByteBufferRef completionBuf, ref sys_binder_write_desc desc, UserPtr readBuffer, int readBufferSize)
        {
            var proc = thr.Parent;
            var marshaledPtr = new Pointer(completionBuf.Location);

            //Arch.Console.Write("read_consumed:");
            //Arch.Console.Write(desc.read_consumed);
            //BinderIPCMarshaler.DumpBuf(new Pointer(completionBuf.Location), (int)desc.read_consumed);

            if (proc.binderVMStart == UserPtr.Zero)
            {
                Arch.Console.WriteLine("proc.binderVMStart == UserPtr.Zero");
                return -ErrorCode.EFAULT;
            }

            if (UnmarshalDataEntries(thr, completionBuf, ref desc) != 0)
            {
                Arch.Console.WriteLine("UnmarshalDataEntries failed");
                return -ErrorCode.ENOMEM;
            }

            if (desc.read_consumed > completionBuf.Length)
            {
                Arch.Console.WriteLine("UnmarshalReadBuffer: bad input");
                return -ErrorCode.ENOMEM;
            }

            // Patch pointers and convert file descriptors
            var b = completionBuf.Slice(0, desc.read_consumed);
            if (PatchReadBuffer(thr, b) != 0)
            {
                Arch.Console.WriteLine("Failed to patch read buffer");
                return -ErrorCode.EINVAL;
            }

            if (readBuffer.Write(thr, marshaledPtr, desc.read_consumed) != 0)
            {
                Arch.Console.WriteLine("readBuffer.Write failed");
                return -ErrorCode.ENOMEM;
            }

            return 0;
        }
Ejemplo n.º 3
0
        private static int UnmarshalDataEntries(Thread current, ByteBufferRef buf, ref sys_binder_write_desc desc)
        {
            var cursor = desc.read_consumed;
            var i = 0;
            while (i < desc.patch_table_entries && cursor < buf.Length)
            {
                if (cursor + 2 * sizeof(uint) > buf.Length)
                    return -1;

                var offset = Deserializer.ReadUInt(buf, cursor);
                cursor += sizeof(uint);
                var length = (int)Deserializer.ReadUInt(buf, cursor);
                cursor += sizeof(int);

                if (cursor + length > buf.Length)
                    return -1;

                //Arch.Console.Write("UnmarshalDataEntries: offset=");
                //Arch.Console.Write(offset);
                //Arch.Console.Write(" length=");
                //Arch.Console.Write(length);
                //Arch.Console.WriteLine();

                //BinderIPCMarshaler.DumpBuf(marshaledPtr, length);
                var b = buf.Slice(cursor, length);

                if ((current.Parent.binderVMStart + offset).Write(current, b) != 0)
                    return -1;

                cursor += length;
                i++;
            }
            return 0;
        }
Ejemplo n.º 4
0
        public static int UnmarshalReadBuffer(Thread thr, ByteBufferRef completionBuf, ref sys_binder_write_desc desc, UserPtr readBuffer, int readBufferSize)
        {
            var proc         = thr.Parent;
            var marshaledPtr = new Pointer(completionBuf.Location);

            //Arch.Console.Write("read_consumed:");
            //Arch.Console.Write(desc.read_consumed);
            //BinderIPCMarshaler.DumpBuf(new Pointer(completionBuf.Location), (int)desc.read_consumed);

            if (proc.binderVMStart == UserPtr.Zero)
            {
                Arch.Console.WriteLine("proc.binderVMStart == UserPtr.Zero");
                return(-ErrorCode.EFAULT);
            }

            if (UnmarshalDataEntries(thr, completionBuf, ref desc) != 0)
            {
                Arch.Console.WriteLine("UnmarshalDataEntries failed");
                return(-ErrorCode.ENOMEM);
            }

            if (desc.read_consumed > completionBuf.Length)
            {
                Arch.Console.WriteLine("UnmarshalReadBuffer: bad input");
                return(-ErrorCode.ENOMEM);
            }

            // Patch pointers and convert file descriptors
            var b = completionBuf.Slice(0, desc.read_consumed);

            if (PatchReadBuffer(thr, b) != 0)
            {
                Arch.Console.WriteLine("Failed to patch read buffer");
                return(-ErrorCode.EINVAL);
            }

            if (readBuffer.Write(thr, marshaledPtr, desc.read_consumed) != 0)
            {
                Arch.Console.WriteLine("readBuffer.Write failed");
                return(-ErrorCode.ENOMEM);
            }

            return(0);
        }