sedna 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/{CHANGES → CHANGES.rdoc} +9 -0
  2. data/{README → README.rdoc} +23 -25
  3. data/Rakefile +32 -9
  4. data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
  5. data/ext/{sedna.c → sedna/sedna.c} +48 -40
  6. data/test/sedna_test.rb +9 -9
  7. data/vendor/sedna/AUTHORS +18 -0
  8. data/vendor/sedna/COPYRIGHT +90 -0
  9. data/vendor/sedna/LICENSE +202 -0
  10. data/vendor/sedna/Makefile.include +423 -0
  11. data/vendor/sedna/Makefile.platform +31 -0
  12. data/vendor/sedna/depend.sed +48 -0
  13. data/vendor/sedna/driver/c/Makefile +98 -0
  14. data/vendor/sedna/driver/c/libsedna.c +1998 -0
  15. data/vendor/sedna/driver/c/libsedna.h +199 -0
  16. data/vendor/sedna/driver/c/sednamt.def +21 -0
  17. data/vendor/sedna/driver/c/sp_defs.h +186 -0
  18. data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
  19. data/vendor/sedna/kernel/common/IntHash.h +314 -0
  20. data/vendor/sedna/kernel/common/IntList.h +224 -0
  21. data/vendor/sedna/kernel/common/Makefile +30 -0
  22. data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
  23. data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
  24. data/vendor/sedna/kernel/common/XptrHash.h +435 -0
  25. data/vendor/sedna/kernel/common/argtable.c +972 -0
  26. data/vendor/sedna/kernel/common/argtable.h +896 -0
  27. data/vendor/sedna/kernel/common/base.cpp +339 -0
  28. data/vendor/sedna/kernel/common/base.h +226 -0
  29. data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
  30. data/vendor/sedna/kernel/common/bit_set.h +55 -0
  31. data/vendor/sedna/kernel/common/commutil.h +67 -0
  32. data/vendor/sedna/kernel/common/config.h +62 -0
  33. data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
  34. data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
  35. data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
  36. data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
  37. data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
  38. data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
  39. data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
  40. data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
  41. data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
  42. data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
  43. data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
  44. data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
  45. data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
  46. data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
  47. data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
  48. data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
  49. data/vendor/sedna/kernel/common/gmm.cpp +192 -0
  50. data/vendor/sedna/kernel/common/gmm.h +29 -0
  51. data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
  52. data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
  53. data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
  54. data/vendor/sedna/kernel/common/lm_base.h +90 -0
  55. data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
  56. data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
  57. data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
  58. data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
  59. data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
  60. data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
  61. data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
  62. data/vendor/sedna/kernel/common/pping.cpp +672 -0
  63. data/vendor/sedna/kernel/common/pping.h +119 -0
  64. data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
  65. data/vendor/sedna/kernel/common/rcv_test.h +19 -0
  66. data/vendor/sedna/kernel/common/sedna.c +128 -0
  67. data/vendor/sedna/kernel/common/sedna.h +49 -0
  68. data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
  69. data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
  70. data/vendor/sedna/kernel/common/sp.c +93 -0
  71. data/vendor/sedna/kernel/common/sp.h +36 -0
  72. data/vendor/sedna/kernel/common/st/Makefile +20 -0
  73. data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
  74. data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
  75. data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
  76. data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
  77. data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
  78. data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
  79. data/vendor/sedna/kernel/common/tr_debug.h +22 -0
  80. data/vendor/sedna/kernel/common/u/Makefile +14 -0
  81. data/vendor/sedna/kernel/common/u/u.c +268 -0
  82. data/vendor/sedna/kernel/common/u/u.h +715 -0
  83. data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
  84. data/vendor/sedna/kernel/common/u/udl.h +31 -0
  85. data/vendor/sedna/kernel/common/u/uevent.c +406 -0
  86. data/vendor/sedna/kernel/common/u/uevent.h +71 -0
  87. data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
  88. data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
  89. data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
  90. data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
  91. data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
  92. data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
  93. data/vendor/sedna/kernel/common/u/ummap.h +60 -0
  94. data/vendor/sedna/kernel/common/u/umutex.c +145 -0
  95. data/vendor/sedna/kernel/common/u/umutex.h +65 -0
  96. data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
  97. data/vendor/sedna/kernel/common/u/upipe.h +74 -0
  98. data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
  99. data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
  100. data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
  101. data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
  102. data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
  103. data/vendor/sedna/kernel/common/u/usem.c +891 -0
  104. data/vendor/sedna/kernel/common/u/usem.h +83 -0
  105. data/vendor/sedna/kernel/common/u/ushm.c +222 -0
  106. data/vendor/sedna/kernel/common/u/ushm.h +46 -0
  107. data/vendor/sedna/kernel/common/u/usocket.c +541 -0
  108. data/vendor/sedna/kernel/common/u/usocket.h +118 -0
  109. data/vendor/sedna/kernel/common/u/usystem.c +57 -0
  110. data/vendor/sedna/kernel/common/u/usystem.h +46 -0
  111. data/vendor/sedna/kernel/common/u/uthread.c +259 -0
  112. data/vendor/sedna/kernel/common/u/uthread.h +95 -0
  113. data/vendor/sedna/kernel/common/u/utime.c +65 -0
  114. data/vendor/sedna/kernel/common/u/utime.h +40 -0
  115. data/vendor/sedna/kernel/common/u/uutils.c +142 -0
  116. data/vendor/sedna/kernel/common/u/uutils.h +65 -0
  117. data/vendor/sedna/kernel/common/ugc.cpp +156 -0
  118. data/vendor/sedna/kernel/common/ugc.h +15 -0
  119. data/vendor/sedna/kernel/common/utils.cpp +156 -0
  120. data/vendor/sedna/kernel/common/utils.h +133 -0
  121. data/vendor/sedna/kernel/common/version.c +16 -0
  122. data/vendor/sedna/kernel/common/version.h +21 -0
  123. data/vendor/sedna/kernel/common/wustructures.h +18 -0
  124. data/vendor/sedna/kernel/common/wutypes.h +34 -0
  125. data/vendor/sedna/kernel/common/xptr.cpp +17 -0
  126. data/vendor/sedna/kernel/common/xptr.h +211 -0
  127. data/vendor/sedna/ver +1 -0
  128. metadata +142 -14
