예제 #1
0
파일: common.c 프로젝트: AgentT/iodine
int
open_dns_from_host(char *host, int port, int addr_family, int flags)
{
	struct sockaddr_storage addr;
	int addrlen;

	addrlen = get_addr(host, port, addr_family, flags, &addr);
	if (addrlen < 0)
		return addrlen;

	return open_dns(&addr, addrlen);
}
예제 #2
0
SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
{
	if (!in) {
		return SWITCH_BLANK_STRING;
	}

	if (in->family == AF_INET) {
		return get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
	}

	return get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen);
}
예제 #3
0
파일: mike_canvas.cpp 프로젝트: msarett/575
static void srcover_rect(const GBitmap& bitmap, const GIRect& rect, const GPixel& color) {
    unsigned a = GPixel_GetA(color);
    if (0 == a) {
        return;
    }

    RowProc proc = (255 == a) ? src_row : srcover_row;
    const int width = rect.width();

    for (int y = rect.top(); y < rect.bottom(); ++y) {
        proc(get_addr(bitmap, rect.x(), y), width, color);
    }
}
예제 #4
0
static int valid_ips( struct sockaddr_storage *their_addr )
{
   char remoteIP[2][INET6_ADDRSTRLEN] = { "", "" };

   inet_ntop(their_addr[0].ss_family, 
         get_addr(u[0].addr),
         remoteIP[0], INET6_ADDRSTRLEN);
   inet_ntop(their_addr[1].ss_family, 
         get_addr(u[0].addr),
         remoteIP[1], INET6_ADDRSTRLEN);


   if ( strcmp( remoteIP[0], remoteIP[1] ) != 0  )
   {
      log_printf("*** Warning: Got two connections from different sources. ***\n");
      log_printf("*** %s :: %s ***\n", remoteIP[0], remoteIP[1]);
      return -1;
   }

   log_message(remoteIP[1]);

   return 0;
}
예제 #5
0
	void print_index(std::string& idx_file_name)
	{
		glib::CharStr contents;
		gsize cont_len;
		if(!g_file_get_contents(idx_file_name.c_str(), get_addr(contents), &cont_len, NULL)) {
			std::cerr << "Unable to open file " << idx_file_name << std::endl;
			return;
		}
		if(!quiet_mode) {
			if(syn_file)
				std::cout << "     INDEX KEY" << std::endl;
			else
				std::cout << "    OFFSET       SIZE KEY" << std::endl;
		}
		gchar *p1 = get_impl(contents);
		gchar *end = p1+cont_len;
		int rec_no = 0;
		const gchar* key;
		if(syn_file) {
			guint32 index;
			while(p1<end) {
				key = p1;
				p1 += strlen(p1) + 1;
				index = g_ntohl(*reinterpret_cast<guint32*>(p1));
				p1 += sizeof(guint32);
				++rec_no;
				if(key_only)
					std::cout << key << std::endl;
				else
					std::cout << std::setw(10) << index << " " << key << std::endl;
			}
		} else {
			guint32 offset, size;
			while(p1<end) {
				key = p1;
				p1 += strlen(p1) + 1;
				offset = g_ntohl(*reinterpret_cast<guint32*>(p1));
				p1 += sizeof(guint32);
				size = g_ntohl(*reinterpret_cast<guint32*>(p1));
				p1 += sizeof(guint32);
				++rec_no;
				if(key_only)
					std::cout << key << std::endl;
				else
					std::cout << std::setw(10) << offset << " " << std::setw(10) << size << " "<< key << std::endl;
			}
		}
		if(!quiet_mode)
			std::cout << "number of entries: " << rec_no << std::endl;
	}
