From 6fbb6d188ef0215fefb06e39b9f1f2244cfcacb6 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 25 Mar 2024 19:09:48 -0400 Subject: [PATCH 1/7] swap macos to dynamic_lookup for undefined. --- src/cli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.c b/src/cli.c index cdb05a1..3872d29 100644 --- a/src/cli.c +++ b/src/cli.c @@ -986,7 +986,7 @@ cli_ldflags(int argc, char **argv) printf("%.*s ", (int)len, p); #if defined(__MACH__) - printf("-dynamiclib -undefined suppress -flat_namespace "); + printf("-dynamiclib -undefined dynamic_lookup -flat_namespace "); #else printf("-shared "); #endif @@ -2221,7 +2221,7 @@ cli_build_ldflags(struct buildopt *bopt) if (bopt->single_binary == 0) { #if defined(__MACH__) cli_buf_appendf(bopt->ldflags, - "-dynamiclib -undefined suppress -flat_namespace "); + "-dynamiclib -undefined dynamic_lookup -flat_namespace "); #else cli_buf_appendf(bopt->ldflags, "-shared "); #endif From 860e21aa50f7bf6e4bd222c08a7412f665792d85 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 29 Apr 2024 09:46:44 +0200 Subject: [PATCH 2/7] linux: add faccessat2 to default seccomp rules. --- src/seccomp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/seccomp.c b/src/seccomp.c index ba4240d..3b1be39 100644 --- a/src/seccomp.c +++ b/src/seccomp.c @@ -70,6 +70,9 @@ static struct sock_filter filter_kore[] = { #endif #if defined(SYS_newfstatat) KORE_SYSCALL_ALLOW(newfstatat), +#endif +#if defined(SYS_faccessat2) + KORE_SYSCALL_ALLOW(faccessat2), #endif KORE_SYSCALL_ALLOW(write), KORE_SYSCALL_ALLOW(fcntl), From 510ad9926a5a93e0d382b50d1c35dde0d1b0087c Mon Sep 17 00:00:00 2001 From: Rickard Lind Date: Sun, 20 Oct 2024 19:39:17 +0200 Subject: [PATCH 3/7] Make it safe to call timer close method from timer callback. --- src/python.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/python.c b/src/python.c index d81448d..0b0aa6f 100644 --- a/src/python.c +++ b/src/python.c @@ -3162,23 +3162,29 @@ pyconnection_x509_cb(void *udata, int islast, int nid, const char *field, static void pytimer_run(void *arg, u_int64_t now) { - PyObject *ret; - struct pytimer *timer = arg; + PyObject *ret; + struct pytimer *timer = arg; + struct kore_timer *run; + + run = timer->run; + timer->run = NULL; PyErr_Clear(); ret = PyObject_CallFunctionObjArgs(timer->callable, timer->udata, NULL); Py_XDECREF(ret); - Py_XDECREF(timer->udata); - timer->udata = NULL; kore_python_log_error("pytimer_run"); if (timer->flags & KORE_TIMER_ONESHOT) { - timer->run = NULL; + run->flags |= KORE_TIMER_ONESHOT; Py_DECREF((PyObject *)timer); } + else { + timer->run = run; + } } + static void pytimer_dealloc(struct pytimer *timer) { @@ -3192,28 +3198,25 @@ pytimer_dealloc(struct pytimer *timer) timer->callable = NULL; } - PyObject_Del((PyObject *)timer); -} - -static PyObject * -pytimer_close(struct pytimer *timer, PyObject *args) -{ - if (timer->run != NULL) { - kore_timer_remove(timer->run); - timer->run = NULL; - } - - if (timer->callable != NULL) { - Py_DECREF(timer->callable); - timer->callable = NULL; - } - if (timer->udata != NULL) { Py_DECREF(timer->udata); timer->udata = NULL; } - Py_INCREF((PyObject *)timer); + PyObject_Del((PyObject *)timer); +} + +static PyObject * +pytimer_close(struct pytimer *timer, PyObject *args) +{ + if (timer->run != NULL) { + kore_timer_remove(timer->run); + timer->run = NULL; + Py_DECREF((PyObject *)timer); + } else { + timer->flags |= KORE_TIMER_ONESHOT; + } + Py_RETURN_TRUE; } From 0356286486310d83087373abb43e6cb0780a8721 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Fri, 25 Oct 2024 12:13:55 +0200 Subject: [PATCH 4/7] up the beer counter --- BEERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BEERS b/BEERS index 0a1fb4d..8c0bf22 100644 --- a/BEERS +++ b/BEERS @@ -33,7 +33,7 @@ I will note down the beer of your choice between the brackets. [] Raphaƫl Monrouzeau [] Raymond Pasco [] Remy Noulin -[] Rickard Lind x 2 +[] Rickard Lind x 3 [] Shih-Yuan Lee [] Stanislav Yudin [] Stig Telfer From 001096460d0cfbafb6e1c9f1833387eb8756959a Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 13 May 2024 10:34:45 +0200 Subject: [PATCH 5/7] Fix the tls-proxy example --- examples/tls-proxy/src/proxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tls-proxy/src/proxy.c b/examples/tls-proxy/src/proxy.c index 9de6bc0..39f8acb 100755 --- a/examples/tls-proxy/src/proxy.c +++ b/examples/tls-proxy/src/proxy.c @@ -64,7 +64,7 @@ client_setup(struct connection *c) struct connection *backend; /* Paranoia. */ - name = SSL_get_servername(c->ssl, TLSEXT_NAMETYPE_host_name); + name = SSL_get_servername(c->tls, TLSEXT_NAMETYPE_host_name); if (name == NULL) { kore_connection_disconnect(c); return; From c437e15b5c41ef7562f64f3407330c4b2390f592 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Fri, 8 Nov 2024 19:29:40 +0100 Subject: [PATCH 6/7] style nits --- src/python.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python.c b/src/python.c index 0b0aa6f..4850662 100644 --- a/src/python.c +++ b/src/python.c @@ -3163,9 +3163,10 @@ static void pytimer_run(void *arg, u_int64_t now) { PyObject *ret; - struct pytimer *timer = arg; struct kore_timer *run; + struct pytimer *timer; + timer = arg; run = timer->run; timer->run = NULL; From 4bd456a334bcf9679fe0f4e762d9c3a86915727d Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Fri, 8 Nov 2024 20:08:19 +0100 Subject: [PATCH 7/7] Support Python 3.13. Since we're using some cpython internals that change from time to time we have to adjust for the 3.13 release accordingly. --- src/python.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/python.c b/src/python.c index 4850662..01c094e 100644 --- a/src/python.c +++ b/src/python.c @@ -55,10 +55,33 @@ #include +/* + * Python 3.13.x requires that Py_BUILD_CORE is defined before we pull + * in the pycore_frame header file, and it loves using unnamed unions + * so we have to turn off pendatic mode before including it. + * + * The f_code member was removed from _PyInterpreterFrame and is replaced + * with a PyObject called f_executable. There is an _PyFrame_GetCode() + * helper function now. + */ +#if PY_VERSION_HEX >= 0x030d0000 +#define Py_BUILD_CORE 1 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#endif + +#if PY_VERSION_HEX < 0x030d0000 +#define _PyFrame_GetCode(frame) (frame->f_code) +#endif + #if PY_VERSION_HEX >= 0x030b0000 #include #endif +#if PY_VERSION_HEX >= 0x030d0000 +#pragma GCC diagnostic pop +#endif + #if PY_VERSION_HEX < 0x030A0000 typedef enum { PYGEN_RETURN = 0, @@ -1201,7 +1224,7 @@ python_resolve_frame_line(void *ptr) frame = ptr; addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); - line = PyCode_Addr2Line(frame->f_code, addr); + line = PyCode_Addr2Line(_PyFrame_GetCode(frame), addr); #else line = PyFrame_GetLineNumber(ptr); #endif @@ -1232,8 +1255,8 @@ python_coro_trace(const char *label, struct python_coro *coro) #else frame = obj->cr_frame; #endif - if (frame != NULL && frame->f_code != NULL) { - code = frame->f_code; + if (frame != NULL && _PyFrame_GetCode(frame) != NULL) { + code = _PyFrame_GetCode(frame); func = PyUnicode_AsUTF8AndSize(code->co_name, NULL); file = PyUnicode_AsUTF8AndSize(code->co_filename, NULL);