- only initialize the fildes_t in usertasks, on create_user_task

This commit is contained in:
Marian Ohligs 2011-09-14 16:25:29 +02:00
parent d633a084ab
commit 39396f1188
4 changed files with 30 additions and 10 deletions

View file

@ -74,7 +74,6 @@ static int socket_open(fildes_t* file, const char* name)
static int socket_close(fildes_t* file)
{
int ret = 0;
kprintf("close %p ", file);
#if defined(CONFIG_LWIP) && LWIP_SOCKET
//ret = lwip_close(file->offset);
if (ret < 0)

View file

@ -39,7 +39,7 @@
/*file descriptor init*/
#define NR_OPEN 10
#define NR_OPEN 100
#define FS_INIT { [0 ... NR_OPEN-1] = {NULL, 0, 0} }
/*open flags*/

View file

@ -93,7 +93,7 @@ typedef struct task {
/// List of VMAs
vma_t* vma_list;
/// Filedescriptor table
fildes_t fildes_table[NR_OPEN];
fildes_t* fildes_table;
/// starting time/tick of the task
uint64_t start_tick;
/// Start address of the heap

View file

@ -47,8 +47,8 @@
* A task's id will be its position in this array.
*/
static task_t task_table[MAX_TASKS] = { \
[0] = {0, TASK_IDLE, 0, 0, 0, NULL, NULL, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, FS_INIT, 0, 0, 0, 0}, \
[1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, 0, 0, NULL, NULL, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, FS_INIT, 0, 0, 0, 0}};
[0] = {0, TASK_IDLE, 0, 0, 0, NULL, NULL, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, NULL, 0, 0, 0, 0}, \
[1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, 0, 0, NULL, NULL, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, NULL, 0, 0, 0, 0}};
static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT;
#if MAX_CORES > 1
@ -280,9 +280,6 @@ static int create_task(tid_t* id, internal_entry_point_t ep, void* arg, uint8_t
task_table[i].vma_list = NULL;
mailbox_wait_msg_init(&task_table[i].inbox);
memset(task_table[i].outbox, 0x00, sizeof(mailbox_wait_msg_t*)*MAX_TASKS);
task_table[i].fildes_table[0].node = findnode_fs("/dev/stdin");
task_table[i].fildes_table[1].node = findnode_fs("/dev/stdout");
task_table[i].fildes_table[2].node = findnode_fs("/dev/stderr");
task_table[i].outbox[curr_task->id] = &curr_task->inbox;
if (id)
@ -369,10 +366,16 @@ int sys_fork(void)
child = &((*child)->next);
}
/* init fildes_table */
task_table[i].fildes_table = kmalloc(sizeof(fildes_t)*NR_OPEN);
memset(task_table[i].fildes_table, 0x00, sizeof(fildes_t)*NR_OPEN);
// copy filedescriptors
for (fd_i = 0; fd_i < NR_OPEN; fd_i++) {
task_table[i].fildes_table[fd_i].node = per_core(current_task)->fildes_table[fd_i].node;
}
mailbox_wait_msg_init(&task_table[i].inbox);
memset(task_table[i].outbox, 0x00, sizeof(mailbox_wait_msg_t*)*MAX_TASKS);
task_table[i].outbox[parent_task->id] = &parent_task->inbox;
@ -732,7 +735,7 @@ static int STDCALL user_entry(void* arg)
int create_user_task(tid_t* id, const char* fname, char** argv)
{
vfs_node_t* node;
int argc = 0;
int argc = 0, ret = 0;
size_t i, buffer_size = 0;
load_args_t* load_args = NULL;
char *dest, *src;
@ -766,7 +769,25 @@ int create_user_task(tid_t* id, const char* fname, char** argv)
while ((*dest++ = *src++) != 0);
}
return create_task(id, user_entry, load_args, NORMAL_PRIO);
/*
* if 'tid_t' id is not initalized, create_task will not set 'tid_t id'
* We need the tid to initalize the fildes, thus we have to check this
*/
if (!id)
id = kmalloc(sizeof(tid_t));
/* == === create new task === == */
ret = create_task(id, user_entry, load_args, NORMAL_PRIO);
/* init fildes_table */
task_table[*id].fildes_table = kmalloc(sizeof(fildes_t)*NR_OPEN);
memset(task_table[*id].fildes_table, 0x00, sizeof(fildes_t)*NR_OPEN);
task_table[*id].fildes_table[0].node = findnode_fs("/dev/stdin");
task_table[*id].fildes_table[1].node = findnode_fs("/dev/stdout");
task_table[*id].fildes_table[2].node = findnode_fs("/dev/stderr");
return ret;
}
/** @brief Used by the execve-Systemcall */