Example #1
0
        private KernelResult ManageNamedPort(long nameAddress, int maxSessions, out int handle)
        {
            handle = 0;

            if (!KernelTransfer.UserToKernelString(_system, nameAddress, 12, out string name))
            {
                return(KernelResult.UserCopyFailed);
            }

            if (maxSessions < 0 || name.Length > 11)
            {
                return(KernelResult.MaximumExceeded);
            }

            if (maxSessions == 0)
            {
                return(KClientPort.RemoveName(_system, name));
            }

            KPort port = new KPort(_system);

            KProcess currentProcess = _system.Scheduler.GetCurrentProcess();

            KernelResult result = currentProcess.HandleTable.GenerateHandle(port.ServerPort, out handle);

            if (result != KernelResult.Success)
            {
                return(result);
            }

            port.Initialize(maxSessions, false, 0);

            result = port.SetName(name);

            if (result != KernelResult.Success)
            {
                currentProcess.HandleTable.CloseHandle(handle);
            }

            return(result);
        }
Example #2
0
        private KernelResult ManageNamedPort(long NameAddress, int MaxSessions, out int Handle)
        {
            Handle = 0;

            if (!KernelTransfer.UserToKernelString(System, NameAddress, 12, out string Name))
            {
                return(KernelResult.UserCopyFailed);
            }

            if (MaxSessions < 0 || Name.Length > 11)
            {
                return(KernelResult.MaximumExceeded);
            }

            if (MaxSessions == 0)
            {
                return(KClientPort.RemoveName(System, Name));
            }

            KPort Port = new KPort(System);

            KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();

            KernelResult Result = CurrentProcess.HandleTable.GenerateHandle(Port.ServerPort, out Handle);

            if (Result != KernelResult.Success)
            {
                return(Result);
            }

            Port.Initialize(MaxSessions, false, 0);

            Result = Port.SetName(Name);

            if (Result != KernelResult.Success)
            {
                CurrentProcess.HandleTable.CloseHandle(Handle);
            }

            return(Result);
        }