Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Mar 2017 13:11:30 +0000 (UTC)
From:      Peter Holm <pho@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r315637 - user/pho/stress2/misc
Message-ID:  <201703201311.v2KDBUVr027418@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pho
Date: Mon Mar 20 13:11:30 2017
New Revision: 315637
URL: https://svnweb.freebsd.org/changeset/base/315637

Log:
  Added a regression test.
  
  Submitted by:	Steven Hartland <killing@multiplay.co.uk>
  Sponsored by:	Dell EMC Isilon

Added:
  user/pho/stress2/misc/sigaltstack.sh   (contents, props changed)

Added: user/pho/stress2/misc/sigaltstack.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/sigaltstack.sh	Mon Mar 20 13:11:30 2017	(r315637)
@@ -0,0 +1,129 @@
+#!/bin/sh
+
+# sigaltstack(2) regression test by Steven Hartland <killing@multiplay.co.uk>
+# Wrong altsigstack clearing on exec
+# https://github.com/golang/go/issues/15658#issuecomment-287276856
+
+# Fixed by r315453
+
+cd /tmp
+cat > test-sigs.c <<EOF
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <pthread.h>
+
+extern char **environ;
+
+static void
+die(const char *s)
+{
+       perror(s);
+       exit(EXIT_FAILURE);
+}
+
+static void
+setstack(void *arg __unused)
+{
+	stack_t ss;
+
+	ss.ss_sp = malloc(SIGSTKSZ);
+	if (ss.ss_sp == NULL)
+		die("malloc");
+
+	ss.ss_size = SIGSTKSZ;
+	ss.ss_flags = 0;
+	if (sigaltstack(&ss, NULL) < 0)
+		die("sigaltstack set");
+}
+
+static void *
+thread_exec(void *arg)
+{
+	struct timespec ts = {0, 1000};
+	char *argv[] = {"./test-sigs", "no-more", 0};
+
+	setstack(arg);
+	nanosleep(&ts, NULL);
+
+	execve(argv[0], &argv[0], environ);
+	die("exec failed");
+
+	return NULL;
+}
+
+static void *
+thread_sleep(void *arg __unused)
+{
+	sleep(10);
+
+	return NULL;
+}
+
+
+int
+main(int argc, char** argv __unused)
+{
+	int j;
+	pthread_t tid1, tid2;
+
+	if (argc != 1) {
+		stack_t ss;
+
+		if (sigaltstack(NULL, &ss) < 0)
+			die("sigaltstack get");
+
+		if (ss.ss_sp != NULL || ss.ss_flags != SS_DISABLE ||
+		    ss.ss_size != 0) {
+			fprintf(stderr, "invalid signal stack after execve: "
+			    "ss_sp=%p ss_size=%lu ss_flags=0x%x\n", ss.ss_sp,
+			    (unsigned long)ss.ss_size,
+			    (unsigned int)ss.ss_flags);
+			return 1;
+		}
+
+		printf("valid signal stack is valid after execve\n");
+
+		return 0;
+	}
+
+	// We have to use two threads to ensure that can detect the
+	// issue when new threads are added to the head (pre 269095)
+	// and the tail of the process thread list.
+	j = pthread_create(&tid1, NULL, thread_exec, NULL);
+	if (j != 0) {
+	       errno = j;
+	       die("pthread_create");
+	}
+
+	j = pthread_create(&tid2, NULL, thread_sleep, NULL);
+	if (j != 0) {
+	       errno = j;
+	       die("pthread_create");
+	}
+
+	j = pthread_join(tid1, NULL);
+	if (j != 0) {
+		errno = j;
+		die("pthread_join");
+	}
+
+	j = pthread_join(tid2, NULL);
+	if (j != 0) {
+		errno = j;
+	}
+
+	return 0;
+}
+EOF
+
+cc -o test-sigs -Wall -Wextra -O2 -g test-sigs.c -lpthread || exit 1
+./test-sigs
+s=$?
+
+rm -f test-sigs test-sigs.c
+exit $s



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703201311.v2KDBUVr027418>