-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththread.c
More file actions
46 lines (37 loc) · 1.06 KB
/
thread.c
File metadata and controls
46 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "load_so.h"
#include "st.h"
#include "eval.h"
#define GetThreadPtr(obj, ptr) \
TypedData_Get_Struct((obj), rb_thread_t, ptr_ruby_thread_data_type, (ptr))
static VALUE (*thread_s_current)(VALUE);
static const rb_data_type_t *ptr_ruby_thread_data_type;
VALUE rb_thread_current() {
return thread_s_current(rb_cThread);
}
rb_thread_t *get_thread(VALUE thread) {
rb_thread_t *th;
GetThreadPtr(thread, th);
return th;
}
int rb_safe_level() {
return GET_THREAD()->safe_level;
}
void rb_secure(int level) {
if (level <= rb_safe_level()) {
rb_raise(rb_eSecurityError, "Insecure operation at level %d",
rb_safe_level());
}
}
void rb_insecure_operation(void) {
rb_raise(rb_eSecurityError, "Insecure operation");
}
void rb_check_safe_obj(VALUE x) {
if (rb_safe_level() > 0 && OBJ_TAINTED(x)) {
rb_insecure_operation();
}
rb_secure(4);
}
void Init_Thread() {
thread_s_current = get_method(rb_cThread, "current");
ptr_ruby_thread_data_type = RTYPEDDATA_TYPE(rb_thread_current());
}