Skip to content

Commit 653d6a3

Browse files
authored
bugfix: Apple Silicon FFI ABI limitation workaround
There is a known issue in LuaJIT (LuaJIT/LuaJIT#205 (comment)) that passing non 64-bit value after the 8th argument in FFI calls doesn't work on Apple ARM64 devices, there is no plan on addressing this issue anytime soon from LuaJIT side. This commit conditionally compiles proxy FFI functions that takes in pointer to struct in order to reduce the length of the argument list, getting around this issue.
1 parent bc2ecda commit 653d6a3

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

src/ngx_http_lua_headers.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,4 +1240,16 @@ ngx_http_lua_ngx_raw_header_cleanup(void *data)
12401240
#endif
12411241

12421242

1243+
#if (NGX_DARWIN)
1244+
int
1245+
ngx_http_lua_ffi_set_resp_header_macos(ngx_http_lua_set_resp_header_params_t *p)
1246+
{
1247+
return ngx_http_lua_ffi_set_resp_header(p->r, p->key_data, p->key_len,
1248+
p->is_nil, p->sval, p->sval_len,
1249+
p->mvals, p->mvals_len,
1250+
p->override, p->errmsg);
1251+
}
1252+
#endif
1253+
1254+
12431255
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_http_lua_headers_out.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
#include "ngx_http_lua_common.h"
1313

1414

15+
#if (NGX_DARWIN)
16+
typedef struct {
17+
ngx_http_request_t *r;
18+
const char *key_data;
19+
size_t key_len;
20+
int is_nil;
21+
const char *sval;
22+
size_t sval_len;
23+
void *mvals;
24+
size_t mvals_len;
25+
int override;
26+
char **errmsg;
27+
} ngx_http_lua_set_resp_header_params_t;
28+
#endif
29+
30+
1531
ngx_int_t ngx_http_lua_set_output_header(ngx_http_request_t *r,
1632
ngx_http_lua_ctx_t *ctx, ngx_str_t key, ngx_str_t value, unsigned override);
1733
int ngx_http_lua_get_output_header(lua_State *L, ngx_http_request_t *r,

src/ngx_http_lua_shdict.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,4 +2092,38 @@ ngx_http_lua_ffi_shdict_free_space(ngx_shm_zone_t *zone)
20922092
#endif
20932093

20942094

2095+
#if (NGX_DARWIN)
2096+
int
2097+
ngx_http_lua_ffi_shdict_get_macos(ngx_http_lua_shdict_get_params_t *p)
2098+
{
2099+
return ngx_http_lua_ffi_shdict_get(p->zone, p->key, p->key_len,
2100+
p->value_type, p->str_value_buf,
2101+
p->str_value_len, p->num_value,
2102+
p->user_flags, p->get_stale,
2103+
p->is_stale, p->errmsg);
2104+
}
2105+
2106+
2107+
int
2108+
ngx_http_lua_ffi_shdict_store_macos(ngx_http_lua_shdict_store_params_t *p)
2109+
{
2110+
return ngx_http_lua_ffi_shdict_store(p->zone, p->op, p->key, p->key_len,
2111+
p->value_type, p->str_value_buf,
2112+
p->str_value_len, p->num_value,
2113+
p->exptime, p->user_flags,
2114+
p->errmsg, p->forcible);
2115+
}
2116+
2117+
2118+
int
2119+
ngx_http_lua_ffi_shdict_incr_macos(ngx_http_lua_shdict_incr_params_t *p)
2120+
{
2121+
return ngx_http_lua_ffi_shdict_incr(p->zone, p->key, p->key_len,
2122+
p->num_value, p->errmsg,
2123+
p->has_init, p->init, p->init_ttl,
2124+
p->forcible);
2125+
}
2126+
#endif
2127+
2128+
20952129
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_http_lua_shdict.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,52 @@ typedef struct {
5555
} ngx_http_lua_shm_zone_ctx_t;
5656

5757

58+
#if (NGX_DARWIN)
59+
typedef struct {
60+
void *zone;
61+
const unsigned char *key;
62+
size_t key_len;
63+
int *value_type;
64+
unsigned char **str_value_buf;
65+
size_t *str_value_len;
66+
double *num_value;
67+
int *user_flags;
68+
int get_stale;
69+
int *is_stale;
70+
char **errmsg;
71+
} ngx_http_lua_shdict_get_params_t;
72+
73+
74+
typedef struct {
75+
void *zone;
76+
int op;
77+
const unsigned char *key;
78+
size_t key_len;
79+
int value_type;
80+
const unsigned char *str_value_buf;
81+
size_t str_value_len;
82+
double num_value;
83+
long exptime;
84+
int user_flags;
85+
char **errmsg;
86+
int *forcible;
87+
} ngx_http_lua_shdict_store_params_t;
88+
89+
90+
typedef struct {
91+
void *zone;
92+
const unsigned char *key;
93+
size_t key_len;
94+
double *num_value;
95+
char **errmsg;
96+
int has_init;
97+
double init;
98+
long init_ttl;
99+
int *forcible;
100+
} ngx_http_lua_shdict_incr_params_t;
101+
#endif
102+
103+
58104
ngx_int_t ngx_http_lua_shdict_init_zone(ngx_shm_zone_t *shm_zone, void *data);
59105
void ngx_http_lua_shdict_rbtree_insert_value(ngx_rbtree_node_t *temp,
60106
ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);

0 commit comments

Comments
 (0)