@@ -0,0 +1,345 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <stdarg.h>
4
+ #include <string.h>
5
+
6
+
7
+ #define IS_WHITESPACE(byte) ((byte)==0 || (byte)=='\n' || (byte)==' ' || (byte)=='\t' || (byte)=='\r')
8
+ #define COMMENT_BEGIN '#'
9
+ #define ERROR_CODE_DELIMITER ":"
10
+ #define ERROR_CODE_MAX_SIZE 10
11
+ #define ERROR_DESCRIPTION_MAX_SIZE 1000
12
+
13
+ /// File names
14
+ #define ERRORS_FILE_NAME "error.codes"
15
+ #define C_ERROR_CODES "error_codes.c"
16
+ #define H_ERROR_CODES "error_codes.h"
17
+ #define JAVA_ERROR_CODES "ErrorCodes.java"
18
+ #define SCM_ERROR_CODES "error_codes_scm.scm"
19
+
20
+ struct error_code
21
+ {
22
+ char* code;
23
+ char* description;
24
+ };
25
+
26
+
27
+ /// Cuts off everyting after the first whitespace
28
+ /// Length of code is returned
29
+ int prepare_error_code(char* dest, const char* src)
30
+ {
31
+ int i = 0;
32
+ while(!IS_WHITESPACE(src[i])) { dest[i] = src[i]; i++; }
33
+ dest[i] = '\0';
34
+ return i;
35
+ }
36
+
37
+ /// Cuts off any leading whitespaces and takes string before newline or it's end.
38
+ /// Length of description is returned
39
+ int prepare_error_description(char* dest, const char* src)
40
+ {
41
+ int i = 0;
42
+ int j = 0;
43
+ while(src[i] == ' ' || src[i] == '\t') { i++; }
44
+ while(src[i] != '\r' && src[i] != '\n' && src[i] != 0) { dest[j] = src[i]; i++; j++; }
45
+ dest[j] = '\0';
46
+ return j;
47
+ }
48
+
49
+
50
+ void write_with_handler(FILE* file, const char *file_name, const char *s, ...)
51
+ {
52
+ va_list ap;
53
+ int res = 0;
54
+
55
+ va_start(ap, s);
56
+ res = vfprintf(file, s, ap);
57
+ va_end(ap);
58
+
59
+ if(res < 0)
60
+ {
61
+ fprintf(stderr, "Can't write error codes: '%s'!\n", file_name);
62
+ exit(1);
63
+ }
64
+ }
65
+
66
+
67
+ void write_quoted_string(FILE* file, const char *file_name, const char *s)
68
+ {
69
+ while(*s)
70
+ {
71
+ switch(*s)
72
+ {
73
+ case '\\':
74
+ case '\"':
75
+ if(fputc('\\', file) == EOF)
76
+ {
77
+ fprintf(stderr, "Can't write error codes: '%s'!\n", file_name);
78
+ exit(1);
79
+ }
80
+ default:
81
+ if(fputc(*s, file) == EOF)
82
+ {
83
+ fprintf(stderr, "Can't write error codes: '%s'!\n", file_name);
84
+ exit(1);
85
+ }
86
+ }
87
+ s++;
88
+ }
89
+ }
90
+
91
+
92
+
93
+ void write_c_error_codes(const struct error_code* codes, const int codes_len)
94
+ {
95
+ FILE* cerrors = NULL;
96
+ FILE* herrors = NULL;
97
+
98
+ int counter = 0;
99
+
100
+ char* c_header = "\n//This file was generated. Do not edit it!!!\n\n\
101
+ #include \"common/errdbg/error_codes.h\"\n\n\
102
+ struct user_error_code_entry user_error_code_entries[] = {\n";
103
+ char* h_header = "#ifndef _USER_ERROR_CODES_H\n\
104
+ #define _USER_ERROR_CODES_H\n\n\
105
+ //This file was generated. Do not edit it!!!\n\n\
106
+ #ifdef __cplusplus\n\
107
+ extern \"C\" {\n\
108
+ #endif\n\n\
109
+ enum user_error_code_act {ueca_NOTHING, ueca_ROLLBACK_TRN};\n\n\
110
+ struct user_error_code_entry\n\
111
+ {\n\
112
+ const char* code; /* error code */\n\
113
+ enum user_error_code_act act; /* reaction on error */\n\
114
+ const char* descr; /* error decrtiption */\n\
115
+ };\n\n\
116
+ extern struct user_error_code_entry user_error_code_entries[];\n\
117
+ extern const int user_error_code_entries_size;\n\n\
118
+ #ifdef __cplusplus\n\
119
+ }\n\
120
+ #endif\n\n";
121
+
122
+ char* c_tail = "};\n\nconst int user_error_code_entries_size = sizeof user_error_code_entries;\n";
123
+ char* h_tail = "\n#endif\n";
124
+
125
+
126
+ if((cerrors = fopen(C_ERROR_CODES, "wb")) == NULL)
127
+ {
128
+ fprintf(stderr, "Can't open file to write C error codes: '%s'!\n", C_ERROR_CODES);
129
+ exit(1);
130
+ }
131
+ if((herrors = fopen(H_ERROR_CODES, "wb")) == NULL)
132
+ {
133
+ fprintf(stderr, "Can't open file to write C error codes: '%s'!\n", H_ERROR_CODES);
134
+ exit(1);
135
+ }
136
+
137
+ write_with_handler(cerrors, C_ERROR_CODES, c_header);
138
+ write_with_handler(herrors, H_ERROR_CODES, h_header);
139
+
140
+ for(counter = 0; counter < codes_len; counter++)
141
+ {
142
+ write_with_handler(herrors, H_ERROR_CODES, "#define %s %d // %s\n", codes[counter].code, counter, codes[counter].description);
143
+
144
+ write_with_handler (cerrors, C_ERROR_CODES, "%c{\"%s\", ueca_ROLLBACK_TRN, \"", counter == 0 ? ' ' : ',', codes[counter].code);
145
+ write_quoted_string (cerrors, C_ERROR_CODES, codes[counter].description);
146
+ write_with_handler (cerrors, C_ERROR_CODES, "\"}\n");
147
+ }
148
+
149
+ write_with_handler(cerrors, C_ERROR_CODES, c_tail);
150
+ write_with_handler(herrors, H_ERROR_CODES, h_tail);
151
+
152
+
153
+ fclose(cerrors);
154
+ fclose(herrors);
155
+ }
156
+
157
+
158
+
159
+ void write_scm_error_codes(const struct error_code* codes, const int codes_len)
160
+ {
161
+ FILE* errors = NULL;
162
+
163
+ int counter = 0;
164
+
165
+ char* header = "\n;; This file was generated. Do not edit it!!!\n\n\
166
+ (declare (unit scm-error-codes))\n\n";
167
+
168
+
169
+ if((errors = fopen(SCM_ERROR_CODES, "wb")) == NULL)
170
+ {
171
+ fprintf(stderr, "Can't open file to write Scheme error codes: '%s'!\n", SCM_ERROR_CODES);
172
+ exit(1);
173
+ }
174
+
175
+ write_with_handler(errors, SCM_ERROR_CODES, header);
176
+
177
+ for(counter = 0; counter < codes_len; counter++)
178
+ {
179
+ write_with_handler(errors, SCM_ERROR_CODES, "(define %s %d) ;; %s\n", codes[counter].code, counter, codes[counter].description);
180
+ }
181
+
182
+ fclose(errors);
183
+ }
184
+
185
+ void write_java_error_codes(const struct error_code* codes, const int codes_len)
186
+ {
187
+ FILE* errors = NULL;
188
+
189
+ int counter = 0;
190
+
191
+
192
+ char* header = "\n// This file was generated. Do not edit it!!!\n\n\
193
+ package ru.ispras.sedna.driver;\n\
194
+ import java.io.*;\n\
195
+ import java.lang.*;\n\n\
196
+ class ErrorCodes {\n";
197
+ char* middle = "\n static String [][] user_error_code_entry = {\n";
198
+ char* tail = " };\n}\n";
199
+
200
+
201
+ if((errors = fopen(JAVA_ERROR_CODES, "wb")) == NULL)
202
+ {
203
+ fprintf(stderr, "Can't open file to write Java error codes: '%s'!\n", JAVA_ERROR_CODES);
204
+ exit(1);
205
+ }
206
+
207
+ write_with_handler(errors, JAVA_ERROR_CODES, header);
208
+
209
+ for(counter = 0; counter < codes_len; counter++)
210
+ {
211
+ write_with_handler(errors, JAVA_ERROR_CODES, " final static int %s = %d; // %s\n", codes[counter].code, counter, codes[counter].description);
212
+ }
213
+
214
+ write_with_handler(errors, JAVA_ERROR_CODES, middle);
215
+
216
+ for(counter = 0; counter < codes_len; counter++)
217
+ {
218
+ write_with_handler (errors, JAVA_ERROR_CODES, " %c{ \"%s\", \"", counter == 0 ? ' ' : ',', codes[counter].code);
219
+ write_quoted_string (errors, JAVA_ERROR_CODES, codes[counter].description);
220
+ write_with_handler (errors, JAVA_ERROR_CODES, "\"}\n");
221
+ }
222
+
223
+ write_with_handler(errors, JAVA_ERROR_CODES, tail);
224
+
225
+ fclose(errors);
226
+ }
227
+
228
+
229
+
230
+
231
+ int main(int argc, char** argv)
232
+ {
233
+ FILE* ferrors = NULL;
234
+ char buf[1024];
235
+ int line = 0;
236
+ struct error_code* codes = NULL;
237
+ int codes_size = 0, counter = 0, code_len = 0, description_len = 0;
238
+
239
+
240
+ if((ferrors = fopen(ERRORS_FILE_NAME, "r")) == NULL)
241
+ {
242
+ fprintf(stderr, "Can't open file with error code: '%s'!\n", ERRORS_FILE_NAME);
243
+ return 1;
244
+ }
245
+
246
+ while(1)
247
+ {
248
+ char *code = NULL, *new_code = NULL, *new_description = NULL;
249
+
250
+ if(fgets(buf, sizeof(buf), ferrors) == NULL)
251
+ {
252
+ if(feof(ferrors)) break;
253
+ else return 1;
254
+ }
255
+ line++;
256
+ if(IS_WHITESPACE(buf[0]) || buf[0] == COMMENT_BEGIN) continue;
257
+
258
+ /// I. Prepare error code
259
+ if((code = strstr(buf, ERROR_CODE_DELIMITER)) == NULL)
260
+ {
261
+ fprintf(stderr, "Error code must be delimited with '%s', line %d\n", ERROR_CODE_DELIMITER, line);
262
+ return 1;
263
+ }
264
+
265
+ if(IS_WHITESPACE(code[1]))
266
+ {
267
+ fprintf(stderr, "Error code can't have leading whitespace or be empty, line %d\n", line);
268
+ return 1;
269
+ }
270
+
271
+ code_len = strlen(code + 1);
272
+ if(code_len > ERROR_CODE_MAX_SIZE)
273
+ {
274
+ fprintf(stderr, "Too long error code, line %d\n", line);
275
+ return 1;
276
+ }
277
+
278
+ new_code = (char*)malloc(code_len + 1);
279
+ prepare_error_code(new_code, code + 1);
280
+
281
+ /// II. Prepare error description
282
+ if(fgets(buf, sizeof(buf), ferrors) == NULL || fgets(buf, sizeof(buf), ferrors) == NULL)
283
+ {
284
+ fprintf(stderr, "Two lines are expected after error code, line %d\n", line);
285
+ return 1;
286
+ }
287
+ line+=2;
288
+
289
+ description_len = strlen(buf);
290
+ if(description_len > ERROR_DESCRIPTION_MAX_SIZE)
291
+ {
292
+ fprintf(stderr, "Too long error code description, line %d\n", line);
293
+ return 1;
294
+ }
295
+
296
+ new_description = (char*)malloc(description_len + 1);
297
+ if(prepare_error_description(new_description, buf) == 0)
298
+ {
299
+ fprintf(stderr, "Empty error description, line %d\n", line);
300
+ return 1;
301
+ }
302
+
303
+
304
+ counter++;
305
+
306
+ /// III. Allocate new error code wrapper
307
+ if(codes_size < counter)
308
+ {
309
+ if(!codes_size)
310
+ {
311
+ codes = (struct error_code*)malloc(sizeof(struct error_code) * 100);
312
+ codes_size = 100;
313
+ }
314
+ else
315
+ {
316
+ codes = (struct error_code*)realloc(codes, sizeof(struct error_code) * codes_size * 2);
317
+ codes_size *= 2;
318
+ }
319
+ }
320
+
321
+ codes[counter-1].code = new_code;
322
+ codes[counter-1].description = new_description;
323
+ }
324
+
325
+ write_c_error_codes(codes, counter);
326
+ write_scm_error_codes(codes, counter);
327
+ write_java_error_codes(codes, counter);
328
+
329
+ while(counter > 0)
330
+ {
331
+ //printf("[%s:%s]\n", codes[counter-1].code, codes[counter-1].description);
332
+ free(codes[counter-1].code);
333
+ codes[counter-1].code = NULL;
334
+ free(codes[counter-1].description);
335
+ codes[counter-1].description = NULL;
336
+ counter--;
337
+ }
338
+
339
+ free(codes);
340
+ codes = NULL;
341
+
342
+ fclose(ferrors);
343
+ return 0;
344
+ }
345
+
@@ -0,0 +1,192 @@
1
+ /*
2
+ * File: gmm.cpp
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+ #include <string>
7
+
8
+ #include "common/sedna.h"
9
+
10
+ #include "common/gmm.h"
11
+ #include "common/base.h"
12
+ #include "common/xptr.h"
13
+ #include "common/u/uutils.h"
14
+ #include "common/u/uprocess.h"
15
+
16
+ static void *global_memory;
17
+ UMMap global_memory_mapping;
18
+
19
+ void create_global_memory_mapping(int os_primitives_id_min_bound)
20
+ {
21
+ char buf[U_MAX_PATH + 20]; /// should be enough to place "%SEDNA_DATA%/data/vmm.dat"
22
+ vmm_region_values v;
23
+
24
+ global_memory_mapping = uCreateFileMapping(U_INVALID_FD, PAGE_SIZE, SEDNA_GLOBAL_MEMORY_MAPPING, NULL, __sys_call_error);
25
+ if (U_INVALID_FILEMAPPING(global_memory_mapping))
26
+ throw USER_EXCEPTION(SE4074);
27
+
28
+ global_memory = uMapViewOfFile(global_memory_mapping, NULL, PAGE_SIZE, 0, __sys_call_error);
29
+ if (global_memory == NULL)
30
+ throw USER_EXCEPTION(SE4078);
31
+
32
+ memset(global_memory, '\0', PAGE_SIZE);
33
+ *(t_layer*)global_memory = INVALID_LAYER;
34
+
35
+ strcpy(buf, SEDNA_DATA);
36
+
37
+ #ifdef _WIN32
38
+ strcat(buf, "\\data\\vmm.dat");
39
+ #else
40
+ strcat(buf, "/data/vmm.dat");
41
+ #endif
42
+
43
+
44
+ if (uIsFileExist(buf, __sys_call_error))
45
+ {
46
+ UFile fd = uOpenFile(buf, U_SHARE_READ, U_READ, 0, __sys_call_error);
47
+ if (fd == U_INVALID_FD)
48
+ throw USER_EXCEPTION2(SE4042, "vmm.dat");
49
+
50
+ int bytes_read = 0;
51
+ int res = uReadFile(fd, &v, sizeof(vmm_region_values), &bytes_read, __sys_call_error);
52
+ if (res == 0 || bytes_read != sizeof(vmm_region_values))
53
+ throw USER_EXCEPTION2(SE4044, "vmm.dat");
54
+
55
+ if (uCloseFile(fd, __sys_call_error) == 0)
56
+ throw USER_EXCEPTION2(SE4043, "vmm.dat");
57
+
58
+ LAYER_ADDRESS_SPACE_START_ADDR_INT = v.LAYER_ADDRESS_SPACE_START_ADDR_INT;
59
+ LAYER_ADDRESS_SPACE_BOUNDARY_INT = v.LAYER_ADDRESS_SPACE_BOUNDARY_INT;
60
+ LAYER_ADDRESS_SPACE_SIZE = v.LAYER_ADDRESS_SPACE_SIZE;
61
+
62
+ LAYER_ADDRESS_SPACE_START_ADDR = (void*)LAYER_ADDRESS_SPACE_START_ADDR_INT;
63
+ LAYER_ADDRESS_SPACE_BOUNDARY = (void*)LAYER_ADDRESS_SPACE_BOUNDARY_INT;
64
+
65
+ *(vmm_region_values*)((char*)global_memory + PAGE_SIZE - sizeof(vmm_region_values)) = v;
66
+ }
67
+ else
68
+ {
69
+ char buf2[128];
70
+ uSetEnvironmentVariable(SEDNA_DETERMINE_VMM_REGION, "1", NULL, __sys_call_error);
71
+ uSetEnvironmentVariable(SEDNA_OS_PRIMITIVES_ID_MIN_BOUND, u_itoa(os_primitives_id_min_bound, buf2, 10), NULL, __sys_call_error);
72
+
73
+ char path_buf[U_MAX_PATH + 10];
74
+ std::string path_str = uGetImageProcPath(path_buf, __sys_call_error) + std::string("/") + SESSION_EXE;
75
+ strcpy(path_buf, path_str.c_str());
76
+
77
+ UPID pid;
78
+ UPHANDLE process_handle;
79
+ if (uCreateProcess(path_buf,
80
+ false, // inherit handles
81
+ NULL,
82
+ U_DETACHED_PROCESS,
83
+ &process_handle,
84
+ NULL,
85
+ &pid,
86
+ NULL,
87
+ NULL,
88
+ __sys_call_error) != 0)
89
+ throw SYSTEM_ENV_EXCEPTION("Cannot create process to determine VMM region");
90
+
91
+ int status = 0;
92
+ int res = 0;
93
+
94
+ res = uWaitForChildProcess(pid, process_handle, &status, __sys_call_error);
95
+ if (0 != res || status)
96
+ throw SYSTEM_ENV_EXCEPTION((std::string("Cannot determine VMM region, status: ") + int2string(status) + ", result: " + int2string(res)).c_str());
97
+
98
+ uCloseProcess(process_handle, __sys_call_error);
99
+ uSetEnvironmentVariable(SEDNA_DETERMINE_VMM_REGION, "0", NULL, __sys_call_error);
100
+
101
+ v = *(vmm_region_values*)((char*)global_memory + PAGE_SIZE - sizeof(vmm_region_values));
102
+
103
+ LAYER_ADDRESS_SPACE_START_ADDR_INT = v.LAYER_ADDRESS_SPACE_START_ADDR_INT;
104
+ LAYER_ADDRESS_SPACE_BOUNDARY_INT = v.LAYER_ADDRESS_SPACE_BOUNDARY_INT;
105
+ LAYER_ADDRESS_SPACE_SIZE = v.LAYER_ADDRESS_SPACE_SIZE;
106
+
107
+ if (LAYER_ADDRESS_SPACE_SIZE < VMM_REGION_MIN_SIZE)
108
+ throw USER_EXCEPTION2(SE1031, (std::string("Determined layer size: ") + int2string(LAYER_ADDRESS_SPACE_SIZE)).c_str());
109
+
110
+ LAYER_ADDRESS_SPACE_START_ADDR = (void*)LAYER_ADDRESS_SPACE_START_ADDR_INT;
111
+ LAYER_ADDRESS_SPACE_BOUNDARY = (void*)LAYER_ADDRESS_SPACE_BOUNDARY_INT;
112
+
113
+ UFile fd = uCreateFile(buf, 0, U_WRITE, 0, NULL, __sys_call_error);
114
+ if (fd == U_INVALID_FD)
115
+ throw USER_EXCEPTION2(SE4040, "vmm.dat");
116
+
117
+ int bytes_written = 0;
118
+ res = uWriteFile(fd, &v, sizeof(vmm_region_values), &bytes_written, __sys_call_error);
119
+ if (res == 0 || bytes_written != sizeof(vmm_region_values))
120
+ throw USER_EXCEPTION2(SE4045, "vmm.dat");
121
+
122
+ if (uCloseFile(fd, __sys_call_error) == 0)
123
+ throw USER_EXCEPTION2(SE4043, "vmm.dat");
124
+ }
125
+
126
+ elog(EL_INFO, ("Layer address space start addr = 0x%x", LAYER_ADDRESS_SPACE_START_ADDR));
127
+ elog(EL_INFO, ("Layer address space boundary = 0x%x", LAYER_ADDRESS_SPACE_BOUNDARY));
128
+ }
129
+
130
+ void release_global_memory_mapping()
131
+ {
132
+ if (uUnmapViewOfFile(global_memory_mapping, global_memory, PAGE_SIZE, __sys_call_error) == -1)
133
+ throw USER_EXCEPTION(SE4079);
134
+
135
+ if (uReleaseFileMapping(global_memory_mapping, SEDNA_GLOBAL_MEMORY_MAPPING, __sys_call_error) == -1)
136
+ throw USER_EXCEPTION(SE4076);
137
+ }
138
+
139
+ void open_global_memory_mapping(int err_code)
140
+ {
141
+ global_memory_mapping = uOpenFileMapping(U_INVALID_FD, PAGE_SIZE, SEDNA_GLOBAL_MEMORY_MAPPING, __sys_call_error);
142
+ if (U_INVALID_FILEMAPPING(global_memory_mapping))
143
+ throw USER_EXCEPTION(err_code);
144
+ }
145
+
146
+ void close_global_memory_mapping()
147
+ {
148
+ if (uCloseFileMapping(global_memory_mapping, __sys_call_error) == -1)
149
+ throw USER_EXCEPTION(SE4077);
150
+ }
151
+
152
+ UMMap get_global_memory_mapping()
153
+ {
154
+ return global_memory_mapping;
155
+ }
156
+
157
+ void get_vmm_region_values()
158
+ {
159
+ global_memory = uMapViewOfFile(global_memory_mapping, NULL, PAGE_SIZE, 0, __sys_call_error);
160
+ if (global_memory == NULL)
161
+ throw USER_EXCEPTION(SE4078);
162
+
163
+ vmm_region_values *v;
164
+ v = (vmm_region_values*)((char*)global_memory + PAGE_SIZE - sizeof(vmm_region_values));
165
+
166
+ LAYER_ADDRESS_SPACE_START_ADDR_INT = v->LAYER_ADDRESS_SPACE_START_ADDR_INT;
167
+ LAYER_ADDRESS_SPACE_BOUNDARY_INT = v->LAYER_ADDRESS_SPACE_BOUNDARY_INT;
168
+ LAYER_ADDRESS_SPACE_SIZE = v->LAYER_ADDRESS_SPACE_SIZE;
169
+
170
+ LAYER_ADDRESS_SPACE_START_ADDR = (void*)LAYER_ADDRESS_SPACE_START_ADDR_INT;
171
+ LAYER_ADDRESS_SPACE_BOUNDARY = (void*)LAYER_ADDRESS_SPACE_BOUNDARY_INT;
172
+
173
+ if (uUnmapViewOfFile(global_memory_mapping, global_memory, PAGE_SIZE, __sys_call_error) == -1)
174
+ throw USER_EXCEPTION(SE4079);
175
+ }
176
+
177
+ void set_vmm_region_values()
178
+ {
179
+ global_memory = uMapViewOfFile(global_memory_mapping, NULL, PAGE_SIZE, 0, __sys_call_error);
180
+ if (global_memory == NULL)
181
+ throw USER_EXCEPTION(SE4078);
182
+
183
+ vmm_region_values *v;
184
+ v = (vmm_region_values*)((char*)global_memory + PAGE_SIZE - sizeof(vmm_region_values));
185
+
186
+ v->LAYER_ADDRESS_SPACE_START_ADDR_INT = LAYER_ADDRESS_SPACE_START_ADDR_INT;
187
+ v->LAYER_ADDRESS_SPACE_BOUNDARY_INT = LAYER_ADDRESS_SPACE_BOUNDARY_INT;
188
+ v->LAYER_ADDRESS_SPACE_SIZE = LAYER_ADDRESS_SPACE_SIZE;
189
+
190
+ if (uUnmapViewOfFile(global_memory_mapping, global_memory, PAGE_SIZE, __sys_call_error) == -1)
191
+ throw USER_EXCEPTION(SE4079);
192
+ }