00001
00002
00011
00012
00013
00014
00015
00029
00030
00031
00032 #include <l4/env/errno.h>
00033 #include <l4/thread/thread.h>
00034
00035 #include <l4/dde_linux/dde.h>
00036
00037
00038 #include <linux/sched.h>
00039
00040
00041 #include "__config.h"
00042 #include "internal.h"
00043
00045 static int _key = -L4_ENOKEY;
00046
00048 static struct task_struct _data = INIT_TASK(_data);
00049
00051 static int _initialized = 0;
00052
00061 struct task_struct * get_current()
00062 {
00063 void *p = l4thread_data_get_current(_key);
00064 Assert(p);
00065 return (struct task_struct *) p;
00066 }
00067
00075 int l4dde_process_add_worker()
00076 {
00077 int err;
00078 void *data;
00079
00080
00081 if (_key < 0)
00082 return _key;
00083
00084
00085 data = vmalloc(sizeof(struct task_struct));
00086 if (!data)
00087 return -L4_ENOMEM;
00088 memcpy(data, &_data, sizeof(struct task_struct));
00089
00090 if ((err = l4thread_data_set_current(_key, data)))
00091 return err;
00092
00093 #if DEBUG_PROCESS
00094 LOG("additional task struct @ %p\n", data);
00095 #endif
00096
00097 return 0;
00098 }
00099
00109 int l4dde_process_init()
00110 {
00111 int err;
00112 void *data;
00113
00114 if (_initialized)
00115 return -L4_ESKIPPED;
00116
00117
00118 if ((_key = l4thread_data_allocate_key()) < 0)
00119 return _key;
00120
00121
00122 data = vmalloc(sizeof(struct task_struct));
00123 if (!data)
00124 return -L4_ENOMEM;
00125 memcpy(data, &_data, sizeof(struct task_struct));
00126
00127 if ((err = l4thread_data_set_current(_key, data)))
00128 return err;
00129
00130 #if DEBUG_PROCESS
00131 LOG("task struct @ %p\n", data);
00132 #endif
00133
00134 ++_initialized;
00135 return 0;
00136 }
00137
00139 struct kernel_thread_data
00140 {
00141 int (*fn)(void *);
00142 void *arg;
00143 };
00144
00146 static void __start_kernel_thread(struct kernel_thread_data *data)
00147 {
00148 int ret;
00149
00150 if (l4dde_process_add_worker())
00151 Panic("add_worker() failed");
00152 if (l4thread_started(NULL))
00153 Panic("l4thread_started() failed");
00154 ret = data->fn(data->arg);
00155 vfree(data);
00156 }
00157
00158
00159
00162 long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
00163 {
00164 int err;
00165 struct kernel_thread_data *data;
00166
00167 data = vmalloc(sizeof(struct kernel_thread_data));
00168 data->fn = fn;
00169 data->arg = arg;
00170
00171 err = l4thread_create_long(L4THREAD_INVALID_ID,
00172 (l4thread_fn_t) __start_kernel_thread,
00173 ".kthread%.2X",
00174 L4THREAD_INVALID_SP,
00175 L4THREAD_DEFAULT_SIZE,
00176 L4THREAD_DEFAULT_PRIO,
00177 (void *) data,
00178 L4THREAD_CREATE_SYNC);
00179
00180 #if 0
00181 if ( err < 0 )
00182
00183 return -EAGAIN;
00184
00185
00186
00187 #endif
00188 return err;
00189 }