lua_vmprep.c revision 679c5329c641e9de6ae65ad1e5b6cb4c9d0ed4b6
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Licensed to the Apache Software Foundation (ASF) under one or more
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * contributor license agreements. See the NOTICE file distributed with
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * this work for additional information regarding copyright ownership.
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * The ASF licenses this file to You under the Apache License, Version 2.0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * (the "License"); you may not use this file except in compliance with
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the License. You may obtain a copy of the License at
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Unless required by applicable law or agreed to in writing, software
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * distributed under the License is distributed on an "AS IS" BASIS,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * See the License for the specific language governing permissions and
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * limitations under the License.
64185f9824e42f21ca7b9ae6c004484215c031a7rbbint ap_lua_register_mutex(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding ap_mutex_register(p, "lua-shm", NULL, APR_LOCK_DEFAULT, 0);
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fieldingvoid ap_lua_init_mutex(apr_pool_t *pool, server_rec *s)
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding ap_proc_mutex_create(&ap_lua_mutex, NULL, "lua-shm", NULL, s, pool, 0);
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding/* forward dec'l from this file */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void pstack_dump(lua_State *L, apr_pool_t *r, int level,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *msg)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding int t = lua_type(L, i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (t) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: userdata", i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: lightuserdata",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: NIL", i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: None", i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding i) ? "true" :
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: <table>", i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: <thread>", i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, level, 0, r, "%d: <function>", i);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* BEGIN modules*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* BEGIN apache lmodule */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define makeintegerfield(L, n) lua_pushinteger(L, n); lua_setfield(L, -2, #n)
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingAP_LUA_DECLARE(void) ap_lua_load_apache2_lmodule(lua_State *L)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_CONTINUE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_SWITCHING_PROTOCOLS);
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb makeintegerfield(L, HTTP_PROCESSING);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_OK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_CREATED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_ACCEPTED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NON_AUTHORITATIVE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NO_CONTENT);
032b8a34c3911bbc5ad5385ca40af65af273bff9wrowe makeintegerfield(L, HTTP_RESET_CONTENT);
032b8a34c3911bbc5ad5385ca40af65af273bff9wrowe makeintegerfield(L, HTTP_PARTIAL_CONTENT);
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb makeintegerfield(L, HTTP_MULTI_STATUS);
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb makeintegerfield(L, HTTP_ALREADY_REPORTED);
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb makeintegerfield(L, HTTP_IM_USED);
5fac45c1ef49924141fe28497deb350cf031b377trawick makeintegerfield(L, HTTP_MULTIPLE_CHOICES);
5fac45c1ef49924141fe28497deb350cf031b377trawick makeintegerfield(L, HTTP_MOVED_PERMANENTLY);
5fac45c1ef49924141fe28497deb350cf031b377trawick makeintegerfield(L, HTTP_MOVED_TEMPORARILY);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_SEE_OTHER);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NOT_MODIFIED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_USE_PROXY);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_TEMPORARY_REDIRECT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_PERMANENT_REDIRECT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_BAD_REQUEST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_UNAUTHORIZED);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe makeintegerfield(L, HTTP_PAYMENT_REQUIRED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_FORBIDDEN);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NOT_FOUND);
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick makeintegerfield(L, HTTP_METHOD_NOT_ALLOWED);
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick makeintegerfield(L, HTTP_NOT_ACCEPTABLE);
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick makeintegerfield(L, HTTP_PROXY_AUTHENTICATION_REQUIRED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_REQUEST_TIME_OUT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_CONFLICT);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm makeintegerfield(L, HTTP_GONE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_LENGTH_REQUIRED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_PRECONDITION_FAILED);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm makeintegerfield(L, HTTP_REQUEST_ENTITY_TOO_LARGE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_REQUEST_URI_TOO_LARGE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_UNSUPPORTED_MEDIA_TYPE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_RANGE_NOT_SATISFIABLE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_EXPECTATION_FAILED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_UNPROCESSABLE_ENTITY);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_LOCKED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_FAILED_DEPENDENCY);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_UPGRADE_REQUIRED);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm makeintegerfield(L, HTTP_PRECONDITION_REQUIRED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_TOO_MANY_REQUESTS);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_INTERNAL_SERVER_ERROR);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NOT_IMPLEMENTED);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm makeintegerfield(L, HTTP_BAD_GATEWAY);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_SERVICE_UNAVAILABLE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_GATEWAY_TIME_OUT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_VERSION_NOT_SUPPORTED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_VARIANT_ALSO_VARIES);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_INSUFFICIENT_STORAGE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_LOOP_DETECTED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NOT_EXTENDED);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding makeintegerfield(L, HTTP_NETWORK_AUTHENTICATION_REQUIRED);
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick/* END apache2 lmodule */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* END library functions */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* callback for cleaning up a lua vm when pool is closed */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_status_t server_cleanup_lua(void *resource)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_lua_server_spec* spec = (ap_lua_server_spec*) resource;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding munge_path(L,
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick lifecycle_pool,
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick spec->package_paths,
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick spec->file);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * field -> "path" or "cpath"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sub_pat -> "?.lua"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * rep_pat -> "./?.lua"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * pool -> lifecycle pool for allocations
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * paths -> things to add
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * file -> ???
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *field,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *sub_pat,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *rep_pat,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *file)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *current;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *pattern;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *modified;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding part = apr_pstrcat(pool, modified, ";", apr_array_pstrcat(pool, paths, ';'),
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int loadjitmodule(lua_State *L, apr_pool_t *lifecycle_pool) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01480)
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_status_t vm_construct(lua_State **vm, void *params, apr_pool_t *lifecycle_pool)
f54da7877f9e092465df38bfda142f3e71dbb7aawrowe munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01481)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rc != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_perror(APLOG_MARK, APLOG_ERR, 0, lifecycle_pool, APLOGNO(01482)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingap_lua_vm_spec* copy_vm_spec(apr_pool_t* pool, ap_lua_vm_spec* spec)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_lua_vm_spec* copied_spec = apr_pcalloc(pool, sizeof(ap_lua_vm_spec));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding copied_spec->bytecode = spec->bytecode ? apr_pstrdup(pool, spec->bytecode) : 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding copied_spec->file = spec->file ? apr_pstrdup(pool, spec->file) : 0;
066877f1a045103acfdd376d48cdd473c33f409bdougm copied_spec->package_cpaths = apr_array_copy(pool, spec->package_cpaths);
1465b960f95b4afba4f4221054dd09e11509bd40rbb copied_spec->package_paths = apr_array_copy(pool, spec->package_paths);
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_status_t server_vm_construct(lua_State **resource, void *params, apr_pool_t *pool)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_lua_server_spec* spec = apr_pcalloc(pool, sizeof(ap_lua_server_spec));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding spec->finfo = apr_pcalloc(pool, sizeof(ap_lua_finfo));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (L != NULL) {
577a76180006add04a166b12f1ad130aeedeaa5estoddard lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Lua.server_spec");
577a76180006add04a166b12f1ad130aeedeaa5estoddard * Function used to create a lua_State instance bound into the web
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * server in the appropriate scope.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
int tryCache = 0;
char *hash;
#if APR_HAS_THREADS
L = sspec->L;
if (L == NULL) {
L = sspec->L;
#if APR_HAS_THREADS
L = NULL;
if(L==NULL) {
char* mkey;
int rc;
if (rc != 0) {
: lua_tostring(L, 0));