update the curl patch for 7.60.0
[AROS-Contrib.git] / scout / disassembler / libc.c
blob14519f49ece674bcae8ed7d850ba6572982fd723
1 /* Internal tiny implementation of necessary libc functions. */
3 #include <exec/tasks.h>
4 #include <proto/exec.h>
5 #include <sys/types.h>
6 #include <setjmp.h>
7 #include <string.h>
9 #include "libc.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
16 * doing this.
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)
24 struct Task *me;
26 me = FindTask(NULL);
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();
50 void *mem;
52 mem = AllocVecPooled(data->pool, size);
53 if (!mem)
54 longjmp(data->abort_buf, EXCEPTION_NO_MEMORY);
56 return mem;
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;