Improve open source compatibility

This change tunes the default stack size for the outside world to 8mb
while at the same time, reducing Cosmopolitan's default stack size to
64kb. You can override the stack size using STATIC_STACK_SIZE(). Your
build scripts should point to o//ape/public/ape.lds

This change also fixes the definition of SOMAXCONN and removes AF_RDS
since it's not polyfilled and Python 3.11 complained.
This commit is contained in:
Justine Tunney 2022-09-08 02:48:17 -07:00
parent 0e2b1bfeed
commit b73e35c6fa
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
13 changed files with 50 additions and 26 deletions

View file

@ -72,6 +72,22 @@ o/$(MODE)/ape/ape.lds: \
libc/str/str.h \
libc/zip.h
o/$(MODE)/ape/public/ape.lds: OVERRIDE_CPPFLAGS += -UCOSMO
o/$(MODE)/ape/public/ape.lds: \
ape/public/ape.lds \
ape/ape.lds \
ape/macros.internal.h \
ape/relocations.h \
libc/intrin/bits.h \
libc/calls/struct/timespec.h \
libc/dce.h \
libc/elf/def.h \
libc/elf/pf2prot.internal.h \
libc/macros.internal.h \
libc/nt/pedef.internal.h \
libc/str/str.h \
libc/zip.h
o/ape/idata.inc: \
ape/idata.internal.h \
ape/relocations.h
@ -159,6 +175,7 @@ o/$(MODE)/ape/ape.macho.dbg: \
o/$(MODE)/ape: $(APE_CHECKS) \
o/$(MODE)/ape/ape.o \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/ape/ape.elf \
o/$(MODE)/ape/ape.macho \
o/$(MODE)/ape/ape-copy-self.o \

1
ape/public/ape.lds Normal file
View file

@ -0,0 +1 @@
#include "ape/ape.lds"

View file

@ -66,8 +66,16 @@
#define __BIGGEST_ALIGNMENT__ 16
#endif
/* TODO(jart): Remove this in favor of GetStackSize() */
#if defined(COSMO) && defined(MODE_DBG)
#define STACKSIZE 0x20000 /* 128kb stack */
#elif defined(COSMO)
#define STACKSIZE 0x10000 /* 64kb stack */
#else
#define STACKSIZE 0x800000 /* 8mb stack */
#endif
#define BIGPAGESIZE 0x200000
#define STACKSIZE 0x20000
#define FRAMESIZE 0x10000 /* 8086 */
#define PAGESIZE 0x1000 /* i386+ */
#define BUFSIZ 0x1000 /* best stdio default */

View file

@ -5,6 +5,7 @@
#include "libc/sock/struct/msghdr.h"
#include "libc/sock/struct/sockaddr.h"
#include "libc/sysv/consts/af.h"
#include "libc/sysv/consts/limits.h"
#include "libc/sysv/consts/msg.h"
#include "libc/sysv/consts/pf.h"
#include "libc/sysv/consts/scm.h"

View file

@ -1230,6 +1230,7 @@ syscon mount MNT_SNAPSHOT 0 0x40000000 0x01000000 0 0 0 # confusing
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon limits PIPE_BUF 4096 512 512 512 512 4096 # bsd consensus
syscon limits NGROUPS_MAX 65536 16 1023 16 16 0 #
syscon limits SOMAXCONN 4096 128 128 128 128 2147483647 # maximum backlog for listen()
syscon limits _ARG_MAX 128*1024 1024*1024 512*1024 512*1024 256*1024 32767*2 # bsd consensus
syscon limits _NAME_MAX 255 255 255 255 511 255 # probably higher on windows?
syscon limits _PATH_MAX 4096 1024 1024 1024 1024 512 # cosmopolitan libc imposes a lower 512 limit; nt theoretically goes up to 32767
@ -2292,7 +2293,6 @@ syscon misc SET_WINDOW 36 0 0 0 0 0
syscon misc SFD_CLOEXEC 0x080000 0 0 0 0 0
syscon misc SFD_NONBLOCK 0x0800 0 0 0 0 0
syscon misc SOMAXCONN 0x80 0x80 0x80 0x80 0x80 0x7fffffff # unix consensus
syscon misc SUBCMDMASK 255 255 255 255 255 0 # unix consensus
syscon misc SUBCMDSHIFT 8 8 8 8 8 0 # unix consensus
syscon misc SYMTYPE 50 50 50 50 50 0 # unix consensus

