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,49 @@
|
|
1
|
+
/*
|
2
|
+
* File: sedna.h
|
3
|
+
* Copyright (C) 2006 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#ifndef _SEDNA_H
|
8
|
+
#define _SEDNA_H
|
9
|
+
|
10
|
+
|
11
|
+
#include "common/u/u.h"
|
12
|
+
#include "sp_defs.h"
|
13
|
+
#include "common/mmgr/se_alloc.h"
|
14
|
+
#include "common/errdbg/event_log.h"
|
15
|
+
|
16
|
+
#ifdef __cplusplus
|
17
|
+
#include "common/errdbg/exceptions.h"
|
18
|
+
#endif
|
19
|
+
|
20
|
+
|
21
|
+
/*
|
22
|
+
* SEDNA_DATA contains path to the Sedna's data directory
|
23
|
+
*/
|
24
|
+
#define SEDNA_DATA_VAR_SIZE 1024
|
25
|
+
SE_EXTERN_C char* SEDNA_DATA;
|
26
|
+
|
27
|
+
/*
|
28
|
+
* Pointer to the governor's shared memory
|
29
|
+
*/
|
30
|
+
SE_EXTERN_C void* sedna_gov_shm_ptr;
|
31
|
+
|
32
|
+
|
33
|
+
SE_EXTERN_C
|
34
|
+
int set_sedna_data(char*, sys_call_error_fun fun);
|
35
|
+
|
36
|
+
SE_EXTERN_C
|
37
|
+
void DumpFaultInfo();
|
38
|
+
|
39
|
+
|
40
|
+
#define SEDNA_SOFT_FAULT_BASE_MSG \
|
41
|
+
fprintf(stderr, "SEDNA Message: FATAL ERROR\n"); \
|
42
|
+
DumpFaultInfo(); \
|
43
|
+
fprintf(stderr, "System error. This error means system malfunction.\n")
|
44
|
+
|
45
|
+
#define SEDNA_SOFT_FAULT_FINALIZER \
|
46
|
+
fflush(stderr); \
|
47
|
+
uExitProcess(1, __sys_call_error)
|
48
|
+
|
49
|
+
#endif /*_SEDNA_H */
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
* File: sedna_ef.h
|
3
|
+
* Copyright (C) 2005 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef _SEDNA_EF_H
|
7
|
+
#define _SEDNA_EF_H
|
8
|
+
|
9
|
+
#define SEDNA_ERROR_MSG_BUF_SIZE 128
|
10
|
+
|
11
|
+
typedef enum sedna_atomic_type {SEDNATYPE_integer, SEDNATYPE_float, SEDNATYPE_double, SEDNATYPE_string} SEDNA_ATOMIC_TYPE;
|
12
|
+
|
13
|
+
typedef int SEDNA_integer;
|
14
|
+
typedef float SEDNA_float;
|
15
|
+
typedef double SEDNA_double;
|
16
|
+
typedef char *SEDNA_string;
|
17
|
+
|
18
|
+
typedef struct sedna_atomic_value
|
19
|
+
{
|
20
|
+
SEDNA_ATOMIC_TYPE type;
|
21
|
+
union
|
22
|
+
{
|
23
|
+
SEDNA_integer val_integer;
|
24
|
+
SEDNA_float val_float;
|
25
|
+
SEDNA_double val_double;
|
26
|
+
SEDNA_string val_string;
|
27
|
+
};
|
28
|
+
} SEDNA_ATOMIC_VALUE;
|
29
|
+
|
30
|
+
typedef struct sedna_sequence_item
|
31
|
+
{
|
32
|
+
SEDNA_ATOMIC_VALUE data;
|
33
|
+
struct sedna_sequence_item *next;
|
34
|
+
} SEDNA_SEQUENCE_ITEM;
|
35
|
+
|
36
|
+
typedef struct sedna_ef_init
|
37
|
+
{
|
38
|
+
void *(*sedna_malloc)(size_t);
|
39
|
+
void (*sedna_free)(void *);
|
40
|
+
SEDNA_SEQUENCE_ITEM *node_buf;
|
41
|
+
void *ptr;
|
42
|
+
} SEDNA_EF_INIT;
|
43
|
+
|
44
|
+
typedef struct sedna_ef_args
|
45
|
+
{
|
46
|
+
int length;
|
47
|
+
SEDNA_SEQUENCE_ITEM **args;
|
48
|
+
} SEDNA_EF_ARGS;
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
#endif /* _SEDNA_EF_H */
|
@@ -0,0 +1,144 @@
|
|
1
|
+
/*
|
2
|
+
* File: sm_vmm_data.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#ifndef _SM_VMM_DATA_H
|
8
|
+
#define _SM_VMM_DATA_H
|
9
|
+
|
10
|
+
#include "common/sedna.h"
|
11
|
+
#include "common/base.h"
|
12
|
+
#include "common/xptr.h"
|
13
|
+
#include "common/wustructures.h"
|
14
|
+
#include "common/lfsGlobals.h"
|
15
|
+
|
16
|
+
struct vmm_sm_blk_hdr
|
17
|
+
{
|
18
|
+
xptr p; // the first 4 bytes is the layer of the block
|
19
|
+
LSN lsn;
|
20
|
+
VersionsHeader versionsHeader;
|
21
|
+
|
22
|
+
int blockType; // (c) A. Kalinin
|
23
|
+
ramoffs roffs; // address of block in buffer memory
|
24
|
+
int is_changed;
|
25
|
+
int trid_wr_access; /* Motherfuckers! Session id (sid) is actually stored here! */
|
26
|
+
|
27
|
+
static void init(vmm_sm_blk_hdr *hdr)
|
28
|
+
{
|
29
|
+
hdr->p = XNULL;
|
30
|
+
hdr->lsn = LFS_INVALID_LSN;
|
31
|
+
memset(hdr->versionsHeader.xptr, 0, sizeof hdr->versionsHeader.xptr);
|
32
|
+
memset(hdr->versionsHeader.creatorTs, -1, sizeof hdr->versionsHeader.creatorTs);
|
33
|
+
hdr->roffs = 0;
|
34
|
+
memcpy(&hdr->blockType, "AKNZ", 4);
|
35
|
+
hdr->is_changed = false;
|
36
|
+
hdr->trid_wr_access = -1;
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
/* Hot-Backup states and answers in messages */
|
41
|
+
enum hb_state
|
42
|
+
{
|
43
|
+
HB_START, // start hot-backup
|
44
|
+
HB_START_CHECKPOINT, // start hot-backup with preceding checkpoint
|
45
|
+
HB_START_INCR, // make primary increment copy
|
46
|
+
HB_ADD_INCR, // archive another portion of the db
|
47
|
+
HB_STOP_INCR, // disable increment mode for the given database
|
48
|
+
HB_NONE_INCR, // non-increment mode
|
49
|
+
HB_CONT, // sm answer: can continue
|
50
|
+
HB_WAIT, // answer: wait for checkpoint to finish
|
51
|
+
HB_ARCHIVELOG, // archive logical log (switch to the next one)
|
52
|
+
HB_END, // end of the hot-backup process
|
53
|
+
HB_ERR, // some error from sm
|
54
|
+
HB_NEXTFILE, // file request from hbp
|
55
|
+
HB_GETPREVLOG // get previous log file number
|
56
|
+
};
|
57
|
+
|
58
|
+
/**
|
59
|
+
*
|
60
|
+
* cmd list:
|
61
|
+
* =========
|
62
|
+
* response list:
|
63
|
+
* ~~~~~~~~~~~~~~
|
64
|
+
* 0 - success
|
65
|
+
* otherwise (int > 0) - fail
|
66
|
+
*
|
67
|
+
* query list:
|
68
|
+
* ~~~~~~~~~~~
|
69
|
+
* 10 - soft shutdown
|
70
|
+
* 11 - hard shutdown
|
71
|
+
*
|
72
|
+
* 21 - bm_register_session
|
73
|
+
* 22 - bm_unregister_session
|
74
|
+
* 23 - bm_allocate_data_block (xptr, offs)
|
75
|
+
* 24 - bm_allocate_tmp_block (xptr, offs)
|
76
|
+
* 25 - bm_delete_block (xptr)
|
77
|
+
* 26 - bm_get_block (xptr, offs)
|
78
|
+
* 27 - bm_enter_exclusive_mode (num)
|
79
|
+
* 28 - bm_exit_exclusive_mode
|
80
|
+
* 29 - bm_memlock_block (xptr)
|
81
|
+
* 30 - bm_memunlock_block (xptr)
|
82
|
+
* 31 - bm_block_statistics (sm_blk_stat)
|
83
|
+
* 32 - bm_pseudo_allocate_data_block (xptr)
|
84
|
+
* 33 - bm_pseudo_delete_data_block (xptr)
|
85
|
+
* 34 - bm_delete_tmp_blocks
|
86
|
+
* 35 - bm_register_transaction
|
87
|
+
* 36 - bm_unregister_transaction
|
88
|
+
* 37 - bm_create_new_version
|
89
|
+
* 38 - transaction rollback
|
90
|
+
* 39 - hot-backup procedure (receive: state, return: status, or log file numbers; use hb_struct for this)
|
91
|
+
*/
|
92
|
+
|
93
|
+
struct sm_blk_stat
|
94
|
+
{
|
95
|
+
int free_data_blocks_num;
|
96
|
+
int free_tmp_blocks_num;
|
97
|
+
int used_data_blocks_num;
|
98
|
+
int used_tmp_blocks_num;
|
99
|
+
};
|
100
|
+
|
101
|
+
struct sm_msg_struct
|
102
|
+
{
|
103
|
+
// cmd (what do you want to do)
|
104
|
+
int cmd;
|
105
|
+
// transaction identifier
|
106
|
+
transaction_id trid;
|
107
|
+
|
108
|
+
//identifier of session
|
109
|
+
session_id sid;
|
110
|
+
|
111
|
+
// additional parameters
|
112
|
+
union {
|
113
|
+
struct {
|
114
|
+
int num; // number of potentially allocated blocks in call to bm_enter_exclusive_mode
|
115
|
+
xptr mptr; // pointer for catalog master block
|
116
|
+
int transaction_flags;
|
117
|
+
} reg;
|
118
|
+
|
119
|
+
xptr ptr; // xptr for deletion, locking and unlocking
|
120
|
+
|
121
|
+
struct {
|
122
|
+
xptr ptr;
|
123
|
+
xptr swapped;
|
124
|
+
int offs;
|
125
|
+
} swap_data;
|
126
|
+
|
127
|
+
struct {
|
128
|
+
uint64_t lnumber;
|
129
|
+
hb_state state;
|
130
|
+
bool is_checkp;
|
131
|
+
hb_state incr_state;
|
132
|
+
TIMESTAMP ts;
|
133
|
+
} hb_struct;
|
134
|
+
|
135
|
+
int64_t snp_ts; // timestamp of snapshot, not used currently, but may be helpful later
|
136
|
+
|
137
|
+
sm_blk_stat stat; // sm block statistics
|
138
|
+
|
139
|
+
char data[2 + MAX_RESOURCE_NAME_LENGTH]; // first byte->lock mode, second byte->resource type, other bytes->resource name
|
140
|
+
|
141
|
+
} data;
|
142
|
+
};
|
143
|
+
|
144
|
+
#endif
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/*
|
2
|
+
* File: sp.c
|
3
|
+
* Copyright (C) 2009 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#include "common/sp.h"
|
8
|
+
#include "common/errdbg/d_printf.h"
|
9
|
+
#include "common/u/uutils.h"
|
10
|
+
|
11
|
+
/* returns zero - if succeeded;
|
12
|
+
returns 1 - if Message length exceeds available size
|
13
|
+
returns U_SOCKET_ERROR if error */
|
14
|
+
int sp_recv_msg(USOCKET s, struct msg_struct *msg)
|
15
|
+
{
|
16
|
+
int rc = 0, got = 0;
|
17
|
+
__int64 buf = 0;
|
18
|
+
char* ptr = (char*)&buf;
|
19
|
+
|
20
|
+
while (got < 8)
|
21
|
+
{
|
22
|
+
rc = urecv(s, ptr + got, 8 - got, __sys_call_error);
|
23
|
+
if ((rc == U_SOCKET_ERROR) || (rc == 0))
|
24
|
+
return U_SOCKET_ERROR;
|
25
|
+
got += rc;
|
26
|
+
}
|
27
|
+
|
28
|
+
msg->instruction = ntohl(*(sp_int32 *) ptr);
|
29
|
+
msg->length = ntohl(*(sp_int32 *) (ptr + 4));
|
30
|
+
if (msg->length > SE_SOCKET_MSG_BUF_SIZE)
|
31
|
+
{
|
32
|
+
return 1; /* Message length exceeds available size */
|
33
|
+
}
|
34
|
+
|
35
|
+
got = 0;
|
36
|
+
while (got < msg->length)
|
37
|
+
{
|
38
|
+
rc = urecv(s, msg->body + got, msg->length - got, __sys_call_error);
|
39
|
+
if ((rc == U_SOCKET_ERROR) || (rc == 0))
|
40
|
+
return U_SOCKET_ERROR;
|
41
|
+
got += rc;
|
42
|
+
}
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
/* returns zero if succeeded
|
48
|
+
returns U_SOCKET_ERROR if error */
|
49
|
+
int sp_send_msg(USOCKET s, const struct msg_struct *msg)
|
50
|
+
{
|
51
|
+
__int64 buf = 0;
|
52
|
+
char* ptr = (char*)&buf;
|
53
|
+
int rc = 0, sent = 0;
|
54
|
+
|
55
|
+
*(sp_int32*)ptr = htonl(msg->instruction);
|
56
|
+
*((sp_int32*)(ptr + 4)) = htonl(msg->length);
|
57
|
+
while (sent < 8)
|
58
|
+
{
|
59
|
+
rc = usend(s, ptr + sent, 8 - sent, __sys_call_error);
|
60
|
+
if (rc == U_SOCKET_ERROR)
|
61
|
+
return U_SOCKET_ERROR;
|
62
|
+
sent += rc;
|
63
|
+
}
|
64
|
+
|
65
|
+
sent = rc = 0;
|
66
|
+
while (sent < msg->length)
|
67
|
+
{
|
68
|
+
rc = usend(s, (const char *) (msg->body + sent), msg->length - sent, __sys_call_error);
|
69
|
+
if (rc == U_SOCKET_ERROR)
|
70
|
+
return U_SOCKET_ERROR;
|
71
|
+
sent += rc;
|
72
|
+
}
|
73
|
+
|
74
|
+
return 0;
|
75
|
+
}
|
76
|
+
|
77
|
+
/* sends error message to client.
|
78
|
+
Error message contains message instruction, message length, error code, error info.
|
79
|
+
returns zero if succeeded, U_SOCKET_ERROR if failed */
|
80
|
+
int sp_error_message_handler(USOCKET s, int error_ins, int error_code, const char *error_info)
|
81
|
+
{
|
82
|
+
struct msg_struct server_msg;
|
83
|
+
int err_length = strlen(error_info);
|
84
|
+
|
85
|
+
server_msg.instruction = error_ins;
|
86
|
+
server_msg.length = err_length + 5 + 4;
|
87
|
+
*(sp_int32*)server_msg.body = htonl(error_code); /* this is error code */
|
88
|
+
server_msg.body[4] = 0;
|
89
|
+
*(sp_int32*)(server_msg.body + 5) = htonl(err_length); /* this is error_info length */
|
90
|
+
memcpy(server_msg.body + 9, error_info, err_length);
|
91
|
+
|
92
|
+
return sp_send_msg(s, &server_msg);
|
93
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
* File: sp.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef _SP_H
|
7
|
+
#define _SP_H
|
8
|
+
|
9
|
+
#include "common/u/usocket.h"
|
10
|
+
#include "sp_defs.h"
|
11
|
+
|
12
|
+
|
13
|
+
#ifdef __cplusplus
|
14
|
+
extern "C"
|
15
|
+
{
|
16
|
+
#endif
|
17
|
+
|
18
|
+
/* returns zero - if succeeded;
|
19
|
+
returns 1 - if Message length exceeds available size
|
20
|
+
returns U_SOCKET_ERROR if error */
|
21
|
+
int sp_recv_msg(USOCKET s, struct msg_struct *msg);
|
22
|
+
|
23
|
+
/* returns zero if succeeded
|
24
|
+
returns U_SOCKET_ERROR if error */
|
25
|
+
int sp_send_msg(USOCKET s, const struct msg_struct *msg);
|
26
|
+
|
27
|
+
/* sends error message to client.
|
28
|
+
Error message contains message instruction, message length, error code, error info.
|
29
|
+
returns zero if succeeded, U_SOCKET_ERROR if failed */
|
30
|
+
int sp_error_message_handler(USOCKET s, int error_ins, int error_code, const char *error_info);
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
}
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#endif
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Makefile for u (GNU make)
|
3
|
+
#
|
4
|
+
|
5
|
+
PP = ../../..
|
6
|
+
|
7
|
+
|
8
|
+
include $(PP)/Makefile.include
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
ifeq ("$(OS)", "CYGWIN_NT")
|
13
|
+
VPATH = $(PP)/kernel/common/st/os_nt
|
14
|
+
else
|
15
|
+
VPATH = $(PP)/kernel/common/st/os_other
|
16
|
+
endif
|
17
|
+
|
18
|
+
OBJS = stacktrace$(OBJ_EXT) stacktrfmt$(OBJ_EXT)
|
19
|
+
|
20
|
+
include $(PP)/Makefile.pseudolib
|
@@ -0,0 +1,213 @@
|
|
1
|
+
/* GNU backtraces
|
2
|
+
* http://docs.linux.cz/programming/c/www.gnu.org/software/libc/manual/html_node/Backtraces.html#Backtraces
|
3
|
+
*
|
4
|
+
* Solaris walkcontext
|
5
|
+
* http://docs.sun.com/app/docs/doc/819-2243/printstack-3c?a=view
|
6
|
+
*
|
7
|
+
* Stack parameters not reported properly with either getcontext() or
|
8
|
+
* when invoking signal handlers
|
9
|
+
* http://sources.redhat.com/bugzilla/show_bug.cgi?id=759
|
10
|
+
*/
|
11
|
+
|
12
|
+
#define _GNU_SOURCE
|
13
|
+
#include <execinfo.h>
|
14
|
+
#include <stdio.h>
|
15
|
+
#include <stdlib.h>
|
16
|
+
#include <signal.h>
|
17
|
+
#include <unistd.h>
|
18
|
+
#include <ucontext.h>
|
19
|
+
#include <string.h>
|
20
|
+
#include <assert.h>
|
21
|
+
#include <fcntl.h>
|
22
|
+
#include <errno.h>
|
23
|
+
#include <stdint.h>
|
24
|
+
#include <dlfcn.h>
|
25
|
+
|
26
|
+
/* Obtain a backtrace and print it to stdout. */
|
27
|
+
void
|
28
|
+
print_trace (void)
|
29
|
+
{
|
30
|
+
void *array[10];
|
31
|
+
size_t size;
|
32
|
+
char **strings;
|
33
|
+
size_t i;
|
34
|
+
|
35
|
+
size = backtrace (array, 10);
|
36
|
+
strings = backtrace_symbols (array, size);
|
37
|
+
|
38
|
+
printf ("Obtained %zd stack frames.\n", size);
|
39
|
+
|
40
|
+
for (i = 0; i < size; i++)
|
41
|
+
printf ("%s\n", strings[i]);
|
42
|
+
|
43
|
+
free (strings);
|
44
|
+
}
|
45
|
+
|
46
|
+
/* A dummy function to make the backtrace more interesting. */
|
47
|
+
void
|
48
|
+
dummy_function ()
|
49
|
+
{
|
50
|
+
print_trace ();
|
51
|
+
}
|
52
|
+
|
53
|
+
#define OFFSET(PTR,DIST) (void*)((char*)(PTR)+(DIST))
|
54
|
+
|
55
|
+
/* Explore process VM layout parsing /proc/${PID}/maps.
|
56
|
+
* If the segment enclosing sample location is found
|
57
|
+
* function succeeds. Non-zero return status indicates
|
58
|
+
* success. If segment is found and is availible for
|
59
|
+
* reading start and end variables recieves pointers
|
60
|
+
* to the start and the end of segment. */
|
61
|
+
int gsegbounds(void *sample, void **start, void **end)
|
62
|
+
{
|
63
|
+
int success = 0, fd = -1;
|
64
|
+
void *localStart = NULL, *localEnd = NULL;
|
65
|
+
char buf[256] = {0}, localPathname[256] = {0}, localPerms[16] = {0};
|
66
|
+
int localOffset = 0, localDevMinor = 0, localDevMajor = 0;
|
67
|
+
int localInode = 0;
|
68
|
+
|
69
|
+
assert(start && end);
|
70
|
+
*start = *end = NULL;
|
71
|
+
|
72
|
+
sprintf(buf, "/proc/%d/maps", getpid());
|
73
|
+
fd = open(buf, O_RDONLY);
|
74
|
+
|
75
|
+
if (fd != -1)
|
76
|
+
{
|
77
|
+
char *bufGetCursor = buf, *bufPutCursor = buf;
|
78
|
+
char *bufEolCursor = NULL;
|
79
|
+
ssize_t readSz = 0, availSz = 0;
|
80
|
+
int numParsed = 0;
|
81
|
+
|
82
|
+
while (1)
|
83
|
+
{
|
84
|
+
if (bufGetCursor != buf)
|
85
|
+
{
|
86
|
+
readSz = bufPutCursor - bufGetCursor;
|
87
|
+
memmove(buf, bufGetCursor, readSz);
|
88
|
+
bufGetCursor = buf;
|
89
|
+
bufPutCursor = buf + readSz;
|
90
|
+
}
|
91
|
+
availSz = sizeof buf - 1 - (bufPutCursor - buf);
|
92
|
+
readSz = read(fd, bufPutCursor, availSz);
|
93
|
+
if (readSz == -1)
|
94
|
+
{
|
95
|
+
if (errno == EINTR) continue;
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
0[bufPutCursor+=readSz]=0;
|
99
|
+
if (readSz == 0 && bufGetCursor >= bufPutCursor) break;
|
100
|
+
bufEolCursor = strchr(buf,'\n');
|
101
|
+
if (!bufEolCursor)
|
102
|
+
{
|
103
|
+
if (readSz == 0) bufEolCursor = bufPutCursor;
|
104
|
+
else break;
|
105
|
+
}
|
106
|
+
*bufEolCursor = 0;
|
107
|
+
strcpy(localPathname,"");
|
108
|
+
numParsed = sscanf(bufGetCursor,
|
109
|
+
"%p-%p %15s %x %x:%x %d %255s",
|
110
|
+
&localStart, &localEnd,
|
111
|
+
localPerms, &localOffset,
|
112
|
+
&localDevMajor, &localDevMinor,
|
113
|
+
&localInode, localPathname);
|
114
|
+
if (numParsed != 7 && numParsed != 8) break;
|
115
|
+
bufGetCursor = bufEolCursor+1;
|
116
|
+
|
117
|
+
if (localStart<=sample && sample<localEnd)
|
118
|
+
{
|
119
|
+
success = 1;
|
120
|
+
if (strchr(localPerms,'r')==NULL)
|
121
|
+
{
|
122
|
+
localStart = localEnd = NULL;
|
123
|
+
}
|
124
|
+
break;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
close(fd); fd=-1;
|
129
|
+
if (success) {*start = localStart; *end = localEnd;}
|
130
|
+
return success;
|
131
|
+
}
|
132
|
+
|
133
|
+
void gsymstr(void *addr, char *buf)
|
134
|
+
{
|
135
|
+
Dl_info dlinfo = {};
|
136
|
+
if (!dladdr(addr, &dlinfo))
|
137
|
+
{
|
138
|
+
strcpy(buf,"error");
|
139
|
+
}
|
140
|
+
else
|
141
|
+
{
|
142
|
+
sprintf(buf,"%s %s", dlinfo.dli_fname, dlinfo.dli_sname);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
void ctxstracefd(const ucontext_t *ucontext, int fd)
|
147
|
+
{
|
148
|
+
uintptr_t stack_top = 0, stack_bot = 0, stack = 0, code = 0, desert = 0;
|
149
|
+
char buf[1024], buf2[512];
|
150
|
+
size_t sz=0;
|
151
|
+
|
152
|
+
assert(ucontext);
|
153
|
+
stack = ucontext->uc_mcontext.gregs[REG_EBP];
|
154
|
+
desert = stack - 1;
|
155
|
+
code = ucontext->uc_mcontext.gregs[REG_EIP];
|
156
|
+
|
157
|
+
if (gsegbounds((void*)stack,(void**)&stack_top,(void**)&stack_bot) &&
|
158
|
+
stack_top<=stack && stack<stack_bot)
|
159
|
+
{
|
160
|
+
/* We have to check that pointers in the list of
|
161
|
+
* stack frames do not point outside the stack segment.
|
162
|
+
* We also assume that we will move towards the stack
|
163
|
+
* bottom while walking the stack. This way we protect
|
164
|
+
* from circular stack frames list in a corrupted stack.
|
165
|
+
* If (stack == 0), we are in the topmost frame. However
|
166
|
+
* we still have to extract the function address. */
|
167
|
+
while (stack == 0 || stack > desert && stack<=stack_bot)
|
168
|
+
{
|
169
|
+
gsymstr((void*)code, buf2);
|
170
|
+
sz = sprintf(buf,"%p %s\n",code,buf2);
|
171
|
+
write(fd, buf, sz);
|
172
|
+
if (stack == 0) break;
|
173
|
+
desert = stack;
|
174
|
+
code = 1[(uintptr_t *)stack];
|
175
|
+
stack = 0[(uintptr_t *)stack];
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
void sig_handler(int signo, siginfo_t *siginfo, void *ucontext)
|
182
|
+
{
|
183
|
+
dummy_function();
|
184
|
+
ctxstracefd(ucontext, 2);
|
185
|
+
abort();
|
186
|
+
}
|
187
|
+
|
188
|
+
void dummy_function2 (void)
|
189
|
+
{
|
190
|
+
strcpy(NULL,"DIE");
|
191
|
+
}
|
192
|
+
|
193
|
+
void dummy_function3 (void)
|
194
|
+
{
|
195
|
+
dummy_function2();
|
196
|
+
}
|
197
|
+
|
198
|
+
int
|
199
|
+
main (void)
|
200
|
+
{
|
201
|
+
void *a = NULL, *b = NULL;
|
202
|
+
struct sigaction act;
|
203
|
+
act.sa_sigaction = sig_handler;
|
204
|
+
sigemptyset(&act.sa_mask);
|
205
|
+
act.sa_flags = SA_SIGINFO;
|
206
|
+
|
207
|
+
gsegbounds(NULL,&a,&b);
|
208
|
+
sigaction (SIGSEGV, &act, NULL);
|
209
|
+
dummy_function3();
|
210
|
+
|
211
|
+
return 0;
|
212
|
+
}
|
213
|
+
|