From 7b26b4276941ade84e5e1d964020f32abc1da5c6 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 12 Sep 2022 23:10:38 -0700 Subject: [PATCH] Pay off more technical debt This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available. Compared to 6f7d0cb1c3962f7cb474b04de75df7cd82a3e5d3, some tiny corrections were made in libc/intrin/g_fds.c and libc/zipos/open.c including double semi colons and incorrect indentation for existing vista changes that were manually pulled from this commit previously. --- ape/ape.S | 1 - dsp/scale/gyarados.c | 8 +- dsp/tty/ident.c | 7 +- dsp/tty/sendtitle.c | 2 +- dsp/tty/ttyraw.c | 3 +- examples/compress.c | 2 +- examples/cosh.c | 7 +- examples/crashreport2.c | 1 + examples/curl.c | 9 +- examples/datauri.c | 3 +- examples/date.c | 4 +- examples/decompress.c | 2 +- examples/defer-statements.c | 2 +- examples/forkrand.c | 2 +- examples/gc.c | 17 + examples/getrandom.c | 5 +- examples/greenbean.c | 1 + examples/hertz.c | 3 +- examples/img.c | 10 +- examples/ispell.c | 160 ------- examples/kilo.c | 6 +- examples/ls.c | 6 +- examples/lstime.c | 9 +- examples/nesemu1.cc | 11 +- examples/panels.c | 5 +- examples/picol.c | 1 + examples/rlimit.c | 2 +- examples/stat.c | 4 +- examples/stringbuffer.c | 2 +- examples/time.c | 3 +- examples/ttyaudio.c | 2 +- examples/ttyinfo.c | 10 +- examples/unbourne.c | 5 +- libc/calls/calls.h | 2 - libc/calls/chdir.c | 2 +- libc/calls/chroot.c | 2 +- libc/calls/clock_getres.c | 2 +- libc/calls/clock_gettime.c | 2 +- libc/calls/close.c | 8 +- libc/calls/close_range.c | 2 +- libc/calls/closefrom.c | 2 +- libc/calls/commandv.c | 2 +- libc/{mem/io.h => calls/copyfd.internal.h} | 0 libc/calls/copyfile.c | 4 +- libc/calls/copyfile.h | 2 +- libc/calls/dup-nt.c | 4 +- libc/calls/dup.c | 2 +- libc/calls/dup2.c | 2 +- libc/calls/dup3-sysv.c | 2 +- libc/calls/dup3.c | 2 +- libc/calls/execve-nt.greg.c | 3 +- libc/calls/execve.c | 10 +- libc/calls/faccessat.c | 8 +- libc/calls/fadvise.c | 2 +- libc/calls/fchmodat.c | 7 +- libc/calls/fchown.c | 2 +- libc/calls/fchownat.c | 7 +- libc/calls/fcntl.c | 4 +- libc/calls/fdatasync.c | 2 +- libc/calls/fileexists.c | 10 +- libc/calls/flock.c | 2 +- libc/calls/fstat-nt.c | 8 +- libc/calls/fstat.c | 4 +- libc/calls/fstatat.c | 8 +- libc/calls/fstatfs-nt.c | 4 +- libc/calls/fstatfs.c | 2 +- libc/calls/fsync.c | 2 +- libc/calls/ftruncate.c | 2 +- libc/calls/getcwd-nt.greg.c | 4 +- libc/calls/getcwd.greg.c | 16 +- libc/calls/getdomainname.c | 2 +- libc/calls/getegid.c | 2 +- libc/calls/geteuid.c | 2 +- libc/calls/getfiledescriptorsize.c | 4 +- libc/calls/gethostname.c | 2 +- libc/calls/getitimer.c | 2 +- libc/calls/getloadavg.c | 2 +- libc/calls/getpgid.c | 2 +- libc/calls/getpgrp.c | 2 +- libc/calls/getppid.c | 2 +- libc/calls/getpriority.c | 2 +- libc/calls/getresgid.c | 2 +- libc/calls/getresuid.c | 2 +- libc/calls/getrlimit.c | 2 +- libc/calls/getrusage.c | 2 +- libc/calls/getsid.c | 2 +- libc/calls/gettimeofday.c | 2 +- libc/calls/getttysize.c | 8 +- libc/calls/getuid.c | 2 +- libc/calls/interrupts-nt.c | 10 +- libc/calls/ioctl_default.c | 4 +- libc/calls/ioctl_fioclex.c | 2 +- libc/calls/ioctl_siocgifconf-nt.c | 22 +- libc/calls/ioctl_siocgifconf.c | 8 +- libc/calls/ioctl_tcgets.c | 2 +- libc/calls/ioctl_tcsets-nt.c | 2 +- libc/calls/ioctl_tcsets.c | 6 +- libc/calls/ioctl_tiocgwinsz-nt.c | 3 +- libc/calls/ioctl_tiocgwinsz.c | 2 +- libc/calls/isatty.c | 2 +- libc/calls/isdirectory.c | 10 +- libc/calls/isregularfile.c | 10 +- libc/calls/issetugid.c | 4 +- libc/calls/issymlink.c | 8 +- libc/calls/kill.c | 2 +- libc/calls/landlock_add_rule.c | 2 +- libc/calls/landlock_create_ruleset.c | 2 +- libc/calls/landlock_restrict_self.c | 2 +- libc/calls/linkat.c | 6 +- libc/calls/lseek.c | 4 +- libc/calls/madvise.c | 2 +- libc/calls/memfd_create.c | 2 +- libc/calls/mincore.c | 2 +- libc/calls/mkdirat.c | 7 +- libc/calls/mkfifo.c | 2 +- libc/calls/mknod.c | 2 +- libc/calls/mkntpath.c | 2 +- libc/calls/mkntpathat.c | 2 +- libc/calls/mremap-sysv.greg.c | 2 +- libc/calls/munmap-sysv.c | 2 +- libc/calls/nanosleep-nt.c | 2 +- libc/calls/nanosleep.c | 2 +- libc/calls/now.c | 2 +- libc/calls/ntaccesscheck.c | 6 +- libc/calls/ntspawn.c | 2 +- libc/calls/oldbench.c | 2 +- libc/calls/onntconsoleevent.c | 2 +- libc/calls/openat-metal.c | 4 +- libc/calls/openat.c | 8 +- libc/calls/openbsd.internal.h | 3 - libc/calls/pause-nt.c | 2 +- libc/calls/pause.c | 2 +- libc/calls/pipe.c | 2 +- libc/calls/pipe2.c | 2 +- libc/calls/pivot_root.c | 2 +- libc/calls/pledge-linux.c | 4 +- libc/calls/pledge.c | 2 +- libc/calls/poll-nt.c | 3 +- libc/calls/poll.c | 2 +- libc/calls/ppoll.c | 2 +- libc/calls/prctl.c | 2 +- libc/calls/pread.c | 8 +- libc/calls/preadv.c | 4 +- libc/calls/ptrace.c | 2 +- libc/calls/pwrite.c | 2 +- libc/calls/pwritev.c | 4 +- libc/calls/raise.c | 2 +- libc/calls/read-nt.c | 2 +- libc/calls/read.c | 4 +- libc/calls/readlinkat-nt.c | 6 +- libc/calls/readlinkat.c | 6 +- libc/calls/readv-nt.c | 2 +- libc/calls/readv.c | 4 +- libc/calls/realpath.c | 8 +- libc/calls/renameat.c | 6 +- libc/calls/reservefd.c | 5 +- libc/calls/sched_get_priority_max.c | 2 +- libc/calls/sched_get_priority_min.c | 2 +- libc/calls/sched_getaffinity.c | 2 +- libc/calls/sched_getscheduler.c | 2 +- libc/calls/sched_rr_get_interval.c | 2 +- libc/calls/sched_setaffinity.c | 2 +- libc/calls/sched_setscheduler.c | 2 +- libc/calls/seccomp.c | 2 +- libc/calls/sedebug.c | 2 +- libc/calls/setegid.c | 2 +- libc/calls/seteuid.c | 2 +- libc/calls/setfsgid.c | 2 +- libc/calls/setfsuid.c | 2 +- libc/calls/setgid.c | 2 +- libc/calls/setitimer-nt.c | 2 +- libc/calls/setitimer.c | 6 +- libc/calls/setpgid.c | 2 +- libc/calls/setregid.c | 2 +- libc/calls/setresgid.c | 2 +- libc/calls/setresuid.c | 2 +- libc/calls/setreuid.c | 2 +- libc/calls/setrlimit.c | 2 +- libc/calls/setsid.c | 2 +- libc/calls/setuid.c | 2 +- libc/calls/sig2.c | 5 +- libc/calls/sigaction.c | 3 +- libc/calls/sigaltstack.c | 2 +- libc/calls/sigchld-nt.c | 2 +- libc/calls/sigpending.c | 2 +- libc/calls/sigprocmask.c | 3 +- libc/calls/sigsuspend.c | 3 +- libc/calls/sigwinch-nt.c | 2 +- libc/calls/statfs.c | 2 +- libc/calls/struct/winsize.h | 2 + libc/calls/symlinkat.c | 2 +- libc/calls/sync.c | 2 +- libc/calls/sys_ptrace.c | 2 +- libc/calls/sysinfo.c | 2 +- libc/calls/tgkill.c | 2 +- libc/calls/tkill.c | 2 +- libc/calls/truncate.c | 2 +- libc/calls/ttyname_r.c | 2 +- libc/calls/umask.c | 2 +- libc/calls/uname.c | 3 +- libc/calls/unlinkat.c | 7 +- libc/calls/unmount.c | 2 +- libc/calls/unsetenv.c | 6 +- libc/calls/unveil.c | 2 +- libc/calls/utimensat-sysv.c | 1 - libc/calls/utimensat.c | 4 +- libc/calls/vdsofunc.greg.c | 2 +- libc/calls/wait4-nt.c | 2 +- libc/calls/wait4.c | 2 +- libc/calls/wincrash.c | 2 +- libc/calls/write-nt.c | 9 +- libc/calls/write.c | 4 +- libc/calls/writev-metal.c | 3 +- libc/calls/writev-nt.c | 2 +- libc/calls/writev.c | 4 +- libc/crt/crt.S | 2 +- libc/dns/getaddrinfo.c | 2 +- libc/fmt/fmt.c | 13 +- libc/fmt/formatbinary64.c | 4 +- libc/fmt/formathex64.c | 4 +- libc/fmt/itoa64radix16.greg.c | 4 +- libc/fmt/sprintf.c | 1 - libc/fmt/stoa.c | 32 +- libc/fmt/strerror.c | 3 +- libc/fmt/vcscanf.c | 12 +- libc/integral/c.inc | 8 +- libc/intrin/_getauxval.c | 2 +- libc/{calls => intrin}/_getauxval.internal.h | 6 +- libc/intrin/arememoryintervalsok.c | 2 +- libc/intrin/asan.c | 103 ++-- libc/intrin/assertfail.greg.c | 19 +- libc/intrin/bextra.c | 2 +- libc/intrin/bitreverse16.c | 4 +- libc/intrin/bitreverse32.c | 2 +- libc/intrin/bitreverse64.c | 2 +- libc/intrin/bitreverse8.c | 4 +- libc/intrin/bits.h | 22 +- libc/{str => intrin}/bsf.c | 8 +- libc/{nexgen32e => intrin}/bsf.h | 14 +- libc/{str => intrin}/bsfl.c | 8 +- libc/{str => intrin}/bsfll.c | 8 +- libc/{str => intrin}/bsr.c | 8 +- libc/{nexgen32e => intrin}/bsr.h | 14 +- libc/{nexgen32e => intrin}/bsr128.S | 7 +- libc/{str => intrin}/bsrl.c | 8 +- libc/{str => intrin}/bsrll.c | 8 +- libc/intrin/closehandle.c | 3 +- libc/intrin/createdirectory.c | 2 +- libc/intrin/createfile.c | 2 +- libc/intrin/createfilemapping.c | 2 +- libc/intrin/createfilemappingnuma.c | 2 +- libc/intrin/createnamedpipe.c | 2 +- libc/intrin/createpipe.c | 2 +- libc/intrin/createprocess.c | 2 +- libc/intrin/createsymboliclink.c | 2 +- libc/intrin/createthread.c | 2 +- libc/intrin/cxaatexit.c | 12 +- libc/intrin/cxafinalize.c | 12 +- libc/intrin/deletefile.c | 2 +- libc/intrin/describefutexresult.c | 4 +- libc/intrin/describerlimit.c | 2 +- libc/intrin/deviceiocontrol.c | 2 +- libc/intrin/directmap.c | 2 +- libc/intrin/exit.c | 2 +- libc/intrin/exit1.greg.c | 2 +- libc/{runtime/close_s.c => intrin/exitr.c} | 19 +- libc/intrin/extend.c | 5 +- libc/{calls => intrin}/extend.internal.h | 0 libc/intrin/ezlea.h | 4 +- libc/intrin/findclose.c | 2 +- libc/intrin/findfirstfile.c | 2 +- libc/intrin/findnextfile.c | 2 +- libc/intrin/flushfilebuffers.c | 2 +- libc/intrin/flushviewoffile.c | 2 +- libc/intrin/g_fds.c | 6 +- libc/intrin/generateconsolectrlevent.c | 2 +- libc/intrin/getenv.greg.c | 2 +- libc/intrin/getexitcodeprocess.c | 2 +- libc/intrin/getfileattributes.c | 2 +- libc/intrin/hamming.c | 2 +- .../{_have_fsgsbase.c => have_fsgsbase.c} | 0 libc/intrin/kprintf.greg.c | 43 +- libc/intrin/mapviewoffileex.c | 2 +- libc/intrin/mapviewoffileexnuma.c | 2 +- libc/intrin/memtrack.greg.c | 3 +- libc/intrin/mmi.init.S | 2 +- libc/intrin/movefileex.c | 2 +- libc/intrin/openprocess.c | 2 +- libc/intrin/pthread_key_create.c | 4 +- libc/intrin/pthread_key_destruct.c | 4 +- libc/intrin/pthread_mutex_init.c | 11 +- libc/intrin/pthread_mutex_lock.c | 11 +- libc/intrin/pthread_mutex_trylock.c | 8 +- libc/intrin/pthread_mutex_unlock.c | 9 +- libc/intrin/pthread_once.c | 4 +- libc/intrin/pthread_yield.c | 2 +- libc/intrin/quick_exit.c | 8 +- libc/intrin/rand64.c | 2 +- libc/intrin/{_rdfsbase.c => rdfsbase.c} | 0 libc/intrin/{_rdgsbase.c => rdgsbase.c} | 0 libc/intrin/removedirectory.c | 2 +- libc/intrin/reopenfile.c | 2 +- libc/intrin/restorewintty.c | 2 +- libc/intrin/rounddown2pow.c | 8 +- libc/intrin/roundup2log.c | 8 +- libc/intrin/roundup2pow.c | 8 +- libc/intrin/setcurrentdirectory.c | 2 +- libc/{calls => intrin}/strace.internal.h | 0 libc/intrin/stracef.greg.c | 2 +- libc/intrin/strerdoc.greg.c | 2 +- libc/intrin/strerrno.greg.c | 3 +- libc/intrin/strerror_wr.greg.c | 5 +- libc/intrin/terminateprocess.c | 2 +- libc/intrin/tpenc.S | 4 +- libc/{str => intrin}/tpenc.h | 6 +- libc/intrin/ubsan.c | 15 +- libc/intrin/unmapviewoffile.c | 2 +- libc/intrin/virtualprotect.c | 2 +- libc/intrin/waitformultipleobjects.c | 2 +- libc/intrin/waitforsingleobject.c | 2 +- libc/intrin/weaken.h | 26 +- libc/intrin/winerr.greg.c | 1 - libc/intrin/{_wrfsbase.c => wrfsbase.c} | 0 libc/intrin/{_wrgsbase.c => wrgsbase.c} | 0 libc/intrin/wsarecv.c | 2 +- libc/intrin/wsarecvfrom.c | 2 +- libc/intrin/wsawaitformultipleevents.c | 2 +- libc/isystem/avx2intrin.h | 4 + libc/isystem/avxintrin.h | 4 + libc/isystem/emmintrin.h | 4 + libc/isystem/pmmintrin.h | 4 + libc/isystem/shaintrin.h | 4 + libc/isystem/smmintrin.h | 4 + libc/isystem/tmmintrin.h | 4 + libc/isystem/wmmintrin.h | 4 + libc/isystem/xmmintrin.h | 4 + libc/log/appendresourcereport.c | 4 +- libc/log/appendresourcereport.internal.h | 11 + libc/log/backtrace2.c | 10 +- libc/log/backtrace3.c | 4 +- libc/log/checkaligned.c | 2 +- libc/log/checkfail.c | 2 +- libc/log/checkfail_ndebug.c | 7 +- libc/log/countexpr.h | 1 - libc/log/cxaprintexits.c | 6 +- libc/log/die.c | 6 +- libc/log/getcallername.c | 2 +- libc/log/getcallername.internal.h | 11 + libc/log/getsymbolbyaddr.c | 2 +- libc/log/leaks.c | 7 +- libc/log/libfatal.internal.h | 2 - libc/log/log.h | 123 +++-- libc/log/{getttycols.c => log_exit.c} | 23 +- .../log/log_get_errno.c | 23 +- libc/log/log_retrace.c | 24 + .../fatalbuf.c => log/log_set_errno.c} | 9 +- libc/log/log_untrace.c | 24 + libc/log/logerrno.c | 2 +- libc/log/meminfo.c | 4 +- libc/log/memlog.c | 1 - libc/log/memsummary.c | 2 +- libc/log/oncrash.c | 12 +- libc/log/onkill.c | 65 --- libc/log/printgarbage.c | 4 +- libc/log/showcrashreports.c | 4 +- libc/log/vflogf.c | 2 +- libc/macros.internal.h | 2 +- libc/mem/_gc_free.c | 2 +- libc/mem/alg.h | 23 +- libc/mem/arena.c | 20 +- libc/mem/balloc.c | 2 +- libc/mem/bfree.c | 2 +- libc/{runtime => mem}/gc.h | 6 +- libc/{runtime => mem}/gc.internal.h | 8 +- libc/mem/putenv.c | 2 +- libc/mem/replacestr.c | 6 +- libc/mem/setenv.c | 2 +- libc/mem/tarjan.c | 8 +- libc/nexgen32e/cachesize.h | 2 +- libc/nexgen32e/cescapec.S | 24 +- libc/nexgen32e/cmpsb.S | 41 -- libc/nexgen32e/cmpsl.S | 44 -- libc/nexgen32e/cmpsq.S | 41 -- libc/nexgen32e/cmpsw.S | 41 -- libc/nexgen32e/cmpub.S | 41 -- libc/nexgen32e/cmpul.S | 41 -- libc/nexgen32e/cmpuq.S | 41 -- libc/nexgen32e/cmpuw.S | 41 -- libc/nexgen32e/gc.internal.h | 6 +- libc/nexgen32e/kcrc32ctab.S | 2 +- libc/nexgen32e/missingno.S | 4 +- libc/nt/ntdllimport.S | 4 +- libc/runtime/arch_prctl.c | 2 +- libc/runtime/{buffer.h => buffer.internal.h} | 6 +- libc/runtime/clearenv.c | 2 +- libc/runtime/clktck.c | 2 +- libc/{thread => runtime}/clone-linux.S | 0 libc/{thread => runtime}/clone-nt.S | 0 libc/{thread => runtime}/clone-openbsd.S | 0 libc/{thread => runtime}/clone.c | 29 +- libc/runtime/clone.internal.h | 11 + libc/runtime/cosmo.S | 2 +- libc/runtime/enable_threads.c | 2 +- libc/runtime/enable_tls.c | 4 +- libc/runtime/exit.c | 9 +- libc/runtime/fork-nt.c | 12 +- libc/runtime/fork.c | 2 +- libc/runtime/getdosargv.c | 4 +- libc/runtime/getdosenviron.c | 4 +- libc/runtime/getinstructionlengths.c | 59 --- libc/runtime/getsymboltable.c | 6 +- libc/runtime/grow.c | 4 +- libc/runtime/inflate.c | 10 +- libc/runtime/mapanon.c | 7 +- libc/runtime/mapshared.c | 6 +- libc/runtime/memtracknt.c | 2 +- libc/runtime/mmap.c | 19 +- libc/runtime/morph.greg.c | 2 +- libc/runtime/mprotect.c | 2 +- libc/runtime/mremap.c | 16 +- libc/runtime/msync.c | 2 +- libc/runtime/munmap.c | 3 +- libc/runtime/opensymboltable.greg.c | 4 +- libc/runtime/printargs.c | 2 +- libc/runtime/runtime.h | 12 +- libc/runtime/stackchkfail.c | 3 +- libc/runtime/straceinit.greg.c | 2 +- libc/runtime/symbols.c | 4 +- libc/runtime/vfork.S | 2 +- libc/runtime/warnifpowersave.c | 2 +- libc/runtime/weakfree.c | 4 +- libc/runtime/winmain.greg.c | 8 +- libc/sock/accept4.c | 2 +- libc/sock/bind.c | 2 +- libc/sock/closesocket-nt.c | 1 - libc/sock/connect.c | 2 +- libc/sock/getpeername.c | 2 +- libc/sock/getsockname.c | 2 +- libc/sock/getsockopt.c | 2 +- libc/sock/kntwsadata.c | 3 +- libc/sock/listen.c | 2 +- libc/sock/pselect.c | 2 +- libc/sock/recv-nt.c | 2 +- libc/sock/recv.c | 2 +- libc/sock/recvfrom.c | 2 +- libc/sock/select.c | 2 +- libc/sock/send.c | 2 +- libc/sock/sendfile.c | 2 +- libc/sock/sendmsg.c | 2 +- libc/sock/sendto.c | 2 +- libc/sock/setsockopt.c | 2 +- libc/sock/shutdown.c | 2 +- libc/sock/sockatmark.c | 2 +- libc/sock/socket.c | 2 +- libc/sock/wsablock.c | 2 +- libc/sock/xinet_ntop.c | 2 +- libc/stdio/{append.internal.h => append.h} | 0 libc/stdio/appendd.c | 2 +- libc/stdio/appendf.c | 2 +- libc/stdio/appendr.c | 6 +- libc/stdio/appends.c | 2 +- libc/stdio/appendstrlist.c | 2 +- libc/stdio/appendw.c | 8 +- libc/stdio/appendz.c | 2 +- libc/stdio/dirstream.c | 20 +- libc/stdio/dtoa.c | 2 +- libc/stdio/dumphexc.c | 2 +- libc/stdio/fclose.c | 2 +- libc/stdio/fputwc_unlocked.c | 4 +- libc/stdio/freestrlist.c | 2 +- libc/stdio/getrandom.c | 2 +- libc/stdio/joinstrlist.c | 2 +- libc/stdio/kappendf.c | 2 +- libc/stdio/kvappendf.c | 2 +- libc/stdio/mkostempsm.c | 2 +- libc/stdio/stderr-init.S | 2 +- libc/stdio/stdin-init.S | 2 +- libc/stdio/stdout-init.S | 2 +- libc/stdio/system.c | 2 +- libc/stdio/ungetwc_unlocked.c | 4 +- libc/stdio/vappendf.c | 2 +- libc/str/_tpenc.h | 0 libc/str/crc32z.c | 4 +- libc/str/djbsort.c | 6 +- libc/str/endswith.c | 2 +- libc/str/endswith16.c | 2 +- libc/str/errfun.h | 11 - libc/str/getcachesize.c | 8 +- libc/str/longsort.c | 14 +- libc/str/smoothsort.c | 2 +- libc/str/startswith.c | 2 +- libc/str/startswith16.c | 2 +- libc/str/startswithi.c | 2 +- libc/str/str.h | 18 +- libc/str/strnwidth.c | 2 +- libc/str/thompike.h | 4 +- libc/str/tpdecodecb.internal.h | 4 +- libc/str/tpencode.ncabi.c | 4 +- libc/str/tprecode16to8.c | 4 +- libc/str/undeflate.c | 263 ----------- libc/str/undeflate.h | 19 - libc/str/wcsendswith.c | 2 +- libc/str/wcsstartswith.c | 2 +- libc/sysv/systemfive.S | 2 +- libc/testlib/endswith.c | 6 +- libc/testlib/ezbench.h | 3 - libc/testlib/formatbinaryasglyphs.c | 2 +- libc/testlib/formatfloat.c | 5 +- libc/testlib/formatrange.c | 2 +- libc/testlib/formatstr.c | 4 +- libc/testlib/quota.c | 8 +- libc/testlib/startswith.c | 6 +- libc/testlib/testlib.h | 18 +- libc/testlib/testmain.c | 9 +- libc/testlib/testrunner.c | 33 +- libc/thread/pthread_create.c | 7 +- libc/thread/pthread_exit.c | 2 +- libc/thread/spawn.c | 1 + libc/thread/thread.h | 11 +- libc/thread/tls.h | 2 +- libc/thread/wait0.c | 2 +- libc/time/localtime.c | 2 +- libc/vga/tty.c | 81 ++-- libc/x/filecmp.c | 78 ---- libc/x/makedirs.c | 3 +- libc/x/utf16to8.c | 8 +- libc/x/utf32to8.c | 4 +- libc/x/x.h | 147 ++---- libc/x/xasprintf.c | 2 +- libc/x/xasprintf.h | 19 + libc/x/xbasename.c | 2 +- libc/x/xdie.c | 2 +- libc/x/xgetline.h | 11 + libc/x/xhomedir.c | 1 + libc/x/xiso8601.h | 19 + libc/x/xjoinpaths.c | 2 +- libc/x/xsigaction.h | 19 + libc/x/xslurp.c | 3 +- libc/x/xspawn.h | 12 + libc/x/xvalloc.c | 2 +- libc/x/xvasprintf.c | 2 +- libc/x/xvspawn.c | 8 +- libc/zipos/get.c | 2 +- libc/zipos/notat.c | 1 - libc/zipos/open.c | 6 +- libc/zipos/stat.c | 1 - net/finger/fingersyn.c | 4 +- net/finger/getosname.c | 4 +- net/http/underlong.c | 4 +- net/http/visualizecontrolcodes.c | 4 +- net/https/chaincertificate.c | 2 +- net/https/finishcertificate.c | 10 +- net/https/sslcache.c | 2 +- test/dsp/core/alaw_test.c | 2 +- test/dsp/core/getintegercoefficients_test.c | 3 +- test/dsp/core/sad16x8n_test.c | 2 +- test/dsp/core/scalevolume_test.c | 2 +- test/dsp/scale/magikarp_test.c | 2 +- test/dsp/scale/scale_test.c | 2 +- test/dsp/tty/windex_test.c | 2 +- test/libc/calls/access_test.c | 3 +- test/libc/calls/commandv_test.c | 2 +- test/libc/calls/diagnose_syscall_test.c | 4 +- test/libc/calls/dup_test.c | 2 +- test/libc/calls/ftruncate_test.c | 2 +- test/libc/calls/getcwd_test.c | 2 +- test/libc/calls/ioctl_siocgifconf_test.c | 2 +- test/libc/calls/mkdir_test.c | 2 +- test/libc/calls/mkntcmdline_test.c | 2 +- test/libc/calls/mkntenvblock_test.c | 2 +- test/libc/calls/mkntpath_test.c | 2 +- test/libc/calls/open_test.c | 2 +- test/libc/calls/pledge_test.c | 2 +- test/libc/calls/poll_test.c | 10 +- test/libc/calls/readlinkat_test.c | 8 +- test/libc/calls/setrlimit_test.c | 3 +- test/libc/calls/sigsuspend_test.c | 4 +- test/libc/calls/stat_test.c | 2 +- test/libc/calls/unveil_test.c | 5 +- test/libc/calls/writev_test.c | 2 +- test/libc/dns/dnsheader_test.c | 2 +- test/libc/fmt/basename_test.c | 2 +- test/libc/fmt/dirname_test.c | 2 +- test/libc/fmt/fmt_test.c | 439 +++++++++--------- test/libc/fmt/formatint64thousands_test.c | 1 - test/libc/fmt/palandprintf_test.c | 16 +- test/libc/fmt/sprintf_s_test.c | 7 +- test/libc/fmt/stripexts_test.c | 2 +- test/libc/fmt/zleb64_test.c | 2 +- test/libc/intrin/asan_test.c | 2 +- test/libc/intrin/bextra_test.c | 6 +- test/libc/intrin/bitreverse_test.c | 34 +- test/libc/intrin/countbits_test.c | 2 +- test/libc/intrin/intrin_test.c | 2 +- test/libc/intrin/lock_test.c | 248 ++++++++++ test/libc/intrin/memcmp_test.c | 2 +- test/libc/intrin/memmove_test.c | 2 +- test/libc/intrin/memset_test.c | 2 +- test/libc/intrin/pthread_mutex_lock2_test.c | 2 +- test/libc/intrin/pthread_mutex_lock_test.c | 5 +- test/libc/intrin/pthread_once_test.c | 2 +- test/libc/intrin/rounddown2pow_test.c | 26 +- test/libc/intrin/roundup2log_test.c | 26 +- test/libc/intrin/roundup2pow_test.c | 30 +- test/libc/intrin/strlen_test.c | 1 - test/libc/intrin/test.mk | 9 + test/libc/log/appendresourcereport_test.c | 2 + test/libc/log/backtrace_test.c | 62 +-- test/libc/mem/arena_test.c | 4 +- test/libc/mem/comparator_test.c | 110 ----- test/libc/mem/djbsort_test.c | 2 +- test/libc/mem/malloc_test.c | 2 +- test/libc/mem/qsort_test.c | 47 +- test/libc/mem/realloc_in_place_test.c | 2 +- test/libc/mem/replacestr_test.c | 22 +- test/libc/mem/tarjan_test.c | 16 +- test/libc/nexgen32e/cescapec_test.c | 22 +- test/libc/nexgen32e/gclongjmp_test.c | 4 +- test/libc/nexgen32e/memset_test.c | 2 +- test/libc/nexgen32e/strcaseconv_test.c | 2 +- test/libc/nexgen32e/strsak32_test.c | 2 +- test/libc/{thread => runtime}/clone_test.c | 19 - test/libc/runtime/mmap_test.c | 11 +- test/libc/runtime/mprotect_test.c | 8 +- test/libc/sock/sendfile_test.c | 2 +- test/libc/sock/sendrecvmsg_test.c | 2 +- test/libc/stdio/devrand_test.c | 2 +- test/libc/stdio/dirstream_test.c | 17 +- test/libc/stdio/dtoa_test.c | 2 +- test/libc/stdio/dumphexc_test.c | 2 +- test/libc/stdio/ecvt_test.c | 5 +- test/libc/stdio/fgetln_test.c | 8 +- test/libc/stdio/fgets_test.c | 2 +- test/libc/stdio/fputs_test.c | 2 +- test/libc/stdio/ftell_test.c | 2 +- test/libc/stdio/fwrite_test.c | 2 +- test/libc/stdio/iconv_test.c | 2 +- test/libc/stdio/joinstrlist_test.c | 2 +- test/libc/stdio/memory_test.c | 2 +- test/libc/stdio/mt19937_test.c | 2 +- test/libc/stdio/tmpfile_test.c | 6 +- test/libc/stdio/vappendf_test.c | 2 +- test/libc/str/bsr_test.c | 10 +- test/libc/str/bzero_test.c | 2 +- test/libc/str/crc32c_test.c | 2 +- test/libc/str/crc32z_test.c | 2 +- test/libc/str/longsort_test.c | 12 +- test/libc/str/memcasecmp_test.c | 2 +- test/libc/str/regex_test.c | 2 +- test/libc/str/strcasestr_test.c | 2 +- test/libc/str/strcmp_test.c | 2 +- test/libc/str/strstr_test.c | 2 +- test/libc/str/tpenc_test.c | 44 +- test/libc/str/undeflate_test.c | 168 ------- test/libc/thread/pthread_barrier_wait_test.c | 2 +- test/libc/thread/pthread_rwlock_rdlock_test.c | 2 +- test/libc/thread/spawn_test.c | 2 +- test/libc/time/clock_gettime_test.c | 2 +- test/libc/tinymath/acos_test.c | 18 +- test/libc/tinymath/acosh_test.c | 2 +- test/libc/tinymath/asin_test.c | 18 +- test/libc/tinymath/asinh_test.c | 35 +- test/libc/tinymath/atan2_test.c | 308 ++++++------ test/libc/tinymath/atan2l_test.c | 53 +-- test/libc/tinymath/atan_test.c | 32 +- test/libc/tinymath/atanh_test.c | 41 +- test/libc/tinymath/atanl_test.c | 2 +- test/libc/tinymath/cbrt_test.c | 32 +- test/libc/tinymath/ceil_test.c | 2 +- test/libc/tinymath/copysign_test.c | 2 +- test/libc/tinymath/cos_test.c | 34 +- test/libc/tinymath/cosh_test.c | 2 +- test/libc/tinymath/csqrt_test.c | 7 +- test/libc/tinymath/erf_test.c | 2 +- test/libc/tinymath/exp10_test.c | 2 +- test/libc/tinymath/exp2_test.c | 2 +- test/libc/tinymath/exp2l_test.c | 2 +- test/libc/tinymath/exp_test.c | 51 +- test/libc/tinymath/expm1_test.c | 75 +-- test/libc/tinymath/fabs_test.c | 2 +- test/libc/tinymath/floor_test.c | 2 +- test/libc/tinymath/fmod_test.c | 2 +- test/libc/tinymath/fsum_test.c | 8 +- test/libc/tinymath/gamma_test.c | 2 +- test/libc/tinymath/hypot_test.c | 2 +- test/libc/tinymath/ldexp_test.c | 131 +++--- test/libc/tinymath/log10_test.c | 2 +- test/libc/tinymath/log1p_test.c | 2 +- test/libc/tinymath/log2_test.c | 2 +- test/libc/tinymath/log_test.c | 2 +- test/libc/tinymath/measureentropy_test.c | 2 +- test/libc/tinymath/powl_test.c | 129 ++--- test/libc/tinymath/round_test.c | 2 +- test/libc/tinymath/sin_test.c | 58 +-- test/libc/tinymath/sincos_test.c | 16 +- test/libc/tinymath/sinh_test.c | 2 +- test/libc/tinymath/sqrt_test.c | 2 +- test/libc/tinymath/strtod_test.c | 10 +- test/libc/tinymath/tan_test.c | 33 +- test/libc/tinymath/tanh_test.c | 61 +-- test/libc/tinymath/tgamma_test.c | 34 +- test/libc/tinymath/trunc_test.c | 2 +- test/libc/x/filecmp_test.c | 66 --- test/libc/x/makedirs_test.c | 2 +- test/libc/x/utf16to32_test.c | 2 +- test/libc/x/utf16to8_test.c | 2 +- test/libc/x/utf8to16_test.c | 2 +- test/libc/x/utf8to32_test.c | 2 +- test/libc/x/xasprintf_test.c | 6 +- test/libc/x/xjoinpaths_test.c | 2 +- test/libc/x/xslurp_test.c | 2 +- test/libc/x/xstrcat_test.c | 3 +- test/libc/xed/x86ild_lib.c | 2 +- test/libc/xed/x86ild_test.c | 2 +- test/libc/zipos/open_test.c | 2 +- test/net/http/decodebase64_test.c | 2 +- test/net/http/decodelatin1_test.c | 2 +- test/net/http/encodebase64_test.c | 2 +- test/net/http/encodehttpheadervalue_test.c | 2 +- test/net/http/escapehtml_test.c | 2 +- test/net/http/escapejsstringliteral_test.c | 2 +- test/net/http/escapeurlparam_test.c | 2 +- test/net/http/indentlines_test.c | 2 +- test/net/http/isacceptablepath_test.c | 2 +- test/net/http/parsehttpmessage_test.c | 2 +- test/net/http/parseurl_test.c | 2 +- test/net/http/underlong_test.c | 2 +- test/net/http/visualizecontrolcodes_test.c | 20 +- test/net/https/mbedtls_test.c | 22 +- test/tool/build/lib/divmul_test.c | 13 +- test/tool/build/lib/interner_test.c | 2 +- test/tool/build/lib/javadown_test.c | 2 +- test/tool/build/lib/machine_test.c | 2 +- test/tool/build/lib/modrm_test.c | 2 +- test/tool/build/lib/optest.c | 2 +- test/tool/build/lib/pty_test.c | 2 +- test/tool/net/redbean_test.c | 4 +- test/tool/plinko/plinko_test.c | 4 +- test/tool/viz/lib/convoindex_test.c | 2 +- test/tool/viz/lib/fun_test.c | 2 +- test/tool/viz/lib/halfblit_test.c | 2 +- third_party/bzip2/blocksort.c | 2 +- third_party/bzip2/bzip2.c | 3 +- third_party/bzip2/huffman.c | 2 +- third_party/chibicc/as.c | 23 +- third_party/chibicc/asm.c | 20 +- third_party/chibicc/chibicc.c | 32 +- third_party/chibicc/chibicc.h | 6 +- third_party/chibicc/codegen.c | 5 +- third_party/chibicc/dox1.c | 13 +- third_party/chibicc/dox2.c | 9 +- third_party/chibicc/file.c | 5 +- third_party/chibicc/parse.c | 1 + third_party/chibicc/preprocess.c | 1 + third_party/chibicc/pybind.c | 10 +- third_party/chibicc/tokenize.c | 4 +- third_party/dlmalloc/dlmalloc.c | 8 +- third_party/dlmalloc/dlmalloc.mk | 7 +- third_party/dlmalloc/dlmalloc_abort.greg.c | 4 +- third_party/dlmalloc/locks.inc | 31 ++ third_party/dlmalloc/mspaces.inc | 4 +- third_party/linenoise/linenoise.c | 30 +- third_party/lua/ldo.c | 7 +- third_party/lua/lobject.h | 4 +- third_party/lua/lrepl.c | 10 +- third_party/lua/lua.main.c | 2 +- third_party/lua/luaencodejsondata.c | 4 +- third_party/lua/luaencodeluadata.c | 2 +- third_party/lua/luaformatstack.c | 2 +- third_party/lua/lunix.c | 12 +- third_party/lua/serialize.c | 2 +- third_party/make/hash.c | 4 +- third_party/make/job.c | 2 +- third_party/mbedtls/bigmul.c | 1 - third_party/mbedtls/bignum.c | 2 +- third_party/mbedtls/des.c | 2 +- third_party/mbedtls/ecp.c | 2 +- third_party/mbedtls/ecp256.c | 2 +- third_party/mbedtls/ecp384.c | 2 +- third_party/mbedtls/formatclientciphers.c | 2 +- third_party/mbedtls/rsa.c | 2 +- third_party/mbedtls/test/lib.c | 4 +- third_party/mbedtls/test/lib.h | 3 +- third_party/musl/crypt_blowfish.c | 2 +- third_party/nsync/futex.c | 2 +- third_party/nsync/malloc.c | 10 +- third_party/nsync/mu.h | 1 + third_party/nsync/yield.c | 2 +- .../Modules/_decimal/libmpdec/transpose.c | 2 +- third_party/python/Modules/getpath.c | 2 +- third_party/python/Modules/posixmodule.c | 4 +- third_party/python/Modules/selectmodule.c | 2 +- third_party/python/Modules/tlsmodule.c | 2 +- third_party/python/Modules/unicodedata.c | 10 +- .../python/Modules/unicodedata_getcode.c | 18 +- .../Modules/unicodedata_getdecomprecord.c | 2 +- .../python/Modules/unicodedata_nfcnfkc.c | 8 +- .../python/Modules/unicodedata_nfdnfkd.c | 6 +- third_party/python/Objects/listobject.c | 2 +- third_party/python/Objects/unicodeobject.c | 8 +- third_party/python/Parser/node.c | 4 +- third_party/python/Python/codecs.c | 4 +- third_party/python/Python/fatality.c | 3 +- third_party/python/Python/getcopyright.c | 6 +- third_party/python/Python/import.c | 12 +- third_party/python/Python/marshal.c | 2 +- third_party/python/Python/sysmodule.c | 2 +- .../python/Tools/unicode/makecjkcodecs.c | 2 +- third_party/python/pycomp.c | 9 +- third_party/python/pyobj.c | 10 +- third_party/python/runpythonmodule.c | 9 +- third_party/quickjs/call.c | 2 +- third_party/quickjs/qjsc.c | 8 +- third_party/quickjs/quickjs.c | 1 + third_party/quickjs/run-test262.c | 3 +- third_party/sed/compile.c | 2 +- third_party/sed/process.c | 2 +- third_party/smallz4/smallz4cat.c | 2 +- third_party/stb/stb_image.c | 28 +- third_party/stb/stb_vorbis.c | 20 +- third_party/tidy/config.c | 2 +- third_party/unzip/unzip.c | 2 +- third_party/xed/x86ild.greg.c | 6 +- third_party/zip/tailor.h | 1 + third_party/zlib/crc32.c | 14 +- third_party/zlib/zalloc.c | 4 +- third_party/zlib/zutil.c | 2 +- tool/args/args.c | 2 +- tool/build/ar.c | 6 +- tool/build/bigmul.c | 2 +- tool/build/blinkenlights.c | 22 +- tool/build/calculator.c | 16 +- tool/build/chmod.c | 3 +- tool/build/compile.c | 70 +-- tool/build/cp.c | 11 +- tool/build/dd.c | 3 +- tool/build/deltaify.c | 2 +- tool/build/fixupobj.c | 3 +- tool/build/gzip.c | 13 +- tool/build/helpop.c | 4 +- tool/build/lib/argv.c | 2 +- tool/build/lib/buffer.c | 6 +- tool/build/lib/clmul.c | 4 +- tool/build/lib/demangle.c | 2 +- tool/build/lib/dis.c | 4 +- tool/build/lib/diself.c | 4 +- tool/build/lib/disinst.c | 4 +- tool/build/lib/elfwriter.c | 8 +- tool/build/lib/elfwriter_zip.c | 15 +- tool/build/lib/eztls.c | 2 + tool/build/lib/instruction.c | 4 +- tool/build/lib/javadown.c | 2 +- tool/build/lib/persist.c | 12 +- tool/build/lib/psk.c | 6 +- tool/build/lib/pty.c | 6 +- tool/build/lib/syscall.c | 2 +- tool/build/lib/throw.c | 2 +- tool/build/lz4toasm.c | 2 +- tool/build/mkdeps.c | 14 +- tool/build/mkdir.c | 3 +- tool/build/mv.c | 9 +- tool/build/ocat.c | 5 +- tool/build/package.c | 14 +- tool/build/pledge.c | 4 +- tool/build/pstrace.c | 19 +- tool/build/refactor.c | 8 +- tool/build/rm.c | 3 +- tool/build/rollup.c | 18 +- tool/build/runit.c | 16 +- tool/build/runitd.c | 17 +- tool/build/strace.c | 5 +- tool/build/touch.c | 3 +- tool/build/unbuffer.c | 2 + tool/build/unbundle.c | 7 +- tool/build/xlat.c | 8 +- tool/build/zipobj.c | 6 +- tool/decode/elf.c | 6 +- tool/decode/lib/asmcodegen.c | 2 +- tool/decode/pe2.c | 14 +- tool/decode/scrubdox.c | 8 +- tool/decode/x87.c | 2 +- tool/decode/xor.c | 2 +- tool/decode/zip.c | 102 ++-- tool/decode/zip2.c | 88 ++-- tool/net/fetch.inc | 36 +- tool/net/lfuncs.c | 10 +- tool/net/ljson.c | 1 - tool/net/redbean.c | 87 ++-- tool/net/wb.c | 17 +- tool/plinko/lib/gc.c | 8 +- tool/plinko/lib/histo.h | 4 +- tool/plinko/lib/plinko.c | 2 +- tool/plinko/lib/printchar.c | 4 +- tool/plinko/lib/printf.c | 2 +- tool/plinko/lib/printheap.c | 2 +- tool/plinko/lib/read.c | 2 +- tool/scripts/asmexpr | 4 +- tool/scripts/awk1 | 2 + tool/scripts/awk2 | 2 + tool/scripts/awk3 | 2 + tool/scripts/awk4 | 2 + tool/scripts/awk5 | 2 + tool/scripts/awk6 | 2 + tool/scripts/awk7 | 2 + tool/scripts/awk8 | 2 + tool/scripts/bf | 4 + tool/scripts/bloat | 5 + tool/scripts/configure-emacs.sh | 17 - tool/scripts/distribute.sh | 43 -- tool/scripts/ezgdb | 4 + tool/scripts/get-deps.py | 10 + tool/scripts/grep | 12 +- tool/scripts/install-emacs.sh | 15 - tool/scripts/loc | 6 + tool/scripts/obj | 3 + tool/scripts/pb | 16 + tool/scripts/pe | 9 + tool/scripts/performance | 2 + tool/scripts/po | 14 + tool/scripts/powersave | 2 + tool/scripts/px | 17 + tool/scripts/re | 4 + tool/scripts/renameheader | 15 + tool/scripts/wut | 98 ++++ tool/viz/basicidea.c | 3 +- tool/viz/bf.c | 10 +- tool/viz/cpuid.c | 14 +- tool/viz/deathstar.c | 59 +-- tool/viz/derasterize.c | 16 +- tool/viz/double2int.c | 2 +- tool/viz/dumphexc.c | 2 +- tool/viz/fontspace.c | 10 +- tool/viz/generatematrix.c | 2 +- tool/viz/generatetortureimage.c | 7 +- tool/viz/getglyph.c | 26 +- tool/viz/int2float.c | 37 +- tool/viz/lib/bilinearscale.c | 20 +- tool/viz/lib/dither.c | 2 +- tool/viz/lib/formatmatrix-byte.c | 6 +- tool/viz/lib/formatmatrix-double.c | 2 +- tool/viz/lib/formatmatrix-float.c | 2 +- tool/viz/lib/formatmatrix-short.c | 5 +- tool/viz/lib/formatstringtable-assembly.c | 2 +- tool/viz/lib/graphic.h | 4 +- tool/viz/lib/resizegraphic.c | 2 +- tool/viz/lib/ycbcr2rgb3.c | 8 +- tool/viz/life.c | 44 +- tool/viz/magikarp.c | 18 +- tool/viz/maxmind.c | 2 +- tool/viz/memplan.c | 2 +- tool/viz/memzoom.c | 22 +- tool/viz/ntmaster.c | 2 +- tool/viz/printansi.c | 2 +- tool/viz/printdos2errno.c | 11 +- tool/viz/printimage.c | 2 +- tool/viz/printvideo.c | 12 +- tool/viz/tailf.c | 4 +- tool/viz/unicode.c | 6 +- tool/viz/vdsosyms.c | 2 +- 959 files changed, 4065 insertions(+), 4868 deletions(-) create mode 100644 examples/gc.c delete mode 100644 examples/ispell.c rename libc/{mem/io.h => calls/copyfd.internal.h} (100%) rename libc/{calls => intrin}/_getauxval.internal.h (59%) rename libc/{str => intrin}/bsf.c (95%) rename libc/{nexgen32e => intrin}/bsf.h (76%) rename libc/{str => intrin}/bsfl.c (95%) rename libc/{str => intrin}/bsfll.c (94%) rename libc/{str => intrin}/bsr.c (95%) rename libc/{nexgen32e => intrin}/bsr.h (76%) rename libc/{nexgen32e => intrin}/bsr128.S (96%) rename libc/{str => intrin}/bsrl.c (95%) rename libc/{str => intrin}/bsrll.c (94%) rename libc/{runtime/close_s.c => intrin/exitr.c} (81%) rename libc/{calls => intrin}/extend.internal.h (100%) rename libc/intrin/{_have_fsgsbase.c => have_fsgsbase.c} (100%) rename libc/intrin/{_rdfsbase.c => rdfsbase.c} (100%) rename libc/intrin/{_rdgsbase.c => rdgsbase.c} (100%) rename libc/{calls => intrin}/strace.internal.h (100%) rename libc/{str => intrin}/tpenc.h (84%) rename libc/intrin/{_wrfsbase.c => wrfsbase.c} (100%) rename libc/intrin/{_wrgsbase.c => wrgsbase.c} (100%) create mode 100644 libc/isystem/avx2intrin.h create mode 100644 libc/isystem/avxintrin.h create mode 100644 libc/isystem/emmintrin.h create mode 100644 libc/isystem/pmmintrin.h create mode 100644 libc/isystem/shaintrin.h create mode 100644 libc/isystem/smmintrin.h create mode 100644 libc/isystem/tmmintrin.h create mode 100644 libc/isystem/wmmintrin.h create mode 100644 libc/isystem/xmmintrin.h create mode 100644 libc/log/appendresourcereport.internal.h create mode 100644 libc/log/getcallername.internal.h rename libc/log/{getttycols.c => log_exit.c} (75%) rename test/libc/mem/replacestr_test.inc => libc/log/log_get_errno.c (74%) create mode 100644 libc/log/log_retrace.c rename libc/{intrin/fatalbuf.c => log/log_set_errno.c} (91%) create mode 100644 libc/log/log_untrace.c delete mode 100644 libc/log/onkill.c rename libc/{runtime => mem}/gc.h (87%) rename libc/{runtime => mem}/gc.internal.h (54%) delete mode 100644 libc/nexgen32e/cmpsb.S delete mode 100644 libc/nexgen32e/cmpsl.S delete mode 100644 libc/nexgen32e/cmpsq.S delete mode 100644 libc/nexgen32e/cmpsw.S delete mode 100644 libc/nexgen32e/cmpub.S delete mode 100644 libc/nexgen32e/cmpul.S delete mode 100644 libc/nexgen32e/cmpuq.S delete mode 100644 libc/nexgen32e/cmpuw.S rename libc/runtime/{buffer.h => buffer.internal.h} (61%) rename libc/{thread => runtime}/clone-linux.S (100%) rename libc/{thread => runtime}/clone-nt.S (100%) rename libc/{thread => runtime}/clone-openbsd.S (100%) rename libc/{thread => runtime}/clone.c (96%) create mode 100644 libc/runtime/clone.internal.h delete mode 100644 libc/runtime/getinstructionlengths.c rename libc/stdio/{append.internal.h => append.h} (100%) create mode 100755 libc/str/_tpenc.h delete mode 100644 libc/str/errfun.h delete mode 100644 libc/str/undeflate.c delete mode 100644 libc/str/undeflate.h delete mode 100644 libc/x/filecmp.c create mode 100644 libc/x/xasprintf.h create mode 100644 libc/x/xgetline.h create mode 100644 libc/x/xiso8601.h create mode 100644 libc/x/xsigaction.h create mode 100644 libc/x/xspawn.h create mode 100644 test/libc/intrin/lock_test.c delete mode 100644 test/libc/mem/comparator_test.c rename test/libc/{thread => runtime}/clone_test.c (87%) delete mode 100644 test/libc/str/undeflate_test.c delete mode 100644 test/libc/x/filecmp_test.c create mode 100755 tool/scripts/awk1 create mode 100755 tool/scripts/awk2 create mode 100755 tool/scripts/awk3 create mode 100755 tool/scripts/awk4 create mode 100755 tool/scripts/awk5 create mode 100755 tool/scripts/awk6 create mode 100755 tool/scripts/awk7 create mode 100755 tool/scripts/awk8 create mode 100755 tool/scripts/bf create mode 100755 tool/scripts/bloat delete mode 100755 tool/scripts/configure-emacs.sh delete mode 100755 tool/scripts/distribute.sh create mode 100755 tool/scripts/ezgdb delete mode 100755 tool/scripts/install-emacs.sh create mode 100755 tool/scripts/loc create mode 100755 tool/scripts/obj create mode 100755 tool/scripts/pb create mode 100755 tool/scripts/pe create mode 100755 tool/scripts/performance create mode 100755 tool/scripts/po create mode 100755 tool/scripts/powersave create mode 100755 tool/scripts/px create mode 100755 tool/scripts/re create mode 100755 tool/scripts/renameheader create mode 100755 tool/scripts/wut diff --git a/ape/ape.S b/ape/ape.S index 873c1b523..13eba1c7e 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -39,7 +39,6 @@ #include "libc/elf/def.h" #include "libc/macho.internal.h" #include "libc/nexgen32e/uart.internal.h" -#include "libc/nexgen32e/vidya.internal.h" #include "libc/nt/pedef.internal.h" #include "libc/runtime/pc.internal.h" #include "libc/sysv/consts/prot.h" diff --git a/dsp/scale/gyarados.c b/dsp/scale/gyarados.c index 5367ce4e0..5bd815d11 100644 --- a/dsp/scale/gyarados.c +++ b/dsp/scale/gyarados.c @@ -21,14 +21,14 @@ #include "dsp/core/ituround.h" #include "dsp/core/q.h" #include "dsp/core/twixt8.h" +#include "libc/intrin/bsr.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/runtime/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" @@ -203,8 +203,8 @@ void *Gyarados(long dyw, long dxw, int dst[dyw][dxw], long syw, long sxw, CHECK_LE(sxn, sxw); CHECK_LE(dyn, dyw); CHECK_LE(dxn, dxw); - CHECK_LT(bsrl(syn) + bsrl(sxn), 32); - CHECK_LT(bsrl(dyn) + bsrl(dxn), 32); + CHECK_LT(_bsrl(syn) + _bsrl(sxn), 32); + CHECK_LT(_bsrl(dyn) + _bsrl(dxn), 32); CHECK_LE(dyw, 0x7fff); CHECK_LE(dxw, 0x7fff); CHECK_LE(syw, 0x7fff); diff --git a/dsp/tty/ident.c b/dsp/tty/ident.c index 2d6a2dccd..45f7e83e3 100644 --- a/dsp/tty/ident.c +++ b/dsp/tty/ident.c @@ -83,10 +83,11 @@ int ttyident(struct TtyIdent *ti, int ttyinfd, int ttyoutfd) { if (ttyident_probe(ti, ttyinfd, ttyoutfd, "\e[>c") != -1) { rc = 0; memset(&outer, 0, sizeof(outer)); - if (ti->id == 83 /* GNU Screen */ && (ti->next || weaken(malloc)) && + if (ti->id == 83 /* GNU Screen */ && (ti->next || _weaken(malloc)) && ttyident_probe(&outer, ttyinfd, ttyoutfd, "\eP\e[>c\e\\") != -1 && - (ti->next = (ti->next ? ti->next - : weaken(malloc)(sizeof(struct TtyIdent))))) { + (ti->next = + (ti->next ? ti->next + : _weaken(malloc)(sizeof(struct TtyIdent))))) { memcpy(ti->next, &outer, sizeof(outer)); } else { free_s(&ti->next); diff --git a/dsp/tty/sendtitle.c b/dsp/tty/sendtitle.c index 520dac6ba..7950aaae6 100644 --- a/dsp/tty/sendtitle.c +++ b/dsp/tty/sendtitle.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/tty.h" #include "libc/mem/arraylist2.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/x/x.h" /* TODO(jart): DELETE */ diff --git a/dsp/tty/ttyraw.c b/dsp/tty/ttyraw.c index c5c28d4ed..9aba855d7 100644 --- a/dsp/tty/ttyraw.c +++ b/dsp/tty/ttyraw.c @@ -25,7 +25,7 @@ #include "libc/calls/ucontext.h" #include "libc/log/log.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" @@ -33,6 +33,7 @@ #include "libc/sysv/consts/sig.h" #include "libc/sysv/errfuns.h" #include "libc/x/x.h" +#include "libc/x/xsigaction.h" /* TODO(jart): DELETE */ diff --git a/examples/compress.c b/examples/compress.c index bd7b80461..bcb123738 100644 --- a/examples/compress.c +++ b/examples/compress.c @@ -13,7 +13,7 @@ #include "libc/fmt/conv.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/examples/cosh.c b/examples/cosh.c index bf91bc7a1..e079977b6 100644 --- a/examples/cosh.c +++ b/examples/cosh.c @@ -9,18 +9,21 @@ #endif #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" +#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/timespec.h" +#include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" +#include "libc/log/appendresourcereport.internal.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/clock.h" @@ -151,7 +154,7 @@ int main(int argc, char *argv[]) { while ((line = linenoiseWithHistory(prompt, "cmd"))) { n = 0; start = line; - if (startswith(start, "time ")) { + if (_startswith(start, "time ")) { timeit = true; start += 5; } else { diff --git a/examples/crashreport2.c b/examples/crashreport2.c index e2eaccf1b..5ac2c7a66 100644 --- a/examples/crashreport2.c +++ b/examples/crashreport2.c @@ -8,6 +8,7 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/calls/calls.h" +#include "libc/calls/struct/sigset.h" #include "libc/log/log.h" #include "libc/stdio/stdio.h" diff --git a/examples/curl.c b/examples/curl.c index 7c17861fb..4d3007348 100644 --- a/examples/curl.c +++ b/examples/curl.c @@ -7,7 +7,6 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/dce.h" @@ -15,15 +14,16 @@ #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" -#include "libc/stdio/rand.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/sock/goodsocket.internal.h" #include "libc/sock/sock.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/slice.h" #include "libc/str/str.h" @@ -40,6 +40,7 @@ #include "libc/sysv/consts/tcp.h" #include "libc/time/struct/tm.h" #include "libc/x/x.h" +#include "libc/x/xsigaction.h" #include "net/http/http.h" #include "net/http/url.h" #include "net/https/https.h" diff --git a/examples/datauri.c b/examples/datauri.c index c07f569ff..70c24db19 100644 --- a/examples/datauri.c +++ b/examples/datauri.c @@ -8,7 +8,8 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/log/log.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/x/x.h" #include "net/http/escape.h" diff --git a/examples/date.c b/examples/date.c index 266808ebf..53a8d8351 100644 --- a/examples/date.c +++ b/examples/date.c @@ -7,9 +7,9 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" -#include "libc/x/x.h" +#include "libc/x/xiso8601.h" /** * @fileoverview ISO-8601 international high-precision timestamp printer. diff --git a/examples/decompress.c b/examples/decompress.c index 617da7732..b1f8eaf12 100644 --- a/examples/decompress.c +++ b/examples/decompress.c @@ -11,7 +11,7 @@ #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "third_party/zlib/zlib.h" diff --git a/examples/defer-statements.c b/examples/defer-statements.c index e2a7b2852..cdb9be3ab 100644 --- a/examples/defer-statements.c +++ b/examples/defer-statements.c @@ -8,7 +8,7 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" /** diff --git a/examples/forkrand.c b/examples/forkrand.c index 691fdb6b4..18aad3392 100644 --- a/examples/forkrand.c +++ b/examples/forkrand.c @@ -11,7 +11,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/nt/nt/process.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" diff --git a/examples/gc.c b/examples/gc.c new file mode 100644 index 000000000..c92c166a2 --- /dev/null +++ b/examples/gc.c @@ -0,0 +1,17 @@ +#if 0 +/*─────────────────────────────────────────────────────────────────╗ +│ To the extent possible under law, Justine Tunney has waived │ +│ all copyright and related or neighboring rights to this file, │ +│ as it is written in the following disclaimers: │ +│ • http://unlicense.org/ │ +│ • http://creativecommons.org/publicdomain/zero/1.0/ │ +╚─────────────────────────────────────────────────────────────────*/ +#endif +#include "libc/mem/gc.h" +#include "libc/mem/mem.h" +#include "libc/str/str.h" + +int main(int argc, char *argv[]) { + char *p = _gc(malloc(64)); + strcpy(p, "this memory is free'd when main() returns"); +} diff --git a/examples/getrandom.c b/examples/getrandom.c index a0dd600c8..e60a1b174 100644 --- a/examples/getrandom.c +++ b/examples/getrandom.c @@ -7,20 +7,21 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" #include "libc/errno.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" #include "libc/nt/runtime.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" -#include "libc/stdio/xorshift.h" #include "libc/stdio/stdio.h" +#include "libc/stdio/xorshift.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" diff --git a/examples/greenbean.c b/examples/greenbean.c index fe4ed1d41..fb76e253a 100644 --- a/examples/greenbean.c +++ b/examples/greenbean.c @@ -15,6 +15,7 @@ #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" +#include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/itoa.h" #include "libc/intrin/atomic.h" diff --git a/examples/hertz.c b/examples/hertz.c index 35cc61075..477a8e3f8 100644 --- a/examples/hertz.c +++ b/examples/hertz.c @@ -14,8 +14,7 @@ #include "libc/stdio/stdio.h" #include "libc/sysv/consts/itimer.h" #include "libc/sysv/consts/sig.h" -#include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" const struct itimerval kHertz = { {1, 0}, diff --git a/examples/img.c b/examples/img.c index 37af07737..621b77c78 100644 --- a/examples/img.c +++ b/examples/img.c @@ -9,9 +9,11 @@ #endif #include "libc/dce.h" #include "libc/log/log.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "net/http/escape.h" #include "net/http/http.h" #include "third_party/getopt/getopt.h" @@ -43,15 +45,15 @@ void PrintImg(const char *path) { size_t n; int opt, i, yn, xn, cn, w, h; void *img, *pix, *src, *mime; - if (!(img = gc(xslurp(path, &n)))) exit(2); - if (!(pix = gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3); + if (!(img = _gc(xslurp(path, &n)))) exit(2); + if (!(pix = _gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3); if (linktag) { printf("", path); } src = path; if (datauri) { src = xasprintf("data:%s;base64,%s", FindContentType(path, -1), - gc(EncodeBase64(img, n, &n))); + _gc(EncodeBase64(img, n, &n))); } w = (xn + (1 << scale) / 2) >> scale; h = (yn + (1 << scale) / 2) >> scale; diff --git a/examples/ispell.c b/examples/ispell.c deleted file mode 100644 index 9b45b1624..000000000 --- a/examples/ispell.c +++ /dev/null @@ -1,160 +0,0 @@ -#if 0 -/*─────────────────────────────────────────────────────────────────╗ -│ To the extent possible under law, Justine Tunney has waived │ -│ all copyright and related or neighboring rights to this file, │ -│ as it is written in the following disclaimers: │ -│ • http://unlicense.org/ │ -│ • http://creativecommons.org/publicdomain/zero/1.0/ │ -╚─────────────────────────────────────────────────────────────────*/ -#endif -#include "libc/mem/alg.h" -#include "libc/mem/arraylist.internal.h" -#include "libc/mem/critbit0.h" -#include "libc/intrin/bits.h" -#include "libc/calls/calls.h" -#include "libc/fmt/conv.h" -#include "libc/log/check.h" -#include "libc/log/log.h" -#include "libc/macros.internal.h" -#include "libc/mem/mem.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/str/tpdecode.internal.h" -#include "libc/sysv/consts/fileno.h" -#include "libc/x/x.h" - -STATIC_YOINK("zip_uri_support"); - -/** - * @fileoverview Simple Interactive Spell Checker. - * - * This is an attempt to get spell checking to work in Emacs across - * platforms. While the computer science behind spell checking is very - * simple, unfortunately Emacs probes all these System Five spell progs - * similar to how websites have been known to probe User-Agent strings. - * - * Here's how we believe the repl works: - * - * $ make -j8 o//examples/ispell.com - * $ o//examples/ispell.com - * @(#) Cosmopolitan Ispell Version 3.4.00 8 Feb 2015 - * word: hello - * ok - * word: héllo - * how about: hills, hello, hilly, jello - * word: lova - * how about: diva, dona, dora, dove, elva, fora, hove, iota - * word: hecruhecrue - * not found - * - * The dictionary for this program is embedded as a text file within the - * zip structure of the binary. It can be edited after distribution. - * - * It's possible to go even fancier than what this code is doing, by - * using cmudict phonemes, bloom filters, unicode tables e.g. e vs. é, - * and even doing ML similar to Google's online spell checker. - * - * TODO: Figure out why Emacs rejects this interface. - */ - -#define MISSING_LETTER_DISTANCE 5 -#define MAX_NEARBY_WORD_DISTANCE 6 -#define MAX_NEARBY_RESULTS 8 - -FILE *f; -char *line; -size_t linesize; -const char *query; -struct critbit0 words; /* does O(log 𝑛) fast path lookup */ - -struct NearbyWords { - size_t i, n; - struct WordMatch { - long dist; - char *word; - } * p; -} nearby; - -long WordDistance(const char *a, const char *b) { - long dist; - int gota, gotb; - unsigned long h, p; - wint_t chara, charb; - dist = p = 0; - for (;;) { - gota = abs(tpdecode(a, &chara)); /* parses utf-8 multibyte characters */ - gotb = abs(tpdecode(b, &charb)); /* abs() handles -1, always yields � */ - if (!chara && !charb) break; - if (!chara || !charb) { - dist += MISSING_LETTER_DISTANCE; - } else if ((h = hamming(chara, charb))) { - dist += h + p++; /* penalize multiple mismatched letters */ - } - if (chara) a += gota; - if (charb) b += gotb; - } - return dist; -} - -intptr_t ConsiderWord(const char *word, void *arg) { - long dist; - if ((dist = WordDistance(word, query)) < MAX_NEARBY_WORD_DISTANCE) { - append(&nearby, &((struct WordMatch){dist, word})); - } - return 0; -} - -int CompareWords(const struct WordMatch *a, const struct WordMatch *b) { - return a->dist < b->dist; -} - -void FindNearbyWords(void) { - nearby.i = 0; - critbit0_allprefixed(&words, "", ConsiderWord, NULL); - qsort(nearby.p, nearby.i, sizeof(struct WordMatch), (void *)CompareWords); -} - -void SpellChecker(void) { - int i; - printf("@(#) Cosmopolitan Ispell Version 3.4.00 8 Feb 2015\r\n"); - while (!feof(stdin)) { - printf("word: "); - fflush(stdout); - if (getline(&line, &linesize, stdin) > 0) { - query = strtolower(_chomp(line)); - if (critbit0_contains(&words, query)) { - printf("ok\r\n"); - } else { - FindNearbyWords(); - if (nearby.i) { - printf("how about: "); - for (i = 0; i < MIN(MAX_NEARBY_RESULTS, nearby.i); ++i) { - if (i) printf(", "); - fputs(nearby.p[i].word, stdout); - } - printf("\r\n"); - } else { - printf("not found\r\n"); - } - } - } - printf("\r\n"); - } - CHECK_NE(-1, fclose(stdin)); - CHECK_NE(-1, fclose(stdout)); -} - -void LoadWords(void) { - CHECK_NOTNULL((f = fopen("/zip/usr/share/dict/words", "r"))); - while (getline(&line, &linesize, f) > 0) { - critbit0_insert(&words, strtolower(_chomp(line))); - } - CHECK_NE(-1, fclose(f)); -} - -int main(int argc, char *argv[]) { - if (!NoDebug()) ShowCrashReports(); - LoadWords(); - SpellChecker(); - return 0; -} diff --git a/examples/kilo.c b/examples/kilo.c index c6e4df37f..f64321df2 100644 --- a/examples/kilo.c +++ b/examples/kilo.c @@ -58,14 +58,14 @@ Contact: antirez@gmail.com\"\n\ #endif #define _GNU_SOURCE -#include "libc/mem/alg.h" -#include "libc/mem/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/calls/termios.h" #include "libc/calls/weirdtypes.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/log/log.h" +#include "libc/mem/alg.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -355,7 +355,7 @@ int getCursorPosition(int64_t ifd, int64_t ofd, int *rows, int *cols) { * Returns 0 on success, -1 on error. */ int getWindowSize(int64_t ifd, int64_t ofd, int *rows, int *cols) { struct winsize ws; - if (getttysize(STDOUT_FILENO, &ws) == -1 || ws.ws_col == 0) { + if (_getttysize(1, &ws) == -1 || ws.ws_col == 0) { /* ioctl() failed. Try to query the terminal itself. */ int orig_row, orig_col, retval; diff --git a/examples/ls.c b/examples/ls.c index f4a647cb9..9ac3bf00c 100644 --- a/examples/ls.c +++ b/examples/ls.c @@ -11,12 +11,12 @@ #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" #include "libc/log/check.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/dt.h" #include "libc/sysv/consts/s.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" struct stat st; @@ -49,7 +49,7 @@ void List(const char *path) { const char *vpath; if (strcmp(path, ".") == 0) { vpath = ""; - } else if (!endswith(path, "/")) { + } else if (!_endswith(path, "/")) { vpath = _gc(xasprintf("%s/", path)); } else { vpath = path; diff --git a/examples/lstime.c b/examples/lstime.c index 2a1119e84..871a98702 100644 --- a/examples/lstime.c +++ b/examples/lstime.c @@ -7,19 +7,20 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/mem/alg.h" -#include "libc/mem/arraylist2.internal.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timespec.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" +#include "libc/mem/alg.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/dt.h" #include "libc/x/x.h" +#include "libc/x/xiso8601.h" struct stat st; struct Files { diff --git a/examples/nesemu1.cc b/examples/nesemu1.cc index 31ff06279..2e648dbea 100644 --- a/examples/nesemu1.cc +++ b/examples/nesemu1.cc @@ -10,21 +10,21 @@ #include "dsp/tty/itoa8.h" #include "dsp/tty/quant.h" #include "dsp/tty/tty.h" -#include "libc/mem/arraylist2.internal.h" #include "libc/assert.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/winsize.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/inttypes.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" @@ -39,7 +39,8 @@ #include "libc/sysv/consts/poll.h" #include "libc/sysv/consts/sig.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xsigaction.h" #include "libc/zip.h" #include "libc/zipos/zipos.internal.h" #include "third_party/getopt/getopt.h" @@ -286,7 +287,7 @@ void GetTermSize(void) { struct winsize wsize_; wsize_.ws_row = 25; wsize_.ws_col = 80; - getttysize(STDIN_FILENO, &wsize_); + _getttysize(0, &wsize_); FreeSamplingSolution(ssy_); FreeSamplingSolution(ssx_); tyn_ = wsize_.ws_row * 2; diff --git a/examples/panels.c b/examples/panels.c index 070276b9e..ebb62c81b 100644 --- a/examples/panels.c +++ b/examples/panels.c @@ -17,14 +17,15 @@ #include "libc/log/gdb.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "tool/build/lib/panel.h" /** @@ -76,7 +77,7 @@ void GetTtySize(void) { struct winsize wsize; wsize.ws_row = tyn; wsize.ws_col = txn; - getttysize(1, &wsize); + _getttysize(1, &wsize); tyn = wsize.ws_row; txn = wsize.ws_col; } diff --git a/examples/picol.c b/examples/picol.c index 767287b40..11e0b4460 100644 --- a/examples/picol.c +++ b/examples/picol.c @@ -36,6 +36,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/log.h" #include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/examples/rlimit.c b/examples/rlimit.c index 04d0e4796..2dac60cf2 100644 --- a/examples/rlimit.c +++ b/examples/rlimit.c @@ -8,7 +8,7 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rlimit.h" #include "libc/errno.h" #include "libc/intrin/describeflags.internal.h" diff --git a/examples/stat.c b/examples/stat.c index 9d85f4101..5ad75aa02 100644 --- a/examples/stat.c +++ b/examples/stat.c @@ -14,11 +14,11 @@ #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/log/log.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/s.h" -#include "libc/x/x.h" +#include "libc/x/xiso8601.h" /** * @fileoverview File metadata viewer. diff --git a/examples/stringbuffer.c b/examples/stringbuffer.c index 8838f91e4..282fcab01 100644 --- a/examples/stringbuffer.c +++ b/examples/stringbuffer.c @@ -11,7 +11,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" /** diff --git a/examples/time.c b/examples/time.c index a09d0b0aa..aab2c1422 100644 --- a/examples/time.c +++ b/examples/time.c @@ -12,10 +12,11 @@ #include "libc/fmt/itoa.h" #include "libc/log/log.h" #include "libc/math.h" +#include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xspawn.h" /** * @fileoverview command for showing how long a command takes diff --git a/examples/ttyaudio.c b/examples/ttyaudio.c index b17120b7a..14125ee12 100644 --- a/examples/ttyaudio.c +++ b/examples/ttyaudio.c @@ -17,7 +17,7 @@ #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/itimer.h" diff --git a/examples/ttyinfo.c b/examples/ttyinfo.c index 575e964dc..e599e8eb1 100644 --- a/examples/ttyinfo.c +++ b/examples/ttyinfo.c @@ -24,7 +24,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" #define CTRL(C) ((C) ^ 0b01000000) #define WRITE(FD, SLIT) write(FD, SLIT, strlen(SLIT)) @@ -80,7 +80,7 @@ int rawmode(void) { } void getsize(void) { - if (getttysize(1, &wsize) != -1) { + if (_getttysize(1, &wsize) != -1) { printf("termios says terminal size is %hu×%hu\r\n", wsize.ws_col, wsize.ws_row); } else { @@ -148,12 +148,12 @@ int main(int argc, char *argv[]) { if (iscntrl(code[0]) && !code[1]) { printf("is CTRL-%c a.k.a. ^%c\r\n", CTRL(code[0]), CTRL(code[0])); if (code[0] == CTRL('C') || code[0] == CTRL('D')) break; - } else if (startswith(code, "\e[") && endswith(code, "R")) { + } else if (_startswith(code, "\e[") && _endswith(code, "R")) { yn = 1, xn = 1; sscanf(code, "\e[%d;%dR", &yn, &xn); printf("inband signalling says terminal size is %d×%d\r\n", xn, yn); - } else if (startswith(code, "\e[<") && - (endswith(code, "m") || endswith(code, "M"))) { + } else if (_startswith(code, "\e[<") && + (_endswith(code, "m") || _endswith(code, "M"))) { e = 0, y = 1, x = 1; sscanf(code, "\e[<%d;%d;%d%c", &e, &y, &x, &c); printf("mouse %s at %d×%d\r\n", describemouseevent(e | (c == 'm') << 2), diff --git a/examples/unbourne.c b/examples/unbourne.c index a9ba11d97..b9bd8526d 100644 --- a/examples/unbourne.c +++ b/examples/unbourne.c @@ -110,12 +110,11 @@ │ cosmopolitan § the unbourne shell » macros ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#include "libc/mem/alg.h" #include "libc/assert.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/rlimit.h" +#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/tms.h" @@ -124,9 +123,11 @@ #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" #include "libc/mem/alloca.h" #include "libc/mem/mem.h" #include "libc/paths.h" diff --git a/libc/calls/calls.h b/libc/calls/calls.h index b147cf83c..f6fc42a04 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -68,7 +68,6 @@ int chdir(const char *); int chmod(const char *, uint32_t); int chown(const char *, uint32_t, uint32_t); int chroot(const char *); -int clone(void *, void *, size_t, int, void *, int *, void *, int *); int close(int); int close_range(unsigned, unsigned, unsigned); int closefrom(int); @@ -94,7 +93,6 @@ int fchown(int, uint32_t, uint32_t); int fchownat(int, const char *, uint32_t, uint32_t, int); int fcntl(int, int, ...); int fdatasync(int); -int filecmp(const char *, const char *); int flock(int, int); int fork(void); int fsync(int); diff --git a/libc/calls/chdir.c b/libc/calls/chdir.c index 3a65fd719..78c43a239 100644 --- a/libc/calls/chdir.c +++ b/libc/calls/chdir.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/chroot.c b/libc/calls/chroot.c index 0ea2f439e..5cadf7444 100644 --- a/libc/calls/chroot.c +++ b/libc/calls/chroot.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/clock_getres.c b/libc/calls/clock_getres.c index 31d5709e4..7d5c0a531 100644 --- a/libc/calls/clock_getres.c +++ b/libc/calls/clock_getres.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/asan.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/clock_gettime.c b/libc/calls/clock_gettime.c index ea5b79d6f..b943e2d8a 100644 --- a/libc/calls/clock_gettime.c +++ b/libc/calls/clock_gettime.c @@ -20,7 +20,7 @@ #include "libc/calls/asan.internal.h" #include "libc/calls/clock_gettime.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.h" #include "libc/calls/syscall_support-sysv.internal.h" diff --git a/libc/calls/close.c b/libc/calls/close.c index 0a7a1f00a..4008aa78a 100644 --- a/libc/calls/close.c +++ b/libc/calls/close.c @@ -20,10 +20,10 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sock/syscall_fd.internal.h" #include "libc/sysv/errfuns.h" @@ -59,7 +59,7 @@ int close(int fd) { // file descriptors the way __zipos_open() does need to retry if // there's indication this race condition happened. if (__isfdkind(fd, kFdZip)) { - rc = weaken(__zipos_close)(fd); + rc = _weaken(__zipos_close)(fd); } else { if (!IsWindows() && !IsMetal()) { rc = sys_close(fd); @@ -67,9 +67,9 @@ int close(int fd) { rc = 0; } else { if (__isfdkind(fd, kFdEpoll)) { - rc = weaken(sys_close_epoll_nt)(fd); + rc = _weaken(sys_close_epoll_nt)(fd); } else if (__isfdkind(fd, kFdSocket)) { - rc = weaken(sys_closesocket_nt)(g_fds.p + fd); + rc = _weaken(sys_closesocket_nt)(g_fds.p + fd); } else if (__isfdkind(fd, kFdFile) || // __isfdkind(fd, kFdConsole) || // __isfdkind(fd, kFdProcess)) { // diff --git a/libc/calls/close_range.c b/libc/calls/close_range.c index 2fe77764b..9d19965d2 100644 --- a/libc/calls/close_range.c +++ b/libc/calls/close_range.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" #include "libc/limits.h" diff --git a/libc/calls/closefrom.c b/libc/calls/closefrom.c index 4a655b9aa..ec02716f4 100644 --- a/libc/calls/closefrom.c +++ b/libc/calls/closefrom.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" #include "libc/limits.h" diff --git a/libc/calls/commandv.c b/libc/calls/commandv.c index 3e606a77d..10f0d4cee 100644 --- a/libc/calls/commandv.c +++ b/libc/calls/commandv.c @@ -19,7 +19,7 @@ #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/log/libfatal.internal.h" diff --git a/libc/mem/io.h b/libc/calls/copyfd.internal.h similarity index 100% rename from libc/mem/io.h rename to libc/calls/copyfd.internal.h diff --git a/libc/calls/copyfile.c b/libc/calls/copyfile.c index 288b716c4..be9fa71a6 100644 --- a/libc/calls/copyfile.c +++ b/libc/calls/copyfile.c @@ -110,8 +110,8 @@ static int sys_copyfile(const char *src, const char *dst, int flags) { * @param flags may have COPYFILE_PRESERVE_TIMESTAMPS, COPYFILE_NOCLOBBER * @return 0 on success, or -1 w/ errno */ -int copyfile(const char *src, const char *dst, int flags) { - if (!IsWindows() || startswith(src, "/zip/") || startswith(dst, "/zip/")) { +int _copyfile(const char *src, const char *dst, int flags) { + if (!IsWindows() || _startswith(src, "/zip/") || _startswith(dst, "/zip/")) { return sys_copyfile(src, dst, flags); } else { return sys_copyfile_nt(src, dst, flags); diff --git a/libc/calls/copyfile.h b/libc/calls/copyfile.h index f9ba2f877..c2473a02a 100644 --- a/libc/calls/copyfile.h +++ b/libc/calls/copyfile.h @@ -8,7 +8,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int copyfile(const char *, const char *, int) paramsnonnull(); +int _copyfile(const char *, const char *, int) paramsnonnull(); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/dup-nt.c b/libc/calls/dup-nt.c index 3fba97484..598056055 100644 --- a/libc/calls/dup-nt.c +++ b/libc/calls/dup-nt.c @@ -80,9 +80,9 @@ textwindows int sys_dup_nt(int oldfd, int newfd, int flags, int start) { g_fds.p[newfd].mode = g_fds.p[oldfd].mode; g_fds.p[newfd].flags = g_fds.p[oldfd].flags & ~O_CLOEXEC; if (flags & O_CLOEXEC) g_fds.p[newfd].flags |= O_CLOEXEC; - if (g_fds.p[oldfd].kind == kFdSocket && weaken(_dupsockfd)) { + if (g_fds.p[oldfd].kind == kFdSocket && _weaken(_dupsockfd)) { g_fds.p[newfd].extra = - (intptr_t)weaken(_dupsockfd)((struct SockFd *)g_fds.p[oldfd].extra); + (intptr_t)_weaken(_dupsockfd)((struct SockFd *)g_fds.p[oldfd].extra); } else { g_fds.p[newfd].extra = g_fds.p[oldfd].extra; } diff --git a/libc/calls/dup.c b/libc/calls/dup.c index 4db6fb2b5..491acee52 100644 --- a/libc/calls/dup.c +++ b/libc/calls/dup.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/dup2.c b/libc/calls/dup2.c index 3dbae29c2..636ab6be3 100644 --- a/libc/calls/dup2.c +++ b/libc/calls/dup2.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/dup3-sysv.c b/libc/calls/dup3-sysv.c index a336a2688..7ac62b1fe 100644 --- a/libc/calls/dup3-sysv.c +++ b/libc/calls/dup3-sysv.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/dup3.c b/libc/calls/dup3.c index 9adc452f3..1f487f096 100644 --- a/libc/calls/dup3.c +++ b/libc/calls/dup3.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/execve-nt.greg.c b/libc/calls/execve-nt.greg.c index 286438eb2..1d41fbc28 100644 --- a/libc/calls/execve-nt.greg.c +++ b/libc/calls/execve-nt.greg.c @@ -20,9 +20,8 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/ntspawn.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/mem/alloca.h" #include "libc/nt/accounting.h" #include "libc/nt/console.h" diff --git a/libc/calls/execve.c b/libc/calls/execve.c index 99f36810d..4a186b218 100644 --- a/libc/calls/execve.c +++ b/libc/calls/execve.c @@ -16,18 +16,18 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/likely.h" -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/pledge.h" #include "libc/calls/pledge.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" +#include "libc/intrin/likely.h" #include "libc/intrin/promises.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/log/libfatal.internal.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" @@ -75,8 +75,8 @@ int execve(const char *prog, char *const argv[], char *const envp[]) { #endif if (!IsWindows()) { rc = 0; - if (IsLinux() && __execpromises && weaken(sys_pledge_linux)) { - rc = weaken(sys_pledge_linux)(__execpromises, __pledge_mode); + if (IsLinux() && __execpromises && _weaken(sys_pledge_linux)) { + rc = _weaken(sys_pledge_linux)(__execpromises, __pledge_mode); } if (!rc) { rc = sys_execve(prog, argv, envp); diff --git a/libc/calls/faccessat.c b/libc/calls/faccessat.c index 4c71328bd..5b0ff4599 100644 --- a/libc/calls/faccessat.c +++ b/libc/calls/faccessat.c @@ -16,15 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -45,8 +45,8 @@ int faccessat(int dirfd, const char *path, int mode, uint32_t flags) { int e, rc; if (IsAsan() && !__asan_is_valid(path, 1)) { rc = efault(); - } else if (weaken(__zipos_notat) && - weaken(__zipos_notat)(dirfd, path) == -1) { + } else if (_weaken(__zipos_notat) && + _weaken(__zipos_notat)(dirfd, path) == -1) { rc = -1; /* TODO(jart): implement me */ } else if (!IsWindows()) { e = errno; diff --git a/libc/calls/fadvise.c b/libc/calls/fadvise.c index 31425e4f7..acf3f847d 100644 --- a/libc/calls/fadvise.c +++ b/libc/calls/fadvise.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/fchmodat.c b/libc/calls/fchmodat.c index 099bdb602..a9effc2d2 100644 --- a/libc/calls/fchmodat.c +++ b/libc/calls/fchmodat.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -45,7 +45,8 @@ int fchmodat(int dirfd, const char *path, uint32_t mode, int flags) { int rc; if (IsAsan() && !__asan_is_valid(path, 1)) { rc = efault(); - } else if (weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { + } else if (_weaken(__zipos_notat) && + (rc = __zipos_notat(dirfd, path)) == -1) { rc = eopnotsupp(); } else if (!IsWindows()) { rc = sys_fchmodat(dirfd, path, mode, flags); diff --git a/libc/calls/fchown.c b/libc/calls/fchown.c index f447de5fe..8b33937f8 100644 --- a/libc/calls/fchown.c +++ b/libc/calls/fchown.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/sysv/consts/at.h" diff --git a/libc/calls/fchownat.c b/libc/calls/fchownat.c index fff6e785a..26eb892c4 100644 --- a/libc/calls/fchownat.c +++ b/libc/calls/fchownat.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -44,7 +44,8 @@ int fchownat(int dirfd, const char *path, uint32_t uid, uint32_t gid, int rc; if (IsAsan() && !__asan_is_valid(path, 1)) { rc = efault(); - } else if (weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { + } else if (_weaken(__zipos_notat) && + (rc = __zipos_notat(dirfd, path)) == -1) { STRACE("zipos fchownat not supported yet"); } else { rc = sys_fchownat(dirfd, path, uid, gid, flags); diff --git a/libc/calls/fcntl.c b/libc/calls/fcntl.c index b840f8552..7bc3d0a04 100644 --- a/libc/calls/fcntl.c +++ b/libc/calls/fcntl.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -61,7 +61,7 @@ int fcntl(int fd, int cmd, ...) { va_end(va); if (fd >= 0) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = weaken(__zipos_fcntl)(fd, cmd, arg); + rc = _weaken(__zipos_fcntl)(fd, cmd, arg); } else if (!IsWindows()) { rc = sys_fcntl(fd, cmd, arg); } else { diff --git a/libc/calls/fdatasync.c b/libc/calls/fdatasync.c index c2c12dd81..eff546629 100644 --- a/libc/calls/fdatasync.c +++ b/libc/calls/fdatasync.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/fileexists.c b/libc/calls/fileexists.c index 11d8e5b91..cec64cd11 100644 --- a/libc/calls/fileexists.c +++ b/libc/calls/fileexists.c @@ -16,9 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/metastat.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall-sysv.internal.h" @@ -26,6 +24,8 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/nt/files.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" @@ -54,9 +54,9 @@ bool fileexists(const char *path) { if (IsAsan() && !__asan_is_valid(path, 1)) { efault(); res = false; - } else if (weaken(__zipos_open) && - weaken(__zipos_parseuri)(path, &zipname) != -1) { - if (weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { + } else if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { res = true; } else { res = false; diff --git a/libc/calls/flock.c b/libc/calls/flock.c index 2f0afbdb3..460c105bc 100644 --- a/libc/calls/flock.c +++ b/libc/calls/flock.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/fstat-nt.c b/libc/calls/fstat-nt.c index 1fe589451..6bbdd4d4a 100644 --- a/libc/calls/fstat-nt.c +++ b/libc/calls/fstat-nt.c @@ -17,12 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bsr.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nt/enum/fileflagandattributes.h" #include "libc/nt/enum/fileinfobyhandleclass.h" #include "libc/nt/enum/filetype.h" @@ -33,7 +34,6 @@ #include "libc/nt/struct/filecompressioninfo.h" #include "libc/nt/struct/reparsedatabuffer.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/errfuns.h" @@ -61,7 +61,7 @@ static textwindows uint32_t GetSizeOfReparsePoint(int64_t fh) { x = 0xfffd; } } - z += x < 0200 ? 1 : bsrl(tpenc(x)) >> 3; + z += x < 0200 ? 1 : _bsrl(_tpenc(x)) >> 3; } } else { STRACE("%s failed %m", "GetSizeOfReparsePoint"); diff --git a/libc/calls/fstat.c b/libc/calls/fstat.c index b9a11d82b..f5773f2ad 100644 --- a/libc/calls/fstat.c +++ b/libc/calls/fstat.c @@ -18,11 +18,11 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/stat.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -39,7 +39,7 @@ int fstat(int fd, struct stat *st) { int rc; if (__isfdkind(fd, kFdZip)) { - rc = weaken(__zipos_fstat)( + rc = _weaken(__zipos_fstat)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st); } else if (!IsWindows() && !IsMetal()) { rc = sys_fstat(fd, st); diff --git a/libc/calls/fstatat.c b/libc/calls/fstatat.c index 27958a2b0..848fc8c45 100644 --- a/libc/calls/fstatat.c +++ b/libc/calls/fstatat.c @@ -19,13 +19,13 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/stat.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/log.h" #include "libc/mem/alloca.h" @@ -59,10 +59,10 @@ int fstatat(int dirfd, const char *path, struct stat *st, int flags) { if (__isfdkind(dirfd, kFdZip)) { STRACE("zipos dirfd not supported yet"); rc = einval(); - } else if (weaken(__zipos_stat) && - weaken(__zipos_parseuri)(path, &zipname) != -1) { + } else if (_weaken(__zipos_stat) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { if (!__vforked) { - rc = weaken(__zipos_stat)(&zipname, st); + rc = _weaken(__zipos_stat)(&zipname, st); } else { rc = enotsup(); } diff --git a/libc/calls/fstatfs-nt.c b/libc/calls/fstatfs-nt.c index 022c8687e..9cc74e891 100644 --- a/libc/calls/fstatfs-nt.c +++ b/libc/calls/fstatfs-nt.c @@ -22,6 +22,7 @@ #include "libc/calls/struct/statfs.h" #include "libc/calls/struct/statfs.internal.h" #include "libc/calls/syscall_support-nt.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/nt/enum/fsinformationclass.h" @@ -32,7 +33,6 @@ #include "libc/nt/struct/filefsfullsizeinformation.h" #include "libc/nt/struct/iostatusblock.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/sysv/errfuns.h" textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) { @@ -60,7 +60,7 @@ textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) { return eio(); } for (h = j = i = 0; FileSystemNameBuffer[i]; i++) { - w = tpenc(FileSystemNameBuffer[i]); + w = _tpenc(FileSystemNameBuffer[i]); do { if (j + 1 < sizeof(f->f_fstypename)) { h = ((unsigned)(w & 255) + h) * 0x9e3779b1u; diff --git a/libc/calls/fstatfs.c b/libc/calls/fstatfs.c index 76d53dc6c..1e47c174e 100644 --- a/libc/calls/fstatfs.c +++ b/libc/calls/fstatfs.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/statfs-meta.internal.h" #include "libc/calls/struct/statfs.internal.h" #include "libc/dce.h" diff --git a/libc/calls/fsync.c b/libc/calls/fsync.c index 859c858f6..0d89cdd5c 100644 --- a/libc/calls/fsync.c +++ b/libc/calls/fsync.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/ftruncate.c b/libc/calls/ftruncate.c index 109c7b2f6..9c9747f5f 100644 --- a/libc/calls/ftruncate.c +++ b/libc/calls/ftruncate.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getcwd-nt.greg.c b/libc/calls/getcwd-nt.greg.c index 3982ef5cb..a4baadf8d 100644 --- a/libc/calls/getcwd-nt.greg.c +++ b/libc/calls/getcwd-nt.greg.c @@ -17,10 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/syscall_support-nt.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/macros.internal.h" #include "libc/nt/files.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #include "libc/sysv/errfuns.h" @@ -62,7 +62,7 @@ textwindows char *sys_getcwd_nt(char *buf, size_t size) { } w = x; } else { - w = tpenc(x); + w = _tpenc(x); } do { if (j < size) { diff --git a/libc/calls/getcwd.greg.c b/libc/calls/getcwd.greg.c index 49befca91..f9bf03eb2 100644 --- a/libc/calls/getcwd.greg.c +++ b/libc/calls/getcwd.greg.c @@ -17,13 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" @@ -51,10 +51,10 @@ char *getcwd(char *buf, size_t size) { STRACE("getcwd(%p, %'zu) %m", buf, size); return 0; } - } else if (weaken(malloc)) { + } else if (_weaken(malloc)) { assert(!__vforked); if (!size) size = PATH_MAX; - if (!(p = weaken(malloc)(size))) { + if (!(p = _weaken(malloc)(size))) { STRACE("getcwd(%p, %'zu) %m", buf, size); return 0; } @@ -79,12 +79,12 @@ char *getcwd(char *buf, size_t size) { } if (!buf) { if (!r) { - if (weaken(free)) { - weaken(free)(p); + if (_weaken(free)) { + _weaken(free)(p); } } else { - if (weaken(realloc)) { - if ((p = weaken(realloc)(r, strlen(r) + 1))) { + if (_weaken(realloc)) { + if ((p = _weaken(realloc)(r, strlen(r) + 1))) { r = p; } } diff --git a/libc/calls/getdomainname.c b/libc/calls/getdomainname.c index aa2c7e854..54df42ee0 100644 --- a/libc/calls/getdomainname.c +++ b/libc/calls/getdomainname.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/kprintf.h" diff --git a/libc/calls/getegid.c b/libc/calls/getegid.c index 711a359e7..199b0399a 100644 --- a/libc/calls/getegid.c +++ b/libc/calls/getegid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/runtime/runtime.h" diff --git a/libc/calls/geteuid.c b/libc/calls/geteuid.c index 36aa40564..80bec34b9 100644 --- a/libc/calls/geteuid.c +++ b/libc/calls/geteuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getfiledescriptorsize.c b/libc/calls/getfiledescriptorsize.c index 098f6e9eb..47721d27c 100644 --- a/libc/calls/getfiledescriptorsize.c +++ b/libc/calls/getfiledescriptorsize.c @@ -18,12 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/metastat.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/limits.h" #include "libc/nt/enum/fileinfobyhandleclass.h" @@ -52,7 +52,7 @@ ssize_t getfiledescriptorsize(int fd) { struct NtFileStandardInformation info; e = errno; if (__isfdkind(fd, kFdZip)) { - if (weaken(__zipos_fstat)( + if (_weaken(__zipos_fstat)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, &st.cosmo) != -1) { rc = st.cosmo.st_size; diff --git a/libc/calls/gethostname.c b/libc/calls/gethostname.c index ffd5ac6df..0b8e2ecff 100644 --- a/libc/calls/gethostname.c +++ b/libc/calls/gethostname.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/kprintf.h" diff --git a/libc/calls/getitimer.c b/libc/calls/getitimer.c index c2a4612d1..9dd4aa8ee 100644 --- a/libc/calls/getitimer.c +++ b/libc/calls/getitimer.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/itimerval.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getloadavg.c b/libc/calls/getloadavg.c index fcab20a2a..aa52b117d 100644 --- a/libc/calls/getloadavg.c +++ b/libc/calls/getloadavg.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sysinfo.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getpgid.c b/libc/calls/getpgid.c index a072d98c1..73c6ef63a 100644 --- a/libc/calls/getpgid.c +++ b/libc/calls/getpgid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getpgrp.c b/libc/calls/getpgrp.c index d083b42c3..88ae6b2e3 100644 --- a/libc/calls/getpgrp.c +++ b/libc/calls/getpgrp.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getppid.c b/libc/calls/getppid.c index a5a30613f..0d409f0be 100644 --- a/libc/calls/getppid.c +++ b/libc/calls/getppid.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getpriority.c b/libc/calls/getpriority.c index 0a8565ca8..1fcfca741 100644 --- a/libc/calls/getpriority.c +++ b/libc/calls/getpriority.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getresgid.c b/libc/calls/getresgid.c index 36aa25dd8..4f2816a70 100644 --- a/libc/calls/getresgid.c +++ b/libc/calls/getresgid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getresuid.c b/libc/calls/getresuid.c index d67c4c28a..1b9042be6 100644 --- a/libc/calls/getresuid.c +++ b/libc/calls/getresuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getrlimit.c b/libc/calls/getrlimit.c index 6676a05c4..eb3168aaa 100644 --- a/libc/calls/getrlimit.c +++ b/libc/calls/getrlimit.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rlimit.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/calls/getrusage.c b/libc/calls/getrusage.c index c15865e5c..029dcef13 100644 --- a/libc/calls/getrusage.c +++ b/libc/calls/getrusage.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rusage.h" #include "libc/calls/struct/rusage.internal.h" #include "libc/dce.h" diff --git a/libc/calls/getsid.c b/libc/calls/getsid.c index 057aeb54e..d5369a990 100644 --- a/libc/calls/getsid.c +++ b/libc/calls/getsid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/gettimeofday.c b/libc/calls/gettimeofday.c index ab64bf4c5..67492d6b1 100644 --- a/libc/calls/gettimeofday.c +++ b/libc/calls/gettimeofday.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/itimerval.internal.h" #include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.internal.h" diff --git a/libc/calls/getttysize.c b/libc/calls/getttysize.c index 518aee917..e1a5048c2 100644 --- a/libc/calls/getttysize.c +++ b/libc/calls/getttysize.c @@ -16,13 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/calls/termios.h" +#include "libc/calls/ioctl.h" +#include "libc/calls/struct/winsize.h" #include "libc/fmt/conv.h" #include "libc/intrin/safemacros.internal.h" #include "libc/log/internal.h" -#include "libc/log/log.h" -#include "libc/runtime/runtime.h" #include "libc/sysv/consts/termios.h" /** @@ -34,7 +32,7 @@ * @param out stores determined dimensions, only on success * @returns -1 on error or something else on success */ -int getttysize(int fd, struct winsize *out) { +int _getttysize(int fd, struct winsize *out) { if (__nocolor) { out->ws_col = atoi(firstnonnull(getenv("COLUMNS"), "80")); out->ws_row = atoi(firstnonnull(getenv("ROWS"), "40")); diff --git a/libc/calls/getuid.c b/libc/calls/getuid.c index 8de2a2003..a59f8bcd8 100644 --- a/libc/calls/getuid.c +++ b/libc/calls/getuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/macros.internal.h" diff --git a/libc/calls/interrupts-nt.c b/libc/calls/interrupts-nt.c index 749d0a192..90ddfa4cf 100644 --- a/libc/calls/interrupts-nt.c +++ b/libc/calls/interrupts-nt.c @@ -20,12 +20,12 @@ #include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/intrin/lockcmpxchgp.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/thread/tls.h" @@ -33,9 +33,9 @@ textwindows bool _check_interrupts(bool restartable, struct Fd *fd) { bool res; if (__time_critical) return false; if (__threaded && __threaded != gettid()) return false; - if (weaken(_check_sigalrm)) weaken(_check_sigalrm)(); - if (weaken(_check_sigchld)) weaken(_check_sigchld)(); - if (fd && weaken(_check_sigwinch)) weaken(_check_sigwinch)(fd); - res = weaken(__sig_check) && weaken(__sig_check)(restartable); + if (_weaken(_check_sigalrm)) _weaken(_check_sigalrm)(); + if (_weaken(_check_sigchld)) _weaken(_check_sigchld)(); + if (fd && _weaken(_check_sigwinch)) _weaken(_check_sigwinch)(fd); + res = _weaken(__sig_check) && _weaken(__sig_check)(restartable); return res; } diff --git a/libc/calls/ioctl_default.c b/libc/calls/ioctl_default.c index 615f668db..2df9a3f85 100644 --- a/libc/calls/ioctl_default.c +++ b/libc/calls/ioctl_default.c @@ -38,10 +38,10 @@ int ioctl_default(int fd, uint64_t request, ...) { } else if (__isfdopen(fd)) { if (g_fds.p[fd].kind == kFdSocket) { handle = __getfdhandleactual(fd); - if ((rc = weaken(__sys_ioctlsocket_nt)(handle, request, arg)) != -1) { + if ((rc = _weaken(__sys_ioctlsocket_nt)(handle, request, arg)) != -1) { return rc; } else { - return weaken(__winsockerr)(); + return _weaken(__winsockerr)(); } } else { return eopnotsupp(); diff --git a/libc/calls/ioctl_fioclex.c b/libc/calls/ioctl_fioclex.c index 9eca2f40a..09e4bef16 100644 --- a/libc/calls/ioctl_fioclex.c +++ b/libc/calls/ioctl_fioclex.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/ioctl.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/sysv/consts/o.h" diff --git a/libc/calls/ioctl_siocgifconf-nt.c b/libc/calls/ioctl_siocgifconf-nt.c index a0fc20a11..09f5d7280 100644 --- a/libc/calls/ioctl_siocgifconf-nt.c +++ b/libc/calls/ioctl_siocgifconf-nt.c @@ -53,10 +53,10 @@ struct HostAdapterInfoNode { /* Frees all the nodes of the _hostInfo */ static void freeHostInfo(void) { struct HostAdapterInfoNode *next, *node = __hostInfo; - if (weaken(free)) { + if (_weaken(free)) { while (node) { next = node->next; - weaken(free)(node); + _weaken(free)(node); node = next; } } @@ -103,7 +103,7 @@ struct HostAdapterInfoNode *appendHostInfo( struct sockaddr_in *a; int attemptNum; - if (!weaken(calloc) || !(node = weaken(calloc)(1, sizeof(*node)))) { + if (!_weaken(calloc) || !(node = _weaken(calloc)(1, sizeof(*node)))) { errno = ENOMEM; return NULL; } @@ -143,8 +143,8 @@ struct HostAdapterInfoNode *appendHostInfo( if (attemptNum == MAX_NAME_CLASH) { /* Cannot resolve the conflict */ - if (weaken(free)) { - weaken(free)(node); + if (_weaken(free)) { + _weaken(free)(node); } errno = EEXIST; return NULL; @@ -315,8 +315,8 @@ static int readAdapterAddresses(void) { goto err; } - if (!weaken(malloc) || - !(aa = (struct NtIpAdapterAddresses *)weaken(malloc)(size))) { + if (!_weaken(malloc) || + !(aa = (struct NtIpAdapterAddresses *)_weaken(malloc)(size))) { enomem(); goto err; } @@ -336,14 +336,14 @@ static int readAdapterAddresses(void) { goto err; } - if (weaken(free)) { - weaken(free)(aa); + if (_weaken(free)) { + _weaken(free)(aa); } return 0; err: - if (weaken(free)) { - weaken(free)(aa); + if (_weaken(free)) { + _weaken(free)(aa); } freeHostInfo(); return -1; diff --git a/libc/calls/ioctl_siocgifconf.c b/libc/calls/ioctl_siocgifconf.c index 0b6f6bb2a..d227956dc 100644 --- a/libc/calls/ioctl_siocgifconf.c +++ b/libc/calls/ioctl_siocgifconf.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/ioctl.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/bits.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" @@ -63,9 +63,9 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) { uint32_t bufLen, ip; size_t numReq, bufMax; if (IsLinux()) return sys_ioctl(fd, SIOCGIFCONF, ifc); - if (!weaken(malloc)) return enomem(); + if (!_weaken(malloc)) return enomem(); bufMax = 15000; /* conservative guesstimate */ - if (!(b = weaken(malloc)(bufMax))) return enomem(); + if (!(b = _weaken(malloc)(bufMax))) return enomem(); memcpy(ifcBsd, &bufMax, 8); /* ifc_len */ memcpy(ifcBsd + (IsXnu() ? 4 : 8), &b, 8); /* ifc_buf */ if ((rc = sys_ioctl(fd, SIOCGIFCONF, &ifcBsd)) != -1) { @@ -92,7 +92,7 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) { } ifc->ifc_len = (char *)req - ifc->ifc_buf; /* Adjust len */ } - if (weaken(free)) weaken(free)(b); + if (_weaken(free)) _weaken(free)(b); return rc; } diff --git a/libc/calls/ioctl_tcgets.c b/libc/calls/ioctl_tcgets.c index 2a27d4987..07ac72cd7 100644 --- a/libc/calls/ioctl_tcgets.c +++ b/libc/calls/ioctl_tcgets.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/ioctl.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.internal.h" diff --git a/libc/calls/ioctl_tcsets-nt.c b/libc/calls/ioctl_tcsets-nt.c index a9219933f..a0775290b 100644 --- a/libc/calls/ioctl_tcsets-nt.c +++ b/libc/calls/ioctl_tcsets-nt.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/termios.internal.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/ioctl_tcsets.c b/libc/calls/ioctl_tcsets.c index 13fd721d9..ca2886bba 100644 --- a/libc/calls/ioctl_tcsets.c +++ b/libc/calls/ioctl_tcsets.c @@ -18,13 +18,13 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/ioctl.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/nomultics.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" @@ -72,9 +72,9 @@ int ioctl_tcsets(int fd, uint64_t request, ...) { va_start(va, request); tio = va_arg(va, const struct termios *); va_end(va); - if (weaken(__on_ioctl_tcsets)) { + if (_weaken(__on_ioctl_tcsets)) { if (!once) { - weaken(__on_ioctl_tcsets)(); + _weaken(__on_ioctl_tcsets)(); once = true; } } diff --git a/libc/calls/ioctl_tiocgwinsz-nt.c b/libc/calls/ioctl_tiocgwinsz-nt.c index c86d89d1b..6d912a36d 100644 --- a/libc/calls/ioctl_tiocgwinsz-nt.c +++ b/libc/calls/ioctl_tiocgwinsz-nt.c @@ -19,13 +19,12 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/errno.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/log.h" #include "libc/nt/console.h" #include "libc/nt/enum/startf.h" diff --git a/libc/calls/ioctl_tiocgwinsz.c b/libc/calls/ioctl_tiocgwinsz.c index a6c941dce..e8bd6c85d 100644 --- a/libc/calls/ioctl_tiocgwinsz.c +++ b/libc/calls/ioctl_tiocgwinsz.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/ioctl.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.internal.h" #include "libc/calls/syscall-sysv.internal.h" diff --git a/libc/calls/isatty.c b/libc/calls/isatty.c index a11399d6a..7c633db07 100644 --- a/libc/calls/isatty.c +++ b/libc/calls/isatty.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/winsize.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" diff --git a/libc/calls/isdirectory.c b/libc/calls/isdirectory.c index c65a12c66..8d197fb83 100644 --- a/libc/calls/isdirectory.c +++ b/libc/calls/isdirectory.c @@ -16,9 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/metastat.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall-sysv.internal.h" @@ -26,6 +24,8 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/nt/files.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/s.h" @@ -54,9 +54,9 @@ bool isdirectory(const char *path) { if (IsAsan() && !__asan_is_valid(path, 1)) { efault(); res = false; - } else if (weaken(__zipos_open) && - weaken(__zipos_parseuri)(path, &zipname) != -1) { - if (weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { + } else if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { res = S_ISDIR(st.cosmo.st_mode); } else { res = false; diff --git a/libc/calls/isregularfile.c b/libc/calls/isregularfile.c index 5256d0c8f..4c143682f 100644 --- a/libc/calls/isregularfile.c +++ b/libc/calls/isregularfile.c @@ -16,15 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/metastat.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/errfuns.h" @@ -51,9 +51,9 @@ bool isregularfile(const char *path) { if (IsAsan() && !__asan_is_valid(path, 1)) { efault(); res = false; - } else if (weaken(__zipos_open) && - weaken(__zipos_parseuri)(path, &zipname) != -1) { - if (weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { + } else if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { res = !!S_ISREG(st.cosmo.st_mode); } else { res = false; diff --git a/libc/calls/issetugid.c b/libc/calls/issetugid.c index 525ce83d4..f07f998a4 100644 --- a/libc/calls/issetugid.c +++ b/libc/calls/issetugid.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/_getauxval.internal.h" +#include "libc/intrin/_getauxval.internal.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/sysv/consts/auxv.h" diff --git a/libc/calls/issymlink.c b/libc/calls/issymlink.c index caf8f6f88..0a1beef2f 100644 --- a/libc/calls/issymlink.c +++ b/libc/calls/issymlink.c @@ -16,9 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/metastat.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall-sysv.internal.h" @@ -26,6 +24,8 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/nt/files.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/s.h" @@ -54,8 +54,8 @@ bool issymlink(const char *path) { if (IsAsan() && !__asan_is_valid(path, 1)) { efault(); res = false; - } else if (weaken(__zipos_open) && - weaken(__zipos_parseuri)(path, &zipname) != -1) { + } else if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { res = false; } else if (IsMetal()) { res = false; diff --git a/libc/calls/kill.c b/libc/calls/kill.c index 58caee509..fd8f459de 100644 --- a/libc/calls/kill.c +++ b/libc/calls/kill.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/landlock_add_rule.c b/libc/calls/landlock_add_rule.c index 6d21975f6..dc0007a32 100644 --- a/libc/calls/landlock_add_rule.c +++ b/libc/calls/landlock_add_rule.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/landlock.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" int sys_landlock_add_rule(int, enum landlock_rule_type, const void *, uint32_t); diff --git a/libc/calls/landlock_create_ruleset.c b/libc/calls/landlock_create_ruleset.c index d57357ea5..1079f63c6 100644 --- a/libc/calls/landlock_create_ruleset.c +++ b/libc/calls/landlock_create_ruleset.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/landlock.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" int sys_landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t, uint32_t); diff --git a/libc/calls/landlock_restrict_self.c b/libc/calls/landlock_restrict_self.c index 96c2ad3b7..668d1c1de 100644 --- a/libc/calls/landlock_restrict_self.c +++ b/libc/calls/landlock_restrict_self.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/landlock.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" int sys_landlock_restrict_self(int, uint32_t); diff --git a/libc/calls/linkat.c b/libc/calls/linkat.c index 0b52ef31b..5e3d8aa7f 100644 --- a/libc/calls/linkat.c +++ b/libc/calls/linkat.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -43,7 +43,7 @@ int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, if (IsAsan() && (!__asan_is_valid(oldpath, 1) || !__asan_is_valid(newpath, 1))) { rc = efault(); - } else if (weaken(__zipos_notat) && + } else if (_weaken(__zipos_notat) && ((rc = __zipos_notat(olddirfd, oldpath)) == -1 || (rc = __zipos_notat(newdirfd, newpath)) == -1)) { STRACE("zipos fchownat not supported yet"); diff --git a/libc/calls/lseek.c b/libc/calls/lseek.c index 0fb3f92b9..07f4332e5 100644 --- a/libc/calls/lseek.c +++ b/libc/calls/lseek.c @@ -18,11 +18,11 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/zipos/zipos.internal.h" @@ -39,7 +39,7 @@ int64_t lseek(int fd, int64_t offset, unsigned whence) { int64_t rc; if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = weaken(__zipos_lseek)( + rc = _weaken(__zipos_lseek)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, offset, whence); } else if (!IsWindows() && !IsOpenbsd() && !IsNetbsd()) { rc = sys_lseek(fd, offset, whence, 0); diff --git a/libc/calls/madvise.c b/libc/calls/madvise.c index 2610d9968..24d8cbc33 100644 --- a/libc/calls/madvise.c +++ b/libc/calls/madvise.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/memfd_create.c b/libc/calls/memfd_create.c index f83f6b680..6107cf156 100644 --- a/libc/calls/memfd_create.c +++ b/libc/calls/memfd_create.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/mincore.c b/libc/calls/mincore.c index 053fbd4e1..05e774690 100644 --- a/libc/calls/mincore.c +++ b/libc/calls/mincore.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/mkdirat.c b/libc/calls/mkdirat.c index da0a87438..b082ff301 100644 --- a/libc/calls/mkdirat.c +++ b/libc/calls/mkdirat.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -44,7 +44,8 @@ int mkdirat(int dirfd, const char *path, unsigned mode) { int rc; if (IsAsan() && !__asan_is_valid(path, 1)) { rc = efault(); - } else if (weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { + } else if (_weaken(__zipos_notat) && + (rc = __zipos_notat(dirfd, path)) == -1) { STRACE("zipos mkdirat not supported yet"); } else if (!IsWindows()) { rc = sys_mkdirat(dirfd, path, mode); diff --git a/libc/calls/mkfifo.c b/libc/calls/mkfifo.c index fece40a90..24cc0d953 100644 --- a/libc/calls/mkfifo.c +++ b/libc/calls/mkfifo.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/calls/mknod.c b/libc/calls/mknod.c index c677fa0cc..821be141c 100644 --- a/libc/calls/mknod.c +++ b/libc/calls/mknod.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/calls/mkntpath.c b/libc/calls/mkntpath.c index 5b11f0b78..2d3c436c5 100644 --- a/libc/calls/mkntpath.c +++ b/libc/calls/mkntpath.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/ntmagicpaths.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/macros.internal.h" #include "libc/nt/systeminfo.h" diff --git a/libc/calls/mkntpathat.c b/libc/calls/mkntpathat.c index 204db959a..408f6057e 100644 --- a/libc/calls/mkntpathat.c +++ b/libc/calls/mkntpathat.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/macros.internal.h" #include "libc/nt/files.h" diff --git a/libc/calls/mremap-sysv.greg.c b/libc/calls/mremap-sysv.greg.c index ef22790a3..1eff68e55 100644 --- a/libc/calls/mremap-sysv.greg.c +++ b/libc/calls/mremap-sysv.greg.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asmflag.h" diff --git a/libc/calls/munmap-sysv.c b/libc/calls/munmap-sysv.c index bf88b2f09..651e715d5 100644 --- a/libc/calls/munmap-sysv.c +++ b/libc/calls/munmap-sysv.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/runtime/directmap.internal.h" diff --git a/libc/calls/nanosleep-nt.c b/libc/calls/nanosleep-nt.c index fe260dd2b..070f907dd 100644 --- a/libc/calls/nanosleep-nt.c +++ b/libc/calls/nanosleep-nt.c @@ -20,7 +20,7 @@ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/limits.h" #include "libc/macros.internal.h" diff --git a/libc/calls/nanosleep.c b/libc/calls/nanosleep.c index 9c9f4b949..2194efafd 100644 --- a/libc/calls/nanosleep.c +++ b/libc/calls/nanosleep.c @@ -19,7 +19,7 @@ #include "libc/calls/asan.internal.h" #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/now.c b/libc/calls/now.c index 4a098aae3..481a5dd44 100644 --- a/libc/calls/now.c +++ b/libc/calls/now.c @@ -23,7 +23,7 @@ #include "libc/calls/calls.h" #include "libc/calls/clock_gettime.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/macros.internal.h" diff --git a/libc/calls/ntaccesscheck.c b/libc/calls/ntaccesscheck.c index 05afa9806..6f2018d05 100644 --- a/libc/calls/ntaccesscheck.c +++ b/libc/calls/ntaccesscheck.c @@ -17,11 +17,11 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/mem/mem.h" #include "libc/nt/enum/accessmask.h" @@ -109,7 +109,7 @@ TryAgain: } else { e = GetLastError(); if (!IsTiny() && e == kNtErrorInsufficientBuffer) { - if (!freeme && weaken(malloc) && (freeme = weaken(malloc)(secsize))) { + if (!freeme && _weaken(malloc) && (freeme = _weaken(malloc)(secsize))) { s = freeme; goto TryAgain; } else { @@ -122,7 +122,7 @@ TryAgain: rc = -1; } } - if (freeme && weaken(free)) weaken(free)(freeme); + if (freeme && _weaken(free)) _weaken(free)(freeme); if (hImpersonatedToken != -1) CloseHandle(hImpersonatedToken); if (hToken != -1) CloseHandle(hToken); return rc; diff --git a/libc/calls/ntspawn.c b/libc/calls/ntspawn.c index 043e1b403..4590dfd1b 100644 --- a/libc/calls/ntspawn.c +++ b/libc/calls/ntspawn.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/pushpop.h" #include "libc/calls/ntspawn.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/filemapflags.h" diff --git a/libc/calls/oldbench.c b/libc/calls/oldbench.c index 34eaad6a5..847938552 100644 --- a/libc/calls/oldbench.c +++ b/libc/calls/oldbench.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/dce.h" #include "libc/intrin/bits.h" diff --git a/libc/calls/onntconsoleevent.c b/libc/calls/onntconsoleevent.c index bca10ac4a..7d013877a 100644 --- a/libc/calls/onntconsoleevent.c +++ b/libc/calls/onntconsoleevent.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/nexgen32e/nt2sysv.h" #include "libc/nt/enum/ctrlevent.h" #include "libc/sysv/consts/sicode.h" diff --git a/libc/calls/openat-metal.c b/libc/calls/openat-metal.c index 9fed85fad..0decc6c94 100644 --- a/libc/calls/openat-metal.c +++ b/libc/calls/openat-metal.c @@ -28,9 +28,9 @@ int sys_openat_metal(int dirfd, const char *file, int flags, unsigned mode) { int fd; struct MetalFile *state; if (strcmp(file, "ape.com")) return enoent(); - if (!weaken(calloc)) return enomem(); + if (!_weaken(calloc)) return enomem(); if ((fd = __reservefd(-1)) == -1) return -1; - state = weaken(calloc)(1, sizeof(struct MetalFile)); + state = _weaken(calloc)(1, sizeof(struct MetalFile)); state->base = (char *)_base; state->size = _end - _base; g_fds.p[fd].kind = kFdFile; diff --git a/libc/calls/openat.c b/libc/calls/openat.c index 8b6c6db25..aef4d2b02 100644 --- a/libc/calls/openat.c +++ b/libc/calls/openat.c @@ -19,12 +19,12 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/log.h" #include "libc/str/str.h" @@ -58,10 +58,10 @@ int openat(int dirfd, const char *file, int flags, ...) { va_end(va); if (file && (!IsAsan() || __asan_is_valid(file, 1))) { if (!__isfdkind(dirfd, kFdZip)) { - if (weaken(__zipos_open) && - weaken(__zipos_parseuri)(file, &zipname) != -1) { + if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(file, &zipname) != -1) { if (!__vforked && dirfd == AT_FDCWD) { - rc = weaken(__zipos_open)(&zipname, flags, mode); + rc = _weaken(__zipos_open)(&zipname, flags, mode); } else { rc = eopnotsupp(); /* TODO */ } diff --git a/libc/calls/openbsd.internal.h b/libc/calls/openbsd.internal.h index b158ac9ff..37b42cfb6 100644 --- a/libc/calls/openbsd.internal.h +++ b/libc/calls/openbsd.internal.h @@ -2,9 +2,6 @@ #define COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § system calls » openbsd ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ typedef unsigned char u_char; diff --git a/libc/calls/pause-nt.c b/libc/calls/pause-nt.c index 24963db15..072f8f550 100644 --- a/libc/calls/pause-nt.c +++ b/libc/calls/pause-nt.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/errors.h" #include "libc/nt/synchronization.h" diff --git a/libc/calls/pause.c b/libc/calls/pause.c index 7815d070d..4c3466654 100644 --- a/libc/calls/pause.c +++ b/libc/calls/pause.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/sock/internal.h" diff --git a/libc/calls/pipe.c b/libc/calls/pipe.c index 94f65eed1..22e65853b 100644 --- a/libc/calls/pipe.c +++ b/libc/calls/pipe.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/pipe2.c b/libc/calls/pipe2.c index 738260ae4..133e77385 100644 --- a/libc/calls/pipe2.c +++ b/libc/calls/pipe2.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/pivot_root.c b/libc/calls/pivot_root.c index 7c81a18e4..b494bc211 100644 --- a/libc/calls/pivot_root.c +++ b/libc/calls/pivot_root.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/pledge-linux.c b/libc/calls/pledge-linux.c index c65dddb7a..17d0fef8f 100644 --- a/libc/calls/pledge-linux.c +++ b/libc/calls/pledge-linux.c @@ -23,10 +23,10 @@ #include "libc/calls/struct/seccomp.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/syscall_support-sysv.internal.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/likely.h" #include "libc/intrin/promises.internal.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/sysv/consts/audit.h" @@ -838,7 +838,7 @@ static privileged char *FixCpy(char p[17], uint64_t x, int k) { } static privileged char *HexCpy(char p[17], uint64_t x) { - return FixCpy(p, x, ROUNDUP(x ? bsrl(x) + 1 : 1, 4)); + return FixCpy(p, x, ROUNDUP(x ? _bsrl(x) + 1 : 1, 4)); } static privileged int GetPid(void) { diff --git a/libc/calls/pledge.c b/libc/calls/pledge.c index 0e3dfe33a..bc14afce5 100644 --- a/libc/calls/pledge.c +++ b/libc/calls/pledge.c @@ -19,7 +19,7 @@ #include "libc/calls/calls.h" #include "libc/calls/pledge.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/calls/poll-nt.c b/libc/calls/poll-nt.c index 17caa46af..121f0c7c6 100644 --- a/libc/calls/poll-nt.c +++ b/libc/calls/poll-nt.c @@ -20,11 +20,10 @@ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/errno.h" #include "libc/intrin/bits.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/nt/enum/filetype.h" diff --git a/libc/calls/poll.c b/libc/calls/poll.c index d9575006d..52799046b 100644 --- a/libc/calls/poll.c +++ b/libc/calls/poll.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/calls/ppoll.c b/libc/calls/ppoll.c index 096510de2..8065c364c 100644 --- a/libc/calls/ppoll.c +++ b/libc/calls/ppoll.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/dce.h" diff --git a/libc/calls/prctl.c b/libc/calls/prctl.c index 1d9c9caab..1863f1c00 100644 --- a/libc/calls/prctl.c +++ b/libc/calls/prctl.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/pread.c b/libc/calls/pread.c index f004744f1..951f2f05a 100644 --- a/libc/calls/pread.c +++ b/libc/calls/pread.c @@ -19,12 +19,12 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/runtime/runtime.h" @@ -50,9 +50,9 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) { if (IsAsan() && !__asan_is_valid(buf, size)) { rc = efault(); } else if (__isfdkind(fd, kFdZip)) { - rc = - weaken(__zipos_read)((struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, - (struct iovec[]){{buf, size}}, 1, offset); + rc = _weaken(__zipos_read)( + (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, + (struct iovec[]){{buf, size}}, 1, offset); } else if (!IsWindows()) { rc = sys_pread(fd, buf, size, offset, offset); } else if (__isfdkind(fd, kFdFile)) { diff --git a/libc/calls/preadv.c b/libc/calls/preadv.c index 349c00988..2681215c4 100644 --- a/libc/calls/preadv.c +++ b/libc/calls/preadv.c @@ -20,7 +20,6 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/sigset.h" @@ -33,6 +32,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/likely.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/iov.h" @@ -60,7 +60,7 @@ static ssize_t Preadv(int fd, struct iovec *iov, int iovlen, int64_t off) { } if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - return weaken(__zipos_read)( + return _weaken(__zipos_read)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, iov, iovlen, off); } diff --git a/libc/calls/ptrace.c b/libc/calls/ptrace.c index c79191c8b..839c86ac2 100644 --- a/libc/calls/ptrace.c +++ b/libc/calls/ptrace.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/pwrite.c b/libc/calls/pwrite.c index dd275ba1b..779ab96a4 100644 --- a/libc/calls/pwrite.c +++ b/libc/calls/pwrite.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" diff --git a/libc/calls/pwritev.c b/libc/calls/pwritev.c index eda149625..8e75c0b61 100644 --- a/libc/calls/pwritev.c +++ b/libc/calls/pwritev.c @@ -19,7 +19,6 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/sigset.internal.h" @@ -30,6 +29,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/likely.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/iov.h" @@ -58,7 +58,7 @@ static ssize_t Pwritev(int fd, const struct iovec *iov, int iovlen, } if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - return weaken(__zipos_write)( + return _weaken(__zipos_write)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, iov, iovlen, off); } diff --git a/libc/calls/raise.c b/libc/calls/raise.c index b94c49e55..1711e3a98 100644 --- a/libc/calls/raise.c +++ b/libc/calls/raise.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/thread/tls.h" diff --git a/libc/calls/read-nt.c b/libc/calls/read-nt.c index 9f529b94a..6afd415c3 100644 --- a/libc/calls/read-nt.c +++ b/libc/calls/read-nt.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" diff --git a/libc/calls/read.c b/libc/calls/read.c index 2108b4d3f..b01f4e166 100644 --- a/libc/calls/read.c +++ b/libc/calls/read.c @@ -18,12 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sock/internal.h" #include "libc/sock/sock.h" @@ -48,7 +48,7 @@ ssize_t read(int fd, void *buf, size_t size) { if (IsAsan() && !__asan_is_valid(buf, size)) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = weaken(__zipos_read)( + rc = _weaken(__zipos_read)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, &(struct iovec){buf, size}, 1, -1); } else if (!IsWindows() && !IsMetal()) { diff --git a/libc/calls/readlinkat-nt.c b/libc/calls/readlinkat-nt.c index 3e75adefc..204567b30 100644 --- a/libc/calls/readlinkat-nt.c +++ b/libc/calls/readlinkat-nt.c @@ -16,8 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/mem/alloca.h" #include "libc/nt/createfile.h" #include "libc/nt/enum/creationdisposition.h" @@ -28,7 +29,6 @@ #include "libc/nt/runtime.h" #include "libc/nt/struct/reparsedatabuffer.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #include "libc/sysv/errfuns.h" @@ -78,7 +78,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf, } w = x; } else { - w = tpenc(x); + w = _tpenc(x); } do { if (j < bufsiz) { diff --git a/libc/calls/readlinkat.c b/libc/calls/readlinkat.c index a26071695..885e196ac 100644 --- a/libc/calls/readlinkat.c +++ b/libc/calls/readlinkat.c @@ -17,13 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/weaken.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/runtime/runtime.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -48,7 +48,7 @@ ssize_t readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) { ssize_t bytes; if ((IsAsan() && !__asan_is_valid(buf, bufsiz)) || (bufsiz && !buf)) { bytes = efault(); - } else if (weaken(__zipos_notat) && + } else if (_weaken(__zipos_notat) && (bytes = __zipos_notat(dirfd, path)) == -1) { STRACE("TODO: zipos support for readlinkat"); } else if (!IsWindows()) { diff --git a/libc/calls/readv-nt.c b/libc/calls/readv-nt.c index a5e627d4b..aa98b04a3 100644 --- a/libc/calls/readv-nt.c +++ b/libc/calls/readv-nt.c @@ -29,7 +29,7 @@ textwindows ssize_t sys_readv_nt(struct Fd *fd, const struct iovec *iov, case kFdConsole: return sys_read_nt(fd, iov, iovlen, -1); case kFdSocket: - return weaken(sys_recv_nt)(fd, iov, iovlen, 0); + return _weaken(sys_recv_nt)(fd, iov, iovlen, 0); default: return ebadf(); } diff --git a/libc/calls/readv.c b/libc/calls/readv.c index f344ac6bf..c0a1f5f21 100644 --- a/libc/calls/readv.c +++ b/libc/calls/readv.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" @@ -27,6 +26,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/likely.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sock/internal.h" #include "libc/sysv/errfuns.h" @@ -52,7 +52,7 @@ ssize_t readv(int fd, const struct iovec *iov, int iovlen) { if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = weaken(__zipos_read)( + rc = _weaken(__zipos_read)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, iov, iovlen, -1); } else if (!IsWindows() && !IsMetal()) { if (iovlen == 1) { diff --git a/libc/calls/realpath.c b/libc/calls/realpath.c index 626ccac06..510af0496 100644 --- a/libc/calls/realpath.c +++ b/libc/calls/realpath.c @@ -26,12 +26,12 @@ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "libc/calls/calls.h" +#include "libc/errno.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" -#include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" -#include "libc/errno.h" #include "libc/limits.h" #include "libc/log/backtrace.internal.h" #include "libc/mem/mem.h" @@ -60,7 +60,7 @@ static size_t GetSlashLen(const char *s) static char *ResolvePath(char *d, const char *s, size_t n) { - if (d || (weaken(malloc) && (d = weaken(malloc)(n+1)))) { + if (d || (_weaken(malloc) && (d = _weaken(malloc)(n+1)))) { return memmove(d, s, n+1); } else { enomem(); diff --git a/libc/calls/renameat.c b/libc/calls/renameat.c index 5253d42b0..4db6cf37f 100644 --- a/libc/calls/renameat.c +++ b/libc/calls/renameat.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -49,7 +49,7 @@ int renameat(int olddirfd, const char *oldpath, int newdirfd, if (IsAsan() && (!__asan_is_valid(oldpath, 1) || !__asan_is_valid(newpath, 1))) { rc = efault(); - } else if (weaken(__zipos_notat) && + } else if (_weaken(__zipos_notat) && ((rc = __zipos_notat(olddirfd, oldpath)) == -1 || (rc = __zipos_notat(newdirfd, newpath)) == -1)) { STRACE("zipos renameat not supported yet"); diff --git a/libc/calls/reservefd.c b/libc/calls/reservefd.c index 5e74fca70..efb698146 100644 --- a/libc/calls/reservefd.c +++ b/libc/calls/reservefd.c @@ -18,14 +18,13 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/extend.internal.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigset.h" #include "libc/dce.h" #include "libc/intrin/cmpxchg.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/extend.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/directmap.internal.h" diff --git a/libc/calls/sched_get_priority_max.c b/libc/calls/sched_get_priority_max.c index e76043931..aaa1df6c8 100644 --- a/libc/calls/sched_get_priority_max.c +++ b/libc/calls/sched_get_priority_max.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/sched-sysv.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/sched.h" diff --git a/libc/calls/sched_get_priority_min.c b/libc/calls/sched_get_priority_min.c index 7592ffae5..f545f43a1 100644 --- a/libc/calls/sched_get_priority_min.c +++ b/libc/calls/sched_get_priority_min.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/sched-sysv.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/sched.h" diff --git a/libc/calls/sched_getaffinity.c b/libc/calls/sched_getaffinity.c index e605d145a..9a2d3cd75 100644 --- a/libc/calls/sched_getaffinity.c +++ b/libc/calls/sched_getaffinity.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sched-sysv.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/cpuset.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" diff --git a/libc/calls/sched_getscheduler.c b/libc/calls/sched_getscheduler.c index d53a22808..44d408604 100644 --- a/libc/calls/sched_getscheduler.c +++ b/libc/calls/sched_getscheduler.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sched-sysv.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sched_param.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/sched_rr_get_interval.c b/libc/calls/sched_rr_get_interval.c index 6ac35aa6a..fce06a0b6 100644 --- a/libc/calls/sched_rr_get_interval.c +++ b/libc/calls/sched_rr_get_interval.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/sched_setaffinity.c b/libc/calls/sched_setaffinity.c index d57d9f813..a45b8b3a0 100644 --- a/libc/calls/sched_setaffinity.c +++ b/libc/calls/sched_setaffinity.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/sched-sysv.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/cpuset.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" diff --git a/libc/calls/sched_setscheduler.c b/libc/calls/sched_setscheduler.c index e5fb93996..06fd7b43a 100644 --- a/libc/calls/sched_setscheduler.c +++ b/libc/calls/sched_setscheduler.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sched-sysv.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.internal.h" #include "libc/dce.h" diff --git a/libc/calls/seccomp.c b/libc/calls/seccomp.c index 60381861a..19601e5c2 100644 --- a/libc/calls/seccomp.c +++ b/libc/calls/seccomp.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/seccomp.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/calls/sedebug.c b/libc/calls/sedebug.c index c3988b70b..3b10616f6 100644 --- a/libc/calls/sedebug.c +++ b/libc/calls/sedebug.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/securityimpersonationlevel.h" #include "libc/nt/errors.h" diff --git a/libc/calls/setegid.c b/libc/calls/setegid.c index 2269cbd61..6570734b0 100644 --- a/libc/calls/setegid.c +++ b/libc/calls/setegid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" /** * Sets effective group ID. diff --git a/libc/calls/seteuid.c b/libc/calls/seteuid.c index 4ff5abc5b..e2f12ef7a 100644 --- a/libc/calls/seteuid.c +++ b/libc/calls/seteuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" /** * Sets effective user ID. diff --git a/libc/calls/setfsgid.c b/libc/calls/setfsgid.c index 526683d47..c6558ebae 100644 --- a/libc/calls/setfsgid.c +++ b/libc/calls/setfsgid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/setfsuid.c b/libc/calls/setfsuid.c index 22895680e..c3e7a3703 100644 --- a/libc/calls/setfsuid.c +++ b/libc/calls/setfsuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/setgid.c b/libc/calls/setgid.c index 07980d230..37cccc8fd 100644 --- a/libc/calls/setgid.c +++ b/libc/calls/setgid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/setitimer-nt.c b/libc/calls/setitimer-nt.c index eab41d87b..81df0c05c 100644 --- a/libc/calls/setitimer-nt.c +++ b/libc/calls/setitimer-nt.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/siginfo.h" #include "libc/dce.h" diff --git a/libc/calls/setitimer.c b/libc/calls/setitimer.c index 4e5e3dedb..d7538c2f0 100644 --- a/libc/calls/setitimer.c +++ b/libc/calls/setitimer.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/itimerval.internal.h" #include "libc/dce.h" @@ -30,7 +30,7 @@ * Raise SIGALRM every 1.5s: * * CHECK_NE(-1, sigaction(SIGALRM, - * &(struct sigaction){.sa_sigaction = missingno}, + * &(struct sigaction){.sa_sigaction = _missingno}, * NULL)); * CHECK_NE(-1, setitimer(ITIMER_REAL, * &(const struct itimerval){{1, 500000}, @@ -40,7 +40,7 @@ * Set single-shot 50ms timer callback to interrupt laggy connect(): * * CHECK_NE(-1, sigaction(SIGALRM, - * &(struct sigaction){.sa_sigaction = missingno, + * &(struct sigaction){.sa_sigaction = _missingno, * .sa_flags = SA_RESETHAND}, * NULL)); * CHECK_NE(-1, setitimer(ITIMER_REAL, diff --git a/libc/calls/setpgid.c b/libc/calls/setpgid.c index 24f6591fd..3f60fa315 100644 --- a/libc/calls/setpgid.c +++ b/libc/calls/setpgid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" diff --git a/libc/calls/setregid.c b/libc/calls/setregid.c index 0134b45f6..3146d0e44 100644 --- a/libc/calls/setregid.c +++ b/libc/calls/setregid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/setresgid.c b/libc/calls/setresgid.c index 04601eccd..3fb5e024a 100644 --- a/libc/calls/setresgid.c +++ b/libc/calls/setresgid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/setresuid.c b/libc/calls/setresuid.c index 8e05da8cf..35593b6ab 100644 --- a/libc/calls/setresuid.c +++ b/libc/calls/setresuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/setreuid.c b/libc/calls/setreuid.c index 9e9e4f14c..c2c44e1d0 100644 --- a/libc/calls/setreuid.c +++ b/libc/calls/setreuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/setrlimit.c b/libc/calls/setrlimit.c index 853dbf250..0039ad90c 100644 --- a/libc/calls/setrlimit.c +++ b/libc/calls/setrlimit.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rlimit.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/calls/setsid.c b/libc/calls/setsid.c index c63b255cf..a1e2700c6 100644 --- a/libc/calls/setsid.c +++ b/libc/calls/setsid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/setuid.c b/libc/calls/setuid.c index 4921d4169..cf10ba64b 100644 --- a/libc/calls/setuid.c +++ b/libc/calls/setuid.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/sig2.c b/libc/calls/sig2.c index 9d4c0bd19..680989e46 100644 --- a/libc/calls/sig2.c +++ b/libc/calls/sig2.c @@ -19,11 +19,11 @@ #include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/siginfo.h" #include "libc/intrin/cmpxchg.h" #include "libc/intrin/lockcmpxchg.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/libfatal.internal.h" #include "libc/macros.internal.h" #include "libc/runtime/internal.h" @@ -170,8 +170,7 @@ bool __sig_handle(bool restartable, int sig, int si_code, ucontext_t *ctx) { case (intptr_t)SIG_DFL: if (__sig_isfatal(sig)) { STRACE("terminating on %G", sig); - __restorewintty(); - _Exit(128 + sig); + _Exitr(128 + sig); } // fallthrough case (intptr_t)SIG_IGN: diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index b760356db..650a267f3 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -21,7 +21,6 @@ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigaction-freebsd.internal.h" #include "libc/calls/struct/sigaction-linux.internal.h" #include "libc/calls/struct/sigaction-netbsd.h" @@ -37,7 +36,7 @@ #include "libc/intrin/asan.internal.h" #include "libc/intrin/bits.h" #include "libc/intrin/describeflags.internal.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/limits.h" #include "libc/log/backtrace.internal.h" #include "libc/log/log.h" diff --git a/libc/calls/sigaltstack.c b/libc/calls/sigaltstack.c index bc990c3e5..6902eac58 100644 --- a/libc/calls/sigaltstack.c +++ b/libc/calls/sigaltstack.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/metasigaltstack.h" #include "libc/calls/struct/sigaltstack.h" #include "libc/calls/struct/sigaltstack.internal.h" diff --git a/libc/calls/sigchld-nt.c b/libc/calls/sigchld-nt.c index bcdadafec..476c10843 100644 --- a/libc/calls/sigchld-nt.c +++ b/libc/calls/sigchld-nt.c @@ -21,7 +21,7 @@ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/siginfo.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" diff --git a/libc/calls/sigpending.c b/libc/calls/sigpending.c index c25a671e8..18512a794 100644 --- a/libc/calls/sigpending.c +++ b/libc/calls/sigpending.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" diff --git a/libc/calls/sigprocmask.c b/libc/calls/sigprocmask.c index 699383779..d51fc9e4f 100644 --- a/libc/calls/sigprocmask.c +++ b/libc/calls/sigprocmask.c @@ -19,14 +19,13 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" #include "libc/fmt/itoa.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/log.h" #include "libc/str/str.h" #include "libc/sysv/consts/sig.h" diff --git a/libc/calls/sigsuspend.c b/libc/calls/sigsuspend.c index 912cf37e4..eeae47cc0 100644 --- a/libc/calls/sigsuspend.c +++ b/libc/calls/sigsuspend.c @@ -19,13 +19,12 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/backtrace.internal.h" #include "libc/nt/errors.h" #include "libc/nt/synchronization.h" diff --git a/libc/calls/sigwinch-nt.c b/libc/calls/sigwinch-nt.c index 0e97b8268..66cb9eb82 100644 --- a/libc/calls/sigwinch-nt.c +++ b/libc/calls/sigwinch-nt.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/winsize.h" diff --git a/libc/calls/statfs.c b/libc/calls/statfs.c index 294040b56..02dad040e 100644 --- a/libc/calls/statfs.c +++ b/libc/calls/statfs.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/statfs-meta.internal.h" #include "libc/calls/struct/statfs.internal.h" #include "libc/calls/syscall_support-nt.internal.h" diff --git a/libc/calls/struct/winsize.h b/libc/calls/struct/winsize.h index 328b25a63..cb3fd652e 100644 --- a/libc/calls/struct/winsize.h +++ b/libc/calls/struct/winsize.h @@ -10,6 +10,8 @@ struct winsize { uint16_t ws_ypixel; }; +int _getttysize(int, struct winsize *); + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_ */ diff --git a/libc/calls/symlinkat.c b/libc/calls/symlinkat.c index cbe3b9af7..c7566ee5f 100644 --- a/libc/calls/symlinkat.c +++ b/libc/calls/symlinkat.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/sync.c b/libc/calls/sync.c index 9586a1b43..95510b487 100644 --- a/libc/calls/sync.c +++ b/libc/calls/sync.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/sys_ptrace.c b/libc/calls/sys_ptrace.c index 8d8ca1be3..48b07ab96 100644 --- a/libc/calls/sys_ptrace.c +++ b/libc/calls/sys_ptrace.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index 02ebbcd30..9cf4b2bd1 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sysinfo.h" #include "libc/calls/struct/sysinfo.internal.h" #include "libc/calls/struct/timespec.h" diff --git a/libc/calls/tgkill.c b/libc/calls/tgkill.c index 214be57e8..ee8abc337 100644 --- a/libc/calls/tgkill.c +++ b/libc/calls/tgkill.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/tkill.c b/libc/calls/tkill.c index 845f2b0ad..291988bc2 100644 --- a/libc/calls/tkill.c +++ b/libc/calls/tkill.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" diff --git a/libc/calls/truncate.c b/libc/calls/truncate.c index 7e0d82ce9..a1d69bb81 100644 --- a/libc/calls/truncate.c +++ b/libc/calls/truncate.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/ttyname_r.c b/libc/calls/ttyname_r.c index 278119a14..88a72dad1 100644 --- a/libc/calls/ttyname_r.c +++ b/libc/calls/ttyname_r.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/umask.c b/libc/calls/umask.c index b1b932ecd..11bbca624 100644 --- a/libc/calls/umask.c +++ b/libc/calls/umask.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/calls/uname.c b/libc/calls/uname.c index 64de99224..fc105eaa8 100644 --- a/libc/calls/uname.c +++ b/libc/calls/uname.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/utsname-linux.internal.h" #include "libc/calls/struct/utsname.h" #include "libc/calls/syscall-sysv.internal.h" @@ -27,7 +26,7 @@ #include "libc/errno.h" #include "libc/fmt/itoa.h" #include "libc/intrin/asan.internal.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/nt/enum/computernameformat.h" diff --git a/libc/calls/unlinkat.c b/libc/calls/unlinkat.c index af0a26fd8..3714cce4b 100644 --- a/libc/calls/unlinkat.c +++ b/libc/calls/unlinkat.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" @@ -42,7 +42,8 @@ int unlinkat(int dirfd, const char *path, int flags) { int rc; if (IsAsan() && !__asan_is_valid(path, 1)) { rc = efault(); - } else if (weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { + } else if (_weaken(__zipos_notat) && + (rc = __zipos_notat(dirfd, path)) == -1) { STRACE("zipos unlinkat not supported yet"); } else if (!IsWindows()) { rc = sys_unlinkat(dirfd, path, flags); diff --git a/libc/calls/unmount.c b/libc/calls/unmount.c index ca4278f62..ef86626b9 100644 --- a/libc/calls/unmount.c +++ b/libc/calls/unmount.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/mount.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" /** diff --git a/libc/calls/unsetenv.c b/libc/calls/unsetenv.c index 4d2ebfa84..b70bb87a5 100644 --- a/libc/calls/unsetenv.c +++ b/libc/calls/unsetenv.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/dce.h" +#include "libc/intrin/weaken.h" #include "libc/mem/internal.h" #include "libc/runtime/runtime.h" @@ -35,8 +35,8 @@ int unsetenv(const char *s) { for (j = 0;; ++j) { if (!s[j]) { if (p[i][j] == '=') { - if (weaken(__freeenv)) { - weaken(__freeenv)(p[i]); + if (_weaken(__freeenv)) { + _weaken(__freeenv)(p[i]); } k = i + 1; do { diff --git a/libc/calls/unveil.c b/libc/calls/unveil.c index b439553b5..7162077cb 100644 --- a/libc/calls/unveil.c +++ b/libc/calls/unveil.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/landlock.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/bpf.h" #include "libc/calls/struct/filter.h" #include "libc/calls/struct/seccomp.h" diff --git a/libc/calls/utimensat-sysv.c b/libc/calls/utimensat-sysv.c index 4fb0b7753..65f5950e7 100644 --- a/libc/calls/utimensat-sysv.c +++ b/libc/calls/utimensat-sysv.c @@ -21,7 +21,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" -#include "libc/intrin/weaken.h" #include "libc/sysv/consts/at.h" #include "libc/time/time.h" #include "libc/zipos/zipos.internal.h" diff --git a/libc/calls/utimensat.c b/libc/calls/utimensat.c index 5db4e7adc..58df289f6 100644 --- a/libc/calls/utimensat.c +++ b/libc/calls/utimensat.c @@ -19,11 +19,11 @@ #include "libc/calls/asan.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/errfuns.h" @@ -63,7 +63,7 @@ int utimensat(int dirfd, const char *path, const struct timespec ts[2], rc = einval(); // unsupported flag } else if (!path && flags) { rc = einval(); // futimens() doesn't take flags - } else if ((path || __isfdkind(dirfd, kFdZip)) && weaken(__zipos_notat) && + } else if ((path || __isfdkind(dirfd, kFdZip)) && _weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { STRACE("zipos utimensat not supported yet"); } else if (!IsWindows()) { diff --git a/libc/calls/vdsofunc.greg.c b/libc/calls/vdsofunc.greg.c index 9a988e138..0924b3971 100644 --- a/libc/calls/vdsofunc.greg.c +++ b/libc/calls/vdsofunc.greg.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/elf/scalar.h" #include "libc/elf/struct/ehdr.h" #include "libc/elf/struct/phdr.h" diff --git a/libc/calls/wait4-nt.c b/libc/calls/wait4-nt.c index 60af0232e..07282ce3c 100644 --- a/libc/calls/wait4-nt.c +++ b/libc/calls/wait4-nt.c @@ -21,7 +21,7 @@ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rusage.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/fmt/conv.h" diff --git a/libc/calls/wait4.c b/libc/calls/wait4.c index 6d25d60e7..b8b9672eb 100644 --- a/libc/calls/wait4.c +++ b/libc/calls/wait4.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rusage.internal.h" #include "libc/calls/wait4.h" #include "libc/dce.h" diff --git a/libc/calls/wincrash.c b/libc/calls/wincrash.c index c1a444132..b4a467975 100644 --- a/libc/calls/wincrash.c +++ b/libc/calls/wincrash.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/ucontext.internal.h" #include "libc/calls/ucontext.h" #include "libc/nt/enum/exceptionhandleractions.h" diff --git a/libc/calls/write-nt.c b/libc/calls/write-nt.c index dcbcdd886..77f825d29 100644 --- a/libc/calls/write-nt.c +++ b/libc/calls/write-nt.c @@ -18,12 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/wincrash.internal.h" #include "libc/errno.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/nt/errors.h" #include "libc/nt/runtime.h" @@ -48,13 +48,12 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size, // return edquot(); /* handled by consts.sh */ case kNtErrorBrokenPipe: // broken pipe case kNtErrorNoData: // closing named pipe - if (weaken(__sig_raise)) { - weaken(__sig_raise)(SIGPIPE, SI_KERNEL); + if (_weaken(__sig_raise)) { + _weaken(__sig_raise)(SIGPIPE, SI_KERNEL); return epipe(); } else { STRACE("broken pipe"); - __restorewintty(); - _Exit(128 + EPIPE); + _Exitr(128 + EPIPE); } case kNtErrorAccessDenied: // write doesn't return EACCESS return ebadf(); // diff --git a/libc/calls/write.c b/libc/calls/write.c index 2fa3ebd5d..900183ed0 100644 --- a/libc/calls/write.c +++ b/libc/calls/write.c @@ -17,12 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sock/sock.h" #include "libc/sysv/errfuns.h" @@ -46,7 +46,7 @@ ssize_t write(int fd, const void *buf, size_t size) { if (IsAsan() && !__asan_is_valid(buf, size)) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = weaken(__zipos_write)( + rc = _weaken(__zipos_write)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, &(struct iovec){buf, size}, 1, -1); } else if (!IsWindows() && !IsMetal()) { diff --git a/libc/calls/writev-metal.c b/libc/calls/writev-metal.c index 7bc473d75..9b2b6a509 100644 --- a/libc/calls/writev-metal.c +++ b/libc/calls/writev-metal.c @@ -26,8 +26,7 @@ ssize_t sys_writev_metal(struct Fd *fd, const struct iovec *iov, int iovlen) { switch (fd->kind) { case kFdConsole: - if (weaken(sys_writev_vga)) - weaken(sys_writev_vga)(fd, iov, iovlen); + if (_weaken(sys_writev_vga)) _weaken(sys_writev_vga)(fd, iov, iovlen); /* fallthrough */ case kFdSerial: return sys_writev_serial(fd, iov, iovlen); diff --git a/libc/calls/writev-nt.c b/libc/calls/writev-nt.c index 5050b8e4d..3dd037f2d 100644 --- a/libc/calls/writev-nt.c +++ b/libc/calls/writev-nt.c @@ -28,7 +28,7 @@ textwindows ssize_t sys_writev_nt(int fd, const struct iovec *iov, int iovlen) { case kFdConsole: return sys_write_nt(fd, iov, iovlen, -1); case kFdSocket: - return weaken(sys_send_nt)(fd, iov, iovlen, 0); + return _weaken(sys_send_nt)(fd, iov, iovlen, 0); default: return ebadf(); } diff --git a/libc/calls/writev.c b/libc/calls/writev.c index 9b27fc49a..ada4dc8b1 100644 --- a/libc/calls/writev.c +++ b/libc/calls/writev.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" @@ -26,6 +25,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/likely.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/sock/internal.h" #include "libc/sysv/errfuns.h" @@ -57,7 +57,7 @@ ssize_t writev(int fd, const struct iovec *iov, int iovlen) { if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = weaken(__zipos_write)( + rc = _weaken(__zipos_write)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, iov, iovlen, -1); } else if (!IsWindows() && !IsMetal()) { if (iovlen == 1) { diff --git a/libc/crt/crt.S b/libc/crt/crt.S index 1cdca0e69..178691f91 100644 --- a/libc/crt/crt.S +++ b/libc/crt/crt.S @@ -74,7 +74,7 @@ _start: // make win32 imps noop .weak ape_idata_iat .weak ape_idata_iatend - ezlea missingno,ax + ezlea _missingno,ax ezlea ape_idata_iat,di ezlea ape_idata_iatend,cx sub %rdi,%rcx diff --git a/libc/dns/getaddrinfo.c b/libc/dns/getaddrinfo.c index e4f31fbb4..dd75eda1b 100644 --- a/libc/dns/getaddrinfo.c +++ b/libc/dns/getaddrinfo.c @@ -24,7 +24,7 @@ #include "libc/dns/servicestxt.h" #include "libc/fmt/conv.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/sock/sock.h" #include "libc/str/str.h" #include "libc/sysv/consts/af.h" diff --git a/libc/fmt/fmt.c b/libc/fmt/fmt.c index b7c5a1153..00015ac1a 100644 --- a/libc/fmt/fmt.c +++ b/libc/fmt/fmt.c @@ -28,7 +28,6 @@ #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/runtime/internal.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" @@ -125,7 +124,7 @@ hidden int __fmt(void *fn, void *arg, const char *format, va_list va) { int d, w, n, sign, prec, flags, width, lasterr; lasterr = errno; - out = fn ? fn : (void *)missingno; + out = fn ? fn : (void *)_missingno; while (*format) { if (*format != '%') { @@ -347,7 +346,7 @@ hidden int __fmt(void *fn, void *arg, const char *format, va_list va) { break; } case 'm': - p = weaken(strerror) ? weaken(strerror)(lasterr) : "?"; + p = _weaken(strerror) ? _weaken(strerror)(lasterr) : "?"; signbit = 0; goto FormatString; case 'r': @@ -381,15 +380,15 @@ hidden int __fmt(void *fn, void *arg, const char *format, va_list va) { case 'E': case 'a': case 'A': - if (!weaken(__fmt_dtoa)) { + if (!_weaken(__fmt_dtoa)) { p = "?"; prec = 0; flags &= ~(FLAGS_PRECISION | FLAGS_PLUS | FLAGS_SPACE); goto FormatString; } - if (weaken(__fmt_dtoa)(out, arg, d, flags, prec, sign, width, - longdouble, qchar, signbit, alphabet, - va) == -1) { + if (_weaken(__fmt_dtoa)(out, arg, d, flags, prec, sign, width, + longdouble, qchar, signbit, alphabet, + va) == -1) { return -1; } break; diff --git a/libc/fmt/formatbinary64.c b/libc/fmt/formatbinary64.c index 5e4e1b011..e7fb3c69a 100644 --- a/libc/fmt/formatbinary64.c +++ b/libc/fmt/formatbinary64.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/itoa.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" static inline int PickGoodWidth(unsigned x) { if (x < 16) { @@ -45,7 +45,7 @@ char *FormatBinary64(char p[hasatleast 67], uint64_t x, char z) { *p++ = '0'; *p++ = 'b'; } - i = PickGoodWidth(bsrl(x)); + i = PickGoodWidth(_bsrl(x)); do { b = 1; b <<= i; diff --git a/libc/fmt/formathex64.c b/libc/fmt/formathex64.c index 94c24fbc7..5e1a5013c 100644 --- a/libc/fmt/formathex64.c +++ b/libc/fmt/formathex64.c @@ -17,8 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/itoa.h" +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" static inline int PickGoodWidth(unsigned x, char z) { if (z) { @@ -48,7 +48,7 @@ char *FormatHex64(char p[hasatleast 19], uint64_t x, char z) { *p++ = '0'; *p++ = 'x'; } - i = PickGoodWidth(bsrl(x), z); + i = PickGoodWidth(_bsrl(x), z); do { *p++ = "0123456789abcdef"[(x >> (i -= 4)) & 15]; } while (i); diff --git a/libc/fmt/itoa64radix16.greg.c b/libc/fmt/itoa64radix16.greg.c index 5d4e8565c..0600d1f89 100644 --- a/libc/fmt/itoa64radix16.greg.c +++ b/libc/fmt/itoa64radix16.greg.c @@ -18,9 +18,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" size_t uint64toarray_radix16(uint64_t x, char b[hasatleast 17]) { - return uint64toarray_fixed16(x, b, ROUNDUP(x ? bsrl(x) + 1 : 1, 4)); + return uint64toarray_fixed16(x, b, ROUNDUP(x ? _bsrl(x) + 1 : 1, 4)); } diff --git a/libc/fmt/sprintf.c b/libc/fmt/sprintf.c index 5ec26e769..fb8b3f90d 100644 --- a/libc/fmt/sprintf.c +++ b/libc/fmt/sprintf.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/fmt/fmt.h" #include "libc/limits.h" #include "libc/log/log.h" diff --git a/libc/fmt/stoa.c b/libc/fmt/stoa.c index 2494e72e3..4d87f7a38 100644 --- a/libc/fmt/stoa.c +++ b/libc/fmt/stoa.c @@ -20,13 +20,13 @@ #include "libc/fmt/fmt.internal.h" #include "libc/fmt/internal.h" #include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/intrin/weaken.h" -#include "libc/nexgen32e/bsr.h" #include "libc/str/str.h" #include "libc/str/strwidth.h" #include "libc/str/thompike.h" -#include "libc/str/tpenc.h" #include "libc/str/unicode.h" #include "libc/str/utf16.h" @@ -40,27 +40,27 @@ static int __fmt_stoa_byte(out_f out, void *a, uint64_t c) { static int __fmt_stoa_wide(out_f out, void *a, uint64_t w) { char buf[8]; - if (!isascii(w)) w = tpenc(w); + if (!isascii(w)) w = _tpenc(w); WRITE64LE(buf, w); - return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1); + return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1); } static int __fmt_stoa_bing(out_f out, void *a, uint64_t w) { char buf[8]; - w = tpenc(kCp437[w & 0xFF]); + w = _tpenc(kCp437[w & 0xFF]); WRITE64LE(buf, w); - return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1); + return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1); } static int __fmt_stoa_quoted(out_f out, void *a, uint64_t w) { char buf[8]; if (isascii(w)) { - w = cescapec(w); + w = _cescapec(w); } else { - w = tpenc(w); + w = _tpenc(w); } WRITE64LE(buf, w); - return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1); + return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1); } /** @@ -102,7 +102,7 @@ int __fmt_stoa(int out(const char *, void *, size_t), void *arg, void *data, } else { emit = __fmt_stoa_wide; } - } else if ((flags & FLAGS_HASH) && weaken(kCp437)) { + } else if ((flags & FLAGS_HASH) && _weaken(kCp437)) { justdobytes = true; emit = __fmt_stoa_bing; ignorenul = flags & FLAGS_PRECISION; @@ -129,15 +129,15 @@ int __fmt_stoa(int out(const char *, void *, size_t), void *arg, void *data, if (width) { w = precision; if (signbit == 63) { - if (weaken(wcsnwidth)) { - w = weaken(wcsnwidth)((const wchar_t *)p, precision, 0); + if (_weaken(wcsnwidth)) { + w = _weaken(wcsnwidth)((const wchar_t *)p, precision, 0); } } else if (signbit == 15) { - if (weaken(strnwidth16)) { - w = weaken(strnwidth16)((const char16_t *)p, precision, 0); + if (_weaken(strnwidth16)) { + w = _weaken(strnwidth16)((const char16_t *)p, precision, 0); } - } else if (weaken(strnwidth)) { - w = weaken(strnwidth)(p, precision, 0); + } else if (_weaken(strnwidth)) { + w = _weaken(strnwidth)(p, precision, 0); } if (!(flags & FLAGS_NOQUOTE) && (flags & FLAGS_REPR)) { w += 2 + (signbit == 63) + (signbit == 15); diff --git a/libc/fmt/strerror.c b/libc/fmt/strerror.c index 0f5eb22e8..dabd4511f 100644 --- a/libc/fmt/strerror.c +++ b/libc/fmt/strerror.c @@ -19,7 +19,6 @@ #include "libc/dce.h" #include "libc/fmt/fmt.h" #include "libc/intrin/safemacros.internal.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" /** @@ -28,7 +27,7 @@ */ char *strerror(int err) { if (IsTiny()) { - return firstnonnull(strerrno(err), "EUNKNOWN"); + return firstnonnull(_strerrno(err), "EUNKNOWN"); } else { _Alignas(1) static char buf[512]; strerror_r(err, buf, sizeof(buf)); diff --git a/libc/fmt/vcscanf.c b/libc/fmt/vcscanf.c index 9fc4df1a7..c51d4044e 100644 --- a/libc/fmt/vcscanf.c +++ b/libc/fmt/vcscanf.c @@ -231,9 +231,9 @@ int vcscanf(int callback(void *), int unget(int, void *), void *arg, if (discard) { buf = NULL; } else if (ismalloc) { - buf = weaken(malloc)(bufsize * charbytes); + buf = _weaken(malloc)(bufsize * charbytes); struct FreeMe *entry; - if (buf && (entry = weaken(calloc)(1, sizeof(struct FreeMe)))) { + if (buf && (entry = _weaken(calloc)(1, sizeof(struct FreeMe)))) { entry->ptr = buf; entry->next = freeme; freeme = entry; @@ -245,7 +245,7 @@ int vcscanf(int callback(void *), int unget(int, void *), void *arg, size_t j = 0; for (;;) { if (ismalloc && !width && j + 2 + 1 >= bufsize && - !weaken(__grow)(&buf, &bufsize, charbytes, 0)) { + !_weaken(__grow)(&buf, &bufsize, charbytes, 0)) { width = bufsize - 1; } if (c != -1 && j + !rawmode < bufsize && (rawmode || !isspace(c))) { @@ -298,11 +298,11 @@ int vcscanf(int callback(void *), int unget(int, void *), void *arg, } } Done: - while (freeme && weaken(free)) { + while (freeme && _weaken(free)) { struct FreeMe *entry = freeme; freeme = entry->next; - if (items == -1) weaken(free)(entry->ptr); - weaken(free)(entry); + if (items == -1) _weaken(free)(entry->ptr); + _weaken(free)(entry); } return items; } diff --git a/libc/integral/c.inc b/libc/integral/c.inc index cfc14baf5..bf1993d3e 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -593,10 +593,10 @@ typedef struct { #endif #endif -#define notpossible \ - do { \ - asm("ud2\nnop"); \ - unreachable; \ +#define notpossible \ + do { \ + asm("ud2\n\tnop"); \ + unreachable; \ } while (0) #define donothing \ diff --git a/libc/intrin/_getauxval.c b/libc/intrin/_getauxval.c index d1cc56d82..9934c262f 100644 --- a/libc/intrin/_getauxval.c +++ b/libc/intrin/_getauxval.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/_getauxval.internal.h" +#include "libc/intrin/_getauxval.internal.h" #include "libc/runtime/runtime.h" /** diff --git a/libc/calls/_getauxval.internal.h b/libc/intrin/_getauxval.internal.h similarity index 59% rename from libc/calls/_getauxval.internal.h rename to libc/intrin/_getauxval.internal.h index d2a1177ed..12217f8f4 100644 --- a/libc/calls/_getauxval.internal.h +++ b/libc/intrin/_getauxval.internal.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_CALLS__GETAUXVAL_H_ -#define COSMOPOLITAN_LIBC_CALLS__GETAUXVAL_H_ +#ifndef COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_INTERNAL_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -12,4 +12,4 @@ struct AuxiliaryValue _getauxval(unsigned long); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_CALLS__GETAUXVAL_H_ */ +#endif /* COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_INTERNAL_H_ */ diff --git a/libc/intrin/arememoryintervalsok.c b/libc/intrin/arememoryintervalsok.c index fc3bf76ec..30ad421a9 100644 --- a/libc/intrin/arememoryintervalsok.c +++ b/libc/intrin/arememoryintervalsok.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/runtime/memtrack.internal.h" noasan bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) { diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index dc0315568..dc1426b68 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -19,7 +19,6 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" @@ -29,6 +28,8 @@ #include "libc/intrin/likely.h" #include "libc/intrin/lockcmpxchg.h" #include "libc/intrin/nomultics.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/log/internal.h" @@ -49,7 +50,6 @@ #include "libc/runtime/stack.h" #include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/nr.h" @@ -108,16 +108,16 @@ STATIC_YOINK("_init_asan"); * movq (%addr),%dst */ -#define HOOK(HOOK, IMPL) \ - do { \ - if (weaken(HOOK)) { \ - *weaken(HOOK) = IMPL; \ - } \ +#define HOOK(HOOK, IMPL) \ + do { \ + if (_weaken(HOOK)) { \ + *_weaken(HOOK) = IMPL; \ + } \ } while (0) #define REQUIRE(FUNC) \ do { \ - if (!weaken(FUNC)) { \ + if (!_weaken(FUNC)) { \ kprintf("error: asan needs %s\n", #FUNC); \ __asan_die()(); \ __asan_unreachable(); \ @@ -170,6 +170,7 @@ struct ReportOriginHeap { int z; }; +static char __asan_bigbuf[FRAMESIZE]; static int __asan_noreentry; static pthread_spinlock_t __asan_lock; static struct AsanMorgue __asan_morgue; @@ -195,7 +196,7 @@ static uint64_t __asan_roundup2pow(uint64_t x) { static char *__asan_utf8cpy(char *p, unsigned c) { uint64_t z; - z = tpenc(c); + z = _tpenc(c); do *p++ = z; while ((z >>= 8)); return p; @@ -350,13 +351,12 @@ static void __asan_exit(void) { kprintf("your asan runtime needs\n" "\tSTATIC_YOINK(\"__die\");\n" "in order to show you backtraces\n"); - __restorewintty(); - _Exit(99); + _Exitr(99); } dontdiscard static __asan_die_f *__asan_die(void) { - if (weaken(__die)) { - return weaken(__die); + if (_weaken(__die)) { + return _weaken(__die); } else { return __asan_exit; } @@ -403,7 +403,7 @@ static bool __asan_is_mapped(int x) { bool res; struct MemoryIntervals *m; __mmi_lock(); - m = weaken(_mmi); + m = _weaken(_mmi); i = FindMemoryInterval(m, x); res = i < m->i && x >= m->p[i].x; __mmi_unlock(); @@ -668,8 +668,8 @@ static void __asan_report_memory_origin_image(intptr_t a, int z) { unsigned l, m, r, n, k; struct SymbolTable *st; kprintf("\nthe memory belongs to image symbols\n"); - if (weaken(GetSymbolTable)) { - if ((st = weaken(GetSymbolTable)())) { + if (_weaken(GetSymbolTable)) { + if ((st = _weaken(GetSymbolTable)())) { l = 0; r = n = st->count; k = a - st->addr_base; @@ -716,10 +716,10 @@ static noasan void OnMemory(void *x, void *y, size_t n, void *a) { static void __asan_report_memory_origin_heap(const unsigned char *a, int z) { struct ReportOriginHeap t; kprintf("\nthe memory was allocated by\n"); - if (weaken(malloc_inspect_all)) { + if (_weaken(malloc_inspect_all)) { t.a = a; t.z = z; - weaken(malloc_inspect_all)(OnMemory, &t); + _weaken(malloc_inspect_all)(OnMemory, &t); } else { kprintf("\tunknown please STATIC_YOINK(\"malloc_inspect_all\");\n"); } @@ -765,7 +765,7 @@ dontdiscard static __asan_die_f *__asan_report(const void *addr, int size, char *p, *q, *base; struct MemoryIntervals *m; --__ftrace; - p = __fatalbuf; + p = __asan_bigbuf; kprintf("\n\e[J\e[1;31masan error\e[0m: %s %d-byte %s at %p shadow %p\n", __asan_describe_access_poison(kind), size, message, addr, SHADOW(addr)); @@ -827,7 +827,7 @@ dontdiscard static __asan_die_f *__asan_report(const void *addr, int size, p = __asan_format_section(p, _etext, _edata, ".data", addr); p = __asan_format_section(p, _end, _edata, ".bss", addr); __mmi_lock(); - for (m = weaken(_mmi), i = 0; i < m->i; ++i) { + for (m = _weaken(_mmi), i = 0; i < m->i; ++i) { x = m->p[i].x; y = m->p[i].y; p = __asan_format_interval(p, x << 16, (y << 16) + (FRAMESIZE - 1)); @@ -839,7 +839,7 @@ dontdiscard static __asan_die_f *__asan_report(const void *addr, int size, } __mmi_unlock(); *p = 0; - kprintf("%s", __fatalbuf); + kprintf("%s", __asan_bigbuf); __asan_report_memory_origin(addr, size, kind); kprintf("\nthe crash was caused by\n"); ++__ftrace; @@ -881,8 +881,8 @@ static void __asan_morgue_flush(void) { void *p; if (__threaded) pthread_spin_lock(&__asan_lock); for (i = 0; i < ARRAYLEN(__asan_morgue.p); ++i) { - if (__asan_morgue.p[i] && weaken(dlfree)) { - weaken(dlfree)(__asan_morgue.p[i]); + if (__asan_morgue.p[i] && _weaken(dlfree)) { + _weaken(dlfree)(__asan_morgue.p[i]); } __asan_morgue.p[i] = 0; } @@ -946,9 +946,9 @@ static void __asan_trace(struct AsanTrace *bt, const struct StackFrame *bp) { } if (!__asan_checka(SHADOW(bp), sizeof(*bp) >> 3).kind) { addr = bp->addr; - if (addr == weakaddr("__gc") && weakaddr("__gc")) { + if (addr == _weakaddr("__gc") && _weakaddr("__gc")) { do --gi; - while ((addr = garbage->p[gi].ret) == weakaddr("__gc")); + while ((addr = garbage->p[gi].ret) == _weakaddr("__gc")); } bt->p[i] = addr; } else { @@ -968,8 +968,8 @@ void *__asan_allocate(size_t a, size_t n, int underrun, int overrun, size_t c; struct AsanExtra *e; n = __asan_user_size(n); - if ((p = weaken(dlmemalign)(a, __asan_heap_size(n)))) { - c = weaken(dlmalloc_usable_size)(p); + if ((p = _weaken(dlmemalign)(a, __asan_heap_size(n)))) { + c = _weaken(dlmalloc_usable_size)(p); e = (struct AsanExtra *)(p + c - sizeof(*e)); __asan_unpoison(p, n); __asan_poison(p - 16, 16, underrun); /* see dlmalloc design */ @@ -986,7 +986,7 @@ static struct AsanExtra *__asan_get_extra(const void *p, size_t *c) { long x, n; struct AsanExtra *e; f = (intptr_t)p >> 16; - if (!kisdangerous(p) && (n = weaken(dlmalloc_usable_size)(p)) > sizeof(*e) && + if (!kisdangerous(p) && (n = _weaken(dlmalloc_usable_size)(p)) > sizeof(*e) && !__builtin_add_overflow((intptr_t)p, n, &x) && x <= 0x800000000000 && (LIKELY(f == (int)((x - 1) >> 16)) || !kisdangerous((void *)(x - 1))) && (LIKELY(f == (int)((x = x - sizeof(*e)) >> 16)) || @@ -1046,9 +1046,9 @@ int __asan_print_trace(void *p) { } for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) { kprintf("\n%*lx %s", 12, e->bt.p[i], - weaken(__get_symbol_by_addr) - ? weaken(__get_symbol_by_addr)(e->bt.p[i]) - : "please STATIC_YOINK(\"__get_symbol_by_addr\")"); + _weaken(GetSymbolByAddr) + ? _weaken(GetSymbolByAddr)(e->bt.p[i]) + : "please STATIC_YOINK(\"GetSymbolByAddr\")"); } return 0; } @@ -1060,13 +1060,13 @@ int __asan_is_leaky(void *p) { intptr_t f, *l; struct AsanExtra *e; struct SymbolTable *st; - if (!weaken(GetSymbolTable)) notpossible; + if (!_weaken(GetSymbolTable)) notpossible; if (!(e = __asan_get_extra(p, &c))) return 0; if (!__asan_read48(e->size, &n)) return 0; if (!__asan_is_mapped((((intptr_t)p >> 3) + 0x7fff8000) >> 16)) return 0; if (!(st = GetSymbolTable())) return 0; for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) { - if ((sym = weaken(__get_symbol)(st, e->bt.p[i])) == -1) continue; + if ((sym = _weaken(__get_symbol)(st, e->bt.p[i])) == -1) continue; f = st->addr_base + st->symbols[sym].x; for (l = _leaky_start; l < _leaky_end; ++l) { if (f == *l) { @@ -1086,7 +1086,7 @@ static void __asan_deallocate(char *p, long kind) { if (c <= ASAN_MORGUE_THRESHOLD) { p = __asan_morgue_add(p); } - weaken(dlfree)(p); + _weaken(dlfree)(p); } else { __asan_report_invalid_pointer(p)(); __asan_unreachable(); @@ -1204,8 +1204,8 @@ void *__asan_realloc_in_place(void *p, size_t n) { int __asan_malloc_trim(size_t pad) { __asan_morgue_flush(); - if (weaken(dlmalloc_trim)) { - return weaken(dlmalloc_trim)(pad); + if (_weaken(dlmalloc_trim)) { + return _weaken(dlmalloc_trim)(pad); } else { return 0; } @@ -1332,7 +1332,7 @@ void __asan_map_shadow(uintptr_t p, size_t n) { kprintf("error: %p size %'zu overlaps shadow space\n", p, n); _Exit(1); } - m = weaken(_mmi); + m = _weaken(_mmi); a = (0x7fff8000 + (p >> 3)) >> 16; b = (0x7fff8000 + (p >> 3) + (n >> 3) + 0xffff) >> 16; for (; a <= b; a += i) { @@ -1349,12 +1349,12 @@ void __asan_map_shadow(uintptr_t p, size_t n) { addr = (void *)(intptr_t)((int64_t)((uint64_t)a << 32) >> 16); prot = PROT_READ | PROT_WRITE; flag = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS; - sm = weaken(sys_mmap)(addr, size, prot, flag, -1, 0); + sm = _weaken(sys_mmap)(addr, size, prot, flag, -1, 0); if (sm.addr == MAP_FAILED || - weaken(TrackMemoryInterval)(m, a, a + i - 1, sm.maphandle, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, - false, false, 0, size) == -1) { + _weaken(TrackMemoryInterval)(m, a, a + i - 1, sm.maphandle, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, + false, false, 0, size) == -1) { kprintf("error: could not map asan shadow memory\n"); __asan_die()(); __asan_unreachable(); @@ -1372,11 +1372,11 @@ static textstartup void __asan_shadow_string(char *s) { static textstartup void __asan_shadow_auxv(intptr_t *auxv) { size_t i; for (i = 0; auxv[i]; i += 2) { - if (weaken(AT_RANDOM) && auxv[i] == *weaken(AT_RANDOM)) { + if (_weaken(AT_RANDOM) && auxv[i] == *_weaken(AT_RANDOM)) { __asan_map_shadow(auxv[i + 1], 16); - } else if (weaken(AT_EXECFN) && auxv[i] == *weaken(AT_EXECFN)) { + } else if (_weaken(AT_EXECFN) && auxv[i] == *_weaken(AT_EXECFN)) { __asan_shadow_string((char *)auxv[i + 1]); - } else if (weaken(AT_PLATFORM) && auxv[i] == *weaken(AT_PLATFORM)) { + } else if (_weaken(AT_PLATFORM) && auxv[i] == *_weaken(AT_PLATFORM)) { __asan_shadow_string((char *)auxv[i + 1]); } } @@ -1414,15 +1414,14 @@ textstartup void __asan_init(int argc, char **argv, char **envp, if (!_lockcmpxchg(&once, false, true)) return; if (IsWindows() && NtGetVersion() < kNtVersionWindows10) { __write_str("error: asan binaries require windows10\r\n"); - __restorewintty(); - _Exit(0); /* So `make MODE=dbg test` passes w/ Windows7 */ + _Exitr(0); /* So `make MODE=dbg test` passes w/ Windows7 */ } REQUIRE(_mmi); REQUIRE(sys_mmap); REQUIRE(TrackMemoryInterval); - if (weaken(hook_malloc) || weaken(hook_calloc) || weaken(hook_realloc) || - weaken(hook_realloc_in_place) || weaken(hook_free) || - weaken(hook_malloc_usable_size)) { + if (_weaken(hook_malloc) || _weaken(hook_calloc) || _weaken(hook_realloc) || + _weaken(hook_realloc_in_place) || _weaken(hook_free) || + _weaken(hook_malloc_usable_size)) { REQUIRE(dlmemalign); REQUIRE(dlmalloc_usable_size); } @@ -1446,8 +1445,8 @@ textstartup void __asan_init(int argc, char **argv, char **envp, } static textstartup void __asan_ctor(void) { - if (weaken(__cxa_atexit)) { - weaken(__cxa_atexit)(__asan_morgue_flush, NULL, NULL); + if (_weaken(__cxa_atexit)) { + _weaken(__cxa_atexit)(__asan_morgue_flush, NULL, NULL); } } diff --git a/libc/intrin/assertfail.greg.c b/libc/intrin/assertfail.greg.c index bb860e137..c1716de61 100644 --- a/libc/intrin/assertfail.greg.c +++ b/libc/intrin/assertfail.greg.c @@ -17,12 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/lockcmpxchgp.h" +#include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/log/internal.h" #include "libc/runtime/internal.h" @@ -43,20 +43,19 @@ relegated void __assert_fail(const char *expr, const char *file, int line) { kprintf("%s:%d: assert(%s) failed (tid %d)\n", file, line, expr, me); if (__vforked || _lockcmpxchgp(&sync, &owner, me)) { __restore_tty(); - if (weaken(ShowBacktrace)) { - weaken(ShowBacktrace)(2, __builtin_frame_address(0)); - } else if (weaken(PrintBacktraceUsingSymbols) && weaken(GetSymbolTable)) { - weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0), - weaken(GetSymbolTable)()); + if (_weaken(ShowBacktrace)) { + _weaken(ShowBacktrace)(2, __builtin_frame_address(0)); + } else if (_weaken(PrintBacktraceUsingSymbols) && + _weaken(GetSymbolTable)) { + _weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0), + _weaken(GetSymbolTable)()); } else { kprintf("can't backtrace b/c `ShowCrashReports` not linked\n"); } - __restorewintty(); - _Exit(23); + _Exitr(23); } else if (owner == me) { kprintf("assert failed while failing\n"); - __restorewintty(); - _Exit(24); + _Exitr(24); } else { _Exit1(25); } diff --git a/libc/intrin/bextra.c b/libc/intrin/bextra.c index 5e5e52362..3922daa65 100644 --- a/libc/intrin/bextra.c +++ b/libc/intrin/bextra.c @@ -21,7 +21,7 @@ /** * Extracts bit field from array. */ -unsigned bextra(const unsigned *p, size_t i, char b) { +unsigned _bextra(const unsigned *p, size_t i, char b) { unsigned k, r, w; w = sizeof(unsigned) * CHAR_BIT; if (b) { diff --git a/libc/intrin/bitreverse16.c b/libc/intrin/bitreverse16.c index 8119066a9..ab36cfe2a 100644 --- a/libc/intrin/bitreverse16.c +++ b/libc/intrin/bitreverse16.c @@ -21,6 +21,6 @@ /** * Reverses bits in 16-bit word. */ -int bitreverse16(int x) { - return BITREVERSE16(x); +int _bitreverse16(int x) { + return kReverseBits[0x00FF & x] << 8 | kReverseBits[(0xFF00 & x) >> 8]; } diff --git a/libc/intrin/bitreverse32.c b/libc/intrin/bitreverse32.c index b36d421ec..cc1c0380c 100644 --- a/libc/intrin/bitreverse32.c +++ b/libc/intrin/bitreverse32.c @@ -22,7 +22,7 @@ /** * Reverses bits in 32-bit word. */ -uint32_t bitreverse32(uint32_t x) { +uint32_t _bitreverse32(uint32_t x) { x = bswap_32(x); x = (x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1; x = (x & 0xcccccccc) >> 2 | (x & 0x33333333) << 2; diff --git a/libc/intrin/bitreverse64.c b/libc/intrin/bitreverse64.c index 8f03fc7b8..ae2b827b6 100644 --- a/libc/intrin/bitreverse64.c +++ b/libc/intrin/bitreverse64.c @@ -22,7 +22,7 @@ /** * Reverses bits in 64-bit word. */ -uint64_t bitreverse64(uint64_t x) { +uint64_t _bitreverse64(uint64_t x) { x = bswap_64(x); x = (x & 0xaaaaaaaaaaaaaaaa) >> 1 | (x & 0x5555555555555555) << 1; x = (x & 0xcccccccccccccccc) >> 2 | (x & 0x3333333333333333) << 2; diff --git a/libc/intrin/bitreverse8.c b/libc/intrin/bitreverse8.c index 2e4cff0d4..a66633ce1 100644 --- a/libc/intrin/bitreverse8.c +++ b/libc/intrin/bitreverse8.c @@ -21,6 +21,6 @@ /** * Reverses bits in 8-bit word. */ -int bitreverse8(int x) { - return BITREVERSE8(x); +int _bitreverse8(int x) { + return kReverseBits[255 & x]; } diff --git a/libc/intrin/bits.h b/libc/intrin/bits.h index d283f9aa8..583b308e4 100644 --- a/libc/intrin/bits.h +++ b/libc/intrin/bits.h @@ -13,24 +13,20 @@ extern const uint8_t kReverseBits[256]; uint32_t gray(uint32_t) pureconst; uint32_t ungray(uint32_t) pureconst; -int bitreverse8(int) libcesque pureconst; -int bitreverse16(int) libcesque pureconst; -uint32_t bitreverse32(uint32_t) libcesque pureconst; -uint64_t bitreverse64(uint64_t) libcesque pureconst; -unsigned long roundup2pow(unsigned long) libcesque pureconst; -unsigned long roundup2log(unsigned long) libcesque pureconst; -unsigned long rounddown2pow(unsigned long) libcesque pureconst; -unsigned long hamming(unsigned long, unsigned long) pureconst; -unsigned bextra(const unsigned *, size_t, char); +int _bitreverse8(int) libcesque pureconst; +int _bitreverse16(int) libcesque pureconst; +uint32_t _bitreverse32(uint32_t) libcesque pureconst; +uint64_t _bitreverse64(uint64_t) libcesque pureconst; +unsigned long _roundup2pow(unsigned long) libcesque pureconst; +unsigned long _roundup2log(unsigned long) libcesque pureconst; +unsigned long _rounddown2pow(unsigned long) libcesque pureconst; +unsigned long _hamming(unsigned long, unsigned long) pureconst; +unsigned _bextra(const unsigned *, size_t, char); /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § bits » no assembly required ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#define BITREVERSE8(X) (kReverseBits[255 & (X)]) -#define BITREVERSE16(X) \ - (kReverseBits[0x00FF & (X)] << 8 | kReverseBits[(0xFF00 & (X)) >> 8]) - #ifdef __STRICT_ANSI__ #define READ16LE(S) ((255 & (S)[1]) << 8 | (255 & (S)[0])) #define READ16BE(S) ((255 & (S)[0]) << 8 | (255 & (S)[1])) diff --git a/libc/str/bsf.c b/libc/intrin/bsf.c similarity index 95% rename from libc/str/bsf.c rename to libc/intrin/bsf.c index 65bfcdbc0..983882c8e 100644 --- a/libc/str/bsf.c +++ b/libc/intrin/bsf.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsf.h" +#include "libc/intrin/bsf.h" /** * Returns position of first bit set. * * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) * 0x00000000 wut 32 0 wut 32 * 0x00000001 0 0 1 0 31 * 0x80000001 0 0 1 31 0 @@ -35,6 +35,6 @@ * @param x is a 32-bit integer * @return number in range 0..31 or undefined if 𝑥 is 0 */ -int(bsf)(int x) { - return bsf(x); +int(_bsf)(int x) { + return _bsf(x); } diff --git a/libc/nexgen32e/bsf.h b/libc/intrin/bsf.h similarity index 76% rename from libc/nexgen32e/bsf.h rename to libc/intrin/bsf.h index 57d6a4a8f..e2faeb63f 100644 --- a/libc/nexgen32e/bsf.h +++ b/libc/intrin/bsf.h @@ -3,25 +3,25 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int bsf(int) pureconst; -int bsfl(long) pureconst; -int bsfll(long long) pureconst; -int bsf128(uintmax_t) pureconst; +int _bsf(int) pureconst; +int _bsfl(long) pureconst; +int _bsfll(long long) pureconst; +int _bsf128(uintmax_t) pureconst; #if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define bsf(u) \ +#define _bsf(u) \ ({ \ unsigned BiTs; \ asm("bsf\t%0,%0" : "=r"(BiTs) : "0"((unsigned)(u)) : "cc"); \ BiTs; \ }) -#define bsfl(u) \ +#define _bsfl(u) \ ({ \ unsigned long BiTs; \ asm("bsf\t%0,%0" : "=r"(BiTs) : "0"((unsigned long)(u)) : "cc"); \ (unsigned)BiTs; \ }) -#define bsfll(u) bsfl(u) +#define _bsfll(u) _bsfl(u) #endif COSMOPOLITAN_C_END_ diff --git a/libc/str/bsfl.c b/libc/intrin/bsfl.c similarity index 95% rename from libc/str/bsfl.c rename to libc/intrin/bsfl.c index 4c0b38ecc..6a60f3326 100644 --- a/libc/str/bsfl.c +++ b/libc/intrin/bsfl.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsf.h" +#include "libc/intrin/bsf.h" /** * Returns position of first bit set. * * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) * 0x00000000 wut 32 0 wut 32 * 0x00000001 0 0 1 0 31 * 0x80000001 0 0 1 31 0 @@ -35,6 +35,6 @@ * @param 𝑥 is a 64-bit integer * @return number in range 0..63 or undefined if 𝑥 is 0 */ -int(bsfl)(long x) { - return bsfl(x); +int(_bsfl)(long x) { + return _bsfl(x); } diff --git a/libc/str/bsfll.c b/libc/intrin/bsfll.c similarity index 94% rename from libc/str/bsfll.c rename to libc/intrin/bsfll.c index 492f1611b..fa60b9c86 100644 --- a/libc/str/bsfll.c +++ b/libc/intrin/bsfll.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsf.h" +#include "libc/intrin/bsf.h" /** * Returns position of first bit set. * * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) * 0x00000000 wut 32 0 wut 32 * 0x00000001 0 0 1 0 31 * 0x80000001 0 0 1 31 0 @@ -35,6 +35,6 @@ * @param 𝑥 is a 64-bit integer * @return number in range 0..63 or undefined if 𝑥 is 0 */ -int(bsfll)(long long x) { - return bsfll(x); +int(_bsfll)(long long x) { + return _bsfll(x); } diff --git a/libc/str/bsr.c b/libc/intrin/bsr.c similarity index 95% rename from libc/str/bsr.c rename to libc/intrin/bsr.c index 65c8c71e2..babd26925 100644 --- a/libc/str/bsr.c +++ b/libc/intrin/bsr.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" /** * Returns binary logarithm of 𝑥. * * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) * 0x00000000 wut 32 0 wut 32 * 0x00000001 0 0 1 0 31 * 0x80000001 0 0 1 31 0 @@ -35,6 +35,6 @@ * @param x is a 32-bit integer * @return number in range 0..31 or undefined if 𝑥 is 0 */ -int(bsr)(int x) { - return bsr(x); +int(_bsr)(int x) { + return _bsr(x); } diff --git a/libc/nexgen32e/bsr.h b/libc/intrin/bsr.h similarity index 76% rename from libc/nexgen32e/bsr.h rename to libc/intrin/bsr.h index c35b731b9..60a1cd316 100644 --- a/libc/nexgen32e/bsr.h +++ b/libc/intrin/bsr.h @@ -3,25 +3,25 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int bsr(int) pureconst; -int bsrl(long) pureconst; -int bsrll(long long) pureconst; +int _bsr(int) pureconst; +int _bsrl(long) pureconst; +int _bsrll(long long) pureconst; #if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__) -int bsr128(uint128_t) pureconst; -#define bsr(u) \ +int _bsr128(uint128_t) pureconst; +#define _bsr(u) \ ({ \ unsigned BiTs; \ asm("bsr\t%0,%0" : "=r"(BiTs) : "0"((unsigned)(u)) : "cc"); \ BiTs; \ }) -#define bsrl(u) \ +#define _bsrl(u) \ ({ \ unsigned long BiTs; \ asm("bsr\t%0,%0" : "=r"(BiTs) : "0"((unsigned long)(u)) : "cc"); \ (unsigned)BiTs; \ }) -#define bsrll(u) bsrl(u) +#define _bsrll(u) _bsrl(u) #endif COSMOPOLITAN_C_END_ diff --git a/libc/nexgen32e/bsr128.S b/libc/intrin/bsr128.S similarity index 96% rename from libc/nexgen32e/bsr128.S rename to libc/intrin/bsr128.S index 9a0f1d6b6..1c75ba1b0 100644 --- a/libc/nexgen32e/bsr128.S +++ b/libc/intrin/bsr128.S @@ -20,7 +20,7 @@ // Returns binary logarithm of integer 𝑥. // -// uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) +// uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) // 0x00000000 wut 32 0 wut 32 // 0x00000001 0 0 1 0 31 // 0x80000001 0 0 1 31 0 @@ -33,7 +33,8 @@ // @param rsi:rdi is 128-bit unsigned 𝑥 value // @return eax number in range [0,128) or undef if 𝑥 is 0 // @see also treasure trove of nearly identical functions -bsr128: .leafprologue +_bsr128: + .leafprologue .profilable bsr %rsi,%rax jnz 2f @@ -41,4 +42,4 @@ bsr128: .leafprologue 1: .leafepilogue 2: add $64,%eax jmp 1b - .endfn bsr128,globl + .endfn _bsr128,globl diff --git a/libc/str/bsrl.c b/libc/intrin/bsrl.c similarity index 95% rename from libc/str/bsrl.c rename to libc/intrin/bsrl.c index 9cd499584..a21ab29a5 100644 --- a/libc/str/bsrl.c +++ b/libc/intrin/bsrl.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" /** * Returns binary logarithm of 𝑥. * * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) * 0x00000000 wut 32 0 wut 32 * 0x00000001 0 0 1 0 31 * 0x80000001 0 0 1 31 0 @@ -35,6 +35,6 @@ * @param x is a 64-bit integer * @return number in range 0..63 or undefined if 𝑥 is 0 */ -int(bsrl)(long x) { - return bsrl(x); +int(_bsrl)(long x) { + return _bsrl(x); } diff --git a/libc/str/bsrll.c b/libc/intrin/bsrll.c similarity index 94% rename from libc/str/bsrll.c rename to libc/intrin/bsrll.c index 7c04ca460..ea57f306a 100644 --- a/libc/str/bsrll.c +++ b/libc/intrin/bsrll.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" /** * Returns binary logarithm of 𝑥. * * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) * 0x00000000 wut 32 0 wut 32 * 0x00000001 0 0 1 0 31 * 0x80000001 0 0 1 31 0 @@ -35,6 +35,6 @@ * @param x is a 64-bit integer * @return number in range 0..63 or undefined if 𝑥 is 0 */ -int(bsrll)(long long x) { - return bsrll(x); +int(_bsrll)(long long x) { + return _bsrll(x); } diff --git a/libc/intrin/closehandle.c b/libc/intrin/closehandle.c index b6a2a6a16..f09b53c03 100644 --- a/libc/intrin/closehandle.c +++ b/libc/intrin/closehandle.c @@ -16,9 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/log.h" #include "libc/nt/runtime.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/createdirectory.c b/libc/intrin/createdirectory.c index 1a3884279..85ea3512d 100644 --- a/libc/intrin/createdirectory.c +++ b/libc/intrin/createdirectory.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/files.h" diff --git a/libc/intrin/createfile.c b/libc/intrin/createfile.c index 2df5cc867..21493b1a9 100644 --- a/libc/intrin/createfile.c +++ b/libc/intrin/createfile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/createfile.h" diff --git a/libc/intrin/createfilemapping.c b/libc/intrin/createfilemapping.c index 7e149b5e8..97461e03b 100644 --- a/libc/intrin/createfilemapping.c +++ b/libc/intrin/createfilemapping.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/memory.h" diff --git a/libc/intrin/createfilemappingnuma.c b/libc/intrin/createfilemappingnuma.c index 33a51289e..0cee3cb0a 100644 --- a/libc/intrin/createfilemappingnuma.c +++ b/libc/intrin/createfilemappingnuma.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/intrin/createnamedpipe.c b/libc/intrin/createnamedpipe.c index 4c6d7a7ea..98aa1168a 100644 --- a/libc/intrin/createnamedpipe.c +++ b/libc/intrin/createnamedpipe.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/ipc.h" diff --git a/libc/intrin/createpipe.c b/libc/intrin/createpipe.c index a8bb75b2e..1d2002e1d 100644 --- a/libc/intrin/createpipe.c +++ b/libc/intrin/createpipe.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/ipc.h" diff --git a/libc/intrin/createprocess.c b/libc/intrin/createprocess.c index 13a7b05c2..5244cda19 100644 --- a/libc/intrin/createprocess.c +++ b/libc/intrin/createprocess.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/process.h" diff --git a/libc/intrin/createsymboliclink.c b/libc/intrin/createsymboliclink.c index 3f8101069..b8aaa0d84 100644 --- a/libc/intrin/createsymboliclink.c +++ b/libc/intrin/createsymboliclink.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/files.h" diff --git a/libc/intrin/createthread.c b/libc/intrin/createthread.c index d9ebf9650..3e5cfad76 100644 --- a/libc/intrin/createthread.c +++ b/libc/intrin/createthread.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/struct/securityattributes.h" diff --git a/libc/intrin/cxaatexit.c b/libc/intrin/cxaatexit.c index bbcbcbf64..0759d96af 100644 --- a/libc/intrin/cxaatexit.c +++ b/libc/intrin/cxaatexit.c @@ -17,12 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/weaken.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/cxaatexit.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/runtime/runtime.h" #include "libc/sysv/errfuns.h" @@ -51,8 +51,8 @@ noasan int __cxa_atexit(void *fp, void *arg, void *pred) { b = __cxa_blocks.p; if (!b) b = __cxa_blocks.p = &__cxa_blocks.root; if (!~b->mask) { - if (weaken(calloc) && - (b2 = weaken(calloc)(1, sizeof(struct CxaAtexitBlock)))) { + if (_weaken(calloc) && + (b2 = _weaken(calloc)(1, sizeof(struct CxaAtexitBlock)))) { b2->next = b; __cxa_blocks.p = b = b2; } else { @@ -60,7 +60,7 @@ noasan int __cxa_atexit(void *fp, void *arg, void *pred) { return enomem(); } } - i = bsr(~b->mask); + i = _bsr(~b->mask); assert(i < ARRAYLEN(b->p)); b->mask |= 1u << i; b->p[i].fp = fp; diff --git a/libc/intrin/cxafinalize.c b/libc/intrin/cxafinalize.c index 22bd58514..d43eae4f1 100644 --- a/libc/intrin/cxafinalize.c +++ b/libc/intrin/cxafinalize.c @@ -17,11 +17,11 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/weaken.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/bsf.h" #include "libc/intrin/cxaatexit.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsf.h" #include "libc/runtime/runtime.h" /** @@ -44,7 +44,7 @@ StartOverLocked: for (;;) { mask = b->mask; while (mask) { - i = bsf(mask); + i = _bsf(mask); mask &= ~(1u << i); if (!pred || pred == b->p[i].pred) { b->mask &= ~(1u << i); @@ -61,8 +61,8 @@ StartOverLocked: b2 = b->next; if (b2) { assert(b != &__cxa_blocks.root); - if (weaken(free)) { - weaken(free)(b); + if (_weaken(free)) { + _weaken(free)(b); } } __cxa_blocks.p = b2; diff --git a/libc/intrin/deletefile.c b/libc/intrin/deletefile.c index c9284a6de..c53263ac3 100644 --- a/libc/intrin/deletefile.c +++ b/libc/intrin/deletefile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/files.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/describefutexresult.c b/libc/intrin/describefutexresult.c index 22c3811b4..843f1f8de 100644 --- a/libc/intrin/describefutexresult.c +++ b/libc/intrin/describefutexresult.c @@ -18,11 +18,11 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/itoa.h" #include "libc/intrin/describeflags.internal.h" -#include "libc/str/errfun.h" +#include "libc/str/str.h" const char *(DescribeFutexResult)(char buf[12], int ax) { const char *s; - if (ax > -4095u && (s = strerrno(-ax))) { + if (ax > -4095u && (s = _strerrno(-ax))) { return s; } else { FormatInt32(buf, ax); diff --git a/libc/intrin/describerlimit.c b/libc/intrin/describerlimit.c index 1d27b600e..c5f1f8a7b 100644 --- a/libc/intrin/describerlimit.c +++ b/libc/intrin/describerlimit.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rlimit.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/intrin/deviceiocontrol.c b/libc/intrin/deviceiocontrol.c index 456f8026f..e5e8c2845 100644 --- a/libc/intrin/deviceiocontrol.c +++ b/libc/intrin/deviceiocontrol.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/files.h" #include "libc/nt/struct/overlapped.h" diff --git a/libc/intrin/directmap.c b/libc/intrin/directmap.c index 2feae3dd0..c5be4ef74 100644 --- a/libc/intrin/directmap.c +++ b/libc/intrin/directmap.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/intrin/exit.c b/libc/intrin/exit.c index b133fcdd5..14f4d0acd 100644 --- a/libc/intrin/exit.c +++ b/libc/intrin/exit.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/promises.internal.h" #include "libc/nexgen32e/vendor.internal.h" diff --git a/libc/intrin/exit1.greg.c b/libc/intrin/exit1.greg.c index 3dacb1533..098a10658 100644 --- a/libc/intrin/exit1.greg.c +++ b/libc/intrin/exit1.greg.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asmflag.h" #include "libc/intrin/promises.internal.h" diff --git a/libc/runtime/close_s.c b/libc/intrin/exitr.c similarity index 81% rename from libc/runtime/close_s.c rename to libc/intrin/exitr.c index 431f251f9..060f2ac2b 100644 --- a/libc/runtime/close_s.c +++ b/libc/intrin/exitr.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,20 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/intrin/lockxchg.h" #include "libc/runtime/runtime.h" -/** - * Closes file descriptor. - * - * The caller's variable is made -1 so subsequent calls are no-ops. - * - * @return 0 on success, or -1 w/ errno - * @asyncsignalsafe - */ -int close_s(int *fdp) { - int fd = -1; - if (lockxchg(fdp, &fd) == -1) return 0; - return close(fd); +privileged wontreturn void _Exitr(int exitcode) { + _restorewintty(); + _Exit(exitcode); } diff --git a/libc/intrin/extend.c b/libc/intrin/extend.c index 3a24354f4..4a8cf4e15 100644 --- a/libc/intrin/extend.c +++ b/libc/intrin/extend.c @@ -52,7 +52,9 @@ static void _mapframe(void *p) { * * !(p & 0xffff) && !(((p >> 3) + 0x7fff8000) & 0xffff) * - * which must be the case when selecting a starting address. + * which must be the case when selecting a starting address. We also + * make the assumption that allocations can only grow monotonically. + * Furthermore allocations shall never be removed or relocated. * * @param p points to start of memory region * @param n specifies how many bytes are needed @@ -81,6 +83,5 @@ noasan void *_extend(void *p, size_t n, void *e, intptr_t h) { *SHADOW(q) = 0; } } - asm("mfence"); return q; } diff --git a/libc/calls/extend.internal.h b/libc/intrin/extend.internal.h similarity index 100% rename from libc/calls/extend.internal.h rename to libc/intrin/extend.internal.h diff --git a/libc/intrin/ezlea.h b/libc/intrin/ezlea.h index 08507b47c..cc128952c 100644 --- a/libc/intrin/ezlea.h +++ b/libc/intrin/ezlea.h @@ -3,9 +3,9 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) #if __pic__ + __pie__ + __code_model_medium__ + __code_model_large__ + 0 > 1 -#define ezlea(symbol) "lea\t" symbol "(%%rip),%" +#define _ezlea(symbol) "lea\t" symbol "(%%rip),%" #else -#define ezlea(symbol) "mov\t$" symbol ",%k" +#define _ezlea(symbol) "mov\t$" symbol ",%k" #endif #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/intrin/findclose.c b/libc/intrin/findclose.c index 652d4f9cd..0177fc8f8 100644 --- a/libc/intrin/findclose.c +++ b/libc/intrin/findclose.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/files.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/findfirstfile.c b/libc/intrin/findfirstfile.c index ed7afc317..8a7a1c5ac 100644 --- a/libc/intrin/findfirstfile.c +++ b/libc/intrin/findfirstfile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/files.h" diff --git a/libc/intrin/findnextfile.c b/libc/intrin/findnextfile.c index d940ae1bb..c2d0c3925 100644 --- a/libc/intrin/findnextfile.c +++ b/libc/intrin/findnextfile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/errors.h" diff --git a/libc/intrin/flushfilebuffers.c b/libc/intrin/flushfilebuffers.c index 918f5d321..aece1bae2 100644 --- a/libc/intrin/flushfilebuffers.c +++ b/libc/intrin/flushfilebuffers.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/files.h" diff --git a/libc/intrin/flushviewoffile.c b/libc/intrin/flushviewoffile.c index 9912b3534..a10acf394 100644 --- a/libc/intrin/flushviewoffile.c +++ b/libc/intrin/flushviewoffile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/memory.h" diff --git a/libc/intrin/g_fds.c b/libc/intrin/g_fds.c index b524f141d..6e8533088 100644 --- a/libc/intrin/g_fds.c +++ b/libc/intrin/g_fds.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/extend.internal.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" +#include "libc/intrin/extend.internal.h" #include "libc/intrin/pushpop.h" #include "libc/intrin/weaken.h" #include "libc/nt/runtime.h" @@ -48,11 +48,11 @@ textstartup void InitializeFileDescriptors(void) { fds->n = 4; fds->f = 3; fds->e = _extend(fds->p, fds->n * sizeof(*fds->p), fds->e, - kMemtrackFdsStart + kMemtrackFdsSize);; + kMemtrackFdsStart + kMemtrackFdsSize); if (IsMetal()) { extern const char vga_console[]; pushmov(&fds->f, 3ull); - if (weaken(vga_console)) { + if (_weaken(vga_console)) { fds->p[0].kind = pushpop(kFdConsole); fds->p[1].kind = pushpop(kFdConsole); fds->p[2].kind = pushpop(kFdConsole); diff --git a/libc/intrin/generateconsolectrlevent.c b/libc/intrin/generateconsolectrlevent.c index 31cfbf60f..be4c2dbd8 100644 --- a/libc/intrin/generateconsolectrlevent.c +++ b/libc/intrin/generateconsolectrlevent.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/console.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/getenv.greg.c b/libc/intrin/getenv.greg.c index 800db2808..b552280c4 100644 --- a/libc/intrin/getenv.greg.c +++ b/libc/intrin/getenv.greg.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/log/libfatal.internal.h" diff --git a/libc/intrin/getexitcodeprocess.c b/libc/intrin/getexitcodeprocess.c index 8a783e3a7..2d2727d43 100644 --- a/libc/intrin/getexitcodeprocess.c +++ b/libc/intrin/getexitcodeprocess.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/accounting.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/getfileattributes.c b/libc/intrin/getfileattributes.c index 10f878149..0ccff0818 100644 --- a/libc/intrin/getfileattributes.c +++ b/libc/intrin/getfileattributes.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/enum/fileflagandattributes.h" diff --git a/libc/intrin/hamming.c b/libc/intrin/hamming.c index 450e3ee9c..1b61ee614 100644 --- a/libc/intrin/hamming.c +++ b/libc/intrin/hamming.c @@ -22,6 +22,6 @@ * Counts number of different bits. * @see https://en.wikipedia.org/wiki/Hamming_code */ -unsigned long hamming(unsigned long x, unsigned long y) { +unsigned long _hamming(unsigned long x, unsigned long y) { return popcnt(x ^ y); } diff --git a/libc/intrin/_have_fsgsbase.c b/libc/intrin/have_fsgsbase.c similarity index 100% rename from libc/intrin/_have_fsgsbase.c rename to libc/intrin/have_fsgsbase.c diff --git a/libc/intrin/kprintf.greg.c b/libc/intrin/kprintf.greg.c index fd072467d..ffee3ed4f 100644 --- a/libc/intrin/kprintf.greg.c +++ b/libc/intrin/kprintf.greg.c @@ -48,7 +48,6 @@ #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/prot.h" @@ -114,27 +113,27 @@ privileged static inline bool kischarmisaligned(const char *p, signed char t) { } privileged static inline bool kismemtrackhosed(void) { - return !((weaken(_mmi)->i <= weaken(_mmi)->n) && - (weaken(_mmi)->p == weaken(_mmi)->s || - weaken(_mmi)->p == (struct MemoryInterval *)kMemtrackStart)); + return !((_weaken(_mmi)->i <= _weaken(_mmi)->n) && + (_weaken(_mmi)->p == _weaken(_mmi)->s || + _weaken(_mmi)->p == (struct MemoryInterval *)kMemtrackStart)); } privileged static bool kismapped(int x) { // xxx: we can't lock because no reentrant locks yet size_t m, r, l = 0; - if (!weaken(_mmi)) return true; + if (!_weaken(_mmi)) return true; if (kismemtrackhosed()) return false; - r = weaken(_mmi)->i; + r = _weaken(_mmi)->i; while (l < r) { m = (l + r) >> 1; - if (weaken(_mmi)->p[m].y < x) { + if (_weaken(_mmi)->p[m].y < x) { l = m + 1; } else { r = m; } } - if (l < weaken(_mmi)->i && x >= weaken(_mmi)->p[l].x) { - return !!(weaken(_mmi)->p[l].prot & PROT_READ); + if (l < _weaken(_mmi)->i && x >= _weaken(_mmi)->p[l].x) { + return !!(_weaken(_mmi)->p[l].prot & PROT_READ); } else { return false; } @@ -462,16 +461,16 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, unixerr = errno; winerr = 0; if (IsWindows()) { - if (type == 1 && weaken(WSAGetLastError)) { - winerr = weaken(WSAGetLastError)(); - } else if (weaken(GetLastError)) { - winerr = weaken(GetLastError)(); + if (type == 1 && _weaken(WSAGetLastError)) { + winerr = _weaken(WSAGetLastError)(); + } else if (_weaken(GetLastError)) { + winerr = _weaken(GetLastError)(); } } if (!unixerr && sign == ' ') { break; - } else if (weaken(strerror_wr) && - !weaken(strerror_wr)(unixerr, winerr, z, sizeof(z))) { + } else if (_weaken(strerror_wr) && + !_weaken(strerror_wr)(unixerr, winerr, z, sizeof(z))) { s = z; type = 0; goto FormatString; @@ -493,7 +492,7 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, case 'G': x = va_arg(va, int); - if (weaken(strsignal) && (s = weaken(strsignal)(x))) { + if (_weaken(strsignal) && (s = _weaken(strsignal)(x))) { goto FormatString; } else { goto FormatDecimal; @@ -508,11 +507,11 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, // can be manually consulted to look up the faulting code. int idx; x = va_arg(va, intptr_t); - if (weaken(__symtab) && *weaken(__symtab) && - (idx = weaken(__get_symbol)(0, x)) != -1) { + if (_weaken(__symtab) && *_weaken(__symtab) && + (idx = _weaken(__get_symbol)(0, x)) != -1) { if (p + 1 <= e) *p++ = '&'; - s = (*weaken(__symtab))->name_base + - (*weaken(__symtab))->names[idx]; + s = (*_weaken(__symtab))->name_base + + (*_weaken(__symtab))->names[idx]; goto FormatString; } base = 4; @@ -651,8 +650,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, EmitChar: if (t <= 0x7f) goto EmitByte; if (uppr) { - if (weaken(towupper)) { - t = weaken(towupper)(t); + if (_weaken(towupper)) { + t = _weaken(towupper)(t); } else if (uppr && 'a' <= t && t <= 'z') { t -= 'a' - 'A'; } diff --git a/libc/intrin/mapviewoffileex.c b/libc/intrin/mapviewoffileex.c index 3542063d1..67ce06dc9 100644 --- a/libc/intrin/mapviewoffileex.c +++ b/libc/intrin/mapviewoffileex.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/enum/filemapflags.h" diff --git a/libc/intrin/mapviewoffileexnuma.c b/libc/intrin/mapviewoffileexnuma.c index 9ec6faae3..3c06d9151 100644 --- a/libc/intrin/mapviewoffileexnuma.c +++ b/libc/intrin/mapviewoffileexnuma.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/intrin/memtrack.greg.c b/libc/intrin/memtrack.greg.c index c00b6351c..826a6aaad 100644 --- a/libc/intrin/memtrack.greg.c +++ b/libc/intrin/memtrack.greg.c @@ -18,13 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/bits.h" #include "libc/intrin/likely.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" diff --git a/libc/intrin/mmi.init.S b/libc/intrin/mmi.init.S index 5910d3c0f..a2a932d99 100644 --- a/libc/intrin/mmi.init.S +++ b/libc/intrin/mmi.init.S @@ -22,5 +22,5 @@ .init.start 200,_init__mmi movb $OPEN_MAX,_mmi+8 movl $_mmi+24,_mmi+16 - movb $PTHREAD_MUTEX_RECURSIVE,__mmi_lock_obj+16(%rip) + movb $PTHREAD_MUTEX_RECURSIVE,__mmi_lock_obj+4(%rip) .init.end 200,_init__mmi diff --git a/libc/intrin/movefileex.c b/libc/intrin/movefileex.c index 7975516cf..7c045f344 100644 --- a/libc/intrin/movefileex.c +++ b/libc/intrin/movefileex.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/files.h" diff --git a/libc/intrin/openprocess.c b/libc/intrin/openprocess.c index d6463a28c..39e8142f6 100644 --- a/libc/intrin/openprocess.c +++ b/libc/intrin/openprocess.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/memory.h" diff --git a/libc/intrin/pthread_key_create.c b/libc/intrin/pthread_key_create.c index e7c7a9c98..a08317384 100644 --- a/libc/intrin/pthread_key_create.c +++ b/libc/intrin/pthread_key_create.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "libc/runtime/runtime.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" @@ -31,7 +31,7 @@ int pthread_key_create(pthread_key_t *key, pthread_key_dtor dtor) { pthread_spin_lock(&_pthread_keys_lock); for (i = 0; i < (PTHREAD_KEYS_MAX + 63) / 64; ++i) { if (~_pthread_key_usage[i]) { - j = bsrl(~_pthread_key_usage[i]); + j = _bsrl(~_pthread_key_usage[i]); _pthread_key_usage[i] |= 1ul << j; _pthread_key_dtor[i * 64 + j] = dtor; *key = i * 64 + j; diff --git a/libc/intrin/pthread_key_destruct.c b/libc/intrin/pthread_key_destruct.c index cfad22162..7d408b085 100644 --- a/libc/intrin/pthread_key_destruct.c +++ b/libc/intrin/pthread_key_destruct.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" @@ -33,7 +33,7 @@ StartOver: for (i = 0; i < (PTHREAD_KEYS_MAX + 63) / 64; ++i) { x = _pthread_key_usage[i]; while (x) { - j = bsrl(x); + j = _bsrl(x); if ((value = key[i * 64 + j]) && (dtor = _pthread_key_dtor[i * 64 + j])) { key[i * 64 + j] = 0; pthread_spin_unlock(&_pthread_keys_lock); diff --git a/libc/intrin/pthread_mutex_init.c b/libc/intrin/pthread_mutex_init.c index f7fda57cd..0b930ccb7 100644 --- a/libc/intrin/pthread_mutex_init.c +++ b/libc/intrin/pthread_mutex_init.c @@ -19,7 +19,16 @@ #include "libc/thread/thread.h" /** - * Initializes mutex. + * Initializes mutex, e.g. + * + * pthread_mutex_t lock; + * pthread_mutexattr_t attr; + * pthread_mutexattr_init(&attr); + * pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + * pthread_mutex_init(&lock, &attr); + * pthread_mutexattr_destroy(&attr); + * // ... + * pthread_mutex_destroy(&lock); * * @param attr may be null * @return 0 on success, or error number on failure diff --git a/libc/intrin/pthread_mutex_lock.c b/libc/intrin/pthread_mutex_lock.c index 2d4d04818..5a70a8097 100644 --- a/libc/intrin/pthread_mutex_lock.c +++ b/libc/intrin/pthread_mutex_lock.c @@ -65,8 +65,15 @@ int pthread_mutex_lock(pthread_mutex_t *mutex) { if (LIKELY(__tls_enabled && // mutex->_type == PTHREAD_MUTEX_NORMAL && // mutex->_pshared == PTHREAD_PROCESS_PRIVATE && // - weaken(nsync_mu_lock))) { - weaken(nsync_mu_lock)((nsync_mu *)mutex); + _weaken(nsync_mu_lock))) { + _weaken(nsync_mu_lock)((nsync_mu *)mutex); + return 0; + } + + if (mutex->_type == PTHREAD_MUTEX_NORMAL) { + while (atomic_exchange_explicit(&mutex->_lock, 1, memory_order_acquire)) { + pthread_yield(); + } return 0; } diff --git a/libc/intrin/pthread_mutex_trylock.c b/libc/intrin/pthread_mutex_trylock.c index 9621115e0..1acc0306d 100644 --- a/libc/intrin/pthread_mutex_trylock.c +++ b/libc/intrin/pthread_mutex_trylock.c @@ -42,8 +42,8 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex) { if (LIKELY(__tls_enabled && // mutex->_type == PTHREAD_MUTEX_NORMAL && // mutex->_pshared == PTHREAD_PROCESS_PRIVATE && // - weaken(nsync_mu_trylock))) { - if (weaken(nsync_mu_trylock)((nsync_mu *)mutex)) { + _weaken(nsync_mu_trylock))) { + if (_weaken(nsync_mu_trylock)((nsync_mu *)mutex)) { return 0; } else { return EBUSY; @@ -51,9 +51,7 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex) { } if (mutex->_type == PTHREAD_MUTEX_NORMAL) { - c = 0; - if (atomic_compare_exchange_strong_explicit( - &mutex->_lock, &c, 1, memory_order_acquire, memory_order_relaxed)) { + if (!atomic_exchange_explicit(&mutex->_lock, 1, memory_order_acquire)) { return 0; } else { return EBUSY; diff --git a/libc/intrin/pthread_mutex_unlock.c b/libc/intrin/pthread_mutex_unlock.c index d0e65b732..7b3538bc4 100644 --- a/libc/intrin/pthread_mutex_unlock.c +++ b/libc/intrin/pthread_mutex_unlock.c @@ -37,8 +37,13 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex) { if (LIKELY(__tls_enabled && // mutex->_type == PTHREAD_MUTEX_NORMAL && // mutex->_pshared == PTHREAD_PROCESS_PRIVATE && // - weaken(nsync_mu_unlock))) { - weaken(nsync_mu_unlock)((nsync_mu *)mutex); + _weaken(nsync_mu_unlock))) { + _weaken(nsync_mu_unlock)((nsync_mu *)mutex); + return 0; + } + + if (mutex->_type == PTHREAD_MUTEX_NORMAL) { + atomic_store_explicit(&mutex->_lock, 0, memory_order_release); return 0; } diff --git a/libc/intrin/pthread_once.c b/libc/intrin/pthread_once.c index dc8ce6fb7..eb13d4e80 100644 --- a/libc/intrin/pthread_once.c +++ b/libc/intrin/pthread_once.c @@ -46,8 +46,8 @@ */ int pthread_once(pthread_once_t *once, void init(void)) { uint32_t old; - if (weaken(nsync_run_once)) { - weaken(nsync_run_once)((nsync_once *)once, init); + if (_weaken(nsync_run_once)) { + _weaken(nsync_run_once)((nsync_once *)once, init); return 0; } switch ((old = atomic_load_explicit(&once->_lock, memory_order_relaxed))) { diff --git a/libc/intrin/pthread_yield.c b/libc/intrin/pthread_yield.c index 273eabde4..46b3595e5 100644 --- a/libc/intrin/pthread_yield.c +++ b/libc/intrin/pthread_yield.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/thread/thread.h" /** diff --git a/libc/intrin/quick_exit.c b/libc/intrin/quick_exit.c index fff957397..31b09a111 100644 --- a/libc/intrin/quick_exit.c +++ b/libc/intrin/quick_exit.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" @@ -31,9 +31,9 @@ wontreturn void quick_exit(int exitcode) { const uintptr_t *p; STRACE("quick_exit(%d)", exitcode); - __restorewintty(); - if (weaken(fflush)) { - weaken(fflush)(0); + _restorewintty(); + if (_weaken(fflush)) { + _weaken(fflush)(0); } for (p = __fini_array_end; p > __fini_array_start;) { ((void (*)(void))(*--p))(); diff --git a/libc/intrin/rand64.c b/libc/intrin/rand64.c index 3d48c6b94..2eddd9de3 100644 --- a/libc/intrin/rand64.c +++ b/libc/intrin/rand64.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/_getauxval.internal.h" +#include "libc/intrin/_getauxval.internal.h" #include "libc/thread/thread.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/thread/tls.h" diff --git a/libc/intrin/_rdfsbase.c b/libc/intrin/rdfsbase.c similarity index 100% rename from libc/intrin/_rdfsbase.c rename to libc/intrin/rdfsbase.c diff --git a/libc/intrin/_rdgsbase.c b/libc/intrin/rdgsbase.c similarity index 100% rename from libc/intrin/_rdgsbase.c rename to libc/intrin/rdgsbase.c diff --git a/libc/intrin/removedirectory.c b/libc/intrin/removedirectory.c index 6d1709fe8..d9c477e09 100644 --- a/libc/intrin/removedirectory.c +++ b/libc/intrin/removedirectory.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/files.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/reopenfile.c b/libc/intrin/reopenfile.c index 5abc149fe..bf1446186 100644 --- a/libc/intrin/reopenfile.c +++ b/libc/intrin/reopenfile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/files.h" diff --git a/libc/intrin/restorewintty.c b/libc/intrin/restorewintty.c index f46670b2d..3f91880c6 100644 --- a/libc/intrin/restorewintty.c +++ b/libc/intrin/restorewintty.c @@ -33,7 +33,7 @@ const char kConsoleHandles[3] = { /** * Puts cmd.exe gui back the way it was. */ -noinstrument void __restorewintty(void) { +noinstrument void _restorewintty(void) { int i; if (!IsWindows()) return; if (GetCurrentProcessId() == __winmainpid) { diff --git a/libc/intrin/rounddown2pow.c b/libc/intrin/rounddown2pow.c index 9b11ea88a..a9e8b8e45 100644 --- a/libc/intrin/rounddown2pow.c +++ b/libc/intrin/rounddown2pow.c @@ -17,14 +17,14 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" /** * Returns 𝑥 rounded down to previous two power. * * @define (𝑥>0→2^⌊log₂𝑥⌋, x=0→0, 𝑇→⊥) - * @see roundup2pow() + * @see _roundup2pow() */ -unsigned long rounddown2pow(unsigned long x) { - return x ? 1ul << bsrl(x) : 0; +unsigned long _rounddown2pow(unsigned long x) { + return x ? 1ul << _bsrl(x) : 0; } diff --git a/libc/intrin/roundup2log.c b/libc/intrin/roundup2log.c index be46e1c62..e74204f3b 100644 --- a/libc/intrin/roundup2log.c +++ b/libc/intrin/roundup2log.c @@ -17,12 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" /** * Returns 𝑥 rounded up to next two power and log'd. - * @see roundup2pow() + * @see _roundup2pow() */ -unsigned long roundup2log(unsigned long x) { - return x > 1 ? (bsrl(x - 1) + 1) : x ? 1 : 0; +unsigned long _roundup2log(unsigned long x) { + return x > 1 ? (_bsrl(x - 1) + 1) : x ? 1 : 0; } diff --git a/libc/intrin/roundup2pow.c b/libc/intrin/roundup2pow.c index 0ce1119cc..62584e874 100644 --- a/libc/intrin/roundup2pow.c +++ b/libc/intrin/roundup2pow.c @@ -17,14 +17,14 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" /** * Returns 𝑥 rounded up to next two power. * * @define (𝑥>0→2^⌈log₂x⌉, x=0→0, 𝑇→⊥) - * @see rounddown2pow() + * @see _rounddown2pow() */ -unsigned long roundup2pow(unsigned long x) { - return x > 1 ? 2ul << bsrl(x - 1) : x ? 1 : 0; +unsigned long _roundup2pow(unsigned long x) { + return x > 1 ? 2ul << _bsrl(x - 1) : x ? 1 : 0; } diff --git a/libc/intrin/setcurrentdirectory.c b/libc/intrin/setcurrentdirectory.c index 9045f7277..82fea86ea 100644 --- a/libc/intrin/setcurrentdirectory.c +++ b/libc/intrin/setcurrentdirectory.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/files.h" #include "libc/nt/memory.h" diff --git a/libc/calls/strace.internal.h b/libc/intrin/strace.internal.h similarity index 100% rename from libc/calls/strace.internal.h rename to libc/intrin/strace.internal.h diff --git a/libc/intrin/stracef.greg.c b/libc/intrin/stracef.greg.c index 6ca880dbf..aef6fb8cc 100644 --- a/libc/intrin/stracef.greg.c +++ b/libc/intrin/stracef.greg.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/kprintf.h" #include "libc/runtime/runtime.h" diff --git a/libc/intrin/strerdoc.greg.c b/libc/intrin/strerdoc.greg.c index 07022eca7..89f5a5f62 100644 --- a/libc/intrin/strerdoc.greg.c +++ b/libc/intrin/strerdoc.greg.c @@ -23,7 +23,7 @@ * Converts errno value to descriptive sentence. * @return non-null rodata string or null if not found */ -privileged char *strerdoc(int x) { +privileged char *_strerdoc(int x) { if (x) { return GetMagnumStr(kErrnoDocs, x); } else { diff --git a/libc/intrin/strerrno.greg.c b/libc/intrin/strerrno.greg.c index 076803a9c..bca7518c7 100644 --- a/libc/intrin/strerrno.greg.c +++ b/libc/intrin/strerrno.greg.c @@ -17,13 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/magnumstrs.internal.h" -#include "libc/str/errfun.h" /** * Converts errno value to symbolic name. * @return non-null rodata string or null if not found */ -privileged char *strerrno(int x) { +privileged char *_strerrno(int x) { if (x) { return GetMagnumStr(kErrnoNames, x); } else { diff --git a/libc/intrin/strerror_wr.greg.c b/libc/intrin/strerror_wr.greg.c index fa2baf8a7..d6a2444f4 100644 --- a/libc/intrin/strerror_wr.greg.c +++ b/libc/intrin/strerror_wr.greg.c @@ -24,7 +24,6 @@ #include "libc/nt/enum/formatmessageflags.h" #include "libc/nt/enum/lang.h" #include "libc/nt/process.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" /** @@ -40,8 +39,8 @@ privileged int strerror_wr(int err, uint32_t winerr, char *buf, size_t size) { char16_t winmsg[256]; const char *sym, *msg; wanting = false; - sym = firstnonnull(strerrno(err), (wanting = true, "EUNKNOWN")); - msg = firstnonnull(strerdoc(err), (wanting = true, "No error information")); + sym = firstnonnull(_strerrno(err), (wanting = true, "EUNKNOWN")); + msg = firstnonnull(_strerdoc(err), (wanting = true, "No error information")); if (IsTiny()) { if (!sym) sym = "EUNKNOWN"; for (; (c = *sym++); --size) diff --git a/libc/intrin/terminateprocess.c b/libc/intrin/terminateprocess.c index c658f1a34..fb2da4468 100644 --- a/libc/intrin/terminateprocess.c +++ b/libc/intrin/terminateprocess.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/console.h" #include "libc/nt/runtime.h" diff --git a/libc/intrin/tpenc.S b/libc/intrin/tpenc.S index aace173e1..f68558d22 100644 --- a/libc/intrin/tpenc.S +++ b/libc/intrin/tpenc.S @@ -23,7 +23,7 @@ // @param edi is int to encode // @return rax is word-encoded byte buffer // @note invented on a napkin in a new jersey diner -tpenc: .leafprologue +_tpenc: .leafprologue .profilable mov %edi,%edi xor %eax,%eax @@ -42,7 +42,7 @@ tpenc: .leafprologue 2: or %ch,%al 3: or %rdi,%rax .leafepilogue - .endfn tpenc,globl + .endfn _tpenc,globl .rodata .align 4 diff --git a/libc/str/tpenc.h b/libc/intrin/tpenc.h similarity index 84% rename from libc/str/tpenc.h rename to libc/intrin/tpenc.h index b693615fa..686adbf45 100644 --- a/libc/str/tpenc.h +++ b/libc/intrin/tpenc.h @@ -3,13 +3,13 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -uint64_t tpenc(int32_t) pureconst; +uint64_t _tpenc(int32_t) pureconst; #if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define tpenc(CODE) \ +#define _tpenc(CODE) \ ({ \ long Edi, Buf; \ - asm("call\ttpenc" \ + asm("call\t_tpenc" \ : "=a"(Buf), "=D"(Edi) \ : "1"((int)(CODE)) \ : "rcx", "rdx", "cc"); \ diff --git a/libc/intrin/ubsan.c b/libc/intrin/ubsan.c index c67c87d8a..ab0d6b937 100644 --- a/libc/intrin/ubsan.c +++ b/libc/intrin/ubsan.c @@ -16,17 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/reverse.internal.h" -#include "libc/intrin/pushpop.h" -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/fmt/fmt.h" #include "libc/intrin/kprintf.h" +#include "libc/intrin/pushpop.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" +#include "libc/mem/reverse.internal.h" #include "libc/nt/runtime.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" @@ -200,8 +200,7 @@ static void __ubsan_exit(void) { kprintf("your ubsan runtime needs\n" "\tSTATIC_YOINK(\"__die\");\n" "in order to show you backtraces\n"); - __restorewintty(); - _Exit(99); + _Exitr(99); } static char *__ubsan_stpcpy(char *d, const char *s) { @@ -214,8 +213,8 @@ static char *__ubsan_stpcpy(char *d, const char *s) { } dontdiscard static __ubsan_die_f *__ubsan_die(void) { - if (weaken(__die)) { - return weaken(__die); + if (_weaken(__die)) { + return _weaken(__die); } else { return __ubsan_exit; } diff --git a/libc/intrin/unmapviewoffile.c b/libc/intrin/unmapviewoffile.c index 455db63d3..795c9d7ab 100644 --- a/libc/intrin/unmapviewoffile.c +++ b/libc/intrin/unmapviewoffile.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/memory.h" diff --git a/libc/intrin/virtualprotect.c b/libc/intrin/virtualprotect.c index f7cec63ab..0d81fc951 100644 --- a/libc/intrin/virtualprotect.c +++ b/libc/intrin/virtualprotect.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/log/libfatal.internal.h" diff --git a/libc/intrin/waitformultipleobjects.c b/libc/intrin/waitformultipleobjects.c index 6a7ae4938..c948c23c2 100644 --- a/libc/intrin/waitformultipleobjects.c +++ b/libc/intrin/waitformultipleobjects.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/synchronization.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/waitforsingleobject.c b/libc/intrin/waitforsingleobject.c index bde8762ef..d51c4339d 100644 --- a/libc/intrin/waitforsingleobject.c +++ b/libc/intrin/waitforsingleobject.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/nt/synchronization.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/intrin/weaken.h b/libc/intrin/weaken.h index ca5000570..afacaa5c9 100644 --- a/libc/intrin/weaken.h +++ b/libc/intrin/weaken.h @@ -4,25 +4,25 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) #ifndef __STRICT_ANSI__ -#define weaken(symbol) ((const typeof(&(symbol)))weakaddr(#symbol)) +#define _weaken(symbol) ((const typeof(&(symbol)))_weakaddr(#symbol)) -#define strongaddr(symbolstr) \ - ({ \ - intptr_t waddr; \ - asm(ezlea(symbolstr) "0" : "=r"(waddr)); \ - waddr; \ +#define _strongaddr(symbolstr) \ + ({ \ + intptr_t waddr; \ + asm(_ezlea(symbolstr) "0" : "=r"(waddr)); \ + waddr; \ }) -#define weakaddr(symbolstr) \ - ({ \ - intptr_t waddr; \ - asm(".weak\t" symbolstr "\n\t" ezlea(symbolstr) "0" : "=r"(waddr)); \ - waddr; \ +#define _weakaddr(symbolstr) \ + ({ \ + intptr_t waddr; \ + asm(".weak\t" symbolstr "\n\t" _ezlea(symbolstr) "0" : "=r"(waddr)); \ + waddr; \ }) #else -#define weaken(symbol) symbol -#define weakaddr(symbolstr) &(symbolstr) +#define _weaken(symbol) symbol +#define _weakaddr(symbolstr) &(symbolstr) #endif /* __STRICT_ANSI__ */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_WEAKEN_H_ */ diff --git a/libc/intrin/winerr.greg.c b/libc/intrin/winerr.greg.c index 6eb869710..7729c4dab 100644 --- a/libc/intrin/winerr.greg.c +++ b/libc/intrin/winerr.greg.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #define ShouldUseMsabiAttribute() 1 -#include "libc/intrin/weaken.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/nt/errors.h" diff --git a/libc/intrin/_wrfsbase.c b/libc/intrin/wrfsbase.c similarity index 100% rename from libc/intrin/_wrfsbase.c rename to libc/intrin/wrfsbase.c diff --git a/libc/intrin/_wrgsbase.c b/libc/intrin/wrgsbase.c similarity index 100% rename from libc/intrin/_wrgsbase.c rename to libc/intrin/wrgsbase.c diff --git a/libc/intrin/wsarecv.c b/libc/intrin/wsarecv.c index a7292ec0d..8029cccfd 100644 --- a/libc/intrin/wsarecv.c +++ b/libc/intrin/wsarecv.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" diff --git a/libc/intrin/wsarecvfrom.c b/libc/intrin/wsarecvfrom.c index 69ebdd61b..6d49a094c 100644 --- a/libc/intrin/wsarecvfrom.c +++ b/libc/intrin/wsarecvfrom.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" diff --git a/libc/intrin/wsawaitformultipleevents.c b/libc/intrin/wsawaitformultipleevents.c index c578ff0fe..667f557fe 100644 --- a/libc/intrin/wsawaitformultipleevents.c +++ b/libc/intrin/wsawaitformultipleevents.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/isystem/avx2intrin.h b/libc/isystem/avx2intrin.h new file mode 100644 index 000000000..06f51d75d --- /dev/null +++ b/libc/isystem/avx2intrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_AVX2INTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_AVX2INTRIN_H_ +#include "libc/intrin/avx2intrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_AVX2INTRIN_H_ */ diff --git a/libc/isystem/avxintrin.h b/libc/isystem/avxintrin.h new file mode 100644 index 000000000..079159e22 --- /dev/null +++ b/libc/isystem/avxintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_AVXINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_AVXINTRIN_H_ +#include "libc/intrin/avxintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_AVXINTRIN_H_ */ diff --git a/libc/isystem/emmintrin.h b/libc/isystem/emmintrin.h new file mode 100644 index 000000000..80f8c5332 --- /dev/null +++ b/libc/isystem/emmintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_EMMINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_EMMINTRIN_H_ +#include "libc/intrin/emmintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_EMMINTRIN_H_ */ diff --git a/libc/isystem/pmmintrin.h b/libc/isystem/pmmintrin.h new file mode 100644 index 000000000..087f0b39a --- /dev/null +++ b/libc/isystem/pmmintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_PMMINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_PMMINTRIN_H_ +#include "libc/intrin/pmmintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_PMMINTRIN_H_ */ diff --git a/libc/isystem/shaintrin.h b/libc/isystem/shaintrin.h new file mode 100644 index 000000000..308744668 --- /dev/null +++ b/libc/isystem/shaintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SHAINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_SHAINTRIN_H_ +#include "libc/intrin/shaintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SHAINTRIN_H_ */ diff --git a/libc/isystem/smmintrin.h b/libc/isystem/smmintrin.h new file mode 100644 index 000000000..b226f1571 --- /dev/null +++ b/libc/isystem/smmintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SMMINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_SMMINTRIN_H_ +#include "libc/intrin/smmintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SMMINTRIN_H_ */ diff --git a/libc/isystem/tmmintrin.h b/libc/isystem/tmmintrin.h new file mode 100644 index 000000000..eebddd130 --- /dev/null +++ b/libc/isystem/tmmintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_TMMINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_TMMINTRIN_H_ +#include "libc/intrin/tmmintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_TMMINTRIN_H_ */ diff --git a/libc/isystem/wmmintrin.h b/libc/isystem/wmmintrin.h new file mode 100644 index 000000000..ee565c59f --- /dev/null +++ b/libc/isystem/wmmintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_WMMINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_WMMINTRIN_H_ +#include "libc/intrin/wmmintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_WMMINTRIN_H_ */ diff --git a/libc/isystem/xmmintrin.h b/libc/isystem/xmmintrin.h new file mode 100644 index 000000000..1aa83665b --- /dev/null +++ b/libc/isystem/xmmintrin.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_XMMINTRIN_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_XMMINTRIN_H_ +#include "libc/intrin/xmmintrin.internal.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_XMMINTRIN_H_ */ diff --git a/libc/log/appendresourcereport.c b/libc/log/appendresourcereport.c index 5d0951d3f..b48c5fd6f 100644 --- a/libc/log/appendresourcereport.c +++ b/libc/log/appendresourcereport.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/struct/rusage.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bits.h" #include "libc/log/log.h" #include "libc/math.h" #include "libc/runtime/clktck.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" struct State { char **b; diff --git a/libc/log/appendresourcereport.internal.h b/libc/log/appendresourcereport.internal.h new file mode 100644 index 000000000..697b951e9 --- /dev/null +++ b/libc/log/appendresourcereport.internal.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_LIBC_LOG_APPENDRESOURCEREPORT_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_LOG_APPENDRESOURCEREPORT_INTERNAL_H_ +#include "libc/calls/struct/rusage.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +void AppendResourceReport(char **, struct rusage *, const char *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_LOG_APPENDRESOURCEREPORT_INTERNAL_H_ */ diff --git a/libc/log/backtrace2.c b/libc/log/backtrace2.c index 2459941a4..f64659e73 100644 --- a/libc/log/backtrace2.c +++ b/libc/log/backtrace2.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/rusage.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" @@ -30,18 +29,19 @@ #include "libc/intrin/kprintf.h" #include "libc/intrin/promises.internal.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/mem/alg.h" #include "libc/mem/bisectcarleft.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/nexgen32e/gc.internal.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/runtime/symbols.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" @@ -111,10 +111,10 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { gi = garbage ? garbage->i : 0; for (frame = bp; frame && i < kBacktraceMaxFrames - 1; frame = frame->next) { addr = frame->addr; - if (addr == weakaddr("__gc")) { + if (addr == _weakaddr("__gc")) { do { --gi; - } while ((addr = garbage->p[gi].ret) == weakaddr("__gc")); + } while ((addr = garbage->p[gi].ret) == _weakaddr("__gc")); } argv[i++] = buf + j; buf[j++] = '0'; diff --git a/libc/log/backtrace3.c b/libc/log/backtrace3.c index 2e5b3c82d..1ff5522f5 100644 --- a/libc/log/backtrace3.c +++ b/libc/log/backtrace3.c @@ -63,10 +63,10 @@ noinstrument noasan int PrintBacktraceUsingSymbols(int fd, break; } addr = frame->addr; - if (addr == weakaddr("__gc")) { + if (addr == _weakaddr("__gc")) { do { --gi; - } while ((addr = garbage->p[gi].ret) == weakaddr("__gc")); + } while ((addr = garbage->p[gi].ret) == _weakaddr("__gc")); } /* * we subtract one to handle the case of noreturn functions with a diff --git a/libc/log/checkaligned.c b/libc/log/checkaligned.c index f0bd5baaa..910722b5c 100644 --- a/libc/log/checkaligned.c +++ b/libc/log/checkaligned.c @@ -26,7 +26,7 @@ void __check_fail_aligned(unsigned bytes, uint64_t ptr, const char *file, int line, const char *fmt, ...) { fflush(stderr); - if (!IsTiny()) memsummary(fileno(stderr)); + if (!IsTiny()) _memsummary(fileno(stderr)); kprintf("%s:%d: error: pointer not %d-byte aligned: %p\n", file, line, bytes, ptr); __die(); diff --git a/libc/log/checkfail.c b/libc/log/checkfail.c index dc15bd116..f8013fc52 100644 --- a/libc/log/checkfail.c +++ b/libc/log/checkfail.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/intrin/kprintf.h" diff --git a/libc/log/checkfail_ndebug.c b/libc/log/checkfail_ndebug.c index 7d4b0abfe..364ba01dd 100644 --- a/libc/log/checkfail_ndebug.c +++ b/libc/log/checkfail_ndebug.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/intrin/kprintf.h" +#include "libc/intrin/weaken.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/runtime/internal.h" @@ -48,7 +48,6 @@ relegated wontreturn void __check_fail_ndebug(uint64_t want, uint64_t got, va_end(va); } kprintf("\n"); - if (weaken(__die)) weaken(__die)(); - __restorewintty(); - _Exit(68); + if (_weaken(__die)) _weaken(__die)(); + _Exitr(68); } diff --git a/libc/log/countexpr.h b/libc/log/countexpr.h index 967c329ef..8ef7af320 100644 --- a/libc/log/countexpr.h +++ b/libc/log/countexpr.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_ #include "libc/macros.internal.h" #include "libc/nexgen32e/bench.h" -#include "libc/nexgen32e/bsr.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/log/cxaprintexits.c b/libc/log/cxaprintexits.c index f7659801d..cf042e434 100644 --- a/libc/log/cxaprintexits.c +++ b/libc/log/cxaprintexits.c @@ -17,9 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" +#include "libc/intrin/bsf.h" #include "libc/intrin/cxaatexit.internal.h" #include "libc/log/log.h" -#include "libc/nexgen32e/bsf.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -42,10 +42,10 @@ void __cxa_printexits(FILE *f, void *pred) { do { mask = b->mask; while (mask) { - i = bsf(mask); + i = _bsf(mask); mask &= ~(1u << i); if (!pred || pred == b->p[i].pred) { - symbol = __get_symbol_by_addr((intptr_t)b->p[i].fp); + symbol = GetSymbolByAddr((intptr_t)b->p[i].fp); if (symbol) { snprintf(name, sizeof(name), "%s", symbol); } else { diff --git a/libc/log/die.c b/libc/log/die.c index 3281690fd..c027c8a0b 100644 --- a/libc/log/die.c +++ b/libc/log/die.c @@ -45,12 +45,10 @@ relegated wontreturn void __die(void) { DebugBreak(); } ShowBacktrace(2, __builtin_frame_address(0)); - __restorewintty(); - _Exit(77); + _Exitr(77); } else if (owner == me) { kprintf("die failed while dying\n"); - __restorewintty(); - _Exit(78); + _Exitr(78); } else { _Exit1(79); } diff --git a/libc/log/getcallername.c b/libc/log/getcallername.c index 18197a372..2aeadcfd8 100644 --- a/libc/log/getcallername.c +++ b/libc/log/getcallername.c @@ -26,6 +26,6 @@ const char *GetCallerName(const struct StackFrame *bp) { struct SymbolTable *st; if (!bp && (bp = __builtin_frame_address(0))) bp = bp->next; - if (bp) return __get_symbol_by_addr(bp->addr); + if (bp) return GetSymbolByAddr(bp->addr); return 0; } diff --git a/libc/log/getcallername.internal.h b/libc/log/getcallername.internal.h new file mode 100644 index 000000000..597409c68 --- /dev/null +++ b/libc/log/getcallername.internal.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_LIBC_LOG_GETCALLERNAME_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_LOG_GETCALLERNAME_INTERNAL_H_ +#include "libc/nexgen32e/stackframe.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +const char *GetCallerName(const struct StackFrame *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_LOG_GETCALLERNAME_INTERNAL_H_ */ diff --git a/libc/log/getsymbolbyaddr.c b/libc/log/getsymbolbyaddr.c index 857eca338..ab62f9869 100644 --- a/libc/log/getsymbolbyaddr.c +++ b/libc/log/getsymbolbyaddr.c @@ -23,7 +23,7 @@ /** * Returns name of symbol at address. */ -noasan char *__get_symbol_by_addr(int64_t addr) { +noasan char *GetSymbolByAddr(int64_t addr) { /* asan runtime depends on this function */ int i; struct SymbolTable *st; diff --git a/libc/log/leaks.c b/libc/log/leaks.c index 4ec7371f4..f4d5c4462 100644 --- a/libc/log/leaks.c +++ b/libc/log/leaks.c @@ -16,19 +16,19 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/bits.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/lockcmpxchg.h" +#include "libc/intrin/strace.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/internal.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/testlib/testlib.h" -STATIC_YOINK("__get_symbol_by_addr"); +STATIC_YOINK("GetSymbolByAddr"); #define MAXLEAKS 1000 @@ -115,7 +115,6 @@ noasan void CheckForMemoryLeaks(void) { /* __print_maps(); */ /* PrintSystemMappings(2); */ /* PrintGarbage(); */ - __restorewintty(); - _Exit(78); + _Exitr(78); } } diff --git a/libc/log/libfatal.internal.h b/libc/log/libfatal.internal.h index 8ff3934ee..a6b80f160 100644 --- a/libc/log/libfatal.internal.h +++ b/libc/log/libfatal.internal.h @@ -10,8 +10,6 @@ COSMOPOLITAN_C_START_ #define __ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c)) -extern char __fatalbuf[]; - forceinline long __sysv_exit(long rc) { long ax; #if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) diff --git a/libc/log/log.h b/libc/log/log.h index 7d9a5283f..2b50a26be 100644 --- a/libc/log/log.h +++ b/libc/log/log.h @@ -1,13 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_ #define COSMOPOLITAN_LIBC_LOG_LOG_H_ -#include "libc/calls/struct/rusage.h" -#include "libc/calls/struct/sigset.h" -#include "libc/calls/struct/winsize.h" -#include "libc/dce.h" -#include "libc/errno.h" -#include "libc/intrin/likely.h" -#include "libc/nexgen32e/stackframe.h" -#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #define kLogFatal 0 @@ -31,6 +23,12 @@ #endif #endif +#ifdef TINY +#define _LOG_TINY 1 +#else +#define _LOG_TINY 0 +#endif + #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -38,31 +36,25 @@ extern FILE *__log_file; int __watch(void *, size_t); void __die(void) relegated wontreturn; /* print backtrace and abort() */ -void meminfo(int); /* shows malloc statistics &c. */ -void memsummary(int); /* light version of same thing */ -uint16_t getttycols(uint16_t); -int getttysize(int, struct winsize *) paramsnonnull(); +void _meminfo(int); /* shows malloc statistics &c. */ +void _memsummary(int); /* light version of same thing */ bool IsTerminalInarticulate(void) nosideeffect; const char *commandvenv(const char *, const char *); const char *GetAddr2linePath(void); const char *GetGdbPath(void); -const char *GetCallerName(const struct StackFrame *); - void ShowCrashReports(void); -void callexitontermination(struct sigset *); bool32 IsDebuggerPresent(bool); bool IsRunningUnderMake(void); const char *GetSiCodeName(int, int); -void AppendResourceReport(char **, struct rusage *, const char *); -char *__get_symbol_by_addr(int64_t); +char *GetSymbolByAddr(int64_t); void PrintGarbage(void); void PrintGarbageNumeric(FILE *); void CheckForMemoryLeaks(void); -#define showcrashreports() ShowCrashReports() - #ifndef __STRICT_ANSI__ +#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0) + extern unsigned __log_level; /* log level for runtime check */ #define LOGGABLE(LEVEL) \ @@ -72,24 +64,22 @@ extern unsigned __log_level; /* log level for runtime check */ // log a message with the specified log level (not checking if LOGGABLE) #define LOGF(LEVEL, FMT, ...) \ do { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } while (0) // report an error without backtrace and debugger invocation #define FATALF(FMT, ...) \ do { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \ - __restorewintty(); \ - _Exit(1); \ - unreachable; \ + _log_exit(1); \ } while (0) #define DIEF(FMT, ...) \ do { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \ unreachable; \ } while (0) @@ -118,102 +108,105 @@ extern unsigned __log_level; /* log level for runtime check */ #define VERBOSEF(FMT, ...) \ do { \ if (LOGGABLE(kLogVerbose)) { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) #define DEBUGF(FMT, ...) \ do { \ - if (UNLIKELY(LOGGABLE(kLogDebug))) { \ - if (!IsTiny()) --__ftrace; \ + if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \ + if (!_LOG_TINY) _log_untrace(); \ fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) #define NOISEF(FMT, ...) \ do { \ - if (UNLIKELY(LOGGABLE(kLogNoise))) { \ - if (!IsTiny()) --__ftrace; \ + if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \ + if (!_LOG_TINY) _log_untrace(); \ fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) #define FLOGF(F, FMT, ...) \ do { \ if (LOGGABLE(kLogInfo)) { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) #define FWARNF(F, FMT, ...) \ do { \ if (LOGGABLE(kLogWarn)) { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) #define FFATALF(F, FMT, ...) \ do { \ - if (!IsTiny()) --__ftrace; \ + if (!_LOG_TINY) _log_untrace(); \ flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \ - __restorewintty(); \ - _Exit(1); \ - unreachable; \ + _log_exit(1); \ } while (0) #define FDEBUGF(F, FMT, ...) \ do { \ - if (UNLIKELY(LOGGABLE(kLogDebug))) { \ - if (!IsTiny()) --__ftrace; \ + if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \ + if (!_LOG_TINY) _log_untrace(); \ fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) #define FNOISEF(F, FMT, ...) \ do { \ - if (UNLIKELY(LOGGABLE(kLogNoise))) { \ - if (!IsTiny()) --__ftrace; \ + if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \ + if (!_LOG_TINY) _log_untrace(); \ fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \ - if (!IsTiny()) ++__ftrace; \ + if (!_LOG_TINY) _log_retrace(); \ } \ } while (0) -#define LOGIFNEG1(FORM) \ - ({ \ - int e = errno; \ - autotype(FORM) Ax = (FORM); \ - if (UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \ - if (!IsTiny()) --__ftrace; \ - __logerrno(__FILE__, __LINE__, #FORM); \ - if (!IsTiny()) ++__ftrace; \ - errno = e; \ - } \ - Ax; \ +#define LOGIFNEG1(FORM) \ + ({ \ + int e = _log_get_errno(); \ + autotype(FORM) Ax = (FORM); \ + if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \ + if (!_LOG_TINY) _log_untrace(); \ + _log_errno(__FILE__, __LINE__, #FORM); \ + if (!_LOG_TINY) _log_retrace(); \ + _log_set_errno(e); \ + } \ + Ax; \ }) #define LOGIFNULL(FORM) \ ({ \ - int e = errno; \ + int e = _log_get_errno(); \ autotype(FORM) Ax = (FORM); \ if (Ax == NULL && LOGGABLE(kLogWarn)) { \ - if (!IsTiny()) --__ftrace; \ - __logerrno(__FILE__, __LINE__, #FORM); \ - if (!IsTiny()) ++__ftrace; \ - errno = e; \ + if (!_LOG_TINY) _log_untrace(); \ + _log_errno(__FILE__, __LINE__, #FORM); \ + if (!_LOG_TINY) _log_retrace(); \ + _log_set_errno(e); \ } \ Ax; \ }) -void __logerrno(const char *, int, const char *) relegated; +void _log_errno(const char *, int, const char *) relegated; +int _log_get_errno(void); +void _log_set_errno(int); +void _log_untrace(void); +void _log_retrace(void); +void _log_exit(int) wontreturn; #define ARGS unsigned, const char *, int, FILE *, const char * #define ATTR paramsnonnull((5)) printfesque(5) diff --git a/libc/log/getttycols.c b/libc/log/log_exit.c similarity index 75% rename from libc/log/getttycols.c rename to libc/log/log_exit.c index 5e89c7d12..dc4b761f9 100644 --- a/libc/log/getttycols.c +++ b/libc/log/log_exit.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -17,23 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/log.h" -#include "libc/calls/calls.h" -#include "libc/calls/termios.h" -#include "libc/sysv/consts/fileno.h" +#include "libc/runtime/runtime.h" -/** - * Shorthand for getting ws_col from getttysize(). - * - * It is recommended that programs err on the side of showing more - * information, if this value can't be obtained with certainty. - * - * @return terminal width or defaultcols on error - */ -uint16_t getttycols(uint16_t defaultcols) { - struct winsize wsize; - if (getttysize(STDIN_FILENO, &wsize) != -1) { - return wsize.ws_col; - } else { - return defaultcols; - } +privileged wontreturn void _log_exit(int exitcode) { + _Exitr(exitcode); } diff --git a/test/libc/mem/replacestr_test.inc b/libc/log/log_get_errno.c similarity index 74% rename from test/libc/mem/replacestr_test.inc rename to libc/log/log_get_errno.c index addf0d8ee..54b8dd5c7 100644 --- a/test/libc/mem/replacestr_test.inc +++ b/libc/log/log_get_errno.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,22 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/errno.h" +#include "libc/log/log.h" -TEST(REPLACESTR, demo) { - EXPECT_STREQ(S("hello friends"), - REPLACESTR(S("hello world"), S("world"), S("friends"))); - EXPECT_STREQ(S("bbbbbbbb"), REPLACESTR(S("aaaa"), S("a"), S("bb"))); -} - -TEST(REPLACESTR, emptyString) { - EXPECT_STREQ(S(""), REPLACESTR(S(""), S("x"), S("y"))); -} - -TEST(REPLACESTR, emptyNeedle) { - EXPECT_EQ(NULL, REPLACESTR(S("a"), S(""), S("a"))); - EXPECT_EQ(EINVAL, errno); -} - -TEST(REPLACESTR, needleInReplacement_doesntExplode) { - EXPECT_STREQ(S("xxxxxxx"), REPLACESTR(S("x"), S("x"), S("xxxxxxx"))); +noinstrument int _log_get_errno(void) { + return errno; } diff --git a/libc/log/log_retrace.c b/libc/log/log_retrace.c new file mode 100644 index 000000000..6ad18e613 --- /dev/null +++ b/libc/log/log_retrace.c @@ -0,0 +1,24 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/log/log.h" +#include "libc/runtime/runtime.h" + +noinstrument void _log_retrace(void) { + ++__ftrace; +} diff --git a/libc/intrin/fatalbuf.c b/libc/log/log_set_errno.c similarity index 91% rename from libc/intrin/fatalbuf.c rename to libc/log/log_set_errno.c index 40658a611..b8d985d85 100644 --- a/libc/intrin/fatalbuf.c +++ b/libc/log/log_set_errno.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,6 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/log/libfatal.internal.h" +#include "libc/errno.h" +#include "libc/log/log.h" -char __fatalbuf[FRAMESIZE]; +noinstrument void _log_set_errno(int e) { + errno = e; +} diff --git a/libc/log/log_untrace.c b/libc/log/log_untrace.c new file mode 100644 index 000000000..9f2296e06 --- /dev/null +++ b/libc/log/log_untrace.c @@ -0,0 +1,24 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/log/log.h" +#include "libc/runtime/runtime.h" + +noinstrument void _log_untrace(void) { + --__ftrace; +} diff --git a/libc/log/logerrno.c b/libc/log/logerrno.c index 450ebb32f..cb029a9f7 100644 --- a/libc/log/logerrno.c +++ b/libc/log/logerrno.c @@ -22,6 +22,6 @@ #include "libc/stdio/stdio.h" #include "libc/str/str.h" -void __logerrno(const char *file, int line, const char *form) { +noinstrument void _log_errno(const char *file, int line, const char *form) { flogf(kLogWarn, file, line, NULL, PFLINK("%s → %s"), form, strerror(errno)); } diff --git a/libc/log/meminfo.c b/libc/log/meminfo.c index 253987c21..587e6eee8 100644 --- a/libc/log/meminfo.c +++ b/libc/log/meminfo.c @@ -30,8 +30,8 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) { /** * Prints memory mappings. */ -void meminfo(int fd) { - memsummary(fd); +void _meminfo(int fd) { + _memsummary(fd); (dprintf)(fd, "%*s %*s %*s %*s\n", POINTER_XDIGITS, "start", POINTER_XDIGITS, "end", 8, "used", 8, "size"); malloc_inspect_all(onmemchunk, &fd); diff --git a/libc/log/memlog.c b/libc/log/memlog.c index 78148f317..1b8dfb4d2 100644 --- a/libc/log/memlog.c +++ b/libc/log/memlog.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/intrin/atomic.h" -#include "libc/intrin/weaken.h" #include "libc/intrin/kprintf.h" #include "libc/log/backtrace.internal.h" #include "libc/log/log.h" diff --git a/libc/log/memsummary.c b/libc/log/memsummary.c index 755719c99..133af514f 100644 --- a/libc/log/memsummary.c +++ b/libc/log/memsummary.c @@ -21,7 +21,7 @@ #include "libc/log/log.h" #include "libc/mem/mem.h" -void memsummary(int fd) { +void _memsummary(int fd) { struct mallinfo mi; mi = mallinfo(); (dprintf)(fd, diff --git a/libc/log/oncrash.c b/libc/log/oncrash.c index 5f722b23d..733770b1a 100644 --- a/libc/log/oncrash.c +++ b/libc/log/oncrash.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/utsname.h" #include "libc/calls/syscall-sysv.internal.h" @@ -28,6 +27,7 @@ #include "libc/intrin/kprintf.h" #include "libc/intrin/lockcmpxchg.h" #include "libc/intrin/lockcmpxchgp.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/log/gdb.h" @@ -35,11 +35,11 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/stackframe.h" -#include "libc/thread/tls.h" #include "libc/runtime/internal.h" #include "libc/runtime/pc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" +#include "libc/thread/tls.h" /** * @fileoverview Abnormal termination handling & GUI debugging. @@ -199,7 +199,7 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si, char host[64]; struct utsname names; static char buf[4096]; - if (weaken(ShowCrashReportHook)) { + if (_weaken(ShowCrashReportHook)) { ShowCrashReportHook(2, err, sig, si, ctx); } names.sysname[0] = 0; @@ -258,8 +258,7 @@ static wontreturn relegated noinstrument void __minicrash(int sig, kind, sig, __argv[0], ctx ? ctx->uc_mcontext.rip : 0, ctx ? ctx->uc_mcontext.rsp : 0, ctx ? ctx->uc_mcontext.rbp : 0, __pid, sys_gettid()); - __restorewintty(); - _Exit(119); + _Exitr(119); } /** @@ -309,8 +308,7 @@ relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) { if (!(gdbpid > 0 && (sig == SIGTRAP || sig == SIGQUIT))) { __restore_tty(); ShowCrashReport(err, sig, si, ctx); - __restorewintty(); - _Exit(128 + sig); + _Exitr(128 + sig); } sync = 0; } else { diff --git a/libc/log/onkill.c b/libc/log/onkill.c deleted file mode 100644 index 3959bf273..000000000 --- a/libc/log/onkill.c +++ /dev/null @@ -1,65 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/calls/struct/sigaction.h" -#include "libc/calls/struct/siginfo.h" -#include "libc/calls/ucontext.h" -#include "libc/dce.h" -#include "libc/intrin/bits.h" -#include "libc/log/log.h" -#include "libc/macros.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/sa.h" -#include "libc/sysv/consts/sig.h" - -/** - * @fileoverview Default handlers for normal termination signals. - * @note This gets linked when __cxa_atexit() is linked. - * @see also libc/oncrash.c - */ - -static const int sigs[] = { - SIGHUP, /* hangup aka ctrl_close_event */ - SIGINT, /* ctrl+c aka ^C aka ETX aka \003 aka ♥ */ - SIGTERM /* kill (default signal) */ -}; - -textexit static void __onkill(int sig, struct siginfo *si, void *context) { - /* https://www.tldp.org/LDP/abs/html/exitcodes.html */ - exit(128 + sig); - unreachable; -} - -/** - * Installs default handlers for friendly kill signals. - * @see ShowCrashReports() - */ -void callexitontermination(sigset_t *opt_out_exitsigs) { - struct sigaction sa; - if (opt_out_exitsigs) sigemptyset(opt_out_exitsigs); - bzero(&sa, sizeof(sa)); - sa.sa_sigaction = __onkill; - sa.sa_flags = SA_RESETHAND; - for (unsigned i = 0; i < ARRAYLEN(sigs); ++i) { - if (!sigs[i]) continue; - if (opt_out_exitsigs) sigaddset(opt_out_exitsigs, sigs[i]); - sigaction(sigs[i], &sa, NULL); - } -} diff --git a/libc/log/printgarbage.c b/libc/log/printgarbage.c index c14d51f51..2cb426c3b 100644 --- a/libc/log/printgarbage.c +++ b/libc/log/printgarbage.c @@ -38,7 +38,7 @@ void PrintGarbage(void) { kprintf("------------ ------------ ------------------ ------------------ ------------------\n"); if ((g = __tls_enabled ? __get_tls()->tib_garbages:0) && g->i) { for (i = g->i; i--;) { - symbol = __get_symbol_by_addr(g->p[i].ret); + symbol = GetSymbolByAddr(g->p[i].ret); if (symbol) { ksnprintf(name, sizeof(name), "%s", symbol); } else { @@ -48,7 +48,7 @@ void PrintGarbage(void) { g->p + i, g->p[i].frame, name, - __get_symbol_by_addr(g->p[i].fn), + GetSymbolByAddr(g->p[i].fn), g->p[i].arg); } } else { diff --git a/libc/log/showcrashreports.c b/libc/log/showcrashreports.c index 66615ef89..1723dbb80 100644 --- a/libc/log/showcrashreports.c +++ b/libc/log/showcrashreports.c @@ -37,7 +37,7 @@ STATIC_YOINK("ShowBacktrace"); // for backtracing STATIC_YOINK("GetSymbolTable"); // for backtracing STATIC_YOINK("PrintBacktraceUsingSymbols"); // for backtracing STATIC_YOINK("malloc_inspect_all"); // for asan memory origin -STATIC_YOINK("__get_symbol_by_addr"); // for asan memory origin +STATIC_YOINK("GetSymbolByAddr"); // for asan memory origin extern const unsigned char __oncrash_thunks[8][11]; static struct sigaltstack g_oldsigaltstack; @@ -99,8 +99,6 @@ static void FreeSigAltStack(void *p) { * Another trick this function enables, is you can press CTRL+\ to open * the debugger GUI at any point while the program is running. It can be * useful, for example, if a program is caught in an infinite loop. - * - * @see callexitontermination() */ void ShowCrashReports(void) { char *sp; diff --git a/libc/log/vflogf.c b/libc/log/vflogf.c index 627889fa4..f2763ae93 100644 --- a/libc/log/vflogf.c +++ b/libc/log/vflogf.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/dprintf.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" diff --git a/libc/macros.internal.h b/libc/macros.internal.h index 9c5099dc8..c32950397 100644 --- a/libc/macros.internal.h +++ b/libc/macros.internal.h @@ -247,7 +247,7 @@ .macro .optfn fn:req .globl "\fn" .weak "\fn" - .equ "\fn",missingno + .equ "\fn",_missingno .type "\fn",@function .endm diff --git a/libc/mem/_gc_free.c b/libc/mem/_gc_free.c index b1679f0ad..2eb6f7402 100644 --- a/libc/mem/_gc_free.c +++ b/libc/mem/_gc_free.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" void _gc_free(void *p) { free(p); diff --git a/libc/mem/alg.h b/libc/mem/alg.h index 9bea7135e..352ffb80c 100644 --- a/libc/mem/alg.h +++ b/libc/mem/alg.h @@ -26,32 +26,13 @@ int heapsort_r(void *, size_t, size_t, int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); int mergesort_r(void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); -int tarjan(int, const int (*)[2], int, int[], int[], int *) +int _tarjan(int, const int (*)[2], int, int[], int[], int *) paramsnonnull((2, 4)) nocallback dontthrow; #define __algalloc returnspointerwithnoaliases dontthrow nocallback dontdiscard -char *replacestr(const char *, const char *, const char *) +char *_replacestr(const char *, const char *, const char *) paramsnonnull() __algalloc; -char16_t *replacestr16(const char16_t *, const char16_t *, const char16_t *) - paramsnonnull() __algalloc; -wchar_t *replacewcs(const wchar_t *, const wchar_t *, const wchar_t *) - paramsnonnull() __algalloc; - -char *concatstr(const char *, ...) nullterminated() paramsnonnull() __algalloc; -char16_t *concatstr16(const char16_t *, ...) nullterminated() - paramsnonnull() __algalloc; -wchar_t *concatwcs(const wchar_t *, ...) nullterminated() - paramsnonnull() __algalloc; - -int cmpsb(const void *, const void *); -int cmpub(const void *, const void *); -int cmpsw(const void *, const void *); -int cmpuw(const void *, const void *); -int cmpsl(const void *, const void *); -int cmpul(const void *, const void *); -int cmpsq(const void *, const void *); -int cmpuq(const void *, const void *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/mem/arena.c b/libc/mem/arena.c index 198c09014..bc2c9c14e 100644 --- a/libc/mem/arena.c +++ b/libc/mem/arena.c @@ -19,6 +19,8 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/dce.h" +#include "libc/intrin/bsf.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/likely.h" #include "libc/intrin/weaken.h" #include "libc/limits.h" @@ -26,8 +28,6 @@ #include "libc/macros.internal.h" #include "libc/mem/arena.h" #include "libc/mem/hook/hook.internal.h" -#include "libc/nexgen32e/bsf.h" -#include "libc/nexgen32e/bsr.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -39,7 +39,7 @@ #define SIZE 0x2ff80000 #define P(i) ((void *)(intptr_t)(i)) #define EXCHANGE(HOOK, SLOT) \ - __arena_hook((intptr_t *)weaken(HOOK), (intptr_t *)(&(SLOT))) + __arena_hook((intptr_t *)_weaken(HOOK), (intptr_t *)(&(SLOT))) static struct Arena { bool once; @@ -58,7 +58,7 @@ static struct Arena { } __arena; static wontreturn void __arena_die(void) { - if (weaken(__die)) weaken(__die)(); + if (_weaken(__die)) _weaken(__die)(); _exit(83); } @@ -120,8 +120,8 @@ static dontinline bool __arena_grow(size_t offset, size_t request) { } else { enomem(); } - if (weaken(__oom_hook)) { - weaken(__oom_hook)(request); + if (_weaken(__oom_hook)) { + _weaken(__oom_hook)(request); } return false; } @@ -165,7 +165,7 @@ static void *__arena_memalign(size_t a, size_t n) { if (a <= sizeof(size_t)) { return __arena_alloc(8, n); } else { - return __arena_alloc(2ul << bsrl(a - 1), n); + return __arena_alloc(2ul << _bsrl(a - 1), n); } } @@ -190,7 +190,7 @@ static void *__arena_realloc(void *p, size_t n) { if ((m = __arena_get_size(p)) >= n) { return p; } else if (n <= SIZE) { - z = 2ul << bsrl(n - 1); + z = 2ul << _bsrl(n - 1); if (__arena.offset[__arena.depth] - m == (o = (intptr_t)p - BASE)) { if (UNLIKELY(o + z > __arena.size)) { if (o + z <= SIZE) { @@ -205,7 +205,7 @@ static void *__arena_realloc(void *p, size_t n) { __arena.offset[__arena.depth] = o + z; *(size_t *)((char *)p - sizeof(size_t)) = z; return p; - } else if ((q = __arena_alloc(1ul << bsfl((intptr_t)p), z))) { + } else if ((q = __arena_alloc(1ul << _bsfl((intptr_t)p), z))) { memmove(q, p, m); return q; } else { @@ -225,7 +225,7 @@ static void *__arena_realloc(void *p, size_t n) { if (n <= 16) { n = 16; } else { - n = 2ul << bsrl(n - 1); + n = 2ul << _bsrl(n - 1); } return __arena_alloc(16, n); } diff --git a/libc/mem/balloc.c b/libc/mem/balloc.c index 1f2894e72..fe47c18e1 100644 --- a/libc/mem/balloc.c +++ b/libc/mem/balloc.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/buffer.h" +#include "libc/runtime/buffer.internal.h" /* TODO(jart): delete */ diff --git a/libc/mem/bfree.c b/libc/mem/bfree.c index d6c5be385..e16a7e950 100644 --- a/libc/mem/bfree.c +++ b/libc/mem/bfree.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/buffer.h" +#include "libc/runtime/buffer.internal.h" /** * Frees memory return by balloc(). diff --git a/libc/runtime/gc.h b/libc/mem/gc.h similarity index 87% rename from libc/runtime/gc.h rename to libc/mem/gc.h index 03c733fad..a25317585 100644 --- a/libc/runtime/gc.h +++ b/libc/mem/gc.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_GC_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_GC_H_ +#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_ +#define COSMOPOLITAN_LIBC_MEM_GC_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -24,4 +24,4 @@ void _gc_free(void *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_GC_H_ */ +#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */ diff --git a/libc/runtime/gc.internal.h b/libc/mem/gc.internal.h similarity index 54% rename from libc/runtime/gc.internal.h rename to libc/mem/gc.internal.h index fb4a7ce92..ef7d6ee6d 100644 --- a/libc/runtime/gc.internal.h +++ b/libc/mem/gc.internal.h @@ -1,6 +1,6 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_GC_INTERNAL_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_GC_INTERNAL_H_ -#include "libc/runtime/gc.h" +#ifndef COSMOPOLITAN_LIBC_MEM_GC_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_MEM_GC_INTERNAL_H_ +#include "libc/mem/gc.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) #define gc(THING) _gc(THING) @@ -8,4 +8,4 @@ #define gclongjmp(JB, ARG) _gclongjmp(JB, ARG) #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_GC_INTERNAL_H_ */ +#endif /* COSMOPOLITAN_LIBC_MEM_GC_INTERNAL_H_ */ diff --git a/libc/mem/putenv.c b/libc/mem/putenv.c index c711bbf7b..561adae93 100644 --- a/libc/mem/putenv.c +++ b/libc/mem/putenv.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/mem/alg.h" diff --git a/libc/mem/replacestr.c b/libc/mem/replacestr.c index 6a9881cb1..1512cdf59 100644 --- a/libc/mem/replacestr.c +++ b/libc/mem/replacestr.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" -#include "libc/mem/arraylist2.internal.h" #include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" @@ -30,7 +30,7 @@ * @return newly allocated memory that must be free()'d or NULL w/ errno * @error ENOMEM, EINVAL */ -char *replacestr(const char *s, const char *needle, const char *replacement) { +char *_replacestr(const char *s, const char *needle, const char *replacement) { char *p1, *p2, *res_p; size_t left, nlen, rlen, res_i, res_n; if (*needle) { diff --git a/libc/mem/setenv.c b/libc/mem/setenv.c index bb9c33cdc..b0de20855 100644 --- a/libc/mem/setenv.c +++ b/libc/mem/setenv.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/mem/internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" diff --git a/libc/mem/tarjan.c b/libc/mem/tarjan.c index 9d27ed213..2ec19588e 100644 --- a/libc/mem/tarjan.c +++ b/libc/mem/tarjan.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/assert.h" #include "libc/limits.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" #include "libc/mem/mem.h" /** @@ -130,9 +130,9 @@ static bool TarjanConnect(struct Tarjan *t, int v) { * @error ENOMEM * @note Tarjan's Algorithm is O(|V|+|E|) */ -int tarjan(int vertex_count, const int (*edges)[2], int edge_count, - int out_sorted[], int out_opt_components[], - int *out_opt_componentcount) { +int _tarjan(int vertex_count, const int (*edges)[2], int edge_count, + int out_sorted[], int out_opt_components[], + int *out_opt_componentcount) { int i, rc, v, e; struct Tarjan *t; assert(0 <= edge_count && edge_count <= INT_MAX); diff --git a/libc/nexgen32e/cachesize.h b/libc/nexgen32e/cachesize.h index 3f028c63c..e4e9dea6c 100644 --- a/libc/nexgen32e/cachesize.h +++ b/libc/nexgen32e/cachesize.h @@ -8,7 +8,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -unsigned getcachesize(int, int); +unsigned _getcachesize(int, int); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/nexgen32e/cescapec.S b/libc/nexgen32e/cescapec.S index 83eea6c53..c5409835b 100644 --- a/libc/nexgen32e/cescapec.S +++ b/libc/nexgen32e/cescapec.S @@ -26,7 +26,7 @@ // // @param dil contains byte to escape // @see libc/nexgen32e/cescapec.c -cescapec: +_cescapec: .leafprologue .profilable movzbl %dil,%edi @@ -35,7 +35,7 @@ cescapec: ja 1f mov $'\\',%eax movzbl %cl,%ecx - jmp *cescapectab(,%rcx,8) + jmp *_cescapectab(,%rcx,8) .Lanchorpoint: .LBEL: mov $'a',%ah .leafepilogue @@ -78,10 +78,10 @@ cescapec: lea (%rdi,%rax,4),%eax add $'0'<<030|'0'<<020|'0'<<010|'\\',%eax .leafepilogue - .endfn cescapec,globl + .endfn _cescapec,globl .initro 300,_init_cescapec -cescapectab.ro: +_cescapectab.ro: .byte 1,.LBEL-.Lanchorpoint .byte 1,.LBS-.Lanchorpoint .byte 1,.LHT-.Lanchorpoint @@ -97,22 +97,22 @@ cescapectab.ro: .byte 1,.LQM-.Lanchorpoint .byte '\\'-'?'-1,1b-.Lanchorpoint .byte 1,.LBSL-.Lanchorpoint - .equ .Lcescapectab.ro.size,.-cescapectab.ro - .org 8 - .Lcescapectab.ro.size % 8 + . - .endobj cescapectab.ro,globl,hidden + .equ .L_cescapectab.ro.size,.-_cescapectab.ro + .org 8 - .L_cescapectab.ro.size % 8 + . + .endobj _cescapectab.ro,globl,hidden .previous .initbss 300,_init_cescapec -cescapectab: +_cescapectab: .rept '\\'-7+1 .quad 0 .endr - .endobj cescapectab + .endobj _cescapectab .previous .init.start 300,_init_cescapec ezlea .Lanchorpoint,dx - mov $.Lcescapectab.ro.size/2,%ch + mov $.L_cescapectab.ro.size/2,%ch 0: xor %eax,%eax lodsb mov %al,%cl @@ -123,7 +123,7 @@ cescapectab: jnz 1b dec %ch jnz 0b - .if .Lcescapectab.ro.size % 8 - add $(8-.Lcescapectab.ro.size%8),%rsi + .if .L_cescapectab.ro.size % 8 + add $(8-.L_cescapectab.ro.size%8),%rsi .endif .init.end 300,_init_cescapec diff --git a/libc/nexgen32e/cmpsb.S b/libc/nexgen32e/cmpsb.S deleted file mode 100644 index 48f649197..000000000 --- a/libc/nexgen32e/cmpsb.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 8-bit signed integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpsb: .leafprologue - .profilable - xor %eax,%eax - cmpsb - cmovl .Lone(%rip),%eax - cmovg .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpsb,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpsl.S b/libc/nexgen32e/cmpsl.S deleted file mode 100644 index 400160c21..000000000 --- a/libc/nexgen32e/cmpsl.S +++ /dev/null @@ -1,44 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 32-bit signed integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpsl: .leafprologue - .profilable - xor %eax,%eax - cmpsl -// mov (%rdi),%edi -// mov (%rsi),%esi -// cmp %edi,%esi - setl %al - cmovg .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpsl,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpsq.S b/libc/nexgen32e/cmpsq.S deleted file mode 100644 index 535a3fd75..000000000 --- a/libc/nexgen32e/cmpsq.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 64-bit signed integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpsq: .leafprologue - .profilable - xor %eax,%eax - cmpsq - cmovl .Lone(%rip),%eax - cmovg .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpsq,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpsw.S b/libc/nexgen32e/cmpsw.S deleted file mode 100644 index 59930f6dd..000000000 --- a/libc/nexgen32e/cmpsw.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 16-bit signed integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpsw: .leafprologue - .profilable - xor %eax,%eax - cmpsw - cmovl .Lone(%rip),%eax - cmovg .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpsw,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpub.S b/libc/nexgen32e/cmpub.S deleted file mode 100644 index e3b1a5aab..000000000 --- a/libc/nexgen32e/cmpub.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 8-bit unsigned integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpub: .leafprologue - .profilable - xor %eax,%eax - cmpsb - cmovb .Lone(%rip),%eax - cmova .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpub,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpul.S b/libc/nexgen32e/cmpul.S deleted file mode 100644 index 83a142fc3..000000000 --- a/libc/nexgen32e/cmpul.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 32-bit unsigned integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpul: .leafprologue - .profilable - xor %eax,%eax - cmpsl - cmovb .Lone(%rip),%eax - cmova .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpul,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpuq.S b/libc/nexgen32e/cmpuq.S deleted file mode 100644 index 297330e37..000000000 --- a/libc/nexgen32e/cmpuq.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 64-bit unsigned integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpuq: .leafprologue - .profilable - xor %eax,%eax - cmpsq - cmovb .Lone(%rip),%eax - cmova .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpuq,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/cmpuw.S b/libc/nexgen32e/cmpuw.S deleted file mode 100644 index 80e529ae2..000000000 --- a/libc/nexgen32e/cmpuw.S +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Compares 16-bit unsigned integers. -// -// @param rdi points to left integer -// @param rsi points to right integer -// @return <0, 0, or >0 based on comparison - .align 16 -cmpuw: .leafprologue - .profilable - xor %eax,%eax - cmpsw - cmovb .Lone(%rip),%eax - cmova .Lneg1(%rip),%eax - .leafepilogue - .endfn cmpuw,globl - - .rodata.cst4 -.Lone: .long 1 - .endobj .Lone -.Lneg1: .long -1 - .endobj .Lneg1 - .previous diff --git a/libc/nexgen32e/gc.internal.h b/libc/nexgen32e/gc.internal.h index b0adc7ac7..0bae234ed 100644 --- a/libc/nexgen32e/gc.internal.h +++ b/libc/nexgen32e/gc.internal.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_ -#define COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_ +#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_GC_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_NEXGEN32E_GC_INTERNAL_H_ #include "libc/nexgen32e/stackframe.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -20,4 +20,4 @@ int64_t __gc(void); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_ */ +#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_GC_INTERNAL_H_ */ diff --git a/libc/nexgen32e/kcrc32ctab.S b/libc/nexgen32e/kcrc32ctab.S index f621f94f0..b86c4d02f 100644 --- a/libc/nexgen32e/kcrc32ctab.S +++ b/libc/nexgen32e/kcrc32ctab.S @@ -21,7 +21,7 @@ // Castagnoli CRC32 ISCSI Polynomial // x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1 // 0b00011110110111000110111101000001 -// bitreverse32(0x1edc6f41) +// _bitreverse32(0x1edc6f41) #define ISCSI_POLYNOMIAL 0x82f63b78 .initbss 300,_init_kCrc32cTab diff --git a/libc/nexgen32e/missingno.S b/libc/nexgen32e/missingno.S index 03c196edb..6d9d7c449 100644 --- a/libc/nexgen32e/missingno.S +++ b/libc/nexgen32e/missingno.S @@ -21,7 +21,7 @@ .code16 # ∩ .code32 ∩ .code64 // Optional function stub. -missingno: +_missingno: xor %ax,%ax ret - .endfn missingno,globl,hidden + .endfn _missingno,globl,hidden diff --git a/libc/nt/ntdllimport.S b/libc/nt/ntdllimport.S index b0572aa7c..3cc90e5fb 100644 --- a/libc/nt/ntdllimport.S +++ b/libc/nt/ntdllimport.S @@ -39,7 +39,7 @@ kNtdllProcRvas: .init.start 202,_init_ntdll push %r12 push %r13 - lea ntdllmissingno(%rip),%r13 + lea _ntdllmissingno(%rip),%r13 sub $32,%rsp loadstr "ntdll.dll",cx call *__imp_GetModuleHandleA(%rip) @@ -61,7 +61,7 @@ kNtdllProcRvas: .init.end 202,_init_ntdll,globl,hidden .text.windows -ntdllmissingno: +_ntdllmissingno: mov $kNtStatusDllNotFound,%eax ret .previous diff --git a/libc/runtime/arch_prctl.c b/libc/runtime/arch_prctl.c index abad88f08..a5710ea26 100644 --- a/libc/runtime/arch_prctl.c +++ b/libc/runtime/arch_prctl.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/runtime/buffer.h b/libc/runtime/buffer.internal.h similarity index 61% rename from libc/runtime/buffer.h rename to libc/runtime/buffer.internal.h index c81dde25a..929d2050a 100644 --- a/libc/runtime/buffer.h +++ b/libc/runtime/buffer.internal.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_BUFFER_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_BUFFER_H_ +#ifndef COSMOPOLITAN_LIBC_RUNTIME_BUFFER_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_RUNTIME_BUFFER_INTERNAL_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -12,4 +12,4 @@ void bfree(struct GuardedBuffer *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_BUFFER_H_ */ +#endif /* COSMOPOLITAN_LIBC_RUNTIME_BUFFER_INTERNAL_H_ */ diff --git a/libc/runtime/clearenv.c b/libc/runtime/clearenv.c index c37f1fb53..59eedfbc5 100644 --- a/libc/runtime/clearenv.c +++ b/libc/runtime/clearenv.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/runtime/runtime.h" /** diff --git a/libc/runtime/clktck.c b/libc/runtime/clktck.c index 80d7580fc..10f86459a 100644 --- a/libc/runtime/clktck.c +++ b/libc/runtime/clktck.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/_getauxval.internal.h" +#include "libc/intrin/_getauxval.internal.h" #include "libc/calls/calls.h" #include "libc/dce.h" #include "libc/fmt/conv.h" diff --git a/libc/thread/clone-linux.S b/libc/runtime/clone-linux.S similarity index 100% rename from libc/thread/clone-linux.S rename to libc/runtime/clone-linux.S diff --git a/libc/thread/clone-nt.S b/libc/runtime/clone-nt.S similarity index 100% rename from libc/thread/clone-nt.S rename to libc/runtime/clone-nt.S diff --git a/libc/thread/clone-openbsd.S b/libc/runtime/clone-openbsd.S similarity index 100% rename from libc/thread/clone-openbsd.S rename to libc/runtime/clone-openbsd.S diff --git a/libc/thread/clone.c b/libc/runtime/clone.c similarity index 96% rename from libc/thread/clone.c rename to libc/runtime/clone.c index d9e1241f4..ad225caeb 100644 --- a/libc/thread/clone.c +++ b/libc/runtime/clone.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/ucontext-netbsd.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" @@ -28,6 +28,7 @@ #include "libc/nt/runtime.h" #include "libc/nt/thread.h" #include "libc/nt/thunk/msabi.h" +#include "libc/runtime/clone.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/stdalign.internal.h" @@ -481,7 +482,26 @@ static int CloneLinux(int (*func)(void *arg, int tid), char *stk, size_t stksz, // COSMOPOLITAN /** - * Creates thread. + * Creates thread without malloc being linked, e.g. + * + * int worker(void *arg) { + * return 0; + * } + * + * struct CosmoTib tib = { + * .tib_self = &tib, + * .tib_self2 = &tib, + * .tib_tid = -1, + * }; + * char *stk = _mapstack(); + * tid = clone(worker, stk, GetStackSize() - 16, + * CLONE_VM | CLONE_THREAD | CLONE_FS | CLONE_FILES | + * CLONE_SIGHAND | CLONE_CHILD_SETTID | + * CLONE_CHILD_CLEARTID | CLONE_SETTLS, + * arg, 0, &tib, &tib.tib_tid); + * // ... + * while (atomic_load(&tib.tib_tid)) sched_yield(); + * _freestack(stk); * * Threads are created in a detached manner. They currently can't be * synchronized using wait() or posix signals. Threads created by this @@ -567,7 +587,7 @@ static int CloneLinux(int (*func)(void *arg, int tid), char *stk, size_t stksz, * @threadsafe */ int clone(void *func, void *stk, size_t stksz, int flags, void *arg, int *ptid, - void *tls, int *ctid) { + void *tls, void *ctid) { int rc; struct CloneArgs *wt; @@ -582,11 +602,10 @@ int clone(void *func, void *stk, size_t stksz, int flags, void *arg, int *ptid, rc = einval(); } else if (IsAsan() && (((flags & CLONE_SETTLS) && !__asan_is_valid(tls, 64)) || - ((flags & CLONE_SETTLS) && !__asan_is_valid(tls, sizeof(long))) || ((flags & CLONE_PARENT_SETTID) && !__asan_is_valid(ptid, sizeof(*ptid))) || ((flags & CLONE_CHILD_SETTID) && - !__asan_is_valid(ctid, sizeof(*ctid))))) { + !__asan_is_valid(ctid, sizeof(int))))) { rc = efault(); } else if (IsLinux()) { rc = CloneLinux(func, stk, stksz, flags, arg, tls, ptid, ctid); diff --git a/libc/runtime/clone.internal.h b/libc/runtime/clone.internal.h new file mode 100644 index 000000000..e1a9142c6 --- /dev/null +++ b/libc/runtime/clone.internal.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_LIBC_RUNTIME_CLONE_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_RUNTIME_CLONE_INTERNAL_H_ +#include "libc/atomic.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int clone(void *, void *, size_t, int, void *, int *, void *, void *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_RUNTIME_CLONE_INTERNAL_H_ */ diff --git a/libc/runtime/cosmo.S b/libc/runtime/cosmo.S index b0f416719..1b6f67739 100644 --- a/libc/runtime/cosmo.S +++ b/libc/runtime/cosmo.S @@ -20,7 +20,7 @@ #include "libc/notice.inc" #include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/map.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/map.h" #include "libc/dce.h" .text.startup diff --git a/libc/runtime/enable_threads.c b/libc/runtime/enable_threads.c index 47a17ee3c..40987b4c3 100644 --- a/libc/runtime/enable_threads.c +++ b/libc/runtime/enable_threads.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/thread/tls.h" #include "libc/runtime/runtime.h" diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index 88b6d6e53..24b40f39c 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -111,9 +111,9 @@ privileged void __enable_tls(void) { // malloc() being linked, which links _mapanon(). otherwise // if you exceed this, you need to STATIC_YOINK("_mapanon"). // please note that it's probably too early to call calloc() - assert(weaken(_mapanon)); + assert(_weaken(_mapanon)); siz = ROUNDUP(siz, FRAMESIZE); - mem = weaken(_mapanon)(siz); + mem = _weaken(_mapanon)(siz); assert(mem); } if (IsAsan()) { diff --git a/libc/runtime/exit.c b/libc/runtime/exit.c index 8eeb5968b..6b4ded62c 100644 --- a/libc/runtime/exit.c +++ b/libc/runtime/exit.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" -#include "libc/calls/strace.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" @@ -35,12 +35,11 @@ wontreturn void exit(int exitcode) { const uintptr_t *p; STRACE("exit(%d)", exitcode); - if (weaken(__cxa_finalize)) { - weaken(__cxa_finalize)(NULL); + if (_weaken(__cxa_finalize)) { + _weaken(__cxa_finalize)(NULL); } for (p = __fini_array_end; p > __fini_array_start;) { ((void (*)(void))(*--p))(); } - __restorewintty(); - _Exit(exitcode); + _Exitr(exitcode); } diff --git a/libc/runtime/fork-nt.c b/libc/runtime/fork-nt.c index 73ebcb2e6..bdc6e5cc1 100644 --- a/libc/runtime/fork-nt.c +++ b/libc/runtime/fork-nt.c @@ -19,17 +19,16 @@ #include "libc/calls/internal.h" #include "libc/calls/ntspawn.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/wincrash.internal.h" #include "libc/fmt/itoa.h" #include "libc/intrin/kprintf.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/mem/alloca.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/nt2sysv.h" -#include "libc/thread/tls.h" #include "libc/nt/console.h" #include "libc/nt/createfile.h" #include "libc/nt/enum/accessmask.h" @@ -53,6 +52,7 @@ #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" +#include "libc/thread/tls.h" STATIC_YOINK("_check_sigchld"); @@ -243,14 +243,14 @@ textwindows void WinMainForked(void) { #ifdef SYSDEBUG RemoveVectoredExceptionHandler(oncrash); #endif - if (weaken(__wincrash_nt)) { + if (_weaken(__wincrash_nt)) { if (!IsTiny()) { RemoveVectoredExceptionHandler(__wincrashearly); } - AddVectoredExceptionHandler(1, (void *)weaken(__wincrash_nt)); + AddVectoredExceptionHandler(1, (void *)_weaken(__wincrash_nt)); } - if (weaken(__onntconsoleevent_nt)) { - SetConsoleCtrlHandler(weaken(__onntconsoleevent_nt), 1); + if (_weaken(__onntconsoleevent_nt)) { + SetConsoleCtrlHandler(_weaken(__onntconsoleevent_nt), 1); } // jump back into function below diff --git a/libc/runtime/fork.c b/libc/runtime/fork.c index 1d50b3fc1..91567fd36 100644 --- a/libc/runtime/fork.c +++ b/libc/runtime/fork.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" diff --git a/libc/runtime/getdosargv.c b/libc/runtime/getdosargv.c index a8aaf78d0..1a890ad44 100644 --- a/libc/runtime/getdosargv.c +++ b/libc/runtime/getdosargv.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/nt/thunk/msabi.h" #include "libc/runtime/internal.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" struct DosArgv { @@ -49,7 +49,7 @@ textwindows noasan void DecodeDosArgv(int ignore, struct DosArgv *st) { static textwindows noasan void AppendDosArgv(wint_t wc, struct DosArgv *st) { uint64_t w; - w = tpenc(wc); + w = _tpenc(wc); do { if (st->p >= st->pe) break; *st->p++ = w & 0xff; diff --git a/libc/runtime/getdosenviron.c b/libc/runtime/getdosenviron.c index 3c0a07271..27339a31a 100644 --- a/libc/runtime/getdosenviron.c +++ b/libc/runtime/getdosenviron.c @@ -17,9 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" +#include "libc/intrin/tpenc.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #define ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c)) @@ -57,7 +57,7 @@ static textwindows noasan noinstrument axdx_t Recode16to8(char *dst, x = ToUpper(x); } } - w = tpenc(x); + w = _tpenc(x); do { if (r.ax + 1 < dstsize) { dst[r.ax++] = w; diff --git a/libc/runtime/getinstructionlengths.c b/libc/runtime/getinstructionlengths.c deleted file mode 100644 index 73b57d8a3..000000000 --- a/libc/runtime/getinstructionlengths.c +++ /dev/null @@ -1,59 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2022 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/macros.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/prot.h" -#include "third_party/xed/x86.h" - -/** - * Returns lengths of x86 ops in binary. - * - * The first decoded instruction is at `_ereal`. Lengths can be 1 to 15 - * bytes. Each byte in the return value is in that range, and the array - * is NUL terminated. The returned memory is memoized, since this costs - * some time. For example, for a 10mb Python binary, it takes 20 millis - * so the basic idea is is you can use this output multiple times which - * is a faster way to iterate over the binary than calling Xed. - * - * @return nul-terminated length array on success, or null - */ -privileged unsigned char *GetInstructionLengths(void) { - static bool once; - int i, n, err, len, rem; - static unsigned char *res; - struct XedDecodedInst xedd; - unsigned char *p, *mem, *code; - if (!once) { - if ((mem = mmap(0, ROUNDUP(__privileged_addr - _ereal + 1, FRAMESIZE), - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, - 0)) != MAP_FAILED) { - for (p = mem, code = _ereal; code < __privileged_addr; code += len) { - rem = __privileged_addr - code; - xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64); - err = xed_instruction_length_decode(&xedd, code, rem); - *p++ = len = !err ? xedd.length : 1; - } - res = mem; - } - once = true; - } - return res; -} diff --git a/libc/runtime/getsymboltable.c b/libc/runtime/getsymboltable.c index 44c897b14..99b334699 100644 --- a/libc/runtime/getsymboltable.c +++ b/libc/runtime/getsymboltable.c @@ -17,16 +17,16 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/calls/strace.internal.h" #include "libc/intrin/bits.h" #include "libc/intrin/promises.internal.h" -#include "libc/thread/thread.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" +#include "libc/thread/thread.h" #include "libc/x/x.h" #include "libc/zip.h" #include "libc/zipos/zipos.internal.h" @@ -127,7 +127,7 @@ struct SymbolTable *GetSymbolTable(void) { struct Zipos *z; if (pthread_spin_trylock(&g_lock)) return 0; if (!__symtab && !__isworker) { - if (weaken(__zipos_get) && (z = weaken(__zipos_get)())) { + if (_weaken(__zipos_get) && (z = _weaken(__zipos_get)())) { if ((__symtab = GetSymbolTableFromZip(z))) { __symtab->names = (uint32_t *)((char *)__symtab + __symtab->names_offset); diff --git a/libc/runtime/grow.c b/libc/runtime/grow.c index 62e04b6c9..9dbe8e578 100644 --- a/libc/runtime/grow.c +++ b/libc/runtime/grow.c @@ -17,9 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "libc/fmt/conv.h" #include "libc/intrin/bits.h" #include "libc/intrin/weaken.h" -#include "libc/fmt/conv.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" @@ -50,7 +50,7 @@ bool __grow(void *pp, size_t *capacity, size_t itemsize, size_t extra) { n2 = (*p ? n1 + (n1 >> 1) : MAX(4, INITIAL_CAPACITY / itemsize)) + extra; if (!__builtin_mul_overflow(n1, itemsize, &t1) && !__builtin_mul_overflow(n2, itemsize, &t2)) { - if (weaken(realloc) && (p2 = weaken(realloc)(p1, ROUNDUP(t2, 32)))) { + if (_weaken(realloc) && (p2 = _weaken(realloc)(p1, ROUNDUP(t2, 32)))) { if (!p1 && *p) memcpy(p2, *p, t1); bzero((char *)p2 + t1, t2 - t1); *capacity = n2; diff --git a/libc/runtime/inflate.c b/libc/runtime/inflate.c index 70e23e143..09679dbdf 100644 --- a/libc/runtime/inflate.c +++ b/libc/runtime/inflate.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" -#include "libc/calls/strace.internal.h" #include "libc/macros.internal.h" #include "libc/runtime/runtime.h" #include "third_party/zlib/puff.h" @@ -35,7 +35,7 @@ int __inflate(void *out, size_t outsize, const void *in, size_t insize) { int rc; z_stream zs; - if (weaken(inflateInit2) && weaken(inflate) && weaken(inflateEnd)) { + if (_weaken(inflateInit2) && _weaken(inflate) && _weaken(inflateEnd)) { zs.next_in = in; zs.avail_in = insize; zs.total_in = insize; @@ -44,9 +44,9 @@ int __inflate(void *out, size_t outsize, const void *in, size_t insize) { zs.total_out = outsize; zs.zalloc = Z_NULL; zs.zfree = Z_NULL; - if ((rc = weaken(inflateInit2)(&zs, -MAX_WBITS)) == Z_OK && - (rc = weaken(inflate)(&zs, Z_FINISH)) == Z_STREAM_END && - (rc = weaken(inflateEnd)(&zs)) == Z_OK) { + if ((rc = _weaken(inflateInit2)(&zs, -MAX_WBITS)) == Z_OK && + (rc = _weaken(inflate)(&zs, Z_FINISH)) == Z_STREAM_END && + (rc = _weaken(inflateEnd)(&zs)) == Z_OK) { rc = 0; } else if (rc == Z_OK) { rc = Z_STREAM_END; // coerce to nonzero diff --git a/libc/runtime/mapanon.c b/libc/runtime/mapanon.c index 713729c98..3dafc301c 100644 --- a/libc/runtime/mapanon.c +++ b/libc/runtime/mapanon.c @@ -16,10 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" #include "libc/errno.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/weaken.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" @@ -63,8 +62,8 @@ void *_mapanon(size_t size) { if (m != MAP_FAILED) { return m; } - if (errno == ENOMEM && weaken(__oom_hook)) { - weaken(__oom_hook)(size); + if (errno == ENOMEM && _weaken(__oom_hook)) { + _weaken(__oom_hook)(size); } return 0; } diff --git a/libc/runtime/mapshared.c b/libc/runtime/mapshared.c index 1810ce294..c4e65fc5e 100644 --- a/libc/runtime/mapshared.c +++ b/libc/runtime/mapshared.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" #include "libc/errno.h" +#include "libc/intrin/weaken.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" @@ -34,8 +34,8 @@ void *_mapshared(size_t size) { if (m != MAP_FAILED) { return m; } - if (errno == ENOMEM && weaken(__oom_hook)) { - weaken(__oom_hook)(size); + if (errno == ENOMEM && _weaken(__oom_hook)) { + _weaken(__oom_hook)(size); } return 0; } diff --git a/libc/runtime/memtracknt.c b/libc/runtime/memtracknt.c index c1a9a6828..80c0d6175 100644 --- a/libc/runtime/memtracknt.c +++ b/libc/runtime/memtracknt.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/nt/memory.h" #include "libc/nt/runtime.h" #include "libc/runtime/memtrack.internal.h" diff --git a/libc/runtime/mmap.c b/libc/runtime/mmap.c index 71efc97da..86fe6d33b 100644 --- a/libc/runtime/mmap.c +++ b/libc/runtime/mmap.c @@ -19,7 +19,6 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" @@ -28,8 +27,8 @@ #include "libc/intrin/bits.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/likely.h" -#include "libc/thread/thread.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/limits.h" #include "libc/log/backtrace.internal.h" @@ -49,6 +48,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" #include "libc/sysv/errfuns.h" +#include "libc/thread/thread.h" #define MAP_ANONYMOUS_linux 0x00000020 #define MAP_ANONYMOUS_openbsd 0x00001000 @@ -64,10 +64,9 @@ #define FRAME(x) ((int)((intptr_t)(x) >> 16)) static wontreturn void OnUnrecoverableMmapError(const char *s) { - if (weaken(__die)) weaken(__die)(); + if (_weaken(__die)) _weaken(__die)(); STRACE("%s %m", s); - __restorewintty(); - _Exit(199); + _Exitr(199); } static noasan inline bool OverlapsExistingMapping(char *p, size_t n) { @@ -165,8 +164,8 @@ static noasan void *FinishMemory(void *addr, size_t size, int prot, int flags, } return MAP_FAILED; } - if (weaken(__asan_map_shadow) && !OverlapsShadowSpace(addr, size)) { - weaken(__asan_map_shadow)((intptr_t)addr, size); + if (_weaken(__asan_map_shadow) && !OverlapsShadowSpace(addr, size)) { + _weaken(__asan_map_shadow)((intptr_t)addr, size); } return addr; } @@ -227,8 +226,8 @@ static textwindows dontinline noasan void *MapMemories(char *addr, size_t size, OnUnrecoverableMmapError("MapMemories unrecoverable #2"); } } - if (weaken(__asan_map_shadow) && !OverlapsShadowSpace(addr, size)) { - weaken(__asan_map_shadow)((intptr_t)addr, size); + if (_weaken(__asan_map_shadow) && !OverlapsShadowSpace(addr, size)) { + _weaken(__asan_map_shadow)((intptr_t)addr, size); } return addr; } @@ -323,7 +322,7 @@ static noasan inline void *Mmap(void *addr, size_t size, int prot, int flags, return VIP(einval()); } - a = max(1, rounddown2pow(size) >> 16); + a = max(1, _rounddown2pow(size) >> 16); f = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; if (flags & MAP_FIXED) { diff --git a/libc/runtime/morph.greg.c b/libc/runtime/morph.greg.c index 24aa69724..d3a578009 100644 --- a/libc/runtime/morph.greg.c +++ b/libc/runtime/morph.greg.c @@ -19,7 +19,7 @@ #define ShouldUseMsabiAttribute() 1 #include "libc/assert.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sigset.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/runtime/mprotect.c b/libc/runtime/mprotect.c index 39dfe6c82..3cb97a01d 100644 --- a/libc/runtime/mprotect.c +++ b/libc/runtime/mprotect.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/runtime/mremap.c b/libc/runtime/mremap.c index 0617a36ef..4170291c0 100644 --- a/libc/runtime/mremap.c +++ b/libc/runtime/mremap.c @@ -17,13 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/likely.h" -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/likely.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/nt/runtime.h" #include "libc/runtime/directmap.internal.h" @@ -152,8 +152,8 @@ void *mremap(void *p, size_t n, size_t m, int f, ... /* void *q */) { if (TrackMemoryInterval(&_mmi, ((uintptr_t)p + n) >> 16, ((uintptr_t)p + m - FRAMESIZE) >> 16, dm.maphandle, prot, flags, false, false, 0, m - n) != -1) { - if (weaken(__asan_map_shadow)) { - weaken(__asan_map_shadow)((uintptr_t)dm.addr, m - n); + if (_weaken(__asan_map_shadow)) { + _weaken(__asan_map_shadow)((uintptr_t)dm.addr, m - n); } return p; } else { @@ -186,12 +186,12 @@ void *mremap(void *p, size_t n, size_t m, int f, ... /* void *q */) { ((uintptr_t)p + n - FRAMESIZE) >> 16, 0) != -1 && TrackMemoryInterval(&_mmi, a, b, -1, prot, flags, false, false, 0, m) != -1) { - if (weaken(__asan_poison)) { + if (_weaken(__asan_poison)) { if (!OverlapsShadowSpace(p, n)) { - weaken(__asan_poison)((intptr_t)p, n, kAsanUnmapped); + _weaken(__asan_poison)((intptr_t)p, n, kAsanUnmapped); } if (!OverlapsShadowSpace(q, m)) { - weaken(__asan_map_shadow)((intptr_t)q, m); + _weaken(__asan_map_shadow)((intptr_t)q, m); } } return (void *)ADDR(a); diff --git a/libc/runtime/msync.c b/libc/runtime/msync.c index 4547c4e97..71e75672c 100644 --- a/libc/runtime/msync.c +++ b/libc/runtime/msync.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" diff --git a/libc/runtime/munmap.c b/libc/runtime/munmap.c index 7e09080bc..a3f8d0b44 100644 --- a/libc/runtime/munmap.c +++ b/libc/runtime/munmap.c @@ -18,13 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/likely.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/backtrace.internal.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" diff --git a/libc/runtime/opensymboltable.greg.c b/libc/runtime/opensymboltable.greg.c index b0d6ffe73..6390bc5cc 100644 --- a/libc/runtime/opensymboltable.greg.c +++ b/libc/runtime/opensymboltable.greg.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/elf/def.h" #include "libc/elf/scalar.h" @@ -164,7 +164,7 @@ struct SymbolTable *OpenSymbolTable(const char *filename) { x = sym->st_value - t->addr_base; stp[m++] = (unsigned long)x << 32 | i; } - longsort(stp, m); + _longsort(stp, m); for (j = i = 0; i < m; ++i) { sym = symtab + (stp[i] & 0x7fffffff); x = stp[i] >> 32; diff --git a/libc/runtime/printargs.c b/libc/runtime/printargs.c index 4337437c1..532571a84 100644 --- a/libc/runtime/printargs.c +++ b/libc/runtime/printargs.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/rlimit.h" #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sigset.h" diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index 0b8c2e8da..a9ead05f3 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.h @@ -63,6 +63,7 @@ void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull(); void exit(int) wontreturn; void _exit(int) libcesque wontreturn; void _Exit(int) libcesque wontreturn; +void _Exitr(int) libcesque wontreturn; void _Exit1(int) libcesque wontreturn; void quick_exit(int) wontreturn; void abort(void) wontreturn; @@ -86,25 +87,22 @@ long gethostid(void); int sethostid(long); char *getlogin(void); int getlogin_r(char *, size_t); -int lchown(const char *, uint32_t, uint32_t); int getpagesize(void); int syncfs(int); int vhangup(void); int getdtablesize(void); int sethostname(const char *, size_t); int acct(const char *); -void longsort(long *, size_t); - +void _longsort(long *, size_t); bool _isheap(void *); int NtGetVersion(void) pureconst; -long missingno(); +long _missingno(); void __oom_hook(size_t); void _loadxmm(void *); void _peekall(void); void _savexmm(void *); void _weakfree(void *); void free_s(void *) paramsnonnull() libcesque; -int close_s(int *) paramsnonnull() libcesque; int OpenExecutable(void); int ftrace_install(void); long GetResourceLimit(int); @@ -116,13 +114,11 @@ void __paginate(int, const char *); int __arg_max(void); void __morph_begin(void); void __morph_end(void); -unsigned char *GetFirstInstruction(void); -unsigned char *GetInstructionLengths(void); void __print_maps(void); void __warn_if_powersave(void); const char *__describe_os(void); bool IsDynamicExecutable(const char *); -void __restorewintty(void); +void _restorewintty(void); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/runtime/stackchkfail.c b/libc/runtime/stackchkfail.c index 29caaeb51..32512169f 100644 --- a/libc/runtime/stackchkfail.c +++ b/libc/runtime/stackchkfail.c @@ -21,6 +21,5 @@ privileged noasan noinstrument void __stack_chk_fail(void) { kprintf("stack smashed\n"); - __restorewintty(); - _Exit(207); + _Exitr(207); } diff --git a/libc/runtime/straceinit.greg.c b/libc/runtime/straceinit.greg.c index 1644f7365..e47bede51 100644 --- a/libc/runtime/straceinit.greg.c +++ b/libc/runtime/straceinit.greg.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/safemacros.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/libfatal.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" diff --git a/libc/runtime/symbols.c b/libc/runtime/symbols.c index 8cfd5c782..1093d0804 100644 --- a/libc/runtime/symbols.c +++ b/libc/runtime/symbols.c @@ -16,15 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/dce.h" +#include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" void __init_symbols(void) { - if (__strace || (IsAsan() && weaken(__die))) { + if (__strace || (IsAsan() && _weaken(__die))) { GetSymbolTable(); } } diff --git a/libc/runtime/vfork.S b/libc/runtime/vfork.S index d013708ed..6e84cf40e 100644 --- a/libc/runtime/vfork.S +++ b/libc/runtime/vfork.S @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" .privileged diff --git a/libc/runtime/warnifpowersave.c b/libc/runtime/warnifpowersave.c index bc3ceaff1..7d3ef9b5b 100644 --- a/libc/runtime/warnifpowersave.c +++ b/libc/runtime/warnifpowersave.c @@ -37,6 +37,6 @@ void __warn_if_powersave(void) { if ((fd = open(FILE, O_RDONLY)) == -1) return; read(fd, buf, 15); close(fd); - if (!startswith(buf, "powersave")) return; + if (!_startswith(buf, "powersave")) return; write(2, WARN, sizeof(WARN) - 1); } diff --git a/libc/runtime/weakfree.c b/libc/runtime/weakfree.c index 44c2b3200..6659da982 100644 --- a/libc/runtime/weakfree.c +++ b/libc/runtime/weakfree.c @@ -24,7 +24,7 @@ * Thunks free() if it's linked, otherwise do nothing. */ void _weakfree(void *p) { - if (weaken(free)) { - weaken(free)(p); + if (_weaken(free)) { + _weaken(free)(p); } } diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index c28db3ec4..3abc226bb 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/elf/pf2prot.internal.h" @@ -27,10 +26,10 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/nomultics.internal.h" #include "libc/intrin/pushpop.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/libfatal.internal.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/nt2sysv.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/nt/console.h" @@ -57,7 +56,6 @@ #include "libc/runtime/winargs.internal.h" #include "libc/sock/internal.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #if IsTiny() @@ -281,7 +279,7 @@ __msabi textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance, #endif NTTRACE("WinMain()"); MakeLongDoubleLongAgain(); - if (weaken(WinSockInit)) weaken(WinSockInit)(); - if (weaken(WinMainForked)) weaken(WinMainForked)(); + if (_weaken(WinSockInit)) _weaken(WinSockInit)(); + if (_weaken(WinMainForked)) _weaken(WinMainForked)(); WinMainNew(cmdline); } diff --git a/libc/sock/accept4.c b/libc/sock/accept4.c index c17e72aa8..0f7c4a8e2 100644 --- a/libc/sock/accept4.c +++ b/libc/sock/accept4.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/sock/internal.h" diff --git a/libc/sock/bind.c b/libc/sock/bind.c index 3bd93ad83..d91dc8e4b 100644 --- a/libc/sock/bind.c +++ b/libc/sock/bind.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/sock/internal.h" diff --git a/libc/sock/closesocket-nt.c b/libc/sock/closesocket-nt.c index 56d644400..e441b7d77 100644 --- a/libc/sock/closesocket-nt.c +++ b/libc/sock/closesocket-nt.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/mem/mem.h" #include "libc/sock/internal.h" diff --git a/libc/sock/connect.c b/libc/sock/connect.c index c5714b7a0..dc604347e 100644 --- a/libc/sock/connect.c +++ b/libc/sock/connect.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/sock/internal.h" diff --git a/libc/sock/getpeername.c b/libc/sock/getpeername.c index dda483b2a..2472f1dd8 100644 --- a/libc/sock/getpeername.c +++ b/libc/sock/getpeername.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/sock/internal.h" diff --git a/libc/sock/getsockname.c b/libc/sock/getsockname.c index 56ab5a5a7..d8a516144 100644 --- a/libc/sock/getsockname.c +++ b/libc/sock/getsockname.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/sock/internal.h" diff --git a/libc/sock/getsockopt.c b/libc/sock/getsockopt.c index b8173445a..ac890fbc5 100644 --- a/libc/sock/getsockopt.c +++ b/libc/sock/getsockopt.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/sock/kntwsadata.c b/libc/sock/kntwsadata.c index 05d974b0b..04602ed76 100644 --- a/libc/sock/kntwsadata.c +++ b/libc/sock/kntwsadata.c @@ -17,9 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/dce.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/mem/mem.h" #include "libc/nt/runtime.h" #include "libc/nt/winsock.h" diff --git a/libc/sock/listen.c b/libc/sock/listen.c index a883ba7ff..29820295e 100644 --- a/libc/sock/listen.c +++ b/libc/sock/listen.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/sock/internal.h" #include "libc/sock/sock.h" diff --git a/libc/sock/pselect.c b/libc/sock/pselect.c index 4869c9ae8..ba9311889 100644 --- a/libc/sock/pselect.c +++ b/libc/sock/pselect.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" diff --git a/libc/sock/recv-nt.c b/libc/sock/recv-nt.c index 20f17ca09..f46f3feb3 100644 --- a/libc/sock/recv-nt.c +++ b/libc/sock/recv-nt.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/errno.h" #include "libc/intrin/likely.h" diff --git a/libc/sock/recv.c b/libc/sock/recv.c index f07d6953b..4edb413aa 100644 --- a/libc/sock/recv.c +++ b/libc/sock/recv.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/sock/recvfrom.c b/libc/sock/recvfrom.c index a0d210e25..5501f196d 100644 --- a/libc/sock/recvfrom.c +++ b/libc/sock/recvfrom.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" diff --git a/libc/sock/select.c b/libc/sock/select.c index c8f3f2cfe..a8e0219b6 100644 --- a/libc/sock/select.c +++ b/libc/sock/select.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/sock/send.c b/libc/sock/send.c index c40dbada0..c9b9ecf4e 100644 --- a/libc/sock/send.c +++ b/libc/sock/send.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index 4908c2f23..8f0e3c48f 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -19,7 +19,7 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" diff --git a/libc/sock/sendmsg.c b/libc/sock/sendmsg.c index d7e4df3b6..dc700b9c2 100644 --- a/libc/sock/sendmsg.c +++ b/libc/sock/sendmsg.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" diff --git a/libc/sock/sendto.c b/libc/sock/sendto.c index b8b0f0631..1b757fe03 100644 --- a/libc/sock/sendto.c +++ b/libc/sock/sendto.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" diff --git a/libc/sock/setsockopt.c b/libc/sock/setsockopt.c index 76f074538..8c6c823ad 100644 --- a/libc/sock/setsockopt.c +++ b/libc/sock/setsockopt.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" diff --git a/libc/sock/shutdown.c b/libc/sock/shutdown.c index 89fa9f265..55d95f355 100644 --- a/libc/sock/shutdown.c +++ b/libc/sock/shutdown.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/dce.h" #include "libc/sock/internal.h" diff --git a/libc/sock/sockatmark.c b/libc/sock/sockatmark.c index a7e022cbd..ca84f8c0f 100644 --- a/libc/sock/sockatmark.c +++ b/libc/sock/sockatmark.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/nt/winsock.h" diff --git a/libc/sock/socket.c b/libc/sock/socket.c index 8c89e5553..d42c584ba 100644 --- a/libc/sock/socket.c +++ b/libc/sock/socket.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" #include "libc/sock/internal.h" diff --git a/libc/sock/wsablock.c b/libc/sock/wsablock.c index acbde754d..130baa518 100644 --- a/libc/sock/wsablock.c +++ b/libc/sock/wsablock.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/nt/enum/wait.h" #include "libc/nt/errors.h" #include "libc/sock/internal.h" diff --git a/libc/sock/xinet_ntop.c b/libc/sock/xinet_ntop.c index 351c6ee7a..12d5ce2d9 100644 --- a/libc/sock/xinet_ntop.c +++ b/libc/sock/xinet_ntop.c @@ -34,7 +34,7 @@ char *sys_xinet_ntop(int af, const void *src) { if (inet_ntop(af, src, ip, sizeof(ip)) && (res = strdup(ip))) { return res; } else { - if (weaken(__die)) weaken(__die)(); + if (_weaken(__die)) _weaken(__die)(); abort(); unreachable; } diff --git a/libc/stdio/append.internal.h b/libc/stdio/append.h similarity index 100% rename from libc/stdio/append.internal.h rename to libc/stdio/append.h diff --git a/libc/stdio/appendd.c b/libc/stdio/appendd.c index b5b3c0468..4c727aa0d 100644 --- a/libc/stdio/appendd.c +++ b/libc/stdio/appendd.c @@ -20,7 +20,7 @@ #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #define W sizeof(size_t) diff --git a/libc/stdio/appendf.c b/libc/stdio/appendf.c index aa1487313..c21633fef 100644 --- a/libc/stdio/appendf.c +++ b/libc/stdio/appendf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" /** * Appends formatted string to buffer, e.g. diff --git a/libc/stdio/appendr.c b/libc/stdio/appendr.c index ca64ac593..902a25821 100644 --- a/libc/stdio/appendr.c +++ b/libc/stdio/appendr.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/dce.h" +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #define W sizeof(size_t) @@ -55,7 +55,7 @@ ssize_t appendr(char **b, size_t i) { z = appendz((p = *b)); if (i != z.i || !p) { n = ROUNDUP(i + 1, 8) + W; - if (n > z.n || bsrl(n) < bsrl(z.n)) { + if (n > z.n || _bsrl(n) < _bsrl(z.n)) { if ((p = realloc(p, n))) { z.n = malloc_usable_size(p); assert(!(z.n & (W - 1))); diff --git a/libc/stdio/appends.c b/libc/stdio/appends.c index 39755ffc0..ac43577ba 100644 --- a/libc/stdio/appends.c +++ b/libc/stdio/appends.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" /** diff --git a/libc/stdio/appendstrlist.c b/libc/stdio/appendstrlist.c index 16f51407c..2834002e4 100644 --- a/libc/stdio/appendstrlist.c +++ b/libc/stdio/appendstrlist.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/strlist.internal.h" int AppendStrList(struct StrList *sl) { diff --git a/libc/stdio/appendw.c b/libc/stdio/appendw.c index b4b0d4538..9513eeeaf 100644 --- a/libc/stdio/appendw.c +++ b/libc/stdio/appendw.c @@ -17,12 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/dce.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #define W sizeof(size_t) @@ -59,7 +59,7 @@ ssize_t appendw(char **b, uint64_t w) { char *p, *q; struct appendz z; z = appendz((p = *b)); - l = w ? (bsrl(w) >> 3) + 1 : 1; + l = w ? (_bsrl(w) >> 3) + 1 : 1; n = ROUNDUP(z.i + 8 + 1, 8) + W; if (n > z.n) { if (!z.n) z.n = W * 2; diff --git a/libc/stdio/appendz.c b/libc/stdio/appendz.c index f56d0da8c..2d6cc7571 100644 --- a/libc/stdio/appendz.c +++ b/libc/stdio/appendz.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/dce.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #define W sizeof(size_t) diff --git a/libc/stdio/dirstream.c b/libc/stdio/dirstream.c index af84a72b1..4bad33ccc 100644 --- a/libc/stdio/dirstream.c +++ b/libc/stdio/dirstream.c @@ -19,14 +19,13 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/errno.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/nopl.internal.h" -#include "libc/thread/thread.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/mem/mem.h" #include "libc/nt/enum/fileflagandattributes.h" @@ -38,6 +37,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/errfuns.h" +#include "libc/thread/thread.h" #include "libc/zip.h" #include "libc/zipos/zipos.internal.h" @@ -264,11 +264,11 @@ DIR *opendir(const char *name) { if (!name || (IsAsan() && !__asan_is_valid(name, 1))) { efault(); res = 0; - } else if (weaken(__zipos_get) && - weaken(__zipos_parseuri)(name, &zipname) != -1) { - if (weaken(__zipos_stat)(&zipname, &st) != -1) { + } else if (_weaken(__zipos_get) && + _weaken(__zipos_parseuri)(name, &zipname) != -1) { + if (_weaken(__zipos_stat)(&zipname, &st) != -1) { if (S_ISDIR(st.st_mode)) { - zip = weaken(__zipos_get)(); + zip = _weaken(__zipos_get)(); res = calloc(1, sizeof(DIR)); res->iszip = true; res->fd = -1; @@ -334,7 +334,7 @@ static struct dirent *readdir_impl(DIR *dir) { struct dirent_openbsd *obsd; if (dir->iszip) { ent = 0; - zip = weaken(__zipos_get)(); + zip = _weaken(__zipos_get)(); while (!ent && dir->tell < dir->zip.records) { assert(ZIP_CFILE_MAGIC(zip->map + dir->zip.offset) == kZipCfileHdrMagic); s = ZIP_CFILE_NAME(zip->map + dir->zip.offset); @@ -496,7 +496,7 @@ void rewinddir(DIR *dir) { _lockdir(dir); if (dir->iszip) { dir->tell = 0; - dir->zip.offset = GetZipCdirOffset(weaken(__zipos_get)()->cdir); + dir->zip.offset = GetZipCdirOffset(_weaken(__zipos_get)()->cdir); } else if (!IsWindows()) { if (!lseek(dir->fd, 0, SEEK_SET)) { dir->buf_pos = dir->buf_end = 0; @@ -521,9 +521,9 @@ void seekdir(DIR *dir, long off) { long i; struct Zipos *zip; _lockdir(dir); - zip = weaken(__zipos_get)(); + zip = _weaken(__zipos_get)(); if (dir->iszip) { - dir->zip.offset = GetZipCdirOffset(weaken(__zipos_get)()->cdir); + dir->zip.offset = GetZipCdirOffset(_weaken(__zipos_get)()->cdir); for (i = 0; i < off && i < dir->zip.records; ++i) { dir->zip.offset += ZIP_CFILE_HDRSIZE(zip->map + dir->zip.offset); } diff --git a/libc/stdio/dtoa.c b/libc/stdio/dtoa.c index 7622f2561..cf7b5f55a 100644 --- a/libc/stdio/dtoa.c +++ b/libc/stdio/dtoa.c @@ -28,7 +28,7 @@ #include "libc/fmt/fmt.internal.h" #include "libc/fmt/internal.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "libc/str/str.h" #include "third_party/gdtoa/gdtoa.h" diff --git a/libc/stdio/dumphexc.c b/libc/stdio/dumphexc.c index e714df9ba..e58b08b86 100644 --- a/libc/stdio/dumphexc.c +++ b/libc/stdio/dumphexc.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/hex.internal.h" #include "libc/str/str.h" diff --git a/libc/stdio/fclose.c b/libc/stdio/fclose.c index ebb7b6e65..092639843 100644 --- a/libc/stdio/fclose.c +++ b/libc/stdio/fclose.c @@ -46,7 +46,7 @@ int fclose(FILE *f) { f->state = EOF; if (f->noclose) { f->fd = -1; - } else if (close_s(&f->fd) == -1) { + } else if (close(f->fd) == -1) { f->state = errno; } if (f->state == EOF) { diff --git a/libc/stdio/fputwc_unlocked.c b/libc/stdio/fputwc_unlocked.c index 05fe668dd..ede03584d 100644 --- a/libc/stdio/fputwc_unlocked.c +++ b/libc/stdio/fputwc_unlocked.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/tpenc.h" #include "libc/stdio/stdio.h" -#include "libc/str/tpenc.h" /** * Writes wide character to stream. @@ -29,7 +29,7 @@ wint_t fputwc_unlocked(wchar_t wc, FILE *f) { uint64_t w; if (wc != -1) { - w = tpenc(wc); + w = _tpenc(wc); do { if (fputc_unlocked(w, f) == -1) { return -1; diff --git a/libc/stdio/freestrlist.c b/libc/stdio/freestrlist.c index 9d866a049..984b5128f 100644 --- a/libc/stdio/freestrlist.c +++ b/libc/stdio/freestrlist.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/strlist.internal.h" void FreeStrList(struct StrList *sl) { diff --git a/libc/stdio/getrandom.c b/libc/stdio/getrandom.c index 9d80911df..ada6d953a 100644 --- a/libc/stdio/getrandom.c +++ b/libc/stdio/getrandom.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/syscall-sysv.internal.h" diff --git a/libc/stdio/joinstrlist.c b/libc/stdio/joinstrlist.c index a87469a76..29914176b 100644 --- a/libc/stdio/joinstrlist.c +++ b/libc/stdio/joinstrlist.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/strlist.internal.h" int JoinStrList(struct StrList *sl, char **buf, uint64_t sep) { diff --git a/libc/stdio/kappendf.c b/libc/stdio/kappendf.c index 8977758ca..e908011e7 100644 --- a/libc/stdio/kappendf.c +++ b/libc/stdio/kappendf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" /** * Appends formatted string to buffer w/ kprintf, e.g. diff --git a/libc/stdio/kvappendf.c b/libc/stdio/kvappendf.c index 58d87af2a..b54c3dabf 100644 --- a/libc/stdio/kvappendf.c +++ b/libc/stdio/kvappendf.c @@ -21,7 +21,7 @@ #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #define W sizeof(size_t) diff --git a/libc/stdio/mkostempsm.c b/libc/stdio/mkostempsm.c index 64f6e17f7..0b85ce1a5 100644 --- a/libc/stdio/mkostempsm.c +++ b/libc/stdio/mkostempsm.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/errno.h" #include "libc/stdio/lcg.internal.h" #include "libc/stdio/rand.h" diff --git a/libc/stdio/stderr-init.S b/libc/stdio/stderr-init.S index 24b3ec928..4be4fc667 100644 --- a/libc/stdio/stderr-init.S +++ b/libc/stdio/stderr-init.S @@ -34,6 +34,6 @@ ezlea __stderr_buf,cx mov %rcx,0x18(%rax) #→ f.buf movl $BUFSIZ,0x20(%rax) #→ f.size - movb $PTHREAD_MUTEX_RECURSIVE,0x38+16(%rax) #→ f.lock.attr + movb $PTHREAD_MUTEX_RECURSIVE,0x38+4(%rax) #→ f.lock._type mov %rax,stderr(%rip) .init.end 400,_init_stderr,globl,hidden diff --git a/libc/stdio/stdin-init.S b/libc/stdio/stdin-init.S index 86051c810..36d79b6b3 100644 --- a/libc/stdio/stdin-init.S +++ b/libc/stdio/stdin-init.S @@ -30,6 +30,6 @@ ezlea __stdin_buf,cx mov %rcx,0x18(%rax) #→ f.buf movl $BUFSIZ,0x20(%rax) #→ f.size - movb $PTHREAD_MUTEX_RECURSIVE,0x38+16(%rax) #→ f.lock.attr + movb $PTHREAD_MUTEX_RECURSIVE,0x38+4(%rax) #→ f.lock._type mov %rax,stdin(%rip) .init.end 400,_init_stdin,globl,hidden diff --git a/libc/stdio/stdout-init.S b/libc/stdio/stdout-init.S index 1711b69b6..71dd87488 100644 --- a/libc/stdio/stdout-init.S +++ b/libc/stdio/stdout-init.S @@ -32,6 +32,6 @@ ezlea __stdout_buf,cx mov %rcx,0x18(%rax) #→ f.buf movl $BUFSIZ,0x20(%rax) #→ f.size - movb $PTHREAD_MUTEX_RECURSIVE,0x38+16(%rax) #→ f.lock.attr + movb $PTHREAD_MUTEX_RECURSIVE,0x38+4(%rax) #→ f.lock._type mov %rax,stdout(%rip) .init.end 400,_init_stdout,globl,hidden diff --git a/libc/stdio/system.c b/libc/stdio/system.c index cadab9b52..98699c225 100644 --- a/libc/stdio/system.c +++ b/libc/stdio/system.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" +#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/sigaction.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/stdio/ungetwc_unlocked.c b/libc/stdio/ungetwc_unlocked.c index 2673e0526..878ab3ab7 100644 --- a/libc/stdio/ungetwc_unlocked.c +++ b/libc/stdio/ungetwc_unlocked.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/tpenc.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" /** * Pushes wide character back to stream. @@ -29,7 +29,7 @@ wint_t ungetwc_unlocked(wint_t c, FILE *f) { uint64_t w; if (c == -1) return -1; n = 0; - w = tpenc(c); + w = _tpenc(c); do { b[n++] = w; } while ((w >>= 8)); diff --git a/libc/stdio/vappendf.c b/libc/stdio/vappendf.c index 6cdf0d7fb..eae9a4293 100644 --- a/libc/stdio/vappendf.c +++ b/libc/stdio/vappendf.c @@ -21,7 +21,7 @@ #include "libc/fmt/fmt.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #define W sizeof(size_t) diff --git a/libc/str/_tpenc.h b/libc/str/_tpenc.h new file mode 100755 index 000000000..e69de29bb diff --git a/libc/str/crc32z.c b/libc/str/crc32z.c index db7e76dee..f35cb121d 100644 --- a/libc/str/crc32z.c +++ b/libc/str/crc32z.c @@ -17,9 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/x86feature.h" @@ -37,7 +37,7 @@ static inline noasan uint64_t WildRead64(const signed char *p) { * * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1 * 0b100000100110000010001110110110111 - * bitreverse32(0x104c11db7) + * _bitreverse32(0x104c11db7) * * This implementation takes 32 picoseconds per byte or 30 gibibyte/s. * diff --git a/libc/str/djbsort.c b/libc/str/djbsort.c index 35ea38260..2ad8d5055 100644 --- a/libc/str/djbsort.c +++ b/libc/str/djbsort.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" +#include "libc/mem/alg.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" @@ -65,7 +65,7 @@ void djbsort(int32_t *a, size_t n) { if (X86_HAVE(AVX2)) { djbsort_avx2(a, n); } else { - intsort(a, n, 1ul << bsrl(n - 1)); + intsort(a, n, 1ul << _bsrl(n - 1)); } } } diff --git a/libc/str/endswith.c b/libc/str/endswith.c index 2b58edd14..301697a51 100644 --- a/libc/str/endswith.c +++ b/libc/str/endswith.c @@ -24,7 +24,7 @@ * @param s is a NUL-terminated string * @param suffix is also NUL-terminated */ -bool endswith(const char *s, const char *suffix) { +bool _endswith(const char *s, const char *suffix) { size_t n, m; n = strlen(s); m = strlen(suffix); diff --git a/libc/str/endswith16.c b/libc/str/endswith16.c index d6e43ad63..247e60308 100644 --- a/libc/str/endswith16.c +++ b/libc/str/endswith16.c @@ -24,7 +24,7 @@ * @param s is a NUL-terminated string * @param suffix is also NUL-terminated */ -bool endswith16(const char16_t *s, const char16_t *suffix) { +bool _endswith16(const char16_t *s, const char16_t *suffix) { size_t n, m; n = strlen16(s); m = strlen16(suffix); diff --git a/libc/str/errfun.h b/libc/str/errfun.h deleted file mode 100644 index 3c1e62439..000000000 --- a/libc/str/errfun.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_STR_ERRFUN_H_ -#define COSMOPOLITAN_LIBC_STR_ERRFUN_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -char *strerrno(int) nosideeffect libcesque; -char *strerdoc(int) nosideeffect libcesque; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_STR_ERRFUN_H_ */ diff --git a/libc/str/getcachesize.c b/libc/str/getcachesize.c index c6ff0b7a7..3902ad639 100644 --- a/libc/str/getcachesize.c +++ b/libc/str/getcachesize.c @@ -17,12 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/dce.h" +#include "libc/intrin/bits.h" #include "libc/nexgen32e/cachesize.h" #include "libc/nexgen32e/cpuid4.internal.h" -static unsigned getcachesize_cpuid4(int type, int level) { +static unsigned _getcachesize_cpuid4(int type, int level) { unsigned i, k; static int once; static unsigned char kCacheKey[8]; @@ -50,8 +50,8 @@ static unsigned getcachesize_cpuid4(int type, int level) { * @param level starts at 1 * @return size in bytes, or 0 if unknown */ -unsigned getcachesize(int type, int level) { +unsigned _getcachesize(int type, int level) { assert(1 <= type && type <= 3); assert(level >= 1); - return getcachesize_cpuid4(type, level); + return _getcachesize_cpuid4(type, level); } diff --git a/libc/str/longsort.c b/libc/str/longsort.c index c18ace576..cd3f4e60b 100644 --- a/libc/str/longsort.c +++ b/libc/str/longsort.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/runtime/runtime.h" -static void longsorter(long *A, size_t n) { +static void _longsorter(long *A, size_t n) { long t, p; size_t i, j; if (n < 2) return; @@ -31,8 +31,8 @@ static void longsorter(long *A, size_t n) { A[i] = A[j]; A[j] = t; } - longsorter(A, i); - longsorter(A + i, n - i); + _longsorter(A, i); + _longsorter(A + i, n - i); } /** @@ -42,9 +42,9 @@ static void longsorter(long *A, size_t n) { * -Lord Capulet * */ -void longsort(long *A, size_t n) { - longsorter(A, n); +void _longsort(long *A, size_t n) { + _longsorter(A, n); if (n > 1000) { - STRACE("longsort(%p, %'zu)", A, n); + STRACE("_longsort(%p, %'zu)", A, n); } } diff --git a/libc/str/smoothsort.c b/libc/str/smoothsort.c index 42a7ed770..f9b4feb99 100644 --- a/libc/str/smoothsort.c +++ b/libc/str/smoothsort.c @@ -23,7 +23,7 @@ └─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/mem/alg.h" -#include "libc/nexgen32e/bsf.h" +#include "libc/intrin/bsf.h" #include "libc/str/str.h" asm(".ident\t\"\\n\\n\ diff --git a/libc/str/startswith.c b/libc/str/startswith.c index 7f86aaad4..eea85df2a 100644 --- a/libc/str/startswith.c +++ b/libc/str/startswith.c @@ -24,7 +24,7 @@ * @param s is a NUL-terminated string * @param prefix is also NUL-terminated */ -bool startswith(const char *s, const char *prefix) { +bool _startswith(const char *s, const char *prefix) { for (;;) { if (!*prefix) return true; if (!*s) return false; diff --git a/libc/str/startswith16.c b/libc/str/startswith16.c index eefd03dfa..7657978fd 100644 --- a/libc/str/startswith16.c +++ b/libc/str/startswith16.c @@ -24,7 +24,7 @@ * @param s is a NUL-terminated string * @param prefix is also NUL-terminated */ -bool startswith16(const char16_t *s, const char16_t *prefix) { +bool _startswith16(const char16_t *s, const char16_t *prefix) { for (;;) { if (!*prefix) return true; if (!*s) return false; diff --git a/libc/str/startswithi.c b/libc/str/startswithi.c index 52a14c949..a749d733d 100644 --- a/libc/str/startswithi.c +++ b/libc/str/startswithi.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" -bool startswithi(const char *s, const char *prefix) { +bool _startswithi(const char *s, const char *prefix) { for (;;) { if (!*prefix) return true; if (!*s) return false; diff --git a/libc/str/str.h b/libc/str/str.h index 20d380c37..a39fd83ac 100644 --- a/libc/str/str.h +++ b/libc/str/str.h @@ -29,7 +29,7 @@ int tolower(int); int ispunct(int); int toupper(int); int hextoint(int); -int cescapec(int); +int _cescapec(int); int iswalnum(wint_t); int iswalpha(wint_t); @@ -141,13 +141,13 @@ char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3)); wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3)); char *wstrtrunc(uint16_t *) memcpyesque; char *wstrntrunc(uint16_t *, size_t) memcpyesque; -bool startswith(const char *, const char *) strlenesque; -bool startswithi(const char *, const char *) strlenesque; -bool startswith16(const char16_t *, const char16_t *) strlenesque; -bool wcsstartswith(const wchar_t *, const wchar_t *) strlenesque; -bool endswith(const char *, const char *) strlenesque; -bool endswith16(const char16_t *, const char16_t *) strlenesque; -bool wcsendswith(const wchar_t *, const wchar_t *) strlenesque; +bool _startswith(const char *, const char *) strlenesque; +bool _startswithi(const char *, const char *) strlenesque; +bool _startswith16(const char16_t *, const char16_t *) strlenesque; +bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque; +bool _endswith(const char *, const char *) strlenesque; +bool _endswith16(const char16_t *, const char16_t *) strlenesque; +bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque; const char *IndexDoubleNulString(const char *, unsigned) strlenesque; int strverscmp(const char *, const char *); wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque; @@ -213,6 +213,8 @@ char *strsignal(int) returnsnonnull libcesque; char *strerror(int) returnsnonnull dontthrow nocallback; int strerror_r(int, char *, size_t) dontthrow nocallback; int strerror_wr(int, uint32_t, char *, size_t) dontthrow nocallback; +char *_strerrno(int) nosideeffect libcesque; +char *_strerdoc(int) nosideeffect libcesque; int __xpg_strerror_r(int, char *, size_t) dontthrow nocallback; COSMOPOLITAN_C_END_ diff --git a/libc/str/strnwidth.c b/libc/str/strnwidth.c index 3354ff316..da75999d0 100644 --- a/libc/str/strnwidth.c +++ b/libc/str/strnwidth.c @@ -20,7 +20,7 @@ #include "libc/intrin/pmovmskb.h" #include "libc/intrin/psubb.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsf.h" +#include "libc/intrin/bsf.h" #include "libc/str/str.h" #include "libc/str/thompike.h" #include "libc/str/unicode.h" diff --git a/libc/str/thompike.h b/libc/str/thompike.h index 2cae952ce..4cf4bb13e 100644 --- a/libc/str/thompike.h +++ b/libc/str/thompike.h @@ -1,11 +1,11 @@ #ifndef COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ #define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #define ThomPikeCont(x) (0200 == (0300 & (x))) #define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3)) #define ThomPikeLen(x) (7 - ThomPikeMsb(x)) -#define ThomPikeMsb(x) ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1) +#define ThomPikeMsb(x) ((255 & (x)) < 252 ? _bsr(255 & ~(x)) : 1) #define ThomPikeMerge(x, y) ((x) << 6 | 077 & (y)) #endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */ diff --git a/libc/str/tpdecodecb.internal.h b/libc/str/tpdecodecb.internal.h index 0bb8f1915..ee46614fa 100644 --- a/libc/str/tpdecodecb.internal.h +++ b/libc/str/tpdecodecb.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ #define COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) /* TODO(jart): DELETE? */ @@ -19,7 +19,7 @@ forceinline int tpdecodecb(wint_t *out, int first, if ((wc = get(arg, i++)) == -1) return -1; } if (__builtin_expect(!(0 <= wc && wc <= 0x7F), 0)) { - msb = wc < 252 ? bsr(~wc & 0xff) : 1; + msb = wc < 252 ? _bsr(~wc & 0xff) : 1; need = 7 - msb; wc &= ((1u << msb) - 1) | 0b00000011; for (j = 1; j < need; ++j) { diff --git a/libc/str/tpencode.ncabi.c b/libc/str/tpencode.ncabi.c index dcead5572..2d39a4c84 100644 --- a/libc/str/tpencode.ncabi.c +++ b/libc/str/tpencode.ncabi.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/tpenc.h" #include "libc/str/internal.h" -#include "libc/str/tpenc.h" #include "libc/str/tpencode.internal.h" /* TODO: DELETE */ @@ -47,7 +47,7 @@ unsigned(tpencode)(char *p, size_t size, wint_t wc, bool32 awesome) { return 2; } i = 0; - w = tpenc(wc); + w = _tpenc(wc); do { if (!size--) break; p[i++] = w & 0xff; diff --git a/libc/str/tprecode16to8.c b/libc/str/tprecode16to8.c index 397d186a2..6ab104c63 100644 --- a/libc/str/tprecode16to8.c +++ b/libc/str/tprecode16to8.c @@ -21,8 +21,8 @@ #include "libc/intrin/pandn.h" #include "libc/intrin/pcmpgtw.h" #include "libc/intrin/pmovmskb.h" +#include "libc/intrin/tpenc.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" static const int16_t kDel16[8] = {127, 127, 127, 127, 127, 127, 127, 127}; @@ -74,7 +74,7 @@ axdx_t tprecode16to8(char *dst, size_t dstsize, const char16_t *src) { if (!(y = src[r.dx++])) break; x = MergeUtf16(x, y); } - w = tpenc(x); + w = _tpenc(x); while (w && r.ax + 1 < dstsize) { dst[r.ax++] = w & 0xFF; w >>= 8; diff --git a/libc/str/undeflate.c b/libc/str/undeflate.c deleted file mode 100644 index 0957919c2..000000000 --- a/libc/str/undeflate.c +++ /dev/null @@ -1,263 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/assert.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/weaken.h" -#include "libc/intrin/repmovsb.h" -#include "libc/macros.internal.h" -#include "libc/nexgen32e/kompressor.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/str/undeflate.h" - -#define kDeflateCompressionTypeNone 0b00 -#define kDeflateCompressionTypeFixedHuffman 0b01 -#define kDeflateCompressionTypeDynamicHuffman 0b10 - -#define kDeflateCodeLengthCopyPrevious3To6Times 16 -#define kDeflateCodeLengthRepeatZero3To10Times 17 -#define kDeflateCodeLengthRepeatZero11To138Times 18 - -#define CONSUME(BITS) \ - hold.word >>= BITS; \ - hold.bits -= BITS - -#define MOAR(BITS) \ - while (hold.bits < BITS) { \ - al = *ip++; \ - hold.word |= (size_t)al << hold.bits; \ - hold.bits += 8; \ - } - -struct DeflateHold { - uint64_t word; - size_t bits; -}; - -static const struct DeflateConsts { - uint16_t lenbase[32]; - uint16_t distbase[32]; - uint8_t lenbits[32]; - uint8_t distbits[32]; - uint8_t orders[19]; - struct RlDecode lensrl[6]; -} kDeflate = { - {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, - 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}, - {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, - 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, - 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}, - {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, - 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5}, - {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, - 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}, - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}, - {{144, 8}, {112, 9}, {24, 7}, {8, 8}, {32, 5}, {0, 0}}, -}; - -static uint32_t undeflatetree(struct DeflateState *ds, uint32_t *tree, - const uint8_t *lens, size_t symcount) { - size_t i, len; - uint32_t code, slot; - uint16_t codes[16], first[16], counts[16]; - bzero(counts, sizeof(counts)); - for (i = 0; i < symcount; i++) { - counts[lens[i]]++; - } - codes[0] = 0; - first[0] = 0; - counts[0] = 0; - for (i = 1; i < ARRAYLEN(codes); i++) { - codes[i] = (codes[i - 1] + counts[i - 1]) << 1; - first[i] = first[i - 1] + counts[i - 1]; - } - assert(first[15] + counts[15] <= symcount); - for (i = 0; i < symcount; i++) { - if ((len = lens[i])) { - code = codes[len]++; - slot = first[len]++; - tree[slot] = code << (32 - len) | i << 4 | len; - } - } - return first[15]; -} - -static struct DeflateHold undeflatesymbol(struct DeflateHold hold, - const uint32_t *tree, - size_t treecount, - uint32_t *out_symbol) { - size_t left, right, m; - uint32_t search, key; - left = 0; - right = treecount; - search = BITREVERSE16(hold.word); - search <<= 16; - search |= 0xffff; - while (left < right) { /* TODO(jart): Make this O(1) like Zlib. */ - m = (left + right) >> 1; - if (search < tree[m]) { - right = m; - } else { - left = m + 1; - } - } - key = tree[left - 1]; - assert(!((search ^ key) >> (32 - (key & 0xf)))); - *out_symbol = (key >> 4) & 0xfff; - CONSUME(key & 0xf); - return hold; -} - -/** - * Decompresses raw DEFLATE data. - * - * This is 10x smaller and 10x slower than chromium zlib. - * - * @param output should be followed by a single guard page, and have - * 36kb of guard pages preceding it too because buffer overflows - * are part of the design of this algorithm - * @note h/t Phil Katz, David Huffman, Claude Shannon - */ -ssize_t undeflate(void *output, size_t outputsize, void *input, - size_t inputsize, struct DeflateState *ds) { - struct DeflateHold hold; - bool isfinalblock; - size_t i, nlit, ndist; - uint8_t *ip, *ipe, *op, *si, b, al, last, compressiontype; - uint32_t j, l, len, sym, tlit, tdist, tlen, nlen; - - op = output; - ip = input; - ipe = ip + inputsize; - hold.word = 0; - hold.bits = 0; - isfinalblock = 0; - - while (!isfinalblock) { - MOAR(3); - isfinalblock = hold.word & 0b1; - CONSUME(1); - compressiontype = hold.word & 0b11; - CONSUME(2); - - switch (compressiontype) { - case kDeflateCompressionTypeNone: - CONSUME(hold.bits & 7); - MOAR(32); - len = hold.word & 0xffff; - nlen = (hold.word >> 16) & 0xffff; - assert(len == ~nlen); - CONSUME(32); - while (len--) { - if (hold.bits) { - *op++ = hold.word; - CONSUME(8); - } else { - *op++ = *ip++; - } - } - continue; - - case kDeflateCompressionTypeFixedHuffman: - nlit = 288; - ndist = 32; - rldecode(ds->lens, kDeflate.lensrl); - break; - - case kDeflateCompressionTypeDynamicHuffman: - MOAR(5 + 5 + 4); - nlit = (hold.word & 0b11111) + 257; - CONSUME(5); - ndist = (hold.word & 0b11111) + 1; - CONSUME(5); - nlen = (hold.word & 0b1111) + 4; - CONSUME(4); - for (i = 0; i < nlen; i++) { - MOAR(3); - ds->lenlens[kDeflate.orders[i]] = hold.word & 0b111; - CONSUME(3); - } - for (; i < ARRAYLEN(ds->lenlens); i++) { - ds->lenlens[kDeflate.orders[i]] = 0; - } - tlen = - undeflatetree(ds, ds->lencodes, ds->lenlens, ARRAYLEN(ds->lenlens)); - i = 0; - last = 0; - while (i < nlit + ndist) { - MOAR(16); - hold = undeflatesymbol(hold, ds->lencodes, tlen, &sym); - b = 2; - j = 1; - switch (sym) { - case kDeflateCodeLengthRepeatZero11To138Times: - b += 4; - j += 8; - /* fallthrough */ - case kDeflateCodeLengthRepeatZero3To10Times: - b += 1; - last = 0; - /* fallthrough */ - case kDeflateCodeLengthCopyPrevious3To6Times: - MOAR(b); - j += (hold.word & ((1u << b) - 1u)) + 2u; - CONSUME(b); - break; - default: - last = sym; - break; - } - while (j--) { - ds->lens[i++] = last; - } - } - break; - default: - return -1; - } - - tlit = undeflatetree(ds, ds->litcodes, ds->lens, nlit); - tdist = undeflatetree(ds, ds->distcodes, &ds->lens[nlit], ndist); - - do { - MOAR(16); - hold = undeflatesymbol(hold, ds->litcodes, tlit, &sym); - if (sym < 256) { - *op++ = sym; - } else if (sym > 256) { - sym -= 257; - b = kDeflate.lenbits[sym]; - MOAR(b); - l = kDeflate.lenbase[sym] + (hold.word & ((1u << b) - 1)); - CONSUME(b); - MOAR(16); - hold = undeflatesymbol(hold, ds->distcodes, tdist, &sym); - b = kDeflate.distbits[sym]; - MOAR(b); - /* max readback: 24577 + 2**13-1 = 32768 */ - si = op - ((uint32_t)kDeflate.distbase[sym] + - (uint32_t)(hold.word & ((1u << b) - 1))); - CONSUME(b); - repmovsb(&op, &si, l); - } - } while (sym != 256); - } - - return 0; -} diff --git a/libc/str/undeflate.h b/libc/str/undeflate.h deleted file mode 100644 index 440ad0c42..000000000 --- a/libc/str/undeflate.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_STR_UNDEFLATE_H_ -#define COSMOPOLITAN_LIBC_STR_UNDEFLATE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct DeflateState { - uint8_t lenlens[19]; - uint32_t lencodes[19]; - uint32_t distcodes[32]; - uint32_t litcodes[288]; - uint8_t lens[288 + 32]; -}; - -ssize_t undeflate(void *output, size_t outputsize, void *input, - size_t inputsize, struct DeflateState *ds); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_STR_UNDEFLATE_H_ */ diff --git a/libc/str/wcsendswith.c b/libc/str/wcsendswith.c index 56579639e..bd30ff33b 100644 --- a/libc/str/wcsendswith.c +++ b/libc/str/wcsendswith.c @@ -24,7 +24,7 @@ * @param s is a NUL-terminated string * @param suffix is also NUL-terminated */ -bool wcsendswith(const wchar_t *s, const wchar_t *suffix) { +bool _wcsendswith(const wchar_t *s, const wchar_t *suffix) { size_t n, m; n = wcslen(s); m = wcslen(suffix); diff --git a/libc/str/wcsstartswith.c b/libc/str/wcsstartswith.c index 8dc18321a..c1591e96b 100644 --- a/libc/str/wcsstartswith.c +++ b/libc/str/wcsstartswith.c @@ -24,7 +24,7 @@ * @param s is a NUL-terminated string * @param prefix is also NUL-terminated */ -bool wcsstartswith(const wchar_t *s, const wchar_t *prefix) { +bool _wcsstartswith(const wchar_t *s, const wchar_t *prefix) { for (;;) { if (!*prefix) return true; if (!*s) return false; diff --git a/libc/sysv/systemfive.S b/libc/sysv/systemfive.S index 719d720c2..fd88a4d4a 100644 --- a/libc/sysv/systemfive.S +++ b/libc/sysv/systemfive.S @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/macros.h" diff --git a/libc/testlib/endswith.c b/libc/testlib/endswith.c index 23168083b..a24134a3a 100644 --- a/libc/testlib/endswith.c +++ b/libc/testlib/endswith.c @@ -22,7 +22,7 @@ bool testlib_endswith(size_t cw, const void *s, const void *suffix) { if (s == suffix) return true; if (!s || !suffix) return false; - return cw == sizeof(wchar_t) ? wcsendswith(s, suffix) - : cw == sizeof(char16_t) ? endswith16(s, suffix) - : endswith(s, suffix); + return cw == sizeof(wchar_t) ? _wcsendswith(s, suffix) + : cw == sizeof(char16_t) ? _endswith16(s, suffix) + : _endswith(s, suffix); } diff --git a/libc/testlib/ezbench.h b/libc/testlib/ezbench.h index 7f8714343..e8f3a0888 100644 --- a/libc/testlib/ezbench.h +++ b/libc/testlib/ezbench.h @@ -1,12 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_ #define COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_ -#include "libc/macros.internal.h" #include "libc/nexgen32e/bench.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/sysv/consts/clock.h" #include "libc/testlib/bench.h" #include "libc/testlib/testlib.h" -#include "libc/time/time.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/testlib/formatbinaryasglyphs.c b/libc/testlib/formatbinaryasglyphs.c index c6100ff87..a68da7fbb 100644 --- a/libc/testlib/formatbinaryasglyphs.c +++ b/libc/testlib/formatbinaryasglyphs.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" void testlib_formatbinaryasglyphs(const char16_t *want, const void *got, size_t n, char **out_v1, char **out_v2) { diff --git a/libc/testlib/formatfloat.c b/libc/testlib/formatfloat.c index c5c028f30..24080a6bd 100644 --- a/libc/testlib/formatfloat.c +++ b/libc/testlib/formatfloat.c @@ -16,11 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/fmt.h" -#include "libc/mem/mem.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" -#include "third_party/gdtoa/gdtoa.h" +#include "libc/x/xasprintf.h" char *testlib_formatfloat(long double x) { return xasprintf("%.15Lg", x); diff --git a/libc/testlib/formatrange.c b/libc/testlib/formatrange.c index 468abaacd..54464f379 100644 --- a/libc/testlib/formatrange.c +++ b/libc/testlib/formatrange.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" dontdiscard char *testlib_formatrange(intptr_t beg, intptr_t end) { return xasprintf("[%#ld,%#ld]", beg, end); diff --git a/libc/testlib/formatstr.c b/libc/testlib/formatstr.c index a836e6cd7..77b055914 100644 --- a/libc/testlib/formatstr.c +++ b/libc/testlib/formatstr.c @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" /** * Turns string into code. diff --git a/libc/testlib/quota.c b/libc/testlib/quota.c index f9d043e4c..2f5c66576 100644 --- a/libc/testlib/quota.c +++ b/libc/testlib/quota.c @@ -51,8 +51,7 @@ static relegated void DieBecauseOfQuota(int rc, const char *message) { gethostname(hostname, sizeof(hostname)); kprintf("%s on %s pid %d\n", message, hostname, (long)getpid()); PrintBacktraceUsingSymbols(2, 0, GetSymbolTable()); - __restorewintty(); - _Exit(rc); + _Exitr(rc); } static relegated void OnXcpu(int sig) { @@ -76,7 +75,7 @@ relegated void __oom_hook(size_t request) { if (IsRunningUnderMake()) { newlim = toto + request; newlim += newlim >> 1; - newlim = roundup2pow(newlim); + newlim = _roundup2pow(newlim); kprintf("FIX CODE OR TUNE QUOTA += -M%dm\n", newlim / (1024 * 1024)); } kprintf("\n"); @@ -84,8 +83,7 @@ relegated void __oom_hook(size_t request) { kprintf("\nTHE STRAW THAT BROKE THE CAMEL'S BACK\n"); PrintBacktraceUsingSymbols(2, 0, GetSymbolTable()); PrintSystemMappings(2); - __restorewintty(); - _Exit(42); + _Exitr(42); } static textstartup void InstallQuotaHandlers(void) { diff --git a/libc/testlib/startswith.c b/libc/testlib/startswith.c index d1a9dfa5a..7a01e04d2 100644 --- a/libc/testlib/startswith.c +++ b/libc/testlib/startswith.c @@ -22,7 +22,7 @@ bool testlib_startswith(size_t cw, const void *s, const void *prefix) { if (s == prefix) return true; if (!s || !prefix) return false; - return cw == sizeof(wchar_t) ? wcsstartswith(s, prefix) - : cw == sizeof(char16_t) ? startswith16(s, prefix) - : startswith(s, prefix); + return cw == sizeof(wchar_t) ? _wcsstartswith(s, prefix) + : cw == sizeof(char16_t) ? _startswith16(s, prefix) + : _startswith(s, prefix); } diff --git a/libc/testlib/testlib.h b/libc/testlib/testlib.h index e8c63249d..081605ec6 100644 --- a/libc/testlib/testlib.h +++ b/libc/testlib/testlib.h @@ -5,7 +5,6 @@ COSMOPOLITAN_C_START_ /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § testing library ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#include "libc/macros.internal.h" /** * Declares test case function. @@ -82,13 +81,16 @@ COSMOPOLITAN_C_START_ #define __ROSTR(STR) __TEST_SECTION(".rodata.str1.1,\"aSM\",@progbits,1", STR) -#define __FIXTURE(KIND, GROUP, ENTRY) \ - asm(__RELOSECTION("." KIND ".2." #GROUP #ENTRY, \ - "\t.quad\t1f\n" \ - "\t.quad\t2f\n" \ - "\t.quad\t" STRINGIFY(GROUP##_##ENTRY)) \ - __ROSTR("1:\t.asciz\t" STRINGIFY(#GROUP)) \ - __ROSTR("2:\t.asciz\t" STRINGIFY(#ENTRY))); \ +#define TESTLIB_STRINGIFY(A) _TESTLIB_STRINGIFY(A) +#define _TESTLIB_STRINGIFY(A) #A + +#define __FIXTURE(KIND, GROUP, ENTRY) \ + asm(__RELOSECTION("." KIND ".2." #GROUP #ENTRY, \ + "\t.quad\t1f\n" \ + "\t.quad\t2f\n" \ + "\t.quad\t" TESTLIB_STRINGIFY(GROUP##_##ENTRY)) \ + __ROSTR("1:\t.asciz\t" TESTLIB_STRINGIFY(#GROUP)) \ + __ROSTR("2:\t.asciz\t" TESTLIB_STRINGIFY(#ENTRY))); \ void GROUP##_##ENTRY(void) /** diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index c15144785..8500e679d 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/rlimit.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigset.h" @@ -27,6 +26,7 @@ #include "libc/intrin/asan.internal.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/check.h" #include "libc/log/color.internal.h" @@ -65,7 +65,7 @@ Flags:\n\ \n" STATIC_YOINK("__die"); -STATIC_YOINK("__get_symbol_by_addr"); +STATIC_YOINK("GetSymbolByAddr"); STATIC_YOINK("testlib_quota_handlers"); STATIC_YOINK("stack_usage_logging"); @@ -182,8 +182,9 @@ noasan int main(int argc, char *argv[]) { if (!IsWindows()) sys_getpid(); // make strace easier to read testlib_clearxmmregisters(); testlib_runalltests(); - if (!g_testlib_failed && runbenchmarks_ && weaken(testlib_runallbenchmarks)) { - weaken(testlib_runallbenchmarks)(); + if (!g_testlib_failed && runbenchmarks_ && + _weaken(testlib_runallbenchmarks)) { + _weaken(testlib_runallbenchmarks)(); if (IsAsan() && !g_testlib_failed) { CheckForMemoryLeaks(); } diff --git a/libc/testlib/testrunner.c b/libc/testlib/testrunner.c index ea8627a26..e505727c5 100644 --- a/libc/testlib/testrunner.c +++ b/libc/testlib/testrunner.c @@ -19,7 +19,6 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/syscall-sysv.internal.h" @@ -28,7 +27,7 @@ #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" #include "libc/intrin/atomic.h" -#include "libc/thread/thread.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/check.h" #include "libc/log/internal.h" @@ -45,6 +44,7 @@ #include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/w.h" #include "libc/testlib/testlib.h" +#include "libc/thread/thread.h" #include "libc/x/x.h" static int x; @@ -81,8 +81,7 @@ void testlib_error_leave(void) { wontreturn void testlib_abort(void) { testlib_finish(); - __restorewintty(); - _Exit(MAX(1, MIN(255, g_testlib_failed))); + _Exitr(MAX(1, MIN(255, g_testlib_failed))); } static void SetupTmpDir(void) { @@ -155,7 +154,7 @@ static void CheckForFileDescriptors(void) { // TODO: race condition on fd cleanup :'( int i; struct pollfd pfds[16]; - if (!weaken(open) && !weaken(socket)) return; + if (!_weaken(open) && !_weaken(socket)) return; for (i = 0; i < ARRAYLEN(pfds); ++i) { pfds[i].fd = i + 3; pfds[i].events = POLLIN; @@ -176,7 +175,7 @@ static void CheckForZombies(void) { sigset_t ss, oldss; struct sigaction oldsa; struct sigaction ignore = {.sa_handler = DoNothing}; - if (!weaken(fork)) return; + if (!_weaken(fork)) return; for (;;) { if ((pid = wait(0)) == -1) { CHECK_EQ(ECHILD, errno); @@ -210,17 +209,17 @@ void testlib_runtestcases(testfn_t *start, testfn_t *end, testfn_t warmup) { */ const testfn_t *fn; CopySignalHandlers(); - if (weaken(testlib_enable_tmp_setup_teardown) || - weaken(testlib_enable_tmp_setup_teardown_once)) { + if (_weaken(testlib_enable_tmp_setup_teardown) || + _weaken(testlib_enable_tmp_setup_teardown_once)) { CHECK_NOTNULL(getcwd(g_testlib_olddir, sizeof(g_testlib_olddir))); } - if (weaken(testlib_enable_tmp_setup_teardown_once)) { + if (_weaken(testlib_enable_tmp_setup_teardown_once)) { SetupTmpDir(); } - if (weaken(SetUpOnce)) weaken(SetUpOnce)(); + if (_weaken(SetUpOnce)) _weaken(SetUpOnce)(); for (x = 0, fn = start; fn != end; ++fn) { - if (weaken(testlib_enable_tmp_setup_teardown)) SetupTmpDir(); - if (weaken(SetUp)) weaken(SetUp)(); + if (_weaken(testlib_enable_tmp_setup_teardown)) SetupTmpDir(); + if (_weaken(SetUp)) _weaken(SetUp)(); errno = 0; SetLastError(0); if (!IsWindows()) sys_getpid(); @@ -228,16 +227,16 @@ void testlib_runtestcases(testfn_t *start, testfn_t *end, testfn_t warmup) { testlib_clearxmmregisters(); (*fn)(); if (!IsWindows()) sys_getpid(); - if (weaken(TearDown)) weaken(TearDown)(); - if (weaken(testlib_enable_tmp_setup_teardown)) TearDownTmpDir(); + if (_weaken(TearDown)) _weaken(TearDown)(); + if (_weaken(testlib_enable_tmp_setup_teardown)) TearDownTmpDir(); CheckForFileDescriptors(); CheckForSignalHandlers(); CheckForZombies(); } - if (weaken(TearDownOnce)) { - weaken(TearDownOnce)(); + if (_weaken(TearDownOnce)) { + _weaken(TearDownOnce)(); } - if (weaken(testlib_enable_tmp_setup_teardown_once)) { + if (_weaken(testlib_enable_tmp_setup_teardown_once)) { TearDownTmpDir(); } } diff --git a/libc/thread/pthread_create.c b/libc/thread/pthread_create.c index 5ae34c19c..a63197ece 100644 --- a/libc/thread/pthread_create.c +++ b/libc/thread/pthread_create.c @@ -32,6 +32,7 @@ #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/gc.internal.h" +#include "libc/runtime/clone.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/sysv/consts/clone.h" @@ -89,8 +90,8 @@ static int PosixThread(void *arg, int tid) { __get_tls()->tib_pthread = (pthread_t)pt; pt->rc = pt->start_routine(pt->arg); } - if (weaken(_pthread_key_destruct)) { - weaken(_pthread_key_destruct)(0); + if (_weaken(_pthread_key_destruct)) { + _weaken(_pthread_key_destruct)(0); } _pthread_ungarbage(); if (atomic_load_explicit(&pt->status, memory_order_acquire) == @@ -232,7 +233,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, // 2. in public world optimize to *work* regardless of memory pt->ownstack = true; pt->attr.stacksize = MAX(pt->attr.stacksize, GetStackSize()); - pt->attr.stacksize = roundup2pow(pt->attr.stacksize); + pt->attr.stacksize = _roundup2pow(pt->attr.stacksize); pt->attr.guardsize = ROUNDUP(pt->attr.guardsize, PAGESIZE); if (pt->attr.guardsize + PAGESIZE >= pt->attr.stacksize) { _pthread_free(pt); diff --git a/libc/thread/pthread_exit.c b/libc/thread/pthread_exit.c index de4d06fd0..60cb72a1e 100644 --- a/libc/thread/pthread_exit.c +++ b/libc/thread/pthread_exit.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/spawn.h" #include "libc/thread/thread.h" diff --git a/libc/thread/spawn.c b/libc/thread/spawn.c index 6ec8a144d..b23f7b7bb 100644 --- a/libc/thread/spawn.c +++ b/libc/thread/spawn.c @@ -19,6 +19,7 @@ #include "libc/calls/calls.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" +#include "libc/runtime/clone.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" diff --git a/libc/thread/thread.h b/libc/thread/thread.h index ab97823ef..51a2d9d8c 100644 --- a/libc/thread/thread.h +++ b/libc/thread/thread.h @@ -50,10 +50,10 @@ typedef struct pthread_spinlock_s { } pthread_spinlock_t; typedef struct pthread_mutex_s { - _Atomic(int) _lock; + _Atomic(int32_t) _lock; + uint16_t _type; + uint16_t _pshared; void *_nsync; - char _type; - char _pshared; } pthread_mutex_t; typedef struct pthread_mutexattr_s { @@ -85,6 +85,9 @@ typedef struct pthread_attr_s { char *stackaddr; } pthread_attr_t; +int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), + void *); + int pthread_yield(void); void pthread_exit(void *) wontreturn; pthread_t pthread_self(void) pureconst; @@ -109,8 +112,6 @@ int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *); int pthread_attr_setstack(pthread_attr_t *, void *, size_t); int pthread_attr_getstacksize(const pthread_attr_t *, size_t *); int pthread_attr_setstacksize(pthread_attr_t *, size_t); -int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), - void *); int pthread_detach(pthread_t); int pthread_cancel(pthread_t); int pthread_join(pthread_t, void **); diff --git a/libc/thread/tls.h b/libc/thread/tls.h index f5a3f422d..641d17836 100644 --- a/libc/thread/tls.h +++ b/libc/thread/tls.h @@ -20,7 +20,7 @@ struct CosmoTib { intptr_t tib_locale; /* 0x20 */ intptr_t tib_pthread; /* 0x28 */ struct CosmoTib *tib_self2; /* 0x30 */ - int32_t tib_tid; /* 0x38 */ + _Atomic(int32_t) tib_tid; /* 0x38 */ int32_t tib_errno; /* 0x3c */ }; diff --git a/libc/thread/wait0.c b/libc/thread/wait0.c index 380eb5718..96f153d90 100644 --- a/libc/thread/wait0.c +++ b/libc/thread/wait0.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/time/localtime.c b/libc/time/localtime.c index f52e4f2f1..df06ba81a 100644 --- a/libc/time/localtime.c +++ b/libc/time/localtime.c @@ -8,7 +8,7 @@ #include "libc/thread/thread.h" #include "libc/mem/mem.h" #include "libc/thread/tls.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" #include "libc/time/struct/tm.h" diff --git a/libc/vga/tty.c b/libc/vga/tty.c index b76129a55..722bd3fab 100644 --- a/libc/vga/tty.c +++ b/libc/vga/tty.c @@ -23,7 +23,6 @@ #include "libc/runtime/pc.internal.h" #include "libc/str/str.h" #include "libc/str/thompike.h" -#include "libc/str/tpenc.h" #include "libc/str/unicode.h" #include "libc/sysv/errfuns.h" #include "libc/vga/vga.internal.h" @@ -40,7 +39,7 @@ #define DEFAULT_FG 7 #define DEFAULT_BG 0 -#define CRTPORT 0x3d4 +#define CRTPORT 0x3d4 static void SetYn(struct Tty *tty, unsigned short yn) { #ifndef VGA_TTY_HEIGHT @@ -54,8 +53,7 @@ static void SetXn(struct Tty *tty, unsigned short xn) { #endif } -static wchar_t * SetWcs(struct Tty *tty, wchar_t *wcs) -{ +static wchar_t *SetWcs(struct Tty *tty, wchar_t *wcs) { #ifdef VGA_USE_WCS tty->wcs = wcs; return wcs; @@ -64,8 +62,7 @@ static wchar_t * SetWcs(struct Tty *tty, wchar_t *wcs) #endif } -static size_t Yn(struct Tty *tty) -{ +static size_t Yn(struct Tty *tty) { #ifdef VGA_TTY_HEIGHT return VGA_TTY_HEIGHT; #else @@ -73,8 +70,7 @@ static size_t Yn(struct Tty *tty) #endif } -static size_t Xn(struct Tty *tty) -{ +static size_t Xn(struct Tty *tty) { #ifdef VGA_TTY_WIDTH return VGA_TTY_WIDTH; #else @@ -82,8 +78,7 @@ static size_t Xn(struct Tty *tty) #endif } -static wchar_t *Wcs(struct Tty *tty) -{ +static wchar_t *Wcs(struct Tty *tty) { #ifdef VGA_USE_WCS return tty->wcs; #else @@ -99,19 +94,15 @@ void _StartTty(struct Tty *tty, unsigned short yn, unsigned short xn, SetYn(tty, yn); SetXn(tty, xn); tty->ccs = ccs; - if (starty >= yn) - starty = yn - 1; - if (startx >= xn) - startx = xn - 1; - if (chr_ht > 32) - chr_ht = 32; + if (starty >= yn) starty = yn - 1; + if (startx >= xn) startx = xn - 1; + if (chr_ht > 32) chr_ht = 32; tty->y = starty; tty->x = startx; tty->chr_ht = chr_ht; if (SetWcs(tty, wcs)) { size_t n = (size_t)yn * xn, i; - for (i = 0; i < n; ++i) - wcs[i] = bing(ccs[i].ch, 0); + for (i = 0; i < n; ++i) wcs[i] = bing(ccs[i].ch, 0); } _TtyResetOutputMode(tty); } @@ -229,8 +220,7 @@ static void TtySetCodepage(struct Tty *tty, char id) { * @see VGA_USE_BLINK macro (libc/vga/vga.internal.h) * @see drivers/tty/vt/vt.c in Linux 5.9.14 source code */ -static uint8_t TtyGetVgaAttr(struct Tty *tty) -{ +static uint8_t TtyGetVgaAttr(struct Tty *tty) { uint8_t attr; if ((tty->pr & kTtyFlip) == 0) attr = tty->fg | tty->bg << 4; @@ -244,11 +234,9 @@ static uint8_t TtyGetVgaAttr(struct Tty *tty) * simplistic than what Linux does, but should be enough. */ attr &= ~0x80; - if ((tty->pr & kTtyBlink) != 0) - attr |= 0x80; + if ((tty->pr & kTtyBlink) != 0) attr |= 0x80; #endif - if ((tty->pr & kTtyBold) != 0) - attr |= 0x08; + if ((tty->pr & kTtyBold) != 0) attr |= 0x08; return attr; } @@ -256,15 +244,13 @@ void _TtyErase(struct Tty *tty, size_t dst, size_t n) { uint8_t attr = TtyGetVgaAttr(tty); size_t i; for (i = 0; i < n; ++i) - tty->ccs[dst + i] = (struct VgaTextCharCell){ ' ', attr }; - if (Wcs(tty)) - wmemset(Wcs(tty) + dst, L' ', n); + tty->ccs[dst + i] = (struct VgaTextCharCell){' ', attr}; + if (Wcs(tty)) wmemset(Wcs(tty) + dst, L' ', n); } void _TtyMemmove(struct Tty *tty, size_t dst, size_t src, size_t n) { memmove(tty->ccs + dst, tty->ccs + src, n * sizeof(struct VgaTextCharCell)); - if (Wcs(tty)) - wmemmove(Wcs(tty) + dst, Wcs(tty) + src, n); + if (Wcs(tty)) wmemmove(Wcs(tty) + dst, Wcs(tty) + src, n); } void _TtyResetOutputMode(struct Tty *tty) { @@ -350,18 +336,15 @@ static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) { uint8_t attr = TtyGetVgaAttr(tty); size_t i; int c; - if (w < 1) - wc = L' ', w = 1; + if (w < 1) wc = L' ', w = 1; if ((tty->conf & kTtyRedzone) || tty->x + w > Xn(tty)) { TtyAdvance(tty); } i = tty->y * Xn(tty) + tty->x; c = unbing(wc); - if (c == -1) - c = 0xFE; - tty->ccs[i] = (struct VgaTextCharCell){ c, attr }; - if (Wcs(tty)) - Wcs(tty)[i] = wc; + if (c == -1) c = 0xFE; + tty->ccs[i] = (struct VgaTextCharCell){c, attr}; + if (Wcs(tty)) Wcs(tty)[i] = wc; if ((tty->x += w) >= Xn(tty)) { tty->x = Xn(tty) - 1; tty->conf |= kTtyRedzone; @@ -376,7 +359,7 @@ static void TtyWriteTab(struct Tty *tty) { } x2 = MIN(Xn(tty), ROUNDUP(tty->x + 1, 8)); for (x = tty->x; x < x2; ++x) { - tty->ccs[tty->y * Xn(tty) + x] = (struct VgaTextCharCell){ ' ', attr }; + tty->ccs[tty->y * Xn(tty) + x] = (struct VgaTextCharCell){' ', attr}; } if (Wcs(tty)) { for (x = tty->x; x < x2; ++x) { @@ -628,15 +611,11 @@ static void TtyCsiN(struct Tty *tty) { * * @see drivers/tty/vt/vt.c in Linux 5.9.14 source code */ -static uint8_t TtyMapTrueColor(uint8_t r, uint8_t g, uint8_t b) -{ +static uint8_t TtyMapTrueColor(uint8_t r, uint8_t g, uint8_t b) { uint8_t hue = 0, max = MAX(MAX(r, g), b); - if (r > max / 2) - hue |= 4; - if (g > max / 2) - hue |= 2; - if (b > max / 2) - hue |= 1; + if (r > max / 2) hue |= 4; + if (g > max / 2) hue |= 2; + if (b > max / 2) hue |= 1; if (hue == 7 && max <= 0x55) hue = 8; else if (max > 0xaa) @@ -650,8 +629,7 @@ static uint8_t TtyMapTrueColor(uint8_t r, uint8_t g, uint8_t b) * * @see drivers/tty/vt/vt.c in Linux 5.9.14 source code */ -static uint8_t TtyMapXtermColor(uint8_t color) -{ +static uint8_t TtyMapXtermColor(uint8_t color) { uint8_t r, g, b; if (color < 8) { r = (color & 1) ? 0xaa : 0; @@ -945,10 +923,8 @@ static void TtyCsi(struct Tty *tty) { static void TtyScreenAlignmentDisplay(struct Tty *tty) { uint8_t attr = TtyGetVgaAttr(tty); size_t n = Yn(tty) * Xn(tty), i; - for (i = 0; i < n; ++i) - tty->ccs[i] = (struct VgaTextCharCell){ 'E', attr }; - if (Wcs(tty)) - wmemset(Wcs(tty), L'E', n); + for (i = 0; i < n; ++i) tty->ccs[i] = (struct VgaTextCharCell){'E', attr}; + if (Wcs(tty)) wmemset(Wcs(tty), L'E', n); } static void TtyEscHash(struct Tty *tty) { @@ -1048,8 +1024,7 @@ static void TtyEscAppend(struct Tty *tty, char c) { static void TtyUpdateHwCursor(struct Tty *tty) { unsigned char start = tty->chr_ht - 2, end = tty->chr_ht - 1; unsigned short pos = tty->y * Xn(tty) + tty->x; - if ((tty->conf & kTtyNocursor)) - start |= 1 << 5; + if ((tty->conf & kTtyNocursor)) start |= 1 << 5; outb(CRTPORT, 0x0A); outb(CRTPORT + 1, start); outb(CRTPORT, 0x0B); diff --git a/libc/x/filecmp.c b/libc/x/filecmp.c deleted file mode 100644 index 0acada13c..000000000 --- a/libc/x/filecmp.c +++ /dev/null @@ -1,78 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" -#include "libc/calls/calls.h" -#include "libc/errno.h" -#include "libc/macros.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/madv.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/o.h" -#include "libc/sysv/consts/prot.h" - -static void *filecmp_mmap(int fd, size_t size) { - return size ? mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0) : NULL; -} - -/** - * Compares contents of files with memcmp(). - * - * @return ≤0, 0, or ≥0 based on comparison; or ≠0 on error, in which - * case we make our best effort to sift failing filenames rightward, - * and errno can be set to 0 beforehand to differentiate errors - */ -int filecmp(const char *pathname1, const char *pathname2) { - int res, olderr; - int fd1 = -1; - int fd2 = -1; - char *addr1 = MAP_FAILED; - char *addr2 = MAP_FAILED; - size_t size1 = 0; - size_t size2 = 0; - if ((fd1 = open(pathname1, O_RDONLY)) != -1 && - (fd2 = open(pathname2, O_RDONLY)) != -1 && - (size1 = getfiledescriptorsize(fd1)) != -1 && - (size2 = getfiledescriptorsize(fd2)) != -1 && - (addr1 = filecmp_mmap(fd1, size1)) != MAP_FAILED && - (addr2 = filecmp_mmap(fd2, size2)) != MAP_FAILED) { - olderr = errno; - madvise(addr1, size1, MADV_WILLNEED | MADV_SEQUENTIAL); - madvise(addr2, size2, MADV_WILLNEED | MADV_SEQUENTIAL); - errno = olderr; - res = memcmp(addr1, addr2, MIN(size1, size2)); - if (!res && size1 != size2) { - char kNul = '\0'; - if (size1 > size2) { - res = cmpub(addr1 + size2, &kNul); - } else { - res = cmpub(addr2 + size1, &kNul); - } - } - } else { - res = cmpuq(&fd1, &fd2) | 1; - } - olderr = errno; - munmap(addr1, size1); - munmap(addr2, size2); - close(fd1); - close(fd2); - errno = olderr; - return res; -} diff --git a/libc/x/makedirs.c b/libc/x/makedirs.c index 89ffff072..3794a7c0f 100644 --- a/libc/x/makedirs.c +++ b/libc/x/makedirs.c @@ -17,10 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/errno.h" #include "libc/intrin/safemacros.internal.h" -#include "libc/intrin/weaken.h" +#include "libc/intrin/strace.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/libc/x/utf16to8.c b/libc/x/utf16to8.c index 64075e2cf..c5cfd94e2 100644 --- a/libc/x/utf16to8.c +++ b/libc/x/utf16to8.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/packsswb.h" #include "libc/intrin/pandn.h" #include "libc/intrin/pcmpgtb.h" @@ -24,11 +25,10 @@ #include "libc/intrin/pmovmskb.h" #include "libc/intrin/punpckhbw.h" #include "libc/intrin/punpcklbw.h" +#include "libc/intrin/tpenc.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/str/str.h" #include "libc/str/thompike.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #include "libc/x/x.h" @@ -77,9 +77,9 @@ char *utf16to8(const char16_t *p, size_t n, size_t *z) { if (x < 0200) { *q++ = x; } else { - w = tpenc(x); + w = _tpenc(x); WRITE64LE(q, w); - q += bsr(w) >> 3; + q += _bsr(w) >> 3; q += 1; } } diff --git a/libc/x/utf32to8.c b/libc/x/utf32to8.c index 32b609469..cf94ff27f 100644 --- a/libc/x/utf32to8.c +++ b/libc/x/utf32to8.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/tpenc.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/x/x.h" /** @@ -38,7 +38,7 @@ char *utf32to8(const wchar_t *p, size_t n, size_t *z) { if ((q = r = malloc(n * 6 + 1))) { for (i = 0; i < n; ++i) { x = p[i]; - w = tpenc(x); + w = _tpenc(x); do { *q++ = w; } while ((w >>= 8)); diff --git a/libc/x/x.h b/libc/x/x.h index 4f4ae4bb5..4f5ff9301 100644 --- a/libc/x/x.h +++ b/libc/x/x.h @@ -1,57 +1,45 @@ #ifndef COSMOPOLITAN_LIBC_X_H_ #define COSMOPOLITAN_LIBC_X_H_ -#include "libc/calls/struct/rusage.h" -#include "libc/calls/struct/sigaction.h" -#include "libc/calls/struct/timespec.h" -#include "libc/calls/struct/timeval.h" -#include "libc/fmt/pflink.h" -#include "libc/stdio/stdio.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│─╝ - Standard Library veneers for folks not building embedded RTOS */ -#define _XPNN paramsnonnull() -#define _XRET dontthrow nocallback dontdiscard returnsnonnull -#define _XMAL returnspointerwithnoaliases _XRET -#define _XMALPG returnsaligned((PAGESIZE)) _XMAL - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » system calls ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *); int xwrite(int, const void *, uint64_t); - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » memory ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - void xdie(void) wontreturn; -char *xdtoa(double) _XMAL; -char *xdtoaf(float) _XMAL; -char *xdtoal(long double) _XMAL; -char *xasprintf(const char *, ...) printfesque(1) paramsnonnull((1)) _XMAL; -char *xvasprintf(const char *, va_list) _XPNN _XMAL; -char *xgetline(struct FILE *) _XPNN mallocesque; -void *xmalloc(size_t) attributeallocsize((1)) _XMAL; +char *xdtoa(double) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xdtoaf(float) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xdtoal(long double) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +void *xmalloc(size_t) attributeallocsize((1)) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; void *xrealloc(void *, size_t) attributeallocsize((2)) dontthrow nocallback dontdiscard; -void *xcalloc(size_t, size_t) attributeallocsize((1, 2)) _XMAL; -void *xvalloc(size_t) attributeallocsize((1)) _XMALPG; -void *xmemalign(size_t, size_t) attributeallocalign((1)) - attributeallocsize((2)) _XMAL; +void *xcalloc(size_t, size_t) attributeallocsize((1, 2)) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((FRAMESIZE)) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2)) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; void *xmemalignzero(size_t, size_t) attributeallocalign((1)) - attributeallocsize((2)) _XMAL; -char *xstrdup(const char *) _XPNN _XMAL; -char *xstrndup(const char *, size_t) _XPNN _XMAL; -char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated() _XMAL; -char *xstrmul(const char *, size_t) paramsnonnull((1)) _XMAL; -char *xinet_ntop(int, const void *) _XPNN _XMAL; -void *xunbinga(size_t, const char16_t *) attributeallocalign((1)) _XMAL _XRET; -void *xunbing(const char16_t *) _XMAL _XRET; + attributeallocsize((2)) returnspointerwithnoaliases dontthrow nocallback + dontdiscard returnsnonnull; +char *xstrdup(const char *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xstrndup(const char *, size_t) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +#define xstrcat(...) (xstrcat)(__VA_ARGS__, 0) +char *xstrmul(const char *, size_t) paramsnonnull((1)) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xinet_ntop(int, const void *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +void *xunbinga(size_t, const char16_t *) + attributeallocalign((1)) returnspointerwithnoaliases dontthrow nocallback + dontdiscard returnsnonnull dontthrow nocallback dontdiscard returnsnonnull; +void *xunbing(const char16_t *) returnspointerwithnoaliases dontthrow nocallback + dontdiscard returnsnonnull dontthrow nocallback dontdiscard returnsnonnull; char16_t *utf8to16(const char *, size_t, size_t *) dontdiscard; char *utf16to8(const char16_t *, size_t, size_t *) dontdiscard; wchar_t *utf8to32(const char *, size_t, size_t *) dontdiscard; @@ -63,75 +51,24 @@ char *xstripexts(const char *) dontdiscard; void *xload(bool *, void **, const void *, size_t, size_t); void *xloadzd(bool *, void **, const void *, size_t, size_t, size_t, size_t, uint32_t); - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » files ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - int rmrf(const char *); int makedirs(const char *, unsigned); -char *xbasename(const char *) paramsnonnull() _XMAL; -char *xdirname(const char *) paramsnonnull() _XMAL; -char *xjoinpaths(const char *, const char *) paramsnonnull() _XMAL; -char *xreadlink(const char *) paramsnonnull() _XMAL; -char *xreadlinkat(int, const char *) paramsnonnull() _XMAL; +char *xbasename(const char *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xdirname(const char *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xjoinpaths(const char *, const char *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xreadlink(const char *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xreadlinkat(int, const char *) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; void xfixpath(void); - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » time ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -char *xiso8601i(int) mallocesque; -char *xiso8601tv(struct timeval *) mallocesque; -char *xiso8601ts(struct timespec *) mallocesque; - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » input / output ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - void *xslurp(const char *, size_t *) paramsnonnull((1)) returnspointerwithnoaliases returnsaligned((PAGESIZE)) dontdiscard; int xbarf(const char *, const void *, size_t); -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » safety ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -#define xstrcat(...) (xstrcat)(__VA_ARGS__, NULL) - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » processes ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -int xspawn(struct rusage *); -int xvspawn(void (*)(void *), void *, struct rusage *); - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » generic typing ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -#if __STDC_VERSION__ + 0 >= 201112 - -#define xiso8601(TS) \ - _Generic(*(TS), struct timeval : xiso8601tv, default : xiso8601ts)(TS) - -#endif /* C11 */ - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § eXtended apis » link-time optimizations ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define xasprintf(FMT, ...) (xasprintf)(PFLINK(FMT), ##__VA_ARGS__) -#define xvasprintf(FMT, VA) (xvasprintf)(PFLINK(FMT), VA) -#define xsigaction(SIG, HANDLER, FLAGS, MASK, OLD) \ - ({ \ - __SIGACTION_YOINK(SIG); \ - xsigaction(SIG, HANDLER, FLAGS, MASK, OLD); \ - }) -#endif - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_X_H_ */ diff --git a/libc/x/xasprintf.c b/libc/x/xasprintf.c index eae68f40a..50293edc9 100644 --- a/libc/x/xasprintf.c +++ b/libc/x/xasprintf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" /** * Returns dynamically formatted string. diff --git a/libc/x/xasprintf.h b/libc/x/xasprintf.h new file mode 100644 index 000000000..193839a74 --- /dev/null +++ b/libc/x/xasprintf.h @@ -0,0 +1,19 @@ +#ifndef COSMOPOLITAN_LIBC_X_XASPRINTF_H_ +#define COSMOPOLITAN_LIBC_X_XASPRINTF_H_ +#include "libc/fmt/pflink.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +char *xasprintf(const char *, ...) printfesque(1) paramsnonnull((1)) + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; +char *xvasprintf(const char *, va_list) paramsnonnull() + returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; + +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) +#define xasprintf(FMT, ...) (xasprintf)(PFLINK(FMT), ##__VA_ARGS__) +#define xvasprintf(FMT, VA) (xvasprintf)(PFLINK(FMT), VA) +#endif + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_X_XASPRINTF_H_ */ diff --git a/libc/x/xbasename.c b/libc/x/xbasename.c index d04cfaa2d..205676b97 100644 --- a/libc/x/xbasename.c +++ b/libc/x/xbasename.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/x/x.h" /** diff --git a/libc/x/xdie.c b/libc/x/xdie.c index 1b9056d65..e23987453 100644 --- a/libc/x/xdie.c +++ b/libc/x/xdie.c @@ -22,6 +22,6 @@ #include "libc/x/x.h" void xdie(void) { - if (weaken(__die)) __die(); + if (_weaken(__die)) __die(); abort(); } diff --git a/libc/x/xgetline.h b/libc/x/xgetline.h new file mode 100644 index 000000000..b92d6c486 --- /dev/null +++ b/libc/x/xgetline.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_LIBC_X_XGETLINE_H_ +#define COSMOPOLITAN_LIBC_X_XGETLINE_H_ +#include "libc/stdio/stdio.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +char *xgetline(struct FILE *) paramsnonnull() mallocesque; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_X_XGETLINE_H_ */ diff --git a/libc/x/xhomedir.c b/libc/x/xhomedir.c index 751678cff..dce954f45 100644 --- a/libc/x/xhomedir.c +++ b/libc/x/xhomedir.c @@ -19,6 +19,7 @@ #include "libc/dce.h" #include "libc/runtime/runtime.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" /** * Returns home directory. diff --git a/libc/x/xiso8601.h b/libc/x/xiso8601.h new file mode 100644 index 000000000..5df767c7d --- /dev/null +++ b/libc/x/xiso8601.h @@ -0,0 +1,19 @@ +#ifndef COSMOPOLITAN_LIBC_X_XISO8601_H_ +#define COSMOPOLITAN_LIBC_X_XISO8601_H_ +#include "libc/calls/struct/timespec.h" +#include "libc/calls/struct/timeval.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +char *xiso8601i(int) mallocesque; +char *xiso8601tv(struct timeval *) mallocesque; +char *xiso8601ts(struct timespec *) mallocesque; + +#if __STDC_VERSION__ + 0 >= 201112 +#define xiso8601(TS) \ + _Generic(*(TS), struct timeval : xiso8601tv, default : xiso8601ts)(TS) +#endif /* C11 */ + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_X_XISO8601_H_ */ diff --git a/libc/x/xjoinpaths.c b/libc/x/xjoinpaths.c index 8d960d5d5..8dcdc863a 100644 --- a/libc/x/xjoinpaths.c +++ b/libc/x/xjoinpaths.c @@ -40,7 +40,7 @@ char *xjoinpaths(const char *path, const char *other) { return xstrdup(other); } else if (_isabspath(other) || !strcmp(path, ".")) { return xstrdup(other); - } else if (endswith(path, "/")) { + } else if (_endswith(path, "/")) { return xstrcat(path, other); } else { return xstrcat(path, '/', other); diff --git a/libc/x/xsigaction.h b/libc/x/xsigaction.h new file mode 100644 index 000000000..806b99313 --- /dev/null +++ b/libc/x/xsigaction.h @@ -0,0 +1,19 @@ +#ifndef COSMOPOLITAN_LIBC_X_XSIGACTION_H_ +#define COSMOPOLITAN_LIBC_X_XSIGACTION_H_ +#include "libc/calls/struct/sigaction.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *); + +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) +#define xsigaction(SIG, HANDLER, FLAGS, MASK, OLD) \ + ({ \ + __SIGACTION_YOINK(SIG); \ + xsigaction(SIG, HANDLER, FLAGS, MASK, OLD); \ + }) +#endif + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_X_XSIGACTION_H_ */ diff --git a/libc/x/xslurp.c b/libc/x/xslurp.c index b3b137a60..b43cf2f87 100644 --- a/libc/x/xslurp.c +++ b/libc/x/xslurp.c @@ -37,7 +37,8 @@ void *xslurp(const char *path, size_t *opt_out_size) { ssize_t rc, size; res = NULL; if ((fd = open(path, O_RDONLY)) != -1) { - if ((size = getfiledescriptorsize(fd)) != -1 && (res = valloc(size + 1))) { + if ((size = getfiledescriptorsize(fd)) != -1 && + (res = memalign(PAGESIZE, size + 1))) { if (size > 2 * 1024 * 1024) { fadvise(fd, 0, size, MADV_SEQUENTIAL); } diff --git a/libc/x/xspawn.h b/libc/x/xspawn.h new file mode 100644 index 000000000..22064fb6d --- /dev/null +++ b/libc/x/xspawn.h @@ -0,0 +1,12 @@ +#ifndef COSMOPOLITAN_LIBC_X_XSPAWN_H_ +#define COSMOPOLITAN_LIBC_X_XSPAWN_H_ +#include "libc/calls/struct/rusage.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int xspawn(struct rusage *); +int xvspawn(void (*)(void *), void *, struct rusage *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_X_XSPAWN_H_ */ diff --git a/libc/x/xvalloc.c b/libc/x/xvalloc.c index 7f0d114b4..12fb45396 100644 --- a/libc/x/xvalloc.c +++ b/libc/x/xvalloc.c @@ -20,7 +20,7 @@ #include "libc/x/x.h" /** - * Allocates page-aligned memory, or dies. + * Allocates frame-aligned memory, or dies. */ void *xvalloc(size_t size) { void *res = valloc(size); diff --git a/libc/x/xvasprintf.c b/libc/x/xvasprintf.c index 243e68fc1..25ece9dbe 100644 --- a/libc/x/xvasprintf.c +++ b/libc/x/xvasprintf.c @@ -17,8 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/fmt.h" -#include "libc/mem/mem.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" /** * Returns dynamically formatted string. diff --git a/libc/x/xvspawn.c b/libc/x/xvspawn.c index dc132948a..63aa82bdf 100644 --- a/libc/x/xvspawn.c +++ b/libc/x/xvspawn.c @@ -17,10 +17,14 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/struct/rusage.h" +#include "libc/calls/struct/sigaction.h" +#include "libc/calls/struct/sigset.h" #include "libc/errno.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/sig.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" +#include "libc/x/xspawn.h" /** * Spawns process using vfork(). @@ -44,7 +48,7 @@ int xvspawn(void f(void *), void *ctx, struct rusage *r) { xsigaction(SIGQUIT, SIG_DFL, 0, 0, 0); sigprocmask(SIG_SETMASK, &savemask, 0); f(ctx); - _exit(127); + _Exit(127); } while (wait4(pid, &wstatus, 0, r) == -1) { if (errno != EINTR) { diff --git a/libc/zipos/get.c b/libc/zipos/get.c index 352b3475d..a6d618c9c 100644 --- a/libc/zipos/get.c +++ b/libc/zipos/get.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/intrin/cmpxchg.h" #include "libc/intrin/promises.internal.h" #include "libc/thread/thread.h" diff --git a/libc/zipos/notat.c b/libc/zipos/notat.c index 30302e2fd..6b2f90860 100644 --- a/libc/zipos/notat.c +++ b/libc/zipos/notat.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/internal.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" diff --git a/libc/zipos/open.c b/libc/zipos/open.c index 4d10357e5..c2bc7abb1 100644 --- a/libc/zipos/open.c +++ b/libc/zipos/open.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/calls/extend.internal.h" #include "libc/calls/internal.h" #include "libc/calls/state.internal.h" #include "libc/calls/struct/sigset.h" @@ -28,6 +27,7 @@ #include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/cmpxchg.h" +#include "libc/intrin/extend.internal.h" #include "libc/intrin/lockcmpxchg.h" #include "libc/nexgen32e/crc32.h" #include "libc/runtime/directmap.internal.h" @@ -54,8 +54,8 @@ static void *__zipos_mmap(size_t mapsize) { maptotal += mapsize; start = (char *)kMemtrackZiposStart; if (!mapend) mapend = start; - mapend = _extend(start, maptotal, mapend, - kMemtrackZiposStart + kMemtrackZiposSize);; + mapend = _extend(start, maptotal, mapend, + kMemtrackZiposStart + kMemtrackZiposSize); return start + offset; } diff --git a/libc/zipos/stat.c b/libc/zipos/stat.c index 6e4f41e9d..95ff71f60 100644 --- a/libc/zipos/stat.c +++ b/libc/zipos/stat.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/stdio/stdio.h" #include "libc/sysv/errfuns.h" #include "libc/zipos/zipos.internal.h" diff --git a/net/finger/fingersyn.c b/net/finger/fingersyn.c index 7a0e73480..096cd04ff 100644 --- a/net/finger/fingersyn.c +++ b/net/finger/fingersyn.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" /** * Fingers IP+TCP SYN packet. @@ -36,7 +36,7 @@ uint32_t FingerSyn(const char *p, size_t n) { // ttl<=128 Windows, OpenVMS 8+ // ttl<=64 Mac, Linux, BSD, Solaris 8+, Tru64, HP-UX ttl = p[8] & 255; - h += bsr(MAX(1, ttl - 1)); + h += _bsr(MAX(1, ttl - 1)); h *= 0x9e3779b1; // TCP Options // We care about the order and presence of leading common options. diff --git a/net/finger/getosname.c b/net/finger/getosname.c index e01bc3069..771e75960 100644 --- a/net/finger/getosname.c +++ b/net/finger/getosname.c @@ -16,12 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "net/finger/finger.h" const char *GetOsName(int os) { if (os) { - switch (bsr(os)) { + switch (_bsr(os)) { case 0: return "LINUX"; case 1: diff --git a/net/http/underlong.c b/net/http/underlong.c index b158745f5..522322a33 100644 --- a/net/http/underlong.c +++ b/net/http/underlong.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/pcmpgtb.h" #include "libc/intrin/pmovmskb.h" +#include "libc/intrin/tpenc.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/str/thompike.h" -#include "libc/str/tpenc.h" #include "net/http/escape.h" /** @@ -72,7 +72,7 @@ char *Underlong(const char *p, size_t n, size_t *z) { } } } - w = tpenc(x); + w = _tpenc(x); do { *q++ = w; } while ((w >>= 8)); diff --git a/net/http/visualizecontrolcodes.c b/net/http/visualizecontrolcodes.c index 084abca2b..52469f0a5 100644 --- a/net/http/visualizecontrolcodes.c +++ b/net/http/visualizecontrolcodes.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/tpenc.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/str/thompike.h" -#include "libc/str/tpenc.h" #include "net/http/escape.h" /** @@ -109,7 +109,7 @@ char *VisualizeControlCodes(const char *data, size_t size, size_t *out_size) { } else if (x == 0x7F) { x = 0x2421; } - w = tpenc(x); + w = _tpenc(x); do { *q++ = w; } while ((w >>= 8)); diff --git a/net/https/chaincertificate.c b/net/https/chaincertificate.c index 6825dc60b..0c9f18377 100644 --- a/net/https/chaincertificate.c +++ b/net/https/chaincertificate.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/log.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "net/https/https.h" bool ChainCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *parent) { diff --git a/net/https/finishcertificate.c b/net/https/finishcertificate.c index d04bac789..add99b40d 100644 --- a/net/https/finishcertificate.c +++ b/net/https/finishcertificate.c @@ -17,8 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/log.h" -#include "libc/runtime/gc.internal.h" -#include "libc/x/x.h" +#include "libc/mem/gc.h" +#include "libc/x/xasprintf.h" #include "net/https/https.h" struct Cert FinishCertificate(struct Cert *ca, mbedtls_x509write_cert *wcert, @@ -37,8 +37,8 @@ struct Cert FinishCertificate(struct Cert *ca, mbedtls_x509write_cert *wcert, if ((rc = mbedtls_pk_check_pair(&cert->pk, key))) { FATALF("generate key (grep -0x%04x)", -rc); } - LogCertificate( - gc(xasprintf("generated %s certificate", mbedtls_pk_get_name(&cert->pk))), - cert); + LogCertificate(_gc(xasprintf("generated %s certificate", + mbedtls_pk_get_name(&cert->pk))), + cert); return (struct Cert){cert, key}; } diff --git a/net/https/sslcache.c b/net/https/sslcache.c index b3165c47c..79c4ceaa5 100644 --- a/net/https/sslcache.c +++ b/net/https/sslcache.c @@ -84,7 +84,7 @@ struct SslCache *CreateSslCache(const char *path, size_t bytes, int lifetime) { struct SslCache *c; if (!bytes) bytes = 10 * 1024 * 1024; if (lifetime <= 0) lifetime = 24 * 60 * 60; - ents = rounddown2pow(MAX(2, bytes / sizeof(struct SslCacheEntry))); + ents = _rounddown2pow(MAX(2, bytes / sizeof(struct SslCacheEntry))); size = sizeof(struct SslCache) + sizeof(struct SslCacheEntry) * ents; size = ROUNDUP(size, FRAMESIZE); c = OpenSslCache(path, size); diff --git a/test/dsp/core/alaw_test.c b/test/dsp/core/alaw_test.c index c9d35f69d..6a681563f 100644 --- a/test/dsp/core/alaw_test.c +++ b/test/dsp/core/alaw_test.c @@ -19,7 +19,7 @@ #include "dsp/core/core.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/dsp/core/getintegercoefficients_test.c b/test/dsp/core/getintegercoefficients_test.c index aaff843df..e263ff581 100644 --- a/test/dsp/core/getintegercoefficients_test.c +++ b/test/dsp/core/getintegercoefficients_test.c @@ -18,8 +18,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/core/q.h" +#include "libc/dce.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/dsp/core/sad16x8n_test.c b/test/dsp/core/sad16x8n_test.c index 3a07dfe5f..2dde7d224 100644 --- a/test/dsp/core/sad16x8n_test.c +++ b/test/dsp/core/sad16x8n_test.c @@ -22,7 +22,7 @@ #include "libc/log/check.h" #include "libc/nexgen32e/x86feature.h" #include "libc/stdio/rand.h" -#include "libc/runtime/buffer.h" +#include "libc/runtime/buffer.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/dsp/core/scalevolume_test.c b/test/dsp/core/scalevolume_test.c index 82d4330e5..11a646480 100644 --- a/test/dsp/core/scalevolume_test.c +++ b/test/dsp/core/scalevolume_test.c @@ -23,7 +23,7 @@ #include "libc/macros.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/stdio/rand.h" -#include "libc/runtime/buffer.h" +#include "libc/runtime/buffer.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/dsp/scale/magikarp_test.c b/test/dsp/scale/magikarp_test.c index 72886bc67..efe764218 100644 --- a/test/dsp/scale/magikarp_test.c +++ b/test/dsp/scale/magikarp_test.c @@ -25,7 +25,7 @@ #include "libc/math.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/dsp/scale/scale_test.c b/test/dsp/scale/scale_test.c index 89f07b6c4..3b9c3e0bf 100644 --- a/test/dsp/scale/scale_test.c +++ b/test/dsp/scale/scale_test.c @@ -24,7 +24,7 @@ #include "libc/fmt/bing.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/dsp/tty/windex_test.c b/test/dsp/tty/windex_test.c index 0a4d82420..8c07cc065 100644 --- a/test/dsp/tty/windex_test.c +++ b/test/dsp/tty/windex_test.c @@ -23,7 +23,7 @@ #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/calls/access_test.c b/test/libc/calls/access_test.c index 0f7a6db52..be795f213 100644 --- a/test/libc/calls/access_test.c +++ b/test/libc/calls/access_test.c @@ -17,10 +17,11 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/dce.h" #include "libc/errno.h" #include "libc/mem/alloca.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/ok.h" diff --git a/test/libc/calls/commandv_test.c b/test/libc/calls/commandv_test.c index d2713ca7e..843e4fc5f 100644 --- a/test/libc/calls/commandv_test.c +++ b/test/libc/calls/commandv_test.c @@ -24,7 +24,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/test/libc/calls/diagnose_syscall_test.c b/test/libc/calls/diagnose_syscall_test.c index ae7515a25..57ca96517 100644 --- a/test/libc/calls/diagnose_syscall_test.c +++ b/test/libc/calls/diagnose_syscall_test.c @@ -20,9 +20,9 @@ #include "libc/calls/ucontext.h" #include "libc/dce.h" #include "libc/intrin/kprintf.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #include "libc/sysv/consts/nr.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/calls/dup_test.c b/test/libc/calls/dup_test.c index 3eda2c135..b12ca97df 100644 --- a/test/libc/calls/dup_test.c +++ b/test/libc/calls/dup_test.c @@ -28,7 +28,7 @@ #include "libc/sysv/consts/fd.h" #include "libc/sysv/consts/o.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xspawn.h" char testlib_enable_tmp_setup_teardown; diff --git a/test/libc/calls/ftruncate_test.c b/test/libc/calls/ftruncate_test.c index f53aa8eb7..008c8d26c 100644 --- a/test/libc/calls/ftruncate_test.c +++ b/test/libc/calls/ftruncate_test.c @@ -21,7 +21,7 @@ #include "libc/calls/struct/stat.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/calls/getcwd_test.c b/test/libc/calls/getcwd_test.c index 4c9f5695f..e795d650a 100644 --- a/test/libc/calls/getcwd_test.c +++ b/test/libc/calls/getcwd_test.c @@ -21,7 +21,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/calls/ioctl_siocgifconf_test.c b/test/libc/calls/ioctl_siocgifconf_test.c index bc6e7e784..54c1372cd 100644 --- a/test/libc/calls/ioctl_siocgifconf_test.c +++ b/test/libc/calls/ioctl_siocgifconf_test.c @@ -23,7 +23,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/sock/sock.h" #include "libc/sock/struct/ifconf.h" #include "libc/sock/struct/ifreq.h" diff --git a/test/libc/calls/mkdir_test.c b/test/libc/calls/mkdir_test.c index bb34e0e02..783dea847 100644 --- a/test/libc/calls/mkdir_test.c +++ b/test/libc/calls/mkdir_test.c @@ -22,7 +22,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" diff --git a/test/libc/calls/mkntcmdline_test.c b/test/libc/calls/mkntcmdline_test.c index 74cbc1e5c..f470408bc 100644 --- a/test/libc/calls/mkntcmdline_test.c +++ b/test/libc/calls/mkntcmdline_test.c @@ -19,7 +19,7 @@ #include "libc/calls/ntspawn.h" #include "libc/errno.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/calls/mkntenvblock_test.c b/test/libc/calls/mkntenvblock_test.c index 505b789fb..6cd545462 100644 --- a/test/libc/calls/mkntenvblock_test.c +++ b/test/libc/calls/mkntenvblock_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/ntspawn.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" char tmp[ARG_MAX]; diff --git a/test/libc/calls/mkntpath_test.c b/test/libc/calls/mkntpath_test.c index 25caa3c22..999fd8abb 100644 --- a/test/libc/calls/mkntpath_test.c +++ b/test/libc/calls/mkntpath_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/calls/syscall_support-nt.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" char16_t p[PATH_MAX]; diff --git a/test/libc/calls/open_test.c b/test/libc/calls/open_test.c index d7cc6c8ba..b04c54f3c 100644 --- a/test/libc/calls/open_test.c +++ b/test/libc/calls/open_test.c @@ -21,7 +21,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/calls/pledge_test.c b/test/libc/calls/pledge_test.c index f10f5d894..11faa1cdc 100644 --- a/test/libc/calls/pledge_test.c +++ b/test/libc/calls/pledge_test.c @@ -30,7 +30,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/macros.internal.h" -#include "libc/mem/io.h" +#include "libc/calls/copyfd.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" diff --git a/test/libc/calls/poll_test.c b/test/libc/calls/poll_test.c index 3e7c8711e..4357222f6 100644 --- a/test/libc/calls/poll_test.c +++ b/test/libc/calls/poll_test.c @@ -18,13 +18,14 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/pledge.h" +#include "libc/calls/struct/sigaction.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/log/libfatal.internal.h" +#include "libc/mem/gc.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/nexgen32e/rdtscp.h" #include "libc/nt/synchronization.h" -#include "libc/runtime/gc.internal.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" #include "libc/sock/struct/sockaddr.h" @@ -36,6 +37,7 @@ #include "libc/sysv/consts/sock.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/test/test.h" #include "tool/decode/lib/flagger.h" #include "tool/decode/lib/pollnames.h" @@ -58,8 +60,8 @@ void OnSig(int sig) { dontdiscard char *FormatPollFd(struct pollfd p[2]) { return xasprintf("fd:%d revents:%s\n" "fd:%d revents:%s\n", - p[0].fd, gc(RecreateFlags(kPollNames, p[0].revents)), - p[1].fd, gc(RecreateFlags(kPollNames, p[1].revents))); + p[0].fd, _gc(RecreateFlags(kPollNames, p[0].revents)), + p[1].fd, _gc(RecreateFlags(kPollNames, p[1].revents))); } TEST(poll, allZero_doesNothingPrettyMuch) { @@ -97,7 +99,7 @@ TEST(poll, testNegativeOneFd_isIgnored) { EXPECT_SYS(0, 0, poll(fds, ARRAYLEN(fds), 1)); EXPECT_STREQ("fd:-1 revents:0\n" "fd:3 revents:0\n", - gc(FormatPollFd(&fds[0]))); + _gc(FormatPollFd(&fds[0]))); ASSERT_SYS(0, 0, close(3)); } diff --git a/test/libc/calls/readlinkat_test.c b/test/libc/calls/readlinkat_test.c index 9a323d744..9812a360c 100644 --- a/test/libc/calls/readlinkat_test.c +++ b/test/libc/calls/readlinkat_test.c @@ -18,9 +18,11 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" +#include "libc/dce.h" +#include "libc/errno.h" #include "libc/log/log.h" -#include "libc/runtime/gc.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" @@ -110,7 +112,7 @@ TEST(readlinkat, realpathReturnsLongPath) { struct stat st; char buf[PATH_MAX]; if (!IsWindows()) return; - if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return; + if (!_startswith(getcwd(buf, PATH_MAX), "/c/")) return; ASSERT_SYS(0, 0, touch("froot", 0644)); ASSERT_STARTSWITH("/c/", realpath("froot", buf)); } diff --git a/test/libc/calls/setrlimit_test.c b/test/libc/calls/setrlimit_test.c index 5fd00042b..5f8786256 100644 --- a/test/libc/calls/setrlimit_test.c +++ b/test/libc/calls/setrlimit_test.c @@ -38,7 +38,8 @@ #include "libc/sysv/consts/sig.h" #include "libc/testlib/testlib.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" +#include "libc/x/xspawn.h" #define MEM (64 * 1024 * 1024) diff --git a/test/libc/calls/sigsuspend_test.c b/test/libc/calls/sigsuspend_test.c index bf0a29504..2ced6f7de 100644 --- a/test/libc/calls/sigsuspend_test.c +++ b/test/libc/calls/sigsuspend_test.c @@ -17,6 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/struct/sigaction.h" +#include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/sigset.h" #include "libc/dce.h" #include "libc/errno.h" @@ -25,7 +27,7 @@ #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xspawn.h" volatile bool gotsig1; volatile bool gotsig2; diff --git a/test/libc/calls/stat_test.c b/test/libc/calls/stat_test.c index ec29205ce..cc1754054 100644 --- a/test/libc/calls/stat_test.c +++ b/test/libc/calls/stat_test.c @@ -23,7 +23,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/nt/files.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" diff --git a/test/libc/calls/unveil_test.c b/test/libc/calls/unveil_test.c index 9d43ddbe7..3642eb060 100644 --- a/test/libc/calls/unveil_test.c +++ b/test/libc/calls/unveil_test.c @@ -24,8 +24,8 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/kprintf.h" -#include "libc/mem/io.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" +#include "libc/calls/copyfd.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" @@ -43,6 +43,7 @@ #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define EACCES_OR_ENOENT (IsOpenbsd() ? ENOENT : EACCES) diff --git a/test/libc/calls/writev_test.c b/test/libc/calls/writev_test.c index 07996d666..04173f2e9 100644 --- a/test/libc/calls/writev_test.c +++ b/test/libc/calls/writev_test.c @@ -22,7 +22,7 @@ #include "libc/errno.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sysv/consts/auxv.h" diff --git a/test/libc/dns/dnsheader_test.c b/test/libc/dns/dnsheader_test.c index b91699674..712c1031e 100644 --- a/test/libc/dns/dnsheader_test.c +++ b/test/libc/dns/dnsheader_test.c @@ -20,7 +20,7 @@ #include "libc/dns/dnsheader.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/fmt/basename_test.c b/test/libc/fmt/basename_test.c index 62b833d38..c81f5edfe 100644 --- a/test/libc/fmt/basename_test.c +++ b/test/libc/fmt/basename_test.c @@ -19,7 +19,7 @@ #include "libc/intrin/bits.h" #include "libc/fmt/conv.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #define BASENAME(x) basename(gc(strdup(x))) diff --git a/test/libc/fmt/dirname_test.c b/test/libc/fmt/dirname_test.c index 42e089209..d634d6da3 100644 --- a/test/libc/fmt/dirname_test.c +++ b/test/libc/fmt/dirname_test.c @@ -20,7 +20,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" TEST(dirname, test) { diff --git a/test/libc/fmt/fmt_test.c b/test/libc/fmt/fmt_test.c index e1670084a..68fc3f545 100644 --- a/test/libc/fmt/fmt_test.c +++ b/test/libc/fmt/fmt_test.c @@ -20,279 +20,284 @@ #include "libc/limits.h" #include "libc/log/log.h" #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(fmt, d) { - EXPECT_STREQ("-123", gc(xasprintf("%d", -123))); - EXPECT_STREQ("-1", gc(xasprintf("%d", -1))); - EXPECT_STREQ("1", gc(xasprintf("%d", 1))); - EXPECT_STREQ("16", gc(xasprintf("%d", 16))); - EXPECT_STREQ("2147483647", gc(xasprintf("%d", INT_MAX))); - EXPECT_STREQ("-2147483648", gc(xasprintf("%d", INT_MIN))); - EXPECT_STREQ(" -123", gc(xasprintf("%10d", -123))); - EXPECT_STREQ(" -1", gc(xasprintf("%10d", -1))); - EXPECT_STREQ(" 1", gc(xasprintf("%10d", 1))); - EXPECT_STREQ(" 16", gc(xasprintf("%10d", 16))); - EXPECT_STREQ("2147483647", gc(xasprintf("%10d", INT_MAX))); - EXPECT_STREQ("-2147483648", gc(xasprintf("%10d", INT_MIN))); - EXPECT_STREQ("-000000123", gc(xasprintf("%010d", -123))); - EXPECT_STREQ("-000000001", gc(xasprintf("%010d", -1))); - EXPECT_STREQ("0000000001", gc(xasprintf("%010d", 1))); - EXPECT_STREQ("0000000016", gc(xasprintf("%010d", 16))); - EXPECT_STREQ("2147483647", gc(xasprintf("%010d", INT_MAX))); - EXPECT_STREQ("-2147483648", gc(xasprintf("%010d", INT_MIN))); - EXPECT_STREQ("-123 ", gc(xasprintf("%-10d", -123))); - EXPECT_STREQ("-1 ", gc(xasprintf("%-10d", -1))); - EXPECT_STREQ("1 ", gc(xasprintf("%-10d", 1))); - EXPECT_STREQ("16 ", gc(xasprintf("%-10d", 16))); - EXPECT_STREQ("2147483647", gc(xasprintf("%-10d", INT_MAX))); - EXPECT_STREQ("-2147483648", gc(xasprintf("%-10d", INT_MIN))); - EXPECT_STREQ(" -123", gc(xasprintf("%+10d", -123))); - EXPECT_STREQ(" -1", gc(xasprintf("%+10d", -1))); - EXPECT_STREQ(" +1", gc(xasprintf("%+10d", 1))); - EXPECT_STREQ(" +16", gc(xasprintf("%+10d", 16))); - EXPECT_STREQ("+2147483647", gc(xasprintf("%+10d", INT_MAX))); - EXPECT_STREQ("-2147483648", gc(xasprintf("%+10d", INT_MIN))); - EXPECT_STREQ("-123", gc(xasprintf("% d", -123))); - EXPECT_STREQ("-1", gc(xasprintf("% d", -1))); - EXPECT_STREQ(" 1", gc(xasprintf("% d", 1))); - EXPECT_STREQ(" 16", gc(xasprintf("% d", 16))); - EXPECT_STREQ(" 2147483647", gc(xasprintf("% d", INT_MAX))); - EXPECT_STREQ("-2147483648", gc(xasprintf("% d", INT_MIN))); + EXPECT_STREQ("-123", _gc(xasprintf("%d", -123))); + EXPECT_STREQ("-1", _gc(xasprintf("%d", -1))); + EXPECT_STREQ("1", _gc(xasprintf("%d", 1))); + EXPECT_STREQ("16", _gc(xasprintf("%d", 16))); + EXPECT_STREQ("2147483647", _gc(xasprintf("%d", INT_MAX))); + EXPECT_STREQ("-2147483648", _gc(xasprintf("%d", INT_MIN))); + EXPECT_STREQ(" -123", _gc(xasprintf("%10d", -123))); + EXPECT_STREQ(" -1", _gc(xasprintf("%10d", -1))); + EXPECT_STREQ(" 1", _gc(xasprintf("%10d", 1))); + EXPECT_STREQ(" 16", _gc(xasprintf("%10d", 16))); + EXPECT_STREQ("2147483647", _gc(xasprintf("%10d", INT_MAX))); + EXPECT_STREQ("-2147483648", _gc(xasprintf("%10d", INT_MIN))); + EXPECT_STREQ("-000000123", _gc(xasprintf("%010d", -123))); + EXPECT_STREQ("-000000001", _gc(xasprintf("%010d", -1))); + EXPECT_STREQ("0000000001", _gc(xasprintf("%010d", 1))); + EXPECT_STREQ("0000000016", _gc(xasprintf("%010d", 16))); + EXPECT_STREQ("2147483647", _gc(xasprintf("%010d", INT_MAX))); + EXPECT_STREQ("-2147483648", _gc(xasprintf("%010d", INT_MIN))); + EXPECT_STREQ("-123 ", _gc(xasprintf("%-10d", -123))); + EXPECT_STREQ("-1 ", _gc(xasprintf("%-10d", -1))); + EXPECT_STREQ("1 ", _gc(xasprintf("%-10d", 1))); + EXPECT_STREQ("16 ", _gc(xasprintf("%-10d", 16))); + EXPECT_STREQ("2147483647", _gc(xasprintf("%-10d", INT_MAX))); + EXPECT_STREQ("-2147483648", _gc(xasprintf("%-10d", INT_MIN))); + EXPECT_STREQ(" -123", _gc(xasprintf("%+10d", -123))); + EXPECT_STREQ(" -1", _gc(xasprintf("%+10d", -1))); + EXPECT_STREQ(" +1", _gc(xasprintf("%+10d", 1))); + EXPECT_STREQ(" +16", _gc(xasprintf("%+10d", 16))); + EXPECT_STREQ("+2147483647", _gc(xasprintf("%+10d", INT_MAX))); + EXPECT_STREQ("-2147483648", _gc(xasprintf("%+10d", INT_MIN))); + EXPECT_STREQ("-123", _gc(xasprintf("% d", -123))); + EXPECT_STREQ("-1", _gc(xasprintf("% d", -1))); + EXPECT_STREQ(" 1", _gc(xasprintf("% d", 1))); + EXPECT_STREQ(" 16", _gc(xasprintf("% d", 16))); + EXPECT_STREQ(" 2147483647", _gc(xasprintf("% d", INT_MAX))); + EXPECT_STREQ("-2147483648", _gc(xasprintf("% d", INT_MIN))); } TEST(fmt, g) { - EXPECT_STREQ("1", gc(xasprintf("%g", 1.))); - EXPECT_STREQ(" 1", gc(xasprintf("% g", 1.))); - EXPECT_STREQ("+1", gc(xasprintf("%+g", 1.))); - EXPECT_STREQ("-1", gc(xasprintf("%g", -1.))); - EXPECT_STREQ("10", gc(xasprintf("%g", 10.))); - EXPECT_STREQ("-10", gc(xasprintf("%g", -10.))); - EXPECT_STREQ("1e+01", gc(xasprintf("%.0g", 10.))); - EXPECT_STREQ("-1e+01", gc(xasprintf("%.0g", -10.))); - EXPECT_STREQ("1", gc(xasprintf("%.0g", 1.0))); - EXPECT_STREQ("1e-05", gc(xasprintf("%.0g", 0.00001))); - EXPECT_STREQ("0.0001", gc(xasprintf("%.0g", 0.0001))); - EXPECT_STREQ("1e+01", gc(xasprintf("%.1g", 10.))); - EXPECT_STREQ("-1e+01", gc(xasprintf("%.1g", -10.))); - EXPECT_STREQ("1", gc(xasprintf("%.1g", 1.0))); - EXPECT_STREQ("1e-05", gc(xasprintf("%.1g", 0.00001))); - EXPECT_STREQ("0.0001", gc(xasprintf("%.1g", 0.0001))); - EXPECT_STREQ("0.007812", gc(xasprintf("%.4g", 0.0078125))); - EXPECT_STREQ("0.023438", gc(xasprintf("%.5g", 0.0234375))); - EXPECT_STREQ("1e+100", gc(xasprintf("%g", 1e100))); - EXPECT_STREQ("1e-100", gc(xasprintf("%g", 1e-100))); - EXPECT_STREQ("-1e-100", gc(xasprintf("%g", -1e-100))); - EXPECT_STREQ("0.123456", gc(xasprintf("%g", 0.1234564))); - EXPECT_STREQ("0.123457", gc(xasprintf("%g", 0.1234566))); - EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1))); - EXPECT_STREQ("0", gc(xasprintf("%g", 0.))); - EXPECT_STREQ("-0", gc(xasprintf("%g", -0.))); - EXPECT_STREQ("nan", gc(xasprintf("%g", NAN))); - EXPECT_STREQ("-nan", gc(xasprintf("%g", -NAN))); - EXPECT_STREQ("inf", gc(xasprintf("%g", INFINITY))); - EXPECT_STREQ("-inf", gc(xasprintf("%g", -INFINITY))); - EXPECT_STREQ("2.22507e-308", gc(xasprintf("%g", __DBL_MIN__))); - EXPECT_STREQ("1.79769e+308", gc(xasprintf("%g", __DBL_MAX__))); - EXPECT_STREQ("0", gc(xasprintf("%G", 0.))); - EXPECT_STREQ("-0", gc(xasprintf("%G", -0.))); - EXPECT_STREQ("NAN", gc(xasprintf("%G", NAN))); - EXPECT_STREQ("-NAN", gc(xasprintf("%G", -NAN))); - EXPECT_STREQ("INF", gc(xasprintf("%G", INFINITY))); - EXPECT_STREQ("-INF", gc(xasprintf("%G", -INFINITY))); - EXPECT_STREQ("2.22507E-308", gc(xasprintf("%G", __DBL_MIN__))); - EXPECT_STREQ("1.79769E+308", gc(xasprintf("%G", __DBL_MAX__))); - EXPECT_STREQ(" 0", gc(xasprintf("%13g", 0.))); - EXPECT_STREQ(" -0", gc(xasprintf("%13g", -0.))); - EXPECT_STREQ(" nan", gc(xasprintf("%13g", NAN))); - EXPECT_STREQ(" -nan", gc(xasprintf("%13g", -NAN))); - EXPECT_STREQ(" inf", gc(xasprintf("%13g", INFINITY))); - EXPECT_STREQ(" -inf", gc(xasprintf("%13g", -INFINITY))); - EXPECT_STREQ(" 2.22507e-308", gc(xasprintf("%13g", __DBL_MIN__))); - EXPECT_STREQ(" 1.79769e+308", gc(xasprintf("%13g", __DBL_MAX__))); - EXPECT_STREQ(" 0", gc(xasprintf("%13G", 0.))); - EXPECT_STREQ(" -0", gc(xasprintf("%13G", -0.))); - EXPECT_STREQ(" NAN", gc(xasprintf("%13G", NAN))); - EXPECT_STREQ(" -NAN", gc(xasprintf("%13G", -NAN))); - EXPECT_STREQ(" INF", gc(xasprintf("%13G", INFINITY))); - EXPECT_STREQ(" -INF", gc(xasprintf("%13G", -INFINITY))); - EXPECT_STREQ(" 2.22507E-308", gc(xasprintf("%13G", __DBL_MIN__))); - EXPECT_STREQ(" 1.79769E+308", gc(xasprintf("%13G", __DBL_MAX__))); + EXPECT_STREQ("1", _gc(xasprintf("%g", 1.))); + EXPECT_STREQ(" 1", _gc(xasprintf("% g", 1.))); + EXPECT_STREQ("+1", _gc(xasprintf("%+g", 1.))); + EXPECT_STREQ("-1", _gc(xasprintf("%g", -1.))); + EXPECT_STREQ("10", _gc(xasprintf("%g", 10.))); + EXPECT_STREQ("-10", _gc(xasprintf("%g", -10.))); + EXPECT_STREQ("1e+01", _gc(xasprintf("%.0g", 10.))); + EXPECT_STREQ("-1e+01", _gc(xasprintf("%.0g", -10.))); + EXPECT_STREQ("1", _gc(xasprintf("%.0g", 1.0))); + EXPECT_STREQ("1e-05", _gc(xasprintf("%.0g", 0.00001))); + EXPECT_STREQ("0.0001", _gc(xasprintf("%.0g", 0.0001))); + EXPECT_STREQ("1e+01", _gc(xasprintf("%.1g", 10.))); + EXPECT_STREQ("-1e+01", _gc(xasprintf("%.1g", -10.))); + EXPECT_STREQ("1", _gc(xasprintf("%.1g", 1.0))); + EXPECT_STREQ("1e-05", _gc(xasprintf("%.1g", 0.00001))); + EXPECT_STREQ("0.0001", _gc(xasprintf("%.1g", 0.0001))); + EXPECT_STREQ("0.007812", _gc(xasprintf("%.4g", 0.0078125))); + EXPECT_STREQ("0.023438", _gc(xasprintf("%.5g", 0.0234375))); + EXPECT_STREQ("1e+100", _gc(xasprintf("%g", 1e100))); + EXPECT_STREQ("1e-100", _gc(xasprintf("%g", 1e-100))); + EXPECT_STREQ("-1e-100", _gc(xasprintf("%g", -1e-100))); + EXPECT_STREQ("0.123456", _gc(xasprintf("%g", 0.1234564))); + EXPECT_STREQ("0.123457", _gc(xasprintf("%g", 0.1234566))); + EXPECT_STREQ("3.14159", _gc(xasprintf("%g", 0x1.921fb54442d1846ap+1))); + EXPECT_STREQ("0", _gc(xasprintf("%g", 0.))); + EXPECT_STREQ("-0", _gc(xasprintf("%g", -0.))); + EXPECT_STREQ("nan", _gc(xasprintf("%g", NAN))); + EXPECT_STREQ("-nan", _gc(xasprintf("%g", -NAN))); + EXPECT_STREQ("inf", _gc(xasprintf("%g", INFINITY))); + EXPECT_STREQ("-inf", _gc(xasprintf("%g", -INFINITY))); + EXPECT_STREQ("2.22507e-308", _gc(xasprintf("%g", __DBL_MIN__))); + EXPECT_STREQ("1.79769e+308", _gc(xasprintf("%g", __DBL_MAX__))); + EXPECT_STREQ("0", _gc(xasprintf("%G", 0.))); + EXPECT_STREQ("-0", _gc(xasprintf("%G", -0.))); + EXPECT_STREQ("NAN", _gc(xasprintf("%G", NAN))); + EXPECT_STREQ("-NAN", _gc(xasprintf("%G", -NAN))); + EXPECT_STREQ("INF", _gc(xasprintf("%G", INFINITY))); + EXPECT_STREQ("-INF", _gc(xasprintf("%G", -INFINITY))); + EXPECT_STREQ("2.22507E-308", _gc(xasprintf("%G", __DBL_MIN__))); + EXPECT_STREQ("1.79769E+308", _gc(xasprintf("%G", __DBL_MAX__))); + EXPECT_STREQ(" 0", _gc(xasprintf("%13g", 0.))); + EXPECT_STREQ(" -0", _gc(xasprintf("%13g", -0.))); + EXPECT_STREQ(" nan", _gc(xasprintf("%13g", NAN))); + EXPECT_STREQ(" -nan", _gc(xasprintf("%13g", -NAN))); + EXPECT_STREQ(" inf", _gc(xasprintf("%13g", INFINITY))); + EXPECT_STREQ(" -inf", _gc(xasprintf("%13g", -INFINITY))); + EXPECT_STREQ(" 2.22507e-308", _gc(xasprintf("%13g", __DBL_MIN__))); + EXPECT_STREQ(" 1.79769e+308", _gc(xasprintf("%13g", __DBL_MAX__))); + EXPECT_STREQ(" 0", _gc(xasprintf("%13G", 0.))); + EXPECT_STREQ(" -0", _gc(xasprintf("%13G", -0.))); + EXPECT_STREQ(" NAN", _gc(xasprintf("%13G", NAN))); + EXPECT_STREQ(" -NAN", _gc(xasprintf("%13G", -NAN))); + EXPECT_STREQ(" INF", _gc(xasprintf("%13G", INFINITY))); + EXPECT_STREQ(" -INF", _gc(xasprintf("%13G", -INFINITY))); + EXPECT_STREQ(" 2.22507E-308", _gc(xasprintf("%13G", __DBL_MIN__))); + EXPECT_STREQ(" 1.79769E+308", _gc(xasprintf("%13G", __DBL_MAX__))); } TEST(fmt, f) { - EXPECT_STREQ("3.141593", gc(xasprintf("%f", 0x1.921fb54442d1846ap+1))); + EXPECT_STREQ("3.141593", _gc(xasprintf("%f", 0x1.921fb54442d1846ap+1))); EXPECT_STREQ("3.1415926535897931", - gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1))); + _gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1))); EXPECT_STREQ("100000000000000001590289110975991804683608085639452813" "89781327557747838772170381060813469985856815104.000000", - gc(xasprintf("%f", 1e100))); - EXPECT_STREQ("0.000000", gc(xasprintf("%f", 0.))); - EXPECT_STREQ("-0.000000", gc(xasprintf("%f", -0.))); - EXPECT_STREQ("nan", gc(xasprintf("%f", NAN))); - EXPECT_STREQ("-nan", gc(xasprintf("%f", -NAN))); - EXPECT_STREQ("inf", gc(xasprintf("%f", INFINITY))); - EXPECT_STREQ("-inf", gc(xasprintf("%f", -INFINITY))); - EXPECT_STREQ("0.000000", gc(xasprintf("%f", __DBL_MIN__))); + _gc(xasprintf("%f", 1e100))); + EXPECT_STREQ("0.000000", _gc(xasprintf("%f", 0.))); + EXPECT_STREQ("-0.000000", _gc(xasprintf("%f", -0.))); + EXPECT_STREQ("nan", _gc(xasprintf("%f", NAN))); + EXPECT_STREQ("-nan", _gc(xasprintf("%f", -NAN))); + EXPECT_STREQ("inf", _gc(xasprintf("%f", INFINITY))); + EXPECT_STREQ("-inf", _gc(xasprintf("%f", -INFINITY))); + EXPECT_STREQ("0.000000", _gc(xasprintf("%f", __DBL_MIN__))); EXPECT_STREQ( "179769313486231570814527423731704356798070567525844996598917476803157260" "780028538760589558632766878171540458953514382464234321326889464182768467" "546703537516986049910576551282076245490090389328944075868508455133942304" "583236903222948165808559332123348274797826204144723168738177180919299881" "250404026184124858368.000000", - gc(xasprintf("%f", __DBL_MAX__))); - EXPECT_STREQ("0.000000", gc(xasprintf("%F", 0.))); - EXPECT_STREQ("-0.000000", gc(xasprintf("%F", -0.))); - EXPECT_STREQ("NAN", gc(xasprintf("%F", NAN))); - EXPECT_STREQ("-NAN", gc(xasprintf("%F", -NAN))); - EXPECT_STREQ("INF", gc(xasprintf("%F", INFINITY))); - EXPECT_STREQ("-INF", gc(xasprintf("%F", -INFINITY))); - EXPECT_STREQ("0.000000", gc(xasprintf("%F", __DBL_MIN__))); + _gc(xasprintf("%f", __DBL_MAX__))); + EXPECT_STREQ("0.000000", _gc(xasprintf("%F", 0.))); + EXPECT_STREQ("-0.000000", _gc(xasprintf("%F", -0.))); + EXPECT_STREQ("NAN", _gc(xasprintf("%F", NAN))); + EXPECT_STREQ("-NAN", _gc(xasprintf("%F", -NAN))); + EXPECT_STREQ("INF", _gc(xasprintf("%F", INFINITY))); + EXPECT_STREQ("-INF", _gc(xasprintf("%F", -INFINITY))); + EXPECT_STREQ("0.000000", _gc(xasprintf("%F", __DBL_MIN__))); EXPECT_STREQ( "179769313486231570814527423731704356798070567525844996598917476803157260" "780028538760589558632766878171540458953514382464234321326889464182768467" "546703537516986049910576551282076245490090389328944075868508455133942304" "583236903222948165808559332123348274797826204144723168738177180919299881" "250404026184124858368.000000", - gc(xasprintf("%F", __DBL_MAX__))); - EXPECT_STREQ(" 0.000000", gc(xasprintf("%10f", 0.))); - EXPECT_STREQ(" -0.000000", gc(xasprintf("%10f", -0.))); - EXPECT_STREQ(" nan", gc(xasprintf("%10f", NAN))); - EXPECT_STREQ(" -nan", gc(xasprintf("%10f", -NAN))); - EXPECT_STREQ(" inf", gc(xasprintf("%10f", INFINITY))); - EXPECT_STREQ(" -inf", gc(xasprintf("%10f", -INFINITY))); - EXPECT_STREQ(" 0.000000", gc(xasprintf("%10f", __DBL_MIN__))); + _gc(xasprintf("%F", __DBL_MAX__))); + EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10f", 0.))); + EXPECT_STREQ(" -0.000000", _gc(xasprintf("%10f", -0.))); + EXPECT_STREQ(" nan", _gc(xasprintf("%10f", NAN))); + EXPECT_STREQ(" -nan", _gc(xasprintf("%10f", -NAN))); + EXPECT_STREQ(" inf", _gc(xasprintf("%10f", INFINITY))); + EXPECT_STREQ(" -inf", _gc(xasprintf("%10f", -INFINITY))); + EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10f", __DBL_MIN__))); EXPECT_STREQ( "179769313486231570814527423731704356798070567525844996598917476803157260" "780028538760589558632766878171540458953514382464234321326889464182768467" "546703537516986049910576551282076245490090389328944075868508455133942304" "583236903222948165808559332123348274797826204144723168738177180919299881" "250404026184124858368.000000", - gc(xasprintf("%10f", __DBL_MAX__))); - EXPECT_STREQ(" 0.000000", gc(xasprintf("%10F", 0.))); - EXPECT_STREQ(" -0.000000", gc(xasprintf("%10F", -0.))); - EXPECT_STREQ(" NAN", gc(xasprintf("%10F", NAN))); - EXPECT_STREQ(" -NAN", gc(xasprintf("%10F", -NAN))); - EXPECT_STREQ(" INF", gc(xasprintf("%10F", INFINITY))); - EXPECT_STREQ(" -INF", gc(xasprintf("%10F", -INFINITY))); - EXPECT_STREQ(" 0.000000", gc(xasprintf("%10F", __DBL_MIN__))); + _gc(xasprintf("%10f", __DBL_MAX__))); + EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10F", 0.))); + EXPECT_STREQ(" -0.000000", _gc(xasprintf("%10F", -0.))); + EXPECT_STREQ(" NAN", _gc(xasprintf("%10F", NAN))); + EXPECT_STREQ(" -NAN", _gc(xasprintf("%10F", -NAN))); + EXPECT_STREQ(" INF", _gc(xasprintf("%10F", INFINITY))); + EXPECT_STREQ(" -INF", _gc(xasprintf("%10F", -INFINITY))); + EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10F", __DBL_MIN__))); EXPECT_STREQ( "179769313486231570814527423731704356798070567525844996598917476803157260" "780028538760589558632766878171540458953514382464234321326889464182768467" "546703537516986049910576551282076245490090389328944075868508455133942304" "583236903222948165808559332123348274797826204144723168738177180919299881" "250404026184124858368.000000", - gc(xasprintf("%10F", __DBL_MAX__))); + _gc(xasprintf("%10F", __DBL_MAX__))); } TEST(fmt, e) { - EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1))); + EXPECT_STREQ("3.14159", _gc(xasprintf("%g", 0x1.921fb54442d1846ap+1))); EXPECT_STREQ("3.141592653589793", - gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1))); - EXPECT_STREQ("1.000000e+100", gc(xasprintf("%e", 1e100))); - EXPECT_STREQ("1.000000E+100", gc(xasprintf("%E", 1e100))); - EXPECT_STREQ(" 0.000000e+00", gc(xasprintf("%24e", 0.))); - EXPECT_STREQ(" -0.000000e+00", gc(xasprintf("%24e", -0.))); - EXPECT_STREQ(" nan", gc(xasprintf("%24e", NAN))); - EXPECT_STREQ(" -nan", gc(xasprintf("%24e", -NAN))); - EXPECT_STREQ(" inf", gc(xasprintf("%24e", INFINITY))); - EXPECT_STREQ(" -inf", gc(xasprintf("%24e", -INFINITY))); - EXPECT_STREQ(" 2.225074e-308", gc(xasprintf("%24e", __DBL_MIN__))); - EXPECT_STREQ(" 1.797693e+308", gc(xasprintf("%24e", __DBL_MAX__))); - EXPECT_STREQ(" 0.000000E+00", gc(xasprintf("%24E", 0.))); - EXPECT_STREQ(" -0.000000E+00", gc(xasprintf("%24E", -0.))); - EXPECT_STREQ(" NAN", gc(xasprintf("%24E", NAN))); - EXPECT_STREQ(" -NAN", gc(xasprintf("%24E", -NAN))); - EXPECT_STREQ(" INF", gc(xasprintf("%24E", INFINITY))); - EXPECT_STREQ(" -INF", gc(xasprintf("%24E", -INFINITY))); - EXPECT_STREQ(" 2.225074E-308", gc(xasprintf("%24E", __DBL_MIN__))); - EXPECT_STREQ(" 1.797693E+308", gc(xasprintf("%24E", __DBL_MAX__))); - EXPECT_STREQ(" +0.000000e+00", gc(xasprintf("%+24e", 0.))); - EXPECT_STREQ(" -0.000000e+00", gc(xasprintf("%+24e", -0.))); - EXPECT_STREQ(" +nan", gc(xasprintf("%+24e", NAN))); - EXPECT_STREQ(" -nan", gc(xasprintf("%+24e", -NAN))); - EXPECT_STREQ(" +inf", gc(xasprintf("%+24e", INFINITY))); - EXPECT_STREQ(" -inf", gc(xasprintf("%+24e", -INFINITY))); - EXPECT_STREQ(" +2.225074e-308", gc(xasprintf("%+24e", __DBL_MIN__))); - EXPECT_STREQ(" +1.797693e+308", gc(xasprintf("%+24e", __DBL_MAX__))); - EXPECT_STREQ(" +0.000000E+00", gc(xasprintf("%+24E", 0.))); - EXPECT_STREQ(" -0.000000E+00", gc(xasprintf("%+24E", -0.))); - EXPECT_STREQ(" +NAN", gc(xasprintf("%+24E", NAN))); - EXPECT_STREQ(" -NAN", gc(xasprintf("%+24E", -NAN))); - EXPECT_STREQ(" +INF", gc(xasprintf("%+24E", INFINITY))); - EXPECT_STREQ(" -INF", gc(xasprintf("%+24E", -INFINITY))); - EXPECT_STREQ(" +2.225074E-308", gc(xasprintf("%+24E", __DBL_MIN__))); - EXPECT_STREQ(" +1.797693E+308", gc(xasprintf("%+24E", __DBL_MAX__))); + _gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1))); + EXPECT_STREQ("1.000000e+100", _gc(xasprintf("%e", 1e100))); + EXPECT_STREQ("1.000000E+100", _gc(xasprintf("%E", 1e100))); + EXPECT_STREQ(" 0.000000e+00", _gc(xasprintf("%24e", 0.))); + EXPECT_STREQ(" -0.000000e+00", _gc(xasprintf("%24e", -0.))); + EXPECT_STREQ(" nan", _gc(xasprintf("%24e", NAN))); + EXPECT_STREQ(" -nan", _gc(xasprintf("%24e", -NAN))); + EXPECT_STREQ(" inf", _gc(xasprintf("%24e", INFINITY))); + EXPECT_STREQ(" -inf", _gc(xasprintf("%24e", -INFINITY))); + EXPECT_STREQ(" 2.225074e-308", _gc(xasprintf("%24e", __DBL_MIN__))); + EXPECT_STREQ(" 1.797693e+308", _gc(xasprintf("%24e", __DBL_MAX__))); + EXPECT_STREQ(" 0.000000E+00", _gc(xasprintf("%24E", 0.))); + EXPECT_STREQ(" -0.000000E+00", _gc(xasprintf("%24E", -0.))); + EXPECT_STREQ(" NAN", _gc(xasprintf("%24E", NAN))); + EXPECT_STREQ(" -NAN", _gc(xasprintf("%24E", -NAN))); + EXPECT_STREQ(" INF", _gc(xasprintf("%24E", INFINITY))); + EXPECT_STREQ(" -INF", _gc(xasprintf("%24E", -INFINITY))); + EXPECT_STREQ(" 2.225074E-308", _gc(xasprintf("%24E", __DBL_MIN__))); + EXPECT_STREQ(" 1.797693E+308", _gc(xasprintf("%24E", __DBL_MAX__))); + EXPECT_STREQ(" +0.000000e+00", _gc(xasprintf("%+24e", 0.))); + EXPECT_STREQ(" -0.000000e+00", _gc(xasprintf("%+24e", -0.))); + EXPECT_STREQ(" +nan", _gc(xasprintf("%+24e", NAN))); + EXPECT_STREQ(" -nan", _gc(xasprintf("%+24e", -NAN))); + EXPECT_STREQ(" +inf", _gc(xasprintf("%+24e", INFINITY))); + EXPECT_STREQ(" -inf", _gc(xasprintf("%+24e", -INFINITY))); + EXPECT_STREQ(" +2.225074e-308", + _gc(xasprintf("%+24e", __DBL_MIN__))); + EXPECT_STREQ(" +1.797693e+308", + _gc(xasprintf("%+24e", __DBL_MAX__))); + EXPECT_STREQ(" +0.000000E+00", _gc(xasprintf("%+24E", 0.))); + EXPECT_STREQ(" -0.000000E+00", _gc(xasprintf("%+24E", -0.))); + EXPECT_STREQ(" +NAN", _gc(xasprintf("%+24E", NAN))); + EXPECT_STREQ(" -NAN", _gc(xasprintf("%+24E", -NAN))); + EXPECT_STREQ(" +INF", _gc(xasprintf("%+24E", INFINITY))); + EXPECT_STREQ(" -INF", _gc(xasprintf("%+24E", -INFINITY))); + EXPECT_STREQ(" +2.225074E-308", + _gc(xasprintf("%+24E", __DBL_MIN__))); + EXPECT_STREQ(" +1.797693E+308", + _gc(xasprintf("%+24E", __DBL_MAX__))); } TEST(fmt, a) { EXPECT_STREQ("0x1.921fb54442d18p+1", - gc(xasprintf("%a", 0x1.921fb54442d1846ap+1))); + _gc(xasprintf("%a", 0x1.921fb54442d1846ap+1))); EXPECT_STREQ("0X1.921FB54442D18P+1", - gc(xasprintf("%A", 0x1.921fb54442d1846ap+1))); - EXPECT_STREQ(" 0x0p+0", gc(xasprintf("%24a", 0.))); - EXPECT_STREQ(" -0x0p+0", gc(xasprintf("%24a", -0.))); - EXPECT_STREQ(" nan", gc(xasprintf("%24a", NAN))); - EXPECT_STREQ(" -nan", gc(xasprintf("%24a", -NAN))); - EXPECT_STREQ(" inf", gc(xasprintf("%24a", INFINITY))); - EXPECT_STREQ(" -inf", gc(xasprintf("%24a", -INFINITY))); - EXPECT_STREQ(" 0x1p-1022", gc(xasprintf("%24a", __DBL_MIN__))); - EXPECT_STREQ(" 0x1.fffffffffffffp+1023", gc(xasprintf("%24a", __DBL_MAX__))); - EXPECT_STREQ(" 0X0P+0", gc(xasprintf("%24A", 0.))); - EXPECT_STREQ(" -0X0P+0", gc(xasprintf("%24A", -0.))); - EXPECT_STREQ(" NAN", gc(xasprintf("%24A", NAN))); - EXPECT_STREQ(" -NAN", gc(xasprintf("%24A", -NAN))); - EXPECT_STREQ(" INF", gc(xasprintf("%24A", INFINITY))); - EXPECT_STREQ(" -INF", gc(xasprintf("%24A", -INFINITY))); - EXPECT_STREQ(" 0X1P-1022", gc(xasprintf("%24A", __DBL_MIN__))); - EXPECT_STREQ(" 0X1.FFFFFFFFFFFFFP+1023", gc(xasprintf("%24A", __DBL_MAX__))); - EXPECT_STREQ(" 0X1.E9A488E8A71DEP+14", gc(xasprintf("%24A", 31337.1337))); - EXPECT_STREQ(" -0X1.E9A488E8A71DEP+14", gc(xasprintf("%24A", -31337.1337))); + _gc(xasprintf("%A", 0x1.921fb54442d1846ap+1))); + EXPECT_STREQ(" 0x0p+0", _gc(xasprintf("%24a", 0.))); + EXPECT_STREQ(" -0x0p+0", _gc(xasprintf("%24a", -0.))); + EXPECT_STREQ(" nan", _gc(xasprintf("%24a", NAN))); + EXPECT_STREQ(" -nan", _gc(xasprintf("%24a", -NAN))); + EXPECT_STREQ(" inf", _gc(xasprintf("%24a", INFINITY))); + EXPECT_STREQ(" -inf", _gc(xasprintf("%24a", -INFINITY))); + EXPECT_STREQ(" 0x1p-1022", _gc(xasprintf("%24a", __DBL_MIN__))); + EXPECT_STREQ(" 0x1.fffffffffffffp+1023", _gc(xasprintf("%24a", __DBL_MAX__))); + EXPECT_STREQ(" 0X0P+0", _gc(xasprintf("%24A", 0.))); + EXPECT_STREQ(" -0X0P+0", _gc(xasprintf("%24A", -0.))); + EXPECT_STREQ(" NAN", _gc(xasprintf("%24A", NAN))); + EXPECT_STREQ(" -NAN", _gc(xasprintf("%24A", -NAN))); + EXPECT_STREQ(" INF", _gc(xasprintf("%24A", INFINITY))); + EXPECT_STREQ(" -INF", _gc(xasprintf("%24A", -INFINITY))); + EXPECT_STREQ(" 0X1P-1022", _gc(xasprintf("%24A", __DBL_MIN__))); + EXPECT_STREQ(" 0X1.FFFFFFFFFFFFFP+1023", _gc(xasprintf("%24A", __DBL_MAX__))); + EXPECT_STREQ(" 0X1.E9A488E8A71DEP+14", _gc(xasprintf("%24A", 31337.1337))); + EXPECT_STREQ(" -0X1.E9A488E8A71DEP+14", _gc(xasprintf("%24A", -31337.1337))); } TEST(fmt, p) { - EXPECT_STREQ("0x1", gc(xasprintf("%p", 1))); - EXPECT_STREQ("0x10", gc(xasprintf("%p", 16))); - EXPECT_STREQ("0x31337", gc(xasprintf("%p", 0x31337))); - EXPECT_STREQ("0xffffffff", gc(xasprintf("%p", 0xffffffff))); - EXPECT_STREQ("0xffff800000031337", gc(xasprintf("%p", 0xffff800000031337))); - EXPECT_STREQ(" 0x1", gc(xasprintf("%10p", 1))); - EXPECT_STREQ(" 0x10", gc(xasprintf("%10p", 16))); - EXPECT_STREQ(" 0x31337", gc(xasprintf("%10p", 0x31337))); - EXPECT_STREQ("0xffffffff", gc(xasprintf("%10p", 0xffffffff))); - EXPECT_STREQ("0xffff800000031337", gc(xasprintf("%10p", 0xffff800000031337))); - EXPECT_STREQ("0x00000001", gc(xasprintf("%010p", 1))); - EXPECT_STREQ("0x00000010", gc(xasprintf("%010p", 16))); - EXPECT_STREQ("0x00031337", gc(xasprintf("%010p", 0x31337))); - EXPECT_STREQ("0xffffffff", gc(xasprintf("%010p", 0xffffffff))); + EXPECT_STREQ("0x1", _gc(xasprintf("%p", 1))); + EXPECT_STREQ("0x10", _gc(xasprintf("%p", 16))); + EXPECT_STREQ("0x31337", _gc(xasprintf("%p", 0x31337))); + EXPECT_STREQ("0xffffffff", _gc(xasprintf("%p", 0xffffffff))); + EXPECT_STREQ("0xffff800000031337", _gc(xasprintf("%p", 0xffff800000031337))); + EXPECT_STREQ(" 0x1", _gc(xasprintf("%10p", 1))); + EXPECT_STREQ(" 0x10", _gc(xasprintf("%10p", 16))); + EXPECT_STREQ(" 0x31337", _gc(xasprintf("%10p", 0x31337))); + EXPECT_STREQ("0xffffffff", _gc(xasprintf("%10p", 0xffffffff))); EXPECT_STREQ("0xffff800000031337", - gc(xasprintf("%010p", 0xffff800000031337))); - EXPECT_STREQ("0x1 ", gc(xasprintf("%-10p", 1))); - EXPECT_STREQ("0x10 ", gc(xasprintf("%-10p", 16))); - EXPECT_STREQ("0x31337 ", gc(xasprintf("%-10p", 0x31337))); - EXPECT_STREQ("0xffffffff", gc(xasprintf("%-10p", 0xffffffff))); + _gc(xasprintf("%10p", 0xffff800000031337))); + EXPECT_STREQ("0x00000001", _gc(xasprintf("%010p", 1))); + EXPECT_STREQ("0x00000010", _gc(xasprintf("%010p", 16))); + EXPECT_STREQ("0x00031337", _gc(xasprintf("%010p", 0x31337))); + EXPECT_STREQ("0xffffffff", _gc(xasprintf("%010p", 0xffffffff))); EXPECT_STREQ("0xffff800000031337", - gc(xasprintf("%-10p", 0xffff800000031337))); - EXPECT_STREQ(" 0x1", gc(xasprintf("%+10p", 1))); - EXPECT_STREQ(" 0x10", gc(xasprintf("%+10p", 16))); - EXPECT_STREQ(" 0x31337", gc(xasprintf("%+10p", 0x31337))); - EXPECT_STREQ("0xffffffff", gc(xasprintf("%+10p", 0xffffffff))); + _gc(xasprintf("%010p", 0xffff800000031337))); + EXPECT_STREQ("0x1 ", _gc(xasprintf("%-10p", 1))); + EXPECT_STREQ("0x10 ", _gc(xasprintf("%-10p", 16))); + EXPECT_STREQ("0x31337 ", _gc(xasprintf("%-10p", 0x31337))); + EXPECT_STREQ("0xffffffff", _gc(xasprintf("%-10p", 0xffffffff))); EXPECT_STREQ("0xffff800000031337", - gc(xasprintf("%+10p", 0xffff800000031337))); - EXPECT_STREQ(" 0x1", gc(xasprintf("% 10p", 1))); - EXPECT_STREQ(" 0x10", gc(xasprintf("% 10p", 16))); - EXPECT_STREQ(" 0x31337", gc(xasprintf("% 10p", 0x31337))); - EXPECT_STREQ("0xffffffff", gc(xasprintf("% 10p", 0xffffffff))); + _gc(xasprintf("%-10p", 0xffff800000031337))); + EXPECT_STREQ(" 0x1", _gc(xasprintf("%+10p", 1))); + EXPECT_STREQ(" 0x10", _gc(xasprintf("%+10p", 16))); + EXPECT_STREQ(" 0x31337", _gc(xasprintf("%+10p", 0x31337))); + EXPECT_STREQ("0xffffffff", _gc(xasprintf("%+10p", 0xffffffff))); EXPECT_STREQ("0xffff800000031337", - gc(xasprintf("% 10p", 0xffff800000031337))); + _gc(xasprintf("%+10p", 0xffff800000031337))); + EXPECT_STREQ(" 0x1", _gc(xasprintf("% 10p", 1))); + EXPECT_STREQ(" 0x10", _gc(xasprintf("% 10p", 16))); + EXPECT_STREQ(" 0x31337", _gc(xasprintf("% 10p", 0x31337))); + EXPECT_STREQ("0xffffffff", _gc(xasprintf("% 10p", 0xffffffff))); + EXPECT_STREQ("0xffff800000031337", + _gc(xasprintf("% 10p", 0xffff800000031337))); } TEST(fmt, quoted) { - ASSERT_STREQ(" \"hello\"", gc(xasprintf("%`*.*s", 10, 5, "hello"))); - ASSERT_STREQ("\"hello\" ", gc(xasprintf("%-`*.*s", 10, 5, "hello"))); + ASSERT_STREQ(" \"hello\"", _gc(xasprintf("%`*.*s", 10, 5, "hello"))); + ASSERT_STREQ("\"hello\" ", _gc(xasprintf("%-`*.*s", 10, 5, "hello"))); } TEST(fmt, nulCharacter) { diff --git a/test/libc/fmt/formatint64thousands_test.c b/test/libc/fmt/formatint64thousands_test.c index ae338e41a..4a050059c 100644 --- a/test/libc/fmt/formatint64thousands_test.c +++ b/test/libc/fmt/formatint64thousands_test.c @@ -21,7 +21,6 @@ #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/math.h" -#include "libc/nexgen32e/bsr.h" #include "libc/stdio/stdio.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/fmt/palandprintf_test.c b/test/libc/fmt/palandprintf_test.c index 86563ebcb..d37248bae 100644 --- a/test/libc/fmt/palandprintf_test.c +++ b/test/libc/fmt/palandprintf_test.c @@ -31,15 +31,15 @@ #include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/math.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" char buffer[1000]; -/* #define Format(...) gc(xasprintf(__VA_ARGS__)) */ +/* #define Format(...) _gc(xasprintf(__VA_ARGS__)) */ #define Format(...) (snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer) TEST(sprintf, test_space_flag) { @@ -572,13 +572,13 @@ TEST(xasprintf, hugeNtoa) { ASSERT_STREQ( "0b1111111111111111111111111111111111111111111111111111111111111111111111" "1111111111111111111111111111111111111111111111111111111111", - gc(xasprintf("%#jjb", UINT128_MAX))); + _gc(xasprintf("%#jjb", UINT128_MAX))); } TEST(xasprintf, twosBane) { - ASSERT_STREQ("-2147483648", gc(xasprintf("%d", 0x80000000))); + ASSERT_STREQ("-2147483648", _gc(xasprintf("%d", 0x80000000))); ASSERT_STREQ("-9223372036854775808", - gc(xasprintf("%ld", 0x8000000000000000))); + _gc(xasprintf("%ld", 0x8000000000000000))); } TEST(snprintf, testFixedWidthString_wontOverrunInput) { @@ -611,8 +611,8 @@ TEST(snprintf, twosBaneWithTypePromotion) { } TEST(snprintf, formatStringLiteral) { - EXPECT_EQ('\\' | 'n' << 8, cescapec('\n')); - EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec('\377')); + EXPECT_EQ('\\' | 'n' << 8, _cescapec('\n')); + EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec('\377')); EXPECT_STREQ("\"hi\\n\"", Format("%`'s", "hi\n")); EXPECT_STREQ("\"\\000\"", Format("%`'.*s", 1, "\0")); } diff --git a/test/libc/fmt/sprintf_s_test.c b/test/libc/fmt/sprintf_s_test.c index 330a45cdb..ce42e44bc 100644 --- a/test/libc/fmt/sprintf_s_test.c +++ b/test/libc/fmt/sprintf_s_test.c @@ -16,16 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/fmt/fmt.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" -#include "libc/fmt/fmt.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" static char buffer[128]; -#define Format(...) gc(xasprintf(__VA_ARGS__)) +#define Format(...) _gc(xasprintf(__VA_ARGS__)) /** * @fileoverview String formatting tests. diff --git a/test/libc/fmt/stripexts_test.c b/test/libc/fmt/stripexts_test.c index d29779620..c1fc1d11c 100644 --- a/test/libc/fmt/stripexts_test.c +++ b/test/libc/fmt/stripexts_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/fmt/zleb64_test.c b/test/libc/fmt/zleb64_test.c index d8cd220de..78659aa9c 100644 --- a/test/libc/fmt/zleb64_test.c +++ b/test/libc/fmt/zleb64_test.c @@ -19,7 +19,7 @@ #include "libc/fmt/leb128.h" #include "libc/limits.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" TEST(zleb64, testZero) { diff --git a/test/libc/intrin/asan_test.c b/test/libc/intrin/asan_test.c index f1cbf0ea2..9a234b089 100644 --- a/test/libc/intrin/asan_test.c +++ b/test/libc/intrin/asan_test.c @@ -22,7 +22,7 @@ #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/intrin/bextra_test.c b/test/libc/intrin/bextra_test.c index 3aaafb2b3..4c962296a 100644 --- a/test/libc/intrin/bextra_test.c +++ b/test/libc/intrin/bextra_test.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" +#include "libc/intrin/bits.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" @@ -106,10 +106,10 @@ unsigned P[] = { TEST(bextra, 9bit) { int i; for (i = 4; i < 257; ++i) { - ASSERT_EQ(i, bextra(P, i, 9)); + ASSERT_EQ(i, _bextra(P, i, 9)); } } BENCH(bextra, bench) { - EZBENCH2("bextra 1/31", donothing, bextra(P, 1, 31)); + EZBENCH2("bextra 1/31", donothing, _bextra(P, 1, 31)); } diff --git a/test/libc/intrin/bitreverse_test.c b/test/libc/intrin/bitreverse_test.c index 408e266f2..076a296b2 100644 --- a/test/libc/intrin/bitreverse_test.c +++ b/test/libc/intrin/bitreverse_test.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" +#include "libc/intrin/bits.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" @@ -25,25 +25,19 @@ void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio", 0)); } -TEST(bitreverse, test) { - EXPECT_EQ(0xde, BITREVERSE8(123)); - EXPECT_EQ(0xde, bitreverse8(123)); - EXPECT_EQ(0xde00, BITREVERSE16(123)); - EXPECT_EQ(0xde00, bitreverse16(123)); - EXPECT_EQ(0xde000000u, bitreverse32(123)); - EXPECT_EQ(0xde00000000000000ul, bitreverse64(123)); - EXPECT_EQ(0x482d96c305f7c697ul, bitreverse64(0xe963efa0c369b412)); +TEST(_bitreverse, test) { + EXPECT_EQ(0xde, _bitreverse8(123)); + EXPECT_EQ(0xde00, _bitreverse16(123)); + EXPECT_EQ(0xde000000u, _bitreverse32(123)); + EXPECT_EQ(0xde00000000000000ul, _bitreverse64(123)); + EXPECT_EQ(0x482d96c305f7c697ul, _bitreverse64(0xe963efa0c369b412)); } -BENCH(bitreverse, bench) { - EZBENCH2("BITREVERSE8", donothing, - EXPROPRIATE(BITREVERSE8(CONCEAL("r", 123)))); - EZBENCH2("bitreverse8", donothing, - EXPROPRIATE(bitreverse8(CONCEAL("r", 123)))); - EZBENCH2("BITREVERSE16", donothing, - EXPROPRIATE(BITREVERSE16(CONCEAL("r", 123)))); - EZBENCH2("bitreverse32", donothing, - EXPROPRIATE(bitreverse32(CONCEAL("r", 123)))); - EZBENCH2("bitreverse64", donothing, - EXPROPRIATE(bitreverse64(CONCEAL("r", 123)))); +BENCH(_bitreverse, bench) { + EZBENCH2("_bitreverse8", donothing, + EXPROPRIATE(_bitreverse8(CONCEAL("r", 123)))); + EZBENCH2("_bitreverse32", donothing, + EXPROPRIATE(_bitreverse32(CONCEAL("r", 123)))); + EZBENCH2("_bitreverse64", donothing, + EXPROPRIATE(_bitreverse64(CONCEAL("r", 123)))); } diff --git a/test/libc/intrin/countbits_test.c b/test/libc/intrin/countbits_test.c index de2ce0ee8..8f17296bf 100644 --- a/test/libc/intrin/countbits_test.c +++ b/test/libc/intrin/countbits_test.c @@ -20,7 +20,7 @@ #include "libc/intrin/popcnt.h" #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/intrin/intrin_test.c b/test/libc/intrin/intrin_test.c index 9ccae1dbd..98d088f58 100644 --- a/test/libc/intrin/intrin_test.c +++ b/test/libc/intrin/intrin_test.c @@ -104,7 +104,7 @@ #include "libc/nexgen32e/kcpuids.h" #include "libc/stdio/lcg.internal.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/intrin/lock_test.c b/test/libc/intrin/lock_test.c new file mode 100644 index 000000000..f16a5ea57 --- /dev/null +++ b/test/libc/intrin/lock_test.c @@ -0,0 +1,248 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/atomic.h" +#include "libc/calls/calls.h" +#include "libc/calls/struct/timespec.h" +#include "libc/errno.h" +#include "libc/fmt/itoa.h" +#include "libc/intrin/atomic.h" +#include "libc/intrin/kprintf.h" +#include "libc/intrin/weaken.h" +#include "libc/runtime/clone.internal.h" +#include "libc/runtime/runtime.h" +#include "libc/runtime/stack.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/clone.h" +#include "libc/thread/thread.h" +#include "libc/thread/tls.h" +#include "third_party/nsync/mu.h" + +/** + * @fileoverview Austere Mutex Test + * + * 1. Tests what happens when *NSYNC isn't linked. + * 2. Tests what happens when TLS isn't enabled. + * + * If either: + * + * 1. malloc() isn't linked, or + * 2. we're in MODE=tiny + * + * Then we use Cosmopolitan's hand-rolled tiny locks. They're not + * scalable. They use a lot of CPU if you have lots of threads. But + * they're wicked fast and free of bloat if your app is tiny. + */ + +// RAW means without *NSYNC +// TLS means gettid() is fast + +// PTHREAD_MUTEX_NORMAL RAW TLS took 6ns +// PTHREAD_MUTEX_RECURSIVE RAW TLS took 12ns +// PTHREAD_MUTEX_ERRORCHECK RAW TLS took 13ns +// PTHREAD_MUTEX_NORMAL RAW TLS contended took 16ns (!!) +// PTHREAD_MUTEX_RECURSIVE RAW TLS contended took 205ns +// PTHREAD_MUTEX_ERRORCHECK RAW TLS contended took 219ns +// PTHREAD_MUTEX_NORMAL RAW took 6ns +// PTHREAD_MUTEX_RECURSIVE RAW took 236ns +// PTHREAD_MUTEX_ERRORCHECK RAW took 233ns +// PTHREAD_MUTEX_NORMAL RAW contended took 20ns (!!) +// PTHREAD_MUTEX_RECURSIVE RAW contended took 421ns +// PTHREAD_MUTEX_ERRORCHECK RAW contended took 435ns + +atomic_int ready; +atomic_int counter; +atomic_int success; +pthread_mutex_t mu; + +#define ASSERT_EQ(WANT, GOT) \ + do { \ + long _want = WANT, _got = GOT; \ + if (_want != _got) \ + __assert_eq_fail(__FILE__, __LINE__, #WANT, #GOT, _want, _got); \ + } while (0) + +void __assert_eq_fail(const char *file, int line, const char *wantstr, + const char *gotstr, long want, long got) { + kprintf("%s:%d: %s vs. %s was %ld vs. %ld (%s)\n", file, line, wantstr, + gotstr, want, got, !(got & ~255) ? _strerrno(got) : "n/a"); + _Exit(1); +} + +double time2dbl(struct timespec t) { + return (((double)t.tv_sec) + ((double)t.tv_nsec * 1e-9)); +} + +char *time2str(double s) { + static char buf[32]; + static const struct { + const char *suffix; + double multiplier; + } scale[] = { + {"ns", 1.0e-9}, // + {"us", 1e-6}, // + {"ms", 1e-3}, // + {"s", 1.0}, // + {"hr", 3600.0}, // + }; + int i = 0; + while (i + 1 != sizeof(scale) / sizeof(scale[0]) && + scale[i + 1].multiplier <= s) { + i++; + } + stpcpy(FormatInt32(buf, s / scale[i].multiplier), scale[i].suffix); + return buf; +} + +int Worker(void *arg) { + int i, x; + atomic_store(&ready, 1); + for (i = 0; i < 10000; ++i) { + ASSERT_EQ(0, pthread_mutex_lock(&mu)); + x = atomic_load_explicit(&counter, memory_order_relaxed); + atomic_store_explicit(&counter, x + 1, memory_order_relaxed); + ASSERT_EQ(x + 1, atomic_load_explicit(&counter, memory_order_relaxed)); + ASSERT_EQ(0, pthread_mutex_unlock(&mu)); + } + atomic_store(&success, 1); + return 0; +} + +void TestContendedLock(const char *name, int kind) { + char *stk; + double ns; + int tid, x, i, n = 10000; + struct timespec t1, t2; + pthread_mutexattr_t attr; + struct CosmoTib tib = {.tib_self = &tib, .tib_self2 = &tib, .tib_tid = -1}; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, kind); + pthread_mutex_init(&mu, &attr); + pthread_mutexattr_destroy(&attr); + atomic_store(&ready, 0); + atomic_store(&success, 0); + stk = _mapstack(); + tid = clone(Worker, stk, GetStackSize() - 16 /* openbsd:stackbound */, + CLONE_VM | CLONE_THREAD | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | + CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | CLONE_SETTLS, + 0, 0, &tib, &tib.tib_tid); + if (tid == -1) { + kprintf("clone failed: %s\n", strerror(errno)); + _Exit(1); + } + while (!atomic_load(&ready)) donothing; + t1 = _timespec_real(); + for (i = 0; i < n; ++i) { + ASSERT_EQ(0, pthread_mutex_lock(&mu)); + x = atomic_load_explicit(&counter, memory_order_relaxed); + atomic_store_explicit(&counter, x - 1, memory_order_relaxed); + ASSERT_EQ(x - 1, atomic_load_explicit(&counter, memory_order_relaxed)); + ASSERT_EQ(0, pthread_mutex_unlock(&mu)); + } + t2 = _timespec_real(); + while (tib.tib_tid) donothing; + ASSERT_EQ(1, atomic_load(&success)); + ASSERT_EQ(0, atomic_load(&counter)); + _freestack(stk); + ASSERT_EQ(0, pthread_mutex_destroy(&mu)); + ns = time2dbl(_timespec_sub(t2, t1)) / n; + kprintf("%s contended took %s\n", name, time2str(ns)); +} + +void TestUncontendedLock(const char *name, int kind) { + double ns; + long i, n = 10000; + struct timespec t1, t2; + pthread_mutex_t lock; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, kind); + pthread_mutex_init(&lock, &attr); + pthread_mutexattr_destroy(&attr); + t1 = _timespec_real(); + for (i = 0; i < n; ++i) { + pthread_mutex_lock(&lock); + pthread_mutex_unlock(&lock); + } + t2 = _timespec_real(); + pthread_mutex_destroy(&lock); + ns = time2dbl(_timespec_sub(t2, t1)) / n; + kprintf("%s took %s\n", name, time2str(ns)); +} + +int main(int argc, char *argv[]) { + pthread_mutexattr_t attr; + + if (_weaken(nsync_mu_lock)) { + kprintf("*NSYNC should not be linked\n"); + _Exit(1); + } + + ASSERT_EQ(0, pthread_mutexattr_init(&attr)); + ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL)); + ASSERT_EQ(0, pthread_mutex_init(&mu, &attr)); + ASSERT_EQ(0, pthread_mutexattr_destroy(&attr)); + ASSERT_EQ(0, pthread_mutex_lock(&mu)); + ASSERT_EQ(0, pthread_mutex_unlock(&mu)); + ASSERT_EQ(0, pthread_mutex_destroy(&mu)); + + ASSERT_EQ(0, pthread_mutexattr_init(&attr)); + ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)); + ASSERT_EQ(0, pthread_mutex_init(&mu, &attr)); + ASSERT_EQ(0, pthread_mutexattr_destroy(&attr)); + ASSERT_EQ(0, pthread_mutex_lock(&mu)); + ASSERT_EQ(0, pthread_mutex_lock(&mu)); + ASSERT_EQ(0, pthread_mutex_unlock(&mu)); + ASSERT_EQ(0, pthread_mutex_unlock(&mu)); + ASSERT_EQ(0, pthread_mutex_destroy(&mu)); + + ASSERT_EQ(0, pthread_mutexattr_init(&attr)); + ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK)); + ASSERT_EQ(0, pthread_mutex_init(&mu, &attr)); + ASSERT_EQ(0, pthread_mutexattr_destroy(&attr)); + ASSERT_EQ(0, pthread_mutex_lock(&mu)); + ASSERT_EQ(EDEADLK, pthread_mutex_lock(&mu)); + ASSERT_EQ(0, pthread_mutex_unlock(&mu)); + ASSERT_EQ(EPERM, pthread_mutex_unlock(&mu)); + ASSERT_EQ(0, pthread_mutex_destroy(&mu)); + + ASSERT_EQ(1, __tls_enabled); + + TestUncontendedLock("PTHREAD_MUTEX_NORMAL RAW TLS", PTHREAD_MUTEX_NORMAL); + TestUncontendedLock("PTHREAD_MUTEX_RECURSIVE RAW TLS", + PTHREAD_MUTEX_RECURSIVE); + TestUncontendedLock("PTHREAD_MUTEX_ERRORCHECK RAW TLS", + PTHREAD_MUTEX_ERRORCHECK); + + TestContendedLock("PTHREAD_MUTEX_NORMAL RAW TLS", PTHREAD_MUTEX_NORMAL); + TestContendedLock("PTHREAD_MUTEX_RECURSIVE RAW TLS", PTHREAD_MUTEX_RECURSIVE); + TestContendedLock("PTHREAD_MUTEX_ERRORCHECK RAW TLS", + PTHREAD_MUTEX_ERRORCHECK); + + __tls_enabled = 0; + + TestUncontendedLock("PTHREAD_MUTEX_NORMAL RAW", PTHREAD_MUTEX_NORMAL); + TestUncontendedLock("PTHREAD_MUTEX_RECURSIVE RAW", PTHREAD_MUTEX_RECURSIVE); + TestUncontendedLock("PTHREAD_MUTEX_ERRORCHECK RAW", PTHREAD_MUTEX_ERRORCHECK); + + TestContendedLock("PTHREAD_MUTEX_NORMAL RAW", PTHREAD_MUTEX_NORMAL); + TestContendedLock("PTHREAD_MUTEX_RECURSIVE RAW", PTHREAD_MUTEX_RECURSIVE); + TestContendedLock("PTHREAD_MUTEX_ERRORCHECK RAW", PTHREAD_MUTEX_ERRORCHECK); + + // +} diff --git a/test/libc/intrin/memcmp_test.c b/test/libc/intrin/memcmp_test.c index e819c6735..44404786c 100644 --- a/test/libc/intrin/memcmp_test.c +++ b/test/libc/intrin/memcmp_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/intrin/memmove_test.c b/test/libc/intrin/memmove_test.c index 203327807..8c99c9d2f 100644 --- a/test/libc/intrin/memmove_test.c +++ b/test/libc/intrin/memmove_test.c @@ -20,7 +20,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/intrin/memset_test.c b/test/libc/intrin/memset_test.c index 38e25db19..d95e0c413 100644 --- a/test/libc/intrin/memset_test.c +++ b/test/libc/intrin/memset_test.c @@ -19,7 +19,7 @@ #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/rand.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/intrin/pthread_mutex_lock2_test.c b/test/libc/intrin/pthread_mutex_lock2_test.c index c582c6167..cb1b74d98 100644 --- a/test/libc/intrin/pthread_mutex_lock2_test.c +++ b/test/libc/intrin/pthread_mutex_lock2_test.c @@ -21,7 +21,7 @@ #include "libc/calls/struct/timespec.h" #include "libc/intrin/atomic.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/thread/posixthread.internal.h" diff --git a/test/libc/intrin/pthread_mutex_lock_test.c b/test/libc/intrin/pthread_mutex_lock_test.c index 396bb9319..e320e76ce 100644 --- a/test/libc/intrin/pthread_mutex_lock_test.c +++ b/test/libc/intrin/pthread_mutex_lock_test.c @@ -20,13 +20,13 @@ #include "libc/atomic.h" #include "libc/calls/calls.h" #include "libc/calls/state.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/errno.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/check.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" @@ -40,6 +40,7 @@ #include "libc/thread/thread.h" #include "libc/thread/tls.h" #include "libc/thread/wait0.internal.h" +#include "third_party/nsync/mu.h" #define THREADS 8 #define ITERATIONS 512 diff --git a/test/libc/intrin/pthread_once_test.c b/test/libc/intrin/pthread_once_test.c index e51f7a574..dc831aa22 100644 --- a/test/libc/intrin/pthread_once_test.c +++ b/test/libc/intrin/pthread_once_test.c @@ -19,7 +19,7 @@ #include "libc/atomic.h" #include "libc/intrin/atomic.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" #include "libc/thread/thread.h" diff --git a/test/libc/intrin/rounddown2pow_test.c b/test/libc/intrin/rounddown2pow_test.c index f7418a13c..b077756e9 100644 --- a/test/libc/intrin/rounddown2pow_test.c +++ b/test/libc/intrin/rounddown2pow_test.c @@ -16,24 +16,24 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" +#include "libc/intrin/bits.h" #include "libc/testlib/testlib.h" void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio", 0)); } -TEST(rounddown2pow, test) { - EXPECT_EQ(0, rounddown2pow(0)); - EXPECT_EQ(1, rounddown2pow(1)); - EXPECT_EQ(2, rounddown2pow(2)); - EXPECT_EQ(2, rounddown2pow(3)); - EXPECT_EQ(4, rounddown2pow(4)); - EXPECT_EQ(PAGESIZE / 2, rounddown2pow(PAGESIZE - 1)); - EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE)); - EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE + 1)); - EXPECT_EQ(PAGESIZE / 2, rounddown2pow(PAGESIZE - 1)); - EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE)); - EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE + 1)); +TEST(_rounddown2pow, test) { + EXPECT_EQ(0, _rounddown2pow(0)); + EXPECT_EQ(1, _rounddown2pow(1)); + EXPECT_EQ(2, _rounddown2pow(2)); + EXPECT_EQ(2, _rounddown2pow(3)); + EXPECT_EQ(4, _rounddown2pow(4)); + EXPECT_EQ(PAGESIZE / 2, _rounddown2pow(PAGESIZE - 1)); + EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE)); + EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE + 1)); + EXPECT_EQ(PAGESIZE / 2, _rounddown2pow(PAGESIZE - 1)); + EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE)); + EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE + 1)); } diff --git a/test/libc/intrin/roundup2log_test.c b/test/libc/intrin/roundup2log_test.c index 07a6aad4a..1ee2acc79 100644 --- a/test/libc/intrin/roundup2log_test.c +++ b/test/libc/intrin/roundup2log_test.c @@ -16,24 +16,24 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" +#include "libc/intrin/bits.h" #include "libc/testlib/testlib.h" void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio", 0)); } -TEST(roundup2log, test) { - EXPECT_EQ(0, roundup2log(0)); - EXPECT_EQ(1, roundup2log(1)); - EXPECT_EQ(1, roundup2log(2)); - EXPECT_EQ(2, roundup2log(3)); - EXPECT_EQ(2, roundup2log(4)); - EXPECT_EQ(12, roundup2log(PAGESIZE - 1)); - EXPECT_EQ(12, roundup2log(PAGESIZE)); - EXPECT_EQ(13, roundup2log(PAGESIZE + 1)); - EXPECT_EQ(12, roundup2log(PAGESIZE - 1)); - EXPECT_EQ(12, roundup2log(PAGESIZE)); - EXPECT_EQ(13, roundup2log(PAGESIZE + 1)); +TEST(_roundup2log, test) { + EXPECT_EQ(0, _roundup2log(0)); + EXPECT_EQ(1, _roundup2log(1)); + EXPECT_EQ(1, _roundup2log(2)); + EXPECT_EQ(2, _roundup2log(3)); + EXPECT_EQ(2, _roundup2log(4)); + EXPECT_EQ(12, _roundup2log(PAGESIZE - 1)); + EXPECT_EQ(12, _roundup2log(PAGESIZE)); + EXPECT_EQ(13, _roundup2log(PAGESIZE + 1)); + EXPECT_EQ(12, _roundup2log(PAGESIZE - 1)); + EXPECT_EQ(12, _roundup2log(PAGESIZE)); + EXPECT_EQ(13, _roundup2log(PAGESIZE + 1)); } diff --git a/test/libc/intrin/roundup2pow_test.c b/test/libc/intrin/roundup2pow_test.c index a62bfcebf..535fad83b 100644 --- a/test/libc/intrin/roundup2pow_test.c +++ b/test/libc/intrin/roundup2pow_test.c @@ -16,28 +16,24 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" -#include "libc/log/check.h" -#include "libc/macros.internal.h" -#include "libc/math.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bits.h" #include "libc/testlib/testlib.h" void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio", 0)); } -TEST(roundup2pow, test) { - EXPECT_EQ(0, roundup2pow(0)); - EXPECT_EQ(1, roundup2pow(1)); - EXPECT_EQ(2, roundup2pow(2)); - EXPECT_EQ(4, roundup2pow(3)); - EXPECT_EQ(4, roundup2pow(4)); - EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE - 1)); - EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE)); - EXPECT_EQ(PAGESIZE * 2, roundup2pow(PAGESIZE + 1)); - EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE - 1)); - EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE)); - EXPECT_EQ(PAGESIZE * 2, roundup2pow(PAGESIZE + 1)); +TEST(_roundup2pow, test) { + EXPECT_EQ(0, _roundup2pow(0)); + EXPECT_EQ(1, _roundup2pow(1)); + EXPECT_EQ(2, _roundup2pow(2)); + EXPECT_EQ(4, _roundup2pow(3)); + EXPECT_EQ(4, _roundup2pow(4)); + EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE - 1)); + EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE)); + EXPECT_EQ(PAGESIZE * 2, _roundup2pow(PAGESIZE + 1)); + EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE - 1)); + EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE)); + EXPECT_EQ(PAGESIZE * 2, _roundup2pow(PAGESIZE + 1)); } diff --git a/test/libc/intrin/strlen_test.c b/test/libc/intrin/strlen_test.c index bfbd3bc3c..374ebc647 100644 --- a/test/libc/intrin/strlen_test.c +++ b/test/libc/intrin/strlen_test.c @@ -19,7 +19,6 @@ #include "libc/intrin/bits.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/intrin/test.mk b/test/libc/intrin/test.mk index 48ce2837a..081cb5581 100644 --- a/test/libc/intrin/test.mk +++ b/test/libc/intrin/test.mk @@ -58,6 +58,15 @@ o/$(MODE)/test/libc/intrin/%.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +# Test what happens when *NSYNC isn't linked. +o/$(MODE)/test/libc/intrin/lock_test.com.dbg: \ + $(TEST_LIBC_INTRIN_DEPS) \ + o/$(MODE)/test/libc/intrin/lock_test.o \ + o/$(MODE)/test/libc/intrin/intrin.pkg \ + $(CRT) \ + $(APE_NO_MODIFY_SELF) + @$(APELINK) + $(TEST_LIBC_INTRIN_OBJS): private \ OVERRIDE_CFLAGS += \ -fno-builtin diff --git a/test/libc/log/appendresourcereport_test.c b/test/libc/log/appendresourcereport_test.c index a9d0d3873..36057a8b4 100644 --- a/test/libc/log/appendresourcereport_test.c +++ b/test/libc/log/appendresourcereport_test.c @@ -17,6 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/struct/rusage.h" +#include "libc/log/appendresourcereport.internal.h" #include "libc/log/log.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/test/libc/log/backtrace_test.c b/test/libc/log/backtrace_test.c index 95c965e44..e210f70b6 100644 --- a/test/libc/log/backtrace_test.c +++ b/test/libc/log/backtrace_test.c @@ -25,19 +25,19 @@ #include "libc/limits.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" -#include "libc/mem/io.h" +#include "libc/mem/gc.h" +#include "libc/calls/copyfd.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/sig.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "net/http/escape.h" STATIC_YOINK("backtrace.com"); @@ -119,14 +119,14 @@ TEST(ShowCrashReports, testMemoryLeakCrash) { EXPECT_EQ(78, WEXITSTATUS(ws)); if (!strstr(output, "UNFREED MEMORY")) { fprintf(stderr, "ERROR: crash report didn't report leak\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (IsAsan()) { if (!OutputHasSymbol(output, "strdup") || !OutputHasSymbol(output, "MemoryLeakCrash")) { fprintf(stderr, "ERROR: crash report didn't backtrace allocation\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } } @@ -197,7 +197,7 @@ TEST(ShowCrashReports, testStackOverrunCrash) { /* NULL is stopgap until we can copy symbol tablces into binary */ if (!OutputHasSymbol(output, "StackOverrunCrash")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (strstr(output, "'int' index 10 into 'char [10]' out of bounds")) { @@ -206,12 +206,12 @@ TEST(ShowCrashReports, testStackOverrunCrash) { // asan nailed it if (!strstr(output, "☺☻♥♦♣♠•◘○")) { fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!strstr(output, "stack overrun")) { fprintf(stderr, "ERROR: crash report misclassified stack overrun\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } } @@ -306,7 +306,7 @@ TEST(ShowCrashReports, testDivideByZero) { #ifdef __FNO_OMIT_FRAME_POINTER__ if (!OutputHasSymbol(output, "FpuCrash")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #endif @@ -314,29 +314,29 @@ TEST(ShowCrashReports, testDivideByZero) { // UBSAN handled it } else { // ShowCrashReports() handled it - if (!strstr(output, gc(xasprintf("%d", pid)))) { + if (!strstr(output, _gc(xasprintf("%d", pid)))) { fprintf(stderr, "ERROR: crash report didn't have pid\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!strstr(output, "SIGFPE")) { fprintf(stderr, "ERROR: crash report didn't have signal name\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!strstr(output, "3.141")) { fprintf(stderr, "ERROR: crash report didn't have fpu register\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!strstr(output, "0f0e0d0c0b0a09080706050403020100")) { fprintf(stderr, "ERROR: crash report didn't have sse register\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!strstr(output, "3133731337")) { fprintf(stderr, "ERROR: crash report didn't have general register\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } } @@ -384,31 +384,31 @@ TEST(ShowCrashReports, testStackOverflow) { #ifdef __FNO_OMIT_FRAME_POINTER__ if (!OutputHasSymbol(output, "StackOverflow")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #endif // ShowCrashReports() handled it - if (!strstr(output, gc(xasprintf("%d", pid)))) { + if (!strstr(output, _gc(xasprintf("%d", pid)))) { fprintf(stderr, "ERROR: crash report didn't have pid\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!strstr(output, "SIGSEGV")) { fprintf(stderr, "ERROR: crash report didn't have signal name\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } if (!IsTiny()) { if (!strstr(output, "Stack Overflow")) { fprintf(stderr, "ERROR: crash report didn't have 'Stack Overflow'\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } } else { if (!strstr(output, "SEGV_MAPERR")) { fprintf(stderr, "ERROR: crash report didn't have 'SEGV_MAPERR'\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } } @@ -499,14 +499,14 @@ TEST(ShowCrashReports, testBssOverrunCrash) { #ifdef __FNO_OMIT_FRAME_POINTER__ if (!OutputHasSymbol(output, "BssOverrunCrash")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #endif if (!strstr(output, "'int' index 10 into 'char [10]' out of bounds") && (!strstr(output, "☺☻♥♦♣♠•◘○") || !strstr(output, "global redzone"))) { fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } free(output); @@ -576,13 +576,13 @@ TEST(ShowCrashReports, testNpeCrash) { /* NULL is stopgap until we can copy symbol tables into binary */ if (!strstr(output, "null pointer")) { fprintf(stderr, "ERROR: crash report didn't diagnose the problem\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #ifdef __FNO_OMIT_FRAME_POINTER__ if (!OutputHasSymbol(output, "NpeCrash")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #endif @@ -592,7 +592,7 @@ TEST(ShowCrashReports, testNpeCrash) { // asan nailed it if (!strstr(output, "∅∅∅∅")) { fprintf(stderr, "ERROR: crash report didn't have shadow diagram\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } } @@ -636,14 +636,14 @@ TEST(ShowCrashReports, testDataOverrunCrash) { #ifdef __FNO_OMIT_FRAME_POINTER__ if (!OutputHasSymbol(output, "DataOverrunCrash")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #endif if (!strstr(output, "'int' index 10 into 'char [10]' out of bounds") && (!strstr(output, "☺☻♥♦♣♠•◘○") || !strstr(output, "global redzone"))) { fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } free(output); @@ -690,13 +690,13 @@ TEST(ShowCrashReports, testNpeCrashAfterFinalize) { /* NULL is stopgap until we can copy symbol tables into binary */ if (!strstr(output, IsAsan() ? "null pointer" : "Uncaught SIGSEGV (SEGV_")) { fprintf(stderr, "ERROR: crash report didn't diagnose the problem\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #ifdef __FNO_OMIT_FRAME_POINTER__ if (!OutputHasSymbol(output, "NpeCrash")) { fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n", - gc(IndentLines(output, -1, 0, 4))); + _gc(IndentLines(output, -1, 0, 4))); __die(); } #endif diff --git a/test/libc/mem/arena_test.c b/test/libc/mem/arena_test.c index a4a5f3725..9b09bf5cb 100644 --- a/test/libc/mem/arena_test.c +++ b/test/libc/mem/arena_test.c @@ -19,8 +19,8 @@ #include "libc/log/libfatal.internal.h" #include "libc/mem/arena.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/mem/gc.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/mem/comparator_test.c b/test/libc/mem/comparator_test.c deleted file mode 100644 index 8bfc0db52..000000000 --- a/test/libc/mem/comparator_test.c +++ /dev/null @@ -1,110 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" -#include "libc/intrin/bits.h" -#include "libc/mem/mem.h" -#include "libc/str/str.h" -#include "libc/testlib/testlib.h" - -TEST(comparator, testByteCompare) { - char *b1 = malloc(1); - char *b2 = malloc(1); - /* sign doesn't matter */ - EXPECT_EQ(cmpsb(memcpy(b1, "a", 1), memcpy(b2, "a", 1)), 0); - EXPECT_LT(cmpsb(memcpy(b1, "a", 1), memcpy(b2, "z", 1)), 0); - EXPECT_GT(cmpsb(memcpy(b1, "z", 1), memcpy(b2, "a", 1)), 0); - EXPECT_EQ(cmpub(memcpy(b1, "a", 1), memcpy(b2, "a", 1)), 0); - EXPECT_LT(cmpub(memcpy(b1, "a", 1), memcpy(b2, "z", 1)), 0); - EXPECT_GT(cmpub(memcpy(b1, "z", 1), memcpy(b2, "a", 1)), 0); - /* sign matters */ - EXPECT_EQ(cmpsb(memcpy(b1, "\xf0", 1), memcpy(b2, "\xf0", 1)), 0); - EXPECT_LT(cmpsb(memcpy(b1, "\xf0", 1), memcpy(b2, "\x10", 1)), 0); - EXPECT_GT(cmpsb(memcpy(b1, "\x10", 1), memcpy(b2, "\xf0", 1)), 0); - EXPECT_EQ(cmpub(memcpy(b1, "\xf0", 1), memcpy(b2, "\xf0", 1)), 0); - EXPECT_GT(cmpub(memcpy(b1, "\xf0", 1), memcpy(b2, "\x10", 1)), 0); - EXPECT_LT(cmpub(memcpy(b1, "\x10", 1), memcpy(b2, "\xf0", 1)), 0); - /* two's complement bane */ - EXPECT_GT(cmpsb(memcpy(b1, "\x7f", 1), memcpy(b2, "\x80", 1)), 0); - EXPECT_LT(cmpub(memcpy(b1, "\x7f", 1), memcpy(b2, "\x80", 1)), 0); - free(b2); - free(b1); -} - -TEST(comparator, testWordCompare) { - char *b1 = malloc(2); - char *b2 = malloc(2); - EXPECT_EQ(cmpsw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x80", 2)), 0); - EXPECT_GT(cmpsw(memcpy(b1, "\x00\x7f", 2), memcpy(b2, "\x00\x80", 2)), 0); - EXPECT_LT(cmpsw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x7f", 2)), 0); - EXPECT_EQ(cmpuw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x80", 2)), 0); - EXPECT_LT(cmpuw(memcpy(b1, "\x00\x7f", 2), memcpy(b2, "\x00\x80", 2)), 0); - EXPECT_GT(cmpuw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x7f", 2)), 0); - free(b2); - free(b1); -} - -TEST(comparator, testDoublewordCompare) { - char *b1 = malloc(4); - char *b2 = malloc(4); - EXPECT_EQ(cmpsl(memcpy(b1, "\x00\x00\x00\x80", 4), - memcpy(b2, "\x00\x00\x00\x80", 4)), - 0); - EXPECT_GT(cmpsl(memcpy(b1, "\x00\x00\x00\x7f", 4), - memcpy(b2, "\x00\x00\x00\x80", 4)), - 0); - EXPECT_LT(cmpsl(memcpy(b1, "\x00\x00\x00\x80", 4), - memcpy(b2, "\x00\x00\x00\x7f", 4)), - 0); - EXPECT_EQ(cmpul(memcpy(b1, "\x00\x00\x00\x80", 4), - memcpy(b2, "\x00\x00\x00\x80", 4)), - 0); - EXPECT_LT(cmpul(memcpy(b1, "\x00\x00\x00\x7f", 4), - memcpy(b2, "\x00\x00\x00\x80", 4)), - 0); - EXPECT_GT(cmpul(memcpy(b1, "\x00\x00\x00\x80", 4), - memcpy(b2, "\x00\x00\x00\x7f", 4)), - 0); - free(b2); - free(b1); -} - -TEST(comparator, testQuadwordCompare) { - char *b1 = malloc(8); - char *b2 = malloc(8); - EXPECT_EQ(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8), - memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)), - 0); - EXPECT_GT(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8), - memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)), - 0); - EXPECT_LT(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8), - memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8)), - 0); - EXPECT_EQ(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8), - memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)), - 0); - EXPECT_LT(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8), - memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)), - 0); - EXPECT_GT(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8), - memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8)), - 0); - free(b2); - free(b1); -} diff --git a/test/libc/mem/djbsort_test.c b/test/libc/mem/djbsort_test.c index 9b2e04bbd..ce7b379b0 100644 --- a/test/libc/mem/djbsort_test.c +++ b/test/libc/mem/djbsort_test.c @@ -23,7 +23,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/mem/malloc_test.c b/test/libc/mem/malloc_test.c index c2088a704..80ed53c03 100644 --- a/test/libc/mem/malloc_test.c +++ b/test/libc/mem/malloc_test.c @@ -24,7 +24,7 @@ #include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" diff --git a/test/libc/mem/qsort_test.c b/test/libc/mem/qsort_test.c index c0d7e7c61..6b451c639 100644 --- a/test/libc/mem/qsort_test.c +++ b/test/libc/mem/qsort_test.c @@ -19,9 +19,8 @@ #include "libc/intrin/bits.h" #include "libc/macros.internal.h" #include "libc/mem/alg.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" @@ -29,6 +28,14 @@ #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" +int CompareInt(const void *a, const void *b) { + const int *x = a; + const int *y = b; + if (*x < *y) return -1; + if (*x > *y) return +1; + return 0; +} + int CompareLong(const void *a, const void *b) { const long *x = a; const long *y = b; @@ -46,7 +53,7 @@ TEST(qsort, test) { {99, 'f'}, {782, 'i'}}; int32_t(*M)[2] = malloc(sizeof(A)); memcpy(M, B, sizeof(A)); - qsort(M, ARRAYLEN(A), sizeof(*M), cmpsl); + qsort(M, ARRAYLEN(A), sizeof(*M), CompareInt); EXPECT_EQ(0, memcmp(M, B, sizeof(B))); free(M); } @@ -54,9 +61,9 @@ TEST(qsort, test) { TEST(qsort, equivalence_random) { size_t i; size_t n = 1000; - long *a = gc(malloc(n * sizeof(long))); - long *b = gc(malloc(n * sizeof(long))); - long *c = gc(malloc(n * sizeof(long))); + long *a = _gc(malloc(n * sizeof(long))); + long *b = _gc(malloc(n * sizeof(long))); + long *c = _gc(malloc(n * sizeof(long))); for (i = 0; i < n; ++i) a[i] = lemur64(); memcpy(b, a, n * sizeof(long)); memcpy(c, a, n * sizeof(long)); @@ -70,16 +77,16 @@ TEST(qsort, equivalence_random) { smoothsort(c, n, sizeof(long), CompareLong); ASSERT_EQ(0, memcmp(b, c, n * sizeof(long))); memcpy(c, a, n * sizeof(long)); - longsort(c, n); + _longsort(c, n); ASSERT_EQ(0, memcmp(b, c, n * sizeof(long))); } TEST(qsort, equivalence_reverse) { size_t i; size_t n = 1000; - long *a = gc(malloc(n * sizeof(long))); - long *b = gc(malloc(n * sizeof(long))); - long *c = gc(malloc(n * sizeof(long))); + long *a = _gc(malloc(n * sizeof(long))); + long *b = _gc(malloc(n * sizeof(long))); + long *c = _gc(malloc(n * sizeof(long))); for (i = 0; i < n; ++i) a[n - i - 1] = i; memcpy(b, a, n * sizeof(long)); memcpy(c, a, n * sizeof(long)); @@ -93,15 +100,15 @@ TEST(qsort, equivalence_reverse) { smoothsort(c, n, sizeof(long), CompareLong); ASSERT_EQ(0, memcmp(b, c, n * sizeof(long))); memcpy(c, a, n * sizeof(long)); - longsort(c, n); + _longsort(c, n); ASSERT_EQ(0, memcmp(b, c, n * sizeof(long))); } BENCH(qsort, bench) { size_t i; size_t n = 1000; - long *p1 = gc(malloc(n * sizeof(long))); - long *p2 = gc(malloc(n * sizeof(long))); + long *p1 = _gc(malloc(n * sizeof(long))); + long *p2 = _gc(malloc(n * sizeof(long))); printf("\n"); for (i = 0; i < n; ++i) p1[i] = i + ((lemur64() % 3) - 1); @@ -113,8 +120,8 @@ BENCH(qsort, bench) { mergesort(p2, n, sizeof(long), CompareLong)); EZBENCH2("smoothsort nearly", memcpy(p2, p1, n * sizeof(long)), smoothsort(p2, n, sizeof(long), CompareLong)); - EZBENCH2("longsort nearly", memcpy(p2, p1, n * sizeof(long)), - longsort(p2, n)); + EZBENCH2("_longsort nearly", memcpy(p2, p1, n * sizeof(long)), + _longsort(p2, n)); printf("\n"); for (i = 0; i < n; ++i) p1[i] = n - i; @@ -126,8 +133,8 @@ BENCH(qsort, bench) { mergesort(p2, n, sizeof(long), CompareLong)); EZBENCH2("smoothsort reverse", memcpy(p2, p1, n * sizeof(long)), smoothsort(p2, n, sizeof(long), CompareLong)); - EZBENCH2("longsort reverse", memcpy(p2, p1, n * sizeof(long)), - longsort(p2, n)); + EZBENCH2("_longsort reverse", memcpy(p2, p1, n * sizeof(long)), + _longsort(p2, n)); printf("\n"); rngset(p1, n * sizeof(long), 0, 0); @@ -139,8 +146,8 @@ BENCH(qsort, bench) { mergesort(p2, n, sizeof(long), CompareLong)); EZBENCH2("smoothsort random", memcpy(p2, p1, n * sizeof(long)), smoothsort(p2, n, sizeof(long), CompareLong)); - EZBENCH2("longsort random", memcpy(p2, p1, n * sizeof(long)), - longsort(p2, n)); + EZBENCH2("_longsort random", memcpy(p2, p1, n * sizeof(long)), + _longsort(p2, n)); printf("\n"); for (i = 0; i < n / 2; ++i) { @@ -155,5 +162,5 @@ BENCH(qsort, bench) { mergesort(p2, n, sizeof(long), CompareLong)); EZBENCH2("smoothsort 2n", memcpy(p2, p1, n * sizeof(long)), smoothsort(p2, n, sizeof(long), CompareLong)); - EZBENCH2("longsort 2n", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n)); + EZBENCH2("_longsort 2n", memcpy(p2, p1, n * sizeof(long)), _longsort(p2, n)); } diff --git a/test/libc/mem/realloc_in_place_test.c b/test/libc/mem/realloc_in_place_test.c index 1803db823..32a0bc8da 100644 --- a/test/libc/mem/realloc_in_place_test.c +++ b/test/libc/mem/realloc_in_place_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/mem/replacestr_test.c b/test/libc/mem/replacestr_test.c index 1cd6afc20..8b41d6a27 100644 --- a/test/libc/mem/replacestr_test.c +++ b/test/libc/mem/replacestr_test.c @@ -16,26 +16,26 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/errno.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/alg.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" -TEST(replacestr, demo) { +TEST(_replacestr, demo) { EXPECT_STREQ("hello friends", - gc(replacestr("hello world", "world", "friends"))); - EXPECT_STREQ("bbbbbbbb", gc(replacestr("aaaa", "a", "bb"))); + _gc(_replacestr("hello world", "world", "friends"))); + EXPECT_STREQ("bbbbbbbb", _gc(_replacestr("aaaa", "a", "bb"))); } -TEST(replacestr, emptyString) { - EXPECT_STREQ("", gc(replacestr("", "x", "y"))); +TEST(_replacestr, emptyString) { + EXPECT_STREQ("", _gc(_replacestr("", "x", "y"))); } -TEST(replacestr, emptyNeedle) { - EXPECT_EQ(NULL, gc(replacestr("a", "", "a"))); +TEST(_replacestr, emptyNeedle) { + EXPECT_EQ(NULL, _gc(_replacestr("a", "", "a"))); EXPECT_EQ(EINVAL, errno); } -TEST(replacestr, needleInReplacement_doesntExplode) { - EXPECT_STREQ("xxxxxxx", gc(replacestr("x", "x", "xxxxxxx"))); +TEST(_replacestr, needleInReplacement_doesntExplode) { + EXPECT_STREQ("xxxxxxx", _gc(_replacestr("x", "x", "xxxxxxx"))); } diff --git a/test/libc/mem/tarjan_test.c b/test/libc/mem/tarjan_test.c index e4dfe6a84..f4a324e87 100644 --- a/test/libc/mem/tarjan_test.c +++ b/test/libc/mem/tarjan_test.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" #include "libc/testlib/testlib.h" STATIC_YOINK("realloc"); @@ -27,7 +27,7 @@ TEST(tarjan, empty_doesNothing) { int edges[][2] = {{0, 0}}; int vertex_count = 0; int edge_count = 0; - tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL); + _tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL); ASSERT_EQ(-1, sorted_vertices[0]); } @@ -53,8 +53,8 @@ TEST(tarjan, topologicalSort_noCycles) { A */ int sorted[4], components[4], componentcount; - ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges), - sorted, components, &componentcount)); + ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges), + sorted, components, &componentcount)); EXPECT_EQ(C, sorted[0]); EXPECT_EQ(D, sorted[1]); EXPECT_EQ(B, sorted[2]); @@ -76,8 +76,8 @@ TEST(tarjan, testOneBigCycle_isDetected_weDontCareAboutOrderInsideTheCycle) { {C /* depends on → */, D /* which must come before C */}, {D /* depends on → */, A /* which must come before D */}}; int sorted[4], components[4], componentcount; - ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges), - sorted, components, &componentcount)); + ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges), + sorted, components, &componentcount)); ASSERT_EQ(1, componentcount); EXPECT_EQ(4, components[0]); } @@ -110,8 +110,8 @@ TEST(tarjan, testHeaders) { int sorted[ARRAYLEN(vertices)]; int components[ARRAYLEN(vertices)]; int componentcount; - ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges), - sorted, components, &componentcount)); + ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges), + sorted, components, &componentcount)); ASSERT_EQ(ARRAYLEN(vertices), componentcount); EXPECT_STREQ("libc/dce.h", vertices[sorted[0]]); EXPECT_STREQ("libc/integral.h", vertices[sorted[1]]); diff --git a/test/libc/nexgen32e/cescapec_test.c b/test/libc/nexgen32e/cescapec_test.c index baca97e02..e9f800a9c 100644 --- a/test/libc/nexgen32e/cescapec_test.c +++ b/test/libc/nexgen32e/cescapec_test.c @@ -19,15 +19,15 @@ #include "libc/str/str.h" #include "libc/testlib/testlib.h" -TEST(cescapec, test) { - EXPECT_EQ(' ', cescapec(0x20)); - EXPECT_EQ('~', cescapec(0x7E)); - EXPECT_EQ('\\' | 'r' << 8, cescapec('\r')); - EXPECT_EQ('\\' | 'n' << 8, cescapec('\n')); - EXPECT_EQ('\\' | '0' << 8 | '0' << 16 | '0' << 24, cescapec(0)); - EXPECT_EQ('\\' | '0' << 8 | '3' << 16 | '3' << 24, cescapec('\e')); - EXPECT_EQ('\\' | '1' << 8 | '7' << 16 | '7' << 24, cescapec(0x7F)); - EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(0xFF)); - EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(0xFFFF)); - EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(-1)); +TEST(_cescapec, test) { + EXPECT_EQ(' ', _cescapec(0x20)); + EXPECT_EQ('~', _cescapec(0x7E)); + EXPECT_EQ('\\' | 'r' << 8, _cescapec('\r')); + EXPECT_EQ('\\' | 'n' << 8, _cescapec('\n')); + EXPECT_EQ('\\' | '0' << 8 | '0' << 16 | '0' << 24, _cescapec(0)); + EXPECT_EQ('\\' | '0' << 8 | '3' << 16 | '3' << 24, _cescapec('\e')); + EXPECT_EQ('\\' | '1' << 8 | '7' << 16 | '7' << 24, _cescapec(0x7F)); + EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec(0xFF)); + EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec(0xFFFF)); + EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec(-1)); } diff --git a/test/libc/nexgen32e/gclongjmp_test.c b/test/libc/nexgen32e/gclongjmp_test.c index 9b95a37ac..6b20afd8a 100644 --- a/test/libc/nexgen32e/gclongjmp_test.c +++ b/test/libc/nexgen32e/gclongjmp_test.c @@ -20,8 +20,8 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/gc.internal.h" #include "libc/nexgen32e/nexgen32e.h" -#include "libc/runtime/gc.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/nexgen32e/memset_test.c b/test/libc/nexgen32e/memset_test.c index c4a0b2880..60516bdf3 100644 --- a/test/libc/nexgen32e/memset_test.c +++ b/test/libc/nexgen32e/memset_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" void *_memset(void *, int, size_t) asm("memset"); diff --git a/test/libc/nexgen32e/strcaseconv_test.c b/test/libc/nexgen32e/strcaseconv_test.c index 52a636142..cfa827af2 100644 --- a/test/libc/nexgen32e/strcaseconv_test.c +++ b/test/libc/nexgen32e/strcaseconv_test.c @@ -19,7 +19,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/nexgen32e/strsak32_test.c b/test/libc/nexgen32e/strsak32_test.c index 5edb67dba..8633b72e9 100644 --- a/test/libc/nexgen32e/strsak32_test.c +++ b/test/libc/nexgen32e/strsak32_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/nexgen32e.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/thread/clone_test.c b/test/libc/runtime/clone_test.c similarity index 87% rename from test/libc/thread/clone_test.c rename to test/libc/runtime/clone_test.c index 4457364fd..e0927d196 100644 --- a/test/libc/thread/clone_test.c +++ b/test/libc/runtime/clone_test.c @@ -18,32 +18,13 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/atomic.h" #include "libc/calls/calls.h" -#include "libc/calls/struct/timespec.h" -#include "libc/dce.h" #include "libc/errno.h" -#include "libc/log/backtrace.internal.h" #include "libc/macros.internal.h" -#include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/runtime/internal.h" -#include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" -#include "libc/runtime/symbols.internal.h" -#include "libc/stdio/stdio.h" -#include "libc/sysv/consts/clock.h" -#include "libc/sysv/consts/clone.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/nr.h" -#include "libc/sysv/consts/o.h" -#include "libc/sysv/consts/prot.h" -#include "libc/sysv/consts/sig.h" -#include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" -#include "libc/thread/tls.h" -#include "libc/thread/tls2.h" -#include "libc/thread/wait0.internal.h" -#include "libc/time/time.h" int x, me, tid; atomic_int thechilde; diff --git a/test/libc/runtime/mmap_test.c b/test/libc/runtime/mmap_test.c index 33838ee4a..ee4a6371f 100644 --- a/test/libc/runtime/mmap_test.c +++ b/test/libc/runtime/mmap_test.c @@ -19,6 +19,7 @@ #include "libc/calls/calls.h" #include "libc/calls/ucontext.h" #include "libc/dce.h" +#include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/intrin/atomic.h" #include "libc/intrin/bits.h" @@ -27,8 +28,8 @@ #include "libc/linux/mmap.h" #include "libc/linux/munmap.h" #include "libc/log/log.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" @@ -42,7 +43,7 @@ #include "libc/sysv/consts/sig.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xspawn.h" #include "third_party/xed/x86.h" char testlib_enable_tmp_setup_teardown; @@ -206,15 +207,15 @@ TEST(isheap, nullPtr) { } TEST(isheap, malloc) { - ASSERT_TRUE(_isheap(gc(malloc(1)))); + ASSERT_TRUE(_isheap(_gc(malloc(1)))); } TEST(isheap, emptyMalloc) { - ASSERT_TRUE(_isheap(gc(malloc(0)))); + ASSERT_TRUE(_isheap(_gc(malloc(0)))); } TEST(isheap, mallocOffset) { - char *p = gc(malloc(131072)); + char *p = _gc(malloc(131072)); ASSERT_TRUE(_isheap(p + 100000)); } diff --git a/test/libc/runtime/mprotect_test.c b/test/libc/runtime/mprotect_test.c index 8559f72f3..30e0f4ab4 100644 --- a/test/libc/runtime/mprotect_test.c +++ b/test/libc/runtime/mprotect_test.c @@ -22,8 +22,8 @@ #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/log/log.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -60,7 +60,7 @@ void OnSigBus(int sig, struct siginfo *si, void *vctx) { #if 0 kprintf("SIGBUS%n"); kprintf("si->si_signo = %G%n", si->si_signo); - kprintf("si->si_errno = %s (%d)%n", strerrno(si->si_errno), + kprintf("si->si_errno = %s (%d)%n", _strerrno(si->si_errno), si->si_errno); kprintf("si->si_code = %s (%d)%n", GetSiCodeName(sig, si->si_code), si->si_code); @@ -111,7 +111,7 @@ TEST(mprotect, testSegfault_writeToReadOnlyAnonymous) { EXPECT_FALSE(gotsegv); EXPECT_FALSE(gotbusted); EXPECT_NE(-1, mprotect(p, PAGESIZE, PROT_READ)); - missingno(p[0]); + _missingno(p[0]); EXPECT_FALSE(gotsegv); EXPECT_FALSE(gotbusted); p[0] = 2; @@ -139,7 +139,7 @@ TEST(mprotect, testProtNone_cantEvenRead) { volatile char *p; p = gc(memalign(PAGESIZE, PAGESIZE)); EXPECT_NE(-1, mprotect(p, PAGESIZE, PROT_NONE)); - missingno(p[0]); + _missingno(p[0]); EXPECT_TRUE(gotsegv | gotbusted); EXPECT_NE(-1, mprotect(p, PAGESIZE, PROT_READ | PROT_WRITE)); } diff --git a/test/libc/sock/sendfile_test.c b/test/libc/sock/sendfile_test.c index 64240e271..5bc1597d0 100644 --- a/test/libc/sock/sendfile_test.c +++ b/test/libc/sock/sendfile_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/sockaddr.h" diff --git a/test/libc/sock/sendrecvmsg_test.c b/test/libc/sock/sendrecvmsg_test.c index 82d6590e1..646efb769 100644 --- a/test/libc/sock/sendrecvmsg_test.c +++ b/test/libc/sock/sendrecvmsg_test.c @@ -21,7 +21,7 @@ #include "libc/calls/struct/iovec.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/sock/sock.h" #include "libc/sock/struct/msghdr.h" #include "libc/sock/struct/sockaddr.h" diff --git a/test/libc/stdio/devrand_test.c b/test/libc/stdio/devrand_test.c index bcc2b1e80..9f2da5884 100644 --- a/test/libc/stdio/devrand_test.c +++ b/test/libc/stdio/devrand_test.c @@ -19,7 +19,7 @@ #include "libc/dce.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/stdio/dirstream_test.c b/test/libc/stdio/dirstream_test.c index c3ea5d5bd..bc0dfca18 100644 --- a/test/libc/stdio/dirstream_test.c +++ b/test/libc/stdio/dirstream_test.c @@ -20,13 +20,14 @@ #include "libc/calls/struct/dirent.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" #include "libc/str/str.h" #include "libc/sysv/consts/dt.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xiso8601.h" STATIC_YOINK("zip_uri_support"); STATIC_YOINK("usr/share/zoneinfo/New_York"); @@ -110,9 +111,9 @@ TEST(dirstream, test) { bool hasfoo = false; bool hasbar = false; char *dpath, *file1, *file2; - dpath = gc(xasprintf("%s.%d", "dirstream", rand())); - file1 = gc(xasprintf("%s/%s", dpath, "foo")); - file2 = gc(xasprintf("%s/%s", dpath, "bar")); + dpath = _gc(xasprintf("%s.%d", "dirstream", rand())); + file1 = _gc(xasprintf("%s/%s", dpath, "foo")); + file2 = _gc(xasprintf("%s/%s", dpath, "bar")); EXPECT_NE(-1, mkdir(dpath, 0755)); EXPECT_NE(-1, touch(file1, 0644)); EXPECT_NE(-1, touch(file2, 0644)); @@ -151,9 +152,9 @@ TEST(rewinddir, test) { bool hasfoo = false; bool hasbar = false; char *dpath, *file1, *file2; - dpath = gc(xasprintf("%s.%d", "dirstream", rand())); - file1 = gc(xasprintf("%s/%s", dpath, "foo")); - file2 = gc(xasprintf("%s/%s", dpath, "bar")); + dpath = _gc(xasprintf("%s.%d", "dirstream", rand())); + file1 = _gc(xasprintf("%s/%s", dpath, "foo")); + file2 = _gc(xasprintf("%s/%s", dpath, "bar")); EXPECT_NE(-1, mkdir(dpath, 0755)); EXPECT_NE(-1, touch(file1, 0644)); EXPECT_NE(-1, touch(file2, 0644)); diff --git a/test/libc/stdio/dtoa_test.c b/test/libc/stdio/dtoa_test.c index 0ecebcccc..b69838046 100644 --- a/test/libc/stdio/dtoa_test.c +++ b/test/libc/stdio/dtoa_test.c @@ -23,7 +23,7 @@ #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/stack.h" #include "libc/stdio/stdio.h" diff --git a/test/libc/stdio/dumphexc_test.c b/test/libc/stdio/dumphexc_test.c index f7839e4fb..91b12e9d1 100644 --- a/test/libc/stdio/dumphexc_test.c +++ b/test/libc/stdio/dumphexc_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/hex.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/stdio/ecvt_test.c b/test/libc/stdio/ecvt_test.c index 013e96640..dc6e9cd02 100644 --- a/test/libc/stdio/ecvt_test.c +++ b/test/libc/stdio/ecvt_test.c @@ -17,14 +17,15 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(fcvt, test) { int decpt, sign; ASSERT_STREQ("3.14159265358979", - gc(xasprintf("%.14f", 3.14159265358979323846))); + _gc(xasprintf("%.14f", 3.14159265358979323846))); ASSERT_STREQ("3141592653589793", fcvt(3.14159265358979323846, 15, &decpt, &sign)); ASSERT_EQ(1, decpt); diff --git a/test/libc/stdio/fgetln_test.c b/test/libc/stdio/fgetln_test.c index 2f7a00367..77e0eb5eb 100644 --- a/test/libc/stdio/fgetln_test.c +++ b/test/libc/stdio/fgetln_test.c @@ -17,18 +17,18 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xgetline.h" TEST(fgetln, test) { FILE *f; - f = fmemopen(gc(strdup(kHyperion)), kHyperionSize, "r+"); + f = fmemopen(_gc(strdup(kHyperion)), kHyperionSize, "r+"); EXPECT_STREQ("The fall of Hyperion - a Dream\n", fgetln(f, 0)); EXPECT_STREQ("John Keats\n", fgetln(f, 0)); EXPECT_STREQ("\n", fgetln(f, 0)); @@ -81,7 +81,7 @@ TEST(fgetln, testReadingFromStdin_doesntLeakMemory) { } BENCH(fgetln, bench) { - FILE *f = fmemopen(gc(strdup(kHyperion)), kHyperionSize, "r+"); + FILE *f = fmemopen(_gc(strdup(kHyperion)), kHyperionSize, "r+"); EZBENCH2("fgetln", donothing, fgetln(f, 0)); EZBENCH2("xgetline", donothing, free(xgetline(f))); fclose(f); diff --git a/test/libc/stdio/fgets_test.c b/test/libc/stdio/fgets_test.c index 37b7fb0eb..7031682a2 100644 --- a/test/libc/stdio/fgets_test.c +++ b/test/libc/stdio/fgets_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/stdio/fputs_test.c b/test/libc/stdio/fputs_test.c index 8aa1cd52d..71e28c9a3 100644 --- a/test/libc/stdio/fputs_test.c +++ b/test/libc/stdio/fputs_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/stdio/ftell_test.c b/test/libc/stdio/ftell_test.c index 58d55e855..d9ee8bb60 100644 --- a/test/libc/stdio/ftell_test.c +++ b/test/libc/stdio/ftell_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/stdio/fwrite_test.c b/test/libc/stdio/fwrite_test.c index db284b10d..5c0717787 100644 --- a/test/libc/stdio/fwrite_test.c +++ b/test/libc/stdio/fwrite_test.c @@ -22,7 +22,7 @@ #include "libc/errno.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/stdio/iconv_test.c b/test/libc/stdio/iconv_test.c index 547b904a2..4a696eca5 100644 --- a/test/libc/stdio/iconv_test.c +++ b/test/libc/stdio/iconv_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/iconv.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/stdio/joinstrlist_test.c b/test/libc/stdio/joinstrlist_test.c index 98c08a3b8..011189928 100644 --- a/test/libc/stdio/joinstrlist_test.c +++ b/test/libc/stdio/joinstrlist_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/strlist.internal.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/stdio/memory_test.c b/test/libc/stdio/memory_test.c index 4852a973a..fee346f42 100644 --- a/test/libc/stdio/memory_test.c +++ b/test/libc/stdio/memory_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/stdio/stdio.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/stdio/mt19937_test.c b/test/libc/stdio/mt19937_test.c index 53cbd1179..b20ef21a4 100644 --- a/test/libc/stdio/mt19937_test.c +++ b/test/libc/stdio/mt19937_test.c @@ -22,7 +22,7 @@ #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/grnd.h" diff --git a/test/libc/stdio/tmpfile_test.c b/test/libc/stdio/tmpfile_test.c index fbba8ae5c..1e96bffd6 100644 --- a/test/libc/stdio/tmpfile_test.c +++ b/test/libc/stdio/tmpfile_test.c @@ -21,14 +21,14 @@ #include "libc/calls/struct/stat.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" char testlib_enable_tmp_setup_teardown; char oldtmpdir[PATH_MAX]; @@ -82,7 +82,7 @@ TEST(tmpfile, renameToRealFile) { f = tmpfile(); ASSERT_EQ(2, fputs("hi", f)); ASSERT_SYS(0, 0, - linkat(AT_FDCWD, gc(xasprintf("/proc/self/fd/%d", fileno(f))), + linkat(AT_FDCWD, _gc(xasprintf("/proc/self/fd/%d", fileno(f))), AT_FDCWD, "real", AT_SYMLINK_FOLLOW)); ASSERT_EQ(0, fclose(f)); ASSERT_NE(NULL, (f = fopen("real", "r"))); diff --git a/test/libc/stdio/vappendf_test.c b/test/libc/stdio/vappendf_test.c index ca28bdb91..11d16982f 100644 --- a/test/libc/stdio/vappendf_test.c +++ b/test/libc/stdio/vappendf_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/str/bsr_test.c b/test/libc/str/bsr_test.c index 1129b7d69..55f29fa84 100644 --- a/test/libc/str/bsr_test.c +++ b/test/libc/str/bsr_test.c @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" -static unsigned Bsr(unsigned x) { +static unsigned _Bsr(unsigned x) { static const char kDebruijn[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31, @@ -35,6 +35,8 @@ static unsigned Bsr(unsigned x) { return kDebruijn[x]; } -TEST(bsr, test) { - ASSERT_EQ(bsr(0xffffffff), Bsr(0xffffffff)); +TEST(_bsr, test) { + for (int i = 1; i < 1000; ++i) { + ASSERT_EQ(_bsr(i), _Bsr(i)); + } } diff --git a/test/libc/str/bzero_test.c b/test/libc/str/bzero_test.c index c2f23efcb..7cefb35c7 100644 --- a/test/libc/str/bzero_test.c +++ b/test/libc/str/bzero_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/str/crc32c_test.c b/test/libc/str/crc32c_test.c index e15452be4..1c51d03f5 100644 --- a/test/libc/str/crc32c_test.c +++ b/test/libc/str/crc32c_test.c @@ -21,7 +21,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/str/crc32z_test.c b/test/libc/str/crc32z_test.c index d930626ef..e75d7a6be 100644 --- a/test/libc/str/crc32z_test.c +++ b/test/libc/str/crc32z_test.c @@ -23,7 +23,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/str/longsort_test.c b/test/libc/str/longsort_test.c index 77586f621..c8048cfc3 100644 --- a/test/libc/str/longsort_test.c +++ b/test/libc/str/longsort_test.c @@ -17,10 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/alg.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/rand.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" @@ -33,23 +33,23 @@ int CompareLong(const void *a, const void *b) { return 0; } -TEST(longsort, test) { +TEST(_longsort, test) { size_t n = 5000; long *a = gc(calloc(n, sizeof(long))); long *b = gc(calloc(n, sizeof(long))); rngset(a, n * sizeof(long), 0, 0); memcpy(b, a, n * sizeof(long)); qsort(a, n, sizeof(long), CompareLong); - longsort(b, n); + _longsort(b, n); ASSERT_EQ(0, memcmp(b, a, n * sizeof(long))); } -BENCH(longsort, bench) { +BENCH(_longsort, bench) { size_t n = 1000; long *p1 = gc(malloc(n * sizeof(long))); long *p2 = gc(malloc(n * sizeof(long))); rngset(p1, n * sizeof(long), 0, 0); - EZBENCH2("longsort", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n)); + EZBENCH2("_longsort", memcpy(p2, p1, n * sizeof(long)), _longsort(p2, n)); EZBENCH2("qsort", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); } diff --git a/test/libc/str/memcasecmp_test.c b/test/libc/str/memcasecmp_test.c index 3c2bf3035..baf0fea6f 100644 --- a/test/libc/str/memcasecmp_test.c +++ b/test/libc/str/memcasecmp_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/str/regex_test.c b/test/libc/str/regex_test.c index 6342eeb98..563d8b92b 100644 --- a/test/libc/str/regex_test.c +++ b/test/libc/str/regex_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/str/strcasestr_test.c b/test/libc/str/strcasestr_test.c index 174f09975..0bd777e94 100644 --- a/test/libc/str/strcasestr_test.c +++ b/test/libc/str/strcasestr_test.c @@ -21,7 +21,7 @@ #include "libc/dce.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/str/strcmp_test.c b/test/libc/str/strcmp_test.c index f2129fa8b..2a10c0fab 100644 --- a/test/libc/str/strcmp_test.c +++ b/test/libc/str/strcmp_test.c @@ -23,7 +23,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/cachesize.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/str/strstr_test.c b/test/libc/str/strstr_test.c index 6817abf21..42c97dcff 100644 --- a/test/libc/str/strstr_test.c +++ b/test/libc/str/strstr_test.c @@ -21,7 +21,7 @@ #include "libc/dce.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/str/tpenc_test.c b/test/libc/str/tpenc_test.c index 9fa94d563..f6966d923 100644 --- a/test/libc/str/tpenc_test.c +++ b/test/libc/str/tpenc_test.c @@ -20,7 +20,7 @@ #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" +#include "libc/intrin/tpenc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" @@ -28,34 +28,34 @@ STATIC_YOINK("strwidth"); volatile uint64_t v; -TEST(tpenc, test) { - EXPECT_EQ(0, tpenc(0)); - EXPECT_EQ(1, tpenc(1)); - EXPECT_EQ(' ', tpenc(' ')); - EXPECT_EQ(0x7f, tpenc(0x7f)); - EXPECT_EQ(0x008496E2, tpenc(L'▄')); - EXPECT_EQ(0x8080808080FEul, tpenc(INT_MIN)); +TEST(_tpenc, test) { + EXPECT_EQ(0, _tpenc(0)); + EXPECT_EQ(1, _tpenc(1)); + EXPECT_EQ(' ', _tpenc(' ')); + EXPECT_EQ(0x7f, _tpenc(0x7f)); + EXPECT_EQ(0x008496E2, _tpenc(L'▄')); + EXPECT_EQ(0x8080808080FEul, _tpenc(INT_MIN)); } -TEST(tpenc, theimp) { - ASSERT_EQ(0x88989FF0, tpenc(L'😈')); +TEST(_tpenc, theimp) { + ASSERT_EQ(0x88989FF0, _tpenc(L'😈')); } -TEST(tpenc, testBeyondTheStandard) { - ASSERT_EQ(0xBFBFBFBFBFFF, tpenc(-1)); +TEST(_tpenc, testBeyondTheStandard) { + ASSERT_EQ(0xBFBFBFBFBFFF, _tpenc(-1)); } -uint64_t Tpenc(int x) { - return (v = EXPROPRIATE(tpenc(VEIL("r", x)))); +uint64_t _Tpenc(int x) { + return (v = EXPROPRIATE(_tpenc(VEIL("r", x)))); } -BENCH(tpenc, bench) { - EZBENCH(donothing, Tpenc(0)); - EZBENCH(donothing, Tpenc(1)); - EZBENCH(donothing, Tpenc(' ')); - EZBENCH(donothing, Tpenc(0x7f)); - EZBENCH(donothing, Tpenc(L'▄')); - EZBENCH(donothing, Tpenc(-1)); - EZBENCH(donothing, Tpenc(INT_MIN)); +BENCH(_tpenc, bench) { + EZBENCH(donothing, _Tpenc(0)); + EZBENCH(donothing, _Tpenc(1)); + EZBENCH(donothing, _Tpenc(' ')); + EZBENCH(donothing, _Tpenc(0x7f)); + EZBENCH(donothing, _Tpenc(L'▄')); + EZBENCH(donothing, _Tpenc(-1)); + EZBENCH(donothing, _Tpenc(INT_MIN)); fprintf(stderr, "\n"); } diff --git a/test/libc/str/undeflate_test.c b/test/libc/str/undeflate_test.c deleted file mode 100644 index 0f6cbf755..000000000 --- a/test/libc/str/undeflate_test.c +++ /dev/null @@ -1,168 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/calls/struct/stat.h" -#include "libc/errno.h" -#include "libc/log/check.h" -#include "libc/macros.internal.h" -#include "libc/mem/mem.h" -#include "libc/nexgen32e/crc32.h" -#include "libc/runtime/gc.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.internal.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/str/undeflate.h" -#include "libc/sysv/consts/fileno.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/o.h" -#include "libc/sysv/consts/prot.h" -#include "libc/sysv/consts/s.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/hyperion.h" -#include "libc/testlib/testlib.h" -#include "libc/x/x.h" -#include "libc/zip.h" -#include "libc/zipos/zipos.internal.h" -#include "third_party/zlib/puff.h" -#include "third_party/zlib/zlib.h" - -STATIC_YOINK("zip_uri_support"); -STATIC_YOINK("libc/testlib/hyperion.txt"); - -TEST(undeflate, testEmbeddedPlaintextConstant) { - EXPECT_STARTSWITH("The fall of Hyperion - a Dream", kHyperion); -} - -TEST(undeflate, testStatCentralDirectory_notFound_noSysCalls) { - uint64_t c; - struct stat st; - stat("/zip/doge.txt", &st); /* warmup */ - c = __syscount; - ASSERT_EQ(-1, stat("/zip/doge.txt", &st)); - ASSERT_EQ(0, __syscount - c); - ASSERT_EQ(ENOENT, errno); -} - -TEST(undeflate, testStatCentralDirectory_isFound_noSysCalls) { - uint64_t c; - struct stat st = {0}; - c = __syscount; - ASSERT_NE(-1, stat("/zip/libc/testlib/hyperion.txt", &st)); - ASSERT_TRUE(S_ISREG(st.st_mode)); - ASSERT_EQ(kHyperionSize, st.st_size); - ASSERT_EQ(0, __syscount - c); -} - -TEST(undeflate, testOpenReadCloseEmbeddedZip) { - int fd; - char *data; - ASSERT_NE(-1, (fd = open("/zip/libc/testlib/hyperion.txt", O_RDONLY))); - ASSERT_NE(NULL, (data = gc(malloc(kHyperionSize)))); - ASSERT_EQ(kHyperionSize, read(fd, data, kHyperionSize)); - EXPECT_EQ(0, memcmp(kHyperion, data, kHyperionSize)); - EXPECT_NE(-1, close(fd)); -} - -TEST(undeflate, testEmbeddedCompressedZipFile_theHardWay) { - int fd; - size_t i; - bool found; - struct stat st; - struct DeflateState ds; - uint8_t *map, *cd, *cf, *lf, *data; - found = false; - ASSERT_NE(-1, (fd = open(FindComBinary(), O_RDONLY))); - ASSERT_NE(-1, fstat(fd, &st)); - ASSERT_NE(MAP_FAILED, - (map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))); - ASSERT_NE(NULL, (cd = GetZipCdir(map, st.st_size))); - ASSERT_GE(ZIP_CDIR_RECORDS(cd), 1); - for (i = 0, cf = map + ZIP_CDIR_OFFSET(cd); i < ZIP_CDIR_RECORDS(cd); - ++i, cf += ZIP_CFILE_HDRSIZE(cf)) { - if (strncmp("libc/testlib/hyperion.txt", ZIP_CFILE_NAME(cf), - ZIP_CFILE_NAMESIZE(cf)) == 0) { - lf = map + ZIP_CFILE_OFFSET(cf); - ASSERT_EQ(kZipCompressionDeflate, ZIP_LFILE_COMPRESSIONMETHOD(lf)); - ASSERT_EQ(kHyperionSize, ZIP_LFILE_UNCOMPRESSEDSIZE(lf)); - undeflate((data = gc(xmalloc(ZIP_LFILE_UNCOMPRESSEDSIZE(lf) * 24))), - ZIP_LFILE_UNCOMPRESSEDSIZE(lf), ZIP_LFILE_CONTENT(lf), - ZIP_LFILE_COMPRESSEDSIZE(lf), &ds); - ASSERT_EQ(ZIP_LFILE_CRC32(lf), - crc32_z(0, data, ZIP_LFILE_UNCOMPRESSEDSIZE(lf))); - ASSERT_EQ(0, memcmp(kHyperion, data, ZIP_LFILE_UNCOMPRESSEDSIZE(lf))); - found = true; - break; - } - } - ASSERT_NE(-1, munmap(map, st.st_size)); - ASSERT_NE(-1, close(fd)); - ASSERT_TRUE(found); -} - -uint8_t *buf_; -size_t bufsize_; -uint8_t *data_; -size_t compressedsize_; -size_t uncompressedsize_; -struct DeflateState ds_; - -void Inflate(void) { - z_stream stream; - stream.next_in = data_; - stream.zalloc = Z_NULL; - stream.zfree = Z_NULL; - stream.avail_in = compressedsize_; - stream.total_in = compressedsize_; - stream.next_out = buf_; - stream.avail_out = bufsize_; - stream.total_out = bufsize_; - CHECK_EQ(Z_OK, inflateInit2(&stream, -MAX_WBITS)); - CHECK_EQ(Z_STREAM_END, inflate(&stream, Z_FINISH)); - CHECK_EQ(Z_OK, inflateEnd(&stream)); -} - -void Undeflate(void) { - undeflate(buf_, uncompressedsize_, data_, compressedsize_, &ds_); -} - -void Puff(void) { - size_t insize = compressedsize_; - size_t outsize = uncompressedsize_; - CHECK_EQ(0, puff(buf_, &outsize, data_, &insize)); -} - -BENCH(undeflate, bench) { - size_t cf, lf; - struct Zipos *zipos; - struct ZiposUri path; - zipos = __zipos_get(); - path.path = "libc/testlib/hyperion.txt"; - path.len = strlen(path.path); - cf = __zipos_find(zipos, &path); - lf = GetZipCfileOffset(zipos->map + cf); - data_ = ZIP_LFILE_CONTENT(zipos->map + lf); - compressedsize_ = ZIP_LFILE_COMPRESSEDSIZE(zipos->map + lf); - uncompressedsize_ = ZIP_LFILE_UNCOMPRESSEDSIZE(zipos->map + lf); - bufsize_ = ROUNDUP(uncompressedsize_, FRAMESIZE / 2); - buf_ = gc(malloc(bufsize_)); - EZBENCH(donothing, Puff()); - EZBENCH(donothing, Inflate()); - EZBENCH(donothing, Undeflate()); -} diff --git a/test/libc/thread/pthread_barrier_wait_test.c b/test/libc/thread/pthread_barrier_wait_test.c index dd9942fed..2a826fb41 100644 --- a/test/libc/thread/pthread_barrier_wait_test.c +++ b/test/libc/thread/pthread_barrier_wait_test.c @@ -21,7 +21,7 @@ #include "libc/errno.h" #include "libc/intrin/atomic.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" #include "libc/thread/thread.h" diff --git a/test/libc/thread/pthread_rwlock_rdlock_test.c b/test/libc/thread/pthread_rwlock_rdlock_test.c index 28f4eab48..b2e259168 100644 --- a/test/libc/thread/pthread_rwlock_rdlock_test.c +++ b/test/libc/thread/pthread_rwlock_rdlock_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/atomic.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" #include "libc/thread/thread.h" diff --git a/test/libc/thread/spawn_test.c b/test/libc/thread/spawn_test.c index 084f00341..bd7c6815f 100644 --- a/test/libc/thread/spawn_test.c +++ b/test/libc/thread/spawn_test.c @@ -23,7 +23,7 @@ #include "libc/intrin/atomic.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" diff --git a/test/libc/time/clock_gettime_test.c b/test/libc/time/clock_gettime_test.c index a10d637ac..05eaf6c75 100644 --- a/test/libc/time/clock_gettime_test.c +++ b/test/libc/time/clock_gettime_test.c @@ -19,7 +19,7 @@ #include "libc/calls/struct/timespec.h" #include "libc/fmt/conv.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/clock.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/tinymath/acos_test.c b/test/libc/tinymath/acos_test.c index 90a97e836..f9836b5b2 100644 --- a/test/libc/tinymath/acos_test.c +++ b/test/libc/tinymath/acos_test.c @@ -17,22 +17,22 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#include "libc/mem/gc.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" double acos_(double) asm("acos"); #define acos acos_ TEST(acos, test) { - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(0.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(-0.)))); - EXPECT_STREQ("1.0471975511966", gc(xasprintf("%.15g", acos(.5)))); - EXPECT_STREQ("2.0943951023932", gc(xasprintf("%.15g", acos(-.5)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", acos(1.)))); - EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", acos(-1.)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", acos(0.)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", acos(-0.)))); + EXPECT_STREQ("1.0471975511966", _gc(xasprintf("%.15g", acos(.5)))); + EXPECT_STREQ("2.0943951023932", _gc(xasprintf("%.15g", acos(-.5)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", acos(1.)))); + EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", acos(-1.)))); EXPECT_TRUE(isnan(acos(1.5))); EXPECT_TRUE(isnan(acos(-1.5))); EXPECT_TRUE(isnan(acos(2.))); @@ -40,7 +40,7 @@ TEST(acos, test) { EXPECT_TRUE(isnan(acos(-NAN))); EXPECT_TRUE(isnan(acos(INFINITY))); EXPECT_TRUE(isnan(acos(-INFINITY))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(__DBL_MIN__)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", acos(__DBL_MIN__)))); EXPECT_TRUE(isnan(acos(__DBL_MAX__))); } diff --git a/test/libc/tinymath/acosh_test.c b/test/libc/tinymath/acosh_test.c index 82c1ddbee..d358ec3bc 100644 --- a/test/libc/tinymath/acosh_test.c +++ b/test/libc/tinymath/acosh_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/asin_test.c b/test/libc/tinymath/asin_test.c index ac714c3a2..f12c22f79 100644 --- a/test/libc/tinymath/asin_test.c +++ b/test/libc/tinymath/asin_test.c @@ -17,22 +17,22 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#include "libc/mem/gc.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" double asin_(double) asm("asin"); #define asin asin_ TEST(asin, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", asin(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", asin(-0.)))); - EXPECT_STREQ("0.523598775598299", gc(xasprintf("%.15g", asin(.5)))); - EXPECT_STREQ("-0.523598775598299", gc(xasprintf("%.15g", asin(-.5)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", asin(1.)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", asin(-1.)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", asin(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", asin(-0.)))); + EXPECT_STREQ("0.523598775598299", _gc(xasprintf("%.15g", asin(.5)))); + EXPECT_STREQ("-0.523598775598299", _gc(xasprintf("%.15g", asin(-.5)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", asin(1.)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", asin(-1.)))); EXPECT_TRUE(isnan(asin(1.5))); EXPECT_TRUE(isnan(asin(-1.5))); EXPECT_TRUE(isnan(asin(NAN))); @@ -40,7 +40,7 @@ TEST(asin, test) { EXPECT_TRUE(isnan(asin(INFINITY))); EXPECT_TRUE(isnan(asin(-INFINITY))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", asin(__DBL_MIN__)))); + _gc(xasprintf("%.15g", asin(__DBL_MIN__)))); EXPECT_TRUE(isnan(asin(__DBL_MAX__))); } diff --git a/test/libc/tinymath/asinh_test.c b/test/libc/tinymath/asinh_test.c index 564a58b54..4ba5590e8 100644 --- a/test/libc/tinymath/asinh_test.c +++ b/test/libc/tinymath/asinh_test.c @@ -17,36 +17,37 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define asinhl(x) asinhl(VEIL("t", (long double)(x))) #define asinh(x) asinh(VEIL("x", (double)(x))) #define asinhf(x) asinhf(VEIL("x", (float)(x))) TEST(asinh, test) { - EXPECT_STREQ(".481211825059603", gc(xdtoa(asinh(+.5)))); - EXPECT_STREQ("-.481211825059603", gc(xdtoa(asinh(-.5)))); - EXPECT_STREQ("0", gc(xdtoa(asinh(0)))); - EXPECT_STREQ("NAN", gc(xdtoa(asinh(NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(asinh(INFINITY)))); + EXPECT_STREQ(".481211825059603", _gc(xdtoa(asinh(+.5)))); + EXPECT_STREQ("-.481211825059603", _gc(xdtoa(asinh(-.5)))); + EXPECT_STREQ("0", _gc(xdtoa(asinh(0)))); + EXPECT_STREQ("NAN", _gc(xdtoa(asinh(NAN)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(asinh(INFINITY)))); EXPECT_STREQ("-2.1073424255447e-08", - gc(xasprintf("%.15g", asinh(-2.1073424255447e-08)))); + _gc(xasprintf("%.15g", asinh(-2.1073424255447e-08)))); } TEST(asinhf, test) { - EXPECT_STREQ(".481212", gc(xdtoaf(asinhf(+.5)))); - EXPECT_STREQ("-.481212", gc(xdtoaf(asinhf(-.5)))); - EXPECT_STREQ("0", gc(xdtoaf(asinhf(0)))); - EXPECT_STREQ("NAN", gc(xdtoaf(asinhf(NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(asinhf(INFINITY)))); + EXPECT_STREQ(".481212", _gc(xdtoaf(asinhf(+.5)))); + EXPECT_STREQ("-.481212", _gc(xdtoaf(asinhf(-.5)))); + EXPECT_STREQ("0", _gc(xdtoaf(asinhf(0)))); + EXPECT_STREQ("NAN", _gc(xdtoaf(asinhf(NAN)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(asinhf(INFINITY)))); } TEST(asinhl, test) { - EXPECT_STREQ(".4812118250596034", gc(xdtoal(asinhl(+.5)))); - EXPECT_STREQ("-.4812118250596034", gc(xdtoal(asinhl(-.5)))); - EXPECT_STREQ("0", gc(xdtoal(asinhl(0)))); - EXPECT_STREQ("NAN", gc(xdtoal(asinhl(NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(asinhl(INFINITY)))); + EXPECT_STREQ(".4812118250596034", _gc(xdtoal(asinhl(+.5)))); + EXPECT_STREQ("-.4812118250596034", _gc(xdtoal(asinhl(-.5)))); + EXPECT_STREQ("0", _gc(xdtoal(asinhl(0)))); + EXPECT_STREQ("NAN", _gc(xdtoal(asinhl(NAN)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(asinhl(INFINITY)))); } diff --git a/test/libc/tinymath/atan2_test.c b/test/libc/tinymath/atan2_test.c index 66ca2d466..ac4d80b32 100644 --- a/test/libc/tinymath/atan2_test.c +++ b/test/libc/tinymath/atan2_test.c @@ -17,149 +17,149 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(atan2, yx) { - EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan(-.5 / 1.5)))); - EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan2(-.5, 1.5)))); + EXPECT_STREQ("-0.321750554396642", _gc(xasprintf("%.15g", atan(-.5 / 1.5)))); + EXPECT_STREQ("-0.321750554396642", _gc(xasprintf("%.15g", atan2(-.5, 1.5)))); } TEST(atan2, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., 0.)))); - EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -0.)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., .5)))); - EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -.5)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., 1.)))); - EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -1.)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., 1.5)))); - EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -1.5)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., 0.)))); + EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", atan2(0., -0.)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., .5)))); + EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", atan2(0., -.5)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., 1.)))); + EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", atan2(0., -1.)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., 1.5)))); + EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", atan2(0., -1.5)))); EXPECT_TRUE(isnan(atan2(0., NAN))); EXPECT_TRUE(isnan(atan2(0., -NAN))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., INFINITY)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(0., -INFINITY)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., __DBL_MIN__)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., __DBL_MAX__)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., 0.)))); - EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., .5)))); - EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -.5)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., 1.)))); - EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -1.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., 1.5)))); - EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -1.5)))); + _gc(xasprintf("%.15g", atan2(0., -INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., __DBL_MIN__)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(0., __DBL_MAX__)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., 0.)))); + EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", atan2(-0., -0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., .5)))); + EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", atan2(-0., -.5)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., 1.)))); + EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", atan2(-0., -1.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., 1.5)))); + EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", atan2(-0., -1.5)))); EXPECT_TRUE(isnan(atan2(-0., NAN))); EXPECT_TRUE(isnan(atan2(-0., -NAN))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., INFINITY)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., INFINITY)))); EXPECT_STREQ("-3.14159265358979", - gc(xasprintf("%.15g", atan2(-0., -INFINITY)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., __DBL_MIN__)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., __DBL_MAX__)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(.5, 0.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(.5, -0.)))); - EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(.5, .5)))); - EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", atan2(.5, -.5)))); - EXPECT_STREQ("0.463647609000806", gc(xasprintf("%.15g", atan2(.5, 1.)))); - EXPECT_STREQ("2.67794504458899", gc(xasprintf("%.15g", atan2(.5, -1.)))); - EXPECT_STREQ("0.321750554396642", gc(xasprintf("%.15g", atan2(.5, 1.5)))); - EXPECT_STREQ("2.81984209919315", gc(xasprintf("%.15g", atan2(.5, -1.5)))); + _gc(xasprintf("%.15g", atan2(-0., -INFINITY)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., __DBL_MIN__)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-0., __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(.5, 0.)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(.5, -0.)))); + EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", atan2(.5, .5)))); + EXPECT_STREQ("2.35619449019234", _gc(xasprintf("%.15g", atan2(.5, -.5)))); + EXPECT_STREQ("0.463647609000806", _gc(xasprintf("%.15g", atan2(.5, 1.)))); + EXPECT_STREQ("2.67794504458899", _gc(xasprintf("%.15g", atan2(.5, -1.)))); + EXPECT_STREQ("0.321750554396642", _gc(xasprintf("%.15g", atan2(.5, 1.5)))); + EXPECT_STREQ("2.81984209919315", _gc(xasprintf("%.15g", atan2(.5, -1.5)))); EXPECT_TRUE(isnan(atan2(.5, NAN))); EXPECT_TRUE(isnan(atan2(.5, -NAN))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(.5, INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(.5, INFINITY)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(.5, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(.5, -INFINITY)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(.5, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(.5, __DBL_MIN__)))); EXPECT_STREQ("2.781342323134e-309", - gc(xasprintf("%.15g", atan2(.5, __DBL_MAX__)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-.5, 0.)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-.5, -0.)))); - EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan2(-.5, .5)))); - EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", atan2(-.5, -.5)))); - EXPECT_STREQ("-0.463647609000806", gc(xasprintf("%.15g", atan2(-.5, 1.)))); - EXPECT_STREQ("-2.67794504458899", gc(xasprintf("%.15g", atan2(-.5, -1.)))); - EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan2(-.5, 1.5)))); - EXPECT_STREQ("-2.81984209919315", gc(xasprintf("%.15g", atan2(-.5, -1.5)))); + _gc(xasprintf("%.15g", atan2(.5, __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan2(-.5, 0.)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan2(-.5, -0.)))); + EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", atan2(-.5, .5)))); + EXPECT_STREQ("-2.35619449019234", _gc(xasprintf("%.15g", atan2(-.5, -.5)))); + EXPECT_STREQ("-0.463647609000806", _gc(xasprintf("%.15g", atan2(-.5, 1.)))); + EXPECT_STREQ("-2.67794504458899", _gc(xasprintf("%.15g", atan2(-.5, -1.)))); + EXPECT_STREQ("-0.321750554396642", _gc(xasprintf("%.15g", atan2(-.5, 1.5)))); + EXPECT_STREQ("-2.81984209919315", _gc(xasprintf("%.15g", atan2(-.5, -1.5)))); EXPECT_TRUE(isnan(atan2(-.5, NAN))); EXPECT_TRUE(isnan(atan2(-.5, -NAN))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-.5, INFINITY)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-.5, INFINITY)))); EXPECT_STREQ("-3.14159265358979", - gc(xasprintf("%.15g", atan2(-.5, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(-.5, -INFINITY)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-.5, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(-.5, __DBL_MIN__)))); EXPECT_STREQ("-2.781342323134e-309", - gc(xasprintf("%.15g", atan2(-.5, __DBL_MAX__)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1., 0.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1., -0.)))); - EXPECT_STREQ("1.10714871779409", gc(xasprintf("%.15g", atan2(1., .5)))); - EXPECT_STREQ("2.0344439357957", gc(xasprintf("%.15g", atan2(1., -.5)))); - EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(1., 1.)))); - EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", atan2(1., -1.)))); - EXPECT_STREQ("0.588002603547568", gc(xasprintf("%.15g", atan2(1., 1.5)))); - EXPECT_STREQ("2.55359005004223", gc(xasprintf("%.15g", atan2(1., -1.5)))); + _gc(xasprintf("%.15g", atan2(-.5, __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(1., 0.)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(1., -0.)))); + EXPECT_STREQ("1.10714871779409", _gc(xasprintf("%.15g", atan2(1., .5)))); + EXPECT_STREQ("2.0344439357957", _gc(xasprintf("%.15g", atan2(1., -.5)))); + EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", atan2(1., 1.)))); + EXPECT_STREQ("2.35619449019234", _gc(xasprintf("%.15g", atan2(1., -1.)))); + EXPECT_STREQ("0.588002603547568", _gc(xasprintf("%.15g", atan2(1., 1.5)))); + EXPECT_STREQ("2.55359005004223", _gc(xasprintf("%.15g", atan2(1., -1.5)))); EXPECT_TRUE(isnan(atan2(1., NAN))); EXPECT_TRUE(isnan(atan2(1., -NAN))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(1., INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(1., INFINITY)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(1., -INFINITY)))); + _gc(xasprintf("%.15g", atan2(1., -INFINITY)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(1., __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(1., __DBL_MIN__)))); EXPECT_STREQ("5.562684646268e-309", - gc(xasprintf("%.15g", atan2(1., __DBL_MAX__)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1., 0.)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1., -0.)))); - EXPECT_STREQ("-1.10714871779409", gc(xasprintf("%.15g", atan2(-1., .5)))); - EXPECT_STREQ("-2.0344439357957", gc(xasprintf("%.15g", atan2(-1., -.5)))); - EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan2(-1., 1.)))); - EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", atan2(-1., -1.)))); - EXPECT_STREQ("-0.588002603547568", gc(xasprintf("%.15g", atan2(-1., 1.5)))); - EXPECT_STREQ("-2.55359005004223", gc(xasprintf("%.15g", atan2(-1., -1.5)))); + _gc(xasprintf("%.15g", atan2(1., __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan2(-1., 0.)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan2(-1., -0.)))); + EXPECT_STREQ("-1.10714871779409", _gc(xasprintf("%.15g", atan2(-1., .5)))); + EXPECT_STREQ("-2.0344439357957", _gc(xasprintf("%.15g", atan2(-1., -.5)))); + EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", atan2(-1., 1.)))); + EXPECT_STREQ("-2.35619449019234", _gc(xasprintf("%.15g", atan2(-1., -1.)))); + EXPECT_STREQ("-0.588002603547568", _gc(xasprintf("%.15g", atan2(-1., 1.5)))); + EXPECT_STREQ("-2.55359005004223", _gc(xasprintf("%.15g", atan2(-1., -1.5)))); EXPECT_TRUE(isnan(atan2(-1., NAN))); EXPECT_TRUE(isnan(atan2(-1., -NAN))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1., INFINITY)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-1., INFINITY)))); EXPECT_STREQ("-3.14159265358979", - gc(xasprintf("%.15g", atan2(-1., -INFINITY)))); + _gc(xasprintf("%.15g", atan2(-1., -INFINITY)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-1., __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(-1., __DBL_MIN__)))); EXPECT_STREQ("-5.562684646268e-309", - gc(xasprintf("%.15g", atan2(-1., __DBL_MAX__)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1.5, 0.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1.5, -0.)))); - EXPECT_STREQ("1.24904577239825", gc(xasprintf("%.15g", atan2(1.5, .5)))); - EXPECT_STREQ("1.89254688119154", gc(xasprintf("%.15g", atan2(1.5, -.5)))); - EXPECT_STREQ("0.982793723247329", gc(xasprintf("%.15g", atan2(1.5, 1.)))); - EXPECT_STREQ("2.15879893034246", gc(xasprintf("%.15g", atan2(1.5, -1.)))); - EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(1.5, 1.5)))); - EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", atan2(1.5, -1.5)))); + _gc(xasprintf("%.15g", atan2(-1., __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(1.5, 0.)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(1.5, -0.)))); + EXPECT_STREQ("1.24904577239825", _gc(xasprintf("%.15g", atan2(1.5, .5)))); + EXPECT_STREQ("1.89254688119154", _gc(xasprintf("%.15g", atan2(1.5, -.5)))); + EXPECT_STREQ("0.982793723247329", _gc(xasprintf("%.15g", atan2(1.5, 1.)))); + EXPECT_STREQ("2.15879893034246", _gc(xasprintf("%.15g", atan2(1.5, -1.)))); + EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", atan2(1.5, 1.5)))); + EXPECT_STREQ("2.35619449019234", _gc(xasprintf("%.15g", atan2(1.5, -1.5)))); EXPECT_TRUE(isnan(atan2(1.5, NAN))); EXPECT_TRUE(isnan(atan2(1.5, -NAN))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(1.5, INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(1.5, INFINITY)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(1.5, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(1.5, -INFINITY)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(1.5, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(1.5, __DBL_MIN__)))); EXPECT_STREQ("8.34402696940201e-309", - gc(xasprintf("%.15g", atan2(1.5, __DBL_MAX__)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1.5, 0.)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1.5, -0.)))); - EXPECT_STREQ("-1.24904577239825", gc(xasprintf("%.15g", atan2(-1.5, .5)))); - EXPECT_STREQ("-1.89254688119154", gc(xasprintf("%.15g", atan2(-1.5, -.5)))); - EXPECT_STREQ("-0.982793723247329", gc(xasprintf("%.15g", atan2(-1.5, 1.)))); - EXPECT_STREQ("-2.15879893034246", gc(xasprintf("%.15g", atan2(-1.5, -1.)))); - EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan2(-1.5, 1.5)))); - EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", atan2(-1.5, -1.5)))); + _gc(xasprintf("%.15g", atan2(1.5, __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan2(-1.5, 0.)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan2(-1.5, -0.)))); + EXPECT_STREQ("-1.24904577239825", _gc(xasprintf("%.15g", atan2(-1.5, .5)))); + EXPECT_STREQ("-1.89254688119154", _gc(xasprintf("%.15g", atan2(-1.5, -.5)))); + EXPECT_STREQ("-0.982793723247329", _gc(xasprintf("%.15g", atan2(-1.5, 1.)))); + EXPECT_STREQ("-2.15879893034246", _gc(xasprintf("%.15g", atan2(-1.5, -1.)))); + EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", atan2(-1.5, 1.5)))); + EXPECT_STREQ("-2.35619449019234", _gc(xasprintf("%.15g", atan2(-1.5, -1.5)))); EXPECT_TRUE(isnan(atan2(-1.5, NAN))); EXPECT_TRUE(isnan(atan2(-1.5, -NAN))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1.5, INFINITY)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-1.5, INFINITY)))); EXPECT_STREQ("-3.14159265358979", - gc(xasprintf("%.15g", atan2(-1.5, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(-1.5, -INFINITY)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-1.5, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(-1.5, __DBL_MIN__)))); EXPECT_STREQ("-8.34402696940201e-309", - gc(xasprintf("%.15g", atan2(-1.5, __DBL_MAX__)))); + _gc(xasprintf("%.15g", atan2(-1.5, __DBL_MAX__)))); EXPECT_TRUE(isnan(atan2(NAN, 0.))); EXPECT_TRUE(isnan(atan2(NAN, -0.))); EXPECT_TRUE(isnan(atan2(NAN, .5))); @@ -188,107 +188,111 @@ TEST(atan2, test) { EXPECT_TRUE(isnan(atan2(-NAN, -INFINITY))); EXPECT_TRUE(isnan(atan2(-NAN, __DBL_MIN__))); EXPECT_TRUE(isnan(atan2(-NAN, __DBL_MAX__))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, 0.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, -0.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, .5)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, -.5)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, 1.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, -1.)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, 1.5)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(INFINITY, 0.)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(INFINITY, -1.5)))); + _gc(xasprintf("%.15g", atan2(INFINITY, -0.)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(INFINITY, .5)))); + EXPECT_STREQ("1.5707963267949", + _gc(xasprintf("%.15g", atan2(INFINITY, -.5)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan2(INFINITY, 1.)))); + EXPECT_STREQ("1.5707963267949", + _gc(xasprintf("%.15g", atan2(INFINITY, -1.)))); + EXPECT_STREQ("1.5707963267949", + _gc(xasprintf("%.15g", atan2(INFINITY, 1.5)))); + EXPECT_STREQ("1.5707963267949", + _gc(xasprintf("%.15g", atan2(INFINITY, -1.5)))); EXPECT_TRUE(isnan(atan2(INFINITY, NAN))); EXPECT_TRUE(isnan(atan2(INFINITY, -NAN))); EXPECT_STREQ("0.785398163397448", - gc(xasprintf("%.15g", atan2(INFINITY, INFINITY)))); + _gc(xasprintf("%.15g", atan2(INFINITY, INFINITY)))); EXPECT_STREQ("2.35619449019234", - gc(xasprintf("%.15g", atan2(INFINITY, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(INFINITY, -INFINITY)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(INFINITY, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(INFINITY, __DBL_MIN__)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(INFINITY, __DBL_MAX__)))); + _gc(xasprintf("%.15g", atan2(INFINITY, __DBL_MAX__)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, 0.)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, 0.)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, -0.)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, -0.)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, .5)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, .5)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, -.5)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, -.5)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, 1.)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, 1.)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, -1.)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, -1.)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, 1.5)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, 1.5)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, -1.5)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, -1.5)))); EXPECT_TRUE(isnan(atan2(-INFINITY, NAN))); EXPECT_TRUE(isnan(atan2(-INFINITY, -NAN))); EXPECT_STREQ("-0.785398163397448", - gc(xasprintf("%.15g", atan2(-INFINITY, INFINITY)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, INFINITY)))); EXPECT_STREQ("-2.35619449019234", - gc(xasprintf("%.15g", atan2(-INFINITY, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, -INFINITY)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, __DBL_MIN__)))); EXPECT_STREQ("-1.5707963267949", - gc(xasprintf("%.15g", atan2(-INFINITY, __DBL_MAX__)))); + _gc(xasprintf("%.15g", atan2(-INFINITY, __DBL_MAX__)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, 0.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, 0.)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, -0.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, -0.)))); EXPECT_STREQ("4.4501477170144e-308", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, .5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, .5)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, -.5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, -.5)))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, 1.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, 1.)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, -1.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, -1.)))); EXPECT_STREQ("1.48338257233813e-308", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, 1.5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, 1.5)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, -1.5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, -1.5)))); EXPECT_TRUE(isnan(atan2(__DBL_MIN__, NAN))); EXPECT_TRUE(isnan(atan2(__DBL_MIN__, -NAN))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(__DBL_MIN__, INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(__DBL_MIN__, INFINITY)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, -INFINITY)))); EXPECT_STREQ("0.785398163397448", - gc(xasprintf("%.15g", atan2(__DBL_MIN__, __DBL_MIN__)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(__DBL_MIN__, __DBL_MAX__)))); + _gc(xasprintf("%.15g", atan2(__DBL_MIN__, __DBL_MIN__)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(__DBL_MIN__, __DBL_MAX__)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, 0.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, 0.)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, -0.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, -0.)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, .5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, .5)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, -.5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, -.5)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, 1.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, 1.)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, -1.)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, -1.)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, 1.5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, 1.5)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, -1.5)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, -1.5)))); EXPECT_TRUE(isnan(atan2(__DBL_MAX__, NAN))); EXPECT_TRUE(isnan(atan2(__DBL_MAX__, -NAN))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(__DBL_MAX__, INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan2(__DBL_MAX__, INFINITY)))); EXPECT_STREQ("3.14159265358979", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, -INFINITY)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, -INFINITY)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MIN__)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MIN__)))); EXPECT_STREQ("0.785398163397448", - gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MAX__)))); + _gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MAX__)))); EXPECT_STREQ("-0", - gc(xasprintf("%.15g", atan2(-0.000000000000001, INFINITY)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1, INFINITY)))); + _gc(xasprintf("%.15g", atan2(-0.000000000000001, INFINITY)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan2(-1, INFINITY)))); EXPECT_STREQ( - "-0", gc(xasprintf("%.15g", atan2(-1.7976931348623157e308, INFINITY)))); + "-0", _gc(xasprintf("%.15g", atan2(-1.7976931348623157e308, INFINITY)))); EXPECT_STREQ("1.5707963267949", - gc(xasprintf("%.15g", atan2(1.4142135623731, 0)))); + _gc(xasprintf("%.15g", atan2(1.4142135623731, 0)))); } BENCH(atan2, bench) { diff --git a/test/libc/tinymath/atan2l_test.c b/test/libc/tinymath/atan2l_test.c index f9cd0b6f1..a5e0bc054 100644 --- a/test/libc/tinymath/atan2l_test.c +++ b/test/libc/tinymath/atan2l_test.c @@ -17,39 +17,40 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(atan2l, test) { volatile double a = -.9816175436063843; volatile double b = -.1908585813741899; - EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2f(b, a)))); - EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2(b, a)))); - EXPECT_STREQ("-2.95", gc(xasprintf("%.2Lf", atan2l(b, a)))); + EXPECT_STREQ("-2.95", _gc(xasprintf("%.2f", atan2f(b, a)))); + EXPECT_STREQ("-2.95", _gc(xasprintf("%.2f", atan2(b, a)))); + EXPECT_STREQ("-2.95", _gc(xasprintf("%.2Lf", atan2l(b, a)))); } TEST(atan2, testSpecialCases) { - ASSERT_STREQ("NAN", gc(xdtoa(atan2(NAN, 0)))); - ASSERT_STREQ("NAN", gc(xdtoa(atan2(0, NAN)))); - ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +0.)))); - ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +1.)))); - ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +2.)))); - ASSERT_STREQ("0", gc(xdtoa(atan2(1, INFINITY)))); - ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -0.)))); - ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -1.)))); - ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -2.)))); - ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-1., -0.)))); - ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-1., +0.)))); - ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-2., -0.)))); - ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-2., +0.)))); - ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+1., -0.)))); - ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+1., +0.)))); - ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+2., -0.)))); - ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+2., +0.)))); - ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(INFINITY, 1)))); - ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(INFINITY, -1)))); - ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(1, -INFINITY)))); - ASSERT_STREQ("2.356194490192345", gc(xdtoal(atan2(INFINITY, -INFINITY)))); - ASSERT_STREQ(".7853981633974483", gc(xdtoal(atan2(INFINITY, INFINITY)))); + ASSERT_STREQ("NAN", _gc(xdtoa(atan2(NAN, 0)))); + ASSERT_STREQ("NAN", _gc(xdtoa(atan2(0, NAN)))); + ASSERT_STREQ("0", _gc(xdtoa(atan2(+0., +0.)))); + ASSERT_STREQ("0", _gc(xdtoa(atan2(+0., +1.)))); + ASSERT_STREQ("0", _gc(xdtoa(atan2(+0., +2.)))); + ASSERT_STREQ("0", _gc(xdtoa(atan2(1, INFINITY)))); + ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(+0., -0.)))); + ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(+0., -1.)))); + ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(+0., -2.)))); + ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-1., -0.)))); + ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-1., +0.)))); + ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-2., -0.)))); + ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-2., +0.)))); + ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+1., -0.)))); + ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+1., +0.)))); + ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+2., -0.)))); + ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+2., +0.)))); + ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(INFINITY, 1)))); + ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(INFINITY, -1)))); + ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(1, -INFINITY)))); + ASSERT_STREQ("2.356194490192345", _gc(xdtoal(atan2(INFINITY, -INFINITY)))); + ASSERT_STREQ(".7853981633974483", _gc(xdtoal(atan2(INFINITY, INFINITY)))); } diff --git a/test/libc/tinymath/atan_test.c b/test/libc/tinymath/atan_test.c index dbd435c4d..3518bbb4d 100644 --- a/test/libc/tinymath/atan_test.c +++ b/test/libc/tinymath/atan_test.c @@ -17,27 +17,27 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(atan, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", atan(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan(-0.)))); - EXPECT_STREQ("0.463647609000806", gc(xasprintf("%.15g", atan(.5)))); - EXPECT_STREQ("-0.463647609000806", gc(xasprintf("%.15g", atan(-.5)))); - EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan(1.)))); - EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan(-1.)))); - EXPECT_STREQ("0.982793723247329", gc(xasprintf("%.15g", atan(1.5)))); - EXPECT_STREQ("-0.982793723247329", gc(xasprintf("%.15g", atan(-1.5)))); - EXPECT_STREQ("nan", gc(xasprintf("%.15g", atan(NAN)))); - EXPECT_STREQ("-nan", gc(xasprintf("%.15g", atan(-NAN)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(INFINITY)))); - EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan(-INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan(-0.)))); + EXPECT_STREQ("0.463647609000806", _gc(xasprintf("%.15g", atan(.5)))); + EXPECT_STREQ("-0.463647609000806", _gc(xasprintf("%.15g", atan(-.5)))); + EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", atan(1.)))); + EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", atan(-1.)))); + EXPECT_STREQ("0.982793723247329", _gc(xasprintf("%.15g", atan(1.5)))); + EXPECT_STREQ("-0.982793723247329", _gc(xasprintf("%.15g", atan(-1.5)))); + EXPECT_STREQ("nan", _gc(xasprintf("%.15g", atan(NAN)))); + EXPECT_STREQ("-nan", _gc(xasprintf("%.15g", atan(-NAN)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan(INFINITY)))); + EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan(-INFINITY)))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", atan(__DBL_MIN__)))); - EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(__DBL_MAX__)))); + _gc(xasprintf("%.15g", atan(__DBL_MIN__)))); + EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan(__DBL_MAX__)))); } BENCH(atanl, bench) { diff --git a/test/libc/tinymath/atanh_test.c b/test/libc/tinymath/atanh_test.c index c0dd57aa4..6804ab6ce 100644 --- a/test/libc/tinymath/atanh_test.c +++ b/test/libc/tinymath/atanh_test.c @@ -17,46 +17,47 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define atanhl(x) atanhl(VEIL("t", (long double)(x))) #define atanh(x) atanh(VEIL("x", (double)(x))) #define atanhf(x) atanhf(VEIL("x", (float)(x))) TEST(atanh, test) { - EXPECT_STREQ("0", gc(xdtoa(atanh(0)))); - EXPECT_STREQ("-0", gc(xdtoa(atanh(-0.)))); - EXPECT_STREQ(".549306144334055", gc(xdtoa(atanh(.5)))); - EXPECT_STREQ("-.549306144334055", gc(xdtoa(atanh(-.5)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(atanh(+1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(atanh(-1)))); + EXPECT_STREQ("0", _gc(xdtoa(atanh(0)))); + EXPECT_STREQ("-0", _gc(xdtoa(atanh(-0.)))); + EXPECT_STREQ(".549306144334055", _gc(xdtoa(atanh(.5)))); + EXPECT_STREQ("-.549306144334055", _gc(xdtoa(atanh(-.5)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(atanh(+1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoa(atanh(-1)))); EXPECT_TRUE(isnan(atanh(+1.1))); EXPECT_TRUE(isnan(atanh(-1.1))); EXPECT_STREQ("-2.1073424255447e-08", - gc(xasprintf("%.15g", atanh(-2.1073424255447e-08)))); + _gc(xasprintf("%.15g", atanh(-2.1073424255447e-08)))); } TEST(atanhl, test) { - EXPECT_STREQ("0", gc(xdtoal(atanhl(0)))); - EXPECT_STREQ("-0", gc(xdtoal(atanhl(-0.)))); - EXPECT_STREQ(".5493061443340548", gc(xdtoal(atanhl(.5)))); - EXPECT_STREQ("-.5493061443340548", gc(xdtoal(atanhl(-.5)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(atanhl(+1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoal(atanhl(-1)))); + EXPECT_STREQ("0", _gc(xdtoal(atanhl(0)))); + EXPECT_STREQ("-0", _gc(xdtoal(atanhl(-0.)))); + EXPECT_STREQ(".5493061443340548", _gc(xdtoal(atanhl(.5)))); + EXPECT_STREQ("-.5493061443340548", _gc(xdtoal(atanhl(-.5)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(atanhl(+1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoal(atanhl(-1)))); EXPECT_TRUE(isnan(atanhl(+1.1))); EXPECT_TRUE(isnan(atanhl(-1.1))); } TEST(atanhf, test) { - EXPECT_STREQ("0", gc(xdtoaf(atanhf(0)))); - EXPECT_STREQ("-0", gc(xdtoaf(atanhf(-0.)))); - EXPECT_STREQ(".549306", gc(xdtoaf(atanhf(.5)))); - EXPECT_STREQ("-.549306", gc(xdtoaf(atanhf(-.5)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(atanhf(+1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoaf(atanhf(-1)))); + EXPECT_STREQ("0", _gc(xdtoaf(atanhf(0)))); + EXPECT_STREQ("-0", _gc(xdtoaf(atanhf(-0.)))); + EXPECT_STREQ(".549306", _gc(xdtoaf(atanhf(.5)))); + EXPECT_STREQ("-.549306", _gc(xdtoaf(atanhf(-.5)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(atanhf(+1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoaf(atanhf(-1)))); EXPECT_TRUE(isnan(atanhf(+1.1))); EXPECT_TRUE(isnan(atanhf(-1.1))); } diff --git a/test/libc/tinymath/atanl_test.c b/test/libc/tinymath/atanl_test.c index 618a08704..8a7542d3f 100644 --- a/test/libc/tinymath/atanl_test.c +++ b/test/libc/tinymath/atanl_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/cbrt_test.c b/test/libc/tinymath/cbrt_test.c index b2a505239..25660cba2 100644 --- a/test/libc/tinymath/cbrt_test.c +++ b/test/libc/tinymath/cbrt_test.c @@ -17,25 +17,25 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(cbrt, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", cbrt(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", cbrt(-0.)))); - EXPECT_STREQ("0.7937005259841", gc(xasprintf("%.15g", cbrt(.5)))); - EXPECT_STREQ("-0.7937005259841", gc(xasprintf("%.15g", cbrt(-.5)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", cbrt(1.)))); - EXPECT_STREQ("-1", gc(xasprintf("%.15g", cbrt(-1.)))); - EXPECT_STREQ("1.14471424255333", gc(xasprintf("%.15g", cbrt(1.5)))); - EXPECT_STREQ("-1.14471424255333", gc(xasprintf("%.15g", cbrt(-1.5)))); - EXPECT_STREQ("nan", gc(xasprintf("%.15g", cbrt(NAN)))); - EXPECT_STREQ("-nan", gc(xasprintf("%.15g", cbrt(-NAN)))); - EXPECT_STREQ("inf", gc(xasprintf("%.15g", cbrt(INFINITY)))); - EXPECT_STREQ("-inf", gc(xasprintf("%.15g", cbrt(-INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", cbrt(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", cbrt(-0.)))); + EXPECT_STREQ("0.7937005259841", _gc(xasprintf("%.15g", cbrt(.5)))); + EXPECT_STREQ("-0.7937005259841", _gc(xasprintf("%.15g", cbrt(-.5)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", cbrt(1.)))); + EXPECT_STREQ("-1", _gc(xasprintf("%.15g", cbrt(-1.)))); + EXPECT_STREQ("1.14471424255333", _gc(xasprintf("%.15g", cbrt(1.5)))); + EXPECT_STREQ("-1.14471424255333", _gc(xasprintf("%.15g", cbrt(-1.5)))); + EXPECT_STREQ("nan", _gc(xasprintf("%.15g", cbrt(NAN)))); + EXPECT_STREQ("-nan", _gc(xasprintf("%.15g", cbrt(-NAN)))); + EXPECT_STREQ("inf", _gc(xasprintf("%.15g", cbrt(INFINITY)))); + EXPECT_STREQ("-inf", _gc(xasprintf("%.15g", cbrt(-INFINITY)))); EXPECT_STREQ("2.81264428523626e-103", - gc(xasprintf("%.15g", cbrt(__DBL_MIN__)))); + _gc(xasprintf("%.15g", cbrt(__DBL_MIN__)))); EXPECT_STREQ("5.64380309412236e+102", - gc(xasprintf("%.15g", cbrt(__DBL_MAX__)))); + _gc(xasprintf("%.15g", cbrt(__DBL_MAX__)))); } diff --git a/test/libc/tinymath/ceil_test.c b/test/libc/tinymath/ceil_test.c index f96cb3ad4..5b0f0ee5e 100644 --- a/test/libc/tinymath/ceil_test.c +++ b/test/libc/tinymath/ceil_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/copysign_test.c b/test/libc/tinymath/copysign_test.c index 13abf6b4a..58399bcba 100644 --- a/test/libc/tinymath/copysign_test.c +++ b/test/libc/tinymath/copysign_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/cos_test.c b/test/libc/tinymath/cos_test.c index 2fc1f13f9..80d154e6d 100644 --- a/test/libc/tinymath/cos_test.c +++ b/test/libc/tinymath/cos_test.c @@ -17,32 +17,32 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(cos, test) { - EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(0.)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-0.)))); - EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cos(.1)))); - EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cos(-.1)))); - EXPECT_STREQ("0.877582561890373", gc(xasprintf("%.15g", cos(.5)))); - EXPECT_STREQ("0.877582561890373", gc(xasprintf("%.15g", cos(-.5)))); - EXPECT_STREQ("0.54030230586814", gc(xasprintf("%.15g", cos(1.)))); - EXPECT_STREQ("0.54030230586814", gc(xasprintf("%.15g", cos(-1.)))); - EXPECT_STREQ("0.0707372016677029", gc(xasprintf("%.15g", cos(1.5)))); - EXPECT_STREQ("0.0707372016677029", gc(xasprintf("%.15g", cos(-1.5)))); - EXPECT_STREQ("-0.416146836547142", gc(xasprintf("%.15g", cos(2.)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", cos(0.)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", cos(-0.)))); + EXPECT_STREQ("0.995004165278026", _gc(xasprintf("%.15g", cos(.1)))); + EXPECT_STREQ("0.995004165278026", _gc(xasprintf("%.15g", cos(-.1)))); + EXPECT_STREQ("0.877582561890373", _gc(xasprintf("%.15g", cos(.5)))); + EXPECT_STREQ("0.877582561890373", _gc(xasprintf("%.15g", cos(-.5)))); + EXPECT_STREQ("0.54030230586814", _gc(xasprintf("%.15g", cos(1.)))); + EXPECT_STREQ("0.54030230586814", _gc(xasprintf("%.15g", cos(-1.)))); + EXPECT_STREQ("0.0707372016677029", _gc(xasprintf("%.15g", cos(1.5)))); + EXPECT_STREQ("0.0707372016677029", _gc(xasprintf("%.15g", cos(-1.5)))); + EXPECT_STREQ("-0.416146836547142", _gc(xasprintf("%.15g", cos(2.)))); EXPECT_TRUE(isnan(cos(NAN))); EXPECT_TRUE(isnan(cos(-NAN))); EXPECT_TRUE(isnan(cos(INFINITY))); EXPECT_TRUE(isnan(cos(-INFINITY))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(__DBL_MIN__)))); - EXPECT_STREQ("-0.99998768942656", gc(xasprintf("%.15g", cos(__DBL_MAX__)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", cos(__DBL_MIN__)))); + EXPECT_STREQ("-0.99998768942656", _gc(xasprintf("%.15g", cos(__DBL_MAX__)))); EXPECT_STREQ("0.54030230586814", - gc(xasprintf("%.15g", cos(-1.0000000000000002)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-2.1073424255447e-08)))); + _gc(xasprintf("%.15g", cos(-1.0000000000000002)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", cos(-2.1073424255447e-08)))); } BENCH(cos, bench) { diff --git a/test/libc/tinymath/cosh_test.c b/test/libc/tinymath/cosh_test.c index c4f56dedc..8bb3c1aa7 100644 --- a/test/libc/tinymath/cosh_test.c +++ b/test/libc/tinymath/cosh_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/csqrt_test.c b/test/libc/tinymath/csqrt_test.c index d585a1b08..b92e3270f 100644 --- a/test/libc/tinymath/csqrt_test.c +++ b/test/libc/tinymath/csqrt_test.c @@ -17,12 +17,11 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/complex.h" -#include "libc/fmt/fmt.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(csqrt, test) { complex double x = csqrt(-1); - EXPECT_STREQ("0 1", gc(xasprintf("%g %g", creal(x), cimag(x)))); + EXPECT_STREQ("0 1", _gc(xasprintf("%g %g", creal(x), cimag(x)))); } diff --git a/test/libc/tinymath/erf_test.c b/test/libc/tinymath/erf_test.c index c274f4390..87cc79e1f 100644 --- a/test/libc/tinymath/erf_test.c +++ b/test/libc/tinymath/erf_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/exp10_test.c b/test/libc/tinymath/exp10_test.c index 47933e504..24493edf9 100644 --- a/test/libc/tinymath/exp10_test.c +++ b/test/libc/tinymath/exp10_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/exp2_test.c b/test/libc/tinymath/exp2_test.c index fb2bf6a28..4da06e410 100644 --- a/test/libc/tinymath/exp2_test.c +++ b/test/libc/tinymath/exp2_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/exp2l_test.c b/test/libc/tinymath/exp2l_test.c index e173f0f9f..2e20d362e 100644 --- a/test/libc/tinymath/exp2l_test.c +++ b/test/libc/tinymath/exp2l_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/exp_test.c b/test/libc/tinymath/exp_test.c index ed9265f57..77008978d 100644 --- a/test/libc/tinymath/exp_test.c +++ b/test/libc/tinymath/exp_test.c @@ -17,50 +17,51 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define expl(x) expl(VEIL("t", (long double)(x))) #define exp(x) exp(VEIL("x", (double)(x))) #define expf(x) expf(VEIL("x", (float)(x))) TEST(expl, test) { - EXPECT_STREQ("1", gc(xdtoal(expl(0)))); - EXPECT_STREQ("1", gc(xdtoal(expl(-0.)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(expl(INFINITY)))); - EXPECT_STREQ("0", gc(xdtoal(expl(-INFINITY)))); - EXPECT_STREQ("NAN", gc(xdtoal(expl(NAN)))); - EXPECT_STREQ("0", gc(xdtoal(expl(-132098844872390)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(expl(132098844872390)))); + EXPECT_STREQ("1", _gc(xdtoal(expl(0)))); + EXPECT_STREQ("1", _gc(xdtoal(expl(-0.)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(expl(INFINITY)))); + EXPECT_STREQ("0", _gc(xdtoal(expl(-INFINITY)))); + EXPECT_STREQ("NAN", _gc(xdtoal(expl(NAN)))); + EXPECT_STREQ("0", _gc(xdtoal(expl(-132098844872390)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(expl(132098844872390)))); } TEST(exp, test) { - EXPECT_STREQ("1", gc(xdtoa(exp(0)))); - EXPECT_STREQ("1", gc(xdtoa(exp(-0.)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(exp(INFINITY)))); - EXPECT_STREQ("0", gc(xdtoa(exp(-INFINITY)))); - EXPECT_STREQ("NAN", gc(xdtoa(exp(NAN)))); - EXPECT_STREQ("0", gc(xdtoa(exp(-132098844872390)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(exp(132098844872390)))); + EXPECT_STREQ("1", _gc(xdtoa(exp(0)))); + EXPECT_STREQ("1", _gc(xdtoa(exp(-0.)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(exp(INFINITY)))); + EXPECT_STREQ("0", _gc(xdtoa(exp(-INFINITY)))); + EXPECT_STREQ("NAN", _gc(xdtoa(exp(NAN)))); + EXPECT_STREQ("0", _gc(xdtoa(exp(-132098844872390)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(exp(132098844872390)))); } TEST(expf, test) { - EXPECT_STREQ("1", gc(xdtoaf(expf(0)))); - EXPECT_STREQ("1", gc(xdtoaf(expf(-0.)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(expf(INFINITY)))); - EXPECT_STREQ("0", gc(xdtoaf(expf(-INFINITY)))); - EXPECT_STREQ("NAN", gc(xdtoaf(expf(NAN)))); - EXPECT_STREQ("0", gc(xdtoaf(expf(-132098844872390)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(expf(132098844872390)))); + EXPECT_STREQ("1", _gc(xdtoaf(expf(0)))); + EXPECT_STREQ("1", _gc(xdtoaf(expf(-0.)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(expf(INFINITY)))); + EXPECT_STREQ("0", _gc(xdtoaf(expf(-INFINITY)))); + EXPECT_STREQ("NAN", _gc(xdtoaf(expf(NAN)))); + EXPECT_STREQ("0", _gc(xdtoaf(expf(-132098844872390)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(expf(132098844872390)))); } TEST(exp, fun) { - ASSERT_STREQ("7.389056", gc(xasprintf("%f", exp(2.0)))); - ASSERT_STREQ("6.389056", gc(xasprintf("%f", expm1(2.0)))); - ASSERT_STREQ("6.389056", gc(xasprintf("%f", exp(2.0) - 1.0))); + ASSERT_STREQ("7.389056", _gc(xasprintf("%f", exp(2.0)))); + ASSERT_STREQ("6.389056", _gc(xasprintf("%f", expm1(2.0)))); + ASSERT_STREQ("6.389056", _gc(xasprintf("%f", exp(2.0) - 1.0))); } BENCH(expl, bench) { diff --git a/test/libc/tinymath/expm1_test.c b/test/libc/tinymath/expm1_test.c index 2d218a26f..5b37389dc 100644 --- a/test/libc/tinymath/expm1_test.c +++ b/test/libc/tinymath/expm1_test.c @@ -17,58 +17,59 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define expm1l(x) expm1l(VEIL("t", (long double)(x))) #define expm1(x) expm1(VEIL("x", (double)(x))) #define expm1f(x) expm1f(VEIL("x", (float)(x))) TEST(expm1, test) { - EXPECT_STREQ("0", gc(xdtoa(expm1(0)))); - EXPECT_STREQ("-0", gc(xdtoa(expm1(-0.)))); - EXPECT_STREQ("NAN", gc(xdtoa(expm1(NAN)))); - EXPECT_STREQ("-1", gc(xdtoa(expm1(-INFINITY)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(INFINITY)))); - /* EXPECT_STREQ("-INFINITY", gc(xdtoa(expm1(-132098844872390)))); */ - /* EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(132098844872390)))); */ - EXPECT_STREQ("0", gc(xasprintf("%.15g", expm1(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", expm1(-0.)))); - EXPECT_STREQ("0.648721270700128", gc(xasprintf("%.15g", expm1(.5)))); - EXPECT_STREQ("-0.393469340287367", gc(xasprintf("%.15g", expm1(-.5)))); - EXPECT_STREQ("1.71828182845905", gc(xasprintf("%.15g", expm1(1.)))); - EXPECT_STREQ("-0.632120558828558", gc(xasprintf("%.15g", expm1(-1.)))); - EXPECT_STREQ("3.48168907033806", gc(xasprintf("%.15g", expm1(1.5)))); - EXPECT_STREQ("-0.77686983985157", gc(xasprintf("%.15g", expm1(-1.5)))); - EXPECT_STREQ("6.38905609893065", gc(xasprintf("%.15g", expm1(2.)))); + EXPECT_STREQ("0", _gc(xdtoa(expm1(0)))); + EXPECT_STREQ("-0", _gc(xdtoa(expm1(-0.)))); + EXPECT_STREQ("NAN", _gc(xdtoa(expm1(NAN)))); + EXPECT_STREQ("-1", _gc(xdtoa(expm1(-INFINITY)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(expm1(INFINITY)))); + /* EXPECT_STREQ("-INFINITY", _gc(xdtoa(expm1(-132098844872390)))); */ + /* EXPECT_STREQ("INFINITY", _gc(xdtoa(expm1(132098844872390)))); */ + EXPECT_STREQ("0", _gc(xasprintf("%.15g", expm1(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", expm1(-0.)))); + EXPECT_STREQ("0.648721270700128", _gc(xasprintf("%.15g", expm1(.5)))); + EXPECT_STREQ("-0.393469340287367", _gc(xasprintf("%.15g", expm1(-.5)))); + EXPECT_STREQ("1.71828182845905", _gc(xasprintf("%.15g", expm1(1.)))); + EXPECT_STREQ("-0.632120558828558", _gc(xasprintf("%.15g", expm1(-1.)))); + EXPECT_STREQ("3.48168907033806", _gc(xasprintf("%.15g", expm1(1.5)))); + EXPECT_STREQ("-0.77686983985157", _gc(xasprintf("%.15g", expm1(-1.5)))); + EXPECT_STREQ("6.38905609893065", _gc(xasprintf("%.15g", expm1(2.)))); EXPECT_TRUE(isnan(expm1(NAN))); EXPECT_TRUE(isnan(expm1(-NAN))); - EXPECT_STREQ("inf", gc(xasprintf("%.15g", expm1(INFINITY)))); - EXPECT_STREQ("-1", gc(xasprintf("%.15g", expm1(-INFINITY)))); + EXPECT_STREQ("inf", _gc(xasprintf("%.15g", expm1(INFINITY)))); + EXPECT_STREQ("-1", _gc(xasprintf("%.15g", expm1(-INFINITY)))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", expm1(__DBL_MIN__)))); - EXPECT_STREQ("inf", gc(xasprintf("%.15g", expm1(__DBL_MAX__)))); + _gc(xasprintf("%.15g", expm1(__DBL_MIN__)))); + EXPECT_STREQ("inf", _gc(xasprintf("%.15g", expm1(__DBL_MAX__)))); } TEST(expm1l, test) { - EXPECT_STREQ("1.718281828459045", gc(xdtoal(expm1l(1)))); - EXPECT_STREQ("1.718281828459045", gc(xdtoal(expl(1) - 1))); - EXPECT_STREQ("0", gc(xdtoal(expm1l(0)))); - EXPECT_STREQ("-0", gc(xdtoal(expm1l(-0.)))); - EXPECT_STREQ("NAN", gc(xdtoal(expm1l(NAN)))); - EXPECT_STREQ("-1", gc(xdtoal(expm1l(-INFINITY)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(expm1l(INFINITY)))); - /* EXPECT_STREQ("-INFINITY", gc(xdtoal(expm1l(-132098844872390)))); */ - /* EXPECT_STREQ("INFINITY", gc(xdtoal(expm1l(132098844872390)))); */ + EXPECT_STREQ("1.718281828459045", _gc(xdtoal(expm1l(1)))); + EXPECT_STREQ("1.718281828459045", _gc(xdtoal(expl(1) - 1))); + EXPECT_STREQ("0", _gc(xdtoal(expm1l(0)))); + EXPECT_STREQ("-0", _gc(xdtoal(expm1l(-0.)))); + EXPECT_STREQ("NAN", _gc(xdtoal(expm1l(NAN)))); + EXPECT_STREQ("-1", _gc(xdtoal(expm1l(-INFINITY)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(expm1l(INFINITY)))); + /* EXPECT_STREQ("-INFINITY", _gc(xdtoal(expm1l(-132098844872390)))); */ + /* EXPECT_STREQ("INFINITY", _gc(xdtoal(expm1l(132098844872390)))); */ } TEST(expm1f, test) { - EXPECT_STREQ("0", gc(xdtoaf(expm1f(0)))); - EXPECT_STREQ("-0", gc(xdtoaf(expm1f(-0.)))); - EXPECT_STREQ("NAN", gc(xdtoaf(expm1f(NAN)))); - EXPECT_STREQ("-1", gc(xdtoaf(expm1f(-INFINITY)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(expm1f(INFINITY)))); - /* EXPECT_STREQ("-INFINITY", gc(xdtoaf(expm1f(-132098844872390)))); */ - /* EXPECT_STREQ("INFINITY", gc(xdtoaf(expm1f(132098844872390)))); */ + EXPECT_STREQ("0", _gc(xdtoaf(expm1f(0)))); + EXPECT_STREQ("-0", _gc(xdtoaf(expm1f(-0.)))); + EXPECT_STREQ("NAN", _gc(xdtoaf(expm1f(NAN)))); + EXPECT_STREQ("-1", _gc(xdtoaf(expm1f(-INFINITY)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(expm1f(INFINITY)))); + /* EXPECT_STREQ("-INFINITY", _gc(xdtoaf(expm1f(-132098844872390)))); */ + /* EXPECT_STREQ("INFINITY", _gc(xdtoaf(expm1f(132098844872390)))); */ } diff --git a/test/libc/tinymath/fabs_test.c b/test/libc/tinymath/fabs_test.c index 6e39603c6..61b34888c 100644 --- a/test/libc/tinymath/fabs_test.c +++ b/test/libc/tinymath/fabs_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/floor_test.c b/test/libc/tinymath/floor_test.c index 4c2ce64e2..e709a60ca 100644 --- a/test/libc/tinymath/floor_test.c +++ b/test/libc/tinymath/floor_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/fmod_test.c b/test/libc/tinymath/fmod_test.c index a9d9ddff0..ce6ea86f9 100644 --- a/test/libc/tinymath/fmod_test.c +++ b/test/libc/tinymath/fmod_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/rand.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/tinymath/fsum_test.c b/test/libc/tinymath/fsum_test.c index 04227e80a..e4772fc70 100644 --- a/test/libc/tinymath/fsum_test.c +++ b/test/libc/tinymath/fsum_test.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define N 100000 @@ -41,11 +41,11 @@ void SetUp(void) { } TEST(fsum, test) { - EXPECT_STREQ("500000000.6", gc(xasprintf("%.15g", fsum(D, N) / N))); + EXPECT_STREQ("500000000.6", _gc(xasprintf("%.15g", fsum(D, N) / N))); } TEST(fsumf, test) { - EXPECT_STREQ("500.6", gc(xasprintf("%.7g", fsumf(F, N) / N))); + EXPECT_STREQ("500.6", _gc(xasprintf("%.7g", fsumf(F, N) / N))); } BENCH(fsum, bench) { diff --git a/test/libc/tinymath/gamma_test.c b/test/libc/tinymath/gamma_test.c index 534028c11..7630e80a6 100644 --- a/test/libc/tinymath/gamma_test.c +++ b/test/libc/tinymath/gamma_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/hypot_test.c b/test/libc/tinymath/hypot_test.c index b9090fbde..9d9258553 100644 --- a/test/libc/tinymath/hypot_test.c +++ b/test/libc/tinymath/hypot_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/ldexp_test.c b/test/libc/tinymath/ldexp_test.c index e8c482702..65f6caf69 100644 --- a/test/libc/tinymath/ldexp_test.c +++ b/test/libc/tinymath/ldexp_test.c @@ -17,12 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#include "libc/mem/gc.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" int rando; @@ -32,83 +33,83 @@ void SetUp(void) { TEST(ldexpl, test) { EXPECT_EQ(rando, ldexpl(rando, 0)); - EXPECT_STREQ("NAN", gc(xdtoal(ldexpl(NAN, 0)))); - EXPECT_STREQ("-NAN", gc(xdtoal(ldexpl(-NAN, 0)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(ldexpl(INFINITY, 0)))); - EXPECT_STREQ("-INFINITY", gc(xdtoal(ldexpl(-INFINITY, 0)))); - EXPECT_STREQ("NAN", gc(xdtoal(ldexpl(NAN, 1)))); - EXPECT_STREQ("-NAN", gc(xdtoal(ldexpl(-NAN, 1)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(ldexpl(INFINITY, 1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoal(ldexpl(-INFINITY, 1)))); - EXPECT_STREQ("16384", gc(xdtoal(log2l(LDBL_MAX)))); - EXPECT_STREQ(".00390625", gc(xdtoal(ldexpl(1, -8)))); - EXPECT_STREQ("0", gc(xdtoal(ldexpl(0, -8)))); - EXPECT_STREQ("0", gc(xdtoal(ldexpl(0, 8)))); - EXPECT_STREQ("256", gc(xdtoal(ldexpl(1, 8)))); - EXPECT_STREQ("512", gc(xdtoal(ldexpl(2, 8)))); - EXPECT_STREQ("768", gc(xdtoal(ldexpl(3, 8)))); - EXPECT_STREQ("6.997616471358197e+3461", gc(xdtoal(ldexpl(1, 11500)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(ldexpl(1, 999999)))); - EXPECT_STREQ("0", gc(xdtoal(ldexpl(1, -999999)))); + EXPECT_STREQ("NAN", _gc(xdtoal(ldexpl(NAN, 0)))); + EXPECT_STREQ("-NAN", _gc(xdtoal(ldexpl(-NAN, 0)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(ldexpl(INFINITY, 0)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoal(ldexpl(-INFINITY, 0)))); + EXPECT_STREQ("NAN", _gc(xdtoal(ldexpl(NAN, 1)))); + EXPECT_STREQ("-NAN", _gc(xdtoal(ldexpl(-NAN, 1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(ldexpl(INFINITY, 1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoal(ldexpl(-INFINITY, 1)))); + EXPECT_STREQ("16384", _gc(xdtoal(log2l(LDBL_MAX)))); + EXPECT_STREQ(".00390625", _gc(xdtoal(ldexpl(1, -8)))); + EXPECT_STREQ("0", _gc(xdtoal(ldexpl(0, -8)))); + EXPECT_STREQ("0", _gc(xdtoal(ldexpl(0, 8)))); + EXPECT_STREQ("256", _gc(xdtoal(ldexpl(1, 8)))); + EXPECT_STREQ("512", _gc(xdtoal(ldexpl(2, 8)))); + EXPECT_STREQ("768", _gc(xdtoal(ldexpl(3, 8)))); + EXPECT_STREQ("6.997616471358197e+3461", _gc(xdtoal(ldexpl(1, 11500)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(ldexpl(1, 999999)))); + EXPECT_STREQ("0", _gc(xdtoal(ldexpl(1, -999999)))); } TEST(ldexp, test) { EXPECT_EQ(rando, ldexp(rando, 0)); - EXPECT_STREQ("NAN", gc(xdtoa(ldexp(NAN, 0)))); - EXPECT_STREQ("-NAN", gc(xdtoa(ldexp(-NAN, 0)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(ldexp(INFINITY, 0)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(ldexp(-INFINITY, 0)))); - EXPECT_STREQ("NAN", gc(xdtoa(ldexp(NAN, 1)))); - EXPECT_STREQ("-NAN", gc(xdtoa(ldexp(-NAN, 1)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(ldexp(INFINITY, 1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(ldexp(-INFINITY, 1)))); - EXPECT_STREQ("16384", gc(xdtoa(log2l(LDBL_MAX)))); - EXPECT_STREQ(".00390625", gc(xdtoa(ldexp(1, -8)))); - EXPECT_STREQ("0", gc(xdtoa(ldexp(0, -8)))); - EXPECT_STREQ("0", gc(xdtoa(ldexp(0, 8)))); - EXPECT_STREQ("256", gc(xdtoa(ldexp(1, 8)))); - EXPECT_STREQ("512", gc(xdtoa(ldexp(2, 8)))); - EXPECT_STREQ("768", gc(xdtoa(ldexp(3, 8)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(ldexp(1, 999999)))); - EXPECT_STREQ("0", gc(xdtoa(ldexp(1, -999999)))); + EXPECT_STREQ("NAN", _gc(xdtoa(ldexp(NAN, 0)))); + EXPECT_STREQ("-NAN", _gc(xdtoa(ldexp(-NAN, 0)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(ldexp(INFINITY, 0)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoa(ldexp(-INFINITY, 0)))); + EXPECT_STREQ("NAN", _gc(xdtoa(ldexp(NAN, 1)))); + EXPECT_STREQ("-NAN", _gc(xdtoa(ldexp(-NAN, 1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(ldexp(INFINITY, 1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoa(ldexp(-INFINITY, 1)))); + EXPECT_STREQ("16384", _gc(xdtoa(log2l(LDBL_MAX)))); + EXPECT_STREQ(".00390625", _gc(xdtoa(ldexp(1, -8)))); + EXPECT_STREQ("0", _gc(xdtoa(ldexp(0, -8)))); + EXPECT_STREQ("0", _gc(xdtoa(ldexp(0, 8)))); + EXPECT_STREQ("256", _gc(xdtoa(ldexp(1, 8)))); + EXPECT_STREQ("512", _gc(xdtoa(ldexp(2, 8)))); + EXPECT_STREQ("768", _gc(xdtoa(ldexp(3, 8)))); + EXPECT_STREQ("INFINITY", _gc(xdtoa(ldexp(1, 999999)))); + EXPECT_STREQ("0", _gc(xdtoa(ldexp(1, -999999)))); } TEST(ldexpf, test) { EXPECT_EQ(rando, ldexpf(rando, 0)); - EXPECT_STREQ("NAN", gc(xdtoaf(ldexpf(NAN, 0)))); - EXPECT_STREQ("-NAN", gc(xdtoaf(ldexpf(-NAN, 0)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(ldexpf(INFINITY, 0)))); - EXPECT_STREQ("-INFINITY", gc(xdtoaf(ldexpf(-INFINITY, 0)))); - EXPECT_STREQ("NAN", gc(xdtoaf(ldexpf(NAN, 1)))); - EXPECT_STREQ("-NAN", gc(xdtoaf(ldexpf(-NAN, 1)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(ldexpf(INFINITY, 1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoaf(ldexpf(-INFINITY, 1)))); - EXPECT_STREQ("16384", gc(xdtoaf(log2l(LDBL_MAX)))); - EXPECT_STREQ(".00390625", gc(xdtoaf(ldexpf(1, -8)))); - EXPECT_STREQ("0", gc(xdtoaf(ldexpf(0, -8)))); - EXPECT_STREQ("0", gc(xdtoaf(ldexpf(0, 8)))); - EXPECT_STREQ("256", gc(xdtoaf(ldexpf(1, 8)))); - EXPECT_STREQ("512", gc(xdtoaf(ldexpf(2, 8)))); - EXPECT_STREQ("768", gc(xdtoaf(ldexpf(3, 8)))); - EXPECT_STREQ("INFINITY", gc(xdtoaf(ldexpf(1, 999999)))); - EXPECT_STREQ("0", gc(xdtoaf(ldexpf(1, -999999)))); + EXPECT_STREQ("NAN", _gc(xdtoaf(ldexpf(NAN, 0)))); + EXPECT_STREQ("-NAN", _gc(xdtoaf(ldexpf(-NAN, 0)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(ldexpf(INFINITY, 0)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoaf(ldexpf(-INFINITY, 0)))); + EXPECT_STREQ("NAN", _gc(xdtoaf(ldexpf(NAN, 1)))); + EXPECT_STREQ("-NAN", _gc(xdtoaf(ldexpf(-NAN, 1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(ldexpf(INFINITY, 1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoaf(ldexpf(-INFINITY, 1)))); + EXPECT_STREQ("16384", _gc(xdtoaf(log2l(LDBL_MAX)))); + EXPECT_STREQ(".00390625", _gc(xdtoaf(ldexpf(1, -8)))); + EXPECT_STREQ("0", _gc(xdtoaf(ldexpf(0, -8)))); + EXPECT_STREQ("0", _gc(xdtoaf(ldexpf(0, 8)))); + EXPECT_STREQ("256", _gc(xdtoaf(ldexpf(1, 8)))); + EXPECT_STREQ("512", _gc(xdtoaf(ldexpf(2, 8)))); + EXPECT_STREQ("768", _gc(xdtoaf(ldexpf(3, 8)))); + EXPECT_STREQ("INFINITY", _gc(xdtoaf(ldexpf(1, 999999)))); + EXPECT_STREQ("0", _gc(xdtoaf(ldexpf(1, -999999)))); } TEST(ldexp, stuff) { volatile int twopow = 5; volatile double pi = 3.14; - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", ldexp(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", ldexpf(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", ldexpl(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalb(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbf(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalbl(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbn(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbnf(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalbnl(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbln(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalblnf(pi, twopow)))); - ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalblnl(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", ldexp(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", ldexpf(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", ldexpl(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalb(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbf(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", scalbl(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbn(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbnf(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", scalbnl(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbln(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalblnf(pi, twopow)))); + ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", scalblnl(pi, twopow)))); } BENCH(ldexpl, bench) { diff --git a/test/libc/tinymath/log10_test.c b/test/libc/tinymath/log10_test.c index ec2535159..bbef1373c 100644 --- a/test/libc/tinymath/log10_test.c +++ b/test/libc/tinymath/log10_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/log1p_test.c b/test/libc/tinymath/log1p_test.c index 0d1cbb429..ed0842b75 100644 --- a/test/libc/tinymath/log1p_test.c +++ b/test/libc/tinymath/log1p_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/log2_test.c b/test/libc/tinymath/log2_test.c index 48dcc707f..f95a0a2b8 100644 --- a/test/libc/tinymath/log2_test.c +++ b/test/libc/tinymath/log2_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/log_test.c b/test/libc/tinymath/log_test.c index 3c2a15e3d..fb3522a22 100644 --- a/test/libc/tinymath/log_test.c +++ b/test/libc/tinymath/log_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/measureentropy_test.c b/test/libc/tinymath/measureentropy_test.c index 1f8ca09bd..2882d3b6b 100644 --- a/test/libc/tinymath/measureentropy_test.c +++ b/test/libc/tinymath/measureentropy_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/tinymath/powl_test.c b/test/libc/tinymath/powl_test.c index c00bc8aa1..ba48c809e 100644 --- a/test/libc/tinymath/powl_test.c +++ b/test/libc/tinymath/powl_test.c @@ -23,15 +23,16 @@ #include "libc/fmt/fmt.h" #include "libc/macros.internal.h" #include "libc/math.h" -#include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/pc.internal.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" int rando; char buf[128]; @@ -55,57 +56,57 @@ static char *fmtf(float x) { } TEST(powl, test) { - EXPECT_STREQ("27", gc(xdtoal(powl(3, 3)))); - EXPECT_STREQ("-27", gc(xdtoal(powl(-3, 3)))); - EXPECT_STREQ("1e+4932", gc(xdtoal(powl(10, 4932)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(10, 4933)))); - EXPECT_STREQ("0", gc(xdtoal(powl(10, -5000)))); - EXPECT_STREQ("1.063382396627933e+37", gc(xdtoal(powl(2, 123)))); - EXPECT_STARTSWITH(".4248496805467504", gc(xdtoal(powl(.7, 2.4)))); - EXPECT_STREQ("1", gc(xdtoal(powl(1, NAN)))); - EXPECT_STREQ("1", gc(xdtoal(powl(1, rando)))); - EXPECT_STREQ("1", gc(xdtoal(powl(NAN, 0)))); - EXPECT_STREQ("1", gc(xdtoal(powl(rando, 0)))); - EXPECT_STREQ("0", gc(xdtoal(powl(0, 1)))); - EXPECT_STREQ("0", gc(xdtoal(powl(0, 2)))); - EXPECT_STREQ("0", gc(xdtoal(powl(0, 2.1)))); - EXPECT_STREQ("1", gc(xdtoal(powl(-1, INFINITY)))); - EXPECT_STREQ("1", gc(xdtoal(powl(-1, -INFINITY)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(1. / MAX(2, rando), -INFINITY)))); - EXPECT_STREQ("0", gc(xdtoal(powl(1.1, -INFINITY)))); - EXPECT_STREQ("0", gc(xdtoal(powl(MAX(2, rando), -INFINITY)))); - EXPECT_STREQ("0", gc(xdtoal(powl(1. / MAX(2, rando), INFINITY)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(MAX(2, rando), INFINITY)))); - EXPECT_STREQ("-0", gc(xdtoal(powl(-INFINITY, -1)))); - EXPECT_STREQ("0", gc(xdtoal(powl(-INFINITY, -1.1)))); - EXPECT_STREQ("0", gc(xdtoal(powl(-INFINITY, -2)))); - EXPECT_STREQ("0", gc(xdtoal(powl(-INFINITY, -2.1)))); - EXPECT_STREQ("-0", gc(xdtoal(powl(-INFINITY, -3)))); - EXPECT_STREQ("0", gc(xdtoal(powl(-INFINITY, -3.1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoal(powl(-INFINITY, 1)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(-INFINITY, 1.1)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(-INFINITY, 2)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(-INFINITY, 2.1)))); - EXPECT_STREQ("-INFINITY", gc(xdtoal(powl(-INFINITY, 3)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(-INFINITY, 3.1)))); - EXPECT_STREQ("0", gc(xdtoal(powl(INFINITY, -1)))); - EXPECT_STREQ("0", gc(xdtoal(powl(INFINITY, -.1)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(INFINITY, 1)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(INFINITY, .1)))); - EXPECT_STREQ("1", gc(xdtoal(powl(INFINITY, 0)))); - EXPECT_STREQ("1", gc(xdtoal(powl(INFINITY, -0.)))); - EXPECT_STREQ("1", gc(xdtoal(powl(0, 0)))); - EXPECT_STREQ("1", gc(xdtoal(powl(0, -0.)))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(0, -(MAX(rando, 1) | 1))))); - EXPECT_STREQ("-INFINITY", gc(xdtoal(powl(-0., -(MAX(rando, 1) | 1))))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(0, -(rando & -2))))); - EXPECT_STREQ("INFINITY", gc(xdtoal(powl(-0., -(rando & -2))))); + EXPECT_STREQ("27", _gc(xdtoal(powl(3, 3)))); + EXPECT_STREQ("-27", _gc(xdtoal(powl(-3, 3)))); + EXPECT_STREQ("1e+4932", _gc(xdtoal(powl(10, 4932)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(10, 4933)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(10, -5000)))); + EXPECT_STREQ("1.063382396627933e+37", _gc(xdtoal(powl(2, 123)))); + EXPECT_STARTSWITH(".4248496805467504", _gc(xdtoal(powl(.7, 2.4)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(1, NAN)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(1, rando)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(NAN, 0)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(rando, 0)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(0, 1)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(0, 2)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(0, 2.1)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(-1, INFINITY)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(-1, -INFINITY)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(1. / MAX(2, rando), -INFINITY)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(1.1, -INFINITY)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(MAX(2, rando), -INFINITY)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(1. / MAX(2, rando), INFINITY)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(MAX(2, rando), INFINITY)))); + EXPECT_STREQ("-0", _gc(xdtoal(powl(-INFINITY, -1)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(-INFINITY, -1.1)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(-INFINITY, -2)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(-INFINITY, -2.1)))); + EXPECT_STREQ("-0", _gc(xdtoal(powl(-INFINITY, -3)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(-INFINITY, -3.1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoal(powl(-INFINITY, 1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(-INFINITY, 1.1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(-INFINITY, 2)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(-INFINITY, 2.1)))); + EXPECT_STREQ("-INFINITY", _gc(xdtoal(powl(-INFINITY, 3)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(-INFINITY, 3.1)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(INFINITY, -1)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(INFINITY, -.1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(INFINITY, 1)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(INFINITY, .1)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(INFINITY, 0)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(INFINITY, -0.)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(0, 0)))); + EXPECT_STREQ("1", _gc(xdtoal(powl(0, -0.)))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(0, -(MAX(rando, 1) | 1))))); + EXPECT_STREQ("-INFINITY", _gc(xdtoal(powl(-0., -(MAX(rando, 1) | 1))))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(0, -(rando & -2))))); + EXPECT_STREQ("INFINITY", _gc(xdtoal(powl(-0., -(rando & -2))))); EXPECT_TRUE(isnan(powl(-3, 1. / MAX(rando, 2)))); EXPECT_TRUE(isnan(powl(-3, -(1. / MAX(rando, 2))))); - EXPECT_STREQ("-.3333333333333333", gc(xdtoal(powl(-3, -1)))); - EXPECT_STREQ(".1111111111111111", gc(xdtoal(powl(-3, -2)))); - EXPECT_STREQ("-0", gc(xdtoal(powl(-0., MAX(1, rando) | 1)))); - EXPECT_STREQ("0", gc(xdtoal(powl(-0., MAX(1, rando) & ~1)))); + EXPECT_STREQ("-.3333333333333333", _gc(xdtoal(powl(-3, -1)))); + EXPECT_STREQ(".1111111111111111", _gc(xdtoal(powl(-3, -2)))); + EXPECT_STREQ("-0", _gc(xdtoal(powl(-0., MAX(1, rando) | 1)))); + EXPECT_STREQ("0", _gc(xdtoal(powl(-0., MAX(1, rando) & ~1)))); } TEST(pow, test) { @@ -156,8 +157,8 @@ TEST(pow, test) { EXPECT_STREQ("inf", fmtd(pow(-0., -(rando & -2)))); EXPECT_STREQ("-0.333333333333333", fmtd(pow(-3, -1))); EXPECT_STREQ("0.111111111111111", fmtd(pow(-3, -2))); - EXPECT_STREQ("-0", gc(xdtoa(pow(-0., MAX(1, rando) | 1)))); - EXPECT_STREQ("0", gc(xdtoa(pow(-0., MAX(1, rando) & ~1)))); + EXPECT_STREQ("-0", _gc(xdtoa(pow(-0., MAX(1, rando) | 1)))); + EXPECT_STREQ("0", _gc(xdtoa(pow(-0., MAX(1, rando) & ~1)))); } TEST(powf, test) { @@ -208,8 +209,8 @@ TEST(powf, test) { EXPECT_STREQ("inf", fmtf(powf(-0., -(rando & -2)))); EXPECT_STREQ("-0.333333", fmtf(powf(-3, -1))); EXPECT_STREQ("0.111111", fmtf(powf(-3, -2))); - EXPECT_STREQ("-0", gc(xdtoaf(powf(-0., MAX(1, rando) | 1)))); - EXPECT_STREQ("0", gc(xdtoaf(powf(-0., MAX(1, rando) & ~1)))); + EXPECT_STREQ("-0", _gc(xdtoaf(powf(-0., MAX(1, rando) | 1)))); + EXPECT_STREQ("0", _gc(xdtoaf(powf(-0., MAX(1, rando) & ~1)))); } TEST(powl, errors) { @@ -547,15 +548,15 @@ TEST(powl, errors) { errno = 0; EXPECT_STREQ("inf", fmtd(POW(__DBL_MAX__, __DBL_MAX__))); /* EXPECT_EQ(ERANGE, errno); */ - EXPECT_STREQ("1", gc(xasprintf("%.15g", POW(0., 0)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", POW(-0., 0)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", POW(-0., 1)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", POW(-0., 11)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", POW(-0., 111)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", POW(-0., 2)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", POW(-0., 22)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", POW(-0., 222)))); - EXPECT_STREQ("0", gc(xasprintf("%.15g", POW(-0., 2.5)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", POW(0., 0)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", POW(-0., 0)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", POW(-0., 1)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", POW(-0., 11)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", POW(-0., 111)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", POW(-0., 2)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", POW(-0., 22)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", POW(-0., 222)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", POW(-0., 2.5)))); } BENCH(powl, bench) { diff --git a/test/libc/tinymath/round_test.c b/test/libc/tinymath/round_test.c index 6684dd4a0..68a8513fa 100644 --- a/test/libc/tinymath/round_test.c +++ b/test/libc/tinymath/round_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/sin_test.c b/test/libc/tinymath/sin_test.c index 22a39c32e..b6519155b 100644 --- a/test/libc/tinymath/sin_test.c +++ b/test/libc/tinymath/sin_test.c @@ -17,59 +17,61 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define sinl(x) sinl(VEIL("t", (long double)(x))) #define sin(x) sin(VEIL("x", (double)(x))) #define sinf(x) sinf(VEIL("x", (float)(x))) TEST(sinl, test) { - EXPECT_STREQ("NAN", gc(xdtoal(sinl(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoal(sinl(+INFINITY)))); - EXPECT_STREQ("-NAN", gc(xdtoal(sinl(-INFINITY)))); - EXPECT_STREQ(".479425538604203", gc(xdtoal(sinl(.5)))); - EXPECT_STREQ("-.479425538604203", gc(xdtoal(sinl(-.5)))); - EXPECT_STREQ(".8414709794048734", gc(xdtoal(sinl(.99999999)))); - /* EXPECT_STREQ("-.998836772397", gc(xdtoal(sinl(555555555555)))); */ - /* EXPECT_STREQ("1", gc(xdtoal(sinl(5.319372648326541e+255L)))); */ + EXPECT_STREQ("NAN", _gc(xdtoal(sinl(NAN)))); + EXPECT_STREQ("-NAN", _gc(xdtoal(sinl(+INFINITY)))); + EXPECT_STREQ("-NAN", _gc(xdtoal(sinl(-INFINITY)))); + EXPECT_STREQ(".479425538604203", _gc(xdtoal(sinl(.5)))); + EXPECT_STREQ("-.479425538604203", _gc(xdtoal(sinl(-.5)))); + EXPECT_STREQ(".8414709794048734", _gc(xdtoal(sinl(.99999999)))); + /* EXPECT_STREQ("-.998836772397", _gc(xdtoal(sinl(555555555555)))); */ + /* EXPECT_STREQ("1", _gc(xdtoal(sinl(5.319372648326541e+255L)))); */ } TEST(sin, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", sin(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", sin(-0.)))); - EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", sin(.1)))); - EXPECT_STREQ("-0.0998334166468282", gc(xasprintf("%.15g", sin(-.1)))); - EXPECT_STREQ("0.479425538604203", gc(xasprintf("%.15g", sin(.5)))); - EXPECT_STREQ("-0.479425538604203", gc(xasprintf("%.15g", sin(-.5)))); - EXPECT_STREQ("0.841470984807897", gc(xasprintf("%.15g", sin(1.)))); - EXPECT_STREQ("-0.841470984807897", gc(xasprintf("%.15g", sin(-1.)))); - EXPECT_STREQ("0.997494986604054", gc(xasprintf("%.15g", sin(1.5)))); - EXPECT_STREQ("-0.997494986604054", gc(xasprintf("%.15g", sin(-1.5)))); - EXPECT_STREQ("0.909297426825682", gc(xasprintf("%.15g", sin(2.)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", sin(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", sin(-0.)))); + EXPECT_STREQ("0.0998334166468282", _gc(xasprintf("%.15g", sin(.1)))); + EXPECT_STREQ("-0.0998334166468282", _gc(xasprintf("%.15g", sin(-.1)))); + EXPECT_STREQ("0.479425538604203", _gc(xasprintf("%.15g", sin(.5)))); + EXPECT_STREQ("-0.479425538604203", _gc(xasprintf("%.15g", sin(-.5)))); + EXPECT_STREQ("0.841470984807897", _gc(xasprintf("%.15g", sin(1.)))); + EXPECT_STREQ("-0.841470984807897", _gc(xasprintf("%.15g", sin(-1.)))); + EXPECT_STREQ("0.997494986604054", _gc(xasprintf("%.15g", sin(1.5)))); + EXPECT_STREQ("-0.997494986604054", _gc(xasprintf("%.15g", sin(-1.5)))); + EXPECT_STREQ("0.909297426825682", _gc(xasprintf("%.15g", sin(2.)))); EXPECT_TRUE(isnan(sin(NAN))); EXPECT_TRUE(isnan(sin(-NAN))); EXPECT_TRUE(isnan(sin(INFINITY))); EXPECT_TRUE(isnan(sin(-INFINITY))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", sin(__DBL_MIN__)))); - EXPECT_STREQ("0.00496195478918406", gc(xasprintf("%.15g", sin(__DBL_MAX__)))); + _gc(xasprintf("%.15g", sin(__DBL_MIN__)))); + EXPECT_STREQ("0.00496195478918406", + _gc(xasprintf("%.15g", sin(__DBL_MAX__)))); EXPECT_STREQ("-0.841470984807897", - gc(xasprintf("%.15g", sin(-1.0000000000000002)))); + _gc(xasprintf("%.15g", sin(-1.0000000000000002)))); EXPECT_STREQ("-2.1073424255447e-08", - gc(xasprintf("%.15g", sin(-2.1073424255447e-08)))); + _gc(xasprintf("%.15g", sin(-2.1073424255447e-08)))); } TEST(sinf, test) { EXPECT_TRUE(isnan(sinf(NAN))); EXPECT_TRUE(isnan(sinf(+INFINITY))); EXPECT_TRUE(isnan(sinf(-INFINITY))); - EXPECT_STREQ("NAN", gc(xdtoaf(sinf(NAN)))); - EXPECT_STARTSWITH(".479426", gc(xdtoaf(sinf(.5f)))); - EXPECT_STARTSWITH("-.479426", gc(xdtoaf(sinf(-.5f)))); - EXPECT_STARTSWITH(".873283", gc(xdtoaf(sinf(555)))); + EXPECT_STREQ("NAN", _gc(xdtoaf(sinf(NAN)))); + EXPECT_STARTSWITH(".479426", _gc(xdtoaf(sinf(.5f)))); + EXPECT_STARTSWITH("-.479426", _gc(xdtoaf(sinf(-.5f)))); + EXPECT_STARTSWITH(".873283", _gc(xdtoaf(sinf(555)))); } BENCH(sin, bench) { diff --git a/test/libc/tinymath/sincos_test.c b/test/libc/tinymath/sincos_test.c index 7fdd0ee05..313c5e201 100644 --- a/test/libc/tinymath/sincos_test.c +++ b/test/libc/tinymath/sincos_test.c @@ -17,30 +17,30 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(sincos, test) { double sine, cosine; sincos(.1, &sine, &cosine); - EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", sine))); - EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cosine))); + EXPECT_STREQ("0.0998334166468282", _gc(xasprintf("%.15g", sine))); + EXPECT_STREQ("0.995004165278026", _gc(xasprintf("%.15g", cosine))); } TEST(sincosf, test) { float sine, cosine; sincosf(.1, &sine, &cosine); - EXPECT_STREQ("0.0998334", gc(xasprintf("%.6g", sine))); - EXPECT_STREQ("0.995004", gc(xasprintf("%.6g", cosine))); + EXPECT_STREQ("0.0998334", _gc(xasprintf("%.6g", sine))); + EXPECT_STREQ("0.995004", _gc(xasprintf("%.6g", cosine))); } TEST(sincosl, test) { long double sine, cosine; sincosl(.1, &sine, &cosine); - EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15Lg", sine))); - EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15Lg", cosine))); + EXPECT_STREQ("0.0998334166468282", _gc(xasprintf("%.15Lg", sine))); + EXPECT_STREQ("0.995004165278026", _gc(xasprintf("%.15Lg", cosine))); } #define NUM .123 diff --git a/test/libc/tinymath/sinh_test.c b/test/libc/tinymath/sinh_test.c index 653bb560b..68ee5680c 100644 --- a/test/libc/tinymath/sinh_test.c +++ b/test/libc/tinymath/sinh_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/sqrt_test.c b/test/libc/tinymath/sqrt_test.c index 4bb30827f..d1d3591ed 100644 --- a/test/libc/tinymath/sqrt_test.c +++ b/test/libc/tinymath/sqrt_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/tinymath/strtod_test.c b/test/libc/tinymath/strtod_test.c index d1ee1d955..6dacc29fe 100644 --- a/test/libc/tinymath/strtod_test.c +++ b/test/libc/tinymath/strtod_test.c @@ -18,12 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/runtime/fenv.h" -#include "libc/runtime/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/double-conversion/wrapper.h" #include "third_party/gdtoa/gdtoa.h" @@ -379,19 +379,19 @@ TEST(strtod, test) { TEST(strtod, testNearest) { fesetround(FE_TONEAREST); EXPECT_STREQ("-1.79769313486231e+308", - gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); + _gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); } TEST(strtod, testDownward) { fesetround(FE_DOWNWARD); EXPECT_STREQ("-1.79769313486232e+308", - gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); + _gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); } TEST(strtod, testUpward) { fesetround(FE_UPWARD); EXPECT_STREQ("-1.7976931348623e+308", - gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); + _gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); } TEST(strtod, testTowardzero) { diff --git a/test/libc/tinymath/tan_test.c b/test/libc/tinymath/tan_test.c index bfce11b0c..7660575a4 100644 --- a/test/libc/tinymath/tan_test.c +++ b/test/libc/tinymath/tan_test.c @@ -17,27 +17,28 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(tan, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", tan(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", tan(-0.)))); - EXPECT_STREQ("0.54630248984379", gc(xasprintf("%.15g", tan(.5)))); - EXPECT_STREQ("-0.54630248984379", gc(xasprintf("%.15g", tan(-.5)))); - EXPECT_STREQ("1.5574077246549", gc(xasprintf("%.15g", tan(1.)))); - EXPECT_STREQ("-1.5574077246549", gc(xasprintf("%.15g", tan(-1.)))); - EXPECT_STREQ("14.1014199471717", gc(xasprintf("%.15g", tan(1.5)))); - EXPECT_STREQ("-14.1014199471717", gc(xasprintf("%.15g", tan(-1.5)))); - EXPECT_STREQ("nan", gc(xasprintf("%.15g", tan(NAN)))); - EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(-NAN)))); - EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(INFINITY)))); - EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(-INFINITY)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", tan(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", tan(-0.)))); + EXPECT_STREQ("0.54630248984379", _gc(xasprintf("%.15g", tan(.5)))); + EXPECT_STREQ("-0.54630248984379", _gc(xasprintf("%.15g", tan(-.5)))); + EXPECT_STREQ("1.5574077246549", _gc(xasprintf("%.15g", tan(1.)))); + EXPECT_STREQ("-1.5574077246549", _gc(xasprintf("%.15g", tan(-1.)))); + EXPECT_STREQ("14.1014199471717", _gc(xasprintf("%.15g", tan(1.5)))); + EXPECT_STREQ("-14.1014199471717", _gc(xasprintf("%.15g", tan(-1.5)))); + EXPECT_STREQ("nan", _gc(xasprintf("%.15g", tan(NAN)))); + EXPECT_STREQ("-nan", _gc(xasprintf("%.15g", tan(-NAN)))); + EXPECT_STREQ("-nan", _gc(xasprintf("%.15g", tan(INFINITY)))); + EXPECT_STREQ("-nan", _gc(xasprintf("%.15g", tan(-INFINITY)))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", tan(__DBL_MIN__)))); - EXPECT_STREQ("-0.0049620158744449", gc(xasprintf("%.15g", tan(__DBL_MAX__)))); + _gc(xasprintf("%.15g", tan(__DBL_MIN__)))); + EXPECT_STREQ("-0.0049620158744449", + _gc(xasprintf("%.15g", tan(__DBL_MAX__)))); } BENCH(tan, bench) { diff --git a/test/libc/tinymath/tanh_test.c b/test/libc/tinymath/tanh_test.c index 3760a9515..dc3d9b789 100644 --- a/test/libc/tinymath/tanh_test.c +++ b/test/libc/tinymath/tanh_test.c @@ -17,55 +17,56 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #define tanhl(x) tanhl(VEIL("t", (long double)(x))) #define tanh(x) tanh(VEIL("x", (double)(x))) #define tanhf(x) tanhf(VEIL("x", (float)(x))) TEST(tanhl, test) { - EXPECT_STREQ(".09966799462495582", gc(xdtoal(tanhl(+.1)))); - EXPECT_STREQ("-.09966799462495582", gc(xdtoal(tanhl(-.1)))); - EXPECT_STREQ("0", gc(xdtoal(tanhl(0)))); - EXPECT_STREQ("-0", gc(xdtoal(tanhl(-0.)))); + EXPECT_STREQ(".09966799462495582", _gc(xdtoal(tanhl(+.1)))); + EXPECT_STREQ("-.09966799462495582", _gc(xdtoal(tanhl(-.1)))); + EXPECT_STREQ("0", _gc(xdtoal(tanhl(0)))); + EXPECT_STREQ("-0", _gc(xdtoal(tanhl(-0.)))); EXPECT_TRUE(isnan(tanhl(NAN))); - EXPECT_STREQ("1", gc(xdtoal(tanhl(INFINITY)))); - EXPECT_STREQ("-1", gc(xdtoal(tanhl(-INFINITY)))); + EXPECT_STREQ("1", _gc(xdtoal(tanhl(INFINITY)))); + EXPECT_STREQ("-1", _gc(xdtoal(tanhl(-INFINITY)))); } TEST(tanh, test) { - EXPECT_STREQ("0", gc(xasprintf("%.15g", tanh(0.)))); - EXPECT_STREQ("-0", gc(xasprintf("%.15g", tanh(-0.)))); - EXPECT_STREQ("0.0996679946249558", gc(xasprintf("%.15g", tanh(.1)))); - EXPECT_STREQ("-0.0996679946249558", gc(xasprintf("%.15g", tanh(-.1)))); - EXPECT_STREQ("0.46211715726001", gc(xasprintf("%.15g", tanh(.5)))); - EXPECT_STREQ("-0.46211715726001", gc(xasprintf("%.15g", tanh(-.5)))); - EXPECT_STREQ("0.761594155955765", gc(xasprintf("%.15g", tanh(1.)))); - EXPECT_STREQ("-0.761594155955765", gc(xasprintf("%.15g", tanh(-1.)))); - EXPECT_STREQ("0.905148253644866", gc(xasprintf("%.15g", tanh(1.5)))); - EXPECT_STREQ("-0.905148253644866", gc(xasprintf("%.15g", tanh(-1.5)))); - EXPECT_STREQ("0.964027580075817", gc(xasprintf("%.15g", tanh(2.)))); + EXPECT_STREQ("0", _gc(xasprintf("%.15g", tanh(0.)))); + EXPECT_STREQ("-0", _gc(xasprintf("%.15g", tanh(-0.)))); + EXPECT_STREQ("0.0996679946249558", _gc(xasprintf("%.15g", tanh(.1)))); + EXPECT_STREQ("-0.0996679946249558", _gc(xasprintf("%.15g", tanh(-.1)))); + EXPECT_STREQ("0.46211715726001", _gc(xasprintf("%.15g", tanh(.5)))); + EXPECT_STREQ("-0.46211715726001", _gc(xasprintf("%.15g", tanh(-.5)))); + EXPECT_STREQ("0.761594155955765", _gc(xasprintf("%.15g", tanh(1.)))); + EXPECT_STREQ("-0.761594155955765", _gc(xasprintf("%.15g", tanh(-1.)))); + EXPECT_STREQ("0.905148253644866", _gc(xasprintf("%.15g", tanh(1.5)))); + EXPECT_STREQ("-0.905148253644866", _gc(xasprintf("%.15g", tanh(-1.5)))); + EXPECT_STREQ("0.964027580075817", _gc(xasprintf("%.15g", tanh(2.)))); EXPECT_TRUE(isnan(tanh(NAN))); EXPECT_TRUE(isnan(tanh(-NAN))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", tanh(INFINITY)))); - EXPECT_STREQ("-1", gc(xasprintf("%.15g", tanh(-INFINITY)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", tanh(INFINITY)))); + EXPECT_STREQ("-1", _gc(xasprintf("%.15g", tanh(-INFINITY)))); EXPECT_STREQ("2.2250738585072e-308", - gc(xasprintf("%.15g", tanh(__DBL_MIN__)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", tanh(__DBL_MAX__)))); + _gc(xasprintf("%.15g", tanh(__DBL_MIN__)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", tanh(__DBL_MAX__)))); EXPECT_STREQ("-0.761594155955765", - gc(xasprintf("%.15g", tanh(-1.0000000000000002)))); + _gc(xasprintf("%.15g", tanh(-1.0000000000000002)))); EXPECT_STREQ("-2.1073424255447e-08", - gc(xasprintf("%.15g", tanh(-2.1073424255447e-08)))); + _gc(xasprintf("%.15g", tanh(-2.1073424255447e-08)))); } TEST(tanhf, test) { - EXPECT_STREQ(".099668", gc(xdtoaf(tanhf(+.1)))); - EXPECT_STREQ("-.099668", gc(xdtoaf(tanhf(-.1)))); - EXPECT_STREQ("0", gc(xdtoaf(tanhf(0)))); - EXPECT_STREQ("-0", gc(xdtoaf(tanhf(-0.)))); + EXPECT_STREQ(".099668", _gc(xdtoaf(tanhf(+.1)))); + EXPECT_STREQ("-.099668", _gc(xdtoaf(tanhf(-.1)))); + EXPECT_STREQ("0", _gc(xdtoaf(tanhf(0)))); + EXPECT_STREQ("-0", _gc(xdtoaf(tanhf(-0.)))); EXPECT_TRUE(isnan(tanhf(NAN))); - EXPECT_STREQ("1", gc(xdtoaf(tanhf(INFINITY)))); - EXPECT_STREQ("-1", gc(xdtoaf(tanhf(-INFINITY)))); + EXPECT_STREQ("1", _gc(xdtoaf(tanhf(INFINITY)))); + EXPECT_STREQ("-1", _gc(xdtoaf(tanhf(-INFINITY)))); } diff --git a/test/libc/tinymath/tgamma_test.c b/test/libc/tinymath/tgamma_test.c index a69f74ccb..50e6446d5 100644 --- a/test/libc/tinymath/tgamma_test.c +++ b/test/libc/tinymath/tgamma_test.c @@ -17,31 +17,31 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(tgamma, test) { - EXPECT_STREQ("inf", gc(xasprintf("%.15g", tgamma(0.)))); - EXPECT_STREQ("-inf", gc(xasprintf("%.15g", tgamma(-0.)))); - EXPECT_STREQ("9.51350769866873", gc(xasprintf("%.15g", tgamma(.1)))); - EXPECT_STREQ("-10.6862870211932", gc(xasprintf("%.15g", tgamma(-.1)))); - EXPECT_STREQ("1.77245385090552", gc(xasprintf("%.15g", tgamma(.5)))); - EXPECT_STREQ("-3.54490770181103", gc(xasprintf("%.15g", tgamma(-.5)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", tgamma(1.)))); + EXPECT_STREQ("inf", _gc(xasprintf("%.15g", tgamma(0.)))); + EXPECT_STREQ("-inf", _gc(xasprintf("%.15g", tgamma(-0.)))); + EXPECT_STREQ("9.51350769866873", _gc(xasprintf("%.15g", tgamma(.1)))); + EXPECT_STREQ("-10.6862870211932", _gc(xasprintf("%.15g", tgamma(-.1)))); + EXPECT_STREQ("1.77245385090552", _gc(xasprintf("%.15g", tgamma(.5)))); + EXPECT_STREQ("-3.54490770181103", _gc(xasprintf("%.15g", tgamma(-.5)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", tgamma(1.)))); EXPECT_TRUE(isnan(tgamma(-1.))); - EXPECT_STREQ("0.886226925452758", gc(xasprintf("%.15g", tgamma(1.5)))); - EXPECT_STREQ("2.36327180120735", gc(xasprintf("%.15g", tgamma(-1.5)))); - EXPECT_STREQ("1", gc(xasprintf("%.15g", tgamma(2.)))); + EXPECT_STREQ("0.886226925452758", _gc(xasprintf("%.15g", tgamma(1.5)))); + EXPECT_STREQ("2.36327180120735", _gc(xasprintf("%.15g", tgamma(-1.5)))); + EXPECT_STREQ("1", _gc(xasprintf("%.15g", tgamma(2.)))); EXPECT_TRUE(isnan(tgamma(NAN))); EXPECT_TRUE(isnan(tgamma(-NAN))); - EXPECT_STREQ("inf", gc(xasprintf("%.15g", tgamma(INFINITY)))); + EXPECT_STREQ("inf", _gc(xasprintf("%.15g", tgamma(INFINITY)))); EXPECT_TRUE(isnan(tgamma(-INFINITY))); EXPECT_STREQ("4.49423283715579e+307", - gc(xasprintf("%.15g", tgamma(__DBL_MIN__)))); - EXPECT_STREQ("inf", gc(xasprintf("%.15g", tgamma(__DBL_MAX__)))); + _gc(xasprintf("%.15g", tgamma(__DBL_MIN__)))); + EXPECT_STREQ("inf", _gc(xasprintf("%.15g", tgamma(__DBL_MAX__)))); EXPECT_STREQ("4.5035996273705e+15", - gc(xasprintf("%.14g", tgamma(-1.0000000000000002)))); + _gc(xasprintf("%.14g", tgamma(-1.0000000000000002)))); EXPECT_STREQ("-47453133.3893415", - gc(xasprintf("%.15g", tgamma(-2.1073424255447e-08)))); + _gc(xasprintf("%.15g", tgamma(-2.1073424255447e-08)))); } diff --git a/test/libc/tinymath/trunc_test.c b/test/libc/tinymath/trunc_test.c index 64f1c0d97..301781b08 100644 --- a/test/libc/tinymath/trunc_test.c +++ b/test/libc/tinymath/trunc_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/x/filecmp_test.c b/test/libc/x/filecmp_test.c deleted file mode 100644 index 0d989a707..000000000 --- a/test/libc/x/filecmp_test.c +++ /dev/null @@ -1,66 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/mem.h" -#include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" -#include "libc/stdio/stdio.h" -#include "libc/sysv/consts/madv.h" -#include "libc/sysv/consts/o.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" -#include "libc/x/x.h" - -// TODO: This test flakes occasionally on Windows. -#if 0 - -#define N (72 * 1024) - -char p[N]; -char testlib_enable_tmp_setup_teardown; - -TEST(filecmp, testEqual) { - rngset(p, N, rand64, -1); - EXPECT_EQ(0, xbarf("a", p, N)); - EXPECT_EQ(0, xbarf("b", p, N)); - EXPECT_EQ(0, filecmp("a", "b")); -} - -TEST(filecmp, testNotEqual) { - rngset(p, N, rand64, -1); - EXPECT_EQ(0, xbarf("a", p, N)); - p[N / 2]++; - EXPECT_EQ(0, xbarf("b", p, N)); - EXPECT_NE(0, filecmp("a", "b")); -} - -TEST(filecmp, testDifferentLength) { - rngset(p, N, rand64, -1); - EXPECT_EQ(0, xbarf("a", p, N)); - EXPECT_EQ(0, xbarf("b", p, N - 1)); - EXPECT_NE(0, filecmp("a", "b")); -} - -BENCH(filecmp, bench) { - rngset(p, N, rand64, -1); - EXPECT_EQ(0, xbarf("a", p, N)); - EXPECT_EQ(0, xbarf("b", p, N)); - EZBENCH2("filecmp", donothing, filecmp("a", "b")); -} - -#endif diff --git a/test/libc/x/makedirs_test.c b/test/libc/x/makedirs_test.c index 388006035..eb1ae9419 100644 --- a/test/libc/x/makedirs_test.c +++ b/test/libc/x/makedirs_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/thread/spawn.h" #include "libc/thread/thread.h" diff --git a/test/libc/x/utf16to32_test.c b/test/libc/x/utf16to32_test.c index 132588a7f..35a8b4d91 100644 --- a/test/libc/x/utf16to32_test.c +++ b/test/libc/x/utf16to32_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/x/utf16to8_test.c b/test/libc/x/utf16to8_test.c index 0af0c445c..057749dfc 100644 --- a/test/libc/x/utf16to8_test.c +++ b/test/libc/x/utf16to8_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/x/utf8to16_test.c b/test/libc/x/utf8to16_test.c index 34dd37e3c..870471d8e 100644 --- a/test/libc/x/utf8to16_test.c +++ b/test/libc/x/utf8to16_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/x/utf8to32_test.c b/test/libc/x/utf8to32_test.c index c01dd60b5..2442b0c6f 100644 --- a/test/libc/x/utf8to32_test.c +++ b/test/libc/x/utf8to32_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/mem/shuffle.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/rand.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/x/xasprintf_test.c b/test/libc/x/xasprintf_test.c index 93cfba40e..26f6a226f 100644 --- a/test/libc/x/xasprintf_test.c +++ b/test/libc/x/xasprintf_test.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(xasprintf, test) { - EXPECT_STREQ("hi.there", gc(xasprintf("%s.%s", "hi", "there"))); + EXPECT_STREQ("hi.there", _gc(xasprintf("%s.%s", "hi", "there"))); } diff --git a/test/libc/x/xjoinpaths_test.c b/test/libc/x/xjoinpaths_test.c index b1d05e539..5857fa547 100644 --- a/test/libc/x/xjoinpaths_test.c +++ b/test/libc/x/xjoinpaths_test.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/x/xslurp_test.c b/test/libc/x/xslurp_test.c index 96982ab6c..be48792f0 100644 --- a/test/libc/x/xslurp_test.c +++ b/test/libc/x/xslurp_test.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/x/xstrcat_test.c b/test/libc/x/xstrcat_test.c index e7df6a83f..a47e45d11 100644 --- a/test/libc/x/xstrcat_test.c +++ b/test/libc/x/xstrcat_test.c @@ -16,12 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" TEST(xstrcat, test) { EXPECT_STREQ("hi", gc(xstrcat("hi"))); diff --git a/test/libc/xed/x86ild_lib.c b/test/libc/xed/x86ild_lib.c index 095bd4dee..d7fe42a90 100644 --- a/test/libc/xed/x86ild_lib.c +++ b/test/libc/xed/x86ild_lib.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/bing.internal.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/test/libc/xed/x86ild_test.c b/test/libc/xed/x86ild_test.c index 9e0f7b678..0b70149de 100644 --- a/test/libc/xed/x86ild_test.c +++ b/test/libc/xed/x86ild_test.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "test/libc/xed/lib.h" diff --git a/test/libc/zipos/open_test.c b/test/libc/zipos/open_test.c index 9b1d5fad2..25c8edbc7 100644 --- a/test/libc/zipos/open_test.c +++ b/test/libc/zipos/open_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" diff --git a/test/net/http/decodebase64_test.c b/test/net/http/decodebase64_test.c index 7583656c8..aa75a2739 100644 --- a/test/net/http/decodebase64_test.c +++ b/test/net/http/decodebase64_test.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" #include "net/http/escape.h" diff --git a/test/net/http/decodelatin1_test.c b/test/net/http/decodelatin1_test.c index 6dab4c079..9201182bf 100644 --- a/test/net/http/decodelatin1_test.c +++ b/test/net/http/decodelatin1_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/net/http/encodebase64_test.c b/test/net/http/encodebase64_test.c index 7b8df1382..0d187ac65 100644 --- a/test/net/http/encodebase64_test.c +++ b/test/net/http/encodebase64_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/net/http/encodehttpheadervalue_test.c b/test/net/http/encodehttpheadervalue_test.c index dafe8cfff..32604424d 100644 --- a/test/net/http/encodehttpheadervalue_test.c +++ b/test/net/http/encodehttpheadervalue_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/net/http/escapehtml_test.c b/test/net/http/escapehtml_test.c index c5434a11e..c3bf37a24 100644 --- a/test/net/http/escapehtml_test.c +++ b/test/net/http/escapehtml_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/net/http/escapejsstringliteral_test.c b/test/net/http/escapejsstringliteral_test.c index f3cbf611f..70a16cf7e 100644 --- a/test/net/http/escapejsstringliteral_test.c +++ b/test/net/http/escapejsstringliteral_test.c @@ -19,7 +19,7 @@ #include "libc/calls/calls.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "libc/str/str.h" diff --git a/test/net/http/escapeurlparam_test.c b/test/net/http/escapeurlparam_test.c index a39c022f9..c65b38cea 100644 --- a/test/net/http/escapeurlparam_test.c +++ b/test/net/http/escapeurlparam_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/net/http/indentlines_test.c b/test/net/http/indentlines_test.c index 4db169138..6c02301e1 100644 --- a/test/net/http/indentlines_test.c +++ b/test/net/http/indentlines_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/net/http/isacceptablepath_test.c b/test/net/http/isacceptablepath_test.c index 4c0378ea8..e64868212 100644 --- a/test/net/http/isacceptablepath_test.c +++ b/test/net/http/isacceptablepath_test.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "net/http/escape.h" diff --git a/test/net/http/parsehttpmessage_test.c b/test/net/http/parsehttpmessage_test.c index 758465367..4adbf900f 100644 --- a/test/net/http/parsehttpmessage_test.c +++ b/test/net/http/parsehttpmessage_test.c @@ -20,7 +20,7 @@ #include "libc/errno.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/net/http/parseurl_test.c b/test/net/http/parseurl_test.c index a67326ce2..18f6dcae0 100644 --- a/test/net/http/parseurl_test.c +++ b/test/net/http/parseurl_test.c @@ -19,7 +19,7 @@ #include "libc/limits.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/net/http/underlong_test.c b/test/net/http/underlong_test.c index 303e052b5..ab887e65b 100644 --- a/test/net/http/underlong_test.c +++ b/test/net/http/underlong_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" diff --git a/test/net/http/visualizecontrolcodes_test.c b/test/net/http/visualizecontrolcodes_test.c index 6bc12fb0b..fc8d90e4e 100644 --- a/test/net/http/visualizecontrolcodes_test.c +++ b/test/net/http/visualizecontrolcodes_test.c @@ -16,36 +16,36 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "net/http/escape.h" TEST(VisualizeControlCodes, test) { size_t n; - EXPECT_STREQ("hello", gc(VisualizeControlCodes("hello", -1, 0))); - EXPECT_STREQ("hello\r\n", gc(VisualizeControlCodes("hello\r\n", -1, 0))); - EXPECT_STREQ("hello␁␂␡", gc(VisualizeControlCodes("hello\1\2\177", -1, 0))); + EXPECT_STREQ("hello", _gc(VisualizeControlCodes("hello", -1, 0))); + EXPECT_STREQ("hello\r\n", _gc(VisualizeControlCodes("hello\r\n", -1, 0))); + EXPECT_STREQ("hello␁␂␡", _gc(VisualizeControlCodes("hello\1\2\177", -1, 0))); EXPECT_STREQ("hello\\u0085", - gc(VisualizeControlCodes("hello\302\205", -1, 0))); - EXPECT_STREQ("hi", gc(VisualizeControlCodes("hi", -1, &n))); + _gc(VisualizeControlCodes("hello\302\205", -1, 0))); + EXPECT_STREQ("hi", _gc(VisualizeControlCodes("hi", -1, &n))); EXPECT_EQ(2, n); } TEST(VisualizeControlCodes, testOom_returnsNullAndSetsSizeToZero) { size_t n = 31337; - EXPECT_EQ(NULL, gc(VisualizeControlCodes("hello", 0x1000000000000, &n))); + EXPECT_EQ(NULL, _gc(VisualizeControlCodes("hello", 0x1000000000000, &n))); EXPECT_EQ(0, n); } TEST(VisualizeControlCodes, testWeirdHttp) { size_t n = 31337; char *p, B[] = "\0GET /redbean.lua\n\n"; - ASSERT_NE(0, (p = gc(VisualizeControlCodes(B, sizeof(B), &n)))); - EXPECT_STREQ("\"␀GET /redbean.lua\\n\\n␀\"", gc(xasprintf("%`'.*s", n, p))); + ASSERT_NE(0, (p = _gc(VisualizeControlCodes(B, sizeof(B), &n)))); + EXPECT_STREQ("\"␀GET /redbean.lua\\n\\n␀\"", _gc(xasprintf("%`'.*s", n, p))); } BENCH(VisualizeControlCodes, bench) { diff --git a/test/net/https/mbedtls_test.c b/test/net/https/mbedtls_test.c index c6095b4b0..a29c3265f 100644 --- a/test/net/https/mbedtls_test.c +++ b/test/net/https/mbedtls_test.c @@ -19,18 +19,18 @@ #include "libc/intrin/bits.h" #include "libc/intrin/bswap.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" #include "libc/nt/typedef/imagetlscallback.h" -#include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/rand.h" #include "libc/str/blake2.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/mbedtls/aes.h" #include "third_party/mbedtls/base64.h" #include "third_party/mbedtls/bignum.h" @@ -168,7 +168,7 @@ BENCH(p256, bench) { #ifdef MBEDTLS_ECP_C mbedtls_ecp_group_init(&grp); mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_SECP256R1); - mbedtls_mpi x = {1, 8, gc(calloc(8, 8))}; + mbedtls_mpi x = {1, 8, _gc(calloc(8, 8))}; rngset(x.p, 8 * 8, rand64, -1); EZBENCH2("P-256 modulus MbedTLS MPI lib", donothing, P256_MPI(&x)); EZBENCH2("P-256 modulus Justine rewrite", donothing, P256_JUSTINE(&x)); @@ -181,7 +181,7 @@ BENCH(p384, bench) { mbedtls_ecp_group_init(&grp); mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_SECP384R1); uint64_t y[12]; - mbedtls_mpi x = {1, 12, gc(calloc(12, 8))}; + mbedtls_mpi x = {1, 12, _gc(calloc(12, 8))}; EZBENCH2("P-384 modulus MbedTLS MPI lib", donothing, P384_MPI(&x)); EZBENCH2("P-384 modulus Justine rewrite", donothing, P384_JUSTINE(&x)); mbedtls_ecp_group_free(&grp); @@ -387,7 +387,7 @@ BENCH(quickjs_remainder, bench) { "2331094682317528819996876363073536047370469375", NULL, BF_PREC_INF, BF_RNDZ | BF_ATOF_NO_NAN_INF); bfdec_rem(&r, &x, &y, BF_PREC_INF, 0, BF_RNDF); - t = gc(bfdec_ftoa(0, &r, BF_PREC_INF, BF_RNDZ | BF_FTOA_FORMAT_FREE)); + t = _gc(bfdec_ftoa(0, &r, BF_PREC_INF, BF_RNDZ | BF_FTOA_FORMAT_FREE)); ASSERT_STREQ("327339060789614187001318969682759915221664204604306478" "948329136809613379640467455488327009232590415715088668" "4127560071009217256545885393053328527589375", @@ -403,7 +403,7 @@ BENCH(quickjs_remainder, bench) { BENCH(mpi_remainder, bench) { mbedtls_mpi *x, *y, r; - x = gc(str2mpi( + x = _gc(str2mpi( "131820409343094310010388979423659136318401916109327276909280345024175692" "811283445510797521231721220331409407564807168230384468176942405812817310" "624525121840385446744443868889563289706427719939300365865529242495144888" @@ -446,7 +446,7 @@ BENCH(mpi_remainder, bench) { "409401269127676106581410793787580434036114254547441805771508552049371634" "609025127325512605396392214570059772472666763440181556475095153967113514" "87546062479444592779055555421362722504575706910949375")); - y = gc(str2mpi( + y = _gc(str2mpi( "402702961953621844286950607555369624422784868935557056881131335461307658" "701727371551406721502307932123276358395008895125652043531209418099658895" "323804953421455502359439932416245276659698167468088937570774479761417692" @@ -481,7 +481,7 @@ BENCH(mpi_remainder, bench) { BENCH(mpi_mul_int, bench) { mbedtls_mpi *x, y; - x = gc(str2mpi( + x = _gc(str2mpi( "131820409343094310010388979423659136318401916109327276909280345024175692" "811283445510797521231721220331409407564807168230384468176942405812817310" "624525121840385446744443868889563289706427719939300365865529242495144888" @@ -674,7 +674,7 @@ BENCH(gcd, bench) { BENCH(inv_mod, bench3) { mbedtls_mpi g = {0}; - mbedtls_mpi *x = gc(str2mpi16( + mbedtls_mpi *x = _gc(str2mpi16( "837B3E23091602B5D14D619D9B2CD79DD039BC9A9F46F0CA1FFD01B398EE42C8EE2142CB" "B295109FC4278DB8AB84A6ADBF319D3297216C349D0EB92925E2794C5FF1AAF664034CB2" "5C15CDA49B7947278AA96BEF9D995C5F99AA4809B12568A1513D8E0A37BB338DC44A1722" @@ -683,7 +683,7 @@ BENCH(inv_mod, bench3) { "68ED274FA7F7D5BC3E014DDC7BEA4A60DF24805B5F94C998CAF28441FB4A5831755CE935" "2F17F5416647A81A78899E5B2C4D3F6C84A81CEB463C1593392ABCF6BF708A55578EB0EF" "E9ABF572")); - mbedtls_mpi *y = gc(str2mpi16( + mbedtls_mpi *y = _gc(str2mpi16( "C14DA3DDE7CD1DD104D74972B899AC0E78E43A3C4ACF3A1316D05AE4CDA30088A7EE1E6B" "96A752B490EF2D727A3E249AFCB634AC24F577E026648C9CB0287DA1DAEA8CE6C91C96BC" "FEC10452B336D4A3FAE1B176D890C161B4665236A22653AAAB745E077D1982DB2AD81FA0" diff --git a/test/tool/build/lib/divmul_test.c b/test/tool/build/lib/divmul_test.c index 36e070997..ea0a96639 100644 --- a/test/tool/build/lib/divmul_test.c +++ b/test/tool/build/lib/divmul_test.c @@ -17,17 +17,18 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/sigaction.h" -#include "libc/log/check.h" -#include "libc/runtime/gc.internal.h" +#include "libc/macros.internal.h" +#include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" -#include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" +#include "third_party/xed/x86.h" #include "tool/build/lib/divmul.h" #include "tool/build/lib/endian.h" #include "tool/build/lib/flags.h" +#include "tool/build/lib/machine.h" #define CX 1 #define OSZ 00000000040 @@ -47,12 +48,12 @@ void OnSigFpe(void) { void SetUp(void) { m->xedd = xedd; - CHECK_NE(-1, xsigaction(SIGFPE, OnSigFpe, SA_NODEFER, 0, oldsigfpe)); + ASSERT_NE(-1, xsigaction(SIGFPE, OnSigFpe, SA_NODEFER, 0, oldsigfpe)); } void TearDown(void) { m->xedd = xedd; - CHECK_NE(-1, sigaction(SIGFPE, oldsigfpe, NULL)); + ASSERT_NE(-1, sigaction(SIGFPE, oldsigfpe, NULL)); } TEST(imul8, test) { diff --git a/test/tool/build/lib/interner_test.c b/test/tool/build/lib/interner_test.c index a9cfa36d0..c2f3d7ac7 100644 --- a/test/tool/build/lib/interner_test.c +++ b/test/tool/build/lib/interner_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/tool/build/lib/javadown_test.c b/test/tool/build/lib/javadown_test.c index b2c36c7eb..fca500753 100644 --- a/test/tool/build/lib/javadown_test.c +++ b/test/tool/build/lib/javadown_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" diff --git a/test/tool/build/lib/machine_test.c b/test/tool/build/lib/machine_test.c index df55d1ea3..8a66bc347 100644 --- a/test/tool/build/lib/machine_test.c +++ b/test/tool/build/lib/machine_test.c @@ -19,7 +19,7 @@ #include "libc/fmt/bing.internal.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/tool/build/lib/modrm_test.c b/test/tool/build/lib/modrm_test.c index 4f7b2e50c..73f50dfa5 100644 --- a/test/tool/build/lib/modrm_test.c +++ b/test/tool/build/lib/modrm_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "third_party/xed/x86.h" #include "tool/build/lib/endian.h" diff --git a/test/tool/build/lib/optest.c b/test/tool/build/lib/optest.c index 891415b7e..e7647cbe5 100644 --- a/test/tool/build/lib/optest.c +++ b/test/tool/build/lib/optest.c @@ -49,7 +49,7 @@ void(RunOpTests)(const uint8_t *ops, size_t n, const char *const *opnames, o << FLAGS_OF; xn = RunGolden(w, ops[h], x, y, &f1); xp = RunOpTest(w, ops[h], x, y, &f2); - if (weaken(FixupUndefOpTestFlags)) { + if (_weaken(FixupUndefOpTestFlags)) { FixupUndefOpTestFlags(w, ops[h], x, y, f1, &f2); } if (xn == xp && (f1 & FMASK) == (f2 & FMASK)) { diff --git a/test/tool/build/lib/pty_test.c b/test/tool/build/lib/pty_test.c index c5bdbfd76..3b2a4d0b9 100644 --- a/test/tool/build/lib/pty_test.c +++ b/test/tool/build/lib/pty_test.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" diff --git a/test/tool/net/redbean_test.c b/test/tool/net/redbean_test.c index 325b19427..7e1e189bd 100644 --- a/test/tool/net/redbean_test.c +++ b/test/tool/net/redbean_test.c @@ -17,8 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/struct/sigset.h" +#include "libc/dce.h" #include "libc/fmt/conv.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/goodsocket.internal.h" #include "libc/sock/sock.h" diff --git a/test/tool/plinko/plinko_test.c b/test/tool/plinko/plinko_test.c index 75fda9923..e35bd896e 100644 --- a/test/tool/plinko/plinko_test.c +++ b/test/tool/plinko/plinko_test.c @@ -17,11 +17,11 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/copyfd.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/errno.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" -#include "libc/mem/io.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -112,7 +112,7 @@ TEST(plinko, worksOrPrintsNiceError) { EXPECT_NE(-1, close(pfds[1][0])); EXPECT_NE(-1, waitpid(pid, &wstatus, 0)); EXPECT_TRUE(WIFEXITED(wstatus)); - if (!startswith(buf, "error: ")) { + if (!_startswith(buf, "error: ")) { EXPECT_STREQ("OKCOMPUTER\n", buf); EXPECT_EQ(0, WEXITSTATUS(wstatus)); } else { diff --git a/test/tool/viz/lib/convoindex_test.c b/test/tool/viz/lib/convoindex_test.c index f82898655..a59178f80 100644 --- a/test/tool/viz/lib/convoindex_test.c +++ b/test/tool/viz/lib/convoindex_test.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "tool/viz/lib/convolution.h" diff --git a/test/tool/viz/lib/fun_test.c b/test/tool/viz/lib/fun_test.c index 392279562..f194b24f8 100644 --- a/test/tool/viz/lib/fun_test.c +++ b/test/tool/viz/lib/fun_test.c @@ -19,7 +19,7 @@ #include "libc/log/check.h" #include "libc/macros.internal.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/tool/viz/lib/halfblit_test.c b/test/tool/viz/lib/halfblit_test.c index 83e14f72d..50d0790fd 100644 --- a/test/tool/viz/lib/halfblit_test.c +++ b/test/tool/viz/lib/halfblit_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/bing.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" #include "tool/viz/lib/halfblit.h" diff --git a/third_party/bzip2/blocksort.c b/third_party/bzip2/blocksort.c index 2069bd0bc..f20ddbf2b 100644 --- a/third_party/bzip2/blocksort.c +++ b/third_party/bzip2/blocksort.c @@ -20,7 +20,7 @@ ------------------------------------------------------------------ */ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "third_party/bzip2/bzlib_private.inc" diff --git a/third_party/bzip2/bzip2.c b/third_party/bzip2/bzip2.c index f46c7bb50..39cae7414 100644 --- a/third_party/bzip2/bzip2.c +++ b/third_party/bzip2/bzip2.c @@ -4,8 +4,9 @@ #include "libc/calls/struct/stat.macros.h" #include "libc/errno.h" #include "libc/log/log.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" diff --git a/third_party/bzip2/huffman.c b/third_party/bzip2/huffman.c index 598b864e5..1b3797edc 100644 --- a/third_party/bzip2/huffman.c +++ b/third_party/bzip2/huffman.c @@ -20,7 +20,7 @@ ------------------------------------------------------------------ */ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "third_party/bzip2/bzlib_private.inc" diff --git a/third_party/chibicc/as.c b/third_party/chibicc/as.c index 69ba3a886..56f66d6f9 100644 --- a/third_party/chibicc/as.c +++ b/third_party/chibicc/as.c @@ -16,17 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" -#include "libc/intrin/popcnt.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/elf/def.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" +#include "libc/intrin/popcnt.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/crc32.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -34,6 +34,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/s.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/file.h" #include "third_party/gdtoa/gdtoa.h" #include "tool/build/lib/elfwriter.h" @@ -479,11 +480,11 @@ static void ReadFlags(struct As *a, int argc, char *argv[]) { for (i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-o")) { a->outpath = StrDup(a, argv[++i]); - } else if (startswith(argv[i], "-o")) { + } else if (_startswith(argv[i], "-o")) { a->outpath = StrDup(a, argv[i] + 2); } else if (!strcmp(argv[i], "-I")) { SaveString(&a->incpaths, strdup(argv[++i])); - } else if (startswith(argv[i], "-I")) { + } else if (_startswith(argv[i], "-I")) { SaveString(&a->incpaths, strdup(argv[i] + 2)); } else if (!strcmp(argv[i], "-Z")) { a->inhibiterr = true; @@ -1667,13 +1668,13 @@ static int GrabSection(struct As *a, int name, int flags, int type, int group, static void OnSection(struct As *a, struct Slice s) { int name, flags, type, group = -1, comdat = -1; name = SliceDup(a, GetSlice(a)); - if (startswith(a->strings.p[name], ".text")) { + if (_startswith(a->strings.p[name], ".text")) { flags = SHF_ALLOC | SHF_EXECINSTR; type = SHT_PROGBITS; - } else if (startswith(a->strings.p[name], ".data")) { + } else if (_startswith(a->strings.p[name], ".data")) { flags = SHF_ALLOC | SHF_WRITE; type = SHT_PROGBITS; - } else if (startswith(a->strings.p[name], ".bss")) { + } else if (_startswith(a->strings.p[name], ".bss")) { flags = SHF_ALLOC | SHF_WRITE; type = SHT_NOBITS; } else { @@ -2025,7 +2026,7 @@ static int ParseModrm(struct As *a, int *disp) { if (((reg & 070) >> 3) == 2) modrm |= HASASZ; // asz if (IsComma(a)) { ++a->i; - modrm |= (bsr(GetInt(a)) & 3) << 6; + modrm |= (_bsr(GetInt(a)) & 3) << 6; } } ConsumePunct(a, ')'); @@ -2607,8 +2608,8 @@ static bool HasXmmOnLine(struct As *a) { int i; for (i = 0; !IsPunct(a, a->i + i, ';'); ++i) { if (IsSlice(a, a->i + i) && a->slices.p[a->things.p[a->i + i].i].n >= 4 && - (startswith(a->slices.p[a->things.p[a->i + i].i].p, "xmm") || - startswith(a->slices.p[a->things.p[a->i + i].i].p, "%xmm"))) { + (_startswith(a->slices.p[a->things.p[a->i + i].i].p, "xmm") || + _startswith(a->slices.p[a->things.p[a->i + i].i].p, "%xmm"))) { return true; } } diff --git a/third_party/chibicc/asm.c b/third_party/chibicc/asm.c index 6ec640eaa..bd7c15a26 100644 --- a/third_party/chibicc/asm.c +++ b/third_party/chibicc/asm.c @@ -16,6 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/bsf.h" +#include "libc/intrin/bsr.h" #include "third_party/chibicc/chibicc.h" #define PRECIOUS 0b1111000000101000 // bx,bp,r12-r15 @@ -299,7 +301,7 @@ static void PickAsmRegisters(Asm *a) { if (!(m = a->ops[i].regmask)) break; if (popcnt(m) != j) break; if (!(m &= regset)) CouldNotAllocateRegister(&a->ops[i], "rm"); - pick = 1 << (a->ops[i].reg = bsf(m)); + pick = 1 << (a->ops[i].reg = _bsf(m)); if (pick & PRECIOUS) a->regclob |= pick; regset &= ~pick; a->ops[i].regmask = 0; @@ -307,14 +309,14 @@ static void PickAsmRegisters(Asm *a) { case kAsmXmm: if (!(m = a->ops[i].regmask)) break; if (!(m &= xmmset)) CouldNotAllocateRegister(&a->ops[i], "xmm"); - xmmset &= ~(1 << (a->ops[i].reg = bsf(m))); + xmmset &= ~(1 << (a->ops[i].reg = _bsf(m))); a->ops[i].regmask = 0; break; case kAsmFpu: if (!(m = a->ops[i].x87mask)) break; if (popcnt(m) != j) break; if (!(m &= x87sts)) CouldNotAllocateRegister(&a->ops[i], "fpu"); - x87sts &= ~(1 << (a->ops[i].reg = bsf(m))); + x87sts &= ~(1 << (a->ops[i].reg = _bsf(m))); a->ops[i].x87mask = 0; break; default: @@ -368,7 +370,7 @@ static Token *ParseAsmClobbers(Asm *a, Token *tok) { a->flagclob = true; } else if ((i = GetIndexOfRegisterName(s)) != -1) { a->regclob |= 1 << i; - } else if (startswith(s, "xmm") && isdigit(s[3]) && + } else if (_startswith(s, "xmm") && isdigit(s[3]) && (!s[4] || isdigit(s[4]))) { i = s[3] - '0'; if (s[4]) { @@ -379,7 +381,7 @@ static Token *ParseAsmClobbers(Asm *a, Token *tok) { a->xmmclob |= 1 << i; } else if (!strcmp(s, "st")) { a->x87clob |= 1; - } else if (startswith(s, "st(") && isdigit(s[3]) && s[4] == ')') { + } else if (_startswith(s, "st(") && isdigit(s[3]) && s[4] == ')') { i = s[3] - '0'; i &= 7; a->x87clob |= 1 << i; @@ -538,7 +540,7 @@ static char *HandleAsmSpecifier(Asm *a, char *p) { if ((i = c - '0') >= a->n) { error_tok(a->tok, "bad asm reference at offset %d", p - a->str); } - z = bsr(a->ops[i].node->ty->size); + z = _bsr(a->ops[i].node->ty->size); if (z > 3 && a->ops[i].type == kAsmReg) { error_tok(a->tok, "bad asm op size"); } @@ -677,7 +679,7 @@ static void StoreAsmOutputs(Asm *a) { println("\tset%s\t(%%rax)", a->ops[i].str + a->ops[i].predicate); break; case kAsmReg: - z = bsr(a->ops[i].node->ty->size); + z = _bsr(a->ops[i].node->ty->size); if (a->ops[i].reg) { gen_addr(a->ops[i].node); if (z > 3) error_tok(a->tok, "bad asm out size"); @@ -732,7 +734,7 @@ static void StoreAsmOutputs(Asm *a) { static void PushClobbers(Asm *a) { int i, regs = a->regclob & PRECIOUS; while (regs) { - i = bsf(regs); + i = _bsf(regs); pushreg(kGreg[3][i]); regs &= ~(1 << i); } @@ -741,7 +743,7 @@ static void PushClobbers(Asm *a) { static void PopClobbers(Asm *a) { int i, regs = a->regclob & PRECIOUS; while (regs) { - i = bsr(regs); + i = _bsr(regs); popreg(kGreg[3][i]); regs &= ~(1 << i); } diff --git a/third_party/chibicc/chibicc.c b/third_party/chibicc/chibicc.c index f92e9d71e..b9be1d6af 100644 --- a/third_party/chibicc/chibicc.c +++ b/third_party/chibicc/chibicc.c @@ -1,9 +1,11 @@ #include "libc/calls/calls.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/siginfo.h" #include "libc/calls/ucontext.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" -#include "libc/x/x.h" +#include "libc/sysv/consts/sig.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" asm(".ident\t\"\\n\\n\ @@ -215,7 +217,7 @@ static void parse_args(int argc, char **argv) { atexit(PrintMemoryUsage); } else if (!strcmp(argv[i], "-o")) { opt_o = argv[++i]; - } else if (startswith(argv[i], "-o")) { + } else if (_startswith(argv[i], "-o")) { opt_o = argv[i] + 2; } else if (!strcmp(argv[i], "-S")) { opt_S = true; @@ -239,19 +241,19 @@ static void parse_args(int argc, char **argv) { opt_P = true; } else if (!strcmp(argv[i], "-I")) { strarray_push(&include_paths, argv[++i]); - } else if (startswith(argv[i], "-I")) { + } else if (_startswith(argv[i], "-I")) { strarray_push(&include_paths, argv[i] + 2); } else if (!strcmp(argv[i], "-iquote")) { strarray_push(&include_paths, argv[++i]); - } else if (startswith(argv[i], "-iquote")) { + } else if (_startswith(argv[i], "-iquote")) { strarray_push(&include_paths, argv[i] + strlen("-iquote")); } else if (!strcmp(argv[i], "-isystem")) { strarray_push(&include_paths, argv[++i]); - } else if (startswith(argv[i], "-isystem")) { + } else if (_startswith(argv[i], "-isystem")) { strarray_push(&include_paths, argv[i] + strlen("-isystem")); } else if (!strcmp(argv[i], "-D")) { define(argv[++i]); - } else if (startswith(argv[i], "-D")) { + } else if (_startswith(argv[i], "-D")) { define(argv[i] + 2); } else if (!strcmp(argv[i], "-U")) { undef_macro(argv[++i]); @@ -263,9 +265,9 @@ static void parse_args(int argc, char **argv) { opt_x = parse_opt_x(argv[++i]); } else if (!strncmp(argv[i], "-x", 2)) { opt_x = parse_opt_x(argv[i] + 2); - } else if (startswith(argv[i], "-Wa")) { + } else if (_startswith(argv[i], "-Wa")) { strarray_push_comma(&as_extra_args, argv[i] + 3); - } else if (startswith(argv[i], "-Wl")) { + } else if (_startswith(argv[i], "-Wl")) { strarray_push_comma(&ld_extra_args, argv[i] + 3); } else if (!strcmp(argv[i], "-Xassembler")) { strarray_push(&as_extra_args, argv[++i]); @@ -333,7 +335,7 @@ static void parse_args(int argc, char **argv) { } else if (!strcmp(argv[i], "-L")) { strarray_push(&ld_extra_args, "-L"); strarray_push(&ld_extra_args, argv[++i]); - } else if (startswith(argv[i], "-L")) { + } else if (_startswith(argv[i], "-L")) { strarray_push(&ld_extra_args, "-L"); strarray_push(&ld_extra_args, argv[i] + 2); } else { @@ -560,11 +562,11 @@ static Token *append_tokens(Token *tok1, Token *tok2) { static FileType get_file_type(const char *filename) { if (opt_x != FILE_NONE) return opt_x; - if (endswith(filename, ".a")) return FILE_AR; - if (endswith(filename, ".o")) return FILE_OBJ; - if (endswith(filename, ".c")) return FILE_C; - if (endswith(filename, ".s")) return FILE_ASM; - if (endswith(filename, ".S")) return FILE_ASM_CPP; + if (_endswith(filename, ".a")) return FILE_AR; + if (_endswith(filename, ".o")) return FILE_OBJ; + if (_endswith(filename, ".c")) return FILE_C; + if (_endswith(filename, ".s")) return FILE_ASM; + if (_endswith(filename, ".S")) return FILE_ASM_CPP; error(": unknown file extension: %s", filename); } diff --git a/third_party/chibicc/chibicc.h b/third_party/chibicc/chibicc.h index 61d254d50..56b9362e5 100644 --- a/third_party/chibicc/chibicc.h +++ b/third_party/chibicc/chibicc.h @@ -1,7 +1,6 @@ #ifndef COSMOPOLITAN_THIRD_PARTY_CHIBICC_CHIBICC_H_ #define COSMOPOLITAN_THIRD_PARTY_CHIBICC_CHIBICC_H_ #include "libc/assert.h" -#include "libc/intrin/popcnt.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/calls/weirdtypes.h" @@ -9,21 +8,20 @@ #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/popcnt.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsf.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/crc32.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "libc/str/str.h" +#include "libc/str/unicode.h" #include "libc/time/struct/tm.h" #include "libc/time/time.h" -#include "libc/str/unicode.h" #include "libc/x/x.h" #include "third_party/gdtoa/gdtoa.h" #include "tool/build/lib/javadown.h" diff --git a/third_party/chibicc/codegen.c b/third_party/chibicc/codegen.c index 3f7bd911b..3f40de693 100644 --- a/third_party/chibicc/codegen.c +++ b/third_party/chibicc/codegen.c @@ -1,3 +1,4 @@ +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" #define GP_MAX 6 @@ -984,7 +985,7 @@ static bool gen_builtin_funcall(Node *node, const char *name) { char regprefix; gen_expr(node->args); emitlin("\tor\t$-1,%edi"); - regprefix = endswith(name, "l") ? 'r' : 'e'; + regprefix = _endswith(name, "l") ? 'r' : 'e'; println("\tbsf\t%%%cax,%%%cax", regprefix, regprefix); emitlin("\tcmovz\t%edi,%eax"); emitlin("\tinc\t%eax"); @@ -1432,7 +1433,7 @@ void gen_expr(Node *node) { case ND_FUNCALL: { const char *funcname = NULL; if (node->lhs->kind == ND_VAR) { - if (startswith(nameof(node->lhs->var), "__builtin_")) { + if (_startswith(nameof(node->lhs->var), "__builtin_")) { funcname = nameof(node->lhs->var) + 10; if (gen_builtin_funcall(node, funcname)) { return; diff --git a/third_party/chibicc/dox1.c b/third_party/chibicc/dox1.c index 19656e527..f6fcf54f0 100644 --- a/third_party/chibicc/dox1.c +++ b/third_party/chibicc/dox1.c @@ -16,10 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" #include "tool/build/lib/asmdown.h" @@ -107,15 +108,15 @@ static char *DescribeType(struct Type *ty) { case TY_LDOUBLE: return DescribeScalar(ty, "long double"); case TY_FUNC: - return xasprintf("%s(*)()", gc(DescribeType(ty->return_ty))); + return xasprintf("%s(*)()", _gc(DescribeType(ty->return_ty))); case TY_PTR: if (ty->base->kind == TY_FUNC) { return DescribeType(ty->base); } else { - return xasprintf("%s*", gc(DescribeType(ty->base))); + return xasprintf("%s*", _gc(DescribeType(ty->base))); } case TY_ARRAY: - return xasprintf("%s[%d]", gc(DescribeType(ty->base)), ty->array_len); + return xasprintf("%s[%d]", _gc(DescribeType(ty->base)), ty->array_len); case TY_ENUM: if (ty->name) { return xasprintf("enum %.*s", ty->name->len, ty->name->loc); @@ -283,7 +284,7 @@ static void LoadPublicDefinitions(struct DoxWriter *dox, Obj *prog) { if (!obj->javadown) { if (*obj->name == '_') continue; if (strchr(obj->name, '$')) continue; - if (startswith(obj->name, "__gdtoa_")) continue; + if (_startswith(obj->name, "__gdtoa_")) continue; if (obj->visibility && !strcmp(obj->visibility, "hidden")) continue; if (!obj->is_definition && (!obj->is_function || !obj->params || !obj->params->name || !*obj->params->name)) { @@ -292,7 +293,7 @@ static void LoadPublicDefinitions(struct DoxWriter *dox, Obj *prog) { } if (obj->is_static) continue; if (obj->is_string_literal) continue; - if (obj->section && startswith(obj->section, ".init_array")) continue; + if (obj->section && _startswith(obj->section, ".init_array")) continue; APPEND(dox->objects); dox->objects.p[dox->objects.n - 1] = obj; } diff --git a/third_party/chibicc/dox2.c b/third_party/chibicc/dox2.c index aef3baf57..c60bbb1e9 100644 --- a/third_party/chibicc/dox2.c +++ b/third_party/chibicc/dox2.c @@ -16,11 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/intrin/bits.h" +#include "libc/mem/alg.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" #define APPEND(L) L.p = realloc(L.p, ++L.n * sizeof(*L.p)) @@ -282,7 +283,7 @@ static int CompareDoxIndexEntry(const void *p1, const void *p2, void *arg) { static void IndexDox(struct Dox *dox) { size_t i, j, n; - dox->names.n = roundup2pow(dox->objects.n + dox->macros.n) << 1; + dox->names.n = _roundup2pow(dox->objects.n + dox->macros.n) << 1; dox->names.p = calloc(dox->names.n, sizeof(*dox->names.p)); n = 0; for (i = 0; i < dox->objects.n; ++i) { @@ -773,7 +774,7 @@ document.addEventListener('DOMContentLoaded', function () {\n\ prefix = xasprintf("%s ", o->params.p[j].name); for (k = 0; k < o->javadown->tags.n; ++k) { if (!strcmp(o->javadown->tags.p[k].tag, "param") && - startswith(o->javadown->tags.p[k].text, prefix)) { + _startswith(o->javadown->tags.p[k].text, prefix)) { fprintf(f, "
"); PrintText(f, o->javadown->tags.p[k].text + strlen(prefix)); fprintf(f, "\n"); @@ -907,7 +908,7 @@ document.addEventListener('DOMContentLoaded', function () {\n\ prefix = xasprintf("%s ", m->params.p[j].name); for (k = 0; k < m->javadown->tags.n; ++k) { if (!strcmp(m->javadown->tags.p[k].tag, "param") && - startswith(m->javadown->tags.p[k].text, prefix)) { + _startswith(m->javadown->tags.p[k].text, prefix)) { fprintf(f, "
"); PrintText(f, m->javadown->tags.p[k].text + strlen(prefix)); fprintf(f, "\n"); diff --git a/third_party/chibicc/file.c b/third_party/chibicc/file.c index d4fe8c60a..6c192d606 100644 --- a/third_party/chibicc/file.c +++ b/third_party/chibicc/file.c @@ -1,3 +1,4 @@ +#include "libc/intrin/bsf.h" #include "third_party/chibicc/chibicc.h" // Slurps contents of file. @@ -66,7 +67,7 @@ void canonicalize_newline(char *p) { p += 16; q += 16; } else { - m = bsf(m); + m = _bsf(m); memmove(q, p, m); p += m; q += m; @@ -125,7 +126,7 @@ void remove_backslash_newline(char *p) { i += 16; j += 16; } else { - m = bsf(m); + m = _bsf(m); memmove(p + j, p + i, m); i += m; j += m; diff --git a/third_party/chibicc/parse.c b/third_party/chibicc/parse.c index b9bd06d7a..cb3fea28b 100644 --- a/third_party/chibicc/parse.c +++ b/third_party/chibicc/parse.c @@ -23,6 +23,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/ffs.h" #include "libc/testlib/testlib.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" #include "third_party/chibicc/kw.h" diff --git a/third_party/chibicc/preprocess.c b/third_party/chibicc/preprocess.c index 5ef0d743f..edfe12479 100644 --- a/third_party/chibicc/preprocess.c +++ b/third_party/chibicc/preprocess.c @@ -26,6 +26,7 @@ #include "libc/mem/arena.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" #include "third_party/chibicc/kw.h" diff --git a/third_party/chibicc/pybind.c b/third_party/chibicc/pybind.c index 48bccc0b4..f4e308642 100644 --- a/third_party/chibicc/pybind.c +++ b/third_party/chibicc/pybind.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/log/libfatal.internal.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/chibicc/chibicc.h" static void AppendStringLiteral(char **b, const char *s, const char *indent) { @@ -537,7 +537,7 @@ const struct _inittab _PyImport_Inittab_%s = {\n\ };\n\ ", module, module, - tok->file->javadown ? gc(xasprintf("pb_%s_doc", module)) : "0", + tok->file->javadown ? _gc(xasprintf("pb_%s_doc", module)) : "0", module, module, module, module, module, module); CHECK_NE(-1, (fd = creat(path, 0644))); CHECK_NE(-1, xwrite(fd, b, appendz(b).i)); diff --git a/third_party/chibicc/tokenize.c b/third_party/chibicc/tokenize.c index 909d07911..b6d213837 100644 --- a/third_party/chibicc/tokenize.c +++ b/third_party/chibicc/tokenize.c @@ -1,5 +1,5 @@ +#include "libc/intrin/bsf.h" #include "libc/log/log.h" -#include "libc/nexgen32e/bsf.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "third_party/chibicc/chibicc.h" @@ -679,7 +679,7 @@ static void convert_universal_chars(char *p) { p += 16; q += 16; } else { - m = bsf(m); + m = _bsf(m); memmove(q, p, m); p += m; q += m; diff --git a/third_party/dlmalloc/dlmalloc.c b/third_party/dlmalloc/dlmalloc.c index 543256f2c..bd8a58499 100644 --- a/third_party/dlmalloc/dlmalloc.c +++ b/third_party/dlmalloc/dlmalloc.c @@ -2,11 +2,11 @@ #include "libc/calls/calls.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/likely.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/runtime/runtime.h" #include "libc/runtime/sysconf.h" @@ -696,8 +696,8 @@ void* dlmalloc(size_t bytes) { mem = sys_alloc(gm, nb); POSTACTION(gm); - if (mem == MAP_FAILED && weaken(__oom_hook)) { - weaken(__oom_hook)(bytes); + if (mem == MAP_FAILED && _weaken(__oom_hook)) { + _weaken(__oom_hook)(bytes); } return mem; @@ -919,7 +919,7 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) { if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ alignment = MIN_CHUNK_SIZE; /* alignment is 32+ bytes rounded up to nearest two power */ - alignment = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1); + alignment = 2ul << _bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1); if (bytes >= MAX_REQUEST - alignment) { if (m != 0) { /* Test isn't needed but avoids compiler warning */ MALLOC_FAILURE_ACTION; diff --git a/third_party/dlmalloc/dlmalloc.mk b/third_party/dlmalloc/dlmalloc.mk index 3a5c2e600..8119ec2b6 100644 --- a/third_party/dlmalloc/dlmalloc.mk +++ b/third_party/dlmalloc/dlmalloc.mk @@ -49,12 +49,15 @@ $(THIRD_PARTY_DLMALLOC_A).pkg: \ $(THIRD_PARTY_DLMALLOC_A_OBJS) \ $(foreach x,$(THIRD_PARTY_DLMALLOC_A_DIRECTDEPS),$($(x)_A).pkg) +ifneq ($(MODE),tiny) +ifneq ($(MODE),tinylinux) # README file recommends -O3 # It does double performance in default mode -o//third_party/dlmalloc/dlmalloc.o \ -o/rel/third_party/dlmalloc/dlmalloc.o: private \ +o/$(MODE)/third_party/dlmalloc/dlmalloc.o: private \ OVERRIDE_CFLAGS += \ -O3 +endif +endif # we can't use address sanitizer because: # address sanitizer depends on dlmalloc diff --git a/third_party/dlmalloc/dlmalloc_abort.greg.c b/third_party/dlmalloc/dlmalloc_abort.greg.c index a9fa884d3..ea75d81df 100644 --- a/third_party/dlmalloc/dlmalloc_abort.greg.c +++ b/third_party/dlmalloc/dlmalloc_abort.greg.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/calls/calls.h" +#include "libc/intrin/weaken.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -26,6 +26,6 @@ void dlmalloc_abort(void) { write(2, MESSAGE, strlen(MESSAGE)); - if (weaken(__die)) weaken(__die)(); + if (_weaken(__die)) _weaken(__die)(); _Exit(44); } diff --git a/third_party/dlmalloc/locks.inc b/third_party/dlmalloc/locks.inc index 5084a5d38..56c19072d 100644 --- a/third_party/dlmalloc/locks.inc +++ b/third_party/dlmalloc/locks.inc @@ -1,5 +1,8 @@ // clang-format off #include "third_party/nsync/mu.h" +#include "libc/atomic.h" +#include "libc/intrin/atomic.h" +#include "libc/calls/calls.h" #include "libc/thread/tls.h" /* --------------------------- Lock preliminaries ------------------------ */ @@ -32,12 +35,40 @@ */ +static int malloc_lock(atomic_int *lk) { + if (!__threaded) return 0; + while (atomic_exchange_explicit(lk, 1, memory_order_acquire)) { + sched_yield(); + } + return 0; +} + +static int malloc_trylock(atomic_int *lk) { + if (!__threaded) return 1; + return !atomic_exchange_explicit(lk, 1, memory_order_acquire); +} + +static inline int malloc_unlock(atomic_int *lk) { + atomic_store_explicit(lk, 0, memory_order_release); + return 0; +} + #if !USE_LOCKS #define USE_LOCK_BIT (0U) #define INITIAL_LOCK(l) (0) #define DESTROY_LOCK(l) (0) #define ACQUIRE_MALLOC_GLOBAL_LOCK() #define RELEASE_MALLOC_GLOBAL_LOCK() +#elif defined(TINY) +#define MLOCK_T atomic_int +#define ACQUIRE_LOCK(lk) malloc_lock(lk) +#define RELEASE_LOCK(lk) malloc_unlock(lk) +#define TRY_LOCK(lk) malloc_trylock(lk) +#define INITIAL_LOCK(lk) (*lk = 0, 0) +#define DESTROY_LOCK(lk) +#define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex); +#define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex); +static MLOCK_T malloc_global_mutex; #else #define MLOCK_T nsync_mu #define ACQUIRE_LOCK(lk) (__threaded && (nsync_mu_lock(lk), 0)) diff --git a/third_party/dlmalloc/mspaces.inc b/third_party/dlmalloc/mspaces.inc index 0ebfa7ecf..2fc5c8638 100644 --- a/third_party/dlmalloc/mspaces.inc +++ b/third_party/dlmalloc/mspaces.inc @@ -208,8 +208,8 @@ void* mspace_malloc(mspace msp, size_t bytes) { mem = sys_alloc(ms, nb); POSTACTION(ms); - if (mem == MAP_FAILED && weaken(__oom_hook)) { - weaken(__oom_hook)(bytes); + if (mem == MAP_FAILED && _weaken(__oom_hook)) { + _weaken(__oom_hook)(bytes); } return mem; diff --git a/third_party/linenoise/linenoise.c b/third_party/linenoise/linenoise.c index efc7d2506..5819c47ab 100644 --- a/third_party/linenoise/linenoise.c +++ b/third_party/linenoise/linenoise.c @@ -124,12 +124,9 @@ │ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/stat.h" #include "libc/calls/termios.h" @@ -139,21 +136,25 @@ #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/nomultics.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/nt/version.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" +#include "libc/str/unicode.h" #include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" @@ -164,7 +165,6 @@ #include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -#include "libc/str/unicode.h" #include "net/http/escape.h" #include "third_party/linenoise/linenoise.h" #include "tool/build/lib/case.h" @@ -368,7 +368,7 @@ static wint_t Capitalize(wint_t c) { static struct rune DecodeUtf8(int c) { struct rune r; if (c < 252) { - r.n = bsr(255 & ~c); + r.n = _bsr(255 & ~c); r.c = c & (((1 << r.n) - 1) | 3); r.n = 6 - r.n; } else { @@ -644,7 +644,7 @@ static void abAppendw(struct abuf *a, unsigned long long w) { p[5] = (0x0000ff0000000000 & w) >> 050; p[6] = (0x00ff000000000000 & w) >> 060; p[7] = (0xff00000000000000 & w) >> 070; - a->len += w ? (bsrll(w) >> 3) + 1 : 1; + a->len += w ? (_bsrll(w) >> 3) + 1 : 1; p[8] = 0; } @@ -1221,7 +1221,7 @@ StartOver: } else { flipit = hasflip && (i == flip[0] || i == flip[1]); if (flipit) abAppendw(&ab, READ32LE("\e[1m")); - abAppendw(&ab, tpenc(rune.c)); + abAppendw(&ab, _tpenc(rune.c)); if (flipit) abAppendw(&ab, READ64LE("\e[22m\0\0")); } t = wcwidth(rune.c); @@ -1470,7 +1470,7 @@ static void linenoiseEditXlatWord(struct linenoiseState *l, r = GetUtf8(l->buf + j, l->len - j); if (iswseparator(r.c)) break; if ((c = xlat(r.c)) != r.c) { - abAppendw(&ab, tpenc(c)); + abAppendw(&ab, _tpenc(c)); } else { /* avoid canonicalization */ abAppend(&ab, l->buf + j, r.n); } @@ -1634,7 +1634,7 @@ static size_t linenoiseEscape(char *d, const char *s, size_t n) { break; } WRITE32LE(p, w); - p += (bsr(w) >> 3) + 1; + p += (_bsr(w) >> 3) + 1; l = w; } return p - d; @@ -1724,7 +1724,7 @@ static void linenoiseEditBarf(struct linenoiseState *l) { /* now move the text */ r = GetUtf8(l->buf + end, l->len - end); memmove(l->buf + pos + r.n, l->buf + pos, end - pos); - w = tpenc(r.c); + w = _tpenc(r.c); for (i = 0; i < r.n; ++i) { l->buf[pos + i] = w; w >>= 8; @@ -2238,7 +2238,7 @@ ssize_t linenoiseEdit(struct linenoiseState *l, const char *prompt, char **obuf, uint64_t w; struct rune rune; rune = GetUtf8(seq, rc); - w = tpenc(xlatCallback(rune.c)); + w = _tpenc(xlatCallback(rune.c)); rc = 0; do { seq[rc++] = w; @@ -2383,7 +2383,7 @@ char *linenoiseGetHistoryPath(const char *prog) { if (*a) { abAppends(&path, a); abAppends(&path, b); - if (!endswith(path.b, "/") && !endswith(path.b, "\\")) { + if (!_endswith(path.b, "/") && !_endswith(path.b, "\\")) { abAppendw(&path, '/'); } } diff --git a/third_party/lua/ldo.c b/third_party/lua/ldo.c index 0412dc463..0fb2068db 100644 --- a/third_party/lua/ldo.c +++ b/third_party/lua/ldo.c @@ -29,7 +29,7 @@ #define LUA_CORE #include "libc/intrin/weaken.h" #include "libc/log/log.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -153,9 +153,8 @@ l_noret luaD_throw (lua_State *L, int errcode) { lua_unlock(L); g->panic(L); /* call panic function (last chance to jump out) */ } - if (weaken(__die)) weaken(__die)(); - __restorewintty(); - _Exit(41); + if (_weaken(__die)) _weaken(__die)(); + _Exitr(41); } } } diff --git a/third_party/lua/lobject.h b/third_party/lua/lobject.h index 2f784103d..af5c03956 100644 --- a/third_party/lua/lobject.h +++ b/third_party/lua/lobject.h @@ -1,7 +1,7 @@ #ifndef lobject_h #define lobject_h -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "third_party/lua/llimits.h" #include "third_party/lua/lua.h" @@ -786,7 +786,7 @@ LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen); ** Computes ceil(log2(x)) */ static inline int luaO_ceillog2 (unsigned int x) { - return --x ? bsr(x) + 1 : 0; + return --x ? _bsr(x) + 1 : 0; } #endif diff --git a/third_party/lua/lrepl.c b/third_party/lua/lrepl.c index 1a47d135c..904ba642c 100644 --- a/third_party/lua/lrepl.c +++ b/third_party/lua/lrepl.c @@ -26,20 +26,20 @@ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #define lua_c -#include "libc/mem/alg.h" #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" #include "libc/errno.h" #include "libc/intrin/nomultics.internal.h" -#include "libc/thread/thread.h" #include "libc/log/check.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/sa.h" +#include "libc/thread/thread.h" #include "third_party/linenoise/linenoise.h" #include "third_party/lua/cosmo.h" #include "third_party/lua/lauxlib.h" @@ -148,7 +148,7 @@ void lua_readline_completions (const char *p, linenoiseCompletions *c) { while (lua_next(L, -2)) { if (lua_type(L, -2) == LUA_TSTRING) { name = lua_tolstring(L, -2, &n); - if (startswithi(name, a) && (s = malloc(a - p + n + 1))) { + if (_startswithi(name, a) && (s = malloc(a - p + n + 1))) { memcpy(s, p, a - p); memcpy(s + (a - p), name, n + 1); lua_readline_addcompletion(c, s); @@ -161,7 +161,7 @@ void lua_readline_completions (const char *p, linenoiseCompletions *c) { lua_pop(L, 1); // pop table for (i = 0; i < ARRAYLEN(kKeywordHints); ++i) { - if (startswithi(kKeywordHints[i], p)) { + if (_startswithi(kKeywordHints[i], p)) { if ((s = strdup(kKeywordHints[i]))) { lua_readline_addcompletion(c, s); } diff --git a/third_party/lua/lua.main.c b/third_party/lua/lua.main.c index 3be1c32c3..066721690 100644 --- a/third_party/lua/lua.main.c +++ b/third_party/lua/lua.main.c @@ -31,7 +31,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/log/log.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/stack.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" diff --git a/third_party/lua/luaencodejsondata.c b/third_party/lua/luaencodejsondata.c index aa316e610..2186a755e 100644 --- a/third_party/lua/luaencodejsondata.c +++ b/third_party/lua/luaencodejsondata.c @@ -23,9 +23,9 @@ #include "libc/log/log.h" #include "libc/log/rop.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/stack.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/strlist.internal.h" #include "libc/str/str.h" #include "net/http/escape.h" diff --git a/third_party/lua/luaencodeluadata.c b/third_party/lua/luaencodeluadata.c index d9db838b6..a280222a0 100644 --- a/third_party/lua/luaencodeluadata.c +++ b/third_party/lua/luaencodeluadata.c @@ -23,7 +23,7 @@ #include "libc/math.h" #include "libc/mem/mem.h" #include "libc/runtime/stack.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/strlist.internal.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/third_party/lua/luaformatstack.c b/third_party/lua/luaformatstack.c index 1c274de6f..374f6f9db 100644 --- a/third_party/lua/luaformatstack.c +++ b/third_party/lua/luaformatstack.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "third_party/lua/cosmo.h" #include "third_party/lua/lauxlib.h" diff --git a/third_party/lua/lunix.c b/third_party/lua/lunix.c index ce2d4cc2a..29d19c7f9 100644 --- a/third_party/lua/lunix.c +++ b/third_party/lua/lunix.c @@ -21,13 +21,13 @@ #include "libc/calls/ioctl.h" #include "libc/calls/makedev.h" #include "libc/calls/pledge.h" -#include "libc/calls/strace.internal.h" #include "libc/calls/struct/bpf.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/flock.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/rlimit.h" #include "libc/calls/struct/rusage.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/stat.h" @@ -43,6 +43,7 @@ #include "libc/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/bits.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/fmt.h" @@ -56,9 +57,8 @@ #include "libc/sock/struct/linger.h" #include "libc/sock/struct/pollfd.h" #include "libc/sock/syslog.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/path.h" #include "libc/str/str.h" #include "libc/sysv/consts/af.h" @@ -2589,11 +2589,11 @@ static int LuaUnixErrnoWinerr(lua_State *L) { } static int LuaUnixErrnoName(lua_State *L) { - return ReturnString(L, strerrno(GetUnixErrno(L)->errno_)); + return ReturnString(L, _strerrno(GetUnixErrno(L)->errno_)); } static int LuaUnixErrnoDoc(lua_State *L) { - return ReturnString(L, strerdoc(GetUnixErrno(L)->errno_)); + return ReturnString(L, _strerdoc(GetUnixErrno(L)->errno_)); } static int LuaUnixErrnoCall(lua_State *L) { @@ -2608,7 +2608,7 @@ static int LuaUnixErrnoToString(lua_State *L) { strerror_wr(e->errno_, e->winerr, msg, sizeof(msg)); lua_pushfstring(L, "%s() failed: %s", e->call, msg); } else { - lua_pushstring(L, strerrno(e->errno_)); + lua_pushstring(L, _strerrno(e->errno_)); } return 1; } diff --git a/third_party/lua/serialize.c b/third_party/lua/serialize.c index dfffe5ccc..bf0302346 100644 --- a/third_party/lua/serialize.c +++ b/third_party/lua/serialize.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/rop.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "third_party/lua/cosmo.h" #include "third_party/lua/lua.h" diff --git a/third_party/make/hash.c b/third_party/make/hash.c index 7023cdc69..798edb5a6 100644 --- a/third_party/make/hash.c +++ b/third_party/make/hash.c @@ -18,9 +18,9 @@ this program. If not, see . */ /**/ #include "libc/assert.h" #include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/likely.h" #include "libc/log/check.h" -#include "libc/nexgen32e/bsr.h" #include "third_party/make/hash.h" /* clang-format off */ @@ -322,7 +322,7 @@ static unsigned long round_up_2 (unsigned long n) { if (UNLIKELY(!n)) return 1; - return 2ul << bsrl(n); + return 2ul << _bsrl(n); } #define rol32(v, n) \ diff --git a/third_party/make/job.c b/third_party/make/job.c index 914f716a0..aa98d54c9 100644 --- a/third_party/make/job.c +++ b/third_party/make/job.c @@ -386,7 +386,7 @@ parse_bool (const char *s) ++s; if (isdigit (*s)) return !! atoi (s); - return startswithi (s, "true"); + return _startswithi (s, "true"); } const char * diff --git a/third_party/mbedtls/bigmul.c b/third_party/mbedtls/bigmul.c index 0ad521491..479241d7e 100644 --- a/third_party/mbedtls/bigmul.c +++ b/third_party/mbedtls/bigmul.c @@ -20,7 +20,6 @@ #include "libc/log/check.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/x86feature.h" #include "third_party/mbedtls/bignum.h" #include "third_party/mbedtls/bignum_internal.h" diff --git a/third_party/mbedtls/bignum.c b/third_party/mbedtls/bignum.c index 756334edc..71f11a2ad 100644 --- a/third_party/mbedtls/bignum.c +++ b/third_party/mbedtls/bignum.c @@ -22,7 +22,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsf.h" +#include "libc/intrin/bsf.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/runtime.h" diff --git a/third_party/mbedtls/des.c b/third_party/mbedtls/des.c index 8a206bf77..274150156 100644 --- a/third_party/mbedtls/des.c +++ b/third_party/mbedtls/des.c @@ -16,7 +16,7 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "third_party/mbedtls/common.h" diff --git a/third_party/mbedtls/ecp.c b/third_party/mbedtls/ecp.c index 26d205ed7..4a6f234aa 100644 --- a/third_party/mbedtls/ecp.c +++ b/third_party/mbedtls/ecp.c @@ -15,7 +15,7 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" diff --git a/third_party/mbedtls/ecp256.c b/third_party/mbedtls/ecp256.c index 9627cc325..b79c11cbb 100644 --- a/third_party/mbedtls/ecp256.c +++ b/third_party/mbedtls/ecp256.c @@ -19,7 +19,7 @@ #include "libc/assert.h" #include "libc/log/check.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "third_party/mbedtls/bignum_internal.h" diff --git a/third_party/mbedtls/ecp384.c b/third_party/mbedtls/ecp384.c index 52da20af9..5a1da4354 100644 --- a/third_party/mbedtls/ecp384.c +++ b/third_party/mbedtls/ecp384.c @@ -20,7 +20,7 @@ #include "libc/intrin/asan.internal.h" #include "libc/log/check.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "third_party/mbedtls/bignum_internal.h" diff --git a/third_party/mbedtls/formatclientciphers.c b/third_party/mbedtls/formatclientciphers.c index 0d8bcef01..9a8f7cc42 100644 --- a/third_party/mbedtls/formatclientciphers.c +++ b/third_party/mbedtls/formatclientciphers.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/macros.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "third_party/mbedtls/iana.h" /** diff --git a/third_party/mbedtls/rsa.c b/third_party/mbedtls/rsa.c index cac5d2afa..d510a80c1 100644 --- a/third_party/mbedtls/rsa.c +++ b/third_party/mbedtls/rsa.c @@ -15,7 +15,7 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" #include "third_party/mbedtls/common.h" diff --git a/third_party/mbedtls/test/lib.c b/third_party/mbedtls/test/lib.c index 82d3fbe0a..46d4ea902 100644 --- a/third_party/mbedtls/test/lib.c +++ b/third_party/mbedtls/test/lib.c @@ -31,14 +31,14 @@ #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/nr.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/mbedtls/config.h" #include "third_party/mbedtls/endian.h" #include "third_party/mbedtls/error.h" diff --git a/third_party/mbedtls/test/lib.h b/third_party/mbedtls/test/lib.h index 9edc2925d..9c6e1576a 100644 --- a/third_party/mbedtls/test/lib.h +++ b/third_party/mbedtls/test/lib.h @@ -1,8 +1,9 @@ #ifndef COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TEST_LIB_H_ #define COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TEST_LIB_H_ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/mbedtls/config.h" #include "third_party/mbedtls/platform.h" diff --git a/third_party/musl/crypt_blowfish.c b/third_party/musl/crypt_blowfish.c index 597e402b8..dc493a506 100644 --- a/third_party/musl/crypt_blowfish.c +++ b/third_party/musl/crypt_blowfish.c @@ -29,7 +29,7 @@ #include "libc/limits.h" #include "libc/literal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "third_party/musl/crypt.internal.h" diff --git a/third_party/nsync/futex.c b/third_party/nsync/futex.c index cc875abbe..c7be2127b 100644 --- a/third_party/nsync/futex.c +++ b/third_party/nsync/futex.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/third_party/nsync/malloc.c b/third_party/nsync/malloc.c index 65708ddfe..c4e681c88 100644 --- a/third_party/nsync/malloc.c +++ b/third_party/nsync/malloc.c @@ -17,9 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/atomic.h" -#include "libc/calls/extend.internal.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/extend.internal.h" #include "libc/macros.internal.h" +#include "libc/runtime/memtrack.internal.h" #include "third_party/nsync/common.internal.h" #include "third_party/nsync/malloc.internal.h" // clang-format off @@ -40,10 +41,11 @@ void *nsync_malloc_ (size_t size) { while (atomic_exchange (&nsync_malloc_lock_, 1)) nsync_yield_ (); offset = nsync_malloc_total_; nsync_malloc_total_ += size; - start = (char *) 0x6fc000040000; + start = (char *) kMemtrackNsyncStart; if (!nsync_malloc_endptr_) nsync_malloc_endptr_ = start; - nsync_malloc_endptr_ = _extend (start, nsync_malloc_total_, - nsync_malloc_endptr_, 0x6fcfffff0000); + nsync_malloc_endptr_ = + _extend (start, nsync_malloc_total_, nsync_malloc_endptr_, + kMemtrackNsyncStart + kMemtrackNsyncSize); atomic_store_explicit (&nsync_malloc_lock_, 0, memory_order_relaxed); return start + offset; } diff --git a/third_party/nsync/mu.h b/third_party/nsync/mu.h index 8d72fea6c..600fc8770 100644 --- a/third_party/nsync/mu.h +++ b/third_party/nsync/mu.h @@ -50,6 +50,7 @@ struct nsync_dll_element_s_; */ typedef struct nsync_mu_s_ { nsync_atomic_uint32_ word; /* internal use only */ + int _zero; /* c pthread_mutex_t */ struct nsync_dll_element_s_ *waiters; /* internal use only */ } nsync_mu; diff --git a/third_party/nsync/yield.c b/third_party/nsync/yield.c index b6183a85c..bf7081c66 100644 --- a/third_party/nsync/yield.c +++ b/third_party/nsync/yield.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "third_party/nsync/common.internal.h" // clang-format off diff --git a/third_party/python/Modules/_decimal/libmpdec/transpose.c b/third_party/python/Modules/_decimal/libmpdec/transpose.c index 92937a035..86d66e3c5 100644 --- a/third_party/python/Modules/_decimal/libmpdec/transpose.c +++ b/third_party/python/Modules/_decimal/libmpdec/transpose.c @@ -28,7 +28,7 @@ │ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "third_party/python/Modules/_decimal/libmpdec/bits.h" #include "third_party/python/Modules/_decimal/libmpdec/constants.h" #include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h" diff --git a/third_party/python/Modules/getpath.c b/third_party/python/Modules/getpath.c index 837f33dbd..eb5b6b62a 100644 --- a/third_party/python/Modules/getpath.c +++ b/third_party/python/Modules/getpath.c @@ -11,7 +11,7 @@ #include "libc/log/log.h" #include "libc/mem/alloca.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/auxv.h" diff --git a/third_party/python/Modules/posixmodule.c b/third_party/python/Modules/posixmodule.c index 2602f2e83..52f1919ac 100644 --- a/third_party/python/Modules/posixmodule.c +++ b/third_party/python/Modules/posixmodule.c @@ -11,6 +11,7 @@ #include "libc/calls/makedev.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/iovec.h" +#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/stat.macros.h" #include "libc/calls/struct/statvfs.h" @@ -25,9 +26,9 @@ #include "libc/calls/weirdtypes.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/weaken.h" #include "libc/log/log.h" #include "libc/mem/alg.h" +#include "libc/mem/gc.internal.h" #include "libc/nt/createfile.h" #include "libc/nt/dll.h" #include "libc/nt/enum/creationdisposition.h" @@ -36,7 +37,6 @@ #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/runtime/dlfcn.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/pathconf.h" #include "libc/runtime/sysconf.h" #include "libc/sock/sendfile.internal.h" diff --git a/third_party/python/Modules/selectmodule.c b/third_party/python/Modules/selectmodule.c index c3739eba5..9ca8067a9 100644 --- a/third_party/python/Modules/selectmodule.c +++ b/third_party/python/Modules/selectmodule.c @@ -9,7 +9,7 @@ #include "libc/errno.h" #include "libc/mem/mem.h" #include "libc/nt/efi.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/sock/epoll.h" #include "libc/sock/select.h" #include "libc/sock/sock.h" diff --git a/third_party/python/Modules/tlsmodule.c b/third_party/python/Modules/tlsmodule.c index 2d4d21399..34ae88c2d 100644 --- a/third_party/python/Modules/tlsmodule.c +++ b/third_party/python/Modules/tlsmodule.c @@ -20,7 +20,7 @@ #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "net/https/https.h" #include "third_party/mbedtls/ctr_drbg.h" diff --git a/third_party/python/Modules/unicodedata.c b/third_party/python/Modules/unicodedata.c index 156137906..6ebaf7a30 100644 --- a/third_party/python/Modules/unicodedata.c +++ b/third_party/python/Modules/unicodedata.c @@ -5,8 +5,8 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #define PY_SSIZE_T_CLEAN -#include "libc/intrin/bits.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/bits.h" #include "libc/nexgen32e/kompressor.h" #include "third_party/python/Include/floatobject.h" #include "third_party/python/Include/import.h" @@ -405,7 +405,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr) /* high byte is number of hex bytes (usually one or two), low byte is prefix code (from*/ - count = bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8; + count = _bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8; /* XXX: could allocate the PyString up front instead (strlen(prefix) + 5 * count + 1 bytes) */ @@ -413,7 +413,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr) /* Based on how index is calculated above and _PyUnicode_Decomp is generated from Tools/unicode/makeunicodedata.py, it should not be possible to overflow _PyUnicode_DecompPrefix. */ - prefix_index = bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255; + prefix_index = _bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255; assert(prefix_index < Py_ARRAY_LENGTH(_PyUnicode_DecompPrefix)); /* copy prefix */ @@ -425,8 +425,8 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr) decomp[i++] = ' '; assert(i < sizeof(decomp)); PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X", - bextra(_PyUnicode_Decomp, ++index, - _PyUnicode_DecompBits)); + _bextra(_PyUnicode_Decomp, ++index, + _PyUnicode_DecompBits)); i += strlen(decomp + i); } return PyUnicode_FromStringAndSize(decomp, i); diff --git a/third_party/python/Modules/unicodedata_getcode.c b/third_party/python/Modules/unicodedata_getcode.c index 52d027bce..d6fcebe4e 100644 --- a/third_party/python/Modules/unicodedata_getcode.c +++ b/third_party/python/Modules/unicodedata_getcode.c @@ -4,8 +4,8 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/bits.h" #include "third_party/python/Include/pyctype.h" #include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pymacro.h" @@ -174,7 +174,7 @@ _PyUnicode_GetCode(PyObject *self, const char *name, int namelen, Py_UCS4 *code, details */ h = (unsigned int)_gethash(name, namelen, _PyUnicode_CodeMagic); i = ~h & mask; - v = bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); + v = _bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); if (!v) return 0; if (_cmpname(self, v, name, namelen)) @@ -184,7 +184,7 @@ _PyUnicode_GetCode(PyObject *self, const char *name, int namelen, Py_UCS4 *code, incr = mask; for (;;) { i = (i + incr) & mask; - v = bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); + v = _bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); if (!v) return 0; if (_cmpname(self, v, name, namelen)) @@ -247,10 +247,10 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen, } /* get offset into phrasebook */ offset = _PyUnicode_PhrasebookOffset1[(code>>_PyUnicode_PhrasebookShift)]; - offset = bextra(_PyUnicode_PhrasebookOffset2, - (offset << _PyUnicode_PhrasebookShift) + - (code & ((1 << _PyUnicode_PhrasebookShift) - 1)), - _PyUnicode_PhrasebookOffset2Bits); + offset = _bextra(_PyUnicode_PhrasebookOffset2, + (offset << _PyUnicode_PhrasebookShift) + + (code & ((1 << _PyUnicode_PhrasebookShift) - 1)), + _PyUnicode_PhrasebookOffset2Bits); if (!offset) return 0; i = 0; @@ -271,8 +271,8 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen, word has bit 7 set. the last word in a string ends with 0x80 */ w = (_PyUnicode_Lexicon + - bextra(_PyUnicode_LexiconOffset, word, - _PyUnicode_LexiconOffsetBits)); + _bextra(_PyUnicode_LexiconOffset, word, + _PyUnicode_LexiconOffsetBits)); while (*w < 128) { if (i >= buflen) return 0; /* buffer overflow */ diff --git a/third_party/python/Modules/unicodedata_getdecomprecord.c b/third_party/python/Modules/unicodedata_getdecomprecord.c index de741665a..8e8ba1a47 100644 --- a/third_party/python/Modules/unicodedata_getdecomprecord.c +++ b/third_party/python/Modules/unicodedata_getdecomprecord.c @@ -31,7 +31,7 @@ _PyUnicode_GetDecompRecord(PyObject *self, } /* high byte is number of hex bytes (usually one or two), low byte is prefix code (from*/ - decomp = bextra(_PyUnicode_Decomp, *index, _PyUnicode_DecompBits); + decomp = _bextra(_PyUnicode_Decomp, *index, _PyUnicode_DecompBits); *count = decomp >> 8; *prefix = decomp & 255; (*index)++; diff --git a/third_party/python/Modules/unicodedata_nfcnfkc.c b/third_party/python/Modules/unicodedata_nfcnfkc.c index 1de589140..5ccebd16d 100644 --- a/third_party/python/Modules/unicodedata_nfcnfkc.c +++ b/third_party/python/Modules/unicodedata_nfcnfkc.c @@ -115,10 +115,10 @@ _PyUnicode_NfcNfkc(PyObject *self, PyObject *input, int k) } index = f * UNIDATA_TOTAL_LAST + l; index1 = _PyUnicode_CompIndex[index >> _PyUnicode_CompShift]; - code = bextra(_PyUnicode_CompData, - (index1 << _PyUnicode_CompShift)+ - (index & ((1 << _PyUnicode_CompShift) - 1)), - _PyUnicode_CompDataBits); + code = _bextra(_PyUnicode_CompData, + (index1 << _PyUnicode_CompShift)+ + (index & ((1 << _PyUnicode_CompShift) - 1)), + _PyUnicode_CompDataBits); if (code == 0) goto not_combinable; /* Replace the original character. */ diff --git a/third_party/python/Modules/unicodedata_nfdnfkd.c b/third_party/python/Modules/unicodedata_nfdnfkd.c index 81fe4f822..03db44c83 100644 --- a/third_party/python/Modules/unicodedata_nfdnfkd.c +++ b/third_party/python/Modules/unicodedata_nfdnfkd.c @@ -97,9 +97,9 @@ _PyUnicode_NfdNfkd(PyObject *self, PyObject *input, int k) /* Copy decomposition onto the stack, in reverse order. */ while(count) { - code = bextra(_PyUnicode_Decomp, - index + (--count), - _PyUnicode_DecompBits); + code = _bextra(_PyUnicode_Decomp, + index + (--count), + _PyUnicode_DecompBits); stack[stackptr++] = code; } } diff --git a/third_party/python/Objects/listobject.c b/third_party/python/Objects/listobject.c index bb7e83d02..8ee457727 100644 --- a/third_party/python/Objects/listobject.c +++ b/third_party/python/Objects/listobject.c @@ -6,7 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/accu.h" #include "third_party/python/Include/boolobject.h" diff --git a/third_party/python/Objects/unicodeobject.c b/third_party/python/Objects/unicodeobject.c index 99b53d570..30893b657 100644 --- a/third_party/python/Objects/unicodeobject.c +++ b/third_party/python/Objects/unicodeobject.c @@ -6,10 +6,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #define PY_SSIZE_T_CLEAN #include "libc/assert.h" -#include "libc/intrin/likely.h" -#include "libc/intrin/weaken.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/likely.h" +#include "libc/intrin/weaken.h" #include "libc/log/countbranch.h" #include "libc/str/str.h" #include "third_party/python/Include/abstract.h" @@ -6029,7 +6029,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s, /* \N{name} */ case 'N': - if (!weaken(_PyUnicode_GetCode)) { + if (!_weaken(_PyUnicode_GetCode)) { PyErr_SetString( PyExc_UnicodeError, "\\N escapes not supported " @@ -6049,7 +6049,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s, s++; ch = 0xffffffff; /* in case 'getcode' messes up */ if (namelen <= INT_MAX && - weaken(_PyUnicode_GetCode)(NULL, start, (int)namelen, &ch, 0)) { + _weaken(_PyUnicode_GetCode)(NULL, start, (int)namelen, &ch, 0)) { assert(ch <= MAX_UNICODE); WRITE_CHAR(ch); continue; diff --git a/third_party/python/Parser/node.c b/third_party/python/Parser/node.c index a0cce63bc..ce8372a9d 100644 --- a/third_party/python/Parser/node.c +++ b/third_party/python/Parser/node.c @@ -5,7 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "third_party/python/Include/errcode.h" #include "third_party/python/Include/node.h" #include "third_party/python/Include/objimpl.h" @@ -32,7 +32,7 @@ fancy_roundup(int x) /* Round up to the closest power of 2 >= n. */ int r; assert(x > 128); - r = 1u << (bsr(x - 1) + 1); /* hacker's delight */ + r = 1u << (_bsr(x - 1) + 1); /* hacker's delight */ return r > 0 ? r : -1; } diff --git a/third_party/python/Python/codecs.c b/third_party/python/Python/codecs.c index 2766ce93f..7d21b6a4d 100644 --- a/third_party/python/Python/codecs.c +++ b/third_party/python/Python/codecs.c @@ -1009,14 +1009,14 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc) return NULL; for (i = start, ressize = 0; i < end; ++i) { /* object is guaranteed to be "ready" */ - if (!weaken(_PyUnicode_GetUcName)) { + if (!_weaken(_PyUnicode_GetUcName)) { PyErr_SetString( PyExc_UnicodeError, "_PyUnicode_GetUcName() not available"); return NULL; } c = PyUnicode_READ_CHAR(object, i); - if (weaken(_PyUnicode_GetUcName)(NULL, c, buffer, sizeof(buffer), 1)) { + if (_weaken(_PyUnicode_GetUcName)(NULL, c, buffer, sizeof(buffer), 1)) { replsize = 1+1+1+(int)strlen(buffer)+1; } else if (c >= 0x10000) { diff --git a/third_party/python/Python/fatality.c b/third_party/python/Python/fatality.c index db61ba09c..823218987 100644 --- a/third_party/python/Python/fatality.c +++ b/third_party/python/Python/fatality.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/weaken.h" #include "libc/log/log.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/pyerrors.h" @@ -159,6 +160,6 @@ exit: #if defined(MS_WINDOWS) && defined(_DEBUG) DebugBreak(); #endif - if (weaken(__die)) weaken(__die)(); + if (_weaken(__die)) _weaken(__die)(); abort(); } diff --git a/third_party/python/Python/getcopyright.c b/third_party/python/Python/getcopyright.c index 854fe3b8b..20456f185 100644 --- a/third_party/python/Python/getcopyright.c +++ b/third_party/python/Python/getcopyright.c @@ -4,9 +4,9 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/intrin/cmpxchg.h" -#include "libc/stdio/append.internal.h" +#include "libc/intrin/weaken.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #include "third_party/python/Include/pylifecycle.h" /* clang-format off */ @@ -32,7 +32,7 @@ Py_GetCopyright(void) static char *res; if (_cmpxchg(&once, 0, 1)) { appends(&res, ""); - for (p = *weaken(kLegalNotices); *p; p += strlen(p) + 1) { + for (p = *_weaken(kLegalNotices); *p; p += strlen(p) + 1) { appends(&res, p); } } diff --git a/third_party/python/Python/import.c b/third_party/python/Python/import.c index 3c968d833..13f8c2fc5 100644 --- a/third_party/python/Python/import.c +++ b/third_party/python/Python/import.c @@ -4,15 +4,15 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.macros.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/s.h" #include "libc/x/x.h" @@ -887,7 +887,7 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, // cpathobj != NULL means cpathname != NULL size_t cpathlen = strlen(cpathname); char *pathname2 = _gc(strdup(cpathname)); - if (endswith(pathname2, ".pyc")) + if (_endswith(pathname2, ".pyc")) { pathname2[cpathlen-2] = '\0'; // so now ends with .py if(!stat(pathname2, &stinfo) && (stinfo.st_mode & S_IFMT) == S_IFREG) @@ -2370,7 +2370,7 @@ static PyObject *_imp_source_from_cache(PyObject *module, PyObject *arg) { Py_ssize_t pathlen = 0; if (!PyArg_Parse(PyOS_FSPath(arg), "z#:source_from_cache", &path, &pathlen)) return NULL; - if (!path || !endswith(path, ".pyc")) { + if (!path || !_endswith(path, ".pyc")) { PyErr_Format(PyExc_ValueError, "%s does not end in .pyc", path); return NULL; } @@ -2666,7 +2666,7 @@ static PyObject *SFLObject_is_package(SourcelessFileLoader *self, self->name, name); return NULL; } - if (startswith(basename(self->path), "__init__")) { + if (_startswith(basename(self->path), "__init__")) { Py_RETURN_TRUE; } Py_RETURN_FALSE; diff --git a/third_party/python/Python/marshal.c b/third_party/python/Python/marshal.c index fd6feda8b..91d30331c 100644 --- a/third_party/python/Python/marshal.c +++ b/third_party/python/Python/marshal.c @@ -9,7 +9,7 @@ #include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/boolobject.h" #include "third_party/python/Include/code.h" diff --git a/third_party/python/Python/sysmodule.c b/third_party/python/Python/sysmodule.c index 4537c638c..9a1355244 100644 --- a/third_party/python/Python/sysmodule.c +++ b/third_party/python/Python/sysmodule.c @@ -9,7 +9,7 @@ #include "libc/mem/mem.h" #include "libc/nt/dll.h" #include "libc/nt/version.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/locale.h" diff --git a/third_party/python/Tools/unicode/makecjkcodecs.c b/third_party/python/Tools/unicode/makecjkcodecs.c index 904faea35..81968d27d 100644 --- a/third_party/python/Tools/unicode/makecjkcodecs.c +++ b/third_party/python/Tools/unicode/makecjkcodecs.c @@ -21,7 +21,7 @@ #include "libc/log/check.h" #include "libc/nexgen32e/crc32.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/x/x.h" #include "third_party/zlib/zlib.h" diff --git a/third_party/python/pycomp.c b/third_party/python/pycomp.c index fca5985e6..0a39710b9 100644 --- a/third_party/python/pycomp.c +++ b/third_party/python/pycomp.c @@ -24,10 +24,11 @@ #include "libc/intrin/bits.h" #include "libc/log/check.h" #include "libc/log/log.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/o.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/getopt/getopt.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/compile.h" @@ -119,15 +120,15 @@ main(int argc, char *argv[]) GetOpts(argc, argv); marshalled = 0; if (stat(inpath, &st) == -1) perror(inpath), exit(1); - CHECK_NOTNULL((p = gc(xslurp(inpath, &n)))); + CHECK_NOTNULL((p = _gc(xslurp(inpath, &n)))); Py_NoUserSiteDirectory++; Py_NoSiteFlag++; Py_IgnoreEnvironmentFlag++; Py_FrozenFlag++; /* Py_VerboseFlag++; */ - Py_SetProgramName(gc(utf8to32(argv[0], -1, 0))); + Py_SetProgramName(_gc(utf8to32(argv[0], -1, 0))); _Py_InitializeEx_Private(1, 0); - name = gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3))); + name = _gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3))); code = Py_CompileStringExFlags(p, name, Py_file_input, NULL, optimize); if (!code) goto error; marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION); diff --git a/third_party/python/pyobj.c b/third_party/python/pyobj.c index d17783441..f0b2dcc3c 100644 --- a/third_party/python/pyobj.c +++ b/third_party/python/pyobj.c @@ -17,19 +17,19 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/stat.h" #include "libc/elf/def.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/clock.h" #include "libc/sysv/consts/o.h" @@ -354,7 +354,7 @@ GetModName(bool *ispkg) { char *mod; mod = Dotify(xstripexts(StripComponents(pyfile, strip_components))); - if ((*ispkg = endswith(mod, ".__init__"))) { + if ((*ispkg = _endswith(mod, ".__init__"))) { mod[strlen(mod) - strlen(".__init__")] = 0; } return mod; @@ -385,7 +385,7 @@ GetParent2(void) { char *p, *mod; mod = Dotify(xstripexts(StripComponents(pyfile, strip_components))); - if (endswith(mod, ".__init__")) mod[strlen(mod) - strlen(".__init__")] = 0; + if (_endswith(mod, ".__init__")) mod[strlen(mod) - strlen(".__init__")] = 0; if ((p = strrchr(mod, '.'))) *p = 0; return mod; } diff --git a/third_party/python/runpythonmodule.c b/third_party/python/runpythonmodule.c index b54ea0350..d40daeb01 100644 --- a/third_party/python/runpythonmodule.c +++ b/third_party/python/runpythonmodule.c @@ -18,8 +18,8 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" #include "libc/stdio/stdio.h" @@ -30,6 +30,7 @@ #include "libc/sysv/consts/sig.h" #include "libc/time/time.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/linenoise/linenoise.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/ceval.h" @@ -95,7 +96,7 @@ CompleteModule(const char *s, const char *p, linenoiseCompletions *c) PyObject *m, *f, *g, *i, *v, *n; plen = strlen(p); for (it = PyImport_Inittab; it->name; ++it) { - if (startswithi(it->name, p)) { + if (_startswithi(it->name, p)) { AddCompletion(c, xasprintf("%s%s", s, it->name + plen)); } } @@ -169,7 +170,7 @@ Complete(const char *p, linenoiseCompletions *c) { PyObject *o, *t, *i; const char *q, *s, *b; - if (startswith(p, "import ")) { + if (_startswith(p, "import ")) { for (q = p + 7; *q; ++q) { if (!isalnum(*q) && *q != '_') { return; @@ -279,7 +280,7 @@ RunPythonModule(int argc, char **argv) int i, res; char *oldloc; - if (argc == 1 && weaken(kLaunchPythonModuleName)) { + if (argc == 1 && _weaken(kLaunchPythonModuleName)) { launchargs[0] = argv[0]; launchargs[1] = strdup("-m"); launchargs[2] = strdup(kLaunchPythonModuleName); diff --git a/third_party/quickjs/call.c b/third_party/quickjs/call.c index 4c293df77..22fccd578 100644 --- a/third_party/quickjs/call.c +++ b/third_party/quickjs/call.c @@ -24,7 +24,7 @@ */ #include "libc/assert.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "third_party/quickjs/internal.h" diff --git a/third_party/quickjs/qjsc.c b/third_party/quickjs/qjsc.c index 885f0b2ee..2bdc46b50 100644 --- a/third_party/quickjs/qjsc.c +++ b/third_party/quickjs/qjsc.c @@ -23,13 +23,15 @@ */ #include "libc/assert.h" #include "libc/calls/calls.h" +#include "libc/dce.h" #include "libc/fmt/fmt.h" #include "libc/log/log.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/gdtoa/gdtoa.h" #include "third_party/getopt/getopt.h" #include "third_party/quickjs/cutils.h" @@ -477,7 +479,7 @@ int main(int argc, char **argv) { int c, i, verbose; const char *out_filename, *cname; - char *cfilename = gc(malloc(1024)); + char *cfilename = _gc(malloc(1024)); FILE *fo; JSRuntime *rt; JSContext *ctx; diff --git a/third_party/quickjs/quickjs.c b/third_party/quickjs/quickjs.c index d33853700..542f8b309 100644 --- a/third_party/quickjs/quickjs.c +++ b/third_party/quickjs/quickjs.c @@ -47,6 +47,7 @@ #include "third_party/quickjs/internal.h" #include "libc/str/str.h" #include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" #include "third_party/quickjs/libbf.h" asm(".ident\t\"\\n\\n\ diff --git a/third_party/quickjs/run-test262.c b/third_party/quickjs/run-test262.c index 0ce7d24da..af5292f79 100644 --- a/third_party/quickjs/run-test262.c +++ b/third_party/quickjs/run-test262.c @@ -22,13 +22,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "libc/mem/alg.h" #include "libc/calls/struct/stat.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/log/log.h" +#include "libc/mem/alg.h" #include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/clock.h" #include "libc/time/time.h" diff --git a/third_party/sed/compile.c b/third_party/sed/compile.c index fe9fa8f11..e22fd6e7f 100644 --- a/third_party/sed/compile.c +++ b/third_party/sed/compile.c @@ -47,7 +47,7 @@ #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/consts/utime.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/time/time.h" #include "libc/str/str.h" diff --git a/third_party/sed/process.c b/third_party/sed/process.c index 7b1d3d750..470553a9b 100644 --- a/third_party/sed/process.c +++ b/third_party/sed/process.c @@ -58,7 +58,7 @@ #include "libc/sysv/consts/sio.h" #include "libc/sysv/consts/termios.h" #include "libc/str/unicode.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/calls/calls.h" #include "libc/str/str.h" diff --git a/third_party/smallz4/smallz4cat.c b/third_party/smallz4/smallz4cat.c index 965dce3e7..8e963ea2f 100644 --- a/third_party/smallz4/smallz4cat.c +++ b/third_party/smallz4/smallz4cat.c @@ -28,7 +28,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/third_party/stb/stb_image.c b/third_party/stb/stb_image.c index 8c284e5cf..9005b8df0 100644 --- a/third_party/stb/stb_image.c +++ b/third_party/stb/stb_image.c @@ -17,9 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/limits.h" #include "libc/log/gdb.h" #include "libc/log/log.h" @@ -2113,8 +2113,8 @@ static unsigned char *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, } static dontinline void *stbi__jpeg_load(stbi__context *s, int *x, int *y, - int *comp, int req_comp, - stbi__result_info *ri) { + int *comp, int req_comp, + stbi__result_info *ri) { unsigned char *result; stbi__jpeg *j = (stbi__jpeg *)malloc(sizeof(stbi__jpeg)); j->s = s; @@ -2178,19 +2178,11 @@ typedef struct { uint16_t value[288]; } stbi__zhuffman; -forceinline int stbi__bitreverse16(int n) { - n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); - n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2); - n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4); - n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8); - return n; -} - forceinline int stbi__bit_reverse(int v, int bits) { assert(bits <= 16); // to bit reverse n bits, reverse 16 and shift // e.g. 11 bits, bit reverse and shift away 5 - return stbi__bitreverse16(v) >> (16 - bits); + return _bitreverse16(v) >> (16 - bits); } static int stbi__zbuild_huffman(stbi__zhuffman *z, @@ -3414,8 +3406,8 @@ static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, } static dontinline void *stbi__png_load(stbi__context *s, int *x, int *y, - int *comp, int req_comp, - stbi__result_info *ri) { + int *comp, int req_comp, + stbi__result_info *ri) { stbi__png p; p.s = s; return stbi__do_png(&p, x, y, comp, req_comp, ri); @@ -3917,8 +3909,8 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, } static dontinline void *stbi__gif_load(stbi__context *s, int *x, int *y, - int *comp, int req_comp, - stbi__result_info *ri) { + int *comp, int req_comp, + stbi__result_info *ri) { unsigned char *u = 0; stbi__gif *g; g = calloc(1, sizeof(stbi__gif)); @@ -3970,8 +3962,8 @@ static int stbi__pnm_test(stbi__context *s) { } static dontinline void *stbi__pnm_load(stbi__context *s, int *x, int *y, - int *comp, int req_comp, - stbi__result_info *ri) { + int *comp, int req_comp, + stbi__result_info *ri) { unsigned char *out; if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n)) { diff --git a/third_party/stb/stb_vorbis.c b/third_party/stb/stb_vorbis.c index eda28c57c..283d7c1a8 100644 --- a/third_party/stb/stb_vorbis.c +++ b/third_party/stb/stb_vorbis.c @@ -32,13 +32,13 @@ // manxorist@github saga musix github:infatum // Timur Gagiev Maxwell Koo // -#include "libc/mem/alg.h" #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/limits.h" #include "libc/math.h" +#include "libc/mem/alg.h" #include "libc/mem/alloca.h" #include "libc/mem/mem.h" #include "libc/str/str.h" @@ -649,7 +649,7 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) { res = available[z]; assert(z >= 0 && z < 32); available[z] = 0; - add_entry(c, bitreverse32(res), i, m++, len[i], values); + add_entry(c, _bitreverse32(res), i, m++, len[i], values); // propagate availability up the tree if (z != len[i]) { assert(len[i] >= 0 && len[i] < 32); @@ -675,7 +675,7 @@ static void compute_accelerated_huffman(Codebook *c) { for (i = 0; i < len; ++i) { if (c->codeword_lengths[i] <= STB_VORBIS_FAST_HUFFMAN_LENGTH) { uint32 z = - c->sparse ? bitreverse32(c->sorted_codewords[i]) : c->codewords[i]; + c->sparse ? _bitreverse32(c->sorted_codewords[i]) : c->codewords[i]; // set table entries for all bit combinations in the higher bits while (z < FAST_HUFFMAN_TABLE_SIZE) { c->fast_huffman[z] = i; @@ -720,11 +720,11 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, int k = 0; for (i = 0; i < c->entries; ++i) if (include_in_sort(c, lengths[i])) - c->sorted_codewords[k++] = bitreverse32(c->codewords[i]); + c->sorted_codewords[k++] = _bitreverse32(c->codewords[i]); assert(k == c->sorted_entries); } else { for (i = 0; i < c->sorted_entries; ++i) - c->sorted_codewords[i] = bitreverse32(c->codewords[i]); + c->sorted_codewords[i] = _bitreverse32(c->codewords[i]); } qsort(c->sorted_codewords, c->sorted_entries, sizeof(c->sorted_codewords[0]), @@ -740,7 +740,7 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, for (i = 0; i < len; ++i) { int huff_len = c->sparse ? lengths[values[i]] : lengths[i]; if (include_in_sort(c, huff_len)) { - uint32 code = bitreverse32(c->codewords[i]); + uint32 code = _bitreverse32(c->codewords[i]); int x = 0, n = c->sorted_entries; while (n > 1) { // invariant: sc[x] <= code < sc[x+n] @@ -808,7 +808,7 @@ static void compute_window(int n, float *window) { static void compute_bitreverse(int n, uint16 *rev) { int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions int i, n8 = n >> 3; - for (i = 0; i < n8; ++i) rev[i] = (bitreverse32(i) >> (32 - ld + 3)) << 2; + for (i = 0; i < n8; ++i) rev[i] = (_bitreverse32(i) >> (32 - ld + 3)) << 2; } static int init_blocksize(vorb *f, int b, int n) { @@ -1182,7 +1182,7 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c) { // sorted_codewords && c->entries > 8 if (c->entries > 8 ? c->sorted_codewords != NULL : !c->codewords) { // binary search - uint32 code = bitreverse32(f->acc); + uint32 code = _bitreverse32(f->acc); int x = 0, n = c->sorted_entries, len; while (n > 1) { @@ -2560,7 +2560,7 @@ void inverse_mdct_naive(float *buffer, int n) // step 4 for (i=0; i < n8; ++i) { - int j = bitreverse32(i) >> (32-ld+3); + int j = _bitreverse32(i) >> (32-ld+3); assert(j < n8); if (i == j) { // paper bug: original code probably swapped in place; if copying, diff --git a/third_party/tidy/config.c b/third_party/tidy/config.c index a31fdd189..d6592df3d 100644 --- a/third_party/tidy/config.c +++ b/third_party/tidy/config.c @@ -16,7 +16,7 @@ #include "libc/assert.h" #include "libc/assert.h" #include "libc/calls/calls.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "third_party/tidy/tags.h" diff --git a/third_party/unzip/unzip.c b/third_party/unzip/unzip.c index c7f4c7e39..6d4f61cd6 100644 --- a/third_party/unzip/unzip.c +++ b/third_party/unzip/unzip.c @@ -71,7 +71,7 @@ #include "third_party/unzip/crypt.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "third_party/unzip/unzvers.h" #include "third_party/unzip/globals.h" diff --git a/third_party/xed/x86ild.greg.c b/third_party/xed/x86ild.greg.c index db9589136..c811c2380 100644 --- a/third_party/xed/x86ild.greg.c +++ b/third_party/xed/x86ild.greg.c @@ -17,10 +17,10 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/bits.h" #include "libc/dce.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "third_party/xed/avx.h" @@ -775,7 +775,7 @@ privileged static void xed_evex_scanner(struct XedDecodedInst *d) { } privileged static uint64_t xed_read_number(uint8_t *p, size_t n, bool s) { - switch (s << 2 | bsr(n)) { + switch (s << 2 | _bsr(n)) { case 0b000: return *p; case 0b100: diff --git a/third_party/zip/tailor.h b/third_party/zip/tailor.h index ff4ba9a97..121ed4613 100644 --- a/third_party/zip/tailor.h +++ b/third_party/zip/tailor.h @@ -38,6 +38,7 @@ #include "libc/str/str.h" #include "libc/calls/struct/stat.h" +#include "libc/runtime/runtime.h" #include "third_party/zip/osdep.h" diff --git a/third_party/zlib/crc32.c b/third_party/zlib/crc32.c index 30970c160..4b8446ee9 100644 --- a/third_party/zlib/crc32.c +++ b/third_party/zlib/crc32.c @@ -5,8 +5,8 @@ │ Use of this source code is governed by the BSD-style licenses that can │ │ be found in the third_party/zlib/LICENSE file. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/weaken.h" #include "libc/dce.h" +#include "libc/intrin/weaken.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" #include "third_party/zlib/deflate.internal.h" @@ -19,22 +19,22 @@ Copyright 1995-2017 Jean-loup Gailly and Mark Adler\""); asm(".include \"libc/disclaimer.inc\""); void crc_reset(struct DeflateState *const s) { - if (X86_HAVE(PCLMUL) && weaken(crc_fold_init)) { - weaken(crc_fold_init)(s); + if (X86_HAVE(PCLMUL) && _weaken(crc_fold_init)) { + _weaken(crc_fold_init)(s); return; } s->strm->adler = crc32(0L, Z_NULL, 0); } void crc_finalize(struct DeflateState *const s) { - if (X86_HAVE(PCLMUL) && weaken(crc_fold_512to32)) { - s->strm->adler = weaken(crc_fold_512to32)(s); + if (X86_HAVE(PCLMUL) && _weaken(crc_fold_512to32)) { + s->strm->adler = _weaken(crc_fold_512to32)(s); } } void copy_with_crc(z_streamp strm, Bytef *dst, long size) { - if (X86_HAVE(PCLMUL) && weaken(crc_fold_copy)) { - weaken(crc_fold_copy)(strm->state, dst, strm->next_in, size); + if (X86_HAVE(PCLMUL) && _weaken(crc_fold_copy)) { + _weaken(crc_fold_copy)(strm->state, dst, strm->next_in, size); return; } memcpy(dst, strm->next_in, size); diff --git a/third_party/zlib/zalloc.c b/third_party/zlib/zalloc.c index d10c0891d..769c2de2b 100644 --- a/third_party/zlib/zalloc.c +++ b/third_party/zlib/zalloc.c @@ -21,9 +21,9 @@ #include "third_party/zlib/zutil.internal.h" void *zcalloc(void *opaque, uInt items, uInt size) { - return weaken(malloc)(items * size); + return _weaken(malloc)(items * size); } void zcfree(void *opaque, void *ptr) { - weaken(free)(ptr); + _weaken(free)(ptr); } diff --git a/third_party/zlib/zutil.c b/third_party/zlib/zutil.c index 2079bcc1d..64d452939 100644 --- a/third_party/zlib/zutil.c +++ b/third_party/zlib/zutil.c @@ -122,7 +122,7 @@ int z_verbose hidden = verbose; void z_error(const char *file, int line, char *m) { kprintf("%s:%d: zlib panic: %s\n", file, line, m); - if (weaken(__die)) weaken(__die)(); + if (_weaken(__die)) _weaken(__die)(); _Exit(1); } #endif diff --git a/tool/args/args.c b/tool/args/args.c index e5398551d..5210884e7 100644 --- a/tool/args/args.c +++ b/tool/args/args.c @@ -20,7 +20,7 @@ #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" diff --git a/tool/build/ar.c b/tool/build/ar.c index 9c75d5b29..b94cb9896 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" +#include "libc/calls/copyfd.internal.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/stat.h" #include "libc/elf/elf.h" @@ -30,7 +31,6 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/arraylist2.internal.h" -#include "libc/mem/io.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" @@ -232,8 +232,8 @@ int main(int argc, char *argv[]) { for (i = 0;; ++i) { TryAgain: if (!(arg = getargs_next(&ga))) break; - if (endswith(arg, "/")) goto TryAgain; - if (endswith(arg, ".pkg")) goto TryAgain; + if (_endswith(arg, "/")) goto TryAgain; + if (_endswith(arg, ".pkg")) goto TryAgain; CHECK_NE(-1, stat(arg, st), "%s", arg); if (!st->st_size || S_ISDIR(st->st_mode)) goto TryAgain; CHECK_NE(-1, (fd = open(arg, O_RDONLY)), "%s", arg); diff --git a/tool/build/bigmul.c b/tool/build/bigmul.c index 07cfb78a3..14e74cb44 100644 --- a/tool/build/bigmul.c +++ b/tool/build/bigmul.c @@ -21,7 +21,7 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/tool/build/blinkenlights.c b/tool/build/blinkenlights.c index 1ea2d8210..8c3d71a3c 100644 --- a/tool/build/blinkenlights.c +++ b/tool/build/blinkenlights.c @@ -41,6 +41,7 @@ #include "libc/intrin/pcmpeqb.h" #include "libc/intrin/pmovmskb.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/color.internal.h" @@ -49,18 +50,17 @@ #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/mem/arraylist2.internal.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/strwidth.h" #include "libc/str/thompike.h" #include "libc/str/tpdecode.internal.h" -#include "libc/str/tpenc.h" #include "libc/str/tpencode.internal.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/ex.h" @@ -77,6 +77,8 @@ #include "libc/sysv/errfuns.h" #include "libc/time/time.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xsigaction.h" #include "third_party/gdtoa/gdtoa.h" #include "third_party/getopt/getopt.h" #include "tool/build/lib/address.h" @@ -589,14 +591,14 @@ static void ToggleMouseTracking(void) { } static void LeaveScreen(void) { - TtyWriteString(gc(xasprintf("\e[%d;%dH\e[S\r\n", tyn, txn))); + TtyWriteString(_gc(xasprintf("\e[%d;%dH\e[S\r\n", tyn, txn))); } static void GetTtySize(int fd) { struct winsize wsize; wsize.ws_row = tyn; wsize.ws_col = txn; - getttysize(fd, &wsize); + _getttysize(fd, &wsize); tyn = wsize.ws_row; txn = wsize.ws_col; } @@ -760,7 +762,7 @@ void TuiSetup(void) { static bool once; report = false; if (!once) { - INFOF("loaded program %s\n%s", codepath, gc(FormatPml4t(m))); + INFOF("loaded program %s\n%s", codepath, _gc(FormatPml4t(m))); CommonSetup(); ioctl(ttyout, TCGETS, &oldterm); xsigaction(SIGINT, OnSigInt, 0, 0, oldsig + 3); @@ -776,7 +778,7 @@ void TuiSetup(void) { DrainInput(ttyin); y = 0; if (GetCursorPosition(&y, NULL) != -1) { - TtyWriteString(gc(xasprintf("\e[%dS", y))); + TtyWriteString(_gc(xasprintf("\e[%dS", y))); } } } @@ -1686,7 +1688,7 @@ static void DrawStatus(struct Panel *p) { rw += AppendStat(s, "freed", a->freed, a->freed != b->freed); rw += AppendStat(s, "tables", a->pagetables, a->pagetables != b->pagetables); rw += AppendStat(s, "fds", m->fds.i, false); - AppendFmt(&p->lines[0], "\e[7m%-*s%s\e[0m", xn - rw, gc(GetStatus(xn - rw)), + AppendFmt(&p->lines[0], "\e[7m%-*s%s\e[0m", xn - rw, _gc(GetStatus(xn - rw)), s->p); free(s->p); free(s); @@ -2258,7 +2260,7 @@ static void OnVidyaServiceWriteCharacter(void) { p = buf; p += FormatCga(m->bx[0], p); p = stpcpy(p, "\e7"); - w = tpenc(GetVidyaByte(m->ax[0])); + w = _tpenc(GetVidyaByte(m->ax[0])); do { *p++ = w; } while ((w >>= 8)); @@ -2286,7 +2288,7 @@ static void OnVidyaServiceTeletypeOutput(void) { uint64_t w; char buf[12]; n = 0 /* FormatCga(m->bx[0], buf) */; - w = tpenc(VidyaServiceXlatTeletype(m->ax[0])); + w = _tpenc(VidyaServiceXlatTeletype(m->ax[0])); do buf[n++] = w; while ((w >>= 8)); PtyWrite(pty, buf, n); diff --git a/tool/build/calculator.c b/tool/build/calculator.c index 0a18a4118..ba146fd50 100644 --- a/tool/build/calculator.c +++ b/tool/build/calculator.c @@ -8,32 +8,32 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "dsp/tty/tty.h" -#include "libc/mem/arraylist2.internal.h" #include "libc/assert.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/morton.h" -#include "libc/intrin/popcnt.h" #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/morton.h" +#include "libc/intrin/popcnt.h" #include "libc/limits.h" #include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/rand.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/sig.h" #include "libc/tinymath/emodl.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" #include "third_party/gdtoa/gdtoa.h" #include "third_party/getopt/getopt.h" @@ -339,7 +339,7 @@ void OpMeminfo(void) { OpCr(); OpCr(); fflush(stdout); - meminfo(fileno(stdout)); + _meminfo(fileno(stdout)); } void Glue2f(FLOAT fn(FLOAT, FLOAT)) { @@ -470,7 +470,7 @@ void ConsumeToken(void) { token.i = 0; if (history.i) history.p[history.i - 1].i = 0; if (comment) return; - if (startswith(token.p, "#!")) return; + if (_startswith(token.p, "#!")) return; switch (setjmp(thrower)) { default: if (CallFunction(token.p)) return; diff --git a/tool/build/chmod.c b/tool/build/chmod.c index 6e62636aa..5020e5e1c 100644 --- a/tool/build/chmod.c +++ b/tool/build/chmod.c @@ -22,7 +22,6 @@ #include "libc/fmt/conv.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" @@ -107,7 +106,7 @@ int main(int argc, char *argv[]) { mode = strtol(argv[optind], 0, 8) & 07777; for (i = optind + 1; i < argc; ++i) { if (chmod(argv[i], mode) == -1) { - const char *s = strerdoc(errno); + const char *s = _strerdoc(errno); fputs(prog, stderr); fputs(": ", stderr); fputs(argv[i], stderr); diff --git a/tool/build/compile.c b/tool/build/compile.c index 7ba0f1f02..8675819b8 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -17,14 +17,17 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/copyfd.internal.h" #include "libc/calls/copyfile.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/rlimit.h" #include "libc/calls/struct/rusage.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timeval.h" +#include "libc/calls/struct/winsize.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" @@ -33,21 +36,20 @@ #include "libc/intrin/kprintf.h" #include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" +#include "libc/log/appendresourcereport.internal.h" #include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/mem/alg.h" -#include "libc/mem/io.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/kcpuids.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/sysconf.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/clock.h" @@ -394,16 +396,16 @@ bool IsGccOnlyFlag(const char *s) { return true; } } - if (startswith(s, "-ffixed-")) return true; - if (startswith(s, "-fcall-saved")) return true; - if (startswith(s, "-fcall-used")) return true; - if (startswith(s, "-fgcse-")) return true; - if (startswith(s, "-fvect-cost-model=")) return true; - if (startswith(s, "-fsimd-cost-model=")) return true; - if (startswith(s, "-fopt-info")) return true; - if (startswith(s, "-mstringop-strategy=")) return true; - if (startswith(s, "-mpreferred-stack-boundary=")) return true; - if (startswith(s, "-Wframe-larger-than=")) return true; + if (_startswith(s, "-ffixed-")) return true; + if (_startswith(s, "-fcall-saved")) return true; + if (_startswith(s, "-fcall-used")) return true; + if (_startswith(s, "-fgcse-")) return true; + if (_startswith(s, "-fvect-cost-model=")) return true; + if (_startswith(s, "-fsimd-cost-model=")) return true; + if (_startswith(s, "-fopt-info")) return true; + if (_startswith(s, "-mstringop-strategy=")) return true; + if (_startswith(s, "-mpreferred-stack-boundary=")) return true; + if (_startswith(s, "-Wframe-larger-than=")) return true; return false; } @@ -436,7 +438,7 @@ void AddEnv(char *s) { } char *StripPrefix(char *s, char *p) { - if (startswith(s, p)) { + if (_startswith(s, p)) { return s + strlen(p); } else { return s; @@ -454,18 +456,18 @@ void AddArg(char *s) { appendw(&shortened, ' '); if ((isar || isbfd || ispkg) && (strcmp(args.p[args.n - 1], "-o") && - (endswith(s, ".o") || endswith(s, ".pkg") || - (endswith(s, ".a") && !isar)))) { + (_endswith(s, ".o") || _endswith(s, ".pkg") || + (_endswith(s, ".a") && !isar)))) { appends(&shortened, basename(s)); } else { appends(&shortened, s); } } else if (/* * a in ('-', '--') or - * a.startswith('-o') or + * a._startswith('-o') or * c == 'ld' and a == '-T' or - * c == 'cc' and a.startswith('-O') or - * c == 'cc' and a.startswith('-x') or + * c == 'cc' and a._startswith('-O') or + * c == 'cc' and a._startswith('-x') or * c == 'cc' and a in ('-c', '-E', '-S') */ s[0] == '-' && (!s[1] || s[1] == 'o' || (s[1] == '-' && !s[2]) || @@ -592,7 +594,7 @@ int Launch(void) { gotchld = 0; if (pipe2(pipefds, O_CLOEXEC) == -1) { - kprintf("pipe2 failed: %s\n", strerrno(errno)); + kprintf("pipe2 failed: %s\n", _strerrno(errno)); exit(1); } @@ -605,7 +607,7 @@ int Launch(void) { pid = vfork(); if (pid == -1) { - kprintf("vfork failed: %s\n", strerrno(errno)); + kprintf("vfork failed: %s\n", _strerrno(errno)); exit(1); } @@ -629,7 +631,7 @@ int Launch(void) { dup2(pipefds[1], 2); sigprocmask(SIG_SETMASK, &savemask, 0); execve(cmd, args.p, env.p); - kprintf("execve(%#s) failed: %s\n", cmd, strerrno(errno)); + kprintf("execve(%#s) failed: %s\n", cmd, _strerrno(errno)); _Exit(127); } close(pipefds[1]); @@ -956,7 +958,7 @@ int main(int argc, char *argv[]) { /* * capture flags */ - if (startswith(argv[i], "-o")) { + if (_startswith(argv[i], "-o")) { if (!strcmp(argv[i], "-o")) { outpath = argv[++i]; } else { @@ -1040,25 +1042,25 @@ int main(int argc, char *argv[]) { if (isgcc && ccversion >= 6) no_sanitize_alignment = true; } else if (!strcmp(argv[i], "-fno-sanitize=pointer-overflow")) { if (isgcc && ccversion >= 6) no_sanitize_pointer_overflow = true; - } else if (startswith(argv[i], "-fsanitize=implicit") && + } else if (_startswith(argv[i], "-fsanitize=implicit") && strstr(argv[i], "integer")) { if (isgcc) AddArg(argv[i]); - } else if (startswith(argv[i], "-fvect-cost") || - startswith(argv[i], "-mstringop") || - startswith(argv[i], "-gz") || + } else if (_startswith(argv[i], "-fvect-cost") || + _startswith(argv[i], "-mstringop") || + _startswith(argv[i], "-gz") || strstr(argv[i], "stack-protector") || strstr(argv[i], "sanitize") || - startswith(argv[i], "-fvect-cost") || - startswith(argv[i], "-fvect-cost")) { + _startswith(argv[i], "-fvect-cost") || + _startswith(argv[i], "-fvect-cost")) { if (isgcc && ccversion >= 6) { AddArg(argv[i]); } - } else if (startswith(argv[i], "-fdiagnostic-color=")) { + } else if (_startswith(argv[i], "-fdiagnostic-color=")) { colorflag = argv[i]; - } else if (startswith(argv[i], "-R") || + } else if (_startswith(argv[i], "-R") || !strcmp(argv[i], "-fsave-optimization-record")) { if (isclang) AddArg(argv[i]); - } else if (isclang && startswith(argv[i], "--debug-prefix-map")) { + } else if (isclang && _startswith(argv[i], "--debug-prefix-map")) { /* llvm doesn't provide a gas interface so simulate w/ clang */ AddArg(xstrcat("-f", argv[i] + 2)); } else if (isgcc && (!strcmp(argv[i], "-Os") || !strcmp(argv[i], "-O2") || @@ -1143,7 +1145,7 @@ int main(int argc, char *argv[]) { * scrub environment for determinism and great justice */ for (envp = environ; *envp; ++envp) { - if (startswith(*envp, "MODE=")) { + if (_startswith(*envp, "MODE=")) { mode = *envp + 5; } if (IsSafeEnv(*envp)) { diff --git a/tool/build/cp.c b/tool/build/cp.c index 89f1ec9ba..4e11bb982 100644 --- a/tool/build/cp.c +++ b/tool/build/cp.c @@ -17,16 +17,15 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/copyfd.internal.h" #include "libc/calls/copyfile.h" #include "libc/calls/struct/stat.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" -#include "libc/mem/io.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/ex.h" @@ -132,7 +131,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag, strcpy(srcfile, fpath); src = srcfile + striplen; strcpy(dstfile, dstdir); - if (!endswith(dstfile, "/")) { + if (!_endswith(dstfile, "/")) { strcat(dstfile, "/"); } strcat(dstfile, src); @@ -210,7 +209,7 @@ void Cp(char *src, char *dst) { if (nftw(src, Visit, 20, 0) == -1) { fputs(prog, stderr); fputs(": nftw failed: ", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputs("\n", stderr); exit(1); } @@ -231,7 +230,7 @@ void Cp(char *src, char *dst) { } return; OnFail: - s = strerdoc(errno); + s = _strerdoc(errno); fputs(prog, stderr); fputs(": ", stderr); fputs(src, stderr); diff --git a/tool/build/dd.c b/tool/build/dd.c index 0fce0779c..7d037d600 100644 --- a/tool/build/dd.c +++ b/tool/build/dd.c @@ -23,7 +23,6 @@ #include "libc/limits.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" @@ -36,7 +35,7 @@ wontreturn void SysFail(const char *func, const char *file) { fputs(" failed: ", stderr); fputs(file, stderr); fputs(": ", stderr); - fputs(nulltoempty(strerdoc(e)), stderr); + fputs(nulltoempty(_strerdoc(e)), stderr); fputs("\n", stderr); exit(__COUNTER__ + 1); } diff --git a/tool/build/deltaify.c b/tool/build/deltaify.c index 66b914783..4121e4a47 100644 --- a/tool/build/deltaify.c +++ b/tool/build/deltaify.c @@ -28,7 +28,7 @@ #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xgetline.h" static int pid; diff --git a/tool/build/fixupobj.c b/tool/build/fixupobj.c index dbfed4e1b..e11556dbd 100644 --- a/tool/build/fixupobj.c +++ b/tool/build/fixupobj.c @@ -30,7 +30,6 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/msync.h" @@ -66,7 +65,7 @@ wontreturn void SysExit(int rc, const char *call, const char *thing) { const char *estr; err = errno; FormatInt32(ibuf, err); - estr = strerdoc(err); + estr = _strerdoc(err); if (!estr) estr = "EUNKNOWN"; Write(thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0); exit(rc); diff --git a/tool/build/gzip.c b/tool/build/gzip.c index ec58970b0..e99102f4e 100644 --- a/tool/build/gzip.c +++ b/tool/build/gzip.c @@ -21,7 +21,6 @@ #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" @@ -171,7 +170,7 @@ void Compress(const char *inpath) { if (!output) { fputs(outpath, stderr); fputs(": gzopen() failed\n", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputs("\n", stderr); exit(1); } @@ -181,7 +180,7 @@ void Compress(const char *inpath) { errnum = 0; fputs(inpath, stderr); fputs(": read failed: ", stderr); - fputs(strerdoc(ferror(input)), stderr); + fputs(_strerdoc(ferror(input)), stderr); fputs("\n", stderr); _Exit(1); } @@ -226,14 +225,14 @@ void Decompress(const char *inpath) { if (!input) { fputs(inpath, stderr); fputs(": gzopen() failed\n", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputs("\n", stderr); exit(1); } if (opt_usestdout) { output = stdout; outpath = "/dev/stdout"; - } else if (endswith(inpath, ".gz")) { + } else if (_endswith(inpath, ".gz")) { n = strlen(inpath); if (n - 3 + 1 > PATH_MAX) _Exit(2); memcpy(pathbuf, inpath, n - 3); @@ -242,7 +241,7 @@ void Decompress(const char *inpath) { if (!(output = fopen(outpath, opt_append ? "wa" : "wb"))) { fputs(outpath, stderr); fputs(": open failed: ", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputs("\n", stderr); _Exit(1); } @@ -264,7 +263,7 @@ void Decompress(const char *inpath) { if (fwrite(databuf, rc, 1, output) != 1) { fputs(outpath, stderr); fputs(": write failed: ", stderr); - fputs(strerdoc(ferror(output)), stderr); + fputs(_strerdoc(ferror(output)), stderr); fputs("\n", stderr); _Exit(1); } diff --git a/tool/build/helpop.c b/tool/build/helpop.c index f956d02c5..c41f8d16d 100644 --- a/tool/build/helpop.c +++ b/tool/build/helpop.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/fmt/conv.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -331,7 +331,7 @@ void HandleOperand(const char *op) { while (*op) { found = false; for (i = 0; i < ARRAYLEN(kDescriptors); ++i) { - if (startswith(op, kDescriptors[i].prefix)) { + if (_startswith(op, kDescriptors[i].prefix)) { found = true; op += strlen(kDescriptors[i].prefix); if (succinct_) { diff --git a/tool/build/lib/argv.c b/tool/build/lib/argv.c index b6374d615..b311f0afb 100644 --- a/tool/build/lib/argv.c +++ b/tool/build/lib/argv.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "tool/build/lib/endian.h" #include "tool/build/lib/machine.h" diff --git a/tool/build/lib/buffer.c b/tool/build/lib/buffer.c index 85540b0bc..06bb45ffd 100644 --- a/tool/build/lib/buffer.c +++ b/tool/build/lib/buffer.c @@ -16,15 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/tpenc.h" #include "libc/macros.internal.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "tool/build/lib/buffer.h" /* TODO(jart): replace with new append*() library */ @@ -55,7 +55,7 @@ void AppendWide(struct Buffer *b, wint_t wc) { uint64_t wb; char buf[8]; i = 0; - wb = tpenc(wc); + wb = _tpenc(wc); do { buf[i++] = wb & 0xFF; wb >>= 8; diff --git a/tool/build/lib/clmul.c b/tool/build/lib/clmul.c index b44abdef1..003db5f57 100644 --- a/tool/build/lib/clmul.c +++ b/tool/build/lib/clmul.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "libc/nexgen32e/x86feature.h" #include "tool/build/lib/clmul.h" #include "tool/build/lib/endian.h" @@ -33,7 +33,7 @@ struct clmul { static struct clmul clmul(uint64_t a, uint64_t b) { uint64_t t, x = 0, y = 0; if (a && b) { - if (bsrl(a) < bsrl(b)) t = a, a = b, b = t; + if (_bsrl(a) < _bsrl(b)) t = a, a = b, b = t; for (t = 0; b; a <<= 1, b >>= 1) { if (b & 1) x ^= a, y ^= t; t = t << 1 | a >> 63; diff --git a/tool/build/lib/demangle.c b/tool/build/lib/demangle.c index 221d86c9b..3baedd9fb 100644 --- a/tool/build/lib/demangle.c +++ b/tool/build/lib/demangle.c @@ -115,7 +115,7 @@ char *Demangle(char *p, const char *symbol, size_t n) { char *r; size_t sn; sn = strlen(symbol); - if (startswith(symbol, "_Z")) { + if (_startswith(symbol, "_Z")) { if ((r = DemangleCxxFilt(p, n, symbol, sn))) return r; } return CopySymbol(p, n, symbol, sn); diff --git a/tool/build/lib/dis.c b/tool/build/lib/dis.c index faad633a1..d85c4c1c4 100644 --- a/tool/build/lib/dis.c +++ b/tool/build/lib/dis.c @@ -18,11 +18,11 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/bing.internal.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/tpenc.h" #include "libc/log/check.h" #include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "third_party/xed/x86.h" #include "tool/build/lib/demangle.h" #include "tool/build/lib/dis.h" @@ -151,7 +151,7 @@ static char *DisLineData(struct Dis *d, char *p, const uint8_t *b, size_t n) { *p++ = '#'; *p++ = ' '; for (i = 0; i < n; ++i) { - w = tpenc(bing(b[i], 0)); + w = _tpenc(bing(b[i], 0)); do { *p++ = w; } while ((w >>= 8)); diff --git a/tool/build/lib/diself.c b/tool/build/lib/diself.c index eed3f7916..6618f780d 100644 --- a/tool/build/lib/diself.c +++ b/tool/build/lib/diself.c @@ -16,12 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/elf/elf.h" #include "libc/elf/struct/sym.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/alg.h" #include "libc/mem/mem.h" #include "libc/runtime/memtrack.internal.h" #include "libc/str/str.h" @@ -85,7 +85,7 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) { for (i = 0; i < n; ++i) { if (ELF64_ST_TYPE(st[i].st_info) == STT_SECTION || ELF64_ST_TYPE(st[i].st_info) == STT_FILE || !st[i].st_name || - startswith(d->syms.stab + st[i].st_name, "v_") || + _startswith(d->syms.stab + st[i].st_name, "v_") || !(0 <= st[i].st_name && st[i].st_name < stablen) || !st[i].st_value || !IsLegalPointer(st[i].st_value)) { continue; diff --git a/tool/build/lib/disinst.c b/tool/build/lib/disinst.c index ce36d4811..e6d75bbcd 100644 --- a/tool/build/lib/disinst.c +++ b/tool/build/lib/disinst.c @@ -158,8 +158,8 @@ static char *DisName(struct Dis *d, char *bp, const char *name, } else { *p++ = 's'; } - } else if (wantsuffix || (ambiguous && !startswith(name, "f") && - !startswith(name, "set"))) { + } else if (wantsuffix || (ambiguous && !_startswith(name, "f") && + !_startswith(name, "set"))) { if (Osz(rde)) { if (ambiguous || Mode(rde) != XED_MODE_REAL) { *p++ = 'w'; diff --git a/tool/build/lib/elfwriter.c b/tool/build/lib/elfwriter.c index 83d5673a5..c8d96c759 100644 --- a/tool/build/lib/elfwriter.c +++ b/tool/build/lib/elfwriter.c @@ -21,7 +21,7 @@ #include "libc/elf/def.h" #include "libc/log/check.h" #include "libc/mem/arraylist2.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/memtrack.internal.h" #include "libc/stdalign.internal.h" #include "libc/str/str.h" @@ -29,7 +29,7 @@ #include "libc/sysv/consts/msync.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "tool/build/lib/elfwriter.h" static const Elf64_Ehdr kObjHeader = { @@ -86,8 +86,8 @@ static void MakeRelaSection(struct ElfWriter *elf, size_t section) { elfwriter_align(elf, alignof(Elf64_Rela), sizeof(Elf64_Rela)); shdr = elfwriter_startsection( elf, - gc(xasprintf("%s%s", ".rela", - &elf->shstrtab->p[elf->shdrs->p[section].sh_name])), + _gc(xasprintf("%s%s", ".rela", + &elf->shstrtab->p[elf->shdrs->p[section].sh_name])), SHT_RELA, SHF_INFO_LINK); elf->shdrs->p[shdr].sh_info = section; elfwriter_reserve(elf, size); diff --git a/tool/build/lib/elfwriter_zip.c b/tool/build/lib/elfwriter_zip.c index 6373d592e..d86c4ac62 100644 --- a/tool/build/lib/elfwriter_zip.c +++ b/tool/build/lib/elfwriter_zip.c @@ -22,12 +22,13 @@ #include "libc/log/check.h" #include "libc/nexgen32e/crc32.h" #include "libc/nt/enum/fileflagandattributes.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/rand.h" #include "libc/str/str.h" #include "libc/sysv/consts/s.h" #include "libc/time/struct/tm.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "libc/zip.h" #include "third_party/zlib/zlib.h" #include "tool/build/lib/elfwriter.h" @@ -166,7 +167,7 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name, /* emit embedded file content w/ pkzip local file header */ elfwriter_align(elf, 1, 0); elfwriter_startsection(elf, - gc(xasprintf("%s%s", ZIP_LOCALFILE_SECTION, name)), + _gc(xasprintf("%s%s", ZIP_LOCALFILE_SECTION, name)), SHT_PROGBITS, SHF_ALLOC); if (method == kZipCompressionDeflate) { CHECK_EQ(Z_OK, deflateInit2(memset(&zs, 0, sizeof(zs)), @@ -195,9 +196,9 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name, EmitZipLfileHdr(lfile, name, namesize, crc, era, gflags, method, mtime, mdate, compsize, uncompsize); elfwriter_commit(elf, lfilehdrsize + compsize); - lfilesym = elfwriter_appendsym(elf, gc(xasprintf("%s%s", "zip+lfile:", name)), - ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), - STV_DEFAULT, 0, lfilehdrsize); + lfilesym = elfwriter_appendsym( + elf, _gc(xasprintf("%s%s", "zip+lfile:", name)), + ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0, lfilehdrsize); elfwriter_appendsym(elf, symbol, ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT), STV_DEFAULT, lfilehdrsize, compsize); elfwriter_finishsection(elf); @@ -205,13 +206,13 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name, /* emit central directory record */ elfwriter_align(elf, 1, 0); elfwriter_startsection(elf, - gc(xasprintf("%s%s", ZIP_DIRECTORY_SECTION, name)), + _gc(xasprintf("%s%s", ZIP_DIRECTORY_SECTION, name)), SHT_PROGBITS, SHF_ALLOC); EmitZipCdirHdr( (cfile = elfwriter_reserve(elf, kZipCdirHdrLinkableSizeBootstrap)), name, namesize, crc, era, gflags, method, mtime, mdate, iattrs, dosmode, mode, compsize, uncompsize, commentsize, mtim, atim, ctim); - elfwriter_appendsym(elf, gc(xasprintf("%s%s", "zip+cdir:", name)), + elfwriter_appendsym(elf, _gc(xasprintf("%s%s", "zip+cdir:", name)), ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0, kZipCdirHdrLinkableSizeBootstrap); elfwriter_appendrela(elf, kZipCfileOffsetOffset, lfilesym, R_X86_64_32, diff --git a/tool/build/lib/eztls.c b/tool/build/lib/eztls.c index d82a29d77..5b5de4800 100644 --- a/tool/build/lib/eztls.c +++ b/tool/build/lib/eztls.c @@ -18,10 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" +#include "libc/errno.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/sig.h" #include "libc/x/x.h" +#include "libc/x/xsigaction.h" #include "net/https/https.h" #include "third_party/mbedtls/net_sockets.h" #include "third_party/mbedtls/ssl.h" diff --git a/tool/build/lib/instruction.c b/tool/build/lib/instruction.c index 13460a152..76e5751f1 100644 --- a/tool/build/lib/instruction.c +++ b/tool/build/lib/instruction.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/bsf.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsf.h" #include "libc/str/str.h" #include "third_party/xed/x86.h" #include "tool/build/lib/address.h" @@ -33,7 +33,7 @@ static bool IsOpcodeEqual(struct XedDecodedInst *xedd, uint8_t *a) { if (xedd->length) { if (xedd->length <= 7) { w = Read64(a) ^ Read64(xedd->bytes); - return !w || bsfl(w) >= (xedd->length << 3); + return !w || _bsfl(w) >= (xedd->length << 3); } else { return memcmp(a, xedd->bytes, xedd->length) == 0; } diff --git a/tool/build/lib/javadown.c b/tool/build/lib/javadown.c index c15a25d2e..b3f0394fc 100644 --- a/tool/build/lib/javadown.c +++ b/tool/build/lib/javadown.c @@ -122,7 +122,7 @@ static void SplitLines(struct Lines *lines, char *p) { static bool ConsumeFileOverview(struct Lines *lines) { int i; if (lines->n && lines->p[0].n >= strlen(FILEOVERVIEW) && - startswith(lines->p[0].p, FILEOVERVIEW)) { + _startswith(lines->p[0].p, FILEOVERVIEW)) { lines->p[0].p += strlen(FILEOVERVIEW); lines->p[0].n -= strlen(FILEOVERVIEW); while (lines->p[0].n && diff --git a/tool/build/lib/persist.c b/tool/build/lib/persist.c index 978bf3ec2..601110453 100644 --- a/tool/build/lib/persist.c +++ b/tool/build/lib/persist.c @@ -18,10 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" +#include "libc/intrin/bsr.h" #include "libc/log/check.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/sock/sock.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" @@ -76,9 +76,9 @@ void PersistObject(const char *path, size_t align, CHECK(IsWithin(sizeof(*obj->abi), obj->abi, obj->size, obj->p)); for (n = i = 0; obj->arrays[i].size; ++i) ++n; iovlen = (n + 1) * 2; - pad = gc(xcalloc(align, 1)); - hdr = gc(xmalloc(obj->size)); - iov = gc(xcalloc(iovlen, sizeof(*iov))); + pad = _gc(xcalloc(align, 1)); + hdr = _gc(xmalloc(obj->size)); + iov = _gc(xcalloc(iovlen, sizeof(*iov))); bytes = obj->size; iov[0].iov_base = memcpy(hdr, obj->p, obj->size); iov[0].iov_len = bytes; @@ -94,7 +94,7 @@ void PersistObject(const char *path, size_t align, p2 = obj->arrays[i].pp; arrayptroffset = p2 - p1; arraydataoffset = filesize; - CHECK((!len || bsrl(len) + bsrl(size) < 31), + CHECK((!len || _bsrl(len) + _bsrl(size) < 31), "path=%s i=%d len=%,lu size=%,lu", path, i, len, size); CHECK(IsWithin(sizeof(void *), pp, obj->size, obj->p)); CHECK(!IsOverlapping(pp, pp + sizeof(void *), obj->magic, diff --git a/tool/build/lib/psk.c b/tool/build/lib/psk.c index 42aa2aab4..ff6ab5b56 100644 --- a/tool/build/lib/psk.c +++ b/tool/build/lib/psk.c @@ -20,10 +20,12 @@ #include "libc/calls/struct/stat.h" #include "libc/log/check.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/stdio.h" #include "libc/sysv/consts/o.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "tool/build/lib/psk.h" /** @@ -33,7 +35,7 @@ void *GetRunitPsk(void) { int fd; char *r, *p; struct stat st; - p = gc(xasprintf("%s/.runit.psk", gc(xhomedir()))); + p = _gc(xasprintf("%s/.runit.psk", _gc(xhomedir()))); if (stat(p, &st) == -1 || st.st_size != 32) { fprintf(stderr, "need o//examples/getrandom.com -bn32 >~/.runit.psk\n"); exit(1); diff --git a/tool/build/lib/pty.c b/tool/build/lib/pty.c index 32d63cccc..ad0426e60 100644 --- a/tool/build/lib/pty.c +++ b/tool/build/lib/pty.c @@ -19,12 +19,12 @@ #include "libc/fmt/itoa.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/log/check.h" #include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/str/thompike.h" -#include "libc/str/tpenc.h" #include "libc/str/unicode.h" #include "libc/sysv/errfuns.h" #include "libc/x/x.h" @@ -1359,7 +1359,7 @@ int PtyAppendLine(struct Pty *pty, struct Buffer *buf, unsigned y) { u = wc; w = 1; } else { - u = tpenc(wc); + u = _tpenc(wc); w = max(1, wcwidth(wc)); } } else { @@ -1370,7 +1370,7 @@ int PtyAppendLine(struct Pty *pty, struct Buffer *buf, unsigned y) { if (u != ' ') { np ^= kPtyFlip; } else { - u = tpenc(u'▂'); + u = _tpenc(u'▂'); if (pty->conf & kPtyBlinkcursor) { np |= kPtyBlink; } diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index 437990ec3..dbd3ea469 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -42,7 +42,7 @@ #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/vendor.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/pc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/select.h" diff --git a/tool/build/lib/throw.c b/tool/build/lib/throw.c index de0dda13e..1ce6187dd 100644 --- a/tool/build/lib/throw.c +++ b/tool/build/lib/throw.c @@ -19,7 +19,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/nexgen32e/vendor.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "tool/build/lib/address.h" diff --git a/tool/build/lz4toasm.c b/tool/build/lz4toasm.c index 6e97bb0dc..6f16ca23c 100644 --- a/tool/build/lz4toasm.c +++ b/tool/build/lz4toasm.c @@ -26,7 +26,7 @@ #include "libc/nexgen32e/kompressor.h" #include "libc/nexgen32e/lz4.h" #include "libc/runtime/ezmap.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index b55bc74b2..0d4d7a257 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -33,14 +33,14 @@ #include "libc/mem/arraylist.internal.h" #include "libc/mem/arraylist2.internal.h" #include "libc/mem/bisectcarleft.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" #include "libc/runtime/ezmap.internal.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/runtime/sysconf.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/clone.h" @@ -166,8 +166,8 @@ void Crunch(void) { free(sources.p); sources.p = 0; sources.i = j; - longsort((const long *)sauces, sources.i); - longsort((const long *)edges.p, edges.i); + _longsort((const long *)sauces, sources.i); + _longsort((const long *)edges.p, edges.i); } void Rehash(void) { @@ -221,7 +221,7 @@ unsigned GetSourceId(const char *name, size_t len) { bool ShouldSkipSource(const char *src) { unsigned j; for (j = 0; j < ARRAYLEN(kIgnorePrefixes); ++j) { - if (startswith(src, kIgnorePrefixes[j])) { + if (_startswith(src, kIgnorePrefixes[j])) { return true; } } @@ -345,7 +345,7 @@ const char *StripExt(char pathbuf[PATH_MAX], const char *s) { bool IsObjectSource(const char *name) { int i; for (i = 0; i < ARRAYLEN(kSourceExts); ++i) { - if (endswith(name, kSourceExts[i])) return true; + if (_endswith(name, kSourceExts[i])) return true; } return false; } @@ -390,7 +390,7 @@ int Diver(void *arg, int tid) { path = strings.p + sauces[i].name; if (!IsObjectSource(path)) continue; appendw(&bout, '\n'); - if (!startswith(path, "o/")) { + if (!_startswith(path, "o/")) { appends(&bout, buildroot); } appends(&bout, StripExt(pathbuf, path)); diff --git a/tool/build/mkdir.c b/tool/build/mkdir.c index 58facc516..7659cc45b 100644 --- a/tool/build/mkdir.c +++ b/tool/build/mkdir.c @@ -12,7 +12,6 @@ #include "libc/fmt/conv.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/x/x.h" @@ -73,7 +72,7 @@ int main(int argc, char *argv[]) { fputs(": cannot create directory '", stderr); fputs(argv[i], stderr); fputs("' ", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputc('\n', stderr); exit(1); } diff --git a/tool/build/mv.c b/tool/build/mv.c index 9f518b45a..28aa4b623 100644 --- a/tool/build/mv.c +++ b/tool/build/mv.c @@ -21,10 +21,9 @@ #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" -#include "libc/runtime/gc.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/ex.h" @@ -117,7 +116,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag, strcpy(srcfile, fpath); src = srcfile + striplen; strcpy(dstfile, dstdir); - if (!endswith(dstfile, "/")) { + if (!_endswith(dstfile, "/")) { strcat(dstfile, "/"); } strcat(dstfile, src); @@ -177,7 +176,7 @@ void Mv(char *src, char *dst) { if (nftw(src, Visit, 20, 0) == -1) { fputs(prog, stderr); fputs(": nftw failed: ", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputs("\n", stderr); exit(1); } @@ -198,7 +197,7 @@ void Mv(char *src, char *dst) { } return; OnFail: - s = strerdoc(errno); + s = _strerdoc(errno); fputs(prog, stderr); fputs(": ", stderr); fputs(src, stderr); diff --git a/tool/build/ocat.c b/tool/build/ocat.c index 77d86355a..c30a929ca 100644 --- a/tool/build/ocat.c +++ b/tool/build/ocat.c @@ -17,11 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/copyfd.internal.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/mem/io.h" #include "libc/runtime/runtime.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/o.h" @@ -44,7 +43,7 @@ wontreturn void SysExit(int rc, const char *call, const char *thing) { const char *estr; err = errno; FormatInt32(ibuf, err); - estr = strerdoc(err); + estr = _strerdoc(err); if (!estr) estr = "EUNKNOWN"; Write(thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0); exit(rc); diff --git a/tool/build/package.c b/tool/build/package.c index 391a0cbbf..e4ffd2bcb 100644 --- a/tool/build/package.c +++ b/tool/build/package.c @@ -228,21 +228,21 @@ void IndexSections(struct Object *obj) { CHECK_NOTNULL((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i))); if (shdr->sh_type != SHT_NULL) { CHECK_NOTNULL((name = GetElfSectionName(obj->elf, obj->size, shdr))); - if (startswith(name, ".sort.")) name += 5; + if (_startswith(name, ".sort.")) name += 5; if ((strcmp(name, ".piro.relo") == 0 || - startswith(name, ".piro.relo.")) || + _startswith(name, ".piro.relo.")) || (strcmp(name, ".data.rel.ro") == 0 || - startswith(name, ".data.rel.ro."))) { + _startswith(name, ".data.rel.ro."))) { sect.kind = kPiroRelo; } else if (strcmp(name, ".piro.data") == 0 || - startswith(name, ".piro.data.")) { + _startswith(name, ".piro.data.")) { sect.kind = kPiroData; } else if (strcmp(name, ".piro.bss") == 0 || - startswith(name, ".piro.bss.")) { + _startswith(name, ".piro.bss.")) { sect.kind = kPiroBss; - } else if (strcmp(name, ".data") == 0 || startswith(name, ".data.")) { + } else if (strcmp(name, ".data") == 0 || _startswith(name, ".data.")) { sect.kind = kData; - } else if (strcmp(name, ".bss") == 0 || startswith(name, ".bss.")) { + } else if (strcmp(name, ".bss") == 0 || _startswith(name, ".bss.")) { sect.kind = kBss; } else { sect.kind = kText; diff --git a/tool/build/pledge.c b/tool/build/pledge.c index c17f1ab7e..937e67676 100644 --- a/tool/build/pledge.c +++ b/tool/build/pledge.c @@ -39,10 +39,10 @@ #include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/math.h" -#include "libc/mem/io.h" +#include "libc/calls/copyfd.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/kcpuids.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/sysconf.h" #include "libc/sock/sock.h" diff --git a/tool/build/pstrace.c b/tool/build/pstrace.c index 3ba54a7ac..5e0b20fab 100644 --- a/tool/build/pstrace.c +++ b/tool/build/pstrace.c @@ -24,8 +24,8 @@ #include "libc/intrin/bits.h" #include "libc/log/check.h" #include "libc/log/log.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -35,7 +35,8 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xgetline.h" #include "third_party/dlmalloc/dlmalloc.h" #include "third_party/getopt/getopt.h" @@ -635,7 +636,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) { CHECK_EQ('.', *p++, DEBUG); us = strtol(p, &p, 10); CHECK_EQ(' ', *p++, DEBUG); - if (startswith(p, "<... ")) { + if (_startswith(p, "<... ")) { CHECK_NOTNULL((p = strchr(p, '>'))); ++p; for (event = t->events.n; event--;) { @@ -655,18 +656,18 @@ static void Parse(struct Trace *t, const char *line, long lineno) { t->events.p[event].sec = sec; t->events.p[event].us = us; t->events.p[event].lineno = lineno; - if (startswith(p, "+++ exited with ")) { + if (_startswith(p, "+++ exited with ")) { p += strlen("+++ exited with "); t->events.p[event].kind = EK_EXIT; t->events.p[event].ret = atoi(p); return; - } else if (startswith(p, "+++ killed by ")) { + } else if (_startswith(p, "+++ killed by ")) { p += strlen("+++ killed by "); CHECK((q = strchr(p, ' ')), DEBUG); t->events.p[event].kind = EK_KILLED; t->events.p[event].ret = GetSignal(p, q - p); return; - } else if (startswith(p, "--- ")) { + } else if (_startswith(p, "--- ")) { p += 4; CHECK(isalpha(*p), DEBUG); CHECK((q = strchr(p, ' ')), DEBUG); @@ -683,7 +684,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) { if (*p == ',') ++p; while (*p == ' ') ++p; CHECK(*p, DEBUG); - if (startswith(p, "")) { + if (_startswith(p, "")) { t->events.p[event].is_interrupted = true; break; } else if (*p == ')') { @@ -703,7 +704,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) { break; } CHECK_LT((arg = t->events.p[event].arity++), 6); - if (isalpha(*p) && !startswith(p, "NULL")) { + if (isalpha(*p) && !_startswith(p, "NULL")) { bzero(&b, sizeof(b)); for (; isalpha(*p) || *p == '_'; ++p) { AppendSlice(&b, *p); @@ -713,7 +714,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) { } else { t->events.p[event].arg[arg].name = -1; } - if (startswith(p, "NULL")) { + if (_startswith(p, "NULL")) { p += 4; t->events.p[event].arg[arg].kind = AK_LONG; t->events.p[event].arg[arg].x = 0; diff --git a/tool/build/refactor.c b/tool/build/refactor.c index d53bbe778..5a7b5f12a 100644 --- a/tool/build/refactor.c +++ b/tool/build/refactor.c @@ -16,15 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" #include "libc/assert.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/alg.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/dt.h" @@ -115,7 +115,7 @@ void RefactorDir(const char *dpath) { char *path = gc(xmalloc(4096)); CHECK_NOTNULL(dir = opendir(firstnonnull(dpath, "."))); while ((ent = readdir(dir))) { - if (startswith(ent->d_name, ".")) continue; + if (_startswith(ent->d_name, ".")) continue; if (strcmp(ent->d_name, "o") == 0) continue; snprintf(path, 4096, "%s%s%s", dpath ? dpath : "", dpath ? "/" : "", ent->d_name); diff --git a/tool/build/rm.c b/tool/build/rm.c index 124b9de90..341914cd3 100644 --- a/tool/build/rm.c +++ b/tool/build/rm.c @@ -20,7 +20,6 @@ #include "libc/errno.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" @@ -74,7 +73,7 @@ void Remove(const char *path) { return; OnFail: if (force && errno == ENOENT) return; - s = strerdoc(errno); + s = _strerdoc(errno); fputs(prog, stderr); fputs(": cannot remove '", stderr); fputs(path, stderr); diff --git a/tool/build/rollup.c b/tool/build/rollup.c index b10be0260..f231ca812 100644 --- a/tool/build/rollup.c +++ b/tool/build/rollup.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/relocations.h" -#include "libc/mem/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/errno.h" @@ -25,9 +24,10 @@ #include "libc/intrin/kprintf.h" #include "libc/log/check.h" #include "libc/log/log.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/map.h" @@ -97,13 +97,13 @@ void Visit(const char *path) { char *map; size_t size; bool isheader; - if (!endswith(path, ".h") && !endswith(path, ".inc")) return; - if (endswith(path, ".internal.h")) return; - if (endswith(path, "/internal.h")) return; - if (endswith(path, ".internal.inc")) return; - if (endswith(path, "/internal.inc")) return; - if (startswith(path, "libc/isystem/")) return; - isheader = endswith(path, ".h"); + if (!_endswith(path, ".h") && !_endswith(path, ".inc")) return; + if (_endswith(path, ".internal.h")) return; + if (_endswith(path, "/internal.h")) return; + if (_endswith(path, ".internal.inc")) return; + if (_endswith(path, "/internal.inc")) return; + if (_startswith(path, "libc/isystem/")) return; + isheader = _endswith(path, ".h"); if (isheader && isinterned(visited, path)) return; appends(&output, "\n\f\n/*!BEGIN "); appends(&output, path); diff --git a/tool/build/runit.c b/tool/build/runit.c index 626a31b2e..8a5cfd3f3 100644 --- a/tool/build/runit.c +++ b/tool/build/runit.c @@ -19,17 +19,19 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/struct/itimerval.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/stat.h" #include "libc/dns/dns.h" +#include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/ipclassify.internal.h" #include "libc/stdio/stdio.h" @@ -42,9 +44,11 @@ #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/sock.h" #include "libc/time/time.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "net/https/https.h" #include "third_party/mbedtls/ssl.h" #include "third_party/zlib/zlib.h" @@ -142,7 +146,7 @@ void Connect(void) { int rc, err, expo; long double t1, t2; struct addrinfo *ai; - if ((rc = getaddrinfo(g_hostname, gc(xasprintf("%hu", g_runitdport)), + if ((rc = getaddrinfo(g_hostname, _gc(xasprintf("%hu", g_runitdport)), &kResolvHints, &ai)) != 0) { FATALF("%s:%hu: EAI_%s %m", g_hostname, g_runitdport, gai_strerror(rc)); unreachable; @@ -199,7 +203,7 @@ bool Send(int tmpfd, const void *output, size_t outputsize) { static bool once; static z_stream zs; zsize = 32768; - zbuf = gc(malloc(zsize)); + zbuf = _gc(malloc(zsize)); if (!once) { CHECK_EQ(Z_OK, deflateInit2(&zs, 4, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY)); @@ -241,7 +245,7 @@ bool SendRequest(int tmpfd) { CHECK_NE(MAP_FAILED, (p = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0))); CHECK_LE((namesize = strlen((name = basename(g_prog)))), PATH_MAX); CHECK_LE((progsize = st.st_size), INT_MAX); - CHECK_NOTNULL((hdr = gc(calloc(1, (hdrsize = 17 + namesize))))); + CHECK_NOTNULL((hdr = _gc(calloc(1, (hdrsize = 17 + namesize))))); crc = crc32_z(0, p, st.st_size); q = hdr; q = WRITE32BE(q, RUNITD_MAGIC); @@ -261,7 +265,7 @@ bool SendRequest(int tmpfd) { void RelayRequest(void) { int i, rc, have, transferred; - char *buf = gc(malloc(PIPE_BUF)); + char *buf = _gc(malloc(PIPE_BUF)); for (transferred = 0;;) { rc = read(13, buf, PIPE_BUF); CHECK_NE(-1, rc); @@ -381,7 +385,7 @@ int SpawnSubprocesses(int argc, char *argv[]) { // create compressed network request ahead of time CHECK_NE(-1, (tmpfd = open( - (tpath = gc(xasprintf( + (tpath = _gc(xasprintf( "%s/runit.%d", firstnonnull(getenv("TMPDIR"), "/tmp"), getpid()))), O_WRONLY | O_CREAT | O_TRUNC, 0755))); diff --git a/tool/build/runitd.c b/tool/build/runitd.c index efeca08db..dfffc8ccf 100644 --- a/tool/build/runitd.c +++ b/tool/build/runitd.c @@ -16,18 +16,19 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.h" #include "libc/nexgen32e/crc32.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" @@ -52,6 +53,7 @@ #include "libc/sysv/consts/w.h" #include "libc/time/time.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "net/https/https.h" #include "third_party/getopt/getopt.h" #include "third_party/mbedtls/ssl.h" @@ -220,7 +222,7 @@ void StartTcpServer(void) { CHECK_NE(-1, listen(g_servfd, 10)); asize = sizeof(g_servaddr); CHECK_NE(-1, getsockname(g_servfd, &g_servaddr, &asize)); - INFOF("%s:%s", "listening on tcp", gc(DescribeAddress(&g_servaddr))); + INFOF("%s:%s", "listening on tcp", _gc(DescribeAddress(&g_servaddr))); if (g_sendready) { printf("ready %hu\n", ntohs(g_servaddr.sin_port)); fflush(stdout); @@ -382,8 +384,8 @@ void HandleClient(void) { EzFd(g_clifd); INFOF("EzHandshake"); EzHandshake(); - addrstr = gc(DescribeAddress(&addr)); - DEBUGF("%s %s %s", gc(DescribeAddress(&g_servaddr)), "accepted", addrstr); + addrstr = _gc(DescribeAddress(&addr)); + DEBUGF("%s %s %s", _gc(DescribeAddress(&g_servaddr)), "accepted", addrstr); Recv(msg, sizeof(msg)); CHECK_EQ(RUNITD_MAGIC, READ32BE(msg)); @@ -391,9 +393,9 @@ void HandleClient(void) { namesize = READ32BE(msg + 5); filesize = READ32BE(msg + 9); crc = READ32BE(msg + 13); - exename = gc(calloc(1, namesize + 1)); + exename = _gc(calloc(1, namesize + 1)); Recv(exename, namesize); - g_exepath = gc(xasprintf("o/%d.%s", getpid(), basename(exename))); + g_exepath = _gc(xasprintf("o/%d.%s", getpid(), basename(exename))); INFOF("%s asked we run %`'s (%,u bytes @ %`'s)", addrstr, exename, filesize, g_exepath); @@ -567,7 +569,6 @@ int main(int argc, char *argv[]) { } else { CHECK_EQ(3, (g_bogusfd = open("/dev/zero", O_RDONLY | O_CLOEXEC))); } - defer(close_s, &g_bogusfd); if (!isdirectory("o")) CHECK_NE(-1, mkdir("o", 0700)); if (g_daemonize) Daemonize(); return Serve(); diff --git a/tool/build/strace.c b/tool/build/strace.c index 1b2852874..4ef2445b7 100644 --- a/tool/build/strace.c +++ b/tool/build/strace.c @@ -35,8 +35,7 @@ #include "libc/log/log.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/append.internal.h" -#include "libc/str/errfun.h" +#include "libc/stdio/append.h" #include "libc/str/str.h" #include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/ptrace.h" @@ -660,7 +659,7 @@ static void Flush(void) { static const char *GetErrnoName(int x) { const char *s; static char buf[16]; - if ((s = strerrno(x))) return s; + if ((s = _strerrno(x))) return s; FormatInt64(buf, x); return buf; } diff --git a/tool/build/touch.c b/tool/build/touch.c index 072a130c4..c161be7b5 100644 --- a/tool/build/touch.c +++ b/tool/build/touch.c @@ -20,7 +20,6 @@ #include "libc/errno.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" /** @@ -33,7 +32,7 @@ int main(int argc, char *argv[]) { prog = argc > 0 ? argv[0] : "touch.com"; for (i = 1; i < argc; ++i) { if (touch(argv[i], 0666) == -1) { - s = strerdoc(errno); + s = _strerdoc(errno); fputs(prog, stderr); fputs(": cannot touch '", stderr); fputs(argv[i], stderr); diff --git a/tool/build/unbuffer.c b/tool/build/unbuffer.c index 8d1eaa765..42492df13 100644 --- a/tool/build/unbuffer.c +++ b/tool/build/unbuffer.c @@ -22,9 +22,11 @@ #include "libc/calls/struct/winsize.h" #include "libc/calls/termios.h" #include "libc/calls/ttydefaults.h" +#include "libc/errno.h" #include "libc/intrin/kprintf.h" #include "libc/log/check.h" #include "libc/log/log.h" +#include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" diff --git a/tool/build/unbundle.c b/tool/build/unbundle.c index 5033cf546..e365741f8 100644 --- a/tool/build/unbundle.c +++ b/tool/build/unbundle.c @@ -23,7 +23,6 @@ #include "libc/fmt/itoa.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" #include "libc/sysv/consts/s.h" #include "libc/x/x.h" @@ -59,12 +58,12 @@ void Execute(char *argv[]) { int Visit(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { - if (tflag == FTW_F && endswith(fpath, ".gz")) { + if (tflag == FTW_F && _endswith(fpath, ".gz")) { Execute((char *[]){"build/bootstrap/gzip.com", "-d", fpath, 0}); strcpy(binpath, fpath); binpath[strlen(binpath) - 3] = 0; chmod(binpath, 0755); - } else if (tflag == FTW_F && endswith(fpath, ".sym")) { + } else if (tflag == FTW_F && _endswith(fpath, ".sym")) { strcpy(binpath, fpath); binpath[strlen(binpath) - 4] = 0; symlink(xslurp(fpath, 0), binpath); @@ -83,7 +82,7 @@ int main(int argc, char *argv[]) { if (nftw(tmpdir, Visit, 20, 0) == -1) { fputs(prog, stderr); fputs(": nftw failed: ", stderr); - fputs(strerdoc(errno), stderr); + fputs(_strerdoc(errno), stderr); fputs("\n", stderr); exit(1); } diff --git a/tool/build/xlat.c b/tool/build/xlat.c index 5f7d49555..68f298597 100644 --- a/tool/build/xlat.c +++ b/tool/build/xlat.c @@ -22,11 +22,11 @@ #include "libc/log/check.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" /** * @fileoverview Tool for generating rldecode'd character sets, e.g. @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) { for (i = 0; i < argc; ++i) { if (i) printf(" "); printf("%s", !ArgNeedsShellQuotes(argv[i]) ? argv[i] - : gc(AddShellQuotes(argv[i]))); + : _gc(AddShellQuotes(argv[i]))); } printf("\n"); @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) { } else { if (runcount) { printf("\t.byte\t%-24s# %02x-%02x %hc-%hc\n", - gc(xasprintf("%3d,%d", runcount, runchar)), runstart, + _gc(xasprintf("%3d,%d", runcount, runchar)), runstart, runstart + runcount - 1, Bing(runstart), Bing(runstart + runcount - 1)); thetally += 2; diff --git a/tool/build/zipobj.c b/tool/build/zipobj.c index b4c1a1192..0a0d880f2 100644 --- a/tool/build/zipobj.c +++ b/tool/build/zipobj.c @@ -24,7 +24,7 @@ #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/clock.h" @@ -138,7 +138,7 @@ void ProcessFile(struct ElfWriter *elf, const char *path) { } if (S_ISDIR(st.st_mode)) { st.st_size = 0; - if (!endswith(name, "/")) { + if (!_endswith(name, "/")) { name = gc(xstrcat(name, '/')); } } @@ -160,7 +160,7 @@ void PullEndOfCentralDirectoryIntoLinkage(struct ElfWriter *elf) { void CheckFilenameKosher(const char *path) { CHECK_LE(kZipCfileHdrMinSize + strlen(path), kZipCdirHdrLinkableSizeBootstrap); - CHECK(!startswith(path, "/")); + CHECK(!_startswith(path, "/")); CHECK(!strstr(path, "..")); } diff --git a/tool/decode/elf.c b/tool/decode/elf.c index 7a1a032c9..298694d87 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -16,8 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/elf/def.h" @@ -26,6 +24,8 @@ #include "libc/elf/struct/shdr.h" #include "libc/errno.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" @@ -36,7 +36,7 @@ #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "tool/decode/lib/asmcodegen.h" #include "tool/decode/lib/elfidnames.h" #include "tool/decode/lib/flagger.h" diff --git a/tool/decode/lib/asmcodegen.c b/tool/decode/lib/asmcodegen.c index be1957f0f..18dbeb34d 100644 --- a/tool/decode/lib/asmcodegen.c +++ b/tool/decode/lib/asmcodegen.c @@ -19,7 +19,7 @@ #include "libc/fmt/fmt.h" #include "libc/intrin/safemacros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "tool/decode/lib/asmcodegen.h" diff --git a/tool/decode/pe2.c b/tool/decode/pe2.c index 4fb519914..9036be814 100644 --- a/tool/decode/pe2.c +++ b/tool/decode/pe2.c @@ -24,12 +24,12 @@ #include "libc/nt/struct/imagedosheader.internal.h" #include "libc/nt/struct/imagentheaders.internal.h" #include "libc/nt/struct/imageoptionalheader.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/xed/x86.h" #include "tool/decode/lib/asmcodegen.h" #include "tool/decode/lib/flagger.h" @@ -181,7 +181,7 @@ static void showpeoptionalheader(struct NtImageOptionalHeader *opt) { show(".long", \ format(b1, "%#X,%u", opt->DataDirectory[x].VirtualAddress, \ opt->DataDirectory[x].Size), \ - gc(xasprintf("opt->DataDirectory[%s]", #x))); \ + _gc(xasprintf("opt->DataDirectory[%s]", #x))); \ } \ } while (0) @@ -212,7 +212,7 @@ static void ShowIlt(int64_t *ilt) { do { printf("\n"); show(".quad", format(b1, "%#lx", *ilt), - gc(xasprintf("@%#lx", (intptr_t)ilt - (intptr_t)mz))); + _gc(xasprintf("@%#lx", (intptr_t)ilt - (intptr_t)mz))); if (*ilt) { char *hint = (char *)((intptr_t)mz + *ilt); printf("/\t.short\t%d\t\t\t# @%#lx\n", READ16LE(hint), @@ -231,13 +231,13 @@ static void ShowIat(char *iat, size_t size) { for (p = iat, e = iat + size; p + 20 <= e; p += 20) { printf("\n"); show(".long", format(b1, "%#x", READ32LE(p)), - gc(xasprintf("ImportLookupTable RVA @%#lx", - (intptr_t)p - (intptr_t)mz))); + _gc(xasprintf("ImportLookupTable RVA @%#lx", + (intptr_t)p - (intptr_t)mz))); show(".long", format(b1, "%#x", READ32LE(p + 4)), "TimeDateStamp"); show(".long", format(b1, "%#x", READ32LE(p + 8)), "ForwarderChain"); show(".long", format(b1, "%#x", READ32LE(p + 12)), READ32LE(p + 12) - ? gc(xasprintf("DllName RVA (%s)", (char *)mz + READ32LE(p + 12))) + ? _gc(xasprintf("DllName RVA (%s)", (char *)mz + READ32LE(p + 12))) : "DllName RVA"); show(".long", format(b1, "%#x", READ32LE(p + 16)), "ImportAddressTable RVA"); diff --git a/tool/decode/scrubdox.c b/tool/decode/scrubdox.c index 9a302c926..6caf6a1b2 100644 --- a/tool/decode/scrubdox.c +++ b/tool/decode/scrubdox.c @@ -73,11 +73,13 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/strwidth.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xgetline.h" #define IsSpace(C) ((C) == ' ') #define IsPipe(C) ((C) == '|' || (C) == u'│') @@ -162,14 +164,14 @@ int main(int argc, char *argv[]) { } xn += 1000; L = xmalloc((yn + 2) * sizeof(*L)); - L[0] = utf8to16(gc(xasprintf(" %*s ", xn, " ")), -1, 0); + L[0] = utf8to16(_gc(xasprintf(" %*s ", xn, " ")), -1, 0); for (y = 0; y < yn; ++y) { s = xasprintf(" %s%*s ", T[y], xn - n, " "); L[y + 1] = utf8to16(s, -1, 0); free(T[y]); free(s); } - L[yn + 2 - 1] = utf8to16(gc(xasprintf(" %*s ", xn, " ")), -1, 0); + L[yn + 2 - 1] = utf8to16(_gc(xasprintf(" %*s ", xn, " ")), -1, 0); free(T); V = xcalloc((yn + 1) * (xn + 1), 1); for (y = 1; y <= yn; ++y) { diff --git a/tool/decode/x87.c b/tool/decode/x87.c index 304e19fd3..acb32bb5e 100644 --- a/tool/decode/x87.c +++ b/tool/decode/x87.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/tool/decode/xor.c b/tool/decode/xor.c index 32f4030cb..7e29142e7 100644 --- a/tool/decode/xor.c +++ b/tool/decode/xor.c @@ -5,7 +5,7 @@ │ • http://unlicense.org/ │ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/tool/decode/zip.c b/tool/decode/zip.c index 66ec4d443..839facd14 100644 --- a/tool/decode/zip.c +++ b/tool/decode/zip.c @@ -16,23 +16,24 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" #include "libc/nt/struct/filetime.h" -#include "libc/runtime/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xiso8601.h" #include "libc/zip.h" #include "tool/decode/lib/asmcodegen.h" #include "tool/decode/lib/disassemblehex.h" @@ -79,9 +80,9 @@ void ShowGeneralFlag(uint16_t generalflag) { void ShowTimestamp(uint16_t time, uint16_t date) { show(".short", format(b1, "%#04hx", time), - gc(xasprintf("%s (%s)", "lastmodifiedtime", gc(FormatDosTime(time))))); + _gc(xasprintf("%s (%s)", "lastmodifiedtime", _gc(FormatDosTime(time))))); show(".short", format(b1, "%#04hx", date), - gc(xasprintf("%s (%s)", "lastmodifieddate", gc(FormatDosDate(date))))); + _gc(xasprintf("%s (%s)", "lastmodifieddate", _gc(FormatDosDate(date))))); } void ShowCompressionMethod(uint16_t compressmethod) { @@ -96,18 +97,19 @@ void ShowNtfs(uint8_t *ntfs, size_t n) { mtime = WindowsTimeToTimeSpec(READ64LE(ntfs + 8)); atime = WindowsTimeToTimeSpec(READ64LE(ntfs + 16)); ctime = WindowsTimeToTimeSpec(READ64LE(ntfs + 24)); - show(".long", gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved"); - show(".short", gc(xasprintf("0x%04x", READ16LE(ntfs + 4))), + show(".long", _gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved"); + show(".short", _gc(xasprintf("0x%04x", READ16LE(ntfs + 4))), "ntfs attribute tag value #1"); - show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))), + show(".short", _gc(xasprintf("%hu", READ16LE(ntfs + 6))), "ntfs attribute tag size"); - show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))), - gc(xasprintf("%s (%s)", "ntfs last modified time", - gc(xiso8601(&mtime))))); - show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))), - gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime))))); - show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))), - gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime))))); + show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 8))), + _gc(xasprintf("%s (%s)", "ntfs last modified time", + _gc(xiso8601(&mtime))))); + show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 16))), + _gc(xasprintf("%s (%s)", "ntfs last access time", + _gc(xiso8601(&atime))))); + show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 24))), + _gc(xasprintf("%s (%s)", "ntfs creation time", _gc(xiso8601(&ctime))))); } void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) { @@ -115,28 +117,28 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) { if (n) { --n; flag = *p++; - show(".byte", gc(xasprintf("0b%03hhb", flag)), "fields present in local"); + show(".byte", _gc(xasprintf("0b%03hhb", flag)), "fields present in local"); if ((flag & 1) && n >= 4) { - show(".long", gc(xasprintf("%u", READ32LE(p))), - gc(xasprintf("%s (%s)", "last modified", - gc(xiso8601(&(struct timespec){READ32LE(p)}))))); + show(".long", _gc(xasprintf("%u", READ32LE(p))), + _gc(xasprintf("%s (%s)", "last modified", + _gc(xiso8601(&(struct timespec){READ32LE(p)}))))); p += 4; n -= 4; } flag >>= 1; if (islocal) { if ((flag & 1) && n >= 4) { - show(".long", gc(xasprintf("%u", READ32LE(p))), - gc(xasprintf("%s (%s)", "access time", - gc(xiso8601(&(struct timespec){READ32LE(p)}))))); + show(".long", _gc(xasprintf("%u", READ32LE(p))), + _gc(xasprintf("%s (%s)", "access time", + _gc(xiso8601(&(struct timespec){READ32LE(p)}))))); p += 4; n -= 4; } flag >>= 1; if ((flag & 1) && n >= 4) { - show(".long", gc(xasprintf("%u", READ32LE(p))), - gc(xasprintf("%s (%s)", "creation time", - gc(xiso8601(&(struct timespec){READ32LE(p)}))))); + show(".long", _gc(xasprintf("%u", READ32LE(p))), + _gc(xasprintf("%s (%s)", "creation time", + _gc(xiso8601(&(struct timespec){READ32LE(p)}))))); p += 4; n -= 4; } @@ -146,19 +148,19 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) { void ShowZip64(uint8_t *p, size_t n, bool islocal) { if (n >= 8) { - show(".quad", gc(xasprintf("%lu", READ64LE(p))), - gc(xasprintf("uncompressed size (%,ld)", READ64LE(p)))); + show(".quad", _gc(xasprintf("%lu", READ64LE(p))), + _gc(xasprintf("uncompressed size (%,ld)", READ64LE(p)))); } if (n >= 16) { - show(".quad", gc(xasprintf("%lu", READ64LE(p + 8))), - gc(xasprintf("compressed size (%,ld)", READ64LE(p + 8)))); + show(".quad", _gc(xasprintf("%lu", READ64LE(p + 8))), + _gc(xasprintf("compressed size (%,ld)", READ64LE(p + 8)))); } if (n >= 24) { - show(".quad", gc(xasprintf("%lu", READ64LE(p + 16))), - gc(xasprintf("lfile hdr offset (%,ld)", READ64LE(p + 16)))); + show(".quad", _gc(xasprintf("%lu", READ64LE(p + 16))), + _gc(xasprintf("lfile hdr offset (%,ld)", READ64LE(p + 16)))); } if (n >= 28) { - show(".long", gc(xasprintf("%u", READ32LE(p + 24))), "disk number"); + show(".long", _gc(xasprintf("%u", READ32LE(p + 24))), "disk number"); } } @@ -166,9 +168,9 @@ void ShowInfoZipNewUnixExtra(uint8_t *p, size_t n, bool islocal) { if (p[0] == 1 && p[1] == 4 && p[6] == 4) { show(".byte", "1", "version"); show(".byte", "4", "uid length"); - show(".long", gc(xasprintf("%u", READ32LE(p + 2))), "uid"); + show(".long", _gc(xasprintf("%u", READ32LE(p + 2))), "uid"); show(".byte", "4", "gid length"); - show(".long", gc(xasprintf("%u", READ32LE(p + 7))), "gid"); + show(".long", _gc(xasprintf("%u", READ32LE(p + 7))), "gid"); } else { disassemblehex(p, n, stdout); } @@ -220,11 +222,11 @@ void ShowExtras(uint8_t *extras, uint16_t extrassize, bool islocal) { p += ZIP_EXTRA_SIZE(p), ++i) { show(".short", firstnonnull(findnamebyid(kZipExtraNames, ZIP_EXTRA_HEADERID(p)), - gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))), - gc(xasprintf("%s[%d].%s", "extras", i, "headerid"))); - show(".short", gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)), - gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize", - ZIP_EXTRA_CONTENTSIZE(p), "bytes"))); + _gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))), + _gc(xasprintf("%s[%d].%s", "extras", i, "headerid"))); + show(".short", _gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)), + _gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize", + ZIP_EXTRA_CONTENTSIZE(p), "bytes"))); if (first) { first = false; printf("%d:", (i + 1) * 10); @@ -242,18 +244,18 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) { show(".ascii", format(b1, "%`'.*s", 4, lf), "magic"); show(".byte", firstnonnull(findnamebyid(kZipEraNames, ZIP_LFILE_VERSIONNEED(lf)), - gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))), + _gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))), "pkzip version need"); show(".byte", firstnonnull(findnamebyid(kZipOsNames, ZIP_LFILE_OSNEED(lf)), - gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))), + _gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))), "os need"); ShowGeneralFlag(ZIP_LFILE_GENERALFLAG(lf)); ShowCompressionMethod(ZIP_LFILE_COMPRESSIONMETHOD(lf)); ShowTimestamp(ZIP_LFILE_LASTMODIFIEDTIME(lf), ZIP_LFILE_LASTMODIFIEDDATE(lf)); show( ".long", - format(b1, "%#x", ZIP_LFILE_CRC32(lf)), gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */))); + format(b1, "%#x", ZIP_LFILE_CRC32(lf)), _gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */))); if (ZIP_LFILE_COMPRESSEDSIZE(lf) == 0xFFFFFFFF) { show(".long", "0xFFFFFFFF", "compressedsize (zip64)"); } else { @@ -274,7 +276,7 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) { printf("0:"); show(".ascii", format(b1, "%`'s", - gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))), + _gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))), "name"); printf("1:"); ShowExtras(ZIP_LFILE_EXTRA(lf), ZIP_LFILE_EXTRASIZE(lf), true); @@ -288,19 +290,19 @@ void ShowCentralFileHeader(uint8_t *cf) { printf("\n/\t%s (%zu %s)\n", "central directory file header", ZIP_CFILE_HDRSIZE(cf), "bytes"); show(".ascii", format(b1, "%`'.*s", 4, cf), "magic"); - show(".byte", gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))), + show(".byte", _gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))), "zip version made"); show(".byte", firstnonnull(findnamebyid(kZipOsNames, ZIP_CFILE_FILEATTRCOMPAT(cf)), - gc(xasprintf("%d", ZIP_CFILE_FILEATTRCOMPAT(cf)))), + _gc(xasprintf("%d", ZIP_CFILE_FILEATTRCOMPAT(cf)))), "file attr compat"); show(".byte", firstnonnull(findnamebyid(kZipEraNames, ZIP_CFILE_VERSIONNEED(cf)), - gc(xasprintf("%d", ZIP_CFILE_VERSIONNEED(cf)))), + _gc(xasprintf("%d", ZIP_CFILE_VERSIONNEED(cf)))), "pkzip version need"); show(".byte", firstnonnull(findnamebyid(kZipOsNames, ZIP_CFILE_OSNEED(cf)), - gc(xasprintf("%d", ZIP_CFILE_OSNEED(cf)))), + _gc(xasprintf("%d", ZIP_CFILE_OSNEED(cf)))), "os need"); ShowGeneralFlag(ZIP_CFILE_GENERALFLAG(cf)); ShowCompressionMethod(ZIP_CFILE_COMPRESSIONMETHOD(cf)); @@ -339,7 +341,7 @@ void ShowCentralFileHeader(uint8_t *cf) { printf("0:"); show(".ascii", format(b1, "%`'s", - gc(strndup(ZIP_CFILE_NAME(cf), ZIP_CFILE_NAMESIZE(cf)))), + _gc(strndup(ZIP_CFILE_NAME(cf), ZIP_CFILE_NAMESIZE(cf)))), "name"); printf("1:"); ShowExtras(ZIP_CFILE_EXTRA(cf), ZIP_CFILE_EXTRASIZE(cf), false); @@ -427,7 +429,7 @@ void DisassembleZip(const char *path, uint8_t *p, size_t n) { uint16_t i; static int records; uint8_t *eocd32, *eocd64, *cdir, *cf, *lf, *q; - if (endswith(path, ".com.dbg") && (q = memmem(p, n, "MZqFpD", 6))) { + if (_endswith(path, ".com.dbg") && (q = memmem(p, n, "MZqFpD", 6))) { n -= q - p; p += q - p; } diff --git a/tool/decode/zip2.c b/tool/decode/zip2.c index 2bfd656ac..16dfc5bf2 100644 --- a/tool/decode/zip2.c +++ b/tool/decode/zip2.c @@ -16,19 +16,20 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/fmt/conv.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" +#include "libc/x/xiso8601.h" #include "libc/zip.h" #include "tool/decode/lib/asmcodegen.h" #include "tool/decode/lib/disassemblehex.h" @@ -65,9 +66,9 @@ void ShowCompressionMethod(uint16_t compressmethod) { void ShowTimestamp(uint16_t time, uint16_t date) { show(".short", format(b1, "%#04hx", time), - gc(xasprintf("%s (%s)", "lastmodifiedtime", gc(FormatDosTime(time))))); + _gc(xasprintf("%s (%s)", "lastmodifiedtime", _gc(FormatDosTime(time))))); show(".short", format(b1, "%#04hx", date), - gc(xasprintf("%s (%s)", "lastmodifieddate", gc(FormatDosDate(date))))); + _gc(xasprintf("%s (%s)", "lastmodifieddate", _gc(FormatDosDate(date))))); } void ShowNtfs(uint8_t *ntfs, size_t n) { @@ -75,18 +76,19 @@ void ShowNtfs(uint8_t *ntfs, size_t n) { mtime = WindowsTimeToTimeSpec(READ64LE(ntfs + 8)); atime = WindowsTimeToTimeSpec(READ64LE(ntfs + 16)); ctime = WindowsTimeToTimeSpec(READ64LE(ntfs + 24)); - show(".long", gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved"); - show(".short", gc(xasprintf("0x%04x", READ16LE(ntfs + 4))), + show(".long", _gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved"); + show(".short", _gc(xasprintf("0x%04x", READ16LE(ntfs + 4))), "ntfs attribute tag value #1"); - show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))), + show(".short", _gc(xasprintf("%hu", READ16LE(ntfs + 6))), "ntfs attribute tag size"); - show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))), - gc(xasprintf("%s (%s)", "ntfs last modified time", - gc(xiso8601(&mtime))))); - show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))), - gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime))))); - show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))), - gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime))))); + show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 8))), + _gc(xasprintf("%s (%s)", "ntfs last modified time", + _gc(xiso8601(&mtime))))); + show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 16))), + _gc(xasprintf("%s (%s)", "ntfs last access time", + _gc(xiso8601(&atime))))); + show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 24))), + _gc(xasprintf("%s (%s)", "ntfs creation time", _gc(xiso8601(&ctime))))); } void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) { @@ -94,28 +96,28 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) { if (n) { --n; flag = *p++; - show(".byte", gc(xasprintf("0b%03hhb", flag)), "fields present in local"); + show(".byte", _gc(xasprintf("0b%03hhb", flag)), "fields present in local"); if ((flag & 1) && n >= 4) { - show(".long", gc(xasprintf("%u", READ32LE(p))), - gc(xasprintf("%s (%s)", "last modified", - gc(xiso8601(&(struct timespec){READ32LE(p)}))))); + show(".long", _gc(xasprintf("%u", READ32LE(p))), + _gc(xasprintf("%s (%s)", "last modified", + _gc(xiso8601(&(struct timespec){READ32LE(p)}))))); p += 4; n -= 4; } flag >>= 1; if (islocal) { if ((flag & 1) && n >= 4) { - show(".long", gc(xasprintf("%u", READ32LE(p))), - gc(xasprintf("%s (%s)", "access time", - gc(xiso8601(&(struct timespec){READ32LE(p)}))))); + show(".long", _gc(xasprintf("%u", READ32LE(p))), + _gc(xasprintf("%s (%s)", "access time", + _gc(xiso8601(&(struct timespec){READ32LE(p)}))))); p += 4; n -= 4; } flag >>= 1; if ((flag & 1) && n >= 4) { - show(".long", gc(xasprintf("%u", READ32LE(p))), - gc(xasprintf("%s (%s)", "creation time", - gc(xiso8601(&(struct timespec){READ32LE(p)}))))); + show(".long", _gc(xasprintf("%u", READ32LE(p))), + _gc(xasprintf("%s (%s)", "creation time", + _gc(xiso8601(&(struct timespec){READ32LE(p)}))))); p += 4; n -= 4; } @@ -125,19 +127,19 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) { void ShowZip64(uint8_t *p, size_t n, bool islocal) { if (n >= 8) { - show(".quad", gc(xasprintf("%lu", READ64LE(p))), - gc(xasprintf("uncompressed size (%,ld)", READ64LE(p)))); + show(".quad", _gc(xasprintf("%lu", READ64LE(p))), + _gc(xasprintf("uncompressed size (%,ld)", READ64LE(p)))); } if (n >= 16) { - show(".quad", gc(xasprintf("%lu", READ64LE(p + 8))), - gc(xasprintf("compressed size (%,ld)", READ64LE(p + 8)))); + show(".quad", _gc(xasprintf("%lu", READ64LE(p + 8))), + _gc(xasprintf("compressed size (%,ld)", READ64LE(p + 8)))); } if (n >= 24) { - show(".quad", gc(xasprintf("%lu", READ64LE(p + 16))), - gc(xasprintf("lfile hdr offset (%,ld)", READ64LE(p + 16)))); + show(".quad", _gc(xasprintf("%lu", READ64LE(p + 16))), + _gc(xasprintf("lfile hdr offset (%,ld)", READ64LE(p + 16)))); } if (n >= 28) { - show(".long", gc(xasprintf("%u", READ32LE(p + 24))), "disk number"); + show(".long", _gc(xasprintf("%u", READ32LE(p + 24))), "disk number"); } } @@ -145,9 +147,9 @@ void ShowInfoZipNewUnixExtra(uint8_t *p, size_t n, bool islocal) { if (p[0] == 1 && p[1] == 4 && p[6] == 4) { show(".byte", "1", "version"); show(".byte", "4", "uid length"); - show(".long", gc(xasprintf("%u", READ32LE(p + 2))), "uid"); + show(".long", _gc(xasprintf("%u", READ32LE(p + 2))), "uid"); show(".byte", "4", "gid length"); - show(".long", gc(xasprintf("%u", READ32LE(p + 7))), "gid"); + show(".long", _gc(xasprintf("%u", READ32LE(p + 7))), "gid"); } else { disassemblehex(p, n, stdout); } @@ -187,11 +189,11 @@ void ShowExtras(uint8_t *extras, uint16_t extrassize, bool islocal) { p += ZIP_EXTRA_SIZE(p), ++i) { show(".short", firstnonnull(findnamebyid(kZipExtraNames, ZIP_EXTRA_HEADERID(p)), - gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))), - gc(xasprintf("%s[%d].%s", "extras", i, "headerid"))); - show(".short", gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)), - gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize", - ZIP_EXTRA_CONTENTSIZE(p), "bytes"))); + _gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))), + _gc(xasprintf("%s[%d].%s", "extras", i, "headerid"))); + show(".short", _gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)), + _gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize", + ZIP_EXTRA_CONTENTSIZE(p), "bytes"))); if (first) { first = false; printf("%d:", (i + 1) * 10); @@ -209,18 +211,18 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) { show(".ascii", format(b1, "%`'.*s", 4, lf), "magic"); show(".byte", firstnonnull(findnamebyid(kZipEraNames, ZIP_LFILE_VERSIONNEED(lf)), - gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))), + _gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))), "pkzip version need"); show(".byte", firstnonnull(findnamebyid(kZipOsNames, ZIP_LFILE_OSNEED(lf)), - gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))), + _gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))), "os need"); ShowGeneralFlag(ZIP_LFILE_GENERALFLAG(lf)); ShowCompressionMethod(ZIP_LFILE_COMPRESSIONMETHOD(lf)); ShowTimestamp(ZIP_LFILE_LASTMODIFIEDTIME(lf), ZIP_LFILE_LASTMODIFIEDDATE(lf)); show( ".long", - format(b1, "%#x", ZIP_LFILE_CRC32(lf)), gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */))); + format(b1, "%#x", ZIP_LFILE_CRC32(lf)), _gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */))); if (ZIP_LFILE_COMPRESSEDSIZE(lf) == 0xFFFFFFFF) { show(".long", "0xFFFFFFFF", "compressedsize (zip64)"); } else { @@ -241,7 +243,7 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) { printf("0:"); show(".ascii", format(b1, "%`'s", - gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))), + _gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))), "name"); printf("1:"); ShowExtras(ZIP_LFILE_EXTRA(lf), ZIP_LFILE_EXTRASIZE(lf), true); diff --git a/tool/net/fetch.inc b/tool/net/fetch.inc index 1bc304fed..46f0e4a6a 100644 --- a/tool/net/fetch.inc +++ b/tool/net/fetch.inc @@ -64,7 +64,7 @@ static int LuaFetch(lua_State *L) { return LuaNilError(L, "invalid header name: %s", key); val = lua_tolstring(L, -1, &vallen); - if (!(hdr = gc(EncodeHttpHeaderValue(val, vallen, 0)))) + if (!(hdr = _gc(EncodeHttpHeaderValue(val, vallen, 0)))) return LuaNilError(L, "invalid header %s value encoding", key); // Content-Length and Connection will be overwritten; @@ -101,14 +101,14 @@ static int LuaFetch(lua_State *L) { if (bodylen > 0 || !(methodidx == kHttpGet || methodidx == kHttpHead || methodidx == kHttpTrace || methodidx == kHttpDelete || methodidx == kHttpConnect)) { - conlenhdr = gc(xasprintf("Content-Length: %zu\r\n", bodylen)); + conlenhdr = _gc(xasprintf("Content-Length: %zu\r\n", bodylen)); } /* * Parse URL. */ - gc(ParseUrl(urlarg, urlarglen, &url)); - gc(url.params.p); + _gc(ParseUrl(urlarg, urlarglen, &url)); + _gc(url.params.p); usingssl = false; if (url.scheme.n) { #ifndef UNSECURE @@ -127,9 +127,9 @@ static int LuaFetch(lua_State *L) { #endif if (url.host.n) { - host = gc(strndup(url.host.p, url.host.n)); + host = _gc(strndup(url.host.p, url.host.n)); if (url.port.n) { - port = gc(strndup(url.port.p, url.port.n)); + port = _gc(strndup(url.port.p, url.port.n)); #ifndef UNSECURE } else if (usingssl) { port = "443"; @@ -146,7 +146,7 @@ static int LuaFetch(lua_State *L) { if (!IsAcceptableHost(host, -1)) { return LuaNilError(L, "invalid host"); } - if (!hosthdr) hosthdr = gc(xasprintf("%s:%s", host, port)); + if (!hosthdr) hosthdr = _gc(xasprintf("%s:%s", host, port)); url.fragment.p = 0, url.fragment.n = 0; url.scheme.p = 0, url.scheme.n = 0; @@ -155,7 +155,7 @@ static int LuaFetch(lua_State *L) { url.host.p = 0, url.host.n = 0; url.port.p = 0, url.port.n = 0; if (!url.path.n || url.path.p[0] != '/') { - p = gc(xmalloc(1 + url.path.n)); + p = _gc(xmalloc(1 + url.path.n)); mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n); url.path.p = p; ++url.path.n; @@ -164,14 +164,14 @@ static int LuaFetch(lua_State *L) { /* * Create HTTP message. */ - request = gc(xasprintf("%s %s HTTP/1.1\r\n" - "Host: %s\r\n" - "Connection: close\r\n" - "User-Agent: %s\r\n" - "%s%s" - "\r\n%s", - method, gc(EncodeUrl(&url, 0)), hosthdr, agenthdr, - conlenhdr, headers ? headers : "", body)); + request = _gc(xasprintf("%s %s HTTP/1.1\r\n" + "Host: %s\r\n" + "Connection: close\r\n" + "User-Agent: %s\r\n" + "%s%s" + "\r\n%s", + method, _gc(EncodeUrl(&url, 0)), hosthdr, agenthdr, + conlenhdr, headers ? headers : "", body)); requestlen = strlen(request); /* @@ -211,7 +211,7 @@ static int LuaFetch(lua_State *L) { if (!evadedragnetsurveillance) { mbedtls_ssl_set_hostname(&sslcli, host); } - bio = gc(malloc(sizeof(struct TlsBio))); + bio = _gc(malloc(sizeof(struct TlsBio))); bio->fd = sock; bio->a = 0; bio->b = 0; @@ -443,7 +443,7 @@ VerifyFailed: LockInc(&shared->c.sslverifyfailed); close(sock); return LuaNilTlsError( - L, gc(DescribeSslVerifyFailure(sslcli.session_negotiate->verify_result)), + L, _gc(DescribeSslVerifyFailure(sslcli.session_negotiate->verify_result)), ret); #endif #undef ssl diff --git a/tool/net/lfuncs.c b/tool/net/lfuncs.c index 2b548b5fe..25961845f 100644 --- a/tool/net/lfuncs.c +++ b/tool/net/lfuncs.c @@ -25,19 +25,19 @@ #include "libc/fmt/itoa.h" #include "libc/fmt/leb128.h" #include "libc/intrin/bits.h" +#include "libc/intrin/bsf.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/popcnt.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/bench.h" -#include "libc/nexgen32e/bsf.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/nexgen32e/rdtscp.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/sysconf.h" #include "libc/sock/sock.h" @@ -316,7 +316,7 @@ int LuaPopcnt(lua_State *L) { int LuaBsr(lua_State *L) { long x; if ((x = luaL_checkinteger(L, 1))) { - lua_pushinteger(L, bsrl(x)); + lua_pushinteger(L, _bsrl(x)); return 1; } else { luaL_argerror(L, 1, "zero"); @@ -327,7 +327,7 @@ int LuaBsr(lua_State *L) { int LuaBsf(lua_State *L) { long x; if ((x = luaL_checkinteger(L, 1))) { - lua_pushinteger(L, bsfl(x)); + lua_pushinteger(L, _bsfl(x)); return 1; } else { luaL_argerror(L, 1, "zero"); diff --git a/tool/net/ljson.c b/tool/net/ljson.c index ac998c7f0..efb20606a 100644 --- a/tool/net/ljson.c +++ b/tool/net/ljson.c @@ -22,7 +22,6 @@ #include "libc/log/log.h" #include "libc/runtime/stack.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/str/utf16.h" #include "third_party/double-conversion/wrapper.h" #include "third_party/lua/cosmo.h" diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 15775acff..b0f10d9a2 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -35,16 +35,18 @@ #include "libc/fmt/conv.h" #include "libc/fmt/itoa.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/bsr.h" #include "libc/intrin/likely.h" #include "libc/intrin/nomultics.internal.h" #include "libc/intrin/safemacros.internal.h" +#include "libc/log/appendresourcereport.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/mem/alloca.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/nt2sysv.h" #include "libc/nexgen32e/rdtsc.h" @@ -52,8 +54,6 @@ #include "libc/nt/enum/fileflagandattributes.h" #include "libc/nt/thread.h" #include "libc/runtime/clktck.h" -#include "libc/runtime/gc.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" @@ -61,7 +61,7 @@ #include "libc/sock/goodsocket.internal.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/hex.internal.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" @@ -93,6 +93,7 @@ #include "libc/thread/thread.h" #include "libc/thread/tls.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "libc/zip.h" #include "net/http/escape.h" #include "net/http/http.h" @@ -642,7 +643,7 @@ static void UseCertificate(mbedtls_ssl_config *c, struct Cert *kp, const char *role) { VERBOSEF("(ssl) using %s certificate %`'s for HTTPS %s", mbedtls_pk_get_name(&kp->cert->pk), - gc(FormatX509Name(&kp->cert->subject)), role); + _gc(FormatX509Name(&kp->cert->subject)), role); CHECK_EQ(0, mbedtls_ssl_conf_own_cert(c, kp->cert, kp->key)); } @@ -659,21 +660,21 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) { if (prev) { if (mbedtls_x509_crt_check_parent(prev, cert, 1)) { DEBUGF("(ssl) unbundling %`'s from %`'s", - gc(FormatX509Name(&prev->subject)), - gc(FormatX509Name(&cert->subject))); + _gc(FormatX509Name(&prev->subject)), + _gc(FormatX509Name(&cert->subject))); prev->next = 0; } else if ((r = mbedtls_x509_crt_check_signature(prev, cert, 0))) { WARNF("(ssl) invalid signature for %`'s -> %`'s (-0x%04x)", - gc(FormatX509Name(&prev->subject)), - gc(FormatX509Name(&cert->subject)), -r); + _gc(FormatX509Name(&prev->subject)), + _gc(FormatX509Name(&cert->subject)), -r); } } if (mbedtls_x509_time_is_past(&cert->valid_to)) { WARNF("(ssl) certificate %`'s is expired", - gc(FormatX509Name(&cert->subject))); + _gc(FormatX509Name(&cert->subject))); } else if (mbedtls_x509_time_is_future(&cert->valid_from)) { WARNF("(ssl) certificate %`'s is from the future", - gc(FormatX509Name(&cert->subject))); + _gc(FormatX509Name(&cert->subject))); } for (i = 0; i < certs.n; ++i) { if (!certs.p[i].cert) continue; @@ -682,7 +683,7 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) { !mbedtls_x509_name_cmp(&cert->subject, &certs.p[i].cert->subject)) { VERBOSEF("(ssl) %s %`'s is already loaded", mbedtls_pk_get_name(&cert->pk), - gc(FormatX509Name(&cert->subject))); + _gc(FormatX509Name(&cert->subject))); return; } } @@ -951,8 +952,8 @@ static void ProgramCache(long x) { } static void SetDefaults(void) { - ProgramBrand(gc(xasprintf("%s/%hhd.%hhd.%hhd", REDBEAN, VERSION >> 020, - VERSION >> 010, VERSION >> 000))); + ProgramBrand(_gc(xasprintf("%s/%hhd.%hhd.%hhd", REDBEAN, VERSION >> 020, + VERSION >> 010, VERSION >> 000))); __log_level = kLogInfo; maxpayloadsize = 64 * 1024; ProgramCache(-1); @@ -1078,7 +1079,7 @@ static bool LuaEvalCode(const char *code) { } static bool LuaEvalFile(const char *path) { - char *f = gc(xslurp(path, 0)); + char *f = _gc(xslurp(path, 0)); if (!f) FATALF("(cfg) error: failed to read file %`'s", path); return LuaEvalCode(f); } @@ -1603,7 +1604,7 @@ static bool TlsRouteFind(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl, 0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key)); DEBUGF("(ssl) TlsRoute(%s, %`'.*s) %s %`'s", mbedtls_pk_type_name(type), size, host, mbedtls_pk_get_name(&certs.p[i].cert->pk), - gc(FormatX509Name(&certs.p[i].cert->subject))); + _gc(FormatX509Name(&certs.p[i].cert->subject))); return true; } } @@ -1618,7 +1619,7 @@ static bool TlsRouteFirst(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl) { 0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key)); DEBUGF("(ssl) TlsRoute(%s) %s %`'s", mbedtls_pk_type_name(type), mbedtls_pk_get_name(&certs.p[i].cert->pk), - gc(FormatX509Name(&certs.p[i].cert->subject))); + _gc(FormatX509Name(&certs.p[i].cert->subject))); return true; } } @@ -1683,7 +1684,7 @@ static bool TlsSetup(void) { ssl.session->compression ? " COMPRESSED" : "", ssl.curve ? ssl.curve->name : "uncurved"); DEBUGF("(ssl) client ciphersuite preference was %s", - gc(FormatSslClientCiphers(&ssl))); + _gc(FormatSslClientCiphers(&ssl))); return true; } else if (r == MBEDTLS_ERR_SSL_WANT_READ) { LockInc(&shared->c.handshakeinterrupts); @@ -1707,12 +1708,12 @@ static bool TlsSetup(void) { case MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN: LockInc(&shared->c.sslnociphers); WARNF("(ssl) %s %s %s", DescribeClient(), "sslnociphers", - gc(FormatSslClientCiphers(&ssl))); + _gc(FormatSslClientCiphers(&ssl))); return false; case MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE: LockInc(&shared->c.sslcantciphers); WARNF("(ssl) %s %s %s", DescribeClient(), "sslcantciphers", - gc(FormatSslClientCiphers(&ssl))); + _gc(FormatSslClientCiphers(&ssl))); return false; case MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION: LockInc(&shared->c.sslnoversion); @@ -1731,7 +1732,7 @@ static bool TlsSetup(void) { case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED: LockInc(&shared->c.sslverifyfailed); WARNF("(ssl) %s SSL %s", DescribeClient(), - gc(DescribeSslVerifyFailure( + _gc(DescribeSslVerifyFailure( ssl.session_negotiate->verify_result))); return false; case MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE: @@ -1791,7 +1792,7 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca, san[nsan - 2].tag = MBEDTLS_X509_SAN_DNS_NAME; san[nsan - 2].val = s; san[nsan - 1].tag = MBEDTLS_X509_SAN_DNS_NAME; - san[nsan - 1].val = gc(xasprintf("*.%s", s)); + san[nsan - 1].val = _gc(xasprintf("*.%s", s)); } } } @@ -1904,7 +1905,7 @@ static void LoadCertificates(void) { if (!havecert && (!psks.n || ksk.key)) { if ((ksk = GetKeySigningKey()).key) { DEBUGF("(ssl) generating ssl certificates using %`'s", - gc(FormatX509Name(&ksk.cert->subject))); + _gc(FormatX509Name(&ksk.cert->subject))); } else { VERBOSEF("(ssl) could not find non-CA SSL certificate key pair with" " -addext keyUsage=digitalSignature" @@ -2013,7 +2014,7 @@ static void IndexAssets(void) { CHECK(READ32LE(zcdir) == kZipCdir64HdrMagic || READ32LE(zcdir) == kZipCdirHdrMagic); n = GetZipCdirRecords(zcdir); - m = roundup2pow(MAX(1, n) * HASH_LOAD_FACTOR); + m = _roundup2pow(MAX(1, n) * HASH_LOAD_FACTOR); p = xcalloc(m, sizeof(struct Asset)); for (cf = GetZipCdirOffset(zcdir); n--; cf += ZIP_CFILE_HDRSIZE(zbase + cf)) { CHECK_EQ(kZipCfileHdrMagic, ZIP_CFILE_MAGIC(zbase + cf)); @@ -2151,11 +2152,11 @@ static char *AppendHeader(char *p, const char *k, const char *v) { static char *AppendContentType(char *p, const char *ct) { p = stpcpy(p, "Content-Type: "); p = stpcpy(p, ct); - if ((cpm.istext = startswith(ct, "text/"))) { + if ((cpm.istext = _startswith(ct, "text/"))) { if (!strchr(ct + 5, ';')) { p = stpcpy(p, "; charset=utf-8"); } - if (!cpm.referrerpolicy && startswith(ct + 5, "html")) { + if (!cpm.referrerpolicy && _startswith(ct + 5, "html")) { cpm.referrerpolicy = "no-referrer-when-downgrade"; } } @@ -2766,10 +2767,10 @@ static void LaunchBrowser(const char *path) { } // assign a loopback address if no server or unknown server address if (!servers.n || !addr.s_addr) addr.s_addr = htonl(INADDR_LOOPBACK); - if (*path != '/') path = gc(xasprintf("/%s", path)); - if ((prog = commandv(GetSystemUrlLauncherCommand(), gc(malloc(PATH_MAX)), + if (*path != '/') path = _gc(xasprintf("/%s", path)); + if ((prog = commandv(GetSystemUrlLauncherCommand(), _gc(malloc(PATH_MAX)), PATH_MAX))) { - u = gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path)); + u = _gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path)); DEBUGF("(srvr) opening browser with command %`'s %s", prog, u); ignore.sa_flags = 0; ignore.sa_handler = SIG_IGN; @@ -2815,7 +2816,7 @@ static int GetDecimalWidth(long x) { } static int GetOctalWidth(int x) { - return !x ? 1 : x < 8 ? 2 : 1 + bsr(x) / 3; + return !x ? 1 : x < 8 ? 2 : 1 + _bsr(x) / 3; } static const char *DescribeCompressionRatio(char rb[8], uint8_t *zcf) { @@ -3405,7 +3406,7 @@ static int LuaGetSslIdentity(lua_State *L) { psks.p[sslpskindex - 1].identity_len); } else { cert = mbedtls_ssl_get_peer_cert(&ssl); - lua_pushstring(L, cert ? gc(FormatX509Name(&cert->subject)) : ""); + lua_pushstring(L, cert ? _gc(FormatX509Name(&cert->subject)) : ""); } } return 1; @@ -3654,7 +3655,7 @@ static void StoreFile(char *path) { size_t plen, tlen; struct stat st; char *target = path; - if (startswith(target, "./")) target += 2; + if (_startswith(target, "./")) target += 2; tlen = strlen(target); if (!IsReasonablePath(target, tlen)) FATALF("(cfg) error: can't store %`'s: contains '.' or '..' segments", @@ -3670,13 +3671,13 @@ static void StorePath(const char *dirpath) { DIR *d; char *path; struct dirent *e; - if (!isdirectory(dirpath) && !endswith(dirpath, "/")) + if (!isdirectory(dirpath) && !_endswith(dirpath, "/")) return StoreFile(dirpath); if (!(d = opendir(dirpath))) FATALF("(cfg) error: can't open %`'s", dirpath); while ((e = readdir(d))) { if (strcmp(e->d_name, ".") == 0) continue; if (strcmp(e->d_name, "..") == 0) continue; - path = gc(xjoinpaths(dirpath, e->d_name)); + path = _gc(xjoinpaths(dirpath, e->d_name)); if (e->d_type == DT_DIR) { StorePath(path); } else { @@ -3748,7 +3749,7 @@ static int LuaNilError(lua_State *L, const char *fmt, ...) { static int LuaNilTlsError(lua_State *L, const char *s, int r) { return LuaNilError(L, "tls %s failed (%s %s)", s, IsTiny() ? "grep" : GetTlsError(r), - gc(xasprintf("-0x%04x", -r))); + _gc(xasprintf("-0x%04x", -r))); } #include "tool/net/fetch.inc" @@ -3815,7 +3816,7 @@ static int LuaLog(lua_State *L) { module = ar.short_src; line = ar.currentline; } else { - module = gc(strndup(effectivepath.p, effectivepath.n)); + module = _gc(strndup(effectivepath.p, effectivepath.n)); line = -1; } flogf(level, module, line, NULL, "%s", msg); @@ -4117,7 +4118,7 @@ static int LuaSetHeader(lua_State *L) { static int LuaGetCookie(lua_State *L) { char *cookie = 0, *cookietmpl, *cookieval; OnlyCallDuringRequest(L, "GetCookie"); - cookietmpl = gc(xasprintf(" %s=", luaL_checkstring(L, 1))); + cookietmpl = _gc(xasprintf(" %s=", luaL_checkstring(L, 1))); if (HasHeader(kHttpCookie)) { appends(&cookie, " "); // prepend space to simplify cookie search appendd(&cookie, HeaderData(kHttpCookie), HeaderLength(kHttpCookie)); @@ -4162,7 +4163,7 @@ static int LuaSetCookie(lua_State *L) { if ((ishostpref || issecurepref) && !usingssl) { luaL_argerror( L, 1, - gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref))); + _gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref))); unreachable; } @@ -4474,7 +4475,7 @@ static int LuaProgramCertificate(lua_State *L) { static int LuaProgramHeader(lua_State *L) { ProgramHeader( - gc(xasprintf("%s: %s", luaL_checkstring(L, 1), luaL_checkstring(L, 2)))); + _gc(xasprintf("%s: %s", luaL_checkstring(L, 1), luaL_checkstring(L, 2)))); return 0; } @@ -4554,7 +4555,7 @@ static int LuaGetZipPaths(lua_State *L) { zcf += ZIP_CFILE_HDRSIZE(zcf)) { CHECK_EQ(kZipCfileHdrMagic, ZIP_CFILE_MAGIC(zcf)); path = GetAssetPath(zcf, &pathlen); - if (prefixlen == 0 || startswith(path, prefix)) { + if (prefixlen == 0 || _startswith(path, prefix)) { lua_pushlstring(L, path, pathlen); lua_seti(L, -2, ++i); } @@ -5844,7 +5845,7 @@ static char *ServeAsset(struct Asset *a, const char *path, size_t pathlen) { } } else if (!IsTiny() && cpm.msg.method != kHttpHead && !IsSslCompressed() && ClientAcceptsGzip() && - ((cpm.contentlength >= 100 && startswithi(ct, "text/")) || + ((cpm.contentlength >= 100 && _startswithi(ct, "text/")) || (cpm.contentlength >= 1000 && MeasureEntropy(cpm.content, 1000) < 7))) { p = ServeAssetCompressed(a); @@ -6324,7 +6325,7 @@ static int MemoryMonitor(void *arg, int tid) { ws.ws_col = 80; ws.ws_row = 40; - getttysize(tty, &ws); + _getttysize(tty, &ws); appendr(&b, 0); appends(&b, "\e[H\e[1m"); @@ -6542,7 +6543,7 @@ static void MakeExecutableModifiable(void) { if (IsWindows()) return; // TODO if (IsOpenbsd()) return; // TODO if (IsNetbsd()) return; // TODO - if (endswith(zpath, ".com.dbg")) return; + if (_endswith(zpath, ".com.dbg")) return; close(zfd); ft = __ftrace; if ((zfd = OpenExecutable()) == -1) { diff --git a/tool/net/wb.c b/tool/net/wb.c index da66f3e5e..25e6c0a7a 100644 --- a/tool/net/wb.c +++ b/tool/net/wb.c @@ -25,12 +25,12 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/sock/goodsocket.internal.h" #include "libc/sock/sock.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/slice.h" #include "libc/str/str.h" @@ -45,6 +45,7 @@ #include "libc/sysv/consts/tcp.h" #include "libc/time/time.h" #include "libc/x/x.h" +#include "libc/x/xsigaction.h" #include "net/http/http.h" #include "net/http/url.h" #include "net/https/https.h" @@ -400,8 +401,8 @@ int main(int argc, char *argv[]) { /* * Parse URL. */ - gc(ParseUrl(urlarg, -1, &url)); - gc(url.params.p); + _gc(ParseUrl(urlarg, -1, &url)); + _gc(url.params.p); usessl = false; if (url.scheme.n) { if (url.scheme.n == 5 && !memcasecmp(url.scheme.p, "https", 5)) { @@ -411,9 +412,9 @@ int main(int argc, char *argv[]) { } } if (url.host.n) { - host = gc(strndup(url.host.p, url.host.n)); + host = _gc(strndup(url.host.p, url.host.n)); if (url.port.n) { - port = gc(strndup(url.port.p, url.port.n)); + port = _gc(strndup(url.port.p, url.port.n)); } else { port = usessl ? "443" : "80"; } @@ -429,7 +430,7 @@ int main(int argc, char *argv[]) { url.host.p = 0, url.host.n = 0; url.port.p = 0, url.port.n = 0; if (!url.path.n || url.path.p[0] != '/') { - char *p = gc(xmalloc(1 + url.path.n)); + char *p = _gc(xmalloc(1 + url.path.n)); mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n); url.path.p = p; ++url.path.n; diff --git a/tool/plinko/lib/gc.c b/tool/plinko/lib/gc.c index 43f840fb5..a3d8df3fa 100644 --- a/tool/plinko/lib/gc.c +++ b/tool/plinko/lib/gc.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "libc/intrin/bsf.h" #include "libc/intrin/popcnt.h" #include "libc/limits.h" #include "libc/log/check.h" @@ -24,7 +25,6 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsf.h" #include "libc/str/str.h" #include "tool/plinko/lib/cons.h" #include "tool/plinko/lib/gc.h" @@ -93,7 +93,7 @@ int Census(struct Gc *G) { if (!~G->M[j]) { l += DWBITS; } else { - l += bsfl(~G->M[j]); + l += _bsfl(~G->M[j]); break; } } @@ -124,7 +124,7 @@ void Sweep(struct Gc *G) { for (; i < G->n; ++i) { m = G->M[i]; if (~m) { - j = bsfl(~m); + j = _bsfl(~m); m >>= j; m <<= j; d -= j; @@ -136,7 +136,7 @@ void Sweep(struct Gc *G) { } for (; i < G->n; b -= DWBITS, m = G->M[++i]) { for (; m; m &= ~((dword)1 << j)) { - a = b + ~(j = bsfl(m)); + a = b + ~(j = _bsfl(m)); Set(--d, MAKE(Relocate(G, LO(Get(a))), Relocate(G, HI(Get(a))))); SetShadow(d, MAKE(LO(GetShadow(a)), Relocate(G, HI(GetShadow(a))))); } diff --git a/tool/plinko/lib/histo.h b/tool/plinko/lib/histo.h index 232f04d64..acbd5960e 100644 --- a/tool/plinko/lib/histo.h +++ b/tool/plinko/lib/histo.h @@ -1,14 +1,14 @@ #ifndef COSMOPOLITAN_TOOL_PLINKO_LIB_HISTO_H_ #define COSMOPOLITAN_TOOL_PLINKO_LIB_HISTO_H_ +#include "libc/intrin/bsr.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define HISTO(H, X) \ do { \ uint64_t x_ = X; \ - x_ = x_ ? bsrl(x_) + 1 : x_; \ + x_ = x_ ? _bsrl(x_) + 1 : x_; \ ++H[MIN(x_, ARRAYLEN(H) - 1)]; \ } while (0) diff --git a/tool/plinko/lib/plinko.c b/tool/plinko/lib/plinko.c index 64f74ad69..64c19214e 100644 --- a/tool/plinko/lib/plinko.c +++ b/tool/plinko/lib/plinko.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/errno.h" #include "libc/intrin/likely.h" diff --git a/tool/plinko/lib/printchar.c b/tool/plinko/lib/printchar.c index c6215497f..e60f87e2f 100644 --- a/tool/plinko/lib/printchar.c +++ b/tool/plinko/lib/printchar.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/bsr.h" +#include "libc/intrin/bsr.h" #include "tool/plinko/lib/char.h" #include "tool/plinko/lib/ktpenc.h" #include "tool/plinko/lib/plinko.h" @@ -31,7 +31,7 @@ int PrintChar(int fd, int s) { if (c == L'\n') Flush(fd); } else { d = c; - e = kTpEnc[bsrl(d) - 7]; + e = kTpEnc[_bsrl(d) - 7]; i = n = e & 255; do g_buffer[fd][bp[fd] + i--] = 0200 | (d & 077); while (d >>= 6, i); diff --git a/tool/plinko/lib/printf.c b/tool/plinko/lib/printf.c index 43fceab34..01a028d14 100644 --- a/tool/plinko/lib/printf.c +++ b/tool/plinko/lib/printf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/nexgen32e/rdtsc.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" diff --git a/tool/plinko/lib/printheap.c b/tool/plinko/lib/printheap.c index a16759c1c..f6deff44f 100644 --- a/tool/plinko/lib/printheap.c +++ b/tool/plinko/lib/printheap.c @@ -40,7 +40,7 @@ static const char *GetElfSymbol(uintptr_t funcaddr) { static const char *GetDispatchName(int x) { const char *s; s = GetElfSymbol(LO(GetShadow(x))); - if (startswith(s, "Dispatch")) s += 8; + if (_startswith(s, "Dispatch")) s += 8; return s; } diff --git a/tool/plinko/lib/read.c b/tool/plinko/lib/read.c index ac0a7b76c..a3aae10b0 100644 --- a/tool/plinko/lib/read.c +++ b/tool/plinko/lib/read.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/errno.h" #include "libc/log/check.h" #include "libc/runtime/runtime.h" diff --git a/tool/scripts/asmexpr b/tool/scripts/asmexpr index 81fc93d8d..62a63b50d 100755 --- a/tool/scripts/asmexpr +++ b/tool/scripts/asmexpr @@ -2,11 +2,11 @@ # # OVERVIEW # -# Micro-experiment assembler. +# Micro-Experiment Assembler # # EXAMPLES # -# asmexpr 'mov $-4096,%rax' 'not %rax' 'bsr %rax,%rax' +# asmexpr 'mov $8,%rax' 'bsr %rax,%rax' # asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2' c=/tmp/asmexpr.c diff --git a/tool/scripts/awk1 b/tool/scripts/awk1 new file mode 100755 index 000000000..83bad6a5c --- /dev/null +++ b/tool/scripts/awk1 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $1}' diff --git a/tool/scripts/awk2 b/tool/scripts/awk2 new file mode 100755 index 000000000..21aac4186 --- /dev/null +++ b/tool/scripts/awk2 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $2}' diff --git a/tool/scripts/awk3 b/tool/scripts/awk3 new file mode 100755 index 000000000..e5bdaf712 --- /dev/null +++ b/tool/scripts/awk3 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $3}' diff --git a/tool/scripts/awk4 b/tool/scripts/awk4 new file mode 100755 index 000000000..6b5b456cb --- /dev/null +++ b/tool/scripts/awk4 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $4}' diff --git a/tool/scripts/awk5 b/tool/scripts/awk5 new file mode 100755 index 000000000..64e1df946 --- /dev/null +++ b/tool/scripts/awk5 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $5}' diff --git a/tool/scripts/awk6 b/tool/scripts/awk6 new file mode 100755 index 000000000..945d69d70 --- /dev/null +++ b/tool/scripts/awk6 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $6}' diff --git a/tool/scripts/awk7 b/tool/scripts/awk7 new file mode 100755 index 000000000..e73455f78 --- /dev/null +++ b/tool/scripts/awk7 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $7}' diff --git a/tool/scripts/awk8 b/tool/scripts/awk8 new file mode 100755 index 000000000..acff1239c --- /dev/null +++ b/tool/scripts/awk8 @@ -0,0 +1,2 @@ +#!/bin/sh +exec awk "$@" '{print $8}' diff --git a/tool/scripts/bf b/tool/scripts/bf new file mode 100755 index 000000000..860e05c04 --- /dev/null +++ b/tool/scripts/bf @@ -0,0 +1,4 @@ +#!/bin/sh +bing.com <"$1" | + fold.com | + exec less diff --git a/tool/scripts/bloat b/tool/scripts/bloat new file mode 100755 index 000000000..ac50ec882 --- /dev/null +++ b/tool/scripts/bloat @@ -0,0 +1,5 @@ +#!/bin/sh +nm -C --size "$@" | + sort -r | + grep ' [bBtTRr] ' | + exec less diff --git a/tool/scripts/configure-emacs.sh b/tool/scripts/configure-emacs.sh deleted file mode 100755 index 735b36955..000000000 --- a/tool/scripts/configure-emacs.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -if ! [ -e ape/ape.S ]; then - echo please cd to cosmopolitan root directory >&2 - exit 1 -fi - -COSMOPOLITAN="$PWD" -EMACSCONFIGS="$HOME/.emacs.d/init.el" -[ -e "$EMACSCONFIGS" ] || EMACSCONFIGS="$HOME/.emacs" - -cat >>"$EMACSCONFIGS" <o/cosmo/cosmopolitan.h -cd o/cosmo - -cat <HELLO.C -int main(int argc, char *argv[]) { - printf("hello world\n"); - return 0; -} -EOF - -gcc -O -s -static -nostdlib -nostdinc \ - -Wl,-T,ape.lds -include cosmopolitan.h \ - -o HELLO.COM.DBG HELLO.C crt.o ape.o cosmopolitan.a - -objcopy -S -O binary HELLO.COM.DBG HELLO.COM -ls -hal ./HELLO.COM -./HELLO.COM diff --git a/tool/scripts/ezgdb b/tool/scripts/ezgdb new file mode 100755 index 000000000..27337ee4c --- /dev/null +++ b/tool/scripts/ezgdb @@ -0,0 +1,4 @@ +#!/bin/sh +PROG="$1" +shift +exec gdb "$PROG" -ex "set args $*" -ex run diff --git a/tool/scripts/get-deps.py b/tool/scripts/get-deps.py index 29d204e35..baf4f87a7 100755 --- a/tool/scripts/get-deps.py +++ b/tool/scripts/get-deps.py @@ -1,4 +1,14 @@ #!/usr/bin/env python.com +# +# OVERVIEW +# +# One-Off Makefile Rule Generator +# +# EXAMPLES +# +# tool/scripts/get-deps.py examples/hello.c +# asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2' +# import os import re diff --git a/tool/scripts/grep b/tool/scripts/grep index 294144699..bb8d7b534 100755 --- a/tool/scripts/grep +++ b/tool/scripts/grep @@ -1,6 +1,10 @@ #!/bin/sh -exec /usr/bin/grep \ - --exclude-dir=o \ - --exclude-dir=gcc \ - --exclude-dir=.git \ +exec grep \ + --exclude=TAGS \ + --exclude=HTAGS \ + --exclude=*.com \ + --exclude-dir=o \ + --exclude-dir=gcc \ + --exclude-dir=.git \ + --exclude=archive-contents \ "$@" diff --git a/tool/scripts/install-emacs.sh b/tool/scripts/install-emacs.sh deleted file mode 100755 index 6b43f4cca..000000000 --- a/tool/scripts/install-emacs.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# installs emacs version w/ working (replace-buffer-contents) -# it's sooooo worth it due to clang-format-10 working so well -set -ex -sudo apt build-dep emacs -cd "$HOME" -export CFLAGS="-O2" -rm -rf emacs-26.3 -wget https://mirrors.kernel.org/gnu/emacs/emacs-26.3.tar.gz -tar xf emacs-26.3.tar.gz -cd emacs-26.3 -./configure -make -j8 -sudo make install -rm -f ../emacs-26.3.tar.gz diff --git a/tool/scripts/loc b/tool/scripts/loc new file mode 100755 index 000000000..f029adb7b --- /dev/null +++ b/tool/scripts/loc @@ -0,0 +1,6 @@ +#!/bin/bash +echo $(( $(find ape dsp libc examples net test third_party tool -name \*.c | xargs cat | wc -l) + + $(find ape dsp libc examples net test third_party tool -name \*.h | xargs cat | wc -l) + + $(find ape dsp libc examples net test third_party tool -name \*.S | xargs cat | wc -l) + + $(find ape dsp libc examples net test third_party tool -name \*.el | xargs cat | wc -l) + + $(find ape dsp libc examples net test third_party tool -name \*.mk | xargs cat | wc -l) )) diff --git a/tool/scripts/obj b/tool/scripts/obj new file mode 100755 index 000000000..cc6c5840f --- /dev/null +++ b/tool/scripts/obj @@ -0,0 +1,3 @@ +#!/bin/sh +objdump -Cwd "$@" | + exec less diff --git a/tool/scripts/pb b/tool/scripts/pb new file mode 100755 index 000000000..78ee628d0 --- /dev/null +++ b/tool/scripts/pb @@ -0,0 +1,16 @@ +#!/bin/sh +exec python.com -c " +# -*- coding: utf-8 -*- +import sys +from math import * +x = $* +s = x < 0 +x = abs(x) +b = str(bin(x))[2:].replace('L', '') +n = len(b) +if n <= 8: n = 8 +elif n <= 16: n = 16 +elif n <= 32: n = 32 +elif n <= 64: n = 64 +sys.stdout.write(('%%s0b%%0%dd' % n) % ('-' if s else '', int(b))) +" diff --git a/tool/scripts/pe b/tool/scripts/pe new file mode 100755 index 000000000..e757f3a94 --- /dev/null +++ b/tool/scripts/pe @@ -0,0 +1,9 @@ +#!/bin/sh +echo "# -*- coding: utf-8 -*- +import os +import sys +from math import * +s = str($*) +sys.stdout.write(s) +" >/tmp/pe +exec python.com /tmp/pe diff --git a/tool/scripts/performance b/tool/scripts/performance new file mode 100755 index 000000000..d35b863c2 --- /dev/null +++ b/tool/scripts/performance @@ -0,0 +1,2 @@ +#!/bin/sh +echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor diff --git a/tool/scripts/po b/tool/scripts/po new file mode 100755 index 000000000..d28d78460 --- /dev/null +++ b/tool/scripts/po @@ -0,0 +1,14 @@ +#!/bin/sh +exec python.com -c " +import sys +from math import * +s = str(oct($*).replace('o','')) +if len(s) > 1: s = s[1:] +b = s.replace('L', '') +n = len(b) +if n <= 3: n = 3 +elif n <= 6: n = 6 +elif n <= 11: n = 11 +elif n <= 22: n = 22 +sys.stdout.write(('0%%0%dd' % n) % int(b)) +" diff --git a/tool/scripts/powersave b/tool/scripts/powersave new file mode 100755 index 000000000..82c56ef27 --- /dev/null +++ b/tool/scripts/powersave @@ -0,0 +1,2 @@ +#!/bin/sh +echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor diff --git a/tool/scripts/px b/tool/scripts/px new file mode 100755 index 000000000..59abec069 --- /dev/null +++ b/tool/scripts/px @@ -0,0 +1,17 @@ +#!/bin/sh +exec python.com -c " +# -*- coding: utf-8 -*- +import sys +from math import * +x = $* +s = x < 0 +x = abs(x) +b = str(hex(x))[2:].replace('L', '') +n = len(b) +if n <= 2: n = 2 +elif n <= 4: n = 4 +elif n <= 8: n = 8 +elif n <= 12: n = 12 +elif n <= 16: n = 16 +sys.stdout.write(('%%s0x%%0%dx' % n) % ('-' if s else '', int(b,16))) +" diff --git a/tool/scripts/re b/tool/scripts/re new file mode 100755 index 000000000..696926a1d --- /dev/null +++ b/tool/scripts/re @@ -0,0 +1,4 @@ +#!/bin/sh +readelf -Wa "$1" | + c++filt | + exec less diff --git a/tool/scripts/renameheader b/tool/scripts/renameheader new file mode 100755 index 000000000..edb9674e1 --- /dev/null +++ b/tool/scripts/renameheader @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +FROM="${1?from}" +TO="${2?to}" + +if [ -f "$TO" ]; then + rm -f "$FROM" || exit +else + mv "$FROM" "$TO" || exit +fi + +sed -i -e "s/$(echo "${FROM//\//_}" | sed 's/\./_/' | tr a-z A-Z)_H_/$(echo "${TO//\//_}" | sed 's/\./_/' | tr a-z A-Z)_H_/" "$TO" || exit + +tool/scripts/grep -nH -RPie "\"$FROM\"" | + tool/scripts/awk1 -F: | + xargs sed -i -e "s/${FROM//\//\\/}/${TO//\//\\/}/" diff --git a/tool/scripts/wut b/tool/scripts/wut new file mode 100755 index 000000000..4d6da7b91 --- /dev/null +++ b/tool/scripts/wut @@ -0,0 +1,98 @@ +#!/bin/sh + +rm -f /tmp/wut-linux + +( + grep -R "$1" ~/dox/susv4-2018/ | sed ' + /meta.idx/d + ' >/tmp/wut-posix +) & + +( + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/linux/include/ | sed ' + /\/asm-/ { + /asm-\(x86\|generic\)/!d + } + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/ + ' >>/tmp/wut-linux +) & + +( + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/linux-2.6.18/include/ | sed ' + /\/asm-/ { + /asm-\(x86\|generic\)/!d + } + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/2.6.18\t\1/ + ' >>/tmp/wut-linux +) & + +( + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/xnu/ | sed ' + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/ + ' >/tmp/wut-xnu +) & + +( + { + if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/freebsd/sys/; then + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/freebsd/lib/libc/ + fi + } | sed ' + /\/contrib\//d + /\/linux\//d + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/ + ' >/tmp/wut-freebsd +) & + +( + { + if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/openbsd/sys/; then + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/openbsd/lib/libc/ + fi + } | sed ' + /\/linux\//d + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/ + ' >/tmp/wut-openbsd +) & + +( + { + if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/netbsd/sys/; then + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/netbsd/lib/libc/ + fi + } | sed ' + /\/linux\//d + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/ + ' >/tmp/wut-netbsd +) & + +( + grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/10.0.18362.0/um/ | sed ' + s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/ + s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/ + ' >/tmp/wut-windows +) & + +wait + +f() { + if [ $(ls -lH /tmp/wut-$1 | awk5) -gt 0 ]; then + cat /tmp/wut-$1 + else + echo $1 says nothing + fi +} + +f linux +f xnu +f freebsd +f openbsd +f netbsd +f windows +f posix diff --git a/tool/viz/basicidea.c b/tool/viz/basicidea.c index b924dbbb8..83eb26c45 100644 --- a/tool/viz/basicidea.c +++ b/tool/viz/basicidea.c @@ -20,11 +20,13 @@ #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" +#include "libc/calls/struct/winsize.h" #include "libc/fmt/fmt.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" +#include "libc/str/locale.h" #include "libc/str/str.h" #include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/fileno.h" @@ -32,7 +34,6 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/termios.h" -#include "libc/str/locale.h" #include "third_party/stb/stb_image.h" #define SQR(X) ((X) * (X)) diff --git a/tool/viz/bf.c b/tool/viz/bf.c index df23ff88c..746e2e38e 100644 --- a/tool/viz/bf.c +++ b/tool/viz/bf.c @@ -16,15 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/bsr.h" +#include "libc/intrin/tpenc.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsr.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/s.h" @@ -44,7 +44,7 @@ void bf(int fd) { char ibuf[W], obuf[12 + 1 + W * 6 + 1 + W * (2 + 11) + 11 + 1]; o = 0; if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode) && st.st_size) { - bits = bsr(roundup2pow(st.st_size)); + bits = _bsr(_roundup2pow(st.st_size)); bits = ROUNDUP(bits, 4); } else { bits = 48; @@ -58,7 +58,7 @@ void bf(int fd) { obuf[n++] = ' '; for (i = 0; i < rc; ++i) { c = ibuf[i] & 0xff; - w = tpenc(kCp437[c]); + w = _tpenc(kCp437[c]); do { obuf[n++] = w; } while ((w >>= 8)); diff --git a/tool/viz/cpuid.c b/tool/viz/cpuid.c index c7e724bad..a2fdf135c 100644 --- a/tool/viz/cpuid.c +++ b/tool/viz/cpuid.c @@ -25,10 +25,10 @@ #include "libc/nexgen32e/rdtscp.h" #include "libc/nexgen32e/x86feature.h" #include "libc/nexgen32e/x86info.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "tool/decode/lib/idname.h" #include "tool/decode/lib/x86idnames.h" @@ -75,15 +75,15 @@ void showcachesizes(void) { CPUID4_ITERATE(i, { printf("%-19s%s%s %u-way %,7u byte cache w/%s %,5u sets of %u byte lines " "shared across %u threads\n", - gc(xasprintf("Level %u%s", CPUID4_CACHE_LEVEL, - CPUID4_CACHE_TYPE == 1 ? " data" - : CPUID4_CACHE_TYPE == 2 ? " code" - : "")), + _gc(xasprintf("Level %u%s", CPUID4_CACHE_LEVEL, + CPUID4_CACHE_TYPE == 1 ? " data" + : CPUID4_CACHE_TYPE == 2 ? " code" + : "")), CPUID4_IS_FULLY_ASSOCIATIVE ? " fully-associative" : "", CPUID4_COMPLEX_INDEXING ? " complexly-indexed" : "", CPUID4_WAYS_OF_ASSOCIATIVITY, CPUID4_CACHE_SIZE_IN_BYTES, CPUID4_PHYSICAL_LINE_PARTITIONS > 1 - ? gc(xasprintf(" %u physically partitioned")) + ? _gc(xasprintf(" %u physically partitioned")) : "", CPUID4_NUMBER_OF_SETS, CPUID4_SYSTEM_COHERENCY_LINE_SIZE, CPUID4_MAX_THREADS_SHARING_CACHE); diff --git a/tool/viz/deathstar.c b/tool/viz/deathstar.c index 2fd3729cd..877b0657a 100644 --- a/tool/viz/deathstar.c +++ b/tool/viz/deathstar.c @@ -1,29 +1,21 @@ -#include "dsp/tty/tty.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/termios.h" -#include "libc/log/check.h" -#include "libc/log/color.internal.h" -#include "libc/log/log.h" -#include "libc/macros.internal.h" -#include "libc/math.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/runtime/runtime.h" -#include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/sig.h" -#include "libc/time/time.h" -#include "libc/x/x.h" +#include "third_party/libcxx/math.h" /** * @fileoverview demo code borrowed from Rosetta Code. */ #define FRAMERATE 23.976 -#define WRITE(s) write(STDOUT_FILENO, s, strlen(s)) +#define WRITE(s) write(1, s, strlen(s)) struct Sphere { - long double cx, cy, cz, r; + double cx, cy, cz, r; }; static const char *kShades[] = { @@ -36,7 +28,7 @@ static const char *kShades[] = { }; static jmp_buf jb_; -static long double light_[3] = {-50, 0, 50}; +static double light_[3] = {-50, 0, 50}; static struct Sphere pos_ = {11, 11, 11, 11}; static struct Sphere neg_ = {1, 1, -4, 11}; @@ -44,42 +36,41 @@ static void OnCtrlC(int sig) { longjmp(jb_, 1); } -static void Normalize(long double v[3]) { - long double len; - len = 1 / sqrtl(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); +static void Normalize(double v[3]) { + double len; + len = 1 / sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); v[0] *= len; v[1] *= len; v[2] *= len; } -static long double Dot(const long double x[3], const long double y[3]) { - return fabsl(x[0] * y[0] + x[1] * y[1] + x[2] * y[2]); +static double Dot(const double x[3], const double y[3]) { + return fabs(x[0] * y[0] + x[1] * y[1] + x[2] * y[2]); } /* check if a ray (x,y, -inf)->(x, y, inf) hits a sphere; if so, return the intersecting z values. z1 is closer to the eye */ -static int HitSphere(struct Sphere *s, long double x, long double y, - long double z[2]) { - long double zsq; +static int HitSphere(struct Sphere *s, double x, double y, double z[2]) { + double zsq; x -= s->cx; y -= s->cy; zsq = s->r * s->r - (x * x + y * y); if (zsq < 0) { return 0; } else { - zsq = sqrtl(zsq); + zsq = sqrt(zsq); z[0] = s->cz - zsq; z[1] = s->cz + zsq; return 1; } } -static void DrawSphere(long double k, long double ambient) { +static void DrawSphere(double k, double ambient) { int i, j, hit_result; - long double x, y, vec[3], zb[2], zs[2]; - for (i = floorl(pos_.cy - pos_.r); i <= ceill(pos_.cy + pos_.r); i++) { + double x, y, vec[3], zb[2], zs[2]; + for (i = floor(pos_.cy - pos_.r); i <= ceil(pos_.cy + pos_.r); i++) { y = i + .5L; - for (j = floorl(pos_.cx - 2 * pos_.r); j <= ceill(pos_.cx + 2 * pos_.r); + for (j = floor(pos_.cx - 2 * pos_.r); j <= ceil(pos_.cx + 2 * pos_.r); j++) { x = .5L * (j - pos_.cx) + .5L + pos_.cx; if (!HitSphere(&pos_, x, y, zb)) { @@ -117,10 +108,10 @@ static void DrawSphere(long double k, long double ambient) { break; } Normalize(vec); - WRITE(kShades[min( - ARRAYLEN(kShades) - 1, - max(0, lroundl((1 - (powl(Dot(light_, vec), k) + ambient)) * - (ARRAYLEN(kShades) - 1))))]); + WRITE( + kShades[min(ARRAYLEN(kShades) - 1, + max(0, lround((1 - (pow(Dot(light_, vec), k) + ambient)) * + (ARRAYLEN(kShades) - 1))))]); } WRITE("\e[0m\n"); } @@ -128,16 +119,16 @@ static void DrawSphere(long double k, long double ambient) { } int main() { - long double ang; + double ang; struct termios old; WRITE("\e[?25l"); if (!setjmp(jb_)) { - xsigaction(SIGINT, OnCtrlC, 0, 0, NULL); + signal(SIGINT, OnCtrlC); ang = 0; for (;;) { WRITE("\e[H"); light_[1] = cosl(ang * 2); - sincosl(ang, &light_[0], &light_[2]); + sincos(ang, &light_[0], &light_[2]); Normalize(light_); ang += .05L; DrawSphere(1.5L, .01L); diff --git a/tool/viz/derasterize.c b/tool/viz/derasterize.c index 3df24fb78..517521b95 100644 --- a/tool/viz/derasterize.c +++ b/tool/viz/derasterize.c @@ -24,18 +24,18 @@ #include "libc/calls/termios.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/tpenc.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/fileno.h" @@ -104,7 +104,7 @@ int y_; /* -y HEIGHT [in flexidecimal] */ #define Mode BEST #if Mode == BEST -#define MC 9u /* log2(#) of color combos to consider */ +#define MC 9u /* log2(#) of color combos to consider */ #define GN 35u /* # of glyphs to consider */ #elif Mode == FAST #define MC 6u @@ -114,10 +114,10 @@ int y_; /* -y HEIGHT [in flexidecimal] */ #define GN 25u #endif -#define CN 3u /* # channels (rgb) */ -#define YS 8u /* row stride -or- block height */ -#define XS 4u /* column stride -or- block width */ -#define GT 44u /* total glyphs */ +#define CN 3u /* # channels (rgb) */ +#define YS 8u /* row stride -or- block height */ +#define XS 4u /* column stride -or- block width */ +#define GT 44u /* total glyphs */ #define BN (YS * XS) /* # scalars in block/glyph plane */ #define PHIPRIME 0x9E3779B1u @@ -138,7 +138,7 @@ extern const char16_t kRunes[]; */ static char *tptoa(char *p, wchar_t x) { unsigned long w; - for (w = tpenc(x); w; w >>= 010) *p++ = w & 0xff; + for (w = _tpenc(x); w; w >>= 010) *p++ = w & 0xff; return p; } diff --git a/tool/viz/double2int.c b/tool/viz/double2int.c index cfc223c80..ea244a6b2 100644 --- a/tool/viz/double2int.c +++ b/tool/viz/double2int.c @@ -19,7 +19,7 @@ #include "libc/fmt/conv.h" #include "libc/limits.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/tool/viz/dumphexc.c b/tool/viz/dumphexc.c index a738c6e46..7e429b7a6 100644 --- a/tool/viz/dumphexc.c +++ b/tool/viz/dumphexc.c @@ -19,7 +19,7 @@ #include "libc/fmt/fmt.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/hex.internal.h" #include "libc/stdio/stdio.h" diff --git a/tool/viz/fontspace.c b/tool/viz/fontspace.c index 9265da55d..07c6682a4 100644 --- a/tool/viz/fontspace.c +++ b/tool/viz/fontspace.c @@ -20,12 +20,12 @@ #include "libc/calls/ioctl.h" #include "libc/calls/struct/winsize.h" #include "libc/fmt/conv.h" +#include "libc/intrin/bsr.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -50,7 +50,7 @@ void PrintBar(unsigned char *p, size_t n) { } for (i = 0; i < j; ++i) { if (p[i]) { - fputwc(u"░░▒▒▓▓██"[bsr(p[i])], stdout); + fputwc(u"░░▒▒▓▓██"[_bsr(p[i])], stdout); } else { fputc(' ', stdout); } @@ -87,8 +87,8 @@ int main(int argc, char *argv[]) { } n = end + 1 - start; m = ROUNDUP(n, 16); - present = gc(malloc(m)); - intotal = gc(calloc(1, m)); + present = _gc(malloc(m)); + intotal = _gc(calloc(1, m)); if (optind < argc) { for (arg = optind; arg < argc; ++arg) { ttf = xslurp(argv[arg], &ttfsize); diff --git a/tool/viz/generatematrix.c b/tool/viz/generatematrix.c index cad8944eb..744665a9f 100644 --- a/tool/viz/generatematrix.c +++ b/tool/viz/generatematrix.c @@ -27,7 +27,7 @@ #include "libc/mem/mem.h" #include "libc/stdio/lcg.internal.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/tool/viz/generatetortureimage.c b/tool/viz/generatetortureimage.c index 20969d137..e8e57166c 100644 --- a/tool/viz/generatetortureimage.c +++ b/tool/viz/generatetortureimage.c @@ -16,9 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/str/str.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "third_party/stb/stb_image_write.h" #define YN (1080 / YM) @@ -53,10 +54,10 @@ void *GenerateTortureImage(unsigned char RGB[YN][YM][XN][XM][3]) { int main(int argc, char *argv[]) { stbi_write_png( - gc(xasprintf("maxwell_%dx%d_%dx%d.png", XN * XM, YN * YM, XM, YM)), + _gc(xasprintf("maxwell_%dx%d_%dx%d.png", XN * XM, YN * YM, XM, YM)), XN * XM, YN * YM, 3, GenerateTortureImage( - gc(xmemalign(32, sizeof(unsigned char) * XN * XM * YN * YM * 3))), + _gc(xmemalign(32, sizeof(unsigned char) * XN * XM * YN * YM * 3))), XN * XM * 3); return 0; } diff --git a/tool/viz/getglyph.c b/tool/viz/getglyph.c index 7a4fb2ff7..359a0767a 100644 --- a/tool/viz/getglyph.c +++ b/tool/viz/getglyph.c @@ -16,16 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/struct/sigaction.h" #include "libc/fmt/conv.h" +#include "libc/intrin/tpenc.h" #include "libc/limits.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" -#include "libc/stdio/append.internal.h" +#include "libc/stdio/append.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" #include "libc/sysv/consts/sig.h" #include "libc/x/x.h" #include "third_party/getopt/getopt.h" @@ -84,7 +85,7 @@ static char *Raster(int yn, int xn, unsigned char Y[yn][xn], int *dw) { bs = s; } } - appendw(&r, tpenc(kBlocks[bi].c)); + appendw(&r, _tpenc(kBlocks[bi].c)); ++w; } if (w > *dw) *dw = w; @@ -109,9 +110,8 @@ int main(int argc, char *argv[]) { unsigned char **ttf; stbtt_fontinfo *font; int c, i, j, m, o, dw, maxw, *w, *h, s = 40 * 4; - struct sigaction sa = {.sa_handler = OnSig}; ShowCrashReports(); - sigaction(SIGPIPE, &sa, 0); + signal(SIGPIPE, OnSig); start = 0; end = 0x10FFFD; while ((o = getopt(argc, argv, "vdc:s:e:S:")) != -1) { @@ -139,14 +139,14 @@ int main(int argc, char *argv[]) { } } m = argc - optind; - w = gc(calloc(m, sizeof(*w))); - h = gc(calloc(m, sizeof(*h))); - ttf = gc(calloc(m, sizeof(*ttf))); - font = gc(calloc(m, sizeof(*font))); - rasters = gc(calloc(m, sizeof(*rasters))); - fasters = gc(calloc(m, sizeof(*fasters))); + w = _gc(calloc(m, sizeof(*w))); + h = _gc(calloc(m, sizeof(*h))); + ttf = _gc(calloc(m, sizeof(*ttf))); + font = _gc(calloc(m, sizeof(*font))); + rasters = _gc(calloc(m, sizeof(*rasters))); + fasters = _gc(calloc(m, sizeof(*fasters))); for (j = 0; j < m; ++j) { - ttf[j] = gc(xslurp(argv[optind + j], &ttfsize)); + ttf[j] = _gc(xslurp(argv[optind + j], &ttfsize)); if (!ttf[j]) { fprintf(stderr, "%s: not found\n", argv[optind + j]); exit(1); diff --git a/tool/viz/int2float.c b/tool/viz/int2float.c index 1e712c594..ba6b12ff9 100644 --- a/tool/viz/int2float.c +++ b/tool/viz/int2float.c @@ -19,10 +19,11 @@ #include "libc/fmt/conv.h" #include "libc/limits.h" #include "libc/macros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" float b32; double b64; @@ -33,41 +34,41 @@ int128_t x; void int2float(const char *s) { x = strtoi128(s, NULL, 0); - if ((0 <= x && x <= UINT32_MAX) && !startswith(s, "-") && - (!endswith(s, "l") && !endswith(s, "L"))) { + if ((0 <= x && x <= UINT32_MAX) && !_startswith(s, "-") && + (!_endswith(s, "l") && !_endswith(s, "L"))) { u32 = x; memcpy(&b32, &u32, 4); - s = gc(xdtoa(b32)); - if (!strchr(s, '.')) s = gc(xasprintf("%s.", s)); - s = gc(xasprintf("%sf", s)); + s = _gc(xdtoa(b32)); + if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); + s = _gc(xasprintf("%sf", s)); puts(s); - } else if ((0 <= x && x <= UINT64_MAX) && !startswith(s, "-")) { + } else if ((0 <= x && x <= UINT64_MAX) && !_startswith(s, "-")) { u64 = x; memcpy(&b64, &u64, 8); - s = gc(xdtoa(b64)); - if (!strchr(s, '.')) s = gc(xasprintf("%s.", s)); + s = _gc(xdtoa(b64)); + if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); puts(s); } else if ((INT32_MIN <= x && x <= 0) && - (!endswith(s, "l") && !endswith(s, "L"))) { + (!_endswith(s, "l") && !_endswith(s, "L"))) { u32 = ABS(x); memcpy(&b32, &u32, 4); b32 = -b32; - s = gc(xdtoa(b32)); - if (!strchr(s, '.')) s = gc(xasprintf("%s.", s)); - s = gc(xasprintf("%sf", s)); + s = _gc(xdtoa(b32)); + if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); + s = _gc(xasprintf("%sf", s)); puts(s); } else if (INT64_MIN <= x && x <= 0) { u64 = ABS(x); memcpy(&b64, &u64, 8); b64 = -b64; - s = gc(xdtoa(b64)); - if (!strchr(s, '.')) s = gc(xasprintf("%s.", s)); + s = _gc(xdtoa(b64)); + if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); puts(s); } else { memcpy(&b80, &x, 16); - s = gc(xdtoa(b80)); - if (!strchr(s, '.')) s = gc(xasprintf("%s.", s)); - s = gc(xasprintf("%sL", s)); + s = _gc(xdtoa(b80)); + if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); + s = _gc(xasprintf("%sL", s)); puts(s); } } diff --git a/tool/viz/lib/bilinearscale.c b/tool/viz/lib/bilinearscale.c index edfa5b077..bbaefaf54 100644 --- a/tool/viz/lib/bilinearscale.c +++ b/tool/viz/lib/bilinearscale.c @@ -17,13 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/twixt8.h" +#include "libc/intrin/bsr.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" -#include "libc/runtime/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" @@ -82,16 +82,16 @@ void *BilinearScale(long dcw, long dyw, long dxw, DCHECK_LE(sxn, sxw); DCHECK_LE(dyn, dyw); DCHECK_LE(dxn, dxw); - DCHECK_LT(bsrl(cn) + bsrl(syn) + bsrl(sxn), 32); - DCHECK_LT(bsrl(cn) + bsrl(dyn) + bsrl(dxn), 32); + DCHECK_LT(_bsrl(cn) + _bsrl(syn) + _bsrl(sxn), 32); + DCHECK_LT(_bsrl(cn) + _bsrl(dyn) + _bsrl(dxn), 32); BilinearScaler(dcw, dyw, dxw, dst, scw, syw, sxw, src, c0, cn, dyn, dxn, syn, sxn, ry, rx, oy, ox, - gc(xmemalign(64, ROUNDUP(sizeof(int) * (dyn + 1), 64))), - gc(xmemalign(64, ROUNDUP(dyn + 1, 64))), - gc(xmemalign(64, ROUNDUP(sizeof(int) * (dxn + 1), 64))), - gc(xmemalign(64, ROUNDUP(dxn + 1, 64))), - gc(xmemalign(64, ROUNDUP(dxn, 64))), - gc(xmemalign(64, ROUNDUP(sxn, 64) * 2))); + _gc(xmemalign(64, ROUNDUP(sizeof(int) * (dyn + 1), 64))), + _gc(xmemalign(64, ROUNDUP(dyn + 1, 64))), + _gc(xmemalign(64, ROUNDUP(sizeof(int) * (dxn + 1), 64))), + _gc(xmemalign(64, ROUNDUP(dxn + 1, 64))), + _gc(xmemalign(64, ROUNDUP(dxn, 64))), + _gc(xmemalign(64, ROUNDUP(sxn, 64) * 2))); } else { bzero(dst[c0], &dst[cn][0][0] - &dst[c0][0][0]); } diff --git a/tool/viz/lib/dither.c b/tool/viz/lib/dither.c index ad82b9818..1a91f292d 100644 --- a/tool/viz/lib/dither.c +++ b/tool/viz/lib/dither.c @@ -24,7 +24,7 @@ #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "tool/viz/lib/graphic.h" #include "tool/viz/lib/knobs.h" diff --git a/tool/viz/lib/formatmatrix-byte.c b/tool/viz/lib/formatmatrix-byte.c index f1c36a8db..848579f77 100644 --- a/tool/viz/lib/formatmatrix-byte.c +++ b/tool/viz/lib/formatmatrix-byte.c @@ -19,8 +19,8 @@ #include "libc/assert.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" -#include "libc/x/x.h" +#include "libc/mem/gc.h" +#include "libc/x/xasprintf.h" #include "tool/viz/lib/formatstringtable.h" #include "tool/viz/lib/stringbuilder.h" @@ -44,7 +44,7 @@ void FormatMatrixByte(long yn, long xn, const unsigned char M[yn][xn], yn, xn, formatter(yn, xn, ConvertByteMatrixToStringTable( - yn, xn, gc(calloc(yn * xn, sizeof(char *))), M), + yn, xn, _gc(calloc(yn * xn, sizeof(char *))), M), emit, arg, param1, param2, param3)); } diff --git a/tool/viz/lib/formatmatrix-double.c b/tool/viz/lib/formatmatrix-double.c index fa5c47475..65e839146 100644 --- a/tool/viz/lib/formatmatrix-double.c +++ b/tool/viz/lib/formatmatrix-double.c @@ -21,7 +21,7 @@ #include "libc/log/check.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/x/x.h" #include "third_party/gdtoa/gdtoa.h" #include "tool/viz/lib/formatstringtable.h" diff --git a/tool/viz/lib/formatmatrix-float.c b/tool/viz/lib/formatmatrix-float.c index e0760caa6..1423780e1 100644 --- a/tool/viz/lib/formatmatrix-float.c +++ b/tool/viz/lib/formatmatrix-float.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/x/x.h" #include "tool/viz/lib/formatstringtable.h" diff --git a/tool/viz/lib/formatmatrix-short.c b/tool/viz/lib/formatmatrix-short.c index fdbff2b0a..9a2cd85d2 100644 --- a/tool/viz/lib/formatmatrix-short.c +++ b/tool/viz/lib/formatmatrix-short.c @@ -19,8 +19,9 @@ #include "libc/assert.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/x/x.h" +#include "libc/x/xasprintf.h" #include "tool/viz/lib/formatstringtable.h" #include "tool/viz/lib/stringbuilder.h" @@ -44,7 +45,7 @@ void FormatMatrixShort(long yn, long xn, const short M[yn][xn], int emit(), yn, xn, formatter(yn, xn, ConvertShortMatrixToStringTable( - yn, xn, gc(xcalloc(yn * xn, sizeof(char *))), M), + yn, xn, _gc(xcalloc(yn * xn, sizeof(char *))), M), emit, arg, param1, param2, param3)); } diff --git a/tool/viz/lib/formatstringtable-assembly.c b/tool/viz/lib/formatstringtable-assembly.c index 497d92497..9a96a283d 100644 --- a/tool/viz/lib/formatstringtable-assembly.c +++ b/tool/viz/lib/formatstringtable-assembly.c @@ -19,7 +19,7 @@ #include "libc/fmt/itoa.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/str/strwidth.h" #include "libc/x/x.h" diff --git a/tool/viz/lib/graphic.h b/tool/viz/lib/graphic.h index a190606a8..fa1ac5245 100644 --- a/tool/viz/lib/graphic.h +++ b/tool/viz/lib/graphic.h @@ -1,8 +1,8 @@ #ifndef COSMOPOLITAN_TOOL_VIZ_LIB_GRAPHIC_H_ #define COSMOPOLITAN_TOOL_VIZ_LIB_GRAPHIC_H_ #include "dsp/tty/quant.h" -#include "libc/runtime/buffer.h" -#include "libc/runtime/gc.internal.h" +#include "libc/runtime/buffer.internal.h" +#include "libc/mem/gc.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/tool/viz/lib/resizegraphic.c b/tool/viz/lib/resizegraphic.c index c0fcf7163..d17e53540 100644 --- a/tool/viz/lib/resizegraphic.c +++ b/tool/viz/lib/resizegraphic.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/intrin/xmmintrin.internal.h" -#include "libc/runtime/buffer.h" +#include "libc/runtime/buffer.internal.h" #include "tool/viz/lib/graphic.h" /** diff --git a/tool/viz/lib/ycbcr2rgb3.c b/tool/viz/lib/ycbcr2rgb3.c index 88ad860f0..a1d9c1cf7 100644 --- a/tool/viz/lib/ycbcr2rgb3.c +++ b/tool/viz/lib/ycbcr2rgb3.c @@ -25,19 +25,19 @@ #include "dsp/core/illumination.h" #include "dsp/core/q.h" #include "dsp/scale/scale.h" -#include "libc/intrin/xmmintrin.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/sigset.h" #include "libc/intrin/pmulhrsw.h" +#include "libc/intrin/xmmintrin.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/gc.internal.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/sig.h" @@ -96,8 +96,8 @@ void YCbCrComputeCoefficients(int swing, double gamma, double x; double f1[6][3]; long longs[6][6]; - long bitlimit = roundup2pow(swing); - long wordoffset = rounddown2pow((bitlimit - swing) / 2); + long bitlimit = _roundup2pow(swing); + long wordoffset = _rounddown2pow((bitlimit - swing) / 2); long chromaswing = swing + 2 * (bitlimit / 2. - swing / 2. - wordoffset); long lumamin = wordoffset; long lumamax = wordoffset + swing; diff --git a/tool/viz/life.c b/tool/viz/life.c index 3e5975386..a3cb922c4 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -16,19 +16,16 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "dsp/core/gamma.h" #include "dsp/scale/scale.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" -#include "libc/calls/struct/stat.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" -#include "libc/calls/termios.internal.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/bits.h" #include "libc/intrin/popcnt.h" #include "libc/intrin/safemacros.internal.h" #include "libc/intrin/xchg.internal.h" @@ -41,9 +38,7 @@ #include "libc/nt/dll.h" #include "libc/nt/enum/bitblt.h" #include "libc/nt/enum/color.h" -#include "libc/nt/enum/cs.h" #include "libc/nt/enum/cw.h" -#include "libc/nt/enum/ht.h" #include "libc/nt/enum/idc.h" #include "libc/nt/enum/mb.h" #include "libc/nt/enum/mf.h" @@ -51,38 +46,26 @@ #include "libc/nt/enum/ofn.h" #include "libc/nt/enum/rdw.h" #include "libc/nt/enum/sc.h" -#include "libc/nt/enum/size.h" #include "libc/nt/enum/sw.h" -#include "libc/nt/enum/tpm.h" -#include "libc/nt/enum/vk.h" #include "libc/nt/enum/wm.h" #include "libc/nt/enum/ws.h" #include "libc/nt/events.h" #include "libc/nt/messagebox.h" #include "libc/nt/paint.h" -#include "libc/nt/struct/msg.h" #include "libc/nt/struct/openfilename.h" -#include "libc/nt/struct/paintstruct.h" -#include "libc/nt/struct/windowplacement.h" -#include "libc/nt/struct/wndclass.h" #include "libc/nt/windows.h" #include "libc/runtime/runtime.h" -#include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/strwidth.h" -#include "libc/str/tpenc.h" -#include "libc/str/unicode.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" -#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/poll.h" -#include "libc/sysv/consts/prot.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" #include "libc/time/time.h" -#include "libc/x/x.h" #include "third_party/getopt/getopt.h" /** @@ -310,12 +293,7 @@ static void Unset(long y, long x) { } static long Population(void) { - long i, n, p; - n = (byn * bxn) >> 6; - for (p = i = 0; i < n; ++i) { - p += popcnt(board[i]); - } - return p; + return _countbits(board, byn * bxn / 64 * 8); } /*───────────────────────────────────────────────────────────────────────────│─╗ @@ -505,9 +483,9 @@ static void *NewBoard(size_t *out_size) { s = (byn * bxn) >> 3; k = PAGESIZE + ROUNDUP(s, PAGESIZE); n = ROUNDUP(k + PAGESIZE, FRAMESIZE); - p = mmap(NULL, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - mprotect(p, PAGESIZE, PROT_NONE); - mprotect(p + k, n - k, PROT_NONE); + p = _mapanon(n); + mprotect(p, PAGESIZE, 0); + mprotect(p + k, n - k, 0); if (out_size) *out_size = n; return p + PAGESIZE; } @@ -734,7 +712,7 @@ static void GetTtySize(void) { struct winsize wsize; wsize.ws_row = tyn + 1; wsize.ws_col = txn; - getttysize(out, &wsize); + _getttysize(out, &wsize); tyn = wsize.ws_row - 1; txn = wsize.ws_col; right = left + txn; @@ -761,11 +739,11 @@ static void OnExit(void) { ioctl(out, TCSETS, &oldterm); } -static void OnSigInt(int sig, struct siginfo *sa, void *uc) { +static void OnSigInt(int sig) { action |= INTERRUPTED; } -static void OnSigWinch(int sig, struct siginfo *sa, void *uc) { +static void OnSigWinch(int sig) { action |= RESIZED; } @@ -1128,8 +1106,8 @@ static void Tui(void) { EnableRaw(); EnableMouse(); atexit(OnExit); - sigaction(SIGINT, &(struct sigaction){.sa_sigaction = OnSigInt}, NULL); - sigaction(SIGWINCH, &(struct sigaction){.sa_sigaction = OnSigWinch}, NULL); + sigaction(SIGINT, &(struct sigaction){.sa_handler = OnSigInt}, 0); + sigaction(SIGWINCH, &(struct sigaction){.sa_handler = OnSigWinch}, 0); do { if (action & RESIZED) { GetTtySize(); diff --git a/tool/viz/magikarp.c b/tool/viz/magikarp.c index 7e52a701c..dceaa0fb3 100644 --- a/tool/viz/magikarp.c +++ b/tool/viz/magikarp.c @@ -28,10 +28,10 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/bsr.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/madv.h" @@ -241,7 +241,7 @@ static void ProcessImageVerbatim(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { CHAR w; void *R, *G, *B, *A; - w = roundup2log(MAX(yn, xn)); + w = _roundup2log(MAX(yn, xn)); R = xvalloc((1u << w) * (1u << w)); G = xvalloc((1u << w) * (1u << w)); B = xvalloc((1u << w) * (1u << w)); @@ -256,7 +256,7 @@ static void ProcessImageVerbatim(LONG yn, LONG xn, static void ProcessImageDouble(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { CHAR w; void *t, *R, *G, *B, *A; - w = roundup2log(MAX(yn, xn)) + 1; + w = _roundup2log(MAX(yn, xn)) + 1; t = xvalloc((1u << w) * (1u << w)); R = xvalloc((1u << w) * (1u << w)); G = xvalloc((1u << w) * (1u << w)); @@ -277,7 +277,7 @@ static void ProcessImageDouble(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { static void ProcessImageHalf(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { CHAR w; void *R, *G, *B, *A; - w = roundup2log(MAX(yn, xn)); + w = _roundup2log(MAX(yn, xn)); R = xvalloc((1u << w) * (1u << w)); G = xvalloc((1u << w) * (1u << w)); B = xvalloc((1u << w) * (1u << w)); @@ -300,7 +300,7 @@ static void ProcessImageHalf(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { static void ProcessImageHalfY(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { CHAR w; void *R, *G, *B, *A; - w = roundup2log(MAX(yn, xn)); + w = _roundup2log(MAX(yn, xn)); R = xvalloc((1u << w) * (1u << w)); G = xvalloc((1u << w) * (1u << w)); B = xvalloc((1u << w) * (1u << w)); @@ -322,7 +322,7 @@ static void ProcessImageHalfLanczos(LONG yn, LONG xn, void *t, *R, *G, *B, *A; t = xvalloc((yn >> 1) * (xn >> 1) * 4); lanczos1b(yn >> 1, xn >> 1, t, yn, xn, &img[0][0][0]); - w = roundup2log(MAX(yn >> 1, xn >> 1)); + w = _roundup2log(MAX(yn >> 1, xn >> 1)); R = xvalloc((1u << w) * (1u << w)); G = xvalloc((1u << w) * (1u << w)); B = xvalloc((1u << w) * (1u << w)); @@ -338,7 +338,7 @@ static void ProcessImageHalfLanczos(LONG yn, LONG xn, static void ProcessImageWash(LONG yn, LONG xn, unsigned char img[yn][xn][4]) { long w; void *R, *G, *B, *A, *t; - w = roundup2log(MAX(yn, xn)) + 1; + w = _roundup2log(MAX(yn, xn)) + 1; t = xvalloc((1u << w) * (1u << w)); R = xvalloc((1u << w) * (1u << w)); G = xvalloc((1u << w) * (1u << w)); @@ -443,7 +443,7 @@ static void ProcessImageMagikarp(LONG syn, LONG sxn, LONG dyn, dxn; dyn = syn >> 1; dxn = sxn >> 1; - sw = roundup2log(MAX(syn, sxn)); + sw = _roundup2log(MAX(syn, sxn)); ProcessImageMagikarpImpl(sw, gc(xvalloc((1u << sw) * (1u << sw) * 5)), syn, sxn, img, dyn, dxn); } diff --git a/tool/viz/maxmind.c b/tool/viz/maxmind.c index baa1b52d6..328a9be3a 100644 --- a/tool/viz/maxmind.c +++ b/tool/viz/maxmind.c @@ -21,7 +21,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "net/http/http.h" #include "net/http/ip.h" diff --git a/tool/viz/memplan.c b/tool/viz/memplan.c index d4577fb2e..e31421bbe 100644 --- a/tool/viz/memplan.c +++ b/tool/viz/memplan.c @@ -24,7 +24,7 @@ struct WinArgs { char envblock[ARG_MAX / 2]; }; -//#define INCREMENT roundup2pow(kAutomapSize/16) +//#define INCREMENT _roundup2pow(kAutomapSize/16) #define INCREMENT (64L*1024*1024*1024) uint64_t last; diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index 9f2266280..4ddeb649d 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -17,10 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/scale/cdecimate2xuint8x8.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/hilbert.h" -#include "libc/intrin/morton.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/sigaction.h" @@ -32,15 +28,20 @@ #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/bsf.h" +#include "libc/intrin/hilbert.h" +#include "libc/intrin/morton.h" +#include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/tpenc.h" #include "libc/log/log.h" #include "libc/macros.internal.h" -#include "libc/nexgen32e/bsf.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpenc.h" +#include "libc/str/unicode.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/map.h" @@ -50,7 +51,6 @@ #include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" #include "libc/time/time.h" -#include "libc/str/unicode.h" #include "third_party/getopt/getopt.h" #define USAGE \ @@ -191,11 +191,11 @@ static void GetTtySize(void) { struct winsize wsize; wsize.ws_row = tyn + 1; wsize.ws_col = txn; - getttysize(out, &wsize); + _getttysize(out, &wsize); tyn = MAX(2, wsize.ws_row) - 1; txn = MAX(17, wsize.ws_col) - 16; - tyn = rounddown2pow(tyn); - txn = rounddown2pow(txn); + tyn = _rounddown2pow(tyn); + txn = _rounddown2pow(txn); tyn = MIN(tyn, txn); } @@ -747,7 +747,7 @@ static void Render(void) { p = FormatInt64(p, fg); *p++ = 'm'; } - w = tpenc(kCp437[c]); + w = _tpenc(kCp437[c]); do { *p++ = w & 0xff; w >>= 8; diff --git a/tool/viz/ntmaster.c b/tool/viz/ntmaster.c index f0fd57448..20c7f748b 100644 --- a/tool/viz/ntmaster.c +++ b/tool/viz/ntmaster.c @@ -21,7 +21,7 @@ #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/x/x.h" +#include "libc/x/xgetline.h" #define DLL "iphlpapi" diff --git a/tool/viz/printansi.c b/tool/viz/printansi.c index 2a8c4bb16..987e20924 100644 --- a/tool/viz/printansi.c +++ b/tool/viz/printansi.c @@ -37,7 +37,7 @@ #include "libc/math.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" diff --git a/tool/viz/printdos2errno.c b/tool/viz/printdos2errno.c index cfb7ef31b..4d479c85d 100644 --- a/tool/viz/printdos2errno.c +++ b/tool/viz/printdos2errno.c @@ -19,7 +19,6 @@ #include "libc/fmt/fmt.h" #include "libc/intrin/dos2errno.internal.h" #include "libc/intrin/kprintf.h" -#include "libc/str/errfun.h" #include "libc/str/str.h" // note: these are supplementary errno magnum mappings @@ -28,11 +27,11 @@ int main(int argc, char *argv[]) { int i; for (i = 0; kDos2Errno[i].doscode; ++i) { - kprintf( - "dos error %10hu maps to rva %10d errno %10d which is %s%n", - kDos2Errno[i].doscode, kDos2Errno[i].systemv, - *(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv), - strerrno(*(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv))); + kprintf("dos error %10hu maps to rva %10d errno %10d which is %s%n", + kDos2Errno[i].doscode, kDos2Errno[i].systemv, + *(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv), + _strerrno( + *(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv))); } return 0; } diff --git a/tool/viz/printimage.c b/tool/viz/printimage.c index 118a70954..b939de902 100644 --- a/tool/viz/printimage.c +++ b/tool/viz/printimage.c @@ -30,7 +30,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/ex.h" diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 248b6fe7b..bd3164d8b 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -34,6 +34,7 @@ #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/sigset.h" +#include "libc/calls/struct/winsize.h" #include "libc/calls/termios.h" #include "libc/calls/ucontext.h" #include "libc/dns/dns.h" @@ -55,8 +56,7 @@ #include "libc/nexgen32e/x86feature.h" #include "libc/nt/console.h" #include "libc/nt/runtime.h" -#include "libc/runtime/buffer.h" -#include "libc/runtime/gc.internal.h" +#include "libc/runtime/buffer.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" @@ -91,7 +91,7 @@ #include "libc/sysv/consts/w.h" #include "libc/sysv/errfuns.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" #include "third_party/getopt/getopt.h" #include "third_party/stb/stb_image_resize.h" #include "tool/viz/lib/graphic.h" @@ -428,7 +428,7 @@ static void DimensionDisplay(void) { wsize_.ws_row = 25; wsize_.ws_col = 80; wsize_ = (struct winsize){.ws_row = 40, .ws_col = 80}; - if (getttysize(outfd_, &wsize_) == -1) getttysize(0, &wsize_); + if (_getttysize(outfd_, &wsize_) == -1) _getttysize(0, &wsize_); dh_ = wsize_.ws_row * 2; dw_ = wsize_.ws_col * 2; } @@ -1397,8 +1397,8 @@ static void OnExit(void) { YCbCrFree(&ycbcr_); RestoreTty(); ttyidentclear(&ti_); - close_s(&infd_); - close_s(&outfd_); + close(infd_), infd_ = -1; + close(outfd_), outfd_ = -1; bfree(&graphic_[0].b); bfree(&graphic_[1].b); bfree(&vtframe_[0].b); diff --git a/tool/viz/tailf.c b/tool/viz/tailf.c index 364f38a2d..78f755f80 100644 --- a/tool/viz/tailf.c +++ b/tool/viz/tailf.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -26,7 +26,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/sig.h" #include "libc/time/time.h" -#include "libc/x/x.h" +#include "libc/x/xsigaction.h" /** * @fileoverview tail -f with lower poll rate diff --git a/tool/viz/unicode.c b/tool/viz/unicode.c index f6258cbbd..33388c504 100644 --- a/tool/viz/unicode.c +++ b/tool/viz/unicode.c @@ -18,11 +18,11 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" -#include "libc/runtime/gc.internal.h" +#include "libc/mem/gc.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/unicode.h" -#include "libc/x/x.h" +#include "libc/x/xasprintf.h" int a, b, w, i; char name[512]; @@ -65,7 +65,7 @@ void DisplayUnicodeBlock(void) { printf("\n\n%-60s%20s\n" "──────────────────────────────────────────────" "──────────────────────────────────\n", - name, gc(xasprintf("%04x .. %04x", a, b))); + name, _gc(xasprintf("%04x .. %04x", a, b))); w = 0; for (i = a; i <= b; ++i) { DisplayUnicodeCharacter(); diff --git a/tool/viz/vdsosyms.c b/tool/viz/vdsosyms.c index 39fecbfd2..d745b3c75 100644 --- a/tool/viz/vdsosyms.c +++ b/tool/viz/vdsosyms.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/elf/def.h" #include "libc/elf/scalar.h" #include "libc/elf/struct/ehdr.h"