Exemple #1
0
        internal int Marshal(UserPtr writeBuf, int size)
        {
            if (size < 0 || size > buf.Length)
            {
                return(-ErrorCode.EINVAL);
            }

            ReadCursor = 0;

            // Copy the full data into the buffer, but don't increment the read pointer yet.
            var r = writeBuf.Read(current, buf, size);

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

            // Advance the cursor
            WriteCursor = size;
            // parse the command
            while (ReadCursor < size)
            {
                if (ReadCursor + sizeof(uint) > buf.Length)
                {
                    return(-ErrorCode.ENOMEM);
                }

                var cmd = Deserializer.ReadUInt(buf, ReadCursor);
                ReadCursor += sizeof(uint);

                switch (cmd)
                {
                case BinderINode.BC_INCREFS:
                case BinderINode.BC_ACQUIRE:
                case BinderINode.BC_RELEASE:
                case BinderINode.BC_DECREFS:
                    ReadCursor += sizeof(int);
                    break;

                case BinderINode.BC_INCREFS_DONE:
                case BinderINode.BC_ACQUIRE_DONE:
                case BinderINode.BC_REQUEST_DEATH_NOTIFICATION:
                case BinderINode.BC_CLEAR_DEATH_NOTIFICATION:
                    ReadCursor += Pointer.Size * 2;
                    break;

                case BinderINode.BC_ATTEMPT_ACQUIRE:
                case BinderINode.BC_ACQUIRE_RESULT:
                    // Unimplemented in Android IPC
                    return(-ErrorCode.EINVAL);

                case BinderINode.BC_FREE_BUFFER:
                {
                    if (ReadCursor + sizeof(uint) > buf.Length)
                    {
                        return(-ErrorCode.ENOMEM);
                    }

                    var addr    = Deserializer.ReadUInt(buf, ReadCursor);
                    var new_val = addr - current.Parent.binderVMStart.Value.ToUInt32() + current.Parent.ShadowBinderVMStart;
                    Deserializer.WriteUInt(new_val, buf, ReadCursor);
                    ReadCursor += Pointer.Size;
                    break;
                }

                case BinderINode.BC_TRANSACTION:
                case BinderINode.BC_REPLY:
                {
                    var ret = MarshalTransaction();
                    if (ret < 0)
                    {
                        return(ret);
                    }

                    break;
                }

                case BinderINode.BC_REGISTER_LOOPER:
                case BinderINode.BC_ENTER_LOOPER:
                case BinderINode.BC_EXIT_LOOPER:
                    break;

                default:
                    Arch.Console.Write("binder: unsupported IPC primitive ");
                    Arch.Console.Write(cmd);
                    Arch.Console.WriteLine();
                    return(-1);
                }
            }

            r = AppendPatchTable();
            if (r != 0)
            {
                return(-1);
            }

            //Arch.Console.Write("Dump write buffer ");
            //Arch.Console.Write(current.Tid);
            //Arch.Console.WriteLine();
            //DumpBuf(new Pointer(buf.Location), size);
            return(0);
        }
 public static long GetSizeFromStat64(ByteBufferRef buf)
 {
     return(Deserializer.ReadLong(buf, OFFSET_OF_SIZE_IN_STAT64));
 }
 public static void SetSizeFromStat64(ByteBufferRef buf, ulong size)
 {
     Deserializer.WriteULong(size, buf, OFFSET_OF_SIZE_IN_STAT64);
 }
        public static bool StatIsDir(ByteBufferRef buf)
        {
            var mode = Deserializer.ReadInt(buf, OFFSET_OF_MODE_IN_STAT64);

            return(((mode & S_IFMT) & S_IFDIR) != 0);
        }