示例#1
0
        public const int SYS_SOCKETPAIR = 8; /* sys_socketpair(2)            */

        #endregion Fields

        #region Methods

        public static void HandleGetSockParamCompletion(GetSockParamCompletion c, int retval, int optlen)
        {
            var current = c.thr;

            if (retval >= 0 && (c.p_addrlen.Write(current, optlen) != 0
                || c.payload.Write(current, new Pointer(c.buf.Location), optlen) != 0))
                retval = -ErrorCode.EFAULT;

            c.Dispose();
            current.ReturnFromCompletion(retval);
        }
示例#2
0
        public static void HandleGetSockParamCompletion(GetSockParamCompletion c, int retval, int optlen)
        {
            var current = c.thr;

            if (retval >= 0 && (c.p_addrlen.Write(current, optlen) != 0 ||
                                c.payload.Write(current, new Pointer(c.buf.Location), optlen) != 0))
            {
                retval = -ErrorCode.EFAULT;
            }

            c.Dispose();
            current.ReturnFromCompletion(retval);
        }
示例#3
0
        private static int Getsockopt(Thread current, ref Arch.ExceptionRegisters regs, int sockfd, int level, int optname, UserPtr optval, UserPtr p_optlen)
        {
            var proc = current.Parent;
            var file = proc.LookupFile(sockfd);

            if (file == null)
            {
                return(-ErrorCode.EBADF);
            }

            if (file.inode.kind != GenericINode.INodeKind.SocketINodeKind)
            {
                return(-ErrorCode.ENOTSOCK);
            }

            uint optlen = 0;

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

            if (optlen > Globals.LinuxIPCBuffer.Length)
            {
                return(-ErrorCode.EINVAL);
            }

            var buf = Globals.AllocateAlignedCompletionBuffer((int)optlen);

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

            var completion = new GetSockParamCompletion(current, optval, p_optlen, buf);

            Arch.IPCStubs.GetSockoptAsync(proc.helperPid, current.impl._value.thread._value, new Pointer(buf.Location), file.inode.LinuxFd, level, optname, (int)optlen);

            Globals.CompletionQueue.Enqueue(completion);
            current.SaveState(ref regs);
            current.AsyncReturn = true;

            return(0);
        }
示例#4
0
        private static int Getsockopt(Thread current, ref Arch.ExceptionRegisters regs, int sockfd, int level, int optname, UserPtr optval, UserPtr p_optlen)
        {
            var proc = current.Parent;
            var file = proc.LookupFile(sockfd);
            if (file == null)
                return -ErrorCode.EBADF;

            if (file.inode.kind != GenericINode.INodeKind.SocketINodeKind)
                return -ErrorCode.ENOTSOCK;

            uint optlen = 0;
            if (p_optlen.Read(current, out optlen) != 0)
                return -ErrorCode.EFAULT;

            if (optlen > Globals.LinuxIPCBuffer.Length)
                return -ErrorCode.EINVAL;

            var buf = Globals.AllocateAlignedCompletionBuffer((int)optlen);

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

            var completion = new GetSockParamCompletion(current, optval, p_optlen, buf);

            Arch.IPCStubs.GetSockoptAsync(proc.helperPid, current.impl._value.thread._value, new Pointer(buf.Location), file.inode.LinuxFd, level, optname, (int)optlen);

            Globals.CompletionQueue.Enqueue(completion);
            current.SaveState(ref regs);
            current.AsyncReturn = true;

            return 0;
        }