mirror of
https://git.openwrt.org/feed/packages.git
synced 2024-06-14 03:13:54 +02:00
635a702255
Description (from libucontext github page): libucontext (https://https://github.com/kaniini/libucontext) is a library which provides the ucontext.h C API. Unlike other implementations, it faithfully follows the kernel process ABI when doing context swaps. libucontext is used on almost all musl distributions to provide the legacy ucontext.h API. This package is meant as a development package. There is no need to install a package on the router if an application or library is linked against the static libraries. Though, shared libraries are provided also. It is used to link libraries/applications against it which need the system calls * makecontext * swapcontext * getcontext * setcontext E.g. the asynchronous API of libmariadb (c-connector) uses this system calls. Because libmusl didn't provide that system calls this synchronous API is currently (without libucontexe) not working - it segfaults. Co-developed-by: Tianling Shen <cnsztl@immortalwrt.org> Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org> Signed-off-by: Volker Christian <me@vchrist.at>
123 lines
3.5 KiB
Diff
123 lines
3.5 KiB
Diff
--- a/test_libucontext.c
|
|
+++ b/test_libucontext.c
|
|
@@ -9,6 +9,9 @@
|
|
#include <string.h>
|
|
#include <libucontext/libucontext.h>
|
|
|
|
+#define handle_error(msg) \
|
|
+ do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
|
+
|
|
static libucontext_ucontext_t ctx[3];
|
|
|
|
|
|
@@ -36,7 +39,8 @@ static void f1 (int a, int b, int c, int
|
|
printf("looks like all arguments are passed correctly\n");
|
|
|
|
printf("swap back to f2\n");
|
|
- libucontext_swapcontext(&ctx[1], &ctx[2]);
|
|
+ if (libucontext_swapcontext(&ctx[1], &ctx[2]) != 0)
|
|
+ handle_error("libucontext_swapcontext");
|
|
printf("finish f1\n");
|
|
}
|
|
|
|
@@ -44,7 +48,8 @@ static void f1 (int a, int b, int c, int
|
|
static void f2 (void) {
|
|
printf("start f2\n");
|
|
printf("swap to f1\n");
|
|
- libucontext_swapcontext(&ctx[2], &ctx[1]);
|
|
+ if (libucontext_swapcontext(&ctx[2], &ctx[1]) != 0)
|
|
+ handle_error("libucontext_swapcontext");
|
|
printf("finish f2, should swap to f1\n");
|
|
}
|
|
|
|
@@ -63,7 +68,8 @@ int main (int argc, const char *argv[])
|
|
printf("setting up context 1\n");
|
|
|
|
|
|
- libucontext_getcontext(&ctx[1]);
|
|
+ if (libucontext_getcontext(&ctx[1]) != 0)
|
|
+ handle_error("libucontext_getcontext");
|
|
ctx[1].uc_stack.ss_sp = st1;
|
|
ctx[1].uc_stack.ss_size = sizeof st1;
|
|
ctx[1].uc_link = &ctx[0];
|
|
@@ -83,16 +89,20 @@ int main (int argc, const char *argv[])
|
|
printf("doing initial swapcontext\n");
|
|
|
|
|
|
- libucontext_swapcontext(&ctx[0], &ctx[2]);
|
|
+ if (libucontext_swapcontext(&ctx[0], &ctx[2]) != 0)
|
|
+ handle_error("libucontext_swapcontext");
|
|
|
|
|
|
printf("returned from initial swapcontext\n");
|
|
|
|
|
|
/* test ability to use getcontext/setcontext without makecontext */
|
|
- libucontext_getcontext(&ctx[1]);
|
|
+ if (libucontext_getcontext(&ctx[1]) != 0)
|
|
+ handle_error("libucontext_getcontext");
|
|
printf("done = %d\n", done);
|
|
- if (done++ == 0) libucontext_setcontext(&ctx[1]);
|
|
+ if (done++ == 0)
|
|
+ if (libucontext_setcontext(&ctx[1]) != 0)
|
|
+ handle_error("libucontext_setcontext");
|
|
if (done != 2) {
|
|
fprintf(stderr, "wrong value for done. got %d, expected 2\n", done);
|
|
abort();
|
|
--- a/test_libucontext_posix.c
|
|
+++ b/test_libucontext_posix.c
|
|
@@ -9,6 +9,9 @@
|
|
#include <string.h>
|
|
#include <ucontext.h>
|
|
|
|
+#define handle_error(msg) \
|
|
+ do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
|
+
|
|
static ucontext_t ctx[3];
|
|
|
|
|
|
@@ -36,7 +39,8 @@ static void f1 (int a, int b, int c, int
|
|
printf("looks like all arguments are passed correctly\n");
|
|
|
|
printf("swap back to f2\n");
|
|
- swapcontext(&ctx[1], &ctx[2]);
|
|
+ if (swapcontext(&ctx[1], &ctx[2]) != 0)
|
|
+ handle_error("swapcontext");
|
|
printf("finish f1\n");
|
|
}
|
|
|
|
@@ -44,7 +48,8 @@ static void f1 (int a, int b, int c, int
|
|
static void f2 (void) {
|
|
printf("start f2\n");
|
|
printf("swap to f1\n");
|
|
- swapcontext(&ctx[2], &ctx[1]);
|
|
+ if (swapcontext(&ctx[2], &ctx[1]) != 0)
|
|
+ handle_error("swapcontext");
|
|
printf("finish f2, should swap to f1\n");
|
|
}
|
|
|
|
@@ -83,16 +88,19 @@ int main (int argc, const char *argv[])
|
|
printf("doing initial swapcontext\n");
|
|
|
|
|
|
- swapcontext(&ctx[0], &ctx[2]);
|
|
-
|
|
+ if (swapcontext(&ctx[0], &ctx[2]) != 0)
|
|
+ handle_error("swapcontext");
|
|
|
|
printf("returned from initial swapcontext\n");
|
|
|
|
|
|
/* test ability to use getcontext/setcontext without makecontext */
|
|
- getcontext(&ctx[1]);
|
|
+ if (getcontext(&ctx[1]) != 0)
|
|
+ handle_error("getcontext");
|
|
printf("done = %d\n", done);
|
|
- if (done++ == 0) setcontext(&ctx[1]);
|
|
+ if (done++ == 0)
|
|
+ if (setcontext(&ctx[1]) != 0)
|
|
+ handle_error("setcontext");
|
|
if (done != 2) {
|
|
fprintf(stderr, "wrong value for done. got %d, expected 2\n", done);
|
|
abort();
|