mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Fix bugs and make improvements to redbean
- Abort if .init.lua fails - Refactor redbean to use new append library - Use first certificate if SNI routing fails - Use function/data sections when building Lua - Don't use self-signed auto-generated cert for client - Add -D staging dirs to redbean lua module default path
This commit is contained in:
parent
55a15c204e
commit
aeeb851422
26 changed files with 703 additions and 513 deletions
9
third_party/lua/loadlib.c
vendored
9
third_party/lua/loadlib.c
vendored
|
@ -16,6 +16,8 @@
|
|||
#include "third_party/lua/lua.h"
|
||||
#include "third_party/lua/lualib.h"
|
||||
|
||||
const char *g_lua_path_default = LUA_PATH_DEFAULT;
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/*
|
||||
|
@ -728,12 +730,17 @@ static void createclibstable (lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
static const char *GetLuaPathDefault(void) {
|
||||
return g_lua_path_default;
|
||||
}
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_package (lua_State *L) {
|
||||
createclibstable(L);
|
||||
luaL_newlib(L, pk_funcs); /* create 'package' table */
|
||||
createsearcherstable(L);
|
||||
/* set paths */
|
||||
setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT);
|
||||
setpath(L, "path", LUA_PATH_VAR, g_lua_path_default);
|
||||
setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
|
||||
/* store config information */
|
||||
lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
|
||||
|
|
44
third_party/lua/lua.h
vendored
44
third_party/lua/lua.h
vendored
|
@ -1,15 +1,8 @@
|
|||
/*
|
||||
** $Id: lua.h $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
*/
|
||||
|
||||
#ifndef lua_h
|
||||
#define lua_h
|
||||
|
||||
#ifndef COSMOPOLITAN_THIRD_PARTY_LUA_LUA_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_LUA_LUA_H_
|
||||
#include "third_party/lua/luaconf.h"
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
/* clang-format off */
|
||||
|
||||
#define LUA_VERSION_MAJOR "5"
|
||||
|
@ -489,29 +482,8 @@ struct lua_Debug {
|
|||
|
||||
/* }====================================================================== */
|
||||
|
||||
extern const char *g_lua_path_default;
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (C) 1994-2021 Lua.org, PUC-Rio.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#endif
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_LUA_LUA_H_ */
|
||||
|
|
5
third_party/lua/lua.mk
vendored
5
third_party/lua/lua.mk
vendored
|
@ -60,6 +60,11 @@ o/$(MODE)/third_party/lua/lauxlib.o: \
|
|||
OVERRIDE_CFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED
|
||||
|
||||
$(THIRD_PARTY_LUA_OBJS): \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-ffunction-sections \
|
||||
-fdata-sections
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/lua
|
||||
o/$(MODE)/third_party/lua: \
|
||||
$(THIRD_PARTY_LUA_BINS) \
|
||||
|
|
79
third_party/lua/luaconf.h
vendored
79
third_party/lua/luaconf.h
vendored
|
@ -1,17 +1,13 @@
|
|||
/*
|
||||
** $Id: luaconf.h $
|
||||
** Configuration file for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef luaconf_h
|
||||
#define luaconf_h
|
||||
|
||||
#define LUA_USE_POSIX
|
||||
#include "libc/assert.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
|
||||
#define LUA_USE_POSIX
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/*
|
||||
|
@ -193,63 +189,20 @@
|
|||
*/
|
||||
|
||||
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||
#if defined(_WIN32) /* { */
|
||||
/*
|
||||
** In Windows, any exclamation mark ('!') in the path is replaced by the
|
||||
** path of the directory of the executable file of the current process.
|
||||
*/
|
||||
#define LUA_LDIR "!\\lua\\"
|
||||
#define LUA_CDIR "!\\"
|
||||
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
|
||||
|
||||
#if !defined(LUA_PATH_DEFAULT)
|
||||
#define LUA_PATH_DEFAULT \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
|
||||
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
|
||||
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
|
||||
".\\?.lua;" ".\\?\\init.lua"
|
||||
#endif
|
||||
|
||||
#if !defined(LUA_CPATH_DEFAULT)
|
||||
#define LUA_CPATH_DEFAULT \
|
||||
LUA_CDIR"?.dll;" \
|
||||
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
|
||||
LUA_CDIR"loadall.dll;" ".\\?.dll"
|
||||
#endif
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
#define LUA_ROOT "zip:"
|
||||
#define LUA_LDIR LUA_ROOT ".lua/"
|
||||
#define LUA_CDIR LUA_ROOT ".lua/"
|
||||
|
||||
#if !defined(LUA_PATH_DEFAULT)
|
||||
#define LUA_PATH_DEFAULT \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua"
|
||||
#endif
|
||||
|
||||
#if !defined(LUA_CPATH_DEFAULT)
|
||||
#define LUA_CPATH_DEFAULT \
|
||||
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#define LUA_PATH_DEFAULT LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" "./?.lua;" "./?/init.lua"
|
||||
#define LUA_CPATH_DEFAULT LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
|
||||
|
||||
/*
|
||||
@@ LUA_DIRSEP is the directory separator (for submodules).
|
||||
** CHANGE it if your machine does not use "/" as the directory separator
|
||||
** and is not Windows. (On Windows Lua automatically uses "\".)
|
||||
*/
|
||||
#if !defined(LUA_DIRSEP)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define LUA_DIRSEP "\\"
|
||||
#else
|
||||
#define LUA_DIRSEP "/"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
@ -269,20 +222,8 @@
|
|||
** the libraries, you may want to use the following definition (define
|
||||
** LUA_BUILD_AS_DLL to get it).
|
||||
*/
|
||||
#if defined(LUA_BUILD_AS_DLL) /* { */
|
||||
|
||||
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
|
||||
#define LUA_API __declspec(dllexport)
|
||||
#else /* }{ */
|
||||
#define LUA_API __declspec(dllimport)
|
||||
#endif /* } */
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
#define LUA_API extern
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
/*
|
||||
** More often than not the libs go together with the core.
|
||||
|
@ -305,12 +246,7 @@
|
|||
** give a warning about it. To avoid these warnings, change to the
|
||||
** default definition.
|
||||
*/
|
||||
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
|
||||
defined(__ELF__) /* { */
|
||||
#define LUAI_FUNC /* __attribute__((visibility("internal"))) */ extern
|
||||
#else /* }{ */
|
||||
#define LUAI_FUNC extern
|
||||
#endif /* } */
|
||||
|
||||
#define LUAI_DDEC(dec) LUAI_FUNC dec
|
||||
#define LUAI_DDEF /* empty */
|
||||
|
@ -710,8 +646,7 @@
|
|||
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
|
||||
** Define it as a help when debugging C code.
|
||||
*/
|
||||
#if defined(LUA_USE_APICHECK)
|
||||
#include <assert.h>
|
||||
#if IsModeDbg()
|
||||
#define luai_apicheck(l,e) assert(e)
|
||||
#endif
|
||||
|
||||
|
|
1
third_party/mbedtls/config.h
vendored
1
third_party/mbedtls/config.h
vendored
|
@ -2,6 +2,7 @@
|
|||
#define MBEDTLS_CONFIG_H_
|
||||
#include "libc/dce.h"
|
||||
|
||||
/* /\* uncomment for testing old cpu code paths *\/ */
|
||||
/* #include "libc/nexgen32e/x86feature.h" */
|
||||
/* #undef X86_HAVE */
|
||||
/* #define X86_HAVE(x) 0 */
|
||||
|
|
32
third_party/mbedtls/ecp384.c
vendored
32
third_party/mbedtls/ecp384.c
vendored
|
@ -35,21 +35,22 @@ mbedtls_p384_isz( uint64_t p[6] )
|
|||
return( !p[0] & !p[1] & !p[2] & !p[3] & !p[4] & !p[5] );
|
||||
}
|
||||
|
||||
bool mbedtls_p384_gte( uint64_t p[7] )
|
||||
static bool
|
||||
mbedtls_p384_gte( uint64_t p[7] )
|
||||
{
|
||||
return( (((int64_t)p[6] > 0) |
|
||||
(!p[6] &
|
||||
(p[5] > 0xffffffffffffffff |
|
||||
(p[5] == 0xffffffffffffffff &
|
||||
(p[4] > 0xffffffffffffffff |
|
||||
(p[4] == 0xffffffffffffffff &
|
||||
(p[3] > 0xffffffffffffffff |
|
||||
(p[3] == 0xffffffffffffffff &
|
||||
(p[2] > 0xfffffffffffffffe |
|
||||
(p[2] == 0xfffffffffffffffe &
|
||||
(p[1] > 0xffffffff00000000 |
|
||||
(p[1] == 0xffffffff00000000 &
|
||||
(p[0] > 0x00000000ffffffff |
|
||||
((p[5] > 0xffffffffffffffff) |
|
||||
((p[5] == 0xffffffffffffffff) &
|
||||
((p[4] > 0xffffffffffffffff) |
|
||||
((p[4] == 0xffffffffffffffff) &
|
||||
((p[3] > 0xffffffffffffffff) |
|
||||
((p[3] == 0xffffffffffffffff) &
|
||||
((p[2] > 0xfffffffffffffffe) |
|
||||
((p[2] == 0xfffffffffffffffe) &
|
||||
((p[1] > 0xffffffff00000000) |
|
||||
((p[1] == 0xffffffff00000000) &
|
||||
((p[0] > 0x00000000ffffffff) |
|
||||
(p[0] == 0x00000000ffffffff)))))))))))))) );
|
||||
}
|
||||
|
||||
|
@ -128,7 +129,8 @@ mbedtls_p384_gro( uint64_t p[7] )
|
|||
#endif
|
||||
}
|
||||
|
||||
void mbedtls_p384_rum( uint64_t p[7] )
|
||||
static inline void
|
||||
mbedtls_p384_rum( uint64_t p[7] )
|
||||
{
|
||||
while( mbedtls_p384_gte( p ) )
|
||||
mbedtls_p384_red( p );
|
||||
|
@ -142,9 +144,7 @@ void mbedtls_p384_mod( uint64_t X[12] )
|
|||
mbedtls_p384_gro(X);
|
||||
} while( (int64_t)X[6] < 0 );
|
||||
} else {
|
||||
while( mbedtls_p384_gte(X) ){
|
||||
mbedtls_p384_red(X);
|
||||
}
|
||||
mbedtls_p384_rum(X);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1
third_party/mbedtls/ecp_internal.h
vendored
1
third_party/mbedtls/ecp_internal.h
vendored
|
@ -261,7 +261,6 @@ int mbedtls_p384_normalize_jac( const mbedtls_ecp_group *,
|
|||
int mbedtls_p384_normalize_jac_many( const mbedtls_ecp_group *,
|
||||
mbedtls_ecp_point *[], size_t );
|
||||
|
||||
void mbedtls_p384_rum( uint64_t p[7] );
|
||||
void mbedtls_p384_mod( uint64_t X[12] );
|
||||
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_MBEDTLS_ECP_INTERNAL_H_ */
|
||||
|
|
39
third_party/mbedtls/test/secp384r1_test.c
vendored
39
third_party/mbedtls/test/secp384r1_test.c
vendored
|
@ -27,6 +27,8 @@
|
|||
#include "third_party/mbedtls/math.h"
|
||||
#ifdef MBEDTLS_ECP_C
|
||||
|
||||
/*P=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff*/
|
||||
|
||||
int ecp_mod_p384_old(mbedtls_mpi *);
|
||||
|
||||
int GetEntropy(void *c, unsigned char *p, size_t n) {
|
||||
|
@ -97,14 +99,6 @@ TEST(secp384r1, needsDownwardCorrection) {
|
|||
|
||||
TEST(secp384r1, needsUpwardCorrection) {
|
||||
int i;
|
||||
uint64_t P[6] = {
|
||||
0x00000000ffffffff, //
|
||||
0xffffffff00000000, //
|
||||
0xfffffffffffffffe, //
|
||||
0xffffffffffffffff, //
|
||||
0xffffffffffffffff, //
|
||||
0xffffffffffffffff, //
|
||||
};
|
||||
uint64_t X[12] = {
|
||||
0x0000000000000000, //
|
||||
0x0000000000000000, //
|
||||
|
@ -136,6 +130,35 @@ TEST(secp384r1, needsUpwardCorrection) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(secp384r1, largestInput_quasiModNeedsTwoDownwardCorrections) {
|
||||
int i;
|
||||
uint64_t X[12] = {
|
||||
// X = (P-1)*(P-1)
|
||||
0xfffffffc00000004, //
|
||||
0x0000000400000000, //
|
||||
0xfffffffe00000002, //
|
||||
0x0000000200000000, //
|
||||
0x0000000000000001, //
|
||||
0x0000000000000000, //
|
||||
0x00000001fffffffc, //
|
||||
0xfffffffe00000000, //
|
||||
0xfffffffffffffffd, //
|
||||
0xffffffffffffffff, //
|
||||
0xffffffffffffffff, //
|
||||
0xffffffffffffffff, //
|
||||
};
|
||||
uint64_t W[12] /* W = X mod P */ = {
|
||||
0x0000000000000001, //
|
||||
};
|
||||
mbedtls_p384_mod(X);
|
||||
if (memcmp(W, X, 12 * 8)) {
|
||||
for (i = 0; i < 12; ++i) {
|
||||
printf("0x%016lx vs. 0x%016lx %d\n", W[i], X[i], W[i] == X[i]);
|
||||
}
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
||||
BENCH(secp384r1, bench) {
|
||||
mbedtls_mpi A;
|
||||
mbedtls_mpi_init(&A);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue