/// <summary> /// FS finddir /// </summary> /// <param name="node">The node</param> /// <param name="name">The name to look for</param> /// <returns>The node</returns> private static unsafe Node rootFindDirImpl(Node node, string name) { int pid = int.Parse(name); if (pid < 0) { return(null); } Task task = Tasking.GetTaskByPID(pid); if (task == null) { return(null); } Node taskNode = new Node(); taskNode.Cookie = new IDCookie(task.PID); taskNode.Flags = NodeFlags.DIRECTORY; taskNode.FindDir = procFindDirImpl; taskNode.ReadDir = procReadDirImpl; return(taskNode); }
/// <summary> /// Read /// </summary> /// <param name="node">The node</param> /// <param name="offset">The offset</param> /// <param name="size">The size</param> /// <param name="buffer">The buffer</param> /// <returns>The amount of bytes written</returns> private static unsafe uint infoReadImpl(Node node, uint offset, uint size, byte[] buffer) { // Check if the task still exists IDCookie cookie = (IDCookie)node.Cookie; Task task = Tasking.GetTaskByPID(cookie.ID); if (task == null) { return(0); } ProcFSInfo info = new ProcFSInfo(); info.Uptime = task.Uptime; info.Priority = (int)task.Priority; info.ThreadCount = task.ThreadCount; info.Pid = task.PID; // Copy name and cmdline String.CopyTo(info.Name, task.Name, 64); String.CopyTo(info.CMDLine, task.CMDLine, 256); if (size > sizeof(ProcFSInfo)) { size = (uint)sizeof(ProcFSInfo); } Memory.Memcpy(Util.ObjectToVoidPtr(buffer), &info, (int)size); return(size); }
/// <summary> /// Sends a signal to a process /// </summary> /// <param name="pid">The PID</param> /// <param name="sig">The signal</param> /// <returns>The errorcode</returns> public static ErrorCode SigSend(int pid, Signal sig) { if (pid <= 0) { return(ErrorCode.EINVAL); } Task task = Tasking.GetTaskByPID(pid); if (task == null) return(ErrorCode.ESRCH); }
/// <summary> /// FS readdir /// </summary> /// <param name="node">The node</param> /// <param name="index">The index</param> /// <returns>The directory entry</returns> private static unsafe DirEntry *procReadDirImpl(Node node, uint index) { // Check if task still exists IDCookie cookie = (IDCookie)node.Cookie; Task task = Tasking.GetTaskByPID(cookie.ID); if (task == null) { return(null); } DirEntry *entry = (DirEntry *)Heap.Alloc(sizeof(DirEntry)); string name = null; // Index zero is the info file if (index == 0) { name = "info"; } else { int j = 0; Thread current = task.FirstThread; while (j < index - 1 && current.NextThread != task.FirstThread) { current = current.NextThread; j++; } // Last thread entry reached but index is still not reached? Stop. if (j < index - 1 && current.NextThread == task.FirstThread) { return(null); } name = current.TID.ToString(); } String.CopyTo(entry->Name, name); // A new string is only created here when index != 0 if (index != 0) { Heap.Free(name); } return(entry); }
/// <summary> /// Waits for (a) process(es) to exit /// </summary> /// <param name="pid">The PID or other identification</param> /// <param name="status">Pointer to status</param> /// <param name="options">Options</param> /// <returns>The error code</returns> public static unsafe ErrorCode WaitPID(int pid, int *status, int options) { // Wait for specific PID if (pid > 0) { // Don't wait, just check if ((options & WNOHANG) == WNOHANG) { if (Tasking.GetTaskByPID(pid) != null) { return(ErrorCode.SUCCESS); } else { return(ErrorCode.ECHILD); } } // If the task is still found, it means it's still there while (Tasking.GetTaskByPID(pid) != null) { Tasking.Yield(); } } // Wait for any child process whose group ID == calling process group ID else if (pid == 0) { } // Wait for any child process else if (pid == -1) { } // Wait for any child process whose group ID == calling process group ID else if (pid < -1) { } return(ErrorCode.SUCCESS); }
/// <summary> /// FS finddir /// </summary> /// <param name="node">The node</param> /// <param name="name">The name to look for</param> /// <returns>The node</returns> private static unsafe Node procFindDirImpl(Node node, string name) { // File is a command: info if (name.Equals("info")) { Node infoNode = new Node(); infoNode.Flags = NodeFlags.FILE; infoNode.Cookie = node.Cookie; // TODO: clone this? infoNode.Size = (uint)sizeof(ProcFSInfo); infoNode.Read = infoReadImpl; return(infoNode); } // Check if task still exists IDCookie cookie = (IDCookie)node.Cookie; if (Tasking.GetTaskByPID(cookie.ID) == null) { return(null); } // File is a thread ID int tid = int.Parse(name); if (tid < 0) { return(null); } Node threadNode = new Node(); threadNode.Flags = NodeFlags.FILE; threadNode.Cookie = new IDCookie(tid); return(threadNode); }