OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-recover.c] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* go-recover.c -- support for the go recover function.
2
 
3
   Copyright 2010 The Go Authors. All rights reserved.
4
   Use of this source code is governed by a BSD-style
5
   license that can be found in the LICENSE file.  */
6
 
7
#include "runtime.h"
8
#include "interface.h"
9
#include "go-panic.h"
10
#include "go-defer.h"
11
 
12
/* This is called by a thunk to see if the real function should be
13
   permitted to recover a panic value.  Recovering a value is
14
   permitted if the thunk was called directly by defer.  RETADDR is
15
   the return address of the function which is calling
16
   __go_can_recover--this is, the thunk.  */
17
 
18
_Bool
19
__go_can_recover (const void* retaddr)
20
{
21
  G *g;
22
  struct __go_defer_stack *d;
23
  const char* ret;
24
  const char* dret;
25
 
26
  g = runtime_g ();
27
 
28
  d = g->defer;
29
  if (d == NULL)
30
    return 0;
31
 
32
  /* The panic which this function would recover is the one on the top
33
     of the panic stack.  We do not want to recover it if that panic
34
     was on the top of the panic stack when this function was
35
     deferred.  */
36
  if (d->__panic == g->panic)
37
    return 0;
38
 
39
  /* D->__RETADDR is the address of a label immediately following the
40
     call to the thunk.  We can recover a panic if that is the same as
41
     the return address of the thunk.  We permit a bit of slack in
42
     case there is any code between the function return and the label,
43
     such as an instruction to adjust the stack pointer.  */
44
 
45
  ret = (const char *) retaddr;
46
 
47
#ifdef __sparc__
48
  /* On SPARC the address we get, from __builtin_return_address, is
49
     the address of the call instruction.  Adjust forward, also
50
     skipping the delayed instruction following the call.  */
51
  ret += 8;
52
#endif
53
 
54
  dret = (const char *) d->__retaddr;
55
  return ret <= dret && ret + 16 >= dret;
56
}
57
 
58
/* This is only called when it is valid for the caller to recover the
59
   value on top of the panic stack, if there is one.  */
60
 
61
struct __go_empty_interface
62
__go_recover ()
63
{
64
  G *g;
65
  struct __go_panic_stack *p;
66
 
67
  g = runtime_g ();
68
 
69
  if (g->panic == NULL || g->panic->__was_recovered)
70
    {
71
      struct __go_empty_interface ret;
72
 
73
      ret.__type_descriptor = NULL;
74
      ret.__object = NULL;
75
      return ret;
76
    }
77
  p = g->panic;
78
  p->__was_recovered = 1;
79
  return p->__arg;
80
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.