| 154 | } |
| 155 | |
| 156 | process_t* InitializeProcessStructure(){ |
| 157 | // Create process structure |
| 158 | process_t* proc = new process_t; |
| 159 | |
| 160 | proc->fileDescriptors.clear(); |
| 161 | proc->sharedMemory.clear(); |
| 162 | proc->children.clear(); |
| 163 | proc->blocking.clear(); |
| 164 | proc->threads.clear(); |
| 165 | |
| 166 | proc->threads.add_back(new thread_t); |
| 167 | proc->threadCount = 1; |
| 168 | |
| 169 | memset(proc->threads[0], 0, sizeof(thread_t)); |
| 170 | |
| 171 | proc->creationTime = Timer::GetSystemUptimeStruct(); |
| 172 | |
| 173 | // Reserve 3 file descriptors for stdin, out and err |
| 174 | FsNode* nullDev = fs::ResolvePath("/dev/null"); |
| 175 | FsNode* logDev = fs::ResolvePath("/dev/kernellog"); |
| 176 | |
| 177 | if(nullDev){ |
| 178 | proc->fileDescriptors.add_back(fs::Open(nullDev)); |
| 179 | } else { |
| 180 | proc->fileDescriptors.add_back(nullptr); |
| 181 | |
| 182 | Log::Warning("Failed to find /dev/null"); |
| 183 | } |
| 184 | |
| 185 | if(logDev){ |
| 186 | proc->fileDescriptors.add_back(fs::Open(logDev)); |
| 187 | proc->fileDescriptors.add_back(fs::Open(logDev)); |
| 188 | } else { |
| 189 | proc->fileDescriptors.add_back(nullptr); |
| 190 | proc->fileDescriptors.add_back(nullptr); |
| 191 | |
| 192 | Log::Warning("Failed to find /dev/kernellog"); |
| 193 | } |
| 194 | |
| 195 | proc->parent = nullptr; |
| 196 | proc->uid = 0; |
| 197 | |
| 198 | proc->addressSpace = Memory::CreateAddressSpace(); |
| 199 | proc->pid = nextPID++; // Set Process ID to the next availiable |
| 200 | |
| 201 | // Create structure for the main thread |
| 202 | thread_t* thread = proc->threads[0]; |
| 203 | |
| 204 | thread->stack = 0; |
| 205 | thread->priority = 1; |
| 206 | thread->timeSliceDefault = 1; |
| 207 | thread->timeSlice = thread->timeSliceDefault; |
| 208 | thread->fsBase = 0; |
| 209 | thread->state = ThreadStateRunning; |
| 210 | |
| 211 | thread->next = nullptr; |
| 212 | thread->prev = nullptr; |
| 213 | thread->parent = proc; |
no test coverage detected