public new static KernelResult RemoveName(Horizon system, string name) { KAutoObject foundObj = FindNamedObject(system, name); if (!(foundObj is KClientPort)) { return(KernelResult.NotFound); } return(KAutoObject.RemoveName(system, name)); }
public new static KernelResult RemoveName(KernelContext context, string name) { KAutoObject foundObj = FindNamedObject(context, name); if (!(foundObj is KClientPort)) { return(KernelResult.NotFound); } return(KAutoObject.RemoveName(context, name)); }
public new static KernelResult RemoveName(Horizon System, string Name) { KAutoObject FoundObj = KAutoObject.FindNamedObject(System, Name); if (!(FoundObj is KClientPort)) { return(KernelResult.NotFound); } return(KAutoObject.RemoveName(System, Name)); }
public void SetReservedHandleObj(int handle, KAutoObject obj) { int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); lock (_table) { KHandleEntry entry = _table[index]; entry.Obj = obj; entry.HandleId = (ushort)(handle >> 15); obj.IncrementReferenceCount(); } }
private KernelResult ConnectToNamedPort(ulong namePtr, out int handle) { handle = 0; if (!KernelTransfer.UserToKernelString(_system, namePtr, 12, out string name)) { return(KernelResult.UserCopyFailed); } if (name.Length > 11) { return(KernelResult.MaximumExceeded); } KAutoObject autoObj = KAutoObject.FindNamedObject(_system, name); if (!(autoObj is KClientPort clientPort)) { return(KernelResult.NotFound); } KProcess currentProcess = _system.Scheduler.GetCurrentProcess(); KernelResult result = currentProcess.HandleTable.ReserveHandle(out handle); if (result != KernelResult.Success) { return(result); } result = clientPort.Connect(out KClientSession clientSession); if (result != KernelResult.Success) { currentProcess.HandleTable.CancelHandleReservation(handle); return(result); } currentProcess.HandleTable.SetReservedHandleObj(handle, clientSession); clientSession.DecrementReferenceCount(); return(result); }
public bool CloseHandle(int handle) { if ((handle >> 30) != 0 || handle == SelfThreadHandle || handle == SelfProcessHandle) { return(false); } int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); KAutoObject obj = null; bool result = false; lock (_table) { if (handleId != 0 && index < _size) { KHandleEntry entry = _table[index]; if ((obj = entry.Obj) != null && entry.HandleId == handleId) { entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; _activeSlotsCount--; result = true; } } } if (result) { obj.DecrementReferenceCount(); } return(result); }
private KernelResult GetMoveObjectHandle(KProcess srcProcess, KProcess dstProcess, int srcHandle, out int dstHandle) { dstHandle = 0; KAutoObject obj = srcProcess.HandleTable.GetObject <KAutoObject>(srcHandle); if (obj != null) { KernelResult result = dstProcess.HandleTable.GenerateHandle(obj, out dstHandle); srcProcess.HandleTable.CloseHandle(srcHandle); return(result); } else { return(KernelResult.InvalidHandle); } }
private KernelResult CloseHandle(int handle) { KAutoObject obj = _process.HandleTable.GetObject <KAutoObject>(handle); _process.HandleTable.CloseHandle(handle); if (obj == null) { return(KernelResult.InvalidHandle); } if (obj is KSession session) { session.Dispose(); } else if (obj is KTransferMemory transferMemory) { _process.MemoryManager.ResetTransferMemory( transferMemory.Address, transferMemory.Size); } return(KernelResult.Success); }
public KernelResult GenerateHandle(KAutoObject obj, out int handle) { handle = 0; lock (_table) { if (_activeSlotsCount >= _size) { return(KernelResult.HandleTableFull); } KHandleEntry entry = _nextFreeEntry; _nextFreeEntry = entry.Next; entry.Obj = obj; entry.HandleId = _idCounter; _activeSlotsCount++; handle = (_idCounter << 15) | entry.Index; obj.IncrementReferenceCount(); if ((short)(_idCounter + 1) >= 0) { _idCounter++; } else { _idCounter = 1; } } return(KernelResult.Success); }