View file

@ -38,7 +38,6 @@ extern const int AF_NFC;
extern const int AF_PACKET;
extern const int AF_PHONET;
extern const int AF_PPPOX;
extern const int AF_RDS;
extern const int AF_ROSE;
extern const int AF_ROUTE;
extern const int AF_RXRPC;
@ -88,7 +87,6 @@ COSMOPOLITAN_C_END_
#define AF_PACKET SYMBOLIC(AF_PACKET)
#define AF_PHONET SYMBOLIC(AF_PHONET)
#define AF_PPPOX SYMBOLIC(AF_PPPOX)
#define AF_RDS SYMBOLIC(AF_RDS)
#define AF_ROSE SYMBOLIC(AF_ROSE)
#define AF_ROUTE SYMBOLIC(AF_ROUTE)
#define AF_RXRPC SYMBOLIC(AF_RXRPC)

View file

@ -46,6 +46,7 @@ COSMOPOLITAN_C_END_
#define IPPROTO_TCP LITERALLY(6)
#define IPPROTO_UDP LITERALLY(17)
#define IPPROTO_RAW LITERALLY(255)
#define IPPROTO_MAX LITERALLY(263) /* xxx */
#define IPPROTO_AH SYMBOLIC(IPPROTO_AH)
#define IPPROTO_BEETPH SYMBOLIC(IPPROTO_BEETPH)
@ -63,7 +64,6 @@ COSMOPOLITAN_C_END_
#define IPPROTO_IGMP SYMBOLIC(IPPROTO_IGMP)
#define IPPROTO_IPIP SYMBOLIC(IPPROTO_IPIP)
#define IPPROTO_IPV6 SYMBOLIC(IPPROTO_IPV6)
#define IPPROTO_MAX SYMBOLIC(IPPROTO_MAX)
#define IPPROTO_MH SYMBOLIC(IPPROTO_MH)
#define IPPROTO_MPLS SYMBOLIC(IPPROTO_MPLS)
#define IPPROTO_MTP SYMBOLIC(IPPROTO_MTP)

View file

@ -6,6 +6,7 @@ COSMOPOLITAN_C_START_
extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int SOMAXCONN;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _NSIG;
@ -16,6 +17,7 @@ COSMOPOLITAN_C_END_
#define NGROUPS_MAX SYMBOLIC(NGROUPS_MAX)
#define PIPE_BUF SYMBOLIC(PIPE_BUF)
#define SOMAXCONN SYMBOLIC(SOMAXCONN)
#define _ARG_MAX SYMBOLIC(_ARG_MAX)
#define _NAME_MAX SYMBOLIC(_NAME_MAX)
#define _NSIG SYMBOLIC(_NSIG)

View file

@ -1,19 +1,20 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
o/$(MODE)/test/libc/release/cosmopolitan.zip: .UNSANDBOXED = 1
o/$(MODE)/test/libc/release/cosmopolitan.zip: \
o/cosmopolitan.h \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/ape/ape-copy-self.o \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a
mkdir -p $(@D)
zip -qj $@ \
o/$(MODE)/cosmopolitan.a \
o/$(MODE)/third_party/zip/zip.com
@$(COMPILE) -AZIP -T$@ \
o/$(MODE)/third_party/zip/zip.com \
-b$(TMPDIR) -qj $@ \
o/cosmopolitan.h \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/ape/ape-copy-self.o \
@ -35,7 +36,7 @@ o/$(MODE)/test/libc/release/smoke.o: \
o/$(MODE)/test/libc/release/smoke.com.dbg: \
o/$(MODE)/test/libc/release/smoke.o \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
@ -43,7 +44,7 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
-static \
-no-pie \
-nostdlib \
-T o/$(MODE)/ape/ape.lds \
-T o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/test/libc/release/smoke.o \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
@ -52,7 +53,7 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
o/$(MODE)/test/libc/release/smoke.o \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a
@ -60,7 +61,7 @@ o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
-static \
-no-pie \
-nostdlib \
-T o/$(MODE)/ape/ape.lds \
-T o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/test/libc/release/smoke.o \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape-no-modify-self.o \
@ -69,7 +70,7 @@ o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
o/$(MODE)/test/libc/release/smoke-chibicc.o \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a \
@ -78,7 +79,7 @@ o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
-static \
-no-pie \
-nostdlib \
-T o/$(MODE)/ape/ape.lds \
-T o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/test/libc/release/smoke-chibicc.o \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape-no-modify-self.o \
@ -106,7 +107,7 @@ o/$(MODE)/test/libc/release/smoke-chibicc.o: \
o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
o/$(MODE)/test/libc/release/smokecxx.o \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
@ -114,7 +115,7 @@ o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
-static \
-no-pie \
-nostdlib \
-T o/$(MODE)/ape/ape.lds \
-T o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/test/libc/release/smokecxx.o \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
@ -136,7 +137,7 @@ o/$(MODE)/test/libc/release/smokecxx.o: \
o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
o/$(MODE)/test/libc/release/smokeansi.o \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
@ -144,7 +145,7 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
-static \
-no-pie \
-nostdlib \
-T o/$(MODE)/ape/ape.lds \
-T o/$(MODE)/ape/public/ape.lds \
o/$(MODE)/test/libc/release/smokeansi.o \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \

View file

@ -769,7 +769,6 @@ if __name__ == 'PYOBJ.COM':
AF_NETROM = 0
AF_PACKET = 0
AF_PPPOX = 0
AF_RDS = 0
AF_ROSE = 0
AF_ROUTE = 0
AF_SECURITY = 0

View file

@ -1696,7 +1696,6 @@ class CANTest(ThreadedCANSocketTest):
class BasicRDSTest(unittest.TestCase):
def testCrucialConstants(self):
socket.AF_RDS
socket.PF_RDS
def testCreateSocket(self):

View file

@ -77,7 +77,6 @@ PYTHON_PROVIDE("_socket.AF_NETBEUI");
PYTHON_PROVIDE("_socket.AF_NETROM");
PYTHON_PROVIDE("_socket.AF_PACKET");
PYTHON_PROVIDE("_socket.AF_PPPOX");
PYTHON_PROVIDE("_socket.AF_RDS");
PYTHON_PROVIDE("_socket.AF_ROSE");
PYTHON_PROVIDE("_socket.AF_ROUTE");
PYTHON_PROVIDE("_socket.AF_SECURITY");
@ -6666,7 +6665,6 @@ PyInit__socket(void)
if (AF_CAN) PyModule_AddIntMacro(m, AF_CAN); /* Controller Area Network */
if (PF_CAN) PyModule_AddIntMacro(m, PF_CAN);
if (AF_RDS) PyModule_AddIntMacro(m, AF_RDS); /* Reliable Datagram Sockets */
if (PF_RDS) PyModule_AddIntMacro(m, PF_RDS);
if (AF_PACKET) PyModule_AddIntMacro(m, AF_PACKET);
if (PF_PACKET) PyModule_AddIntMacro(m, PF_PACKET);

View file

@ -204,7 +204,7 @@ void LoadProgram(struct Machine *m, const char *prog, char **args, char **vars,
sp = 0x800000000000;
Write64(m->sp, sp);
m->cr3 = AllocateLinearPage(m);
CHECK_NE(-1, ReserveVirtual(m, sp - STACKSIZE, STACKSIZE,
CHECK_NE(-1, ReserveVirtual(m, sp - 0x800000, 0x800000,
PAGE_V | PAGE_RW | PAGE_U | PAGE_RSRV));
LoadArgv(m, prog, args, vars);
if (memcmp(elf->map, "\177ELF", 4) == 0) {