static ObjectDesc *cpuManager_getCAS(ObjectDesc * self, ObjectDesc * classNameObj, ObjectDesc * fieldNameObj)
{
    CASProxy *p;
    char value[128];
    ClassDesc *c;
    u32 o;
    int i;

    /* TODO: check access permissions to class and field ! */
    if (classNameObj == NULL || fieldNameObj == NULL)
        exceptionHandlerInternal("classname or fieldname == null");

    stringToChar(classNameObj, value, sizeof(value));
    for (i = 0; i < strlen(value); i++) {
        if (value[i] == '.')
            value[i] = '/';
    }
    c = findClassDesc(value);
    if (c == NULL)
        exceptionHandlerInternal("no such class");
    stringToChar(fieldNameObj, value, sizeof(value));
    o = findFieldOffset(c, value);
    if (o == -1)
        exceptionHandlerInternal("no such field");
    p = allocCASProxyInDomain(curdom(), casClass, o);
    return (ObjectDesc *) p;
}
jint cpuManager_dump(ObjectDesc * self, ObjectDesc * msg, ObjectDesc * ref)
{
    char c[128];
    ClassDesc *cl;
    c[0] = '\0';
    if (msg != NULL)
        stringToChar(msg, c, sizeof(c));
    if (ref == NULL)
        return -1;
    if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_MEMORY) {
        printk(KERN_INFO "   MEMORY\n");
    } else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_PORTAL) {
        printk(KERN_INFO "   PORTAL: index=%d\n", ((Proxy *) ref)->index);
    } else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_OBJECT) {
        cl = obj2ClassDesc(ref);
        printk(KERN_INFO "     INSTANCE of class: %s\n", cl->name);
    } else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_CAS) {
        printk(KERN_INFO "     CAS\n");
    } else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_SERVICE) {
        DEPDesc *s = (DEPDesc *) ref;
        printk(KERN_INFO "     Service: interface=%s\n", s->interface->name);
    } else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_SERVICE_POOL) {
        printk(KERN_INFO "     Servicepool\n");
    } else {
        printk(KERN_INFO "     unknown object type. flags=(%p)\n", (void *) getObjFlags(ref));
    }
    return 0;
}
ObjectDesc *cpuManager_getClass(ObjectDesc * self, ObjectDesc * nameObj)
{
	char name[128];
	Class *cl;
	int i;
	ObjectDesc *vmclassObj;
	if (nameObj == NULL)
		return NULL;
	stringToChar(nameObj, name, sizeof(name));
	for (i = 0; i < strlen(name); i++) {
		if (name[i] == '.')
			name[i] = '/';
	}
	cl = findClass(curdom(), name);
	if (cl == NULL)
		return NULL;
	vmclassObj = class2Obj(cl);
#ifdef DEBUG
	{
		u4_t flags;
		flags = getObjFlags(vmclassObj) & FLAGS_MASK;
		ASSERT(flags == OBJFLAGS_EXTERNAL_CLASS);
		printf("getClass %s -> %p\n", name, vmclassObj);
	}
#endif
	return vmclassObj;
}
Exemple #4
0
static Something systemGetEnv(Thread *thread){
    char* variableName = stringToChar(stackGetVariable(0, thread).object->value);
    char* env = getenv(variableName);
    
    if(!env)
        return NOTHINGNESS;
    
    free(variableName);
    return somethingObject(stringFromChar(env));
}
void debugsupport_sendBinary(ObjectDesc * self, ObjectDesc * name, struct MemoryProxy_s *data, jint size)
{
#if (defined(DEBUGSUPPORT_DUMP) || defined(MONITOR)) && defined(KERNEL)
	char value[128];
	if (name == 0 || data == 0)
		return;
	stringToChar(name, value, sizeof(value));
	ASSERT(size <= memory_size(data));
	send_binary(value, memory_getMem(data), size);
#endif
}
void cpuManager_setThreadName(ObjectDesc * self, ObjectDesc * name)
{
	char value[128];
	if (name == NULL)
		return;
	stringToChar(name, value, sizeof(value));

	DISABLE_IRQ;
	setThreadName(curthr(), value, "");
	RESTORE_IRQ;
}
Exemple #7
0
char* Utility::buildJson(std::vector<HttpRequestParameter> values){
	string result="{";
	for (int i = 0; i < values.size(); i++){
		result += "\"" + values[i].name + "\"";
		result += ":";
		result += "\"" + values[i].data + "\"";
		if (i != values.size() - 1)
			result += ",";
	}
	result += "}";
	return stringToChar(result);
}
jint cpuManager_createNewEvent(ObjectDesc * self, ObjectDesc * label)
{
#ifdef EVENT_LOG
	if (n_event_types == MAX_EVENT_TYPES)
		return -1;
	stringToChar(label, eventTypes[n_event_types],
		     /*MAX_EVENT_TYPE_SIZE */
		     sizeof(eventTypes[n_event_types]));
	return n_event_types++;
#else
	return -1;
#endif
}
Exemple #9
0
void socketInitWithHost(Thread *thread) {
    char *string = stringToChar(stackGetVariable(0, thread).object->value);
    char *service = stringToChar(stackGetVariable(1, thread).object->value);
    
    struct addrinfo *res;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    if (getaddrinfo(string, service, &hints, &res) == -1) {
        stackGetThisObject(thread)->value = NULL;
        return;
    }
    free(string);
    free(service);
    int socketDescriptor = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (socketDescriptor == -1 || connect(socketDescriptor, res->ai_addr, res->ai_addrlen) == -1) {
        freeaddrinfo(res);
        stackGetThisObject(thread)->value = NULL;
        return;
    }
    freeaddrinfo(res);
    *(int *)stackGetThisObject(thread)->value = socketDescriptor;
}
Exemple #10
0
std::vector<string> Utility::splitString(std::string string, std::string  delim){

	char* str = stringToChar(string);

	char * pch;
	const char* tmp = delim.c_str();
	std::vector<std::string> result;
	//strcpy(str, string.c_str());
	//std::strcpy(str, string.c_str());
		
	pch = strtok(str, tmp);
	while (pch != NULL)
	{
		result.push_back(pch);
		pch = strtok(NULL, tmp);
	}
	return result;
}
static ObjectDesc *cpuManager_getClass(ObjectDesc * self, ObjectDesc * nameObj)
{
    char name[128];
    JClass *cl;
    int i;
    ObjectDesc *vmclassObj;
    if (nameObj == NULL)
        return NULL;
    stringToChar(nameObj, name, sizeof(name));
    for (i = 0; i < strlen(name); i++) {
        if (name[i] == '.')
            name[i] = '/';
    }
    cl = findClass(curdom(), name);
    if (cl == NULL)
        return NULL;
    vmclassObj = class2Obj(cl);
    return vmclassObj;
}
Exemple #12
0
static Something systemSystem(Thread *thread) {
    char *command = stringToChar(stackGetVariable(0, thread).object->value);
    FILE *f = popen(command, "r");
    free(command);
    
    if (!f) {
        return NOTHINGNESS;
    }
    
    size_t bufferUsedSize = 0;
    int bufferSize = 50;
    Object *buffer = newArray(bufferSize);
    
    while (fgets((char *)buffer->value + bufferUsedSize, bufferSize - (int)bufferUsedSize, f) != NULL) {
        bufferUsedSize = strlen(buffer->value);
        
        if (bufferSize - bufferUsedSize < 2) {
            bufferSize *= 2;
            buffer = resizeArray(buffer, bufferSize);
        }
    }
    
    bufferUsedSize = strlen(buffer->value);
    
    EmojicodeInteger len = u8_strlen_l(buffer->value, bufferUsedSize);
    
    Object *so = newObject(CL_STRING);
    stackSetVariable(0, somethingObject(so), thread);
    String *string = so->value;
    string->length = len;
    
    Object *chars = newArray(len * sizeof(EmojicodeChar));
    string = stackGetVariable(0, thread).object->value;
    string->characters = chars;
    
    u8_toucs(characters(string), len, buffer->value, bufferUsedSize);
    
    return stackGetVariable(0, thread);
}
void debugsupport_registerMonitorCommand(ObjectDesc * self, ObjectDesc * name, ObjectDesc * cmd)
{
#if defined(MONITOR)
#if defined(JAVA_MONITOR_COMMANDS)
	char value[128];
	Proxy *proxy;
	u4_t quota = 1000;
	DomainDesc *domain = CALLERDOMAIN;
	if (name == 0 || cmd == 0)
		return;
	stringToChar(name, value, sizeof(value));

	DISABLE_IRQ;
#ifdef COPY_TO_DOMAINZERO
	proxy = cmd;
#else
	proxy = copy_reference(domain, curdom(), cmd, &quota);
#endif
	RESTORE_IRQ;

	register_command(value, registerObject(curdom(), proxy), domain);
#endif
#endif				/* MONITOR */
}
Exemple #14
0
/*
 * Get Letter
 *
 * Retruns the character in the Boggle board at the
 * given row and col
 */
