Skip to content

Commit 5eafe03

Browse files
spacewanderagentzh
authored andcommitted
feature: added support for ARM64 (AArch64).
now we require OpenResty's LuaJIT branch to work properly on ARM64 since we make use of the thread.exdata Lua API. also implemented the ndk.* API with FFI. Thanks Dejiang Zhu and Zexuan Luo for the development work of this patch. Thanks Cloudflare for sponsoring this work. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent bdbac70 commit 5eafe03

36 files changed

+3956
-112
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ install:
6666
- git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
6767
- git clone https://github.com/openresty/lua-resty-lrucache.git
6868
- git clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module
69-
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git
69+
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git luajit2
70+
- git clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module
7071
- git clone https://github.com/openresty/mockeagain.git
7172
- git clone https://github.com/openresty/test-nginx.git
7273
- git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module
@@ -102,7 +103,7 @@ script:
102103
- export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH
103104
- export TEST_NGINX_RESOLVER=8.8.4.4
104105
- export NGX_BUILD_CC=$CC
105-
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-pcre-jit --with-cc-opt="-I$OPENSSL_INC -I$PCRE_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB -L$PCRE_LIB -Wl,-rpath,$PCRE_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug --with-stream_ssl_module --with-stream --with-ipv6 --add-module=../stream-lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1)
106+
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-pcre-jit --with-cc-opt="-I$OPENSSL_INC -I$PCRE_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB -L$PCRE_LIB -Wl,-rpath,$PCRE_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../set-misc-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug --with-stream_ssl_module --with-stream --with-ipv6 --add-module=../stream-lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1)
106107
- nginx -V
107108
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
108109
- prove -Itest-nginx/lib -j$JOBS -r t

README.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ API Implemented
230230

