summaryrefslogtreecommitdiffstats
path: root/runtime/user/emul.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/user/emul.h')
-rw-r--r--runtime/user/emul.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/runtime/user/emul.h b/runtime/user/emul.h
index 3086a666..b1cc1478 100644
--- a/runtime/user/emul.h
+++ b/runtime/user/emul.h
@@ -1,3 +1,6 @@
+#define kmalloc(size,flags) malloc(size)
+
+#define kfree(ptr) free(ptr)
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
@@ -8,8 +11,52 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
#define _stp_log printf
+/* cpu emulation */
#undef smp_processor_id
-#define smp_processor_id(x) 0
+#undef get_cpu
+#undef put_cpu
+#undef for_each_cpu
+#define for_each_cpu(cpu) \
+ for (cpu = 0; cpu < NR_CPUS; cpu++)
+
+int _processor_number = 0;
+#define smp_processor_id() _processor_number
+#define get_cpu() _processor_number
+#define put_cpu() ;
+
+#include "alloc.c"
+void *__alloc_percpu(size_t size, size_t align)
+{
+ int i;
+ struct percpu_data *pdata = malloc(sizeof (*pdata));
+
+ if (!pdata)
+ return NULL;
+
+ for (i = 0; i < NR_CPUS; i++) {
+ pdata->ptrs[i] = malloc(size);
+
+ if (!pdata->ptrs[i])
+ return NULL;
+
+ memset(pdata->ptrs[i], 0, size);
+ }
+
+ /* Catch derefs w/o wrappers */
+ return (void *) (~(unsigned long) pdata);
+}
+
+void
+free_percpu(const void *objp)
+{
+ int i;
+ struct percpu_data *p = (struct percpu_data *) (~(unsigned long) objp);
+
+ for (i = 0; i < NR_CPUS; i++) {
+ free(p->ptrs[i]);
+ }
+ free(p);
+}
#include <stdarg.h>
unsigned long strtoul(const char *nptr, char **endptr, int base);