char Boggle::getLetter(int row, int col) {
    return stringToChar(board[row][col]);   // remove this
}
Exemple #15
0
void newErrorBridge(Thread *thread){
    EmojicodeError *error = stackGetThisObject(thread)->value;
    error->message = stringToChar(stackGetVariable(0, thread).object->value);
    error->code = unwrapInteger(stackGetVariable(1, thread));
}
jint cpuManager_dump(ObjectDesc * self, ObjectDesc * msg, ObjectDesc * ref)
{
	char c[128];
	int i = 0;
	ClassDesc *cl;
	c[0] = '\0';
	if (msg != NULL)
		stringToChar(msg, c, sizeof(c));
	//printStackTraceNew("DUMP");
	printf("DUMP %s 0x%lx ", c, ref);
	if (ref == NULL)
		return;
	if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_MEMORY) {
#if 0
		MemoryProxy *m = (MemoryProxy *) ref;
		printf("   MEMORY: dz=%p mem=%p size=%d valid=%d refcount=%d\n", m->dz, m->mem, m->size, m->dz->valid,
		       m->dz->refcount);
#ifdef DEBUG_MEMORY_CREATION
		if (m->dz->createdBy) {
			printf("     created at : ");
			print_eip_info(m->dz->createdAt);
			printf(", by: %s ", m->dz->createdBy->domainName);
			if (m->dz->createdUsing)
				printf(" using %s", m->dz->createdUsing);
#endif
		} else {
			printf(", unknown creator");
		}
		printf("\n");
		{
#if 0
			DZMemoryProxy *dz;
			printf("--\n");
			dz = m->dz;
			while (dz->prev) {
				printf("  PREV %p owner=%d size=%d valid=%d\n", dz->prev, dz->prevOwner, dz->prev->size,
				       dz->prev->valid);
				dz = dz->prev;
				if (i++ > 20)
					sys_panic("POSSIBLE CIRCULARITY IN MEMORY CHAIN");
			}
			dz = m->dz;
			while (dz->next) {
				printf("  NEXT %p owner=%d size=%d valid=%d\n", dz->next, dz->nextOwner, dz->next->size,
				       dz->next->valid);
				dz = dz->next;
			}
		}
#endif

#endif				/* DEBUG_MEMORY_CREATION */
		{
			int i;
			ClassDesc *cd = obj2ClassDesc(ref);
			ASSERTCLASSDESC(cd);
			/*
			   printf("vtable: \n");
			   for(i=0; i<cd->vtableSize; i++) {
			   if (cd->vtable[i] != NULL) printf("%d %p\n", i, cd->vtable[i]);
			   }
			 */
		}
	} else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_PORTAL) {
		printf("   PORTAL: index=%d\n", ((Proxy *) ref)->index);
		//dumpVTable(ref, cl->vtableSize);
	} else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_OBJECT) {
		cl = obj2ClassDesc(ref);
		printf("     INSTANCE of class: %s\n", cl->name);
	} else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_CAS) {
		printf("     CAS\n");
	} else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_SERVICE) {
		DEPDesc *s = (DEPDesc *) ref;
		printf("     Service: interface=%s\n", s->interface->name);
	} else if ((getObjFlags(ref) & FLAGS_MASK) == OBJFLAGS_SERVICE_POOL) {
		printf("     Servicepool\n");
#if 0
	} else if (getObjFlags(ref) == OBJFLAGS_EXTERNAL_CPUSTATE) {
		printf("     CPUSTATE thread %d.%d\n", TID(cpuState2thread(ref)));
		//printStackTraceNew("CPUSTATE");
#endif
	} else {
		printf("     unknown object type. flags=(%p)\n", getObjFlags(ref));
	}
	return 0;
}