231231
[Back to TOC](#table-of-contents)
232232

233+
## resty.core.ndk
234+
235+
* [ndk.set_var](https://github.com/openresty/lua-nginx-module#ndkset_vardirective)
236+
233237
## ngx.semaphore
234238

235239
This Lua module implements a semaphore API for efficient "light thread" synchronization,

lib/ngx/balancer.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local errmsg = base.get_errmsg_ptr()
1212
local FFI_OK = base.FFI_OK
1313
local FFI_ERROR = base.FFI_ERROR
1414
local int_out = ffi.new("int[1]")
15-
local getfenv = getfenv
15+
local get_request = base.get_request
1616
local error = error
1717
local type = type
1818
local tonumber = tonumber
@@ -104,7 +104,7 @@ local _M = { version = base.version }
104104

105105

106106
function _M.set_current_peer(addr, port)
107-
local r = getfenv(0).__ngx_req
107+
local r = get_request()
108108
if not r then
109109
error("no request found")
110110
end
@@ -126,7 +126,7 @@ end
126126

127127

128128
function _M.set_more_tries(count)
129-
local r = getfenv(0).__ngx_req
129+
local r = get_request()
130130
if not r then
131131
error("no request found")
132132
end
@@ -144,7 +144,7 @@ end
144144

145145

146146
function _M.get_last_failure()
147-
local r = getfenv(0).__ngx_req
147+
local r = get_request()
148148
if not r then
149149
error("no request found")
150150
end
@@ -164,7 +164,7 @@ end
164164

165165

166166
function _M.set_timeouts(connect_timeout, send_timeout, read_timeout)
167-
local r = getfenv(0).__ngx_req
167+
local r = get_request()
168168
if not r then
169169
error("no request found")
170170
end

lib/ngx/errlog.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local ffi_new = ffi.new
1515
local charpp = ffi_new("char *[1]")
1616
local intp = ffi.new("int[1]")
1717
local num_value = ffi_new("double[1]")
18-
local getfenv = getfenv
18+
local get_request = base.get_request
1919
local tonumber = tonumber
2020
local type = type
2121
local error = error
@@ -107,7 +107,7 @@ end
107107

108108

109109
function _M.get_sys_filter_level()
110-
local r = getfenv(0).__ngx_req
110+
local r = get_request()
111111
return tonumber(C.ngx_http_lua_ffi_errlog_get_sys_filter_level(r))
112112
end
113113

@@ -121,7 +121,7 @@ function _M.raw_log(level, msg)
121121
error("bad argument #2 to 'raw_log' (must be a string)", 2)
122122
end
123123

124-
local r = getfenv(0).__ngx_req
124+
local r = get_request()
125125

126126
local rc = C.ngx_http_lua_ffi_raw_log(r, level, msg, #msg)
127127

lib/ngx/ocsp.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ base.allows_subsystem('http')
88
local ffi = require "ffi"
99
local C = ffi.C
1010
local ffi_str = ffi.string
11-
local getfenv = getfenv
11+
local get_request = base.get_request
1212
local error = error
1313
local tonumber = tonumber
1414
local errmsg = base.get_errmsg_ptr()
@@ -123,7 +123,7 @@ end
123123

124124

125125
function _M.set_ocsp_status_resp(ocsp_resp)
126-
local r = getfenv(0).__ngx_req
126+
local r = get_request()
127127
if not r then
128128
error("no request found")
129129
end

lib/ngx/re.lua

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44

55
local base = require "resty.core.base"
6-
base.allows_subsystem('http')
7-
8-
96
local ffi = require 'ffi'
107
local bit = require "bit"
118
local core_regex = require "resty.core.regex"
@@ -27,6 +24,7 @@ local destroy_compiled_regex = core_regex.destroy_compiled_regex
2724
local get_string_buf = base.get_string_buf
2825
local get_size_ptr = base.get_size_ptr
2926
local FFI_OK = base.FFI_OK
27+
local subsystem = ngx.config.subsystem
3028

3129

3230
local MAX_ERR_MSG_LEN = 128
@@ -36,12 +34,28 @@ local DEFAULT_SPLIT_RES_SIZE = 4
3634

3735

3836
local split_ctx = new_tab(0, 1)
37+
local ngx_lua_ffi_set_jit_stack_size
38+
local ngx_lua_ffi_exec_regex
3939

4040

41-
ffi.cdef[[
41+
if subsystem == 'http' then
42+
ffi.cdef[[
4243
int ngx_http_lua_ffi_set_jit_stack_size(int size, unsigned char *errstr,
4344
size_t *errstr_size);
44-
]]
45+
]]
46+
47+
ngx_lua_ffi_exec_regex = C.ngx_http_lua_ffi_exec_regex
48+
ngx_lua_ffi_set_jit_stack_size = C.ngx_http_lua_ffi_set_jit_stack_size
49+
50+
elseif subsystem == 'stream' then
51+
ffi.cdef[[
52+
int ngx_stream_lua_ffi_set_jit_stack_size(int size, unsigned char *errstr,
53+
size_t *errstr_size);
54+
]]
55+
56+
ngx_lua_ffi_exec_regex = C.ngx_stream_lua_ffi_exec_regex
57+
ngx_lua_ffi_set_jit_stack_size = C.ngx_stream_lua_ffi_set_jit_stack_size
58+
end
4559

4660

4761
local _M = { version = base.version }
@@ -52,7 +66,7 @@ local function re_split_helper(subj, compiled, compile_once, flags, ctx)
5266
do
5367
local pos = math_max(ctx.pos, 0)
5468

55-
rc = C.ngx_http_lua_ffi_exec_regex(compiled, flags, subj, #subj, pos)
69+
rc = ngx_lua_ffi_exec_regex(compiled, flags, subj, #subj, pos)
5670
end
5771

5872
if rc == PCRE_ERROR_NOMATCH then
@@ -282,7 +296,7 @@ function _M.opt(option, value)
282296
local sizep = get_size_ptr()
283297
sizep[0] = MAX_ERR_MSG_LEN
284298

285-
local rc = C.ngx_http_lua_ffi_set_jit_stack_size(value, errbuf, sizep)
299+
local rc = ngx_lua_ffi_set_jit_stack_size(value, errbuf, sizep)
286300

287301
if rc == FFI_OK then
288302
return

lib/ngx/semaphore.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local C = ffi.C
1919
local type = type
2020
local error = error
2121
local tonumber = tonumber
22-
local getfenv = getfenv
22+
local get_request = base.get_request
2323
local get_string_buf = base.get_string_buf
2424
local get_size_ptr = base.get_size_ptr
2525
local setmetatable = setmetatable
@@ -121,7 +121,7 @@ function _M.wait(self, seconds)
121121
error("not a semaphore instance", 2)
122122
end
123123

124-
local r = getfenv(0).__ngx_req
124+
local r = get_request()
125125
if not r then
126126
error("no request found")
127127
end

lib/ngx/ssl.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local ffi = require "ffi"
99
local C = ffi.C
1010
local ffi_str = ffi.string
1111
local ffi_gc = ffi.gc
12-
local getfenv = getfenv
12+
local get_request = base.get_request
1313
local error = error
1414
local tonumber = tonumber
1515
local errmsg = base.get_errmsg_ptr()
@@ -73,7 +73,7 @@ local intp = ffi.new("int[1]")
7373

7474

7575
function _M.clear_certs()
76-
local r = getfenv(0).__ngx_req
76+
local r = get_request()
7777
if not r then
7878
error("no request found")
7979
end
@@ -88,7 +88,7 @@ end
8888

8989

9090
function _M.set_der_cert(data)
91-
local r = getfenv(0).__ngx_req
91+
local r = get_request()
9292
if not r then
9393
error("no request found")
9494
end
@@ -104,7 +104,7 @@ end
104104

105105

106106
function _M.set_der_priv_key(data)
107-
local r = getfenv(0).__ngx_req
107+
local r = get_request()
108108
if not r then
109109
error("no request found")
110110
end
@@ -127,7 +127,7 @@ local addr_types = {
127127

128128

129129
function _M.raw_server_addr()
130-
local r = getfenv(0).__ngx_req
130+
local r = get_request()
131131
if not r then
132132
error("no request found")
133133
end
@@ -149,7 +149,7 @@ end
149149

150150

151151
function _M.server_name()
152-
local r = getfenv(0).__ngx_req
152+
local r = get_request()
153153
if not r then
154154
error("no request found")
155155
end
@@ -170,7 +170,7 @@ end
170170

171171

172172
function _M.raw_client_addr()
173-
local r = getfenv(0).__ngx_req
173+
local r = get_request()
174174
if not r then
175175
error("no request found")
176176
end
@@ -217,7 +217,7 @@ end
217217

218218
local function get_tls1_version()
219219

220-
local r = getfenv(0).__ngx_req
220+
local r = get_request()
221221
if not r then
222222
error("no request found")
223223
end
@@ -258,7 +258,7 @@ end
258258

259259

260260
function _M.set_cert(cert)
261-
local r = getfenv(0).__ngx_req
261+
local r = get_request()
262262
if not r then
263263
error("no request found")
264264
end
@@ -273,7 +273,7 @@ end
273273

274274

275275
function _M.set_priv_key(priv_key)
276-
local r = getfenv(0).__ngx_req
276+
local r = get_request()
277277
if not r then
278278
error("no request found")
279279
end

lib/ngx/ssl/session.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ base.allows_subsystem('http')
88
local ffi = require "ffi"
99
local C = ffi.C
1010
local ffi_str = ffi.string
11-
local getfenv = getfenv
11+
local get_request = base.get_request
1212
local error = error
1313
local errmsg = base.get_errmsg_ptr()
1414
local get_string_buf = base.get_string_buf
@@ -38,7 +38,7 @@ local _M = { version = base.version }
3838

3939
-- return session, err
4040
function _M.get_serialized_session()
41-
local r = getfenv(0).__ngx_req
41+
local r = get_request()
4242
if not r then
4343
error("no request found")
4444
end
@@ -66,7 +66,7 @@ end
6666

6767
-- return session_id, err
6868
function _M.get_session_id()
69-
local r = getfenv(0).__ngx_req
69+
local r = get_request()
7070
if not r then
7171
error("no request found")
7272
end
@@ -91,7 +91,7 @@ end
9191

9292
-- return ok, err
9393
function _M.set_serialized_session(sess)
94-
local r = getfenv(0).__ngx_req
94+
local r = get_request()
9595
if not r then
9696
error("no request found")
9797
end

lib/resty/core.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
local subsystem = ngx.config.subsystem
44

55

6+
require "resty.core.regex"
67
require "resty.core.shdict"
8+
require "resty.core.time"
79

810

911
if subsystem == 'http' then
@@ -20,6 +22,7 @@ if subsystem == 'http' then
2022
require "resty.core.time"
2123
require "resty.core.worker"
2224
require "resty.core.phase"
25+
require "resty.core.ndk"
2326
end
2427

2528

0 commit comments

Comments
 (0)