예제 #6
0
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
{
    DRESULT result;

    if (pdrv >= N_PDRV)
    {
        result = RES_ERROR;
    }
    else if (!pdrv_data[pdrv].initialized)
    {
        result = RES_NOTRDY;
    }
    else if (!pdrv_data[pdrv].present)
    {
        result = RES_ERROR;
    }
    else if (pdrv_data[pdrv].write_protected)
    {
        result = RES_ERROR;
    }
    else
    {
        while (count > 0)
        {
            uint32_t addr;
            int write_res;

            addr = get_addr(sector, pdrv_data[pdrv].byte_addressable);
            write_res = sd_write_single_block(addr, buff);
            if (write_res != 0)
            {
                break;
            }
            buff += SD_SECTOR_SIZE;
            sector++;
            count--;
        }
        if (count > 0)
        {
            result = RES_ERROR;
        }
        else
        {
            result = RES_OK;
        }
    }

    return result;
}
예제 #7
0
파일: ep.cpp 프로젝트: DragonL/YAC6xSim
//TODO remove it
void EP::gen_inst(std::vector<Instruction*>& inst_vec,bool use_cache)
{
  uint pc = get_addr();
  for (size_t i = 0;i < _code_num;i++)
  {
    code_t code = _code[i];

    //Instruction *pInst = new Instruction(code, pc & 0xFFFFFFE0,pc);
    // Instruction *inst = 
    //  InstFetchController::fetch_inst(code,pc & 0xFFFFFFE0,pc,use_cache);
                        
    //inst_vec.push_back(inst);
    pc += 4;
  }
}
예제 #8
0
void *mem_pool(size_t size)
{
	char *ret;
	char *last_mm; //当前块
	char *new_mm;
	char *p;
	if (head == NULL) { /*第一次申请空间`*/

		head = mk_smm(size);

		return get_addr(head, size);
	}

	/*获取此内存池链表的最后一个的首地址给 cur_mm*/
	if (((memctl_t *)head)->next) { /*不止一次申请过空间*/
		for (p = head; ((memctl_t *)p)->next;  p =(char *)((memctl_t *)p)->next) { /*每个池中都检测能否放下此 size 大小*/
			if (((memctl_t *)p)->left >= size) { /*此碎片能放下此 size */
				return  get_addr(p, size);
			}  /*此碎片放不下,继续向下走*/
		}
		last_mm = p; 
	} else			/*只申请过一次空间*/
		last_mm = head;

	/*从当前内存池链表的末尾判断能否放下,还是需要新申请空间*/
	if (((memctl_t *)last_mm)->left >= size) { /*能放得下*/ 
		ret = get_addr(last_mm, size);
	} else { /*放不下,需要另外申请空间*/
		new_mm = mk_smm(size);
		((memctl_t *)last_mm)->next = (memctl_t *)new_mm;

		ret = get_addr(new_mm, size);
	}

	return ret;
}
예제 #9
0
파일: force_bind.c 프로젝트: hilbix/misc
void
_init(void)
{
  DP(("hello world"));

  _socket	= dlwrap("socket");

  _sock.domain	= get_u16("FORCE_BIND_SOCKDOM", AF_INET);
  _sock.type	= get_u16("FORCE_BIND_SOCKTYPE", SOCK_DGRAM);
  _sock.proto	= get_u16("FORCE_BIND_SOCKPROTO", IPPROTO_UDP);

  get_addr(&_saddr, "FORCE_BIND_ADDR", "127.0.0.1\0\0\0\0\0\0");
  get_port(&_saddr, "FORCE_BIND_PORT");
  _saddr.sin_family = _sock.domain;
}
예제 #10
0
파일: storage.c 프로젝트: MengWenkui/dnfs
/* 
 * copy the data to the backup osd
 * return the error information 
 */
void *do_copy(void *copy_arg)
{
	PDEBUG("[do_copy thread]\n");
	
	static int ret = 0;
	co_write_in *arg = (co_write_in*)copy_arg;
	co_write_out res;
	res.err = 0;
	
	char ipp[IP_BUF];
	get_addr(ipp, arg->ip);
	arg->ip = 0;
	ret = copy_data(arg, &res, ipp);
	
	return (void*)&ret;
}
예제 #11
0
static void incoming_arp(struct clip_vcc *clip_vcc, struct atmarphdr *hdr,
    int len)
{
    void *spa,*tpa;
    u32 src_ip,tgt_ip;
    u8 *here;

    if (len < hdr->data - (u8 *)hdr)
    {
	printk(KERN_WARNING "got truncated ARP packet (%d bytes)\n", len);
	return;
    }
    if (hdr->ar_hrd != htons(ARPHRD_ATM))
    {
	printk(KERN_WARNING "unknown hw protocol 0x%04x", ntohs(hdr->ar_hrd));
	return;
    }
    if (hdr->ar_pro != htons(ETH_P_IP))
    {
	printk(KERN_WARNING "unknown upper protocol 0x%04x",
	    ntohs(hdr->ar_pro));
	return;
    }
    if (!(hdr->ar_shtl & TL_LEN)) hdr->ar_shtl = 0; /* paranoia */
    if (!(hdr->ar_thtl & TL_LEN)) hdr->ar_thtl = 0;
    here = hdr->data;
    get_addr(&here, hdr->ar_shtl & TL_LEN);
    get_addr(&here, hdr->ar_sstl & TL_LEN);
    spa = get_addr(&here, hdr->ar_spln);
    get_addr(&here, hdr->ar_thtl & TL_LEN);
    get_addr(&here, hdr->ar_tstl & TL_LEN);
    tpa = get_addr(&here, hdr->ar_tpln);
    if (here - (u8 *)hdr > len)
    {
	printk(KERN_WARNING "message too short (got %d, need %d)",len,
	    here - (u8 *)hdr);
	return;
    }
    src_ip = get_ip(spa);
    tgt_ip = get_ip(tpa);
    
    switch (ntohs(hdr->ar_op)) {
    case ARPOP_InREQUEST:
	DPRINTK("got InARP_REQ");
	if (!clip_learn(clip_vcc, src_ip))
	    clip_inarp_reply_send(clip_vcc->vcc, src_ip);
	break;
    case ARPOP_InREPLY:
	DPRINTK("got InARP_REP");
	clip_learn(clip_vcc, src_ip);
	break;
    default:
	DPRINTK("unrecognized ARP op 0x%x", ntohs(hdr->ar_op));
    }
}
예제 #12
0
int fdt_decode_sdmmc(const void *blob, int node, struct fdt_sdmmc *config)
{
	config->reg = (struct tegra2_mmc *)get_addr(blob, node, "reg");
	config->enabled = get_is_enabled(blob, node, 1);
	config->periph_id = get_int(blob, node, "periph-id", -1);
	config->width = get_int(blob, node, "width", -1);
	config->removable = get_int(blob, node, "removable", 1);
	if (config->periph_id == -1 || config->width == -1)
		return -FDT_ERR_MISSING;

	/* These GPIOs are optional */
	decode_gpio(blob, node, "cd-gpio", &config->cd_gpio);
	decode_gpio(blob, node, "wp-gpio", &config->wp_gpio);
	decode_gpio(blob, node, "power-gpio", &config->power_gpio);
	return 0;
}
예제 #13
0
파일: tun.c 프로젝트: Gexecho/andiodine
int
open_tun(const char *tun_device)
{
	char adapter[256];
	char tapfile[512];
	int tunfd;
	struct sockaddr_storage localsock;
	int localsock_len;

	memset(adapter, 0, sizeof(adapter));
	memset(if_name, 0, sizeof(if_name));
	get_device(adapter, sizeof(adapter), tun_device);

	if (strlen(adapter) == 0 || strlen(if_name) == 0) {
		if (tun_device) {
			warnx("No TAP adapters found. Try without -d.");
		} else {
			warnx("No TAP adapters found. Version 0801 and 0901 are supported.");
		}
		return -1;
	}

	fprintf(stderr, "Opening device %s\n", if_name);
	snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
	dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
	if (dev_handle == INVALID_HANDLE_VALUE) {
		warnx("Could not open device!");
		return -1;
	}

	/* Use a UDP connection to forward packets from tun,
	 * so we can still use select() in main code.
	 * A thread does blocking reads on tun device and
	 * sends data as udp to this socket */

	localsock_len = get_addr("127.0.0.1", 55353, AF_INET, 0, &localsock);
	tunfd = open_dns(&localsock, localsock_len);

	data.tun = dev_handle;
	memcpy(&(data.addr), &localsock, localsock_len);
	data.addrlen = localsock_len;
	CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tun_reader, &data, 0, NULL);

	return tunfd;
}
예제 #14
0
bool MapFile::open(const char *file_name, bool logerr, long file_size)
{
	filename_ = file_name;

	close();
	size = file_size;
#ifdef HAVE_MMAP
	if ((mmap_fd = ::open(file_name, O_RDONLY)) < 0) {
		if (logerr)
			g_warning(_("Can not open %s: %s\n"), file_name, strerror(errno));
		else
			g_info(_("Can not open %s: %s\n"), file_name, strerror(errno));
		return false;
	}
	
	if (-1 == size) {
		struct stat stat_info;
		if (fstat(mmap_fd, &stat_info)==-1)
			return false;
		size = stat_info.st_size;
	}
	data = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, mmap_fd, 0);
	if ((void *)data == (void *)(-1))
		return false;

#elif defined(WIN32)
	//TODO: rewirte to handle CreateFileA and CreateFileW cases
	hFile = CreateFile(file_name, GENERIC_READ, 0, NULL, OPEN_ALWAYS,
			   FILE_ATTRIBUTE_NORMAL, 0);
	if (-1==size)
		size=GetFileSize(hFile, NULL);
	hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0,
				     size, NULL);
	data = (char *)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, size);
#  else
	gsize fsize;
	if (!g_file_get_contents(file_name, get_addr(databuf_), &fsize, NULL))
		return false;
	size = fsize;
	data = get_impl(databuf_);
#endif
	cur = data;
	end_of_file = data + size;
	return true;
}
예제 #15
0
static int parse_encap_mpls(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
{
	inet_prefix addr;
	int argc = *argcp;
	char **argv = *argvp;

	if (get_addr(&addr, *argv, AF_MPLS)) {
		fprintf(stderr, "Error: an inet address is expected rather than \"%s\".\n", *argv);
		exit(1);
	}

	rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST, &addr.data,
		      addr.bytelen);

	*argcp = argc;
	*argvp = argv;

	return 0;
}
예제 #16
0
static void trace_sock(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
    debug("trace_sock %d");

    Descriptor *d = get_descriptor(sockfd);
    if (d == NULL) {
        return;
    }

    char *addrstr = get_addr(addr, addrlen);
    if (addrstr == NULL) {
        /* It is not a type of socket we understand */
        return;
    }

    debug("sock addr %s", addrstr);

    if (d->path == NULL || strcmp(addrstr, d->path) != 0) {
        /* This is here to handle the case where a socket is reused to connect
         * to another address without being closed first. This happens, for example,
         * with DNS lookups in curl.
         */
        trace_close(sockfd);

        /* Reset the descriptor */
        d->type = DTYPE_NONE;
        d->path = NULL;
        d->bread = 0;
        d->bwrite = 0;
        d->nread = 0;
        d->nwrite = 0;
        d->bseek = 0;
        d->nseek = 0;

        char *temp = strdup(addrstr);
        if (temp == NULL) {
            printerr("strdup: %s\n", strerror(errno));
            return;
        }

        d->type = DTYPE_SOCK;
        d->path = temp;
    }
}
예제 #17
0
int connect_to(char * host, char * port) 
{
	int sockfd;
	struct addrinfo hints, *servinfo, *p;
	int rv;
	char s[INET6_ADDRSTRLEN];

	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	printf("port:%s\n",port);
	if ((rv = getaddrinfo(host, port, &hints, &servinfo)) != 0) 
	{
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
		return -1;
	}
	for(p = servinfo; p != NULL; p = p->ai_next) 
	{
		if ((sockfd = socket(p->ai_family, p->ai_socktype,
		p->ai_protocol)) == -1) 
		{
			perror("client: socket");
			continue;
		}
		if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) 
		{
			close(sockfd);
			perror("client: connect");
		continue;
			}
		break;
	}
	if (p == NULL) 
	{
		fprintf(stderr, "client: failed to connect\n");
		return -1;
	}

	inet_ntop(p->ai_family, get_addr((struct sockaddr *)p->ai_addr),	s, sizeof s);
	fprintf(stdout, "client: connecting to %s\n", s);
	freeaddrinfo(servinfo); 
	return sockfd;
}
예제 #18
0
void ARMInstruction::decode_data_refs()
{
	if ((m_opcode & 0x0c000000) == 0x04000000) {
		int regN = (m_opcode >> 16) & 0xf;
		//int regD = (m_opcode >> 12) & 0xf;
		u32 offset = 0;
		int IPUBWL = (m_opcode >> 20) & 0x3f;
		
		if (regN != 15)
			return;

		if (IPUBWL & (1 << 5)) { // I -> not an immediate
			return;
		} else {
			offset = m_opcode & 0xfff;
		}

		
		address_t base = get_addr() + 8;
		
		address_t taddr;
		
		if (IPUBWL & (1 << 4)) { // P
			if (IPUBWL & (1 << 3)) // U
				taddr = base + offset;
			else
				taddr = base - offset;
		} else {
			taddr = base;
		}
		
		if (IPUBWL & (1 << 0)) { // ldr
			m_pcflags |= PCFLAG_DREF;

			if (IPUBWL & (1 << 2)) // ldrb
				m_pcflags |= PCFLAG_DSBYTE;
			else
				m_pcflags |= PCFLAG_DSWORD;
			
			m_data_ref_addr = taddr;
		} 
	}
예제 #19
0
/*---------------------------------------------------------------------*/
void sg2d_fill_pixel( const struct rect *_rect, u8 color )
{
	u32 screen_ofsx = 0;//_info.screen_width >> 1;
	u32 screen_ofsy = 0;//_info.screen_height >> 1;
	u8 *addr = NULL;
	u32 y,x;
//	vector2_t pos, base;
	
	for( y = 0; y < _rect->height; ++y ) {
//		base.y = _rect->posy + y;
		for( x = 0; x < _rect->width; ++x ) {
//			base.x = _rect->posx + x;
//			rotate( &pos, &base, rot );
			addr = get_addr( (_rect->posy+y), (_rect->posx+x) );
			if( is_valid_address(addr) ) {
				*addr = color;
			}
		}
	}
}
예제 #20
0
파일: common.c 프로젝트: AgentT/iodine
END_TEST

START_TEST(test_parse_format_ipv4_listen_all)
{
	char *host = "0.0.0.0";
	char *formatted;
	struct sockaddr_storage addr;
	struct sockaddr_in *v4addr;
	int addr_len;

	addr_len = get_addr(NULL, 53, AF_INET, AI_PASSIVE, &addr);
	fail_unless(addr_len == sizeof(struct sockaddr_in));

	v4addr = (struct sockaddr_in *) &addr;
	fail_unless(v4addr->sin_addr.s_addr == htonl(0x00000000));
	fail_unless(v4addr->sin_port == htons(53));

	formatted = format_addr(&addr, addr_len);
	fail_if(strcmp(host, formatted));
}
예제 #21
0
파일: common.c 프로젝트: AgentT/iodine
END_TEST

START_TEST(test_parse_format_ipv4)
{
	char *host = "192.168.2.10";
	char *formatted;
	struct sockaddr_storage addr;
	struct sockaddr_in *v4addr;
	int addr_len;

	addr_len = get_addr(host, 53, AF_INET, 0, &addr);
	fail_unless(addr_len == sizeof(struct sockaddr_in));

	v4addr = (struct sockaddr_in *) &addr;
	fail_unless(v4addr->sin_addr.s_addr == htonl(0xc0a8020a));
	fail_unless(v4addr->sin_port == htons(53));

	formatted = format_addr(&addr, addr_len);
	fail_if(strcmp(host, formatted));
}
예제 #22
0
	int ParseCommandLine(int argc, char * argv [])
	{
		quiet_mode = FALSE;
		key_only = FALSE;
		static GOptionEntry entries[] = {
			{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet_mode, "no additional information, only index entries", NULL },
			{ "key-only", 'k', 0, G_OPTION_ARG_NONE, &key_only, "print only keys (implies --quiet option)", NULL },
			{ NULL },
		};
		glib::OptionContext opt_cnt(g_option_context_new("INDEX_FILE"));
		g_option_context_add_main_entries(get_impl(opt_cnt), entries, NULL);
		g_option_context_set_help_enabled(get_impl(opt_cnt), TRUE);
		g_option_context_set_summary(get_impl(opt_cnt),
			"Print context of StarDict index file in human readable form.\n"
			"\n"
			"Supported files: .idx, .ridx, .syn\n"
			);
		glib::Error err;
		if (!g_option_context_parse(get_impl(opt_cnt), &argc, &argv, get_addr(err))) {
			std::cerr << "Option parsing failed: " <<  err->message << std::endl;
			return EXIT_FAILURE;
		}
		if(argc == 1) {
			std::cerr << "Index file is not specified." << std::endl;
			return EXIT_FAILURE;
		}
		if(argc > 2) {
			std::cerr << "warning: only the first file will be processed." <<std::endl;
		}
		idx_file_name = argv[1];
		if(!g_str_has_suffix(idx_file_name.c_str(), ".idx")
				&& !g_str_has_suffix(idx_file_name.c_str(), ".syn")
				&& !g_str_has_suffix(idx_file_name.c_str(), ".ridx")) {
			std::cerr << "Unsupported index type." << std::endl;
			return EXIT_FAILURE;
		}
		syn_file = g_str_has_suffix(idx_file_name.c_str(), ".syn");
		if(key_only)
			quiet_mode = TRUE;
		return EXIT_SUCCESS;
	}
unsigned long dwarf_function_ending_address(Dwarf_Die function_die,  struct dwarf_compilation_unit * unit){
  Dwarf_Error error = 0;
  Dwarf_Attribute *attrbuf = 0;
  Dwarf_Addr highpc = 0;
  Dwarf_Signed attrcount = 0;
  Dwarf_Unsigned i;

  int res = dwarf_attrlist(function_die,&attrbuf,&attrcount,&error);
  if(res != DW_DLV_OK) {
    return 0;
  }
  for(i = 0; i < attrcount ; ++i) {
    Dwarf_Half aform;
    res = dwarf_whatattr(attrbuf[i],&aform,&error);
    if(aform == DW_AT_high_pc) {
      get_addr(attrbuf[i],&highpc);
      return highpc;
    }
  }
  return 0;
}
예제 #24
0
t_sock		connect_server_ipv4(char *ip, int port, char *proto_name)
{
	t_sock			client;
	t_protoent		*proto;
	t_sockaddr_in	sin;

	ft_dprintf(1, "{yellow}Try connecting to '%s:%d' on ipv4\n{eoc}", ip, port);
	client = 0;
	proto = getprotobyname(proto_name);
	if (proto)
		if ((client = socket(PF_INET, SOCK_STREAM, proto->p_proto)) == -1)
			exit(ft_dprintf(2, "can't create socket\n"));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(port);
	sin.sin_addr.s_addr = get_addr(ip);
	if ((connect(client, (const t_sockaddr*)&sin, sizeof(sin))) == -1)
		exit(ft_dprintf(1, "\033[22;31mError : init client on %d\033[22;37m\n",
					port));
	ft_dprintf(1, "{yellow}Success\n{eoc}");
	return (client);
}
예제 #25
0
파일: Nsf_Impl.cpp 프로젝트: kode54/Cog
void Nsf_Impl::map_memory()
{
	// Map standard things
	cpu.reset( unmapped_code() );
	cpu.map_code( 0, 0x2000, low_ram, low_ram_size ); // mirrored four times
	cpu.map_code( sram_addr, sram_size, sram() );
	
	// Determine initial banks
	byte banks [bank_count];
	static byte const zero_banks [sizeof header_.banks] = { 0 };
	if ( memcmp( header_.banks, zero_banks, sizeof zero_banks ) )
	{
		banks [0] = header_.banks [6];
		banks [1] = header_.banks [7];
		memcpy( banks + fds_banks, header_.banks, sizeof header_.banks );
	}
	else
	{
		// No initial banks, so assign them based on load_addr
		int first_bank = (get_addr( header_.load_addr ) - sram_addr) / bank_size;
		unsigned total_banks = rom.size() / bank_size;
		for ( int i = bank_count; --i >= 0; )
		{
			int bank = i - first_bank;
			if ( (unsigned) bank >= total_banks )
				bank = 0;
			banks [i] = bank;
		}
	}
	
	// Map banks
	for ( int i = (fds_enabled() ? 0 : fds_banks); i < bank_count; ++i )
		write_bank( i, banks [i] );
	
	// Map FDS RAM
	if ( fds_enabled() )
		cpu.map_code( rom_addr, fdsram_size, fdsram() );
}
예제 #26
0
int fdt_decode_get_spi_switch(const void *blob, struct fdt_spi_uart *config)
{
	int node, uart_node;
	const u32 *gpio;

	node = fdt_node_offset_by_compatible(blob, 0,
					     "nvidia,spi-uart-switch");
	if (node < 0)
		return node;

	uart_node = lookup_phandle(blob, node, "uart");
	if (uart_node < 0)
		return uart_node;
	config->port = get_int(blob, uart_node, "id", -1);
	if (config->port == -1)
		return -FDT_ERR_NOTFOUND;
	config->gpio = -1;
	config->regs = (NS16550_t)get_addr(blob, uart_node, "reg");
	gpio = fdt_getprop(blob, node, "gpios", NULL);
	if (gpio)
		config->gpio = fdt32_to_cpu(gpio[1]);
	return 0;
}
예제 #27
0
파일: connect_pool.cpp 프로젝트: neland/acl
bool connect_pool::aliving()
{
	// XXX,虽然此处未加锁,但也应该不会有问题,因为下面的 peek() 过程会再次
	// 对 alive_ 加锁,以防止多线程操作时的冲突
	if (alive_)
		return true;

	time_t now = time(NULL);

	lock_.lock();
	if (retry_inter_ > 0 && now - last_dead_ >= retry_inter_)
	{
		alive_ = true;
		lock_.unlock();

		// 重置服务端连接状态,以便重试
		logger("reset server: %s", get_addr());
		return true;
	}

	lock_.unlock();
	return false;
}
예제 #28
0
파일: Nsf_Impl.cpp 프로젝트: kode54/Cog
blargg_err_t Nsf_Impl::load_( Data_Reader& in )
{
	// pad ROM data with 0
	RETURN_ERR( rom.load( in, header_.size, &header_, 0 ) );
	
	if ( !header_.valid_tag() )
		return blargg_err_file_type;
	
	RETURN_ERR( high_ram.resize( (fds_enabled() ? fdsram_offset + fdsram_size : fdsram_offset) ) );

	addr_t load_addr = get_addr( header_.load_addr );
	if ( load_addr < (fds_enabled() ? sram_addr : rom_addr) )
		set_warning( "Load address is too low" );
	
	rom.set_addr( load_addr % bank_size );
	
	if ( header_.vers != 1 )
		set_warning( "Unknown file version" );
	
	set_play_period( header_.play_period() );
	
	return blargg_ok;
}
예제 #29
0
//address
static void *add_free_block(void *bp) {
//dbg_printf("addfree%p\n",bp);
    void* block;
    if (free_list==base) {
        set_succ(bp,0);
        set_pred(bp,0);
        free_list=bp;
        return bp;
    }
//int i=0;
    block=free_list;
    size_t block_off;
    while(block!=base) {
//printf("freehead%p",block);
        block_off=get_offset(block);
        if (get_offset(bp)<block_off) {
            set_succ(bp,block_off);
            set_pred(bp,get_pred_offset(block));
            void *pred=pred_blkp(block);
            set_pred(block,get_offset(bp));
            if (block==free_list)
                free_list=bp;
            else {
                set_succ(pred,get_offset(bp));
            }//printf("add%p %p %p %p\n",bp,pred_blkp(bp),succ_blkp(bp),block);
            return bp;
        }
        block=succ_blkp(block);
        //	i++;
    }
    set_succ(bp,0);
    set_pred(bp,block_off);
    set_succ(get_addr(block_off),get_offset(bp));
    return bp;

}
예제 #30
0
파일: Nsf_Impl.cpp 프로젝트: kode54/Cog
blargg_err_t Nsf_Impl::start_track( int track )
{
	int speed_flags = 0;
	#if NSF_EMU_EXTRA_FLAGS
		speed_flags = header().speed_flags;
	#endif
	
	apu.reset( header().pal_only(), (speed_flags & 0x20) ? 0x3F : 0 );
	apu.enable_w4011_( enable_w4011 );
	apu.write_register( 0, 0x4015, 0x0F );
	apu.write_register( 0, 0x4017, (speed_flags & 0x10) ? 0x80 : 0 );
	
	// Clear memory
	memset( unmapped_code(), Nes_Cpu::halt_opcode, unmapped_size );
	memset( low_ram, 0, low_ram_size );
	memset( sram(), 0, sram_size );
	
	map_memory();
	
	// Arrange time of first call to play routine
	play_extra = 0;
	next_play  = play_period;
	
	play_delay = initial_play_delay;
	saved_state.pc = idle_addr;
	
	// Setup for call to init routine
	cpu.r.a  = track;
	cpu.r.x  = header_.pal_only();
	cpu.r.sp = 0xFF;
	jsr_then_stop( header_.init_addr );
	if ( cpu.r.pc < get_addr( header_.load_addr ) )
		set_warning( "Init address < load address" );
	
	return blargg_ok;
}