mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH v2] track pthread stack guard sizes
@ 2018-02-02 20:08 William Pitcock
  2018-02-05 16:18 ` Alexander Monakov
  0 siblings, 1 reply; 4+ messages in thread
From: William Pitcock @ 2018-02-02 20:08 UTC (permalink / raw)
  To: musl; +Cc: William Pitcock

some applications (rustc) are dependent on pthread_getattr_np() providing the guard size.
---
 src/internal/pthread_impl.h     | 1 +
 src/thread/pthread_create.c     | 3 ++-
 src/thread/pthread_getattr_np.c | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h
index f0b2c20c..4a0db987 100644
--- a/src/internal/pthread_impl.h
+++ b/src/internal/pthread_impl.h
@@ -46,6 +46,7 @@ struct pthread {
 	char *dlerror_buf;
 	int dlerror_flag;
 	void *stdio_locks;
+	size_t guard_size;
 	uintptr_t canary_at_end;
 	void **dtv_copy;
 };
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 34cd9936..439ee363 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -232,8 +232,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
 			memset(stack, 0, need);
 		} else {
 			size = ROUND(need);
-			guard = 0;
 		}
+		guard = 0;
 	} else {
 		guard = ROUND(attr._a_guardsize);
 		size = guard + ROUND(attr._a_stacksize
@@ -265,6 +265,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
 	new->map_size = size;
 	new->stack = stack;
 	new->stack_size = stack - stack_limit;
+	new->guard_size = guard;
 	new->start = entry;
 	new->start_arg = arg;
 	new->self = new;
diff --git a/src/thread/pthread_getattr_np.c b/src/thread/pthread_getattr_np.c
index ae26a5ab..29a209bd 100644
--- a/src/thread/pthread_getattr_np.c
+++ b/src/thread/pthread_getattr_np.c
@@ -7,6 +7,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
 {
 	*a = (pthread_attr_t){0};
 	a->_a_detach = !!t->detached;
+	a->_a_guardsize = t->guard_size;
 	if (t->stack) {
 		a->_a_stackaddr = (uintptr_t)t->stack;
 		a->_a_stacksize = t->stack_size;
-- 
2.16.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] track pthread stack guard sizes
  2018-02-02 20:08 [PATCH v2] track pthread stack guard sizes William Pitcock
@ 2018-02-05 16:18 ` Alexander Monakov
  2018-02-05 16:24   ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Monakov @ 2018-02-05 16:18 UTC (permalink / raw)
  To: musl

On Fri, 2 Feb 2018, William Pitcock wrote:
> --- a/src/internal/pthread_impl.h
> +++ b/src/internal/pthread_impl.h
> @@ -46,6 +46,7 @@ struct pthread {
>  	char *dlerror_buf;
>  	int dlerror_flag;
>  	void *stdio_locks;
> +	size_t guard_size;
>  	uintptr_t canary_at_end;
>  	void **dtv_copy;
>  };

Doesn't this break SSP on powerpc and powerpc64 by changing offset of
'canary_at_end'? If not, can you please mention why in the commit message?

Alexander


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] track pthread stack guard sizes
  2018-02-05 16:18 ` Alexander Monakov
@ 2018-02-05 16:24   ` Rich Felker
  2018-02-05 16:50     ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Felker @ 2018-02-05 16:24 UTC (permalink / raw)
  To: musl

On Mon, Feb 05, 2018 at 07:18:44PM +0300, Alexander Monakov wrote:
> On Fri, 2 Feb 2018, William Pitcock wrote:
> > --- a/src/internal/pthread_impl.h
> > +++ b/src/internal/pthread_impl.h
> > @@ -46,6 +46,7 @@ struct pthread {
> >  	char *dlerror_buf;
> >  	int dlerror_flag;
> >  	void *stdio_locks;
> > +	size_t guard_size;
> >  	uintptr_t canary_at_end;
> >  	void **dtv_copy;
> >  };
> 
> Doesn't this break SSP on powerpc and powerpc64 by changing offset of
> 'canary_at_end'? If not, can you please mention why in the commit message?

The "_at_end" means it's at a fixed negative offset from the end of
the structure. I already have this patch pending push in my tree, but
I can add a separate commit commenting the ABI-mandated layout of the
structure.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] track pthread stack guard sizes
  2018-02-05 16:24   ` Rich Felker
@ 2018-02-05 16:50     ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2018-02-05 16:50 UTC (permalink / raw)
  To: musl

On Mon, Feb 05, 2018 at 11:24:03AM -0500, Rich Felker wrote:
> On Mon, Feb 05, 2018 at 07:18:44PM +0300, Alexander Monakov wrote:
> > On Fri, 2 Feb 2018, William Pitcock wrote:
> > > --- a/src/internal/pthread_impl.h
> > > +++ b/src/internal/pthread_impl.h
> > > @@ -46,6 +46,7 @@ struct pthread {
> > >  	char *dlerror_buf;
> > >  	int dlerror_flag;
> > >  	void *stdio_locks;
> > > +	size_t guard_size;
> > >  	uintptr_t canary_at_end;
> > >  	void **dtv_copy;
> > >  };
> > 
> > Doesn't this break SSP on powerpc and powerpc64 by changing offset of
> > 'canary_at_end'? If not, can you please mention why in the commit message?
> 
> The "_at_end" means it's at a fixed negative offset from the end of
> the structure. I already have this patch pending push in my tree, but
> I can add a separate commit commenting the ABI-mandated layout of the
> structure.

Done, pending push. BTW I wonder if we should also add static asserts
for this sort of thing, e.g.

_Static_assert(offsetof(struct pthread, canary_at_end) == sizeof(struct pthread) - 2*sizeof(size_t))

It would probably have to be implemented without actually using the
_Static_assert keyword since we don't depend on a C11 compiler, but of
course the usual tricks apply just fine.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-05 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-02 20:08 [PATCH v2] track pthread stack guard sizes William Pitcock
2018-02-05 16:18 ` Alexander Monakov
2018-02-05 16:24   ` Rich Felker
2018-02-05 16:50     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).