1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRCID_MARSHALD_CMD_CONNECT 0x0000
38 #include"drd64_marshald.h"
40 #define DRD64_FUNCID_Marshald_Cmd_Connect_Client 0x12
41 #define DRD64_FUNCID_Marshald_Cmd_Connect_Server 0x11
42 #define DRD64_FUNCID_Marshald_Cmd_Connect 0x01
44 /*----------------------------------------------------------------------
46 Drd64_Intel64_DisAsm_GetSize_SizeID(
47 : Get Operand Size form Intel 64 DB SizeID
49 int i_operandsize, : [src] Default Operand Size
50 Word w_methodtype, : [src] Method Type ID
51 Word w_sizeid ) : [src] Size ID
52 ----------------------------------------------------------------------*/
54 Drd64_Marshald_Cmd_Connect_Client(
56 Drd64_PacketHeader *p_phead,
57 Drd64_PacketData_Connect *p_connect )
59 Drd64_Marshald_ConnectInfo *p_cinfo;
61 DRD64_LOG_DEBUG(" [DEBUG] CMD: Connect(Client) Start");
63 p_cinfo = Drd64_Marshald_CInfo_GetConnectInfo(
64 p_connect->i_client_cinfo_id );
65 assert( NULL != p_cinfo );
67 p_cinfo->i_dest_cinfo_id = p_connect->i_connect_id;
70 DRD64_LOG_DEBUG(" [DEBUG] CMD: Connect(Client) Ended");
72 return DRD64_MARSHALD_DISPATCH_RESULT_RESTART;
76 /*----------------------------------------------------------------------
77 ----------------------------------------------------------------------*/
79 Drd64_Marshald_Cmd_Connect_Server(
81 Drd64_PacketHeader *p_phead,
82 Drd64_PacketData_Connect *p_connect )
89 Drd64_Marshald_ConnectInfo *p_cinfo;
90 Drd64_Server_RecvStatus *p_recv;
92 DRD64_LOG_DEBUG(" [DEBUG] CMD: Connect(Server) Start");
94 i_result = DRD64_MARSHALD_DISPATCH_RESULT_COMPLETE;
95 dw_errcode = DRD64_ERROR_CODE_CLEAR;
96 dw_errlocation = DRD64_ERROR_SET_LOCATION(
97 DRD64_ERROR_MODULE_MARSHALD,
98 DRD64_ERROR_ARCH_NODEPEND,
99 DRD64_SRCID_MARSHALD_CMD_CONNECT,
100 DRD64_FUNCID_Marshald_Cmd_Connect_Server );
102 p_recv = Drd64_Server_RecvStatus_GetRecvStatus( i_recv_id );
103 assert( NULL != p_recv );
104 i_fds = p_recv->i_fds_id;
106 /* Alloc ConnectInfo. */
107 p_cinfo = Drd64_Marshald_CInfo_AllocConnectInfo();
108 if( NULL == p_cinfo ) {
109 dw_errcode = DRD64_ERROR_SET_CODE(
110 DRD64_ERROR_TYPE_ERROR,
111 DRD64_ERROR_PTN_NOMEMORY,
113 //Drd64_LibBrownie_Error_SetErrorInfo( dw_errcode, dw_errlocation, errno );
115 i_result = DRD64_MARSHALD_DISPATCH_RESULT_CLOSE;
117 goto goto_Marshald_Cmd_Connect_Server_Answer;
120 /* Set Cinfo Common Info. ---*/
121 p_cinfo->b_cinfo_type = DRD64_MARSHALD_CINFOTYPE_SERVER;
122 p_cinfo->i_cinfo_refcount = 1;
124 /* p_cinfo->t_dest_addr_inet = NONE */
125 p_cinfo->i_dest_cinfo_id = -1;
126 p_cinfo->i_dest_socket = -1;
127 p_cinfo->str_dest_addr_local[0] = '\0';
129 Drd64_LibBrownie_INetAddr_CopyInAddr(
130 &(p_cinfo->t_src_addr_inet),
131 &(p_connect->t_client_addr_inet) );
132 p_cinfo->i_src_cinfo_id = p_connect->i_client_cinfo_id;
133 p_cinfo->i_src_socket = i_fds;
135 /* p_cinfo->t_src_addr_inet = NONE */
136 p_cinfo->i_prog_pid = -1;
138 p_cinfo->i_debugd_pid = -1;
139 p_cinfo->i_debugd_socket = -1;
141 Drd64_LibBrownie_INetAddr_CopyInAddr(
142 &(p_cinfo->t_client_addr_inet),
143 &(p_connect->t_client_addr_inet) );
144 p_cinfo->i_client_socket = i_fds;
145 p_cinfo->i_client_pid = p_connect->i_client_pid;
148 Drd64_Server_RecvStatus_SetConnectionInfoPointer(
149 p_recv, (void *)p_cinfo );
151 p_connect->i_connect_id = p_cinfo->i_cinfo_id;
152 p_connect->i_marshald_pid = getpid();
154 /* Set Answer Data ---------*/
155 goto_Marshald_Cmd_Connect_Server_Answer:
156 p_phead->dw_errcode = dw_errcode;
157 p_phead->dw_errlocation = dw_errlocation;
158 p_phead->w_packettype |= DRD64_PACKETTYPE_FLAG_ANSWER;
160 i_wlen = send( i_fds, (void *)p_phead, DRD64_PacketSize(p_phead), 0x00 );
161 DRD64_DEBUG_PRINT("send",i_wlen,"Socket",i_fds,"errno",errno);
162 if( i_wlen != DRD64_PacketSize(p_phead) ) {
163 dw_errcode = DRD64_ERROR_SET_CODE(
164 DRD64_ERROR_TYPE_ERROR,
165 DRD64_ERROR_PTN_SOCKET,
167 //Drd64_LibBrownie_Error_SetErrorInfo( dw_errcode, dw_errlocation, errno );
169 i_result = DRD64_MARSHALD_DISPATCH_RESULT_CLOSE;
172 DRD64_LOG_DEBUG(" [DEBUG] CMD: Connect(Server) Complete ");
178 /*----------------------------------------------------------------------
179 Drd64_Marshald_Cmd_Connect(
180 ----------------------------------------------------------------------*/
182 Drd64_Marshald_Cmd_Connect(
184 Drd64_PacketHeader *p_phead,
185 Drd64_PacketData_Connect *p_connect )
189 DRD64_LOG_VERBOSE("[STAT]CMD: Connect Start");
191 if( DRD64_IsPacketType_Answer( p_phead ) ) {
192 i_result = Drd64_Marshald_Cmd_Connect_Client(
193 i_recv_id, p_phead, p_connect );
197 i_result = Drd64_Marshald_Cmd_Connect_Server(
198 i_recv_id, p_phead, p_connect );
201 DRD64_LOG_VERBOSE("[STAT]CMD: Connect Ended");
207 /* EOF of drd64_.c ----------------------------------- */