Skip to content

Commit b73e35c

Browse files
committed
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.
1 parent 0e2b1bf commit b73e35c

File tree

13 files changed

+50
-26
lines changed

13 files changed

+50
-26
lines changed

ape/ape.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ o/$(MODE)/ape/ape.lds: \
7272
libc/str/str.h \
7373
libc/zip.h
7474

75+
o/$(MODE)/ape/public/ape.lds: OVERRIDE_CPPFLAGS += -UCOSMO
76+
o/$(MODE)/ape/public/ape.lds: \
77+
ape/public/ape.lds \
78+
ape/ape.lds \
79+
ape/macros.internal.h \
80+
ape/relocations.h \
81+
libc/intrin/bits.h \
82+
libc/calls/struct/timespec.h \
83+
libc/dce.h \
84+
libc/elf/def.h \
85+
libc/elf/pf2prot.internal.h \
86+
libc/macros.internal.h \
87+
libc/nt/pedef.internal.h \
88+
libc/str/str.h \
89+
libc/zip.h
90+
7591
o/ape/idata.inc: \
7692
ape/idata.internal.h \
7793
ape/relocations.h
@@ -159,6 +175,7 @@ o/$(MODE)/ape/ape.macho.dbg: \
159175
o/$(MODE)/ape: $(APE_CHECKS) \
160176
o/$(MODE)/ape/ape.o \
161177
o/$(MODE)/ape/ape.lds \
178+
o/$(MODE)/ape/public/ape.lds \
162179
o/$(MODE)/ape/ape.elf \
163180
o/$(MODE)/ape/ape.macho \
164181
o/$(MODE)/ape/ape-copy-self.o \

ape/public/ape.lds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "ape/ape.lds"

libc/integral/normalize.inc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@
6666
#define __BIGGEST_ALIGNMENT__ 16
6767
#endif
6868

69+
/* TODO(jart): Remove this in favor of GetStackSize() */
70+
#if defined(COSMO) && defined(MODE_DBG)
71+
#define STACKSIZE 0x20000 /* 128kb stack */
72+
#elif defined(COSMO)
73+
#define STACKSIZE 0x10000 /* 64kb stack */
74+
#else
75+
#define STACKSIZE 0x800000 /* 8mb stack */
76+
#endif
77+
6978
#define BIGPAGESIZE 0x200000
70-
#define STACKSIZE 0x20000
7179
#define FRAMESIZE 0x10000 /* 8086 */
7280
#define PAGESIZE 0x1000 /* i386+ */
7381
#define BUFSIZ 0x1000 /* best stdio default */

libc/isystem/sys/socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "libc/sock/struct/msghdr.h"
66
#include "libc/sock/struct/sockaddr.h"
77
#include "libc/sysv/consts/af.h"
8+
#include "libc/sysv/consts/limits.h"
89
#include "libc/sysv/consts/msg.h"
910
#include "libc/sysv/consts/pf.h"
1011
#include "libc/sysv/consts/scm.h"

libc/sysv/consts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ syscon mount MNT_SNAPSHOT 0 0x40000000 0x01000000 0 0 0 # confusing
12301230
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
12311231
syscon limits PIPE_BUF 4096 512 512 512 512 4096 # bsd consensus
12321232
syscon limits NGROUPS_MAX 65536 16 1023 16 16 0 #
1233+
syscon limits SOMAXCONN 4096 128 128 128 128 2147483647 # maximum backlog for listen()
12331234
syscon limits _ARG_MAX 128*1024 1024*1024 512*1024 512*1024 256*1024 32767*2 # bsd consensus
12341235
syscon limits _NAME_MAX 255 255 255 255 511 255 # probably higher on windows?
12351236
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
22922293
syscon misc SFD_CLOEXEC 0x080000 0 0 0 0 0
22932294
syscon misc SFD_NONBLOCK 0x0800 0 0 0 0 0
22942295

2295-
syscon misc SOMAXCONN 0x80 0x80 0x80 0x80 0x80 0x7fffffff # unix consensus
22962296
syscon misc SUBCMDMASK 255 255 255 255 255 0 # unix consensus
22972297
syscon misc SUBCMDSHIFT 8 8 8 8 8 0 # unix consensus
22982298
syscon misc SYMTYPE 50 50 50 50 50 0 # unix consensus

