/// <summary> /// Starts a new process based on the given path and arguments /// </summary> /// <param name="path">The path</param> /// <param name="argv">The arguments</param> /// <param name="flags">Spawn flags</param> /// <returns>Errorcode or PID</returns> public static int StartProcess(string path, string[] argv, Task.SpawnFlags flags) { if (argv == null) { Panic.DoPanic("argv == null"); } Node node = VFS.GetByAbsolutePath(path); if (node == null) { return(-(int)ErrorCode.ENOENT); } // Open and create buffer VFS.Open(node, (int)FileMode.O_RDONLY); byte[] buffer = new byte[node.Size]; if (buffer == null) { Heap.Free(node); VFS.Close(node); return(-(int)ErrorCode.ENOMEM); } // Fill buffer contents VFS.Read(node, 0, node.Size, buffer); VFS.Close(node); // Pass execution to ELF loader int status = ELFLoader.Execute(buffer, node.Size, argv, flags); Heap.Free(buffer); Heap.Free(node); return(status); }
/// <summary> /// Read from a file descriptor /// </summary> /// <param name="descriptor">The descriptor ID</param> /// <param name="buffer">The buffer</param> /// <param name="size">The size</param> /// <returns>The amount of bytes read</returns> public static int Read(int descriptor, byte[] buffer, uint size) { FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors; Node node = descriptors.GetNode(descriptor); if (node == null) { return(-(int)ErrorCode.EBADF); } // Can't do read from a directory if ((node.Flags & NodeFlags.DIRECTORY) == NodeFlags.DIRECTORY) { return(-(int)ErrorCode.EISDIR); } bool isNonBlocking = ((node.OpenFlags & O_NONBLOCK) == O_NONBLOCK); // Wait until data is available if its blocking if (!isNonBlocking) { while (VFS.GetSize(node) == 0) { Tasking.Yield(); } } // Non-blocking but no data available? else { if (VFS.GetSize(node) == 0) { return(-(int)ErrorCode.EAGAIN); } } uint offset = descriptors.GetOffset(descriptor); uint readBytes = VFS.Read(node, offset, size, buffer); descriptors.SetOffset(descriptor, offset + readBytes); return((int)readBytes); }
private static unsafe void HttpTest2() { Node node = TCPSocketDevice.BindNode("80"); string message = "<!doctype html><html><title>Van Sharpen</title><body>Wij serveren dit van Sharpen naar Dossche</body></html>"; string httpResp = "HTTP/1.1 200 OK\r\nDate: Fri, 13 May 2005 05:51:12 GMT\r\nServer: Sharpen :)\r\nLast-Modified: Fri, 13 May 2005 05:25:02 GMT\r\nAccept-Ranges: bytes\r\nContent-Length: "; string count = message.Length.ToString(); httpResp = String.Merge(httpResp, count); httpResp = String.Merge(httpResp, "\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n"); string finalResp = String.Merge(httpResp, message); byte[] array = new byte[4000]; TCPPacketSmallDescriptor *ptr = (TCPPacketSmallDescriptor *)Util.ObjectToVoidPtr(array); byte *data = (byte *)ptr + sizeof(TCPPacketSmallDescriptor); while (true) { uint sz = VFS.Read(node, 0, 4000, array); if (sz == 0) { continue; } if (ptr->Type == TCPPacketDescriptorTypes.ACCEPT) { Console.Write("New connection from: "); for (int i = 0; i < 3; i++) { Console.WriteNum(data[i]); Console.Write('.'); } Console.WriteNum(data[3]); Console.Write(" with XID: "); Console.WriteHex(ptr->xid); Console.WriteLine(""); } else if (ptr->Type == TCPPacketDescriptorTypes.RECEIVE) { Console.Write("New data from XID: "); Console.WriteHex(ptr->xid); Console.WriteLine(""); byte[] sendData = new byte[sizeof(TCPPacketSendDescriptor)]; TCPPacketSendDescriptor *sendd = (TCPPacketSendDescriptor *)Util.ObjectToVoidPtr(sendData); sendd->xid = ptr->xid; sendd->data = (byte *)Util.ObjectToVoidPtr(finalResp); sendd->Size = finalResp.Length; Console.WriteLine("Writing"); VFS.Write(node, 0, (uint)sizeof(TCPPacketSendDescriptor), sendData); //TCP.Send(con, ptr->xid, (byte*)Util.ObjectToVoidPtr(finalResp), (uint)finalResp.Length); //TCP.Close(con, ptr->xid); } else if (ptr->Type == TCPPacketDescriptorTypes.RESET) { Console.Write("RESET from XID: "); Console.WriteHex(ptr->xid); Console.WriteLine(""); } else if (ptr->Type == TCPPacketDescriptorTypes.CLOSE) { Console.Write("CLOSE from XID: "); Console.WriteHex(ptr->xid); Console.WriteLine(""); } else { Console.WriteLine("Invalid ptr->Type!"); break; } Heap.Free(ptr); } Console.WriteLine("EXIAT"); for (;;) { ; } }