/* Emit an instruction to the assembly program. */
void emit(context* ctx, assembly* casm,
		  int op, operand* op1, operand* op2, operand* opdest)
{
	int nextslot = casm->nextslot;
	operand o = {0};			/* a dummy operand for padding */
#ifdef ZEN_ENABLE_OPTIMIZATION
	/* a simple optimizing trick */
	if (op==opLD && nextslot &&
		casm->instructions[nextslot-1].op==opST &&
		casm->instructions[nextslot-1].op1.ival==op1->ival &&
		casm->instructions[nextslot-1].op2.ival==op2->ival &&
		casm->instructions[nextslot-1].opdest.ival==opdest->ival &&
		!(ctx->inleader&&ctx->insord==0))	/* can't be a leader's first ins */
		return;
#endif
	if (nextslot >= casm->size)	/* buffer is full, reallocate */
	{
		casm->size = casm->size*2+1;
		if ((casm->instructions =
			realloc(casm->instructions, casm->size*sizeof(instruction))) == NULL)
			setlasterror(ctx, ZEN_OUT_OF_MEMORY, "Not enough memory.\n");
	}
	casm->instructions[nextslot].op = op;
	casm->instructions[nextslot].op1 = (op1!=NULL?*op1:o);
	casm->instructions[nextslot].op2 = (op2!=NULL?*op2:o);
	casm->instructions[nextslot].opdest = (opdest!=NULL?*opdest:o);
	casm->nextslot++;
	ctx->insord++;
}
Example #2
0
uintptr
runtime·syscall(void *fn, uintptr nargs, void *args, uintptr *err)
{
	G *oldlock;
	uintptr ret;

	/*
	 * Lock g to m to ensure we stay on the same stack if we do a callback.
	 */
	oldlock = m->lockedg;
	m->lockedg = g;
	g->lockedm = m;

	runtime·entersyscall();
	runtime·setlasterror(0);
	ret = (uintptr)runtime·stdcall_raw(fn, nargs, args);
	if(err)
		*err = runtime·getlasterror();
	runtime·exitsyscall();

	m->lockedg = oldlock;
	if(oldlock == nil)
		g->lockedm = nil;

	return ret;
}
//	===========================================================================
//	METHOD: authdclient::executecmd
//	===========================================================================
int authdclient::executecmd (const string &command)
{
	string 	result;
	bool   	success 	= false;


	s.puts (command);
	
	// Wait for result
	try
	{
		result = s.gets ();
	}
	catch (exception e)
	{
		syslog (LOG_ERR, "Error talking to authd: %s", e.description);
		result = e.description;
		setlasterror (result);
		return ERR_AUTHD_FAILURE;
	}
	
	// Get Results from string
	success 	= (result && result[0] == '+');
	
	if (! success)
	{
		string rawcmd;
		rawcmd = command;
		rawcmd.cropat (' ');
		
		syslog (LOG_ERR, "Error on command <%s>: %s", rawcmd.str(),
				result.str());
		setlasterror (result);
		
		return ERR_AUTHD_FAILURE;
	}
	
	return ERR_OK;
}