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); }
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); }
public static void InitializePort(Horizon system) { KPort port = new KPort(system.KernelContext, 256, false, 0); port.ClientPort.SetName("sm:"); port.ClientPort.Service = new IUserInterface(); }
public bool TryRegister(string name, KPort port) { if (_registeredServices.TryAdd(name, port)) { _serviceRegistrationEvent.Set(); return(true); } return(false); }
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); }
// 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); }
public void Initialize(KPort parent, int maxSessions) { _maxSessions = maxSessions; _parent = parent; }
public void Initialize(KPort Parent) { this.Parent = Parent; }
public bool TryGetService(string name, out KPort port) { return(_registeredServices.TryGetValue(name, out port)); }
public void Initialize(KPort parent) { _parent = parent; }
public void Initialize(KPort Parent, int MaxSessions) { this.MaxSessions = MaxSessions; this.Parent = Parent; }