• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2004 Hewlett-Packard Co
3 	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 
5 This file is part of libunwind.
6 
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25 
26 /* This file verifies that read-only registers cannot be written to.  */
27 
28 #include <errno.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #include <libunwind.h>
34 
35 #define panic(args...)							  \
36 	do { printf (args); ++nerrors; } while (0)
37 
38 static int verbose;
39 static int nerrors;
40 
41 extern void test_func (void (*) (void));
42 
43 void
checker(void)44 checker (void)
45 {
46   unw_fpreg_t fpval;
47   unw_context_t uc;
48   unw_cursor_t c;
49   int ret;
50 
51   fpval.raw.bits[0] = 100;
52   fpval.raw.bits[1] = 101;
53 
54   unw_getcontext (&uc);
55 
56   if ((ret = unw_init_local (&c, &uc)) < 0)
57     panic ("%s: unw_init_local (ret=%d)\n", __FUNCTION__, ret);
58 
59   if ((ret = unw_step (&c)) < 0)
60     panic ("%s: unw_step (ret=%d)\n", __FUNCTION__, ret);
61 
62   if ((ret = unw_step (&c)) < 0)
63     panic ("%s: unw_step (ret=%d)\n", __FUNCTION__, ret);
64 
65   if ((ret = unw_set_reg (&c, UNW_IA64_IP, 99)) != -UNW_EREADONLYREG)
66     panic ("%s: unw_set_reg (ip) returned %d instead of %d\n",
67 	   __FUNCTION__, ret, -UNW_EREADONLYREG);
68   if ((ret = unw_set_reg (&c, UNW_IA64_AR_LC, 99)) != -UNW_EREADONLYREG)
69     panic ("%s: unw_set_reg (ar.lc) returned %d instead of %d\n",
70 	   __FUNCTION__, ret, -UNW_EREADONLYREG);
71 }
72 
73 int
main(int argc,char ** argv)74 main (int argc, char **argv)
75 {
76   if (argc > 1)
77     verbose = 1;
78 
79   test_func (checker);
80 
81   if (nerrors > 0)
82     {
83       fprintf (stderr, "FAILURE: detected %d errors\n", nerrors);
84       exit (-1);
85     }
86   if (verbose)
87     printf ("SUCCESS.\n");
88   return 0;
89 }
90