NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg/57708: rust problem when building firefox



> Date: Sun, 19 Nov 2023 20:52:17 +0000
> From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
> 
> The attached program [...]

actually attached now.
#include <err.h>
#include <pthread.h>
#include <stdio.h>

static void
showstack(const char *who)
{
	pthread_attr_t attr;
	void *stackaddr, *guardaddr;
	size_t stacksize, guardsize;
	int error;

	error = pthread_getattr_np(pthread_self(), &attr);
	if (error)
		errc(1, error, "pthread_getattr_np");

	error = pthread_attr_getstack(&attr, &stackaddr, &stacksize);
	if (error)
		errc(1, error, "pthread_attr_getstack");
	error = pthread_attr_getguardsize(&attr, &guardsize);
	if (error)
		errc(1, error, "pthread_attr_getguardsize");

	error = pthread_attr_destroy(&attr);
	if (error)
		errc(1, error, "pthread_attr_destroy");

#ifdef __MACHINE_STACK_GROWS_UP
	guardaddr = (char *)stackaddr + stacksize - guardsize;
#else
	guardaddr = stackaddr;
#endif

	printf("%s: stack %zu/0x%zx bytes @ [%p, %p)\n",
	    who, stacksize, stacksize,
	    stackaddr, (char *)stackaddr + stacksize);
	printf("%s: guard %zu/0x%zx bytes @ [%p, %p)\n",
	    who, guardsize, guardsize,
	    guardaddr, (char *)guardaddr + guardsize);
}

static void *
start(void *cookie)
{

	showstack("pthread_create");
	return cookie;
}

int
main(void)
{
	pthread_t t;
	int error;

	showstack("main thread");
	fflush(stdout);

	error = pthread_create(&t, NULL, &start, NULL);
	if (error)
		errc(1, error, "pthread_create");
	error = pthread_join(t, NULL);
	if (error)
		errc(1, error, "pthread_join");

	fflush(stdout);
	return ferror(stdout);
}


Home | Main Index | Thread Index | Old Index