/*************************************************************************** * Copyright (C) 2012 by Terraneo Federico * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * As a special exception, if other files instantiate templates or use * * macros or inline functions from this file, or you compile this file * * and link it with other works to produce a work based on this file, * * this file does not by itself cause the resulting work to be covered * * by the GNU General Public License. However the source code for this * * file must still be made available in accordance with the GNU General * * Public License. This exception does not invalidate any other reasons * * why a work based on this file might be covered by the GNU General * * Public License. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ #ifndef PROCESS_H #define PROCESS_H #include #include #include #include #include #include "kernel.h" #include "sync.h" #include "elf_program.h" #include "config/miosix_settings.h" #include "filesystem/file_access.h" #ifdef WITH_PROCESSES namespace miosix { /** * List of Miosix syscalls */ enum Syscalls { // Yield. Can be called both by kernel threads and process threads both in // userspace and kernelspace mode. It causes the scheduler to switch to // another thread. It is the only SVC that is available also when processes // are disabled in miosix_config.h. No parameters, no return value. SYS_YIELD=0, // Back to userspace. It is used by process threads running in kernelspace // mode to return to userspace mode after completing an SVC. If called by a // process thread already in userspace mode it does nothing. Use of this // SVC by kernel threads is forbidden. No parameters, no return value. SYS_USERSPACE=1, // Standard unix syscalls. Use of these SVC by kernel threads is forbidden. SYS_EXIT=2, SYS_WRITE=3, SYS_READ=4, SYS_USLEEP=5, SYS_OPEN=6, SYS_CLOSE=7, SYS_LSEEK=8, SYS_SYSTEM=9, SYS_FSTAT=10, SYS_ISATTY=11, SYS_STAT=12, SYS_LSTAT=13, SYS_FCNTL=14, SYS_IOCTL=15, SYS_GETDENTS=16, SYS_GETCWD=17, SYS_CHDIR=18, SYS_MKDIR=19, SYS_RMDIR=20, SYS_UNLINK=21, SYS_RENAME=22 }; //Forware decl class Process; /** * This class contains the fields that are in common between the kernel and * processes */ class ProcessBase { public: /** * Constructor */ ProcessBase() : pid(0), ppid(0) {} /** * \return the process' pid */ pid_t getPid() const { return pid; } FileDescriptorTable& getFileTable() { return fileTable; } protected: pid_t pid; /// childs; /// zombies; /// */ static pid_t getNewPid(); ElfProgram program; /// threads; ///