source: release/1.9/source/lisp-kernel/x86-utils.c @ 16083

Last change on this file since 16083 was 15090, checked in by rme, 8 years ago

New functions ptr_in_area() and in_any_consing_area().

File size: 1.7 KB
Line 
1/*
2   Copyright (C) 2011 Clozure Associates
3   This file is part of Clozure CL. 
4
5   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
6   License , known as the LLGPL and distributed with Clozure CL as the
7   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
8   which is distributed with Clozure CL as the file "LGPL".  Where these
9   conflict, the preamble takes precedence. 
10
11   Clozure CL is referenced in the preamble as the "LIBRARY."
12
13   The LLGPL is also available online at
14   http://opensource.franz.com/preamble.html
15*/
16
17#include "lisp.h"
18#include "x86-utils.h"
19
20LispObj
21tra_function(LispObj tra)
22{
23  LispObj f = 0;
24
25#ifdef X8664
26  if (tag_of(tra) == tag_tra) {
27    if ((*((unsigned short *)tra) == RECOVER_FN_FROM_RIP_WORD0) &&
28        (*((unsigned char *)(tra + 2)) == RECOVER_FN_FROM_RIP_BYTE2)) {
29      int sdisp = (*(int *)(tra + RECOVER_FN_FROM_RIP_DISP_OFFSET));
30      f = RECOVER_FN_FROM_RIP_LENGTH + tra + sdisp;
31    }
32  }
33#else
34  if (fulltag_of(tra) == fulltag_tra) {
35    if (*((unsigned char *)tra) == RECOVER_FN_OPCODE) {
36      natural n = *((natural *)(tra + 1));
37      f = (LispObj)n;
38    }
39  }
40#endif
41  return f;
42}
43
44int
45tra_offset(LispObj tra)
46{
47  LispObj f = tra_function(tra);
48  int disp = 0;
49
50  if (functionp(f))
51    disp = tra - f;
52  return disp;
53}
54
55int
56ptr_in_area(char *p, area *a)
57{
58  return a->low <= p && a->high > p;
59}
60
61area *
62in_any_consing_area(LispObj thing)
63{
64  area *a = all_areas->succ;
65  char *p = (char *)thing;
66
67  while (a != all_areas) {
68    area_code code = a->code;
69    if (code == AREA_READONLY || code == AREA_WATCHED ||
70        code == AREA_MANAGED_STATIC || code == AREA_STATIC ||
71        code == AREA_DYNAMIC) {
72      if (a->low <= p && p < a->high)
73        return a;
74    }
75    a = a->succ;
76  }
77  return NULL;
78}
Note: See TracBrowser for help on using the repository browser.