new_thread is now pthread_create
This commit is contained in:
parent
24e34f0011
commit
76eedfb921
@ -9,6 +9,7 @@
|
||||
#include <initrd.h>
|
||||
#include <dbg.h>
|
||||
#include <vfs.h>
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct {
|
||||
char filename[100];
|
||||
@ -129,13 +130,14 @@ char load_proc(uint32_t datapos,char* initrd) {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
void thread() {
|
||||
void thread_func() {
|
||||
for (;;) yield();
|
||||
}
|
||||
|
||||
int main() {
|
||||
serial_print("IN INIT\n");
|
||||
new_thread(thread);
|
||||
pthread_t thread;
|
||||
pthread_create(&thread,NULL,thread_func,NULL);
|
||||
blockThread(THREAD_BLOCKED);
|
||||
for (int i=0;i<5;i++) {
|
||||
serial_print("YIELDING\n");
|
||||
|
@ -250,9 +250,13 @@ void isr_handler(registers_t* r) {
|
||||
serial_printf("Copying initrd\n");
|
||||
memcpy((char*)r->ebx,initrd,initrd_sz);
|
||||
break;
|
||||
case SYSCALL_NEW_THREAD:
|
||||
tasking_new_thread((void*)r->ebx,tasking_getPID(),0,0);
|
||||
break;
|
||||
case SYSCALL_NEW_THREAD: {
|
||||
uint32_t tid=tasking_new_thread((void*)r->ebx,tasking_getPID(),1,r->edx);
|
||||
if ((uint32_t*)r->ecx!=NULL) {
|
||||
*((uint32_t*)r->ecx)=tid;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -167,8 +167,9 @@ int* tasking_get_errno_address() {
|
||||
return ¤tThread->errno;
|
||||
}
|
||||
|
||||
void tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg) {
|
||||
uint32_t tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg) {
|
||||
tasking_createTask(start,NULL,0,param_exists,param_arg,0,pid,1);
|
||||
return processes[pid]->firstThread->tid;
|
||||
}
|
||||
|
||||
void switch_to_thread(Thread* thread) {
|
||||
|
@ -13,7 +13,7 @@ void tasking_init();
|
||||
char tasking_isPrivleged();
|
||||
pid_t tasking_getPID();
|
||||
int* tasking_get_errno_address();
|
||||
void tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg);
|
||||
uint32_t tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg);
|
||||
|
||||
void tasking_exit(uint8_t code);
|
||||
void tasking_block(ThreadState newstate);
|
||||
|
81
kernel/rpc.c
81
kernel/rpc.c
@ -1,37 +1,48 @@
|
||||
#include "cpu/tasking.h"
|
||||
#include <string.h>
|
||||
#include "rpc.h"
|
||||
#include "cpu/i386/serial.h"
|
||||
#include "cpu/halt.h"
|
||||
void rpc_init_struct(ThreadRPCStruct* info) {
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
info->funcs[i].code=NULL;
|
||||
memset(info->funcs[i].name,'\0',32);
|
||||
}
|
||||
info->rpc_response=NULL;
|
||||
info->next_func=0;
|
||||
}
|
||||
// #include "cpu/tasking.h"
|
||||
// #include <string.h>
|
||||
// #include "rpc.h"
|
||||
// #include "cpu/i386/serial.h"
|
||||
// #include "cpu/halt.h"
|
||||
// #include "cpu/i386/address_spaces.h"
|
||||
// void rpc_init_struct(ThreadRPCStruct* info) {
|
||||
// for (size_t i = 0; i < 32; i++) {
|
||||
// info->funcs[i].code=NULL;
|
||||
// memset(info->funcs[i].name,'\0',32);
|
||||
// }
|
||||
// info->rpc_response=NULL;
|
||||
// info->num_funcs=0;
|
||||
// }
|
||||
|
||||
void rpc_reg_func(void* (*code)(void*),char* name) {
|
||||
if (strlen(name)>31) {
|
||||
serial_printf("Max length for RPC function name is 31!\n");
|
||||
halt();
|
||||
}
|
||||
ThreadRPCStruct* info=tasking_get_rpc_struct(0);
|
||||
if (info->next_func==32) {
|
||||
serial_printf("Maximum # of RPC functions registered\n");
|
||||
halt();
|
||||
}
|
||||
info->funcs[info->next_func].code=code;
|
||||
strcpy(info->funcs[info->next_func].name,name);
|
||||
info->next_func++;
|
||||
}
|
||||
// void rpc_reg_func(void* (*code)(void*),char* name) {
|
||||
// if (strlen(name)>31) {
|
||||
// serial_printf("Max length for RPC function name is 31!\n");
|
||||
// halt();
|
||||
// }
|
||||
// ThreadRPCStruct* info=tasking_get_rpc_struct(0);
|
||||
// if (info->num_funcs==32) {
|
||||
// serial_printf("Maximum # of RPC functions registered\n");
|
||||
// halt();
|
||||
// }
|
||||
// info->funcs[info->num_funcs].code=code;
|
||||
// strcpy(info->funcs[info->num_funcs].name,name);
|
||||
// info->num_funcs++;
|
||||
// }
|
||||
|
||||
void rpc_call(char* name,pid_t pid,void* data) {
|
||||
if (strlen(name)>31) {
|
||||
serial_printf("Max length for RPC function name is 31!\n");
|
||||
halt();
|
||||
}
|
||||
ThreadRPCStruct* info=tasking_get_rpc_struct(pid);
|
||||
int func_idx;
|
||||
}
|
||||
// void rpc_call(char* name,pid_t pid,void* data,size_t size) {
|
||||
// if (strlen(name)>31) {
|
||||
// serial_printf("Max length for RPC function name is 31!\n");
|
||||
// halt();
|
||||
// }
|
||||
// ThreadRPCStruct* info=tasking_get_rpc_struct(pid);
|
||||
// int func_idx=-1;
|
||||
// for (size_t i=0;i<info->num_funcs;i++) {
|
||||
// if (strcmp(info->funcs[i].name,name)==0) {
|
||||
// func_idx=i;
|
||||
// }
|
||||
// }
|
||||
// if (func_idx==-1) {
|
||||
// serial_printf("No such rpc function %s for PID %d",name,pid);
|
||||
// }
|
||||
// void* copieddata=address_spaces_put_data(currentThread->cr3,data,size);
|
||||
// tasking_new_thread(info->funcs[func_idx].code,pid,1,copieddata);
|
||||
// }
|
||||
|
@ -8,7 +8,7 @@ typedef struct RPCFuncInfo {
|
||||
|
||||
typedef struct ThreadRPCStruct {
|
||||
RPCFuncInfo funcs[32];
|
||||
int next_func;
|
||||
int num_funcs;
|
||||
void* rpc_response;
|
||||
} ThreadRPCStruct;
|
||||
|
||||
|
16
libc/pthread.c
Normal file
16
libc/pthread.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <pthread.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/syscalls.h>
|
||||
#define QUAUX(X) #X
|
||||
#define QU(X) QUAUX(X)
|
||||
|
||||
int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void*), void *restrict arg) {
|
||||
if (thread==NULL) {
|
||||
return 1;
|
||||
}
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_NEW_THREAD) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(start_routine),"c"(thread),"d"(arg));
|
||||
return 0;
|
||||
}
|
@ -57,10 +57,3 @@ void unblockThread(pid_t pid,uint32_t tid) {
|
||||
int $80; \
|
||||
"::"b"(pid),"c"(tid));
|
||||
}
|
||||
|
||||
void new_thread(void* start) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_NEW_THREAD) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(start));
|
||||
}
|
||||
|
12
sysroot/usr/include/pthread.h
Normal file
12
sysroot/usr/include/pthread.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef PTHREAD_H
|
||||
#define PTHREAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint32_t pthread_t;
|
||||
typedef int pthread_attr_t; //Created as dummy
|
||||
|
||||
int pthread_create(pthread_t *restrict thread,
|
||||
const pthread_attr_t *restrict attr,
|
||||
void *(*start_routine)(void*), void *restrict arg);
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user