1 /* Internal tiny implementation of necessary libc functions. */
3 #include <exec/tasks.h>
4 #include <proto/exec.h>
12 * Note that we use tc_UserData in order to store a pointer to our
13 * data. Since applications may use tc_UserData for their own purpose,
14 * we save old value upon function entry and restore it upon exit.
15 * libc_setcontext() and libc_unsetcontext() are responsible for
17 * I hope this will not clash with some weird stuff (like using tc_UserData
18 * inside exceptions). In theory it is possible to keep own list of contexts
19 * and associated tasks, but this would be slow and overcomplicated.
22 static inline struct LibcData
*GetLibcData(void)
27 return (struct LibcData
*)me
->tc_UserData
;
30 void _abort(char *file
, unsigned int line
)
32 struct LibcData
*ctx
= GetLibcData();
34 ctx
->exception_arg1
= file
;
35 ctx
->exception_arg2
= line
;
36 longjmp(ctx
->abort_buf
, EXCEPTION_ABORT
);
39 void *calloc(size_t nmemb
, size_t size
)
41 struct LibcData
*data
= GetLibcData();
43 /* Note that this implies that the pool was created with MEMF_CLEAR flag */
44 return AllocVecPooled(data
->pool
, nmemb
* size
);
47 void* xmalloc (size_t size
)
49 struct LibcData
*data
= GetLibcData();
52 mem
= AllocVecPooled(data
->pool
, size
);
54 longjmp(data
->abort_buf
, EXCEPTION_NO_MEMORY
);
61 void libc_setcontext(struct LibcData
*data
)
63 struct Task
*me
= FindTask(NULL
);
64 data
->userdata
= me
->tc_UserData
;
66 me
->tc_UserData
= data
;
69 void libc_unsetcontext(void)
71 struct Task
*me
= FindTask(NULL
);
72 struct LibcData
*data
= (struct LibcData
*)me
->tc_UserData
;
74 me
->tc_UserData
= data
->userdata
;