]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: remove memset in _cgo_sys_thread_start on linux
authorTobias Klauser <tklauser@distanz.ch>
Thu, 5 May 2022 18:46:29 +0000 (20:46 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Fri, 6 May 2022 15:32:04 +0000 (15:32 +0000)
pthread_attr_init in glibc and musl libc already explicitly clear the
pthread_attr argument before setting it, see
https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_attr_init.c
and https://git.musl-libc.org/cgit/musl/log/src/thread/pthread_attr_init.c

It looks like pthread_attr_init has been implemented like this for a
long time in both libcs. The comment and memset in _cgo_sys_thread_start
probably stem from a time where not all libcs did the explicit memset in
pthread_attr_init.

Also, the memset in _cgo_sys_thread_start is not performed on all linux
platforms further indicating that this isn't an issue anymore.

Change-Id: I920148b5d24751195ced7af5bb7c52a7f8293259
Reviewed-on: https://go-review.googlesource.com/c/go/+/404275
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/runtime/cgo/gcc_darwin_arm64.c
src/runtime/cgo/gcc_linux_386.c
src/runtime/cgo/gcc_linux_arm.c
src/runtime/cgo/gcc_linux_arm64.c
src/runtime/cgo/gcc_linux_mips64x.c
src/runtime/cgo/gcc_linux_mipsx.c
src/runtime/cgo/gcc_linux_riscv64.c

index a5f07f1f1bc71bdcf26c2dd09d42087c54019b1d..24be6758d928acc2e9728db968326eed7610b707 100644 (file)
@@ -37,7 +37,6 @@ _cgo_sys_thread_start(ThreadStart *ts)
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;
index 70c942aeb842d9bd87d23d2bb6a61e3ec666184d..0ce93596166961f41f2e3199472b2c9813320fe0 100644 (file)
@@ -43,12 +43,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
        sigfillset(&ign);
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
-       // Not sure why the memset is necessary here,
-       // but without it, we get a bogus stack size
-       // out of pthread_attr_getstacksize. C'est la Linux.
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;
index 5bc0fee90d4949bda561b86195005296d9e70567..5e97a9ed314b355ac28294f295abcc6f6e86b30e 100644 (file)
@@ -25,12 +25,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
        sigfillset(&ign);
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
-       // Not sure why the memset is necessary here,
-       // but without it, we get a bogus stack size
-       // out of pthread_attr_getstacksize. C'est la Linux.
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;
index 17ff274fbbeae61c2a42f702502e63f07c92e985..dac45e418be2951b25aa5304f151b978708ee2ca 100644 (file)
@@ -27,12 +27,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
        sigfillset(&ign);
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
-       // Not sure why the memset is necessary here,
-       // but without it, we get a bogus stack size
-       // out of pthread_attr_getstacksize. C'est la Linux.
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;
index 42837b14df54aebe97a7be7256d9f58d44367ed4..3ea29b0f86a1c60de2b55fbd4a38ac07c68bafa7 100644 (file)
@@ -29,12 +29,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
        sigfillset(&ign);
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
-       // Not sure why the memset is necessary here,
-       // but without it, we get a bogus stack size
-       // out of pthread_attr_getstacksize.  C'est la Linux.
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;
index a44ea3057da44e3fd297e2539c10c04cfa754af6..3b60a0ea5899b426951d3250cc5540489deeada3 100644 (file)
@@ -29,12 +29,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
        sigfillset(&ign);
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
-       // Not sure why the memset is necessary here,
-       // but without it, we get a bogus stack size
-       // out of pthread_attr_getstacksize.  C'est la Linux.
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;
@@ -68,7 +63,6 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
 
        setg_gcc = setg;
 
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
        pthread_attr_getstacksize(&attr, &size);
        g->stacklo = (uintptr)&attr - size + 4096;
index 22b76c2fccf40510d227bcdb67242648957abfe7..99c2866de42c084d1c5955336412ceeb22dc8f2e 100644 (file)
@@ -25,12 +25,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
        sigfillset(&ign);
        pthread_sigmask(SIG_SETMASK, &ign, &oset);
 
-       // Not sure why the memset is necessary here,
-       // but without it, we get a bogus stack size
-       // out of pthread_attr_getstacksize.  C'est la Linux.
-       memset(&attr, 0, sizeof attr);
        pthread_attr_init(&attr);
-       size = 0;
        pthread_attr_getstacksize(&attr, &size);
        // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
        ts->g->stackhi = size;