You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
12 KiB

  1. commit 330e08dfc588dc9b0ad42203123fab6c191ca2f8
  2. Author: Willy Tarreau <w@1wt.eu>
  3. Date: Tue Oct 16 17:52:55 2018 +0200
  4. MINOR: lua: all functions calling lua_yieldk() may return
  5. There was a mistake when tagging functions which always use longjmp and
  6. those which may use it in that all those supposed to call lua_yieldk()
  7. may return without calling longjmp. Thus they must not use WILL_LJMP()
  8. but MAY_LJMP(). It has zero impact on the code emitted as such, but
  9. prevents other fixes from being properly implemented : this was the
  10. cause of the previous failure with the __unreachable() calls.
  11. This may be backported to older versions. It may or may not apply
  12. well depending on the context, though the change simply consists in
  13. replacing "WILL_LJMP(hlua_yieldk" with "MAY_LJMP(hlua_yieldk", and
  14. same with the single call to lua_yieldk() in hlua_yieldk().
  15. (cherry picked from commit 9635e03c41e95dff38731f67cc9d8b00e3731d2a)
  16. Signed-off-by: Willy Tarreau <w@1wt.eu>
  17. diff --git a/src/hlua.c b/src/hlua.c
  18. index 60ba94ea..64102e8a 100644
  19. --- a/src/hlua.c
  20. +++ b/src/hlua.c
  21. @@ -852,7 +852,7 @@ __LJMP void hlua_yieldk(lua_State *L, int nresults, int ctx,
  22. hlua->flags |= flags;
  23. /* Process the yield. */
  24. - WILL_LJMP(lua_yieldk(L, nresults, ctx, k));
  25. + MAY_LJMP(lua_yieldk(L, nresults, ctx, k));
  26. }
  27. /* This function initialises the Lua environment stored in the stream.
  28. @@ -1003,7 +1003,7 @@ void hlua_hook(lua_State *L, lua_Debug *ar)
  29. * If the state is not yieldable, trying yield causes an error.
  30. */
  31. if (lua_isyieldable(L))
  32. - WILL_LJMP(hlua_yieldk(L, 0, 0, NULL, TICK_ETERNITY, HLUA_CTRLYIELD));
  33. + MAY_LJMP(hlua_yieldk(L, 0, 0, NULL, TICK_ETERNITY, HLUA_CTRLYIELD));
  34. /* If we cannot yield, update the clock and check the timeout. */
  35. tv_update_date(0, 1);
  36. @@ -1883,7 +1883,7 @@ connection_empty:
  37. WILL_LJMP(luaL_error(L, "out of memory"));
  38. }
  39. xref_unlock(&socket->xref, peer);
  40. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_receive_yield, TICK_ETERNITY, 0));
  41. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_receive_yield, TICK_ETERNITY, 0));
  42. return 0;
  43. }
  44. @@ -2082,7 +2082,7 @@ hlua_socket_write_yield_return:
  45. WILL_LJMP(luaL_error(L, "out of memory"));
  46. }
  47. xref_unlock(&socket->xref, peer);
  48. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_write_yield, TICK_ETERNITY, 0));
  49. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_write_yield, TICK_ETERNITY, 0));
  50. return 0;
  51. }
  52. @@ -2375,7 +2375,7 @@ __LJMP static int hlua_socket_connect_yield(struct lua_State *L, int status, lua
  53. WILL_LJMP(luaL_error(L, "out of memory error"));
  54. }
  55. xref_unlock(&socket->xref, peer);
  56. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
  57. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
  58. return 0;
  59. }
  60. @@ -2493,7 +2493,7 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
  61. task_wakeup(s->task, TASK_WOKEN_INIT);
  62. /* Return yield waiting for connection. */
  63. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
  64. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
  65. return 0;
  66. }
  67. @@ -2819,7 +2819,7 @@ __LJMP static int hlua_channel_dup_yield(lua_State *L, int status, lua_KContext
  68. chn = MAY_LJMP(hlua_checkchannel(L, 1));
  69. if (_hlua_channel_dup(chn, L) == 0)
  70. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup_yield, TICK_ETERNITY, 0));
  71. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup_yield, TICK_ETERNITY, 0));
  72. return 1;
  73. }
  74. @@ -2845,7 +2845,7 @@ __LJMP static int hlua_channel_get_yield(lua_State *L, int status, lua_KContext
  75. ret = _hlua_channel_dup(chn, L);
  76. if (unlikely(ret == 0))
  77. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_get_yield, TICK_ETERNITY, 0));
  78. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_get_yield, TICK_ETERNITY, 0));
  79. if (unlikely(ret == -1))
  80. return 1;
  81. @@ -2883,7 +2883,7 @@ __LJMP static int hlua_channel_getline_yield(lua_State *L, int status, lua_KCont
  82. ret = ci_getline_nc(chn, &blk1, &len1, &blk2, &len2);
  83. if (ret == 0)
  84. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_getline_yield, TICK_ETERNITY, 0));
  85. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_getline_yield, TICK_ETERNITY, 0));
  86. if (ret == -1) {
  87. lua_pushnil(L);
  88. @@ -2932,7 +2932,7 @@ __LJMP static int hlua_channel_append_yield(lua_State *L, int status, lua_KConte
  89. */
  90. if (chn->buf->size == 0) {
  91. si_applet_cant_put(chn_prod(chn));
  92. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
  93. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
  94. }
  95. max = channel_recv_limit(chn) - buffer_len(chn->buf);
  96. @@ -2946,7 +2946,7 @@ __LJMP static int hlua_channel_append_yield(lua_State *L, int status, lua_KConte
  97. }
  98. if (ret == -1) {
  99. chn->flags |= CF_WAKE_WRITE;
  100. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
  101. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
  102. }
  103. l += ret;
  104. lua_pop(L, 1);
  105. @@ -2962,7 +2962,7 @@ __LJMP static int hlua_channel_append_yield(lua_State *L, int status, lua_KConte
  106. return 1;
  107. }
  108. if (l < len)
  109. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
  110. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
  111. return 1;
  112. }
  113. @@ -3026,7 +3026,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
  114. */
  115. if (chn->buf->size == 0) {
  116. si_applet_cant_put(chn_prod(chn));
  117. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_send_yield, TICK_ETERNITY, 0));
  118. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_send_yield, TICK_ETERNITY, 0));
  119. }
  120. /* the writed data will be immediatly sent, so we can check
  121. @@ -3082,7 +3082,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
  122. HLUA_SET_WAKERESWR(hlua);
  123. else
  124. HLUA_SET_WAKEREQWR(hlua);
  125. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_send_yield, TICK_ETERNITY, 0));
  126. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_send_yield, TICK_ETERNITY, 0));
  127. }
  128. return 1;
  129. @@ -3146,7 +3146,7 @@ __LJMP static int hlua_channel_forward_yield(lua_State *L, int status, lua_KCont
  130. HLUA_SET_WAKEREQWR(hlua);
  131. /* Otherwise, we can yield waiting for new data in the inpout side. */
  132. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_forward_yield, TICK_ETERNITY, 0));
  133. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_forward_yield, TICK_ETERNITY, 0));
  134. }
  135. return 1;
  136. @@ -3654,7 +3654,7 @@ __LJMP static int hlua_applet_tcp_getline_yield(lua_State *L, int status, lua_KC
  137. /* Data not yet avalaible. return yield. */
  138. if (ret == 0) {
  139. si_applet_cant_get(si);
  140. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_getline_yield, TICK_ETERNITY, 0));
  141. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_getline_yield, TICK_ETERNITY, 0));
  142. }
  143. /* End of data: commit the total strings and return. */
  144. @@ -3709,7 +3709,7 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
  145. /* Data not yet avalaible. return yield. */
  146. if (ret == 0) {
  147. si_applet_cant_get(si);
  148. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
  149. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
  150. }
  151. /* End of data: commit the total strings and return. */
  152. @@ -3732,7 +3732,7 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
  153. luaL_addlstring(&appctx->b, blk2, len2);
  154. co_skip(si_oc(si), len1 + len2);
  155. si_applet_cant_get(si);
  156. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
  157. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
  158. } else {
  159. @@ -3756,7 +3756,7 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
  160. lua_pushinteger(L, len);
  161. lua_replace(L, 2);
  162. si_applet_cant_get(si);
  163. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
  164. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
  165. }
  166. /* return the result. */
  167. @@ -3825,7 +3825,7 @@ __LJMP static int hlua_applet_tcp_send_yield(lua_State *L, int status, lua_KCont
  168. */
  169. if (l < len) {
  170. si_applet_cant_put(si);
  171. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_send_yield, TICK_ETERNITY, 0));
  172. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_send_yield, TICK_ETERNITY, 0));
  173. }
  174. return 1;
  175. @@ -4122,7 +4122,7 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
  176. */
  177. if (ret == -1) {
  178. si_applet_cant_put(si);
  179. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_getline_yield, TICK_ETERNITY, 0));
  180. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_getline_yield, TICK_ETERNITY, 0));
  181. }
  182. appctx->appctx->ctx.hlua_apphttp.flags &= ~APPLET_100C;
  183. }
  184. @@ -4139,7 +4139,7 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
  185. /* Data not yet avalaible. return yield. */
  186. if (ret == 0) {
  187. si_applet_cant_get(si);
  188. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_getline_yield, TICK_ETERNITY, 0));
  189. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_getline_yield, TICK_ETERNITY, 0));
  190. }
  191. /* End of data: commit the total strings and return. */
  192. @@ -4208,7 +4208,7 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
  193. */
  194. if (ret == -1) {
  195. si_applet_cant_put(si);
  196. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_recv_yield, TICK_ETERNITY, 0));
  197. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_recv_yield, TICK_ETERNITY, 0));
  198. }
  199. appctx->appctx->ctx.hlua_apphttp.flags &= ~APPLET_100C;
  200. }
  201. @@ -4219,7 +4219,7 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
  202. /* Data not yet avalaible. return yield. */
  203. if (ret == 0) {
  204. si_applet_cant_get(si);
  205. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_recv_yield, TICK_ETERNITY, 0));
  206. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_recv_yield, TICK_ETERNITY, 0));
  207. }
  208. /* End of data: commit the total strings and return. */
  209. @@ -4254,7 +4254,7 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
  210. lua_pushinteger(L, len);
  211. lua_replace(L, 2);
  212. si_applet_cant_get(si);
  213. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_recv_yield, TICK_ETERNITY, 0));
  214. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_recv_yield, TICK_ETERNITY, 0));
  215. }
  216. /* return the result. */
  217. @@ -4320,7 +4320,7 @@ __LJMP static int hlua_applet_http_send_yield(lua_State *L, int status, lua_KCon
  218. */
  219. if (l < len) {
  220. si_applet_cant_put(si);
  221. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_send_yield, TICK_ETERNITY, 0));
  222. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_send_yield, TICK_ETERNITY, 0));
  223. }
  224. return 1;
  225. @@ -4460,7 +4460,7 @@ __LJMP static int hlua_applet_http_start_response_yield(lua_State *L, int status
  226. /* If ret is -1, we dont have room in the buffer, so we yield. */
  227. if (ret == -1) {
  228. si_applet_cant_put(si);
  229. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_start_response_yield, TICK_ETERNITY, 0));
  230. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_start_response_yield, TICK_ETERNITY, 0));
  231. }
  232. /* Headers sent, set the flag. */
  233. @@ -5510,7 +5510,7 @@ __LJMP static int hlua_sleep_yield(lua_State *L, int status, lua_KContext ctx)
  234. {
  235. int wakeup_ms = lua_tointeger(L, -1);
  236. if (now_ms < wakeup_ms)
  237. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
  238. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
  239. return 0;
  240. }
  241. @@ -5525,7 +5525,7 @@ __LJMP static int hlua_sleep(lua_State *L)
  242. wakeup_ms = tick_add(now_ms, delay);
  243. lua_pushinteger(L, wakeup_ms);
  244. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
  245. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
  246. return 0;
  247. }
  248. @@ -5540,7 +5540,7 @@ __LJMP static int hlua_msleep(lua_State *L)
  249. wakeup_ms = tick_add(now_ms, delay);
  250. lua_pushinteger(L, wakeup_ms);
  251. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
  252. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
  253. return 0;
  254. }
  255. @@ -5555,7 +5555,7 @@ __LJMP static int hlua_yield_yield(lua_State *L, int status, lua_KContext ctx)
  256. __LJMP static int hlua_yield(lua_State *L)
  257. {
  258. - WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_yield_yield, TICK_ETERNITY, HLUA_CTRLYIELD));
  259. + MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_yield_yield, TICK_ETERNITY, HLUA_CTRLYIELD));
  260. return 0;
  261. }