libc/sysv/consts/af.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ extern const int AF_NFC;
3838
extern const int AF_PACKET;
3939
extern const int AF_PHONET;
4040
extern const int AF_PPPOX;
41-
extern const int AF_RDS;
4241
extern const int AF_ROSE;
4342
extern const int AF_ROUTE;
4443
extern const int AF_RXRPC;
@@ -88,7 +87,6 @@ COSMOPOLITAN_C_END_
8887
#define AF_PACKET SYMBOLIC(AF_PACKET)
8988
#define AF_PHONET SYMBOLIC(AF_PHONET)
9089
#define AF_PPPOX SYMBOLIC(AF_PPPOX)
91-
#define AF_RDS SYMBOLIC(AF_RDS)
9290
#define AF_ROSE SYMBOLIC(AF_ROSE)
9391
#define AF_ROUTE SYMBOLIC(AF_ROUTE)
9492
#define AF_RXRPC SYMBOLIC(AF_RXRPC)

libc/sysv/consts/ipproto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ COSMOPOLITAN_C_END_
4646
#define IPPROTO_TCP LITERALLY(6)
4747
#define IPPROTO_UDP LITERALLY(17)
4848
#define IPPROTO_RAW LITERALLY(255)
49+
#define IPPROTO_MAX LITERALLY(263) /* xxx */
4950

5051
#define IPPROTO_AH SYMBOLIC(IPPROTO_AH)
5152
#define IPPROTO_BEETPH SYMBOLIC(IPPROTO_BEETPH)
@@ -63,7 +64,6 @@ COSMOPOLITAN_C_END_
6364
#define IPPROTO_IGMP SYMBOLIC(IPPROTO_IGMP)
6465
#define IPPROTO_IPIP SYMBOLIC(IPPROTO_IPIP)
6566
#define IPPROTO_IPV6 SYMBOLIC(IPPROTO_IPV6)
66-
#define IPPROTO_MAX SYMBOLIC(IPPROTO_MAX)
6767
#define IPPROTO_MH SYMBOLIC(IPPROTO_MH)
6868
#define IPPROTO_MPLS SYMBOLIC(IPPROTO_MPLS)
6969
#define IPPROTO_MTP SYMBOLIC(IPPROTO_MTP)

libc/sysv/consts/limits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ COSMOPOLITAN_C_START_
66

77
extern const int NGROUPS_MAX;
88
extern const int PIPE_BUF;
9+
extern const int SOMAXCONN;
910
extern const int _ARG_MAX;
1011
extern const int _NAME_MAX;
1112
extern const int _NSIG;
@@ -16,6 +17,7 @@ COSMOPOLITAN_C_END_
1617

1718
#define NGROUPS_MAX SYMBOLIC(NGROUPS_MAX)
1819
#define PIPE_BUF SYMBOLIC(PIPE_BUF)
20+
#define SOMAXCONN SYMBOLIC(SOMAXCONN)
1921
#define _ARG_MAX SYMBOLIC(_ARG_MAX)
2022
#define _NAME_MAX SYMBOLIC(_NAME_MAX)
2123
#define _NSIG SYMBOLIC(_NSIG)

test/libc/release/test.mk

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
22
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
33

4-
o/$(MODE)/test/libc/release/cosmopolitan.zip: .UNSANDBOXED = 1
54
o/$(MODE)/test/libc/release/cosmopolitan.zip: \
65
o/cosmopolitan.h \
7-
o/$(MODE)/ape/ape.lds \
6+
o/$(MODE)/ape/public/ape.lds \
87
o/$(MODE)/libc/crt/crt.o \
98
o/$(MODE)/ape/ape.o \
109
o/$(MODE)/ape/ape-copy-self.o \
1110
o/$(MODE)/ape/ape-no-modify-self.o \
12-
o/$(MODE)/cosmopolitan.a
13-
mkdir -p $(@D)
14-
zip -qj $@ \
11+
o/$(MODE)/cosmopolitan.a \
12+
o/$(MODE)/third_party/zip/zip.com
13+
@$(COMPILE) -AZIP -T$@ \
14+
o/$(MODE)/third_party/zip/zip.com \
15+
-b$(TMPDIR) -qj $@ \
1516
o/cosmopolitan.h \
16-
o/$(MODE)/ape/ape.lds \
17+
o/$(MODE)/ape/public/ape.lds \
1718
o/$(MODE)/libc/crt/crt.o \
1819
o/$(MODE)/ape/ape.o \
1920
o/$(MODE)/ape/ape-copy-self.o \
@@ -35,15 +36,15 @@ o/$(MODE)/test/libc/release/smoke.o: \
3536

