Vhex-kernel/include/kernel/process.h

103 lines
2.0 KiB
C
Raw Normal View History

2019-12-29 16:39:30 +01:00
#ifndef __KERNEL_PROCESS_H__
# define __KERNEL_PROCESS_H__
#include <stddef.h>
#include <stdint.h>
#include <kernel/fs/file.h>
2020-01-10 17:21:44 +01:00
#include <kernel/fs/filesystem.h>
2019-12-29 16:39:30 +01:00
#include <kernel/context.h>
#include <kernel/types.h>
#define PROCESS_NB_OPEN_FILE (4)
#define PROCESS_USER_STACK_SIZE (15 * 1024)
2020-01-05 10:35:44 +01:00
#define PROCESS_KERNEL_STACK_SIZE (512)
#define PROCESS_NAME_LENGHT (16)
#define PROCESS_MAX (3)
2019-12-29 16:39:30 +01:00
2020-01-05 10:35:44 +01:00
#define PROC_IDLE (0)
2019-12-29 16:39:30 +01:00
// define process struct.
//TODO: signal !
struct process
2019-12-29 16:39:30 +01:00
{
2020-01-05 10:35:44 +01:00
// Used when interrupt or exception occur
struct {
uint32_t kernel;
uint32_t user;
} stack;
2019-12-29 16:39:30 +01:00
// Process name.
char name[PROCESS_NAME_LENGHT];
// Context management
common_context_t context;
// Open file management
struct {
enum {
PROCESS_FILE_SLOT_UNUSED,
PROCESS_FILE_SLOT_USED
} status;
FILE file;
} opfile[PROCESS_NB_OPEN_FILE];
2020-01-10 17:21:44 +01:00
struct dentry *working_dir;
// ignals management.
2019-12-29 16:39:30 +01:00
//sighandler_t signal[NSIG];
2020-01-01 14:19:18 +01:00
// Virtual / Physical memory management.
// @note
// For now, we can not use the MMU
// so we just save all physical allocated
// space. This is an hardcode of each
// process memory management.
struct {
struct {
uint32_t user;
uint32_t kernel;
struct {
uint32_t user;
uint32_t kernel;
} size;
2020-01-01 14:19:18 +01:00
} stack;
struct {
uint32_t start;
uint32_t size;
} program;
struct {
uint32_t start;
uint32_t size;
} exit;
} memory;
2019-12-29 16:39:30 +01:00
// Other process management.
struct process *parent;
struct process *child;
struct process *next;
};
2019-12-29 16:39:30 +01:00
// Internal struct used by the
// static process stack
struct process_stack
2019-12-29 16:39:30 +01:00
{
// Indicate process slot status
enum {
PROC_USED,
PROC_UNUSED
} status;
// Internal process data
struct process process;
2019-12-29 16:39:30 +01:00
};
// Functions.
extern struct process *process_create(const char *name);
extern struct process *process_get(pid_t pid);
2019-12-29 16:39:30 +01:00
extern int process_switch(pid_t pid);
// Internal function.
extern pid_t process_alloc(struct process **process);
extern int process_free(struct process *process);
2019-12-29 16:39:30 +01:00
#endif /*__KERNEL_PROCESS_H__*/