Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Test for stack alignment.
- Loading branch information
Ulrich Drepper
committed
Dec 22, 2004
1 parent
ec8c29d
commit 7d58530
Showing
9 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* Copyright (C) 2003 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, write to the Free | ||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
02111-1307 USA. */ | ||
|
||
#include <pthread.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <tst-stack-align.h> | ||
|
||
static void * | ||
tf (void *arg) | ||
{ | ||
bool ok = true; | ||
|
||
puts ("in thread"); | ||
|
||
if (TEST_STACK_ALIGN ()) | ||
ok = false; | ||
|
||
return ok ? NULL : (void *) -1l; | ||
} | ||
|
||
static int | ||
do_test (void) | ||
{ | ||
bool ok = true; | ||
|
||
puts ("in main"); | ||
|
||
if (TEST_STACK_ALIGN ()) | ||
ok = false; | ||
|
||
pthread_t th; | ||
if (pthread_create (&th, NULL, tf, NULL) != 0) | ||
{ | ||
puts ("create failed"); | ||
return 1; | ||
} | ||
|
||
void *res; | ||
if (pthread_join (th, &res) != 0) | ||
{ | ||
puts ("join failed"); | ||
return 1; | ||
} | ||
|
||
if (res != NULL) | ||
ok = false; | ||
|
||
return ok ? 0 : 1; | ||
} | ||
|
||
|
||
#define TEST_FUNCTION do_test () | ||
#include "../test-skeleton.c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* Copyright (C) 2004 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, write to the Free | ||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
02111-1307 USA. */ | ||
|
||
#include <sched.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include <tst-stack-align.h> | ||
|
||
static int | ||
f (void *arg) | ||
{ | ||
bool ok = true; | ||
|
||
if (TEST_STACK_ALIGN ()) | ||
ok = false; | ||
|
||
return ok ? 0 : 1; | ||
} | ||
|
||
static int | ||
do_test (void) | ||
{ | ||
bool ok = true; | ||
|
||
puts ("in main"); | ||
|
||
if (TEST_STACK_ALIGN ()) | ||
ok = false; | ||
|
||
#ifdef __ia64__ | ||
extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base, | ||
size_t __child_stack_size, int __flags, | ||
void *__arg, ...); | ||
char st[256 * 1024]; | ||
pid_t p = __clone2 (f, st, sizeof (st), 0, 0); | ||
#else | ||
char st[128 * 1024]; | ||
pid_t p = clone (f, st + sizeof (st), 0, 0); | ||
#endif | ||
if (p == -1) | ||
{ | ||
printf("clone failed: %m\n"); | ||
return 1; | ||
} | ||
|
||
int e; | ||
if (waitpid (p, &e, __WCLONE) != p) | ||
{ | ||
puts ("waitpid failed"); | ||
kill (p, SIGKILL); | ||
return 1; | ||
} | ||
if (!WIFEXITED (e)) | ||
{ | ||
if (WIFSIGNALED (e)) | ||
printf ("died from signal %s\n", strsignal (WTERMSIG (e))); | ||
else | ||
puts ("did not terminate correctly"); | ||
return 1; | ||
} | ||
if (WEXITSTATUS (e) != 0) | ||
ok = false; | ||
|
||
return ok ? 0 : 1; | ||
} | ||
|
||
#define TEST_FUNCTION do_test () | ||
#include "../test-skeleton.c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Copyright (C) 2004 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, write to the Free | ||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
02111-1307 USA. */ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
typedef struct { int i[4]; } int_al16 __attribute__((aligned (16))); | ||
|
||
#define TEST_STACK_ALIGN() \ | ||
({ \ | ||
int_al16 _m; \ | ||
double _d = 12.0; \ | ||
long double _ld = 15.0; \ | ||
int _ret = 0; \ | ||
printf ("int_al16: %p %zu\n", &_m, __alignof (int_al16)); \ | ||
if ((((uintptr_t) &_m) & (__alignof (int_al16) - 1)) != 0) \ | ||
_ret = 1; \ | ||
\ | ||
printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ | ||
if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ | ||
_ret = 1; \ | ||
\ | ||
printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ | ||
if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ | ||
_ret = 1; \ | ||
_ret; \ | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters