runtime: use alignof to check alignment of ucontext_t
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 9 Sep 2016 16:39:44 +0000 (16:39 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 9 Sep 2016 16:39:44 +0000 (16:39 +0000)
    Use alignof rather than assuming a 16 byte alignment.

    Reviewed-on: https://go-review.googlesource.com/28913

From-SVN: r240047

gcc/go/gofrontend/MERGE
libgo/runtime/proc.c

index 99e32cec32db1735c8275c50894082f60d7fd743..261a79ae2bbbabc8fe1c0af6c92a1367646aaa41 100644 (file)
@@ -1,4 +1,4 @@
-b37a9e66ea584885043240f8f6f1d1c0284eadec
+6c1f159cdcb56ebff617f6bbc6c97943a1a8a34d
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 7e2b172492e2d870854b53facef6569ec9b7371d..6ac8857338b6e82c8242fc6fa1a295b9975b9308 100644 (file)
@@ -166,7 +166,13 @@ static ucontext_t*
 ucontext_arg(void** go_ucontext)
 {
        uintptr_t p = (uintptr_t)go_ucontext;
-       p = (p + 15) &~ (uintptr_t)0xf;
+       size_t align = __alignof__(ucontext_t);
+       if(align > 16) {
+               // We only ensured space for up to a 16 byte alignment
+               // in libgo/go/runtime/runtime2.go.
+               runtime_throw("required alignment of ucontext_t too large");
+       }
+       p = (p + align - 1) &~ (uintptr_t)(align - 1);
        return (ucontext_t*)p;
 }