Skip to content

Commit a3deef7

Browse files
committed
Release Cosmopolitan v3.2
1 parent 873069f commit a3deef7

File tree

11 files changed

+75
-18
lines changed

11 files changed

+75
-18
lines changed

ape/loader.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,9 @@ static char FindCommand(struct PathSearcher *ps) {
597597
return SearchPath(ps);
598598
}
599599

600-
static char *Commandv(struct PathSearcher *ps, int os, const char *name,
601-
const char *syspath) {
600+
static char *Commandv(struct PathSearcher *ps, int os, char *name,
601+
const char *syspath, int may_path_search) {
602+
if (!may_path_search) return name;
602603
ps->os = os;
603604
ps->syspath = syspath ? syspath : "/bin:/usr/local/bin:/usr/bin";
604605
if (!(ps->namelen = StrLen((ps->name = name)))) return 0;
@@ -978,6 +979,7 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
978979
}
979980

980981
/* we can load via shell, shebang, or binfmt_misc */
982+
int may_path_search = 1;
981983
if ((literally = argc >= 3 && !StrCmp(argv[1], "-"))) {
982984
/* if the first argument is a hyphen then we give the user the
983985
power to change argv[0] or omit it entirely. most operating
@@ -986,12 +988,12 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
986988
prog = (char *)sp[3];
987989
argc = sp[3] = sp[0] - 3;
988990
argv = (char **)((sp += 3) + 1);
991+
may_path_search = 0;
989992
} else if (argc < 2) {
990993
ShowUsage(os, 2, 1);
991994
} else {
992995
if (argv[1][0] == '-') {
993-
rc = !(argv[1][1] == 'h' && !argv[1][2]) || !StrCmp(argv[1] + 1,
994-
"-help");
996+
rc = !(argv[1][1] == 'h' && !argv[1][2]) || !StrCmp(argv[1] + 1, "-help");
995997
ShowUsage(os, 1 + rc, rc);
996998
}
997999
prog = (char *)sp[2];
@@ -1027,7 +1029,8 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
10271029
}
10281030

10291031
/* resolve path of executable and read its first page */
1030-
if (!(exe = Commandv(&M->ps, os, prog, GetEnv(envp, "PATH")))) {
1032+
if (!(exe = Commandv(&M->ps, os, prog, GetEnv(envp, "PATH"),
1033+
may_path_search))) {
10311034
Pexit(os, prog, 0, "not found (maybe chmod +x or ./ needed)");
10321035
} else if ((fd = Open(exe, O_RDONLY, 0, os)) < 0) {
10331036
Pexit(os, exe, fd, "open");

libc/calls/isqemu.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2024 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "ape/sections.internal.h"
20+
#include "libc/calls/calls.h"
21+
#include "libc/calls/syscall-sysv.internal.h"
22+
#include "libc/errno.h"
23+
24+
/**
25+
* Returns true if process is running under qemu-x86_64 or qemu-x86_64.
26+
*/
27+
int IsQemu(void) {
28+
// qemu doesn't validate the advice argument
29+
// we could also check if __getcwd(0, 0) raises efault
30+
int e = errno;
31+
int r = !sys_madvise(__executable_start, 16384, 127);
32+
errno = e;
33+
return r;
34+
}

libc/dce.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ COSMOPOLITAN_C_START_
121121

122122
extern const int __hostos;
123123

124+
int IsQemu(void);
125+
124126
COSMOPOLITAN_C_END_
125127
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
126128
#endif /* _COSMO_SOURCE */

libc/integral/normalize.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#endif
44

55
#define __COSMOPOLITAN_MAJOR__ 3
6-
#define __COSMOPOLITAN_MINOR__ 1
7-
#define __COSMOPOLITAN_PATCH__ 3
6+
#define __COSMOPOLITAN_MINOR__ 2
7+
#define __COSMOPOLITAN_PATCH__ 0
88
#define __COSMOPOLITAN__ \
99
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
1010
__COSMOPOLITAN_PATCH__)

test/libc/calls/getcwd_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include "libc/dce.h"
2121
#include "libc/errno.h"
2222
#include "libc/fmt/libgen.h"
23-
#include "libc/serialize.h"
2423
#include "libc/limits.h"
2524
#include "libc/macros.internal.h"
2625
#include "libc/mem/gc.internal.h"
26+
#include "libc/serialize.h"
2727
#include "libc/str/str.h"
2828
#include "libc/testlib/testlib.h"
2929

@@ -33,6 +33,7 @@ void SetUpOnce(void) {
3333
}
3434

3535
TEST(__getcwd, zero) {
36+
if (IsQemu()) return;
3637
ASSERT_SYS(ERANGE, -1, __getcwd(0, 0));
3738
}
3839

test/libc/calls/getprogramexecutablename_test.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
╚─────────────────────────────────────────────────────────────────────────────*/
1919
#include "libc/calls/calls.h"
2020
#include "libc/calls/metalfile.internal.h"
21+
#include "libc/calls/syscall-nt.internal.h"
2122
#include "libc/calls/syscall-sysv.internal.h"
23+
#include "libc/calls/syscall_support-sysv.internal.h"
2224
#include "libc/dce.h"
2325
#include "libc/limits.h"
2426
#include "libc/runtime/runtime.h"
@@ -58,7 +60,13 @@ void SetUpOnce(void) {
5860

5961
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
6062
if (argc >= 2 && !strcmp(argv[1], "Child")) {
61-
if (sys_chdir("/")) {
63+
int rc;
64+
if (!IsWindows()) {
65+
rc = sys_chdir("/");
66+
} else {
67+
rc = sys_chdir_nt("/");
68+
}
69+
if (rc) {
6270
exit(122);
6371
}
6472
if (strcmp(argv[2], GetProgramExecutableName())) {
@@ -105,6 +113,13 @@ TEST(GetProramExecutableName, weirdArgv0NullEnv) {
105113

106114
TEST(GetProgramExecutableName, movedSelf) {
107115
if (skiptests) return;
116+
if (IsAarch64() && IsQemu()) {
117+
// clang-format off
118+
// TODO(mrdomino): fix: make -j8 m=aarch64 o/aarch64/test/libc/calls/getprogramexecutablename_test.com.ok
119+
// possibly related to the intersection of binfmt_misc and qemu-aarch64
120+
// clang-format on
121+
return;
122+
}
108123
char buf[BUFSIZ];
109124
ASSERT_SYS(0, 3, open(GetProgramExecutableName(), O_RDONLY));
110125
ASSERT_SYS(0, 4, creat("test", 0755));

test/libc/calls/madvise_test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ TEST(madvise, subPages) {
7070
TEST(madvise, misalign) {
7171
char *p;
7272
if (!IsLinux()) return; // most platforms don't care
73+
if (IsQemu()) return; // qemu claims to be linux but doesn't care
7374
ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
7475
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)));
7576
ASSERT_SYS(EINVAL, -1, madvise(p + 1, FRAMESIZE - 1, MADV_WILLNEED));
@@ -78,14 +79,16 @@ TEST(madvise, misalign) {
7879

7980
TEST(madvise, badAdvice) {
8081
char *p;
82+
if (IsAarch64() && IsQemu()) return; // qemu doesn't validate advice
8183
ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
8284
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)));
8385
ASSERT_SYS(EINVAL, -1, madvise(p, FRAMESIZE, 127));
8486
ASSERT_SYS(0, 0, munmap(p, FRAMESIZE));
8587
}
8688

8789
TEST(madvise, missingMemory) {
88-
if (!IsLinux()) return;
90+
if (!IsLinux()) return; // most platforms don't care
91+
if (IsQemu()) return; // qemu claims to be linux but doesn't care
8992
ASSERT_SYS(ENOMEM, -1,
9093
madvise((char *)0x83483838000, FRAMESIZE, MADV_WILLNEED));
9194
}

test/libc/calls/writev_test.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ TEST(writev, empty_stillPerformsIoOperation) {
126126
ASSERT_NE(-1, (fd = open("file", O_RDONLY)));
127127
errno = 0;
128128
EXPECT_SYS(EBADF, -1, writev(fd, iov, ARRAYLEN(iov)));
129-
#ifndef __aarch64__
130-
// Can't test this due to qemu-aarch64 bug
131-
EXPECT_EQ(-1, writev(fd, NULL, 0));
132-
#endif
129+
if (!(IsAarch64() && IsQemu())) {
130+
EXPECT_EQ(-1, writev(fd, NULL, 0));
131+
}
133132
EXPECT_NE(-1, close(fd));
134133
}

test/libc/stdio/tmpfile_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TEST(tmpfile, test) {
8181
}
8282

8383
#ifndef __aarch64__
84-
// TODO(jart): Find way to detect qemu-aarch64
84+
// TODO(jart): Why does this apply to pi and qemu-aarch64?
8585
TEST(tmpfile, renameToRealFile) {
8686
if (!(IsLinux() && __is_linux_2_6_23())) return; // need non-ancient linux
8787
FILE *f;

tool/cosmocc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ statements instead, so that Cosmopolitan Libc's system constants will
298298
work as expected. Our modifications to GNU GCC are published under the
299299
ISC license at <https://github.com/ahgamut/gcc/tree/portcosmo-11.2>. The
300300
binaries you see here were first published at
301-
<https://github.com/ahgamut/superconfigure/releases/tag/z0.0.29> which
301+
<https://github.com/ahgamut/superconfigure/releases/tag/z0.0.30> which
302302
is regularly updated.
303303
304304
## Legal

0 commit comments

Comments
 (0)