dec93aa25157778784a699030e0b6f0bc8a7eff7
[ghc-hetmet.git] / ghc / runtime / c-as-asm / StablePtrOps.lc
1 \section[stable-ptr-ops]{Stable Pointer Operations}
2
3 The code that implements @performIO@ is mostly in
4 @ghc/runtime/c-as-asm/PerformIO.lhc@.  However, this code can be
5 called from the C world so it goes in a @.lc@ file.
6
7 This code is based heavily on the code in @ghc/runtime/main/main.lc@.
8
9 It is used to call a (stable pointer to a) function of type
10 @IoWorld -> PrimIntAndIoWorld@ (ie @PrimIO_Int#@).
11
12 (I doubt very much that this works at the moment - and we're going to
13 change it to take/return a byte array anyway.  Code in PerformIO.lhc
14 is even more dated.)
15
16 \begin{code}
17 #ifndef PAR
18
19 #include "rtsdefs.h"
20
21 extern StgPtr unstable_Closure;
22
23 void
24 enterStablePtr(stableIndex, startCode)
25   StgStablePtr stableIndex;
26   StgFunPtr startCode;
27 {
28     unstable_Closure
29       = _deRefStablePointer(stableIndex, StorageMgrInfo.StablePointerTable);
30
31 /* ToDo: Set arity to right value - if necessary */
32
33     miniInterpret(startCode);
34 }
35 \end{code}
36
37 \begin{code}
38 EXTFUN(startPerformIO);
39
40 extern void checkInCCallGC(STG_NO_ARGS);
41
42 void
43 performIO(stableIndex)
44   StgStablePtr stableIndex;
45 {
46   checkInCCallGC();
47   enterStablePtr( stableIndex, (StgFunPtr) startPerformIO );
48 }
49
50 extern StgInt enterInt_Result;
51 EXTFUN(startEnterInt);
52
53 StgInt
54 enterInt(stableIndex)
55   StgStablePtr stableIndex;
56 {
57   checkInCCallGC();
58   enterStablePtr( stableIndex, (StgFunPtr) startEnterInt );
59   return enterInt_Result;
60 }
61
62 extern StgFloat enterFloat_Result;
63 EXTFUN(startEnterFloat);
64
65 StgInt
66 enterFloat(stableIndex)
67   StgStablePtr stableIndex;
68 {
69   checkInCCallGC();
70   enterStablePtr( stableIndex, (StgFunPtr) startEnterFloat );
71   return enterFloat_Result;
72 }
73 \end{code}
74
75 \begin{code}
76 StgPtr
77 deRefStablePointer(stableIndex)
78   StgStablePtr stableIndex;
79 {
80   return _deRefStablePointer(stableIndex, StorageMgrInfo.StablePointerTable);
81 }
82 \end{code}
83
84 Despite the file name, we have two small malloc ptr operation - not
85 worth putting in a file by itself.
86
87 \begin{code}
88 StgInt 
89 eqMallocPtr(p1, p2)
90   StgMallocPtr p1;
91   StgMallocPtr p2;
92 {
93   return (p1 == p2);
94 }
95 \end{code}
96
97 And some code that HAS NO RIGHT being here.
98
99 \begin{code}
100 StgStablePtr softHeapOverflowHandler = -1;
101
102 StgInt
103 catchSoftHeapOverflow( newHandler, deltaLimit )
104   StgStablePtr newHandler;
105   StgInt deltaLimit;
106 {
107   StgStablePtr oldHandler = softHeapOverflowHandler;
108
109   /* If we're in a _ccall_GC_ then HpLim will be stored in SAVE_HpLim
110      which provides an easy way of changing it. */
111   checkInCCallGC();
112
113   StorageMgrInfo.hardHpOverflowSize += deltaLimit;
114   SAVE_HpLim -= deltaLimit;
115
116   if (StorageMgrInfo.hardHpOverflowSize < 0) {
117     fprintf(stderr, "Error: Setting Hard Heap Overflow Size to negative value!\n");
118     EXIT(EXIT_FAILURE);
119   }
120
121   softHeapOverflowHandler = newHandler;
122   return oldHandler;
123 }
124
125 StgInt
126 getSoftHeapOverflowHandler(STG_NO_ARGS)
127 {
128   return (StgInt) softHeapOverflowHandler;
129 }
130
131 #endif /* !PAR */
132 \end{code}