Exemplo n.º 1
0
char *resolve_name(int serviceid)
{
	struct directory_resolvename res_cmd;
	struct directory_response dir_res;
	char *service_name = "";
	int id_proc;

	res_cmd.command = DIRECTORY_RESOLVENAME;
	res_cmd.serviceid = serviceid;
 	res_cmd.ret_port = dirlib_port;
	res_cmd.thr_id = get_current_thread();
	// we will send an smo with size 1 first
	// servicename will not fit and directory will return
	// an error spacifying dir name size.
	res_cmd.name_smo = share_mem(DIRECTORY_TASK, service_name, 1, WRITE_PERM); 
	
	send_msg(DIRECTORY_TASK, DIRECTORY_PORT, &res_cmd);
  
	while (get_msg_count(dirlib_port) == 0) { reschedule(); }

	get_msg(dirlib_port, &dir_res, &id_proc);

	claim_mem(res_cmd.name_smo);	

	if(dir_res.ret == DIRECTORYERR_SMO_TOOSMALL)
	{
		// now malloc for servicename
		service_name = (char *)malloc(dir_res.ret_value + 1);

		res_cmd.name_smo = share_mem(DIRECTORY_TASK, service_name, len(service_name) + 1, WRITE_PERM); 

		send_msg(DIRECTORY_TASK, DIRECTORY_PORT, &res_cmd);
  
		while (get_msg_count(dirlib_port) == 0) { reschedule(); }

		get_msg(dirlib_port, &dir_res, &id_proc);

		claim_mem(res_cmd.name_smo);	

		if(dir_res.ret != DIRECTORYERR_OK) 
		{
			free(service_name);
			return NULL; // fail
		}

		return service_name;
	}
	else
	{
		return NULL; // fail
	}
}
// is the instruction a candidate to be shared?
bool BipartiteWeightedMatchingBinding::isInstructionSharable(Instruction *I,
        Allocation *alloc) {

    return (share_div(I) ||
            share_rem(I) ||
            share_mem(I) ||
            is_floating_point(I) ||
            share_dsp(I, alloc));
}
Exemplo n.º 3
0
int main()
{
    ShareMem share_mem(12345, 10000000);  
    ShareHashSet<Obj, HashFunctor> share_set(share_mem, 100000);

    share_set.insert("11111");
    share_set.insert("22222");
    share_set.insert("33333");
    share_set.insert("33333");
    share_set.erase("11111");
    share_set.insert("11111");
    share_set.insert("33333");
    share_set.insert("22222");
    share_set.insert("33333");
    share_set.erase("33333");
    share_set.erase("22222");

    /*
    pid_t child_pid = fork();    
    if(child_pid)
    {
        share_set.insert("4444444");
        sleep(10);
    }
    */
    {
        share_set.insert("11111");
        share_set.insert("33333");
        share_set.insert("22222");

        sleep(1);
        uint64_t idx = 0;
        Obj *obj = new Obj();
        while(true)
        {
            if(share_set.get_next(idx, *obj))
                printf("%lu %p %s\n", idx, obj, obj->buf);
            else
                break;
        }
    }

    return 0;
}
Exemplo n.º 4
0
void show_partition_list(int term)
{
	/* Use IOCTRL command ATAC_IOCTRL_ENUMDEVS :D */	
	struct atac_enum_dev_param params;
	struct atac_ioctl_enumdevs cmd;
	struct stddev_ioctrl_res res;
	int taskid;
	struct fdisk_dev *dev = NULL;

    term_color_print(term, "\nListing Partitions...  ", 7);
	params.continuation = 0;

	cmd.command = STDDEV_IOCTL;
	cmd.request = ATAC_IOCTRL_ENUMDEVS;
	cmd.enum_dev_smo = share_mem(aid, &params, sizeof(struct atac_enum_dev_param), READ_PERM | WRITE_PERM);
	cmd.msg_id = 0;
	cmd.ret_port = SHELL_INITRET_PORT;
    
    params.devinf.size = 0;
    params.devinf.id = -1; 

	do
	{
		send_msg(aid, stddevport, &cmd);

		while(get_msg_count(SHELL_INITRET_PORT) == 0){ reschedule(); }

		get_msg(SHELL_INITRET_PORT, &res, &taskid);
		if(res.ret != STDDEV_ERR)
		{
            if(params.devinf.id & STDDEV_PHDEV_FLAG)
				term_color_printf(term, "\n-> P ldevid=%x, size=%i sec, metaend %i ",7, params.devinf.id, params.devinf.size, params.devinf.metadata_end);
			else
				term_color_printf(term, "\n  +- phyid=%i, ldevid=%i, slba=%i, size=%i sec, type=%x, metaend %i ", 7, params.devinf.pid, params.devinf.id, params.devinf.start_lba, params.devinf.size, params.devinf.ptype, params.devinf.metadata_end);
		}
	}while(res.ret != STDDEV_ERR);

	claim_mem(cmd.enum_dev_smo);
}
Exemplo n.º 5
0
int dir_resolveid(char *service_name)
{
	struct directory_resolveid res_cmd;
	struct directory_response dir_res;
	int id_proc;

	res_cmd.command = DIRECTORY_RESOLVEID;
 	res_cmd.ret_port = dirlib_port;
	res_cmd.thr_id = get_current_thread();
	res_cmd.service_name_smo = share_mem(DIRECTORY_TASK, service_name, len(service_name) + 1, READ_PERM);
	
	send_msg(DIRECTORY_TASK, DIRECTORY_PORT, &res_cmd);
  
	while (get_msg_count(dirlib_port) == 0) { reschedule(); }

	get_msg(dirlib_port, &dir_res, &id_proc);

	claim_mem(res_cmd.service_name_smo);

	if(dir_res.ret != DIRECTORYERR_OK) return -1; // fail

	return dir_res.ret_value;
}
Exemplo n.º 6
0
/* Service entry point */
pipes_main()
{
    int id;
    struct stdservice_cmd service_cmd;
    struct stdservice_res servres;
    struct stdservice_res dieres;
    struct pipes_cmd pcmd;
    char *service_name = "fs/pipes";
    struct directory_register reg_cmd;
    struct directory_response dir_res;

    init_mem(malloc_buffer, 1024 * 30);
    avl_init(&pipes);

    // open ports with permisions for services only (lv 0, 1, 2) //
    open_port(1, 2, PRIV_LEVEL_ONLY);
    open_port(STDSERVICE_PORT, 2, PRIV_LEVEL_ONLY);
    open_port(PIPES_PORT, 2, PRIV_LEVEL_ONLY);

    _sti; // set interrupts

    // register with directory
    // register service with directory //
    reg_cmd.command = DIRECTORY_REGISTER_SERVICE;
    reg_cmd.ret_port = 1;
    reg_cmd.service_name_smo = share_mem(DIRECTORY_TASK, service_name, len(service_name) + 1, READ_PERM);

    while (send_msg(DIRECTORY_TASK, DIRECTORY_PORT, &reg_cmd) < 0)
    {
        reschedule();
    }

    while (get_msg_count(1) == 0) {
        reschedule();
    }

    get_msg(1, &dir_res, &id);

    close_port(1);

    claim_mem(reg_cmd.service_name_smo);

    for(;;)
    {
        while(get_msg_count(PIPES_PORT) == 0 && get_msg_count(STDSERVICE_PORT) == 0)
        {
            reschedule();
        }

        // process incoming STDSERVICE messages
        int service_count = get_msg_count(STDSERVICE_PORT);

        while(service_count != 0)
        {
            get_msg(STDSERVICE_PORT, &service_cmd, &id);

            servres.ret = STDSERVICE_RESPONSE_OK;
            servres.command = service_cmd.command;

            if(service_cmd.command == STDSERVICE_DIE)
            {
                // FIXME: return failure to al pending commands and die
                dieres.ret = STDSERVICE_RESPONSE_OK;
                dieres.command = service_cmd.command;
                send_msg(id, service_cmd.ret_port, &dieres);
            }
            else if(service_cmd.command == STDSERVICE_QUERYINTERFACE)
            {
                process_query_interface((struct stdservice_query_interface *)&service_cmd, id);
                service_count--;
                continue;
            }
            send_msg(id, service_cmd.ret_port, &servres);
            service_count--;
        }

        // process incoming pipes messages
        int pipes_count = get_msg_count(PIPES_PORT);

        while(pipes_count != 0)
        {
            get_msg(PIPES_PORT, &pcmd, &id);
            process_pipes_cmd(&pcmd, id);
            pipes_count--;
        }
    }
}
Exemplo n.º 7
0
Arquivo: io.c Projeto: ahamid/sartoris
// initofs ["service name on directory"|device id] [logic device]
void init_ofs(int term, char **args, int argc)
{
	struct stdfss_init init_msg;	
	struct stdfss_res res;
	int id;
	int serviceid = 0;
	int logic_dev = 0;
	char path[4];
	struct directory_resolveid resolve_cmd;
	struct directory_response dir_res;
	int ofs_task = resolve_fs();	// function call from iolib
	
	if(!initialized)
	{
		if(argc == 0)
		{
			term_color_print(term, invalid_params, 12);
			term_color_print(term, "Usage: initofs <[Service name] | [Service id]> [logic device nr].\n", 7);
			return;
		}

		if(argc > 2 || (argc == 2 && !isnumeric(args[1])))
		{
			term_color_print(term, invalid_params, 12);
			term_color_print(term, "Usage: initofs <[Service name] | [Service id]> [logic device nr].\n", 7);
			return;
		}

		if(argc > 0 && !isnumeric(args[0]))
		{
			// resolve default fs service //
			resolve_cmd.command = DIRECTORY_RESOLVEID;
			resolve_cmd.ret_port = IOLIB_PORT;
			resolve_cmd.service_name_smo = share_mem(DIRECTORY_TASK, args[0], len(args[0]) + 1, READ_PERM);
					
			send_msg(DIRECTORY_TASK, DIRECTORY_PORT, &resolve_cmd);

			while (get_msg_count(IOLIB_PORT) == 0) { }

			get_msg(IOLIB_PORT, &dir_res, &id);

			claim_mem(resolve_cmd.service_name_smo);

			if(dir_res.ret != DIRECTORYERR_OK)
			{
				term_color_print(term, "\nInvalid service directory name.\n", 12);
				return;
			}
			term_color_print(term, "\nResolved service id.\n", 7);

			serviceid = dir_res.ret_value;
		}	
		else if(argc > 0)
		{
			serviceid = atoi(args[0]);
		}

		if(argc == 2)
		{
			logic_dev = atoi(args[1]);
		}

		term_color_print(term, "Initializing OFS Service... ", 7);

		path[0] = '/';
		path[1] = '\0';

	
		init_msg.command = STDFSS_INIT;
		init_msg.path_smo = share_mem(ofs_task, path, 2, READ_PERM);
		init_msg.ret_port = INITOFS_PORT;
		init_msg.deviceid = serviceid;
		init_msg.logic_deviceid = logic_dev;

		send_msg(ofs_task, STDFSS_PORT, &init_msg);

		while(get_msg_count(INITOFS_PORT) == 0){ reschedule(); } // wait for OFS response

		get_msg(INITOFS_PORT, &res, &id); 

		claim_mem(init_msg.path_smo);

		if(res.ret != STDFSSERR_OK)
		{
			term_color_print(term, " FAILED\n", 12);
			return;
		}

		term_color_print(term, " OK\n", 11);
	}
	else
	{
		term_color_print(term, "OFS Already initialized\n", 11);
	}
	
	initialized = 1;

}
Exemplo n.º 8
0
void atactst(int term, char **args, int argc)
{
    int storage_size = 0, id, i;
    	
	struct stddev_devtype_res devtype_res;
	struct stdservice_query_interface query_cmd;
	struct stdservice_query_res query_res;
	struct stddev_res stddevres;
	struct stddev_cmd stddevcmd;
	struct stdblockdev_read_cmd block_read;
	struct stdblockdev_res block_res;
	struct stddev_getdev_cmd getdev_cmd;

	term_color_print(term, "\nQuery Interface...  ", 7);

	// use stdservice query interface to get stddev port
	query_cmd.command = STDSERVICE_QUERYINTERFACE;
	query_cmd.uiid = STDDEV_UIID;
	query_cmd.ret_port = SHELL_INITRET_PORT;
	query_cmd.ver = STDDEV_VERSION;
	query_cmd.msg_id = 0;

	send_msg(aid, STDSERVICE_PORT, &query_cmd);

	while(get_msg_count(SHELL_INITRET_PORT) == 0){ reschedule(); }

	get_msg(SHELL_INITRET_PORT, &query_res, &id);

	if(query_res.ret == STDSERVICE_RESPONSE_FAILED)
	{
        term_color_print(term, "FAILED", 12);
		return;
	}

    term_color_print(term, "OK", 11);

	stddevport = query_res.port;

    term_color_print(term, "\nGet Device Type...  ", 7);
	// get device type //
	stddevcmd.command = STDDEV_GET_DEVICETYPE;
	stddevcmd.ret_port = SHELL_INITRET_PORT;
	stddevcmd.msg_id = 1;
	
	send_msg(aid, stddevport, &stddevcmd);
	
	while(get_msg_count(SHELL_INITRET_PORT) == 0){ reschedule(); }

	get_msg(SHELL_INITRET_PORT, &devtype_res, &id);

	if(devtype_res.dev_type != STDDEV_BLOCK)
	{
        term_color_print(term, "FAILED", 12);
		return;
	}

    term_color_print(term, "OK", 11);

	// issue query interface command for stdblockdev //
    term_color_print(term, "\nGet STD BLOCK DEV PORT...  ", 7);

	query_cmd.command = STDSERVICE_QUERYINTERFACE;
	query_cmd.uiid = STD_BLOCK_DEV_UIID;
	query_cmd.ret_port = SHELL_INITRET_PORT;
	query_cmd.ver = STD_BLOCK_DEV_VER;
	query_cmd.msg_id = 1;

	send_msg(aid, STDSERVICE_PORT, &query_cmd);
	
	while(get_msg_count(SHELL_INITRET_PORT) == 0){ reschedule(); }

	get_msg(SHELL_INITRET_PORT, &query_res, &id);

	if(query_res.ret != STDSERVICE_RESPONSE_OK)
	{
        term_color_print(term, "FAILED", 12);
		return;
	}

	protocol_port = query_res.port;
	
    term_color_print(term, "OK", 11);

    // all set to comunicate with atac
    show_partition_list(term);
    term_color_print(term, "\n\n", 11);

    // request the device so we can read!
    term_color_print(term, "\nRequest device...  ", 7);

    getdev_cmd.command = STDDEV_GET_DEVICE;
	getdev_cmd.ret_port = SHELL_INITRET_PORT;
	getdev_cmd.logic_deviceid = 0;

	send_msg(aid, stddevport, &getdev_cmd);

	while(get_msg_count(SHELL_INITRET_PORT) == 0){ reschedule(); }
	
	get_msg(SHELL_INITRET_PORT, &stddevres, &id);

	if(stddevres.ret == STDDEV_ERR)
	{
		term_color_print(term, "FAILED", 12);
		return;
	}
    term_color_print(term, "OK", 11);
    term_color_print(term, "\nReading...  ", 7);

    // read sector 2 and show first dword
	block_read.buffer_smo = share_mem(aid, buffer, 512, WRITE_PERM);
	block_read.command = BLOCK_STDDEV_READ;
	block_read.dev = 0;
	block_read.msg_id = 0;
	block_read.pos = 1;
	block_read.ret_port = SHELL_INITRET_PORT;

    for(i = 0; i < 512; i++)
    {
        buffer[i] = 0xFF;
    }
    
	send_msg(aid, protocol_port, &block_read);

	while(get_msg_count(SHELL_INITRET_PORT) == 0){ reschedule(); }
	
	get_msg(SHELL_INITRET_PORT, &block_res, &id);

    claim_mem(block_read.buffer_smo);

    if(block_res.ret == STDBLOCKDEV_ERR)
	{
        term_color_print(term, "FAILED", 11);
    }
    else
    {
        term_color_print(term, "OK", 11);
        term_color_printf(term, "\nread %x %x %x \n", 11, *((int*)buffer), *((int*)&buffer[4]), *((int*)&buffer[8]));
    }

	return;
}