Example #1
0
        private ResultCode RegisterService(ServiceCtx context, string name, bool isLight, int maxSessions)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(ResultCode.InvalidName);
            }

            Logger.Info?.Print(LogClass.ServiceSm, $"Register \"{name}\".");

            KPort port = new KPort(context.Device.System.KernelContext, maxSessions, isLight, 0);

            if (!_registeredServices.TryAdd(name, port))
            {
                return(ResultCode.AlreadyRegistered);
            }

            if (context.Process.HandleTable.GenerateHandle(port.ServerPort, out int handle) != KernelResult.Success)
            {
                throw new InvalidOperationException("Out of handles!");
            }

            context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);

            return(ResultCode.Success);
        }
Example #2
0
        private KernelResult CreatePort(
            int maxSessions,
            bool isLight,
            ulong namePtr,
            out int serverPortHandle,
            out int clientPortHandle)
        {
            serverPortHandle = clientPortHandle = 0;

            if (maxSessions < 1)
            {
                return(KernelResult.MaximumExceeded);
            }

            KPort port = new KPort(_system, maxSessions, isLight, (long)namePtr);

            KProcess currentProcess = _system.Scheduler.GetCurrentProcess();

            KernelResult result = currentProcess.HandleTable.GenerateHandle(port.ClientPort, out clientPortHandle);

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

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

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

            return(result);
        }
Example #3
0
        public static void InitializePort(Horizon system)
        {
            KPort port = new KPort(system.KernelContext, 256, false, 0);

            port.ClientPort.SetName("sm:");

            port.ClientPort.Service = new IUserInterface();
        }
Example #4
0
        public bool TryRegister(string name, KPort port)
        {
            if (_registeredServices.TryAdd(name, port))
            {
                _serviceRegistrationEvent.Set();
                return(true);
            }

            return(false);
        }
Example #5
0
        private KernelResult ManageNamedPort(ulong namePtr, int maxSessions, out int handle)
        {
            handle = 0;

            if (!KernelTransfer.UserToKernelString(_system, namePtr, 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 #6
0
        // RegisterService(ServiceName name, u8, u32 maxHandles) -> handle<move, port>
        public ResultCode RegisterService(ServiceCtx context)
        {
            if (!_isInitialized)
            {
                return(ResultCode.NotInitialized);
            }

            long namePosition = context.RequestData.BaseStream.Position;

            string name = ReadName(context);

            context.RequestData.BaseStream.Seek(namePosition + 8, SeekOrigin.Begin);

            bool isLight = (context.RequestData.ReadInt32() & 1) != 0;

            int maxSessions = context.RequestData.ReadInt32();

            if (name == string.Empty)
            {
                return(ResultCode.InvalidName);
            }

            Logger.PrintInfo(LogClass.ServiceSm, $"Register \"{name}\".");

            KPort port = new KPort(context.Device.System.KernelContext, maxSessions, isLight, 0);

            if (!_registeredServices.TryAdd(name, port))
            {
                return(ResultCode.AlreadyRegistered);
            }

            if (context.Process.HandleTable.GenerateHandle(port.ServerPort, out int handle) != KernelResult.Success)
            {
                throw new InvalidOperationException("Out of handles!");
            }

            context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);

            return(ResultCode.Success);
        }
Example #7
0
 public void Initialize(KPort parent, int maxSessions)
 {
     _maxSessions = maxSessions;
     _parent      = parent;
 }
Example #8
0
 public void Initialize(KPort Parent)
 {
     this.Parent = Parent;
 }
Example #9
0
 public bool TryGetService(string name, out KPort port)
 {
     return(_registeredServices.TryGetValue(name, out port));
 }
Example #10
0
 public void Initialize(KPort parent)
 {
     _parent = parent;
 }
Example #11
0
 public void Initialize(KPort Parent, int MaxSessions)
 {
     this.MaxSessions = MaxSessions;
     this.Parent      = Parent;
 }