sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,206 @@
|
|
1
|
+
/*
|
2
|
+
* File: uhdd.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef _UHDD_H
|
7
|
+
#define _UHDD_H
|
8
|
+
|
9
|
+
#include "common/u/u.h"
|
10
|
+
#include "common/u/usecurity.h"
|
11
|
+
|
12
|
+
|
13
|
+
#ifdef _WIN32
|
14
|
+
|
15
|
+
/* UShareMode */
|
16
|
+
#define U_SHARE_READ FILE_SHARE_READ
|
17
|
+
#define U_SHARE_WRITE FILE_SHARE_WRITE
|
18
|
+
/* UAccess */
|
19
|
+
#define U_WRITE GENERIC_WRITE
|
20
|
+
#define U_READ GENERIC_READ
|
21
|
+
#define U_READ_WRITE (GENERIC_READ | GENERIC_WRITE)
|
22
|
+
#define U_ALL_ACCESS GENERIC_ALL
|
23
|
+
/* uCreateFile/UOpenFile error return value */
|
24
|
+
#define U_INVALID_FD INVALID_HANDLE_VALUE
|
25
|
+
/* UFlag (for create/open) */
|
26
|
+
#define U_WRITE_THROUGH FILE_FLAG_WRITE_THROUGH
|
27
|
+
#define U_NO_BUFFERING FILE_FLAG_NO_BUFFERING
|
28
|
+
/* UFlag (for setting file pointer) */
|
29
|
+
#define U_FILE_BEGIN FILE_BEGIN
|
30
|
+
#define U_FILE_END FILE_END
|
31
|
+
#define U_FILE_CURRENT FILE_CURRENT
|
32
|
+
|
33
|
+
#define U_INVALID_DIR INVALID_HANDLE_VALUE
|
34
|
+
|
35
|
+
typedef HANDLE UFile;
|
36
|
+
typedef DWORD UAccess;
|
37
|
+
typedef DWORD UShareMode;
|
38
|
+
typedef HANDLE UDir;
|
39
|
+
|
40
|
+
/* Defines maximum length of the temporary file name.
|
41
|
+
* Should be used to check total path length where appropriate.
|
42
|
+
* WIN32 template "tmp.XXXXXXXX.XXX"
|
43
|
+
*/
|
44
|
+
#define SE_MAX_TMP_FILE_NAME (16)
|
45
|
+
|
46
|
+
#else
|
47
|
+
|
48
|
+
#include <dirent.h>
|
49
|
+
#include <sys/types.h>
|
50
|
+
|
51
|
+
/* UShareMode */
|
52
|
+
#define U_SHARE_READ 0
|
53
|
+
#define U_SHARE_WRITE 0
|
54
|
+
/* UAccess */
|
55
|
+
#define U_WRITE O_WRONLY
|
56
|
+
#define U_READ O_RDONLY
|
57
|
+
#define U_READ_WRITE O_RDWR
|
58
|
+
#define U_ALL_ACCESS O_RDWR
|
59
|
+
/* uCreateFile/UOpenFile error return value */
|
60
|
+
#define U_INVALID_FD (-1)
|
61
|
+
/* UFlag (for create/open) */
|
62
|
+
|
63
|
+
#if (defined(DARWIN) || defined(FreeBSD))
|
64
|
+
#define U_WRITE_THROUGH O_FSYNC
|
65
|
+
#define U_NO_BUFFERING O_FSYNC
|
66
|
+
#else /* Linux */
|
67
|
+
#define U_WRITE_THROUGH O_SYNC
|
68
|
+
/* !!! It has been found that there are some problems with
|
69
|
+
!!! O_DIRECT flag in Linux, so it has been temporary substituted wih
|
70
|
+
!!! the O_SYNC flag */
|
71
|
+
/* #define U_NO_BUFFERING O_DIRECT */
|
72
|
+
#define U_NO_BUFFERING O_SYNC
|
73
|
+
#endif /* FreeBSD && Mac OS */
|
74
|
+
|
75
|
+
/* UFlag (for setting file pointer) */
|
76
|
+
#define U_FILE_BEGIN SEEK_SET
|
77
|
+
#define U_FILE_END SEEK_END
|
78
|
+
#define U_FILE_CURRENT SEEK_CUR
|
79
|
+
|
80
|
+
#define U_INVALID_DIR NULL
|
81
|
+
|
82
|
+
/* Defines maximum length of the temporary file name.
|
83
|
+
* Should be used to check total path length where appropriate.
|
84
|
+
* *NIX template "tmpXXXXXX"
|
85
|
+
*/
|
86
|
+
#define SE_MAX_TMP_FILE_NAME (9)
|
87
|
+
|
88
|
+
typedef int UFile;
|
89
|
+
typedef int UAccess;
|
90
|
+
typedef int UShareMode;
|
91
|
+
typedef DIR* UDir;
|
92
|
+
|
93
|
+
#endif
|
94
|
+
|
95
|
+
struct UFindDataStruct {
|
96
|
+
char fname[U_MAX_PATH];
|
97
|
+
};
|
98
|
+
|
99
|
+
struct file_struct {
|
100
|
+
UFile f;
|
101
|
+
char name[U_MAX_PATH];
|
102
|
+
};
|
103
|
+
|
104
|
+
#ifdef __cplusplus
|
105
|
+
extern "C"
|
106
|
+
{
|
107
|
+
#endif
|
108
|
+
|
109
|
+
/* return U_INVALID_FD in the case of error*/
|
110
|
+
UFile uCreateFile(const char *name, UShareMode share, UAccess accs, UFlag attr, USECURITY_ATTRIBUTES* sa, sys_call_error_fun fun);
|
111
|
+
|
112
|
+
/* return U_INVALID_FD in the case of error*/
|
113
|
+
UFile uOpenFile(const char *name, UShareMode share, UAccess accs, UFlag attr, sys_call_error_fun fun);
|
114
|
+
|
115
|
+
/* If the function succeeds, the return value is nonzero.*/
|
116
|
+
/* If the function fails, the return value is zero.*/
|
117
|
+
int uCloseFile(UFile fd, sys_call_error_fun fun);
|
118
|
+
|
119
|
+
/* If the function succeeds to delete the file, it returns nonzero.*/
|
120
|
+
/* If the function fails to detele file, it returns zero.*/
|
121
|
+
int uDeleteFile(const char *name, sys_call_error_fun fun);
|
122
|
+
|
123
|
+
/* If the function succeeds, the return value is nonzero.*/
|
124
|
+
/* If the function fails, the return value is zero.*/
|
125
|
+
int uDelDir(const char *dir, sys_call_error_fun fun);
|
126
|
+
|
127
|
+
/* If the function succeeds, the return value is nonzero.*/
|
128
|
+
/* If the function fails, the return value is zero.*/
|
129
|
+
int uMoveFile(const char* old_name, const char* new_name, sys_call_error_fun fun);
|
130
|
+
|
131
|
+
/* If the function succeeds, the return value is nonzero. If the return value */
|
132
|
+
/* is nonzero and the number of bytes read is zero, the file pointer was beyond */
|
133
|
+
/* the current end of the file at the time of the read operation.*/
|
134
|
+
/* If the function fails, the return value is zero*/
|
135
|
+
int uReadFile(UFile fd, void *buf, int to_read, int *already_read, sys_call_error_fun fun);
|
136
|
+
|
137
|
+
/* If the function succeeds, the return value is nonzero.*/
|
138
|
+
/* If the function fails, the return value is zero.*/
|
139
|
+
int uWriteFile(UFile fd, const void *buf, int to_write, int *already_written, sys_call_error_fun fun);
|
140
|
+
|
141
|
+
/* If the function succeeds, the return value is nonzero.*/
|
142
|
+
/* If the function fails, the return value is zero.*/
|
143
|
+
int uSetFilePointer(UFile fd, __int64 offs, __int64 * res_pos, UFlag meth, sys_call_error_fun fun);
|
144
|
+
|
145
|
+
/* If the function succeeds, the return value is nonzero.*/
|
146
|
+
/* If the function fails, the return value is zero.*/
|
147
|
+
int uSetEndOfFile(UFile fd, __int64 offs, UFlag meth, sys_call_error_fun fun);
|
148
|
+
|
149
|
+
/* If the function succeeds, the return value is nonzero.*/
|
150
|
+
/* If the function fails, the return value is zero.*/
|
151
|
+
int uMkDir(const char *name, USECURITY_ATTRIBUTES* sa, sys_call_error_fun fun);
|
152
|
+
|
153
|
+
/* Returns true if the file exists*/
|
154
|
+
int uIsFileExist(const char *name, sys_call_error_fun fun);
|
155
|
+
|
156
|
+
/* If the function succeeds, the return value is nonzero.*/
|
157
|
+
/* If the function fails, the return value is zero.*/
|
158
|
+
int uCopyFile(const char *existing_file, const char *new_file, int fail_if_exists, sys_call_error_fun fun);
|
159
|
+
|
160
|
+
/* If the function succeeds, the return value is nonzero.*/
|
161
|
+
/* If the function fails, the return value is zero.*/
|
162
|
+
int uGetFileSize(UFile fd, __int64 * file_size, sys_call_error_fun fun);
|
163
|
+
|
164
|
+
/* If the function succeeds, the return value is nonzero.*/
|
165
|
+
/* If the function fails, the return value is zero.*/
|
166
|
+
int uGetFileSizeByName(const char* name, __int64 * file_size, sys_call_error_fun fun);
|
167
|
+
|
168
|
+
/* If the function succeeds, the return value is nonzero.*/
|
169
|
+
/* If the function fails, the return value is zero.*/
|
170
|
+
int uGetDiskSectorSize(int *sector_size, const char *path, sys_call_error_fun fun);
|
171
|
+
|
172
|
+
/* If the function succeeds, it returns nonzero.*/
|
173
|
+
/* If the function fails, it returns 1.*/
|
174
|
+
int uGetUniqueFileStruct(const char *directoryName, struct file_struct *fs, int sid, sys_call_error_fun fun);
|
175
|
+
|
176
|
+
/* If the function succeeds, it returns nonzero.
|
177
|
+
* Else it returns 0. */
|
178
|
+
int uCleanupUniqueFileStructs(const char *dir, sys_call_error_fun fun);
|
179
|
+
|
180
|
+
/* If the function succeeds, the return value is pointer to the absolute path*/
|
181
|
+
/* If the function fails, the return value is NULL*/
|
182
|
+
char *uGetAbsoluteFilePath(const char *relPath, char *absPath, int maxLength, sys_call_error_fun fun);
|
183
|
+
|
184
|
+
/* If the function succeeds, the return value is pointer to the absolute path of current working directory*/
|
185
|
+
/* If the function fails, the return value is NULL*/
|
186
|
+
char *uGetCurrentWorkingDirectory(char *buf, int maxLength, sys_call_error_fun fun);
|
187
|
+
|
188
|
+
/* If the function succeeds, the return value is 0*/
|
189
|
+
/* If the function fails, the return value is -1*/
|
190
|
+
int uChangeWorkingDirectory(const char *path, sys_call_error_fun fun);
|
191
|
+
|
192
|
+
char *uGetDirectoryFromFilePath(const char *path, char *buf, int buf_len, sys_call_error_fun fun);
|
193
|
+
|
194
|
+
char *uGetFileNameFromFilePath(const char *path, char *buf, int buf_len, sys_call_error_fun fun);
|
195
|
+
|
196
|
+
UDir uFindFirstFile(const char* filename, struct UFindDataStruct* find_data, sys_call_error_fun fun);
|
197
|
+
|
198
|
+
int uFindNextFile(UDir dir, struct UFindDataStruct* find_data, sys_call_error_fun fun);
|
199
|
+
|
200
|
+
int uFindClose(UDir dir, sys_call_error_fun fun);
|
201
|
+
|
202
|
+
#ifdef __cplusplus
|
203
|
+
}
|
204
|
+
#endif
|
205
|
+
|
206
|
+
#endif
|
@@ -0,0 +1,268 @@
|
|
1
|
+
/*
|
2
|
+
* File: ummap.cpp
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#include "common/u/ummap.h"
|
8
|
+
#include "common/errdbg/d_printf.h"
|
9
|
+
#include "common/u/ugnames.h"
|
10
|
+
|
11
|
+
//#define RIGHTS 00660
|
12
|
+
|
13
|
+
UMMap uCreateFileMapping(UFile fd, int size, const char* name, USECURITY_ATTRIBUTES* sa, sys_call_error_fun fun)
|
14
|
+
{
|
15
|
+
char buf[128];
|
16
|
+
const char *uName = NULL;
|
17
|
+
#ifdef _WIN32
|
18
|
+
UMMap m;
|
19
|
+
m.fd = fd;
|
20
|
+
uName = UWinIPCNameFromGlobalName(name, buf, sizeof buf);
|
21
|
+
m.map = CreateFileMapping(fd, sa, PAGE_READWRITE, 0, size, uName);
|
22
|
+
if (m.map == NULL) sys_call_error("CreateFileMapping");
|
23
|
+
|
24
|
+
if (m.map == NULL || GetLastError() == ERROR_ALREADY_EXISTS) m.map = NULL;
|
25
|
+
|
26
|
+
return m;
|
27
|
+
#else
|
28
|
+
UMMap m;
|
29
|
+
uName = UPosixIPCNameFromGlobalName(name, buf, sizeof buf);
|
30
|
+
if (fd == U_INVALID_FD)
|
31
|
+
{
|
32
|
+
USECURITY_ATTRIBUTES mmap_access_mode = U_SEDNA_DEFAULT_ACCESS_PERMISSIONS_MASK;
|
33
|
+
if (sa) mmap_access_mode = *sa;
|
34
|
+
m.map = shm_open(uName, O_RDWR | O_CREAT | O_EXCL, mmap_access_mode);
|
35
|
+
m.size = size;
|
36
|
+
m.to_file = 0;
|
37
|
+
if (m.map == -1)
|
38
|
+
{
|
39
|
+
sys_call_error("shm_open");
|
40
|
+
return m;
|
41
|
+
}
|
42
|
+
|
43
|
+
if (ftruncate(m.map, size) == -1)
|
44
|
+
{
|
45
|
+
sys_call_error("ftruncate");
|
46
|
+
m.map = -1;
|
47
|
+
return m;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
else
|
51
|
+
{
|
52
|
+
struct stat buf;
|
53
|
+
if (fstat(fd, &buf) == -1)
|
54
|
+
{
|
55
|
+
sys_call_error("fstat");
|
56
|
+
m.map = -1;
|
57
|
+
return m;
|
58
|
+
}
|
59
|
+
|
60
|
+
m.map = fd;
|
61
|
+
m.size = buf.st_size;
|
62
|
+
m.to_file = 1;
|
63
|
+
}
|
64
|
+
|
65
|
+
return m;
|
66
|
+
#endif
|
67
|
+
}
|
68
|
+
|
69
|
+
UMMap uOpenFileMapping(UFile fd, int size, const char *name, sys_call_error_fun fun)
|
70
|
+
{
|
71
|
+
char buf[128];
|
72
|
+
const char *uName = NULL;
|
73
|
+
#ifdef _WIN32
|
74
|
+
UMMap m;
|
75
|
+
m.fd = INVALID_HANDLE_VALUE;
|
76
|
+
uName = UWinIPCNameFromGlobalName(name, buf, sizeof buf);
|
77
|
+
m.map = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, uName);
|
78
|
+
if (m.map == NULL) sys_call_error("OpenFileMapping");
|
79
|
+
return m;
|
80
|
+
#else
|
81
|
+
UMMap m;
|
82
|
+
uName = UPosixIPCNameFromGlobalName(name, buf, sizeof buf);
|
83
|
+
if (fd == U_INVALID_FD)
|
84
|
+
{
|
85
|
+
m.map = shm_open(uName, O_RDWR, 0);
|
86
|
+
m.size = size;
|
87
|
+
m.to_file = 0;
|
88
|
+
if (m.map == -1)
|
89
|
+
{
|
90
|
+
sys_call_error("shm_open");
|
91
|
+
return m;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
else
|
95
|
+
{
|
96
|
+
struct stat buf;
|
97
|
+
if (fstat(fd, &buf) == -1)
|
98
|
+
{
|
99
|
+
sys_call_error("fstat");
|
100
|
+
m.map = -1;
|
101
|
+
return m;
|
102
|
+
}
|
103
|
+
|
104
|
+
m.map = fd;
|
105
|
+
m.size = buf.st_size;
|
106
|
+
m.to_file = 1;
|
107
|
+
}
|
108
|
+
|
109
|
+
return m;
|
110
|
+
#endif
|
111
|
+
}
|
112
|
+
|
113
|
+
int uReleaseFileMapping(UMMap m, const char *name, sys_call_error_fun fun)
|
114
|
+
{
|
115
|
+
char buf[128];
|
116
|
+
const char *uName = NULL;
|
117
|
+
#ifdef _WIN32
|
118
|
+
uName = UWinIPCNameFromGlobalName(name, buf, sizeof buf);
|
119
|
+
if( CloseHandle(m.map) == 0)
|
120
|
+
{
|
121
|
+
sys_call_error("CloseHandle");
|
122
|
+
return -1;
|
123
|
+
}
|
124
|
+
else return 0;
|
125
|
+
#else
|
126
|
+
uName = UPosixIPCNameFromGlobalName(name, buf, sizeof buf);
|
127
|
+
if (uName)
|
128
|
+
{
|
129
|
+
if(0 == m.to_file && -1 != m.map)
|
130
|
+
{
|
131
|
+
if(close(m.map) == -1)
|
132
|
+
{
|
133
|
+
sys_call_error("close");
|
134
|
+
return -1;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
if (shm_unlink(uName) == -1)
|
139
|
+
{
|
140
|
+
sys_call_error("shm_unlink");
|
141
|
+
return -1;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
return 0;
|
146
|
+
#endif
|
147
|
+
}
|
148
|
+
|
149
|
+
int uCloseFileMapping(UMMap m, sys_call_error_fun fun)
|
150
|
+
{
|
151
|
+
#ifdef _WIN32
|
152
|
+
if (CloseHandle(m.map) == 0)
|
153
|
+
{
|
154
|
+
sys_call_error("CloseHandle");
|
155
|
+
return -1;
|
156
|
+
}
|
157
|
+
else return 0;
|
158
|
+
#else
|
159
|
+
return 0;
|
160
|
+
#endif
|
161
|
+
}
|
162
|
+
|
163
|
+
void *uMapViewOfFile(UMMap m, void *addr, int size, int offs, sys_call_error_fun fun)
|
164
|
+
{
|
165
|
+
#ifdef _WIN32
|
166
|
+
void *ret_val;
|
167
|
+
if ((ret_val = MapViewOfFileEx(m.map, FILE_MAP_ALL_ACCESS, 0, offs, size, addr)) == NULL)
|
168
|
+
{
|
169
|
+
sys_call_error("MapViewOfFileEx");
|
170
|
+
return ret_val;
|
171
|
+
}
|
172
|
+
else return ret_val;
|
173
|
+
#else
|
174
|
+
if (size == 0) size = m.size;
|
175
|
+
void* ret_val;
|
176
|
+
|
177
|
+
if (addr)
|
178
|
+
ret_val = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, m.map, offs);
|
179
|
+
else
|
180
|
+
ret_val = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_SHARED, m.map, offs);
|
181
|
+
|
182
|
+
if (ret_val == MAP_FAILED)
|
183
|
+
sys_call_error("mmap");
|
184
|
+
|
185
|
+
return ret_val == MAP_FAILED ? NULL : ret_val;
|
186
|
+
|
187
|
+
#endif
|
188
|
+
}
|
189
|
+
|
190
|
+
int uUnmapViewOfFile(UMMap m, void *addr, int size, sys_call_error_fun fun)
|
191
|
+
{
|
192
|
+
#ifdef _WIN32
|
193
|
+
if (UnmapViewOfFile(addr) == 0)
|
194
|
+
{
|
195
|
+
sys_call_error("UnmapViewOfFile");
|
196
|
+
return -1;
|
197
|
+
}
|
198
|
+
else return 0;
|
199
|
+
#else
|
200
|
+
if (size == 0) size = m.size;
|
201
|
+
|
202
|
+
int res;
|
203
|
+
if ((res = munmap(addr, size)) == -1)
|
204
|
+
{
|
205
|
+
sys_call_error("munmap");
|
206
|
+
return res;
|
207
|
+
}
|
208
|
+
else return res;
|
209
|
+
#endif
|
210
|
+
}
|
211
|
+
|
212
|
+
int uFlushViewOfFile(UMMap m, void *addr, int size, sys_call_error_fun fun)
|
213
|
+
{
|
214
|
+
#ifdef _WIN32
|
215
|
+
if (FlushViewOfFile(addr, size) == 0)
|
216
|
+
{
|
217
|
+
sys_call_error("FlushViewOfFile");
|
218
|
+
return -1;
|
219
|
+
}
|
220
|
+
else return 0;
|
221
|
+
#else
|
222
|
+
if (m.to_file)
|
223
|
+
{
|
224
|
+
int res;
|
225
|
+
if (size == 0) size = m.size;
|
226
|
+
if ((res = msync(addr, size, MS_SYNC)) == -1)
|
227
|
+
{
|
228
|
+
sys_call_error("msync");
|
229
|
+
return res;
|
230
|
+
}
|
231
|
+
else return res;
|
232
|
+
}
|
233
|
+
else return 0;
|
234
|
+
#endif
|
235
|
+
}
|
236
|
+
|
237
|
+
int uMemLock(void *addr, size_t size, sys_call_error_fun fun)
|
238
|
+
{
|
239
|
+
#ifdef _WIN32
|
240
|
+
if (VirtualLock(addr, size) == 0)
|
241
|
+
{
|
242
|
+
sys_call_error("VirtualLock");
|
243
|
+
return -1;
|
244
|
+
}
|
245
|
+
else return 0;
|
246
|
+
#else
|
247
|
+
int res = mlock(addr, size);
|
248
|
+
if (res == -1) sys_call_error("mlock");
|
249
|
+
return res;
|
250
|
+
#endif
|
251
|
+
}
|
252
|
+
|
253
|
+
int uMemUnlock(void *addr, size_t size, sys_call_error_fun fun)
|
254
|
+
{
|
255
|
+
#ifdef _WIN32
|
256
|
+
if (VirtualUnlock(addr, size) == 0)
|
257
|
+
{
|
258
|
+
sys_call_error("VirtualUnlock");
|
259
|
+
return -1;
|
260
|
+
}
|
261
|
+
else return 0;
|
262
|
+
#else
|
263
|
+
int res = munlock(addr, size);
|
264
|
+
if (res == -1)
|
265
|
+
sys_call_error("munlock");
|
266
|
+
return res;
|
267
|
+
#endif
|
268
|
+
}
|