summaryrefslogblamecommitdiff
path: root/src/kernel/task/task.h
blob: 5cd3fb288d826a4610f3d6d7b62628f2b00ac659 (plain) (tree)
1
2
3
4
5
6
7
8
9


                  

                       

                
                       
                    
 
                        
                                                                                                
 

                    

                   
                                                                                           
 

                                    

                                                    
             
           


               
                                                   

                                
                           
 
                             

                      
 
                        
                                                                                          
 


                                                            
                                                                   

                                    
                                    

                                

  



                               

                               


                                  
                                                                       

                                                                                       
                  

                      

  
                              
                                
 
                    


                           
                


                                                                                            
 
                                                                                                                      
                                                         
 


                                 
                                    
                             

                                                       

      
#ifndef DEF_TASK_H
#define DEF_TASK_H

#include <types.h>
#include <mem/paging.h>
#include "idt.h"

#include <lib/earray.h>
#include <tce/vfs.h>

#define TS_RUNNING 0	
#define TS_WAKEWAIT 2	//Waiting to be waked up by something precise (thread currently blocked)

#define PL_UNKNOWN 2
#define PL_USER 1
#define PL_KERNEL 0

#define USER_STACK_SIZE 0x10000	//64k, but pages will be mapped one by one as they are used

typedef void (*thread_entry)(void*);

typedef int FILE;	// DUPLICATE FROM vfs/node.h

class thread;
class node;
class process {
	public:

	uint32_t pid, uid, privilege, thread_count;
	process *parent;
	page_directory *pagedir;
	size_t stack, data;

	segment_map *dataseg;
	bool finished;
	int retval;

	thread *threads;
	thread *threads_waiting;		// threads waiting for this process to end

	earray<node> fd;		// file descriptors

	process() : fd(4, 4) {}	// must not be used directly
	process(process *parent, uint32_t uid, uint32_t privilege);

	void* set_args(char** args);
	size_t sbrk(ptrdiff_t size);

	void finish(int retval);
};

class thread {
	public:

	class process *process;
	uint32_t esp, ebp, eip;
	uint8_t state;
	void* kernelStack_addr;
	uint32_t kernelStack_size;

	thread *next, *queue_next;	//queue_next is used in sched.c

	thread(class process *proc, thread_entry entry_point, void *data, void *u_esp);
	~thread();

	void wakeUp();
};

extern thread *current_thread;
extern process *current_process;

void tasking_init();
#ifdef __cplusplus
extern "C" void schedule();
#else
void schedule();
#endif
void tasking_updateKernelPagetable(uint32_t idx, page_table *table, uint32_t tablePhysical);
uint32_t tasking_handleException(registers *regs);

void thread_goInactive();	//Blocks the current thread. it is then waked up by another thread or a system event. 
int proc_priv();	//Returns current privilege level

// syscalls
void thread_exit();
void process_exit(size_t retval);
size_t process_sbrk(ptrdiff_t size);
void process_brk(size_t ptr);
int process_run(char* file, char** args, FILE zero_fd);
int process_waitpid(int pid, int block);

#endif