source: Include/system/exception.ab@ 249

Last change on this file since 249 was 249, checked in by dai, 17 years ago

[32bitコンパイラ]ByRef指定のInteger/Byte型のローカル変数に値を代入すると強制終了してしまうバグを修正。
(呼び出し単体コードも対応→)関数の戻り値オブジェクトのメンバ・メソッドを一時オブジェクトを介さずに参照できるようにした。
オブジェクトの先頭バッファのサイズを4ポインタ分に拡張した。

File size: 3.0 KB
Line 
1'TODO: ローカルオブジェクト確保及び解放時にTryServiceに通知する必要がある。
2
3Class TryLayer
4Public
5 Const AddressOfCatch As VoidPtr
6 Const StackPtr As LONG_PTR
7 context As CONTEXT
8 Const debugProcNum As DWord
9
10 Sub TryLayer( AddressOfCatch As VoidPtr, StackPtr As LONG_PTR )
11 This.AddressOfCatch = AddressOfCatch
12 This.StackPtr = StackPtr
13
14 context.ContextFlags=CONTEXT_ALL
15 If Thread.CurrentThread().__GetContext(context) = 0 Then
16 ' TODO: エラー処理
17 debug
18 End If
19
20#ifdef _DEBUG
21 Dim ThreadNum As Long
22 ThreadNum=_DebugSys_GetThread()
23 If ThreadNum <> -1 Then
24 debugProcNum = _DebugSys_ProcNum[ThreadNum]
25 End If
26#endif
27 End Sub
28 Sub ~TryLayer()
29 End Sub
30End Class
31
32Class ExceptionService
33 ppTryLayers As **TryLayer
34 nTryLayers As Long
35
36 Sub FreeLocalObjects()
37 'TODO: 破棄されていないローカルオブジェクトを破棄
38 End Sub
39Public
40
41 Sub ExceptionService()
42 ppTryLayers = _System_malloc( 1 )
43 nTryLayers = 0
44 End Sub
45 Sub ~ExceptionService()
46 Dim i As Long
47 For i = 0 To ELM( nTryLayers )
48 Delete ppTryLayers[i]
49 Next
50 _System_free( ppTryLayers )
51 ppTryLayers = 0
52 End Sub
53
54 'Try
55 Function BeginTryScope( AddressOfCatch As VoidPtr, StackPtr As LONG_PTR ) As TryLayer
56 ppTryLayers = _System_realloc( ppTryLayers, ( nTryLayers + 1 ) * SizeOf( *TryLayer ) )
57 ppTryLayers[nTryLayers] = New TryLayer( AddressOfCatch, StackPtr )
58 nTryLayers++
59
60 Return ByVal ppTryLayers[nTryLayers-1]
61 End Function
62
63 'End Try
64 Sub EndTryScope()
65 nTryLayers--
66 Delete ppTryLayers[nTryLayers]
67 End Sub
68
69 'Throw
70 Sub _Throw()
71 If nTryLayers <= 0 then
72 '例外処理スコープ制御が無効なとき
73
74 'TODO: 適切なエラー処理
75 MessageBox( NULL, "例外", "", MB_OK or MB_ICONEXCLAMATION )
76
77 Return
78 End If
79
80 '未解放なローカルオブジェクトを解放する
81 FreeLocalObjects()
82
83
84
85 '--------------------------------------------------
86 ' スレッドのコンテキストを設定(Catchへ遷移する)
87 '--------------------------------------------------
88
89 'カレント スレッドを取得
90 Dim thread = Thread.CurrentThread
91
92 'レジスタ情報を取得
93 Dim context = ppTryLayers[nTryLayers - 1]->context
94debug
95 '新しいip, spをセット
96#ifdef _WIN64
97 context.Rip = ppTryLayers[nTryLayers - 1]->AddressOfCatch As QWord
98 'context.Rsp = ppTryLayers[nTryLayers - 1]->StackPtr
99#else
100 context.Eip = ppTryLayers[nTryLayers - 1]->AddressOfCatch As DWord
101 context.Esp = ppTryLayers[nTryLayers - 1]->StackPtr
102#endif
103
104#ifdef _DEBUG
105 Dim ThreadNum As Long
106 ThreadNum=_DebugSys_GetThread()
107 If ThreadNum <> -1 Then
108 _DebugSys_ProcNum[ThreadNum] = ppTryLayers[nTryLayers - 1]->debugProcNum-1
109 End If
110#endif
111
112 If thread.__SetContext( context ) = 0 Then
113 OutputDebugString(Ex"レジスタ情報の設定に失敗しました。\r\n")
114 Return
115 End If
116 End Sub
117
118 Sub _Throw( msg As String )
119 _Throw()
120 End Sub
121
122 Static Sub AllocateObject( pObj As VoidPtr )
123 Dim thread = Thread.CurrentThread
124 'TODO: ローカルオブジェクトを登録
125 End Sub
126
127 Static Sub DeallocateObject( pObj As VoidPtr )
128 'TODO: ローカルオブジェクトを破棄
129 End Sub
130End Class
131
Note: See TracBrowser for help on using the repository browser.