Exemple #1
0
/*
 * Return number of deserialized sequence information
 */
size_t
gtm_deserialize_sequence(GTM_SeqInfo *seq, const char *buf, size_t buflen)
{
	size_t len = 0;

	seq->gs_key = (GTM_SequenceKeyData *)genAlloc0(sizeof(GTM_SequenceKeyData));

	memcpy(&seq->gs_key->gsk_keylen, buf + len, sizeof(uint32));
	len += sizeof(uint32);/* gs_key.gsk_keylen */

	seq->gs_key->gsk_key = (char *)genAlloc0(seq->gs_key->gsk_keylen+1);
	memcpy(seq->gs_key->gsk_key, buf + len, seq->gs_key->gsk_keylen);
	len += seq->gs_key->gsk_keylen;/* gs_key.gsk_key */

	memcpy(&seq->gs_key->gsk_type, buf + len, sizeof(GTM_SequenceKeyType));
	len += sizeof(GTM_SequenceKeyType);   /* gs_key.gsk_type */

	memcpy(&seq->gs_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_value */

	memcpy(&seq->gs_init_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_init_value */

	memcpy(&seq->gs_max_lastvals, buf + len, sizeof(uint32));
	len += sizeof(uint32);		  /* gs_max_lastvals */
	if (seq->gs_max_lastvals > 0)
		seq->gs_last_values = (GTM_SeqLastVal *)
				genAlloc(seq->gs_max_lastvals * sizeof(GTM_SeqLastVal));
	memcpy(&seq->gs_lastval_count, buf + len, sizeof(uint32));
	len += sizeof(uint32);		  /* gs_lastval_count */
	if (seq->gs_lastval_count > 0)
	{
		memcpy(seq->gs_last_values, buf + len,
				seq->gs_lastval_count * sizeof(GTM_SeqLastVal));
		len += seq->gs_lastval_count * sizeof(GTM_SeqLastVal); /* gs_last_values */
	}

	memcpy(&seq->gs_increment_by, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_increment_by */

	memcpy(&seq->gs_min_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_min_value */

	memcpy(&seq->gs_max_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_max_value */

	memcpy(&seq->gs_cycle, buf + len, sizeof(bool));
	len += sizeof(bool);  /* gs_cycle */

	memcpy(&seq->gs_called, buf + len, sizeof(bool));
	len += sizeof(bool);  /* gs_called */

	memcpy(&seq->gs_ref_count, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	memcpy(&seq->gs_state, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	return len;
}
void PrologEpilogGenerator::genCode() {

    containCall = opndManager->getContainCall();

    saveRestoreRp();              // affects: mem stack, reg stack  use: 
    saveRestorePr();              // affects: mem stack, reg stack  use: 
    genAlloc();                   // affects: mem stack, reg stack  use: reg stack
    saveRestoreUnat();            // affects: mem stack             use: 
    saveRestorePreservedGr();     // affects: mem stack             use: 
    saveRestorePreservedFr();     // affects: mem stack             use:
    saveRestorePreservedBr();     // affects: mem stack             use: 
    saveRestoreSp();              // affects:                       use: mem stack

    prologInsts.splice(prologInsts.end(), allocInsts);
    prologInsts.splice(prologInsts.end(), saveSpInsts);
    prologInsts.splice(prologInsts.end(), savePfsInsts);
    prologInsts.splice(prologInsts.end(), saveUnatInsts);
    prologInsts.splice(prologInsts.end(), saveGrsInsts);
    prologInsts.splice(prologInsts.end(), saveFrsInsts);
    prologInsts.splice(prologInsts.end(), saveBrsInsts);
    prologInsts.splice(prologInsts.end(), savePrsInsts);
    prologInsts.splice(prologInsts.end(), saveRpInsts);

    epilogInsts.splice(epilogInsts.end(), restRpInsts);
    epilogInsts.splice(epilogInsts.end(), restPrsInsts);
    epilogInsts.splice(epilogInsts.end(), restBrsInsts);
    epilogInsts.splice(epilogInsts.end(), restFrsInsts);
    epilogInsts.splice(epilogInsts.end(), restGrsInsts);
    epilogInsts.splice(epilogInsts.end(), restUnatInsts);
    epilogInsts.splice(epilogInsts.end(), restPfsInsts);
    epilogInsts.splice(epilogInsts.end(), restSpInsts);

    // Print Prolog and Epilog insts
    IPF_LOG << "    Prolog:" << endl << IrPrinter::toString(prologInsts);
    IPF_LOG << "    Epilog:" << endl << IrPrinter::toString(epilogInsts) << endl;

    // Insert prolog instructions in begining of enter node
    BbNode     *enterNode  = (BbNode *)cfg.getEnterNode();
    InstVector &enterInsts = enterNode->getInsts();
    enterInsts.insert(enterInsts.begin(), prologInsts.begin(), prologInsts.end());

    // Insert epilog instructions in each epilog node (all nodes which end with "br.ret")
    for(uint16 i=0; i<epilogNodes.size(); i++) {
        InstVector &exitInsts = ((BbNode *)epilogNodes[i])->getInsts();
        exitInsts.insert(exitInsts.end()-1, epilogInsts.begin(), epilogInsts.end());
    }
}
Exemple #3
0
/* -----------------------------------------------------
 * Deserialize a GTM_SnapshotData structure
 * -----------------------------------------------------
 */
size_t
gtm_deserialize_snapshotdata(GTM_SnapshotData *data, const char *buf, size_t buflen)
{
	size_t len = 0;

	/* GTM_SnapshotData.sn_xmin */
	memcpy(&(data->sn_xmin), buf + len, sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_SnapshotData.sn_xmax */
	memcpy(&(data->sn_xmax), buf + len, sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_SnapshotData.sn_recent_global_xmin */
	memcpy(&(data->sn_recent_global_xmin), buf + len, sizeof(GlobalTransactionId));
	len += sizeof(GlobalTransactionId);

	/* GTM_SnapshotData.sn_xcnt */
	memcpy(&(data->sn_xcnt), buf + len, sizeof(uint32));
	len += sizeof(uint32);

	/* GTM_SnapshotData.sn_xip */
	if (data->sn_xcnt > 0)
	{
		/*
		 * Please note that this function runs with TopMemoryContext.  So we must
		 * free this area manually later.
		 */
		data->sn_xip = genAlloc(sizeof(GlobalTransactionId) * data->sn_xcnt);
		memcpy(data->sn_xip, buf + len, sizeof(GlobalTransactionId) * data->sn_xcnt);
		len += sizeof(GlobalTransactionId) * data->sn_xcnt;
	}
	else
	{
		data->sn_xip = NULL;
	}

	return len;
}
Exemple #4
0
size_t
gtm_deserialize_pgxcnodeinfo(GTM_PGXCNodeInfo *data, const char *buf, size_t buflen)
#endif
{
	size_t len = 0;
	uint32 len_wk;

	/* GTM_PGXCNodeInfo.type */
#ifdef XCP
	if (len + sizeof(GTM_PGXCNodeType) > buflen)
	{
		printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of node info. buflen = %d", (int) buflen);
		return (size_t) 0;
	}
#endif
	memcpy(&(data->type), buf + len, sizeof(GTM_PGXCNodeType));
	len += sizeof(GTM_PGXCNodeType);

	/* GTM_PGXCNodeInfo.nodename*/
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	if (len_wk == 0)
	{
		data->nodename = NULL;
	}
	else
	{
#ifdef XCP
		if (len + len_wk > buflen)
		{
			printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of node name");
			return (size_t) 0;
		}
#endif

		/* PGXCTODO: free memory */
		data->nodename = (char *)genAlloc(len_wk + 1);
		memcpy(data->nodename, buf + len, (size_t)len_wk);
		data->nodename[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}


	/* GTM_PGXCNodeInfo.proxyname*/
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->proxyname = NULL;
	}
	else
	{
#ifdef XCP
		if (len + len_wk > buflen)
		{
			printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of node info after proxy name");
			return (size_t) 0;
		}
#endif
		/* PGXCTODO: free memory */
		data->proxyname = (char *)genAlloc(len_wk + 1);
		memcpy(data->proxyname, buf + len, (size_t)len_wk);
		data->proxyname[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.port */
#ifdef XCP
	if (len + sizeof(GTM_PGXCNodePort) > buflen)
	{
		printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of node port");
		return (size_t) 0;
	}
#endif
	memcpy(&(data->port), buf + len, sizeof(GTM_PGXCNodePort));
	len += sizeof(GTM_PGXCNodePort);

	/* GTM_PGXCNodeInfo.ipaddress */
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->ipaddress = NULL;
	}
	else
	{
#ifdef XCP
		if (len + len_wk > buflen)
		{
			printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of ipaddress");
			return (size_t) 0;
		}
#endif
		data->ipaddress = (char *)genAlloc(len_wk + 1);
		memcpy(data->ipaddress, buf + len, (size_t)len_wk);
		data->ipaddress[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.datafolder */
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->datafolder = NULL;
	}
	else
	{
#ifdef XCP
		if (len + len_wk > buflen)
		{
			printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of node info after data folder");
			return (size_t) 0;
		}
#endif
		data->datafolder = (char *)genAlloc(len_wk + 1);
		memcpy(data->datafolder, buf + len, (size_t)len_wk);
		data->datafolder[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.status */
#ifdef XCP
	if (len + sizeof(GTM_PGXCNodeStatus) > buflen)
	{
		printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of node info after status");
		return (size_t) 0;
	}
#endif
	memcpy(&(data->status), buf + len, sizeof(GTM_PGXCNodeStatus));
	len += sizeof(GTM_PGXCNodeStatus);

#ifdef XCP
	/* GTM_PGXCNodeInfo.sessions */
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	data->max_sessions = len_wk;
	if (len_wk > 0)
		data->sessions = (GTM_PGXCSession *)
				genAlloc(len_wk * sizeof(GTM_PGXCSession));
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	data->num_sessions = len_wk;
	if (len_wk > 0)
	{
		if (len + (data->num_sessions * sizeof(GTM_PGXCSession)) > buflen)
		{
			printfGTMPQExpBuffer(errorbuf, "Buffer length error in deserialization of session info");
			return (size_t) 0;
		}
		memcpy(data->sessions, buf + len, len_wk * sizeof(GTM_PGXCSession));
		len += len_wk * sizeof(GTM_PGXCSession);
	}
#endif

	/* NOTE: nothing to be done for node_lock */

	return len;
}
/*
 * Return a deserialize number of PGXC node information
 */
size_t
gtm_deserialize_pgxcnodeinfo(GTM_PGXCNodeInfo *data, const char *buf, size_t buflen)
{
	size_t len = 0;
	uint32 len_wk;

	/* GTM_PGXCNodeInfo.type */
	memcpy(&(data->type), buf + len, sizeof(GTM_PGXCNodeType));
	len += sizeof(GTM_PGXCNodeType);

	/* GTM_PGXCNodeInfo.nodename*/
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->nodename = NULL;
	}
	else
	{
		/* PGXCTODO: free memory */
		data->nodename = (char *)genAlloc(len_wk + 1);
		memcpy(data->nodename, buf + len, (size_t)len_wk);
		data->nodename[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.proxyname*/
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->proxyname = NULL;
	}
	else
	{
		/* PGXCTODO: free memory */
		data->proxyname = (char *)genAlloc(len_wk + 1);
		memcpy(data->proxyname, buf + len, (size_t)len_wk);
		data->proxyname[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.port */
	memcpy(&(data->port), buf + len, sizeof(GTM_PGXCNodePort));
	len += sizeof(GTM_PGXCNodePort);

	/* GTM_PGXCNodeInfo.ipaddress */
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->ipaddress = NULL;
	}
	else
	{
		data->ipaddress = (char *)genAlloc(len_wk + 1);
		memcpy(data->ipaddress, buf + len, (size_t)len_wk);
		data->ipaddress[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.datafolder */
	memcpy(&len_wk, buf + len, sizeof(uint32));
	len += sizeof(uint32);
	if (len_wk == 0)
	{
		data->datafolder = NULL;
	}
	else
	{
		data->datafolder = (char *)genAlloc(len_wk + 1);
		memcpy(data->datafolder, buf + len, (size_t)len_wk);
		data->datafolder[len_wk] = 0;	/* null_terminate */
		len += len_wk;
	}

	/* GTM_PGXCNodeInfo.status */
	memcpy(&(data->status), buf + len, sizeof(GTM_PGXCNodeStatus));
	len += sizeof(GTM_PGXCNodeStatus);

	/* NOTE: nothing to be done for node_lock */

	return len;
}