Make more fixes and improvements

- Remove PAGESIZE constant
- Fix realloc() documentation
- Fix ttyname_r() error reporting
- Make forking more reliable on Windows
- Make execvp() a few microseconds faster
- Make system() a few microseconds faster
- Tighten up the socket-related magic numbers
- Loosen restrictions on mmap() offset alignment
- Improve GetProgramExecutableName() with getenv("_")
- Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd()
- Fix flakes in pthread_cancel_test, unix_test, fork_test
- Fix recently introduced futex stack overflow regression
- Let sockets be passed as stdio to subprocesses on Windows
- Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
Justine Tunney 2023-07-29 18:44:15 -07:00
parent 140a8a52e5
commit 18bb5888e1
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
311 changed files with 1239 additions and 2622 deletions

View file

@ -16,15 +16,19 @@
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/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/msync.h"
#include "libc/sysv/consts/prot.h"
@ -38,6 +42,7 @@ TEST(fork, testPipes) {
int a, b;
int ws, pid;
int pipefds[2];
alarm(5);
ASSERT_NE(-1, pipe(pipefds));
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
@ -52,9 +57,11 @@ TEST(fork, testPipes) {
EXPECT_NE(-1, close(pipefds[0]));
EXPECT_NE(-1, waitpid(pid, &ws, 0));
EXPECT_EQ(31337, b);
alarm(0);
}
TEST(fork, testSharedMemory) {
alarm(5);
int ws, pid;
int stackvar;
int *sharedvar;
@ -86,6 +93,7 @@ TEST(fork, testSharedMemory) {
EXPECT_EQ(1, *privatevar);
EXPECT_NE(-1, munmap(sharedvar, FRAMESIZE));
EXPECT_NE(-1, munmap(privatevar, FRAMESIZE));
alarm(0);
}
static volatile bool gotsigusr1;
@ -109,6 +117,7 @@ TEST(fork, childToChild) {
signal(SIGUSR1, OnSigusr1);
signal(SIGUSR2, OnSigusr2);
sigemptyset(&mask);
sigaddset(&mask, SIGUSR1);
sigaddset(&mask, SIGUSR2);
sigprocmask(SIG_BLOCK, &mask, &oldmask);
ASSERT_NE(-1, (child1 = fork()));
@ -117,28 +126,27 @@ TEST(fork, childToChild) {
sigsuspend(0);
_Exit(!gotsigusr1);
}
sigdelset(&mask, SIGUSR2);
sigsuspend(&mask);
sigsuspend(0);
ASSERT_NE(-1, (child2 = fork()));
if (!child2) {
kill(child1, SIGUSR1);
_Exit(0);
}
ASSERT_NE(-1, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(0, WEXITSTATUS(ws));
EXPECT_EQ(0, ws);
ASSERT_NE(-1, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(0, WEXITSTATUS(ws));
EXPECT_EQ(0, ws);
sigprocmask(SIG_SETMASK, &oldmask, 0);
}
TEST(fork, preservesTlsMemory) {
alarm(5);
int pid;
__get_tls()->tib_errno = 31337;
SPAWN(fork);
ASSERT_EQ(31337, __get_tls()->tib_errno);
EXITS(0);
alarm(0);
}
void ForkInSerial(void) {