ObjFW  Check-in [0c06c94bac]

Overview
Comment:exception.m: Clean up a little.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0c06c94bac917ac4acd2a4888593f243a3fecbf91d8fd09d595c5e458ddd625b
User & Date: js on 2012-07-04 11:43:59
Other Links: manifest | tags
Context
2012-07-04
19:11
Add -I for included runtime in generators. check-in: 910631a4c8 user: js tags: trunk
11:43
exception.m: Clean up a little. check-in: 0c06c94bac user: js tags: trunk
2012-07-03
20:17
Get rid of a warning with clang trunk. check-in: 6ec1bc64a4 user: js tags: trunk
Changes

Modified src/runtime/exception.m from [c1024e0f89] to [775286f90c].

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133

134
135
136
137
138
139
140
extern uint64_t _Unwind_GetIP(struct _Unwind_Context*);
extern void _Unwind_SetIP(struct _Unwind_Context*, uint64_t);
extern void _Unwind_SetGR(struct _Unwind_Context*, int, uint64_t);
extern void _Unwind_DeleteException(struct _Unwind_Exception*);

static objc_uncaught_exception_handler uncaught_exception_handler;

static inline uint64_t
read_leb128(const uint8_t **ptr, uint8_t *bits)
{
	uint64_t value = 0;
	uint8_t shift = 0;

	do {
		value |= (**ptr & 0x7F) << shift;
		(*ptr)++;
		shift += 7;
	} while (*(*ptr - 1) & 0x80);

	if (bits != NULL)
		*bits = shift;

	return value;
}

static uint64_t
read_uleb128(const uint8_t **ptr)
{
	return read_leb128(ptr, NULL);
}

static int64_t
read_sleb128(const uint8_t **ptr)
{

	uint8_t bits;
	int64_t value;

	value = read_leb128(ptr, &bits);


	if (bits < 64 && value & (1 << (bits - 1)))
		value |= -(1 << bits);

	return value;
}








|
|










<
<
<



<
<
<
<
<
<



>



|
>







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114



115
116
117






118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
extern uint64_t _Unwind_GetIP(struct _Unwind_Context*);
extern void _Unwind_SetIP(struct _Unwind_Context*, uint64_t);
extern void _Unwind_SetGR(struct _Unwind_Context*, int, uint64_t);
extern void _Unwind_DeleteException(struct _Unwind_Exception*);

static objc_uncaught_exception_handler uncaught_exception_handler;

static uint64_t
read_uleb128(const uint8_t **ptr)
{
	uint64_t value = 0;
	uint8_t shift = 0;

	do {
		value |= (**ptr & 0x7F) << shift;
		(*ptr)++;
		shift += 7;
	} while (*(*ptr - 1) & 0x80);




	return value;
}







static int64_t
read_sleb128(const uint8_t **ptr)
{
	const uint8_t *oldptr = *ptr;
	uint8_t bits;
	int64_t value;

	value = read_uleb128(ptr);
	bits = (*ptr - oldptr) * 7;

	if (bits < 64 && value & (1 << (bits - 1)))
		value |= -(1 << bits);

	return value;
}

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
{
	uint64_t value;

	if (enc == DW_EH_PE_aligned)
		/* Not implemented */
		abort();

#define READ_TYPE(type, size)			\
	{					\
		value = *(type*)(void*)*ptr;	\
		*ptr += size;			\
		break;				\
	}

	switch (enc & 0x0F) {
	case DW_EH_PE_absptr:
		READ_TYPE(uintptr_t, sizeof(void*))
	case DW_EH_PE_uleb128:
		value = read_uleb128(ptr);
		break;
	case DW_EH_PE_udata2:
		READ_TYPE(uint16_t, 2)
	case DW_EH_PE_udata4:
		READ_TYPE(uint32_t, 4)
	case DW_EH_PE_udata8:
		READ_TYPE(uint64_t, 8)
	case DW_EH_PE_sleb128:
		value = read_sleb128(ptr);
		break;
	case DW_EH_PE_sdata2:
		READ_TYPE(int16_t, 2)
	case DW_EH_PE_sdata4:
		READ_TYPE(int32_t, 4)
	case DW_EH_PE_sdata8:
		READ_TYPE(int64_t, 8)
	default:
		abort();
	}

#undef READ_TYPE

	return value;







|


|





|




|

|

|




|

|

|







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{
	uint64_t value;

	if (enc == DW_EH_PE_aligned)
		/* Not implemented */
		abort();

#define READ_TYPE(type)				\
	{					\
		value = *(type*)(void*)*ptr;	\
		*ptr += size_for_encoding(enc);	\
		break;				\
	}

	switch (enc & 0x0F) {
	case DW_EH_PE_absptr:
		READ_TYPE(uintptr_t)
	case DW_EH_PE_uleb128:
		value = read_uleb128(ptr);
		break;
	case DW_EH_PE_udata2:
		READ_TYPE(uint16_t)
	case DW_EH_PE_udata4:
		READ_TYPE(uint32_t)
	case DW_EH_PE_udata8:
		READ_TYPE(uint64_t)
	case DW_EH_PE_sleb128:
		value = read_sleb128(ptr);
		break;
	case DW_EH_PE_sdata2:
		READ_TYPE(int16_t)
	case DW_EH_PE_sdata4:
		READ_TYPE(int32_t)
	case DW_EH_PE_sdata8:
		READ_TYPE(int64_t)
	default:
		abort();
	}

#undef READ_TYPE

	return value;
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
read_lsda(struct _Unwind_Context *ctx, const uint8_t *ptr, struct lsda *lsda)
{
	uint8_t landingpads_start_enc;
	uintptr_t callsites_size;

	lsda->region_start = _Unwind_GetRegionStart(ctx);
	lsda->landingpads_start = lsda->region_start;
	lsda->typestable = 0;

	if ((landingpads_start_enc = *ptr++) != DW_EH_PE_omit)
		lsda->landingpads_start =
		    read_value(landingpads_start_enc, &ptr);

	if ((lsda->typestable_enc = *ptr++) != DW_EH_PE_omit) {
		uintptr_t tmp = read_uleb128(&ptr);







|







237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
read_lsda(struct _Unwind_Context *ctx, const uint8_t *ptr, struct lsda *lsda)
{
	uint8_t landingpads_start_enc;
	uintptr_t callsites_size;

	lsda->region_start = _Unwind_GetRegionStart(ctx);
	lsda->landingpads_start = lsda->region_start;
	lsda->typestable = NULL;

	if ((landingpads_start_enc = *ptr++) != DW_EH_PE_omit)
		lsda->landingpads_start =
		    read_value(landingpads_start_enc, &ptr);

	if ((lsda->typestable_enc = *ptr++) != DW_EH_PE_omit) {
		uintptr_t tmp = read_uleb128(&ptr);