3637
o/$(MODE)/test/libc/release/smoke.com.dbg: \
3738
o/$(MODE)/test/libc/release/smoke.o \
38-
o/$(MODE)/ape/ape.lds \
39+
o/$(MODE)/ape/public/ape.lds \
3940
o/$(MODE)/libc/crt/crt.o \
4041
o/$(MODE)/ape/ape.o \
4142
o/$(MODE)/cosmopolitan.a
4243
@$(COMPILE) -ALD $(LD) \
4344
-static \
4445
-no-pie \
4546
-nostdlib \
46-
-T o/$(MODE)/ape/ape.lds \
47+
-T o/$(MODE)/ape/public/ape.lds \
4748
o/$(MODE)/test/libc/release/smoke.o \
4849
o/$(MODE)/libc/crt/crt.o \
4950
o/$(MODE)/ape/ape.o \
@@ -52,15 +53,15 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
5253

5354
o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
5455
o/$(MODE)/test/libc/release/smoke.o \
55-
o/$(MODE)/ape/ape.lds \
56+
o/$(MODE)/ape/public/ape.lds \
5657
o/$(MODE)/libc/crt/crt.o \
5758
o/$(MODE)/ape/ape-no-modify-self.o \
5859
o/$(MODE)/cosmopolitan.a
5960
@$(COMPILE) -ALD $(LD) \
6061
-static \
6162
-no-pie \
6263
-nostdlib \
63-
-T o/$(MODE)/ape/ape.lds \
64+
-T o/$(MODE)/ape/public/ape.lds \
6465
o/$(MODE)/test/libc/release/smoke.o \
6566
o/$(MODE)/libc/crt/crt.o \
6667
o/$(MODE)/ape/ape-no-modify-self.o \
@@ -69,7 +70,7 @@ o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
6970

7071
o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
7172
o/$(MODE)/test/libc/release/smoke-chibicc.o \
72-
o/$(MODE)/ape/ape.lds \
73+
o/$(MODE)/ape/public/ape.lds \
7374
o/$(MODE)/libc/crt/crt.o \
7475
o/$(MODE)/ape/ape-no-modify-self.o \
7576
o/$(MODE)/cosmopolitan.a \
@@ -78,7 +79,7 @@ o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
7879
-static \
7980
-no-pie \
8081
-nostdlib \
81-
-T o/$(MODE)/ape/ape.lds \
82+
-T o/$(MODE)/ape/public/ape.lds \
8283
o/$(MODE)/test/libc/release/smoke-chibicc.o \
8384
o/$(MODE)/libc/crt/crt.o \
8485
o/$(MODE)/ape/ape-no-modify-self.o \
@@ -106,15 +107,15 @@ o/$(MODE)/test/libc/release/smoke-chibicc.o: \
106107

107108
o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
108109
o/$(MODE)/test/libc/release/smokecxx.o \
109-
o/$(MODE)/ape/ape.lds \
110+
o/$(MODE)/ape/public/ape.lds \
110111
o/$(MODE)/libc/crt/crt.o \
111112
o/$(MODE)/ape/ape.o \
112113
o/$(MODE)/cosmopolitan.a
113114
@$(COMPILE) -ALD $(LD) \
114115
-static \
115116
-no-pie \
116117
-nostdlib \
117-
-T o/$(MODE)/ape/ape.lds \
118+
-T o/$(MODE)/ape/public/ape.lds \
118119
o/$(MODE)/test/libc/release/smokecxx.o \
119120
o/$(MODE)/libc/crt/crt.o \
120121
o/$(MODE)/ape/ape.o \
@@ -136,15 +137,15 @@ o/$(MODE)/test/libc/release/smokecxx.o: \
136137

137138
o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
138139
o/$(MODE)/test/libc/release/smokeansi.o \
139-
o/$(MODE)/ape/ape.lds \
140+
o/$(MODE)/ape/public/ape.lds \
140141
o/$(MODE)/libc/crt/crt.o \
141142
o/$(MODE)/ape/ape.o \
142143
o/$(MODE)/cosmopolitan.a
143144
@$(COMPILE) -ALD $(LD) \
144145
-static \
145146
-no-pie \
146147
-nostdlib \
147-
-T o/$(MODE)/ape/ape.lds \
148+
-T o/$(MODE)/ape/public/ape.lds \
148149
o/$(MODE)/test/libc/release/smokeansi.o \
149150
o/$(MODE)/libc/crt/crt.o \
150151
o/$(MODE)/ape/ape.o \

third_party/python/Lib/socket.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
769769
AF_NETROM = 0
770770
AF_PACKET = 0
771771
AF_PPPOX = 0
772-
AF_RDS = 0
773772
AF_ROSE = 0
774773
AF_ROUTE = 0
775774
AF_SECURITY = 0

0 commit comments

Comments
 (0)