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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#ifndef RUST_INTERNAL_H
#define RUST_INTERNAL_H
#include "rust_globals.h"
#include "util/array_list.h"
#include "util/indexed_list.h"
#include "util/synchronized_indexed_list.h"
#include "util/hash_map.h"
#include "sync/sync.h"
#include "sync/lock_and_signal.h"
#include "sync/lock_free_queue.h"
struct rust_task_thread;
struct rust_task;
class rust_log;
class rust_port;
class rust_kernel;
struct stk_seg;
struct type_desc;
struct frame_glue_fns;
typedef intptr_t rust_sched_id;
typedef intptr_t rust_task_id;
typedef intptr_t rust_port_id;
#define I(dom, e) ((e) ? (void)0 : \
(dom)->srv->fatal(#e, __FILE__, __LINE__, ""))
#define W(dom, e, s, ...) ((e) ? (void)0 : \
(dom)->srv->warning(#e, __FILE__, __LINE__, s, ## __VA_ARGS__))
#define A(dom, e, s, ...) ((e) ? (void)0 : \
(dom)->srv->fatal(#e, __FILE__, __LINE__, s, ## __VA_ARGS__))
#define K(srv, e, s, ...) ((e) ? (void)0 : \
srv->fatal(#e, __FILE__, __LINE__, s, ## __VA_ARGS__))
#define PTR "0x%" PRIxPTR
// This drives our preemption scheme.
static size_t const TIME_SLICE_IN_MS = 10;
// This accounts for logging buffers.
static size_t const BUF_BYTES = 2048;
// The error status to use when the process fails
#define PROC_FAIL_CODE 101
// Every reference counted object should use this macro and initialize
// ref_count.
#define RUST_REFCOUNTED(T) \
RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this)
#define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \
intptr_t ref_count; \
void ref() { ++ref_count; } \
void deref() { if (--ref_count == 0) { dtor; } }
#define RUST_ATOMIC_REFCOUNT() \
private: \
intptr_t ref_count; \
public: \
void ref() { \
intptr_t old = sync::increment(ref_count); \
assert(old > 0); \
} \
void deref() { if(0 == sync::decrement(ref_count)) { delete_this(); } } \
intptr_t get_ref_count() { return sync::read(ref_count); }
template <typename T> struct task_owned {
inline void *operator new(size_t size, rust_task *task, const char *tag);
inline void *operator new[](size_t size, rust_task *task,
const char *tag);
inline void *operator new(size_t size, rust_task &task, const char *tag);
inline void *operator new[](size_t size, rust_task &task,
const char *tag);
void operator delete(void *ptr) {
((T *)ptr)->task->free(ptr);
}
};
template <typename T> struct kernel_owned {
inline void *operator new(size_t size, rust_kernel *kernel,
const char *tag);
void operator delete(void *ptr) {
((T *)ptr)->kernel->free(ptr);
}
};
template <typename T> struct region_owned {
void operator delete(void *ptr) {
((T *)ptr)->region->free(ptr);
}
};
// A cond(ition) is something we can block on. This can be a channel
// (writing), a port (reading) or a task (waiting).
struct rust_cond { };
#include "memory_region.h"
#include "rust_srv.h"
#include "rust_log.h"
#include "rust_kernel.h"
#include "rust_task_thread.h"
typedef void CDECL (glue_fn)(void *, void *,
const type_desc **, void *);
struct rust_shape_tables {
uint8_t *tags;
uint8_t *resources;
};
typedef unsigned long ref_cnt_t;
// Corresponds to the boxed data in the @ region. The body follows the
// header; you can obtain a ptr via box_body() below.
struct rust_opaque_box {
ref_cnt_t ref_count;
type_desc *td;
rust_opaque_box *prev;
rust_opaque_box *next;
};
// The type of functions that we spawn, which fall into two categories:
// - the main function: has a NULL environment, but uses the void* arg
// - unique closures of type fn~(): have a non-NULL environment, but
// no arguments (and hence the final void*) is harmless
typedef void (*CDECL spawn_fn)(void*, rust_opaque_box*, void *);
// corresponds to the layout of a fn(), fn@(), fn~() etc
struct fn_env_pair {
spawn_fn f;
rust_opaque_box *env;
};
static inline void *box_body(rust_opaque_box *box) {
// Here we take advantage of the fact that the size of a box in 32
// (resp. 64) bit is 16 (resp. 32) bytes, and thus always 16-byte aligned.
// If this were to change, we would have to update the method
// rustc::middle::trans::base::opaque_box_body() as well.
return (void*)(box + 1);
}
struct type_desc {
// First part of type_desc is known to compiler.
// first_param = &descs[1] if dynamic, null if static.
const type_desc **first_param;
size_t size;
size_t align;
glue_fn *take_glue;
glue_fn *drop_glue;
glue_fn *free_glue;
void *UNUSED;
glue_fn *sever_glue; // For GC.
glue_fn *mark_glue; // For GC.
uintptr_t unused2;
void *UNUSED_2;
const uint8_t *shape;
const rust_shape_tables *shape_tables;
uintptr_t n_params;
uintptr_t n_obj_params;
// Residual fields past here are known only to runtime.
UT_hash_handle hh;
size_t n_descs;
const type_desc *descs[];
};
extern "C" type_desc *rust_clone_type_desc(type_desc*);
#include "circular_buffer.h"
#include "rust_task.h"
#include "rust_port.h"
#include "memory.h"
//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//
#endif
|