static void sanitise_sendmsg(int childno) { struct msghdr *msg; struct sockaddr *sa = NULL; socklen_t salen; msg = malloc(sizeof(struct msghdr)); shm->scratch[childno] = (unsigned long) msg; if (msg == NULL) { // just do something weird. shm->syscall[childno].a2 = (unsigned long) get_address(); return; } generate_sockaddr((struct sockaddr **) &sa, (socklen_t *) &salen, rand() % TRINITY_PF_MAX); msg->msg_name = sa; msg->msg_namelen = salen; msg->msg_iov = get_address(); msg->msg_iovlen = get_len(); msg->msg_control = get_address(); msg->msg_controllen = get_len(); msg->msg_flags = rand32(); shm->syscall[childno].a2 = (unsigned long) msg; }
static int get_address_range(address *start_ptr, address *stop_ptr, int offset) { int ret_code=NO_ERROR; char *add_ptrs[2]; int nmbr_of_adds; if (n_parts < offset+1) { PrntMessage(DISP_INTERNAL, "get_address_range received bad offset: %d",offset); ret_code = ERROR; } else { if (!Split_String(parts[offset],"-", add_ptrs, 2, &nmbr_of_adds)) { PrntMessage(DISP_WARNING, "The address range has too many componets. Using %s-%s", add_ptrs[0], add_ptrs[1]); } if (!get_address(add_ptrs[0], start_ptr)) { ret_code = ERROR; } else { *stop_ptr = *start_ptr; if (nmbr_of_adds == 2) { if (!get_address(add_ptrs[1], stop_ptr)) ret_code = ERROR; else if (*start_ptr > *stop_ptr) { PrntMessage(DISP_ERROR,"Second address is smaller"); ret_code = ERROR; } } } } return (ret_code); }
static unsigned long handle_arg_address(struct syscallrecord *rec, unsigned int argnum) { unsigned long addr = 0; if (argnum == 1) return (unsigned long) get_address(); if (RAND_BOOL()) return (unsigned long) get_address(); /* Half the time, we look to see if earlier args were also ARG_ADDRESS, * and munge that instead of returning a new one from get_address() */ addr = find_previous_arg_address(rec, argnum); switch (rnd() % 4) { case 0: break; /* return unmodified */ case 1: addr++; break; case 2: addr+= sizeof(int); break; case 3: addr+= sizeof(long); break; } return addr; }
//Add a <key,value> pair to the cache //If key already exists, overwrite the old value //If maxmem capacity is exceeded, values will be removed void cache_set(cache_t cache, _key_t key, val_t val, uint32_t val_size) { cache_real_obj *c = cache->cache; //Delete the value if it's already in the cache. meta_t old = get_key_loc(cache,key); if (old != NULL) cache_delete(cache, key); uint64_t available_memory = cache->cache->size - cache_space_used(cache); printf("Trying to add a value of size %"PRIu32", with available memory %"PRIu64"\n",val_size,available_memory); if (available_memory < val_size) { printf(" Increasing size.\n"); defrag(cache, 1); //This doubles the cache size (defragmenting at the same time). } bucket_timer_up(cache); //Create a new meta object and pair it to a slab address, and copy the value over meta_t next_meta = create_meta(cache,key,val_size); next_meta->address = get_address(c->slab_manager,val_size); //enact eviction policy if we need space if (next_meta->address == NULL){ uint32_t val_slab_class = get_slab_class(c->slab_manager, val_size); cache_evict(cache, val_slab_class); next_meta->address = get_address(c->slab_manager,val_size); if (next_meta->address == NULL){ uint32_t slab_class = get_slab_class(c->slab_manager, val_size); printf("Couldn't add a %u-%u byte value because there are no slabs of that range, and no free slabs to be allocated\n",slab_class>>1, slab_class); free(next_meta); return; }
void test_nodes() { const char * test_nodes[] = { "memyselfi:129", "zebra:321", "apple:123", "intheory:876"}; init_network_nodes(0, 4, test_nodes); assert(my_id() == 2); assert(get_port(0) == 123); assert(get_port(1) == 876); assert(get_port(2) == 129); assert(get_port(3) == 321); char *got = get_address(0); assert(strcmp(got, "apple") == 0); free(got); got = get_address(1); assert(strcmp(got, "intheory") == 0); free(got); got = get_address(2); assert(strcmp(got, "memyselfi") == 0); free(got); got = get_address(3); assert(strcmp(got, "zebra") == 0); free(got); destroy_network_nodes(); }
void set_data( const char* raw_data, Elf64_Addr updateAddress, Elf_Word dataSize ) { if (dataSize <= (get_address() + get_size() - updateAddress)) { std::copy(raw_data, raw_data + dataSize, data + (updateAddress - get_address())); } }
static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmdstr) { int idx = 0; /* parse the command * format is: [addr][,addr]cmd * |----||-----||-| * part1 part2 part3 */ /* first part (if present) is an address: either a number or a /regex/ */ if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/') idx = get_address(sed_cmd, cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match); /* second part (if present) will begin with a comma */ if (cmdstr[idx] == ',') { idx++; idx += get_address(sed_cmd, &cmdstr[idx], &sed_cmd->end_line, &sed_cmd->end_match); } /* last part (mandatory) will be a command */ if (cmdstr[idx] == '\0') error_msg_and_die("missing command"); sed_cmd->cmd = cmdstr[idx]; /* if it was a single-letter command that takes no arguments (such as 'p' * or 'd') all we need to do is increment the index past that command */ if (strchr("pd", cmdstr[idx])) { idx++; } /* handle (s)ubstitution command */ else if (sed_cmd->cmd == 's') { idx += parse_subst_cmd(sed_cmd, &cmdstr[idx]); } /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ else if (strchr("aic", sed_cmd->cmd)) { if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') error_msg_and_die("only a beginning address can be specified for edit commands"); idx += parse_edit_cmd(sed_cmd, &cmdstr[idx]); } /* handle file cmds: (r)ead */ else if (sed_cmd->cmd == 'r') { if (sed_cmd->end_line || sed_cmd->end_match) error_msg_and_die("Command only uses one address"); idx += parse_file_cmd(sed_cmd, &cmdstr[idx]); } else { error_msg_and_die("invalid command"); } /* give back whatever's left over */ return (char *)&cmdstr[idx]; }
void Allocator::move(index_t original_start, index_t final_start, size_t original_blocks, size_t final_blocks) { void* origin = get_address(original_start); void* destination = get_address(final_start); size_t bytes = std::min(original_blocks, final_blocks) * block_size; memcpy(destination, origin, bytes); fill_map(original_start, original_blocks, false); fill_map(final_start, final_blocks, true); }
void Log_client::on_client_write() { if (m_socket_type == stTCP) { char buf[1024]; int read_cnt = 0; do { read_cnt = m_socket_client->readLine(buf, sizeof(buf)); QString line = QString::fromLocal8Bit(buf, read_cnt); if(m_log_format.isNull()) { if(get_log_format(line)) m_log_format->add_line(line, get_address()); else m_log_format.clear(); } else m_log_format->add_line(line, get_address()); } while (read_cnt > 0); } else if (m_socket_type == stUDP) { QUdpSocket *udp_socket = dynamic_cast<QUdpSocket*>(m_socket_client); while (udp_socket->hasPendingDatagrams()) { QByteArray datagram; datagram.resize(udp_socket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; udp_socket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); m_udp_id = QString("%1 %2").arg(sender.toString()).arg(senderPort); QString line = QString::fromLocal8Bit(datagram.data(), datagram.size()); if(m_log_format.isNull()) { if(get_log_format(line)) m_log_format->add_line(line, get_address()); else m_log_format.clear(); } else m_log_format->add_line(line, get_address()); } } }
static inline errval_t find_mapping_for_cap(struct cte *cap, struct cte **mapping) { genpaddr_t faddr = get_address(&cap->cap); struct cte *next = cap; while ((next = mdb_successor(next)) && get_address(&next->cap) == faddr) { if (next->cap.type == get_mapping_type(cap->cap.type) && next->cap.u.frame_mapping.cap == &cap->cap) { *mapping = next; return SYS_ERR_OK; } } return SYS_ERR_CAP_NOT_FOUND; }
tiled_region thread::get_tiled_address(u32 offset, u32 location) { u32 address = get_address(offset, location); GcmTileInfo *tile = find_tile(offset, location); u32 base = 0; if (tile) { base = offset - tile->offset; address = get_address(tile->offset, location); } return{ address, base, tile, (u8*)vm::base(address) }; }
static void socket_fill_address(JNIEnv *env, jobject obj, server_socket_t *ss, connection_t *conn, jbyteArray local_addr, jbyteArray remote_addr) { char temp_buf[1024]; struct sockaddr_in *sin; if (ss->_isSecure) { jboolean is_secure = conn->sock != 0 && conn->ssl_cipher != 0; (*env)->SetBooleanField(env, obj, ss->_isSecure, is_secure); } if (local_addr) { /* the 16 must match JniSocketImpl 16 bytes ipv6 */ get_address(conn->server_sin, temp_buf, 16); set_byte_array_region(env, local_addr, 0, 16, temp_buf); } if (ss->_localPort) { jint local_port; sin = (struct sockaddr_in *) conn->server_sin; local_port = ntohs(sin->sin_port); (*env)->SetIntField(env, obj, ss->_localPort, local_port); } if (remote_addr) { /* the 16 must match JniSocketImpl 16 bytes ipv6 */ get_address(conn->client_sin, temp_buf, 16); set_byte_array_region(env, remote_addr, 0, 16, temp_buf); } if (ss->_remotePort) { jint remote_port; sin = (struct sockaddr_in *) conn->client_sin; remote_port = ntohs(sin->sin_port); (*env)->SetIntField(env, obj, ss->_remotePort, remote_port); } }
void it_read_instruction(Word word, char line[], Instruction *ins, char ***ids, int index, Queue *strs, Queue *ins_indices) { InsEntry *entry = (InsEntry *) hashtable_lookup(global_it.ins_ht, word.word); NULL_CHECK(entry, "Attempted to read instruction name, but was not registered.") ins->op = entry->op; char *str; switch (entry->type) { case I_VAL: str = get_value(ins, &word, line); if (STRING_INS == ins->type) { ins->op = PUSHM; queue_add_front(strs, str); queue_add_front(ins_indices, (int *) index); } break; case I_ADR: get_address(&word, line, ins, ids, index); break; case I_ID: get_id(&word, line, ins->id); break; case I_NONE: default: break; } }
int BATT_SMBUS::search() { bool found_slave = false; uint16_t tmp; int16_t orig_addr = get_address(); // search through all valid SMBus addresses for (uint8_t i = BATT_SMBUS_ADDR_MIN; i <= BATT_SMBUS_ADDR_MAX; i++) { set_address(i); if (read_reg(BATT_SMBUS_VOLTAGE, tmp) == OK) { warnx("battery found at 0x%x", (int)i); found_slave = true; } // short sleep usleep(1); } // restore original i2c address set_address(orig_addr); // display completion message if (found_slave) { warnx("Done."); } else { warnx("No smart batteries found."); } return OK; }
void partition_resolver_simple::handle_pending_requests(std::deque<request_context_ptr>& reqs, error_code err) { for (auto& req : reqs) { if (err == ERR_OK) { rpc_address addr; err = get_address(req->partition_index, addr); if (err == ERR_OK) { end_request(std::move(req), err, addr); } else { call(std::move(req), true); } } else if (err == ERR_HANDLER_NOT_FOUND) { end_request(std::move(req), err, rpc_address()); } else { call(std::move(req), true); } } reqs.clear(); }
//TODO: get some real error checking in here void write_page(void) { #ifndef PLATFORM_LINUX uint8_t pagebuf[PAGESIZE]; uint16_t i; void *addr; //uint8_t int_handle; /* if(load_state == 0) start_code_image(); load_state++; */ addr = get_address(); for(i=0; i<PAGESIZE; i++) pagebuf[i] = mcs_recv(); mcs_send(PAGE_RECVD); #warning "Not sure if this mos_prog_add_page () is correct" if(mos_prog_add_page (pagebuf) == PROG_OK) mcs_send(PAGE_WRITTEN); else mcs_send(FLASH_FULL); #else //TODO: linux program write goes here #endif }
/**@brief Function for swapping existing SoftDevice with newly received. */ uint32_t dfu_sd_image_swap(void) { uint32_t err_code = NRF_SUCCESS; bootloader_settings_t bootloader_settings; bootloader_settings_load(&bootloader_settings); if ((bootloader_settings.bank_1 & BANK_VALID_MASK) & (BANK_VALID_SD)) { bootloader_settings.bank_1 &= ~(BANK_VALID_SD); bootloader_settings_save(&bootloader_settings); err_code = copy((uint32_t *)get_address(SOFTDEVICE_PART), (uint32_t *)SOFTDEVICE_REGION_START, bootloader_settings.sd_image_size); nrf_delay_ms(100); if (err_code == NRF_SUCCESS) { NVIC_SystemReset(); } } return err_code; }
/* * create a symbol table entry unless one already exists */ void create_symbol( int type, unsigned char value, char *buffer, int length) { TUPLE *tuple; /* * first search for same identifier string */ tuple = find_symbol( data.level, buffer, length); /* * update symbol type entry or make new symbol table entry */ if( tuple) { if( 0 < type) tuple->token = type; if( 0 < value) tuple->value = value; return; } tuple = new_tuple( type, value, get_address( 1), 0, buffer, length); tuple->level = data.level; /* * attach it to the head of the symbol table list (LIFO) */ tuple->next = data.symbol_table; data.symbol_table = tuple; return; }
void set(size_t bIdx) { if (bIdx >= size()) { throw std::runtime_error("Out of array"); } const auto& address = get_address(bIdx); data_[std::get<0>(address)] |= std::get<1>(address); }
/// Ctor. Prepares session for connection as an initiator. ClientSession (const F8MetaCntx& ctx, const std::string& conf_file, const std::string& session_name, bool init_con_later=false) : ClientSessionBase(ctx, conf_file, session_name), _sci(get_sender_comp_id(_ses)), _tci(get_target_comp_id(_ses)), _id(_ctx._beginStr, _sci, _tci), _log(create_logger(_ses, session_log, &_id)), _plog(create_logger(_ses, protocol_log, &_id)), _persist(create_persister(_ses, nullptr, this->_loginParameters._reset_sequence_numbers)), _session(new T(_ctx, _id, _persist, _log, _plog)), _addr(get_address(_ses)) #ifdef FIX8_HAVE_OPENSSL ,_ssl(get_ssl_context(_ses), true) #endif { if (!init_con_later) { #ifdef FIX8_HAVE_OPENSSL bool secured(_ssl.is_secure()); _sock = secured ? new Poco::Net::SecureStreamSocket(_ssl._context) : new Poco::Net::StreamSocket; #else bool secured(false); _sock = new Poco::Net::StreamSocket; #endif _cc = new ClientConnection(_sock, _addr, *_session, this->_loginParameters._hb_int, get_process_model(_ses), true, secured); } _session->set_login_parameters(this->_loginParameters); _session->set_session_config(this); }
/* Returns if the line was successfully parsed */ int process_opcode(char *line, label_table_t *table, FILE *fout, int verbose) { int i; char addr_s[MAX_LABEL_SIZE]; int addr; for (i = 0; i < 8; i++) { if (!strncmp(line, opcode_str[i], 3)) { /* Found opcode. Skip over opcode and get address. * If the opcode is STP there shouldn't be a memory address * and this gives the empty string which becomes zero. * It's just a fluke that this works but less cases is better, right? */ sscanf(line + 3, "%s", addr_s); if (*addr_s == LABEL_C) { addr = get_address(table, addr_s + 1); if (addr < 0) { fprintf(stderr, "Unknown label \"%s\"\n", addr_s + 1); exit(1); } } else { addr = strtol(addr_s, NULL, 0); } fprintf(fout, "%01x%03x\n", i, addr); return 1; } } return 0; }
static DBusMessage *cancel_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; struct service_adapter *serv_adapter = data; struct pending_auth *auth; const gchar *sender; sender = dbus_message_get_sender(msg); auth = find_pending_by_sender(serv_adapter, sender); if (auth == NULL) return btd_error_does_not_exist(msg); btd_cancel_authorization(auth->id); reply = btd_error_not_authorized(auth->msg); dbus_message_unref(auth->msg); g_dbus_send_message(btd_get_dbus_connection(), reply); serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list, auth); g_free(auth); auth = next_pending(serv_adapter); if (auth == NULL) goto done; auth->id = btd_request_authorization(get_address(serv_adapter), &auth->dst, auth->uuid, auth_cb, serv_adapter); done: return dbus_message_new_method_return(msg); }
boolean RF22Mesh::init() { boolean ret = RF22Router::init(); if( ret && _thisAddress == 0 ) { return get_address(); } }
int main(int argc, char *argv[]) { vector<int> objIdents (object_id, object_id + sizeof(object_id) / sizeof(object_id[0]) ); vector<int> npAngles (np_angles, np_angles + sizeof(np_angles) / sizeof(np_angles[0]) ); string output_library_address = string(_SOURCE_DIRECTORY_) + "/yml_library/output"; string raw_data_address = get_address("raw_data_address.txt", "image_library/image_library"); objectIdentifier objI; objI.restrictData(objIdents, npAngles); objI.setDevelopmentDirectory(string(_SOURCE_DIRECTORY_) + "/output"); // Loops through and creates all the YML files cout << "Generating library YML files..." << endl; objI.generateLibrary(raw_data_address, output_library_address, DEBUG_MODE); std::printf("%s << Exiting... (press any key)\n", __FUNCTION__); cin.get(); #if defined(_WIN32) && defined(_DEBUG) && defined(TerminateProcess) TerminateProcess(GetCurrentProcess(), EXIT_SUCCESS); #endif return 0; }
void mainemuinit() { // initialize cpu memory mem_init(); #ifndef __GP32__ graphics_init(NULL); #else graphics_init(); #endif // initialize the TLCS-900H cpu tlcs_init(); #ifdef DRZ80 Z80_Reset(); #else z80Init(); #endif // if neogeo pocket color rom, act if we are a neogeo pocket color tlcsMemWriteB(0x6F91,tlcsMemReadB(0x00200023)); // pretend we're running in English mode tlcsMemWriteB(0x00006F87,0x01); // kludges & fixes switch (tlcsMemReadW(0x00200020)) { case 0x0059: // Sonic case 0x0061: // Metal SLug 2nd *get_address(0x0020001F) = 0xFF; break; } ngpSoundOff(); //Flavor sound_start(); }
int XIOsocket::open(const char* uri, XOFLAGS oflags) { DEBUGLOG(("XIOsocket(%p)::open(%s, %x)\n", this, uri, oflags)); if (strnicmp(uri, "tcpip://", 8) == 0) uri += 8; const char* cp = strchr(uri, ':'); if (cp == NULL) { seterror(SOCESOCKTNOSUPPORT); return -1; } char* host = (char*)alloca(cp-uri+1); memcpy(host, uri, cp-uri); host[cp-uri] = 0; u_long address = get_address(host); if (address == (u_long)-1L) { error = errno; return -1; } int port = get_service(cp+1); if (port == -1) { error = errno; return -1; } error = 0; return open(address, port); }
bool get(size_t bIdx) const { if (bIdx >= size()) { throw std::runtime_error("Out of array"); } const auto& address = get_address(bIdx); return data_[std::get<0>(address)] & std::get<1>(address); }
//ERR_OBJECT_NOT_FOUND not in cache. //ERR_IO_PENDING in cache but invalid, remove from cache. //ERR_OK in cache and valid error_code partition_resolver_simple::get_address(int partition_index, /*out*/ rpc_address& addr) { //partition_configuration config; { zauto_read_lock l(_config_lock); auto it = _config_cache.find(partition_index); if (it != _config_cache.end()) { //config = it->second->config; addr = get_address(it->second->config); if (addr.is_invalid()) { return ERR_IO_PENDING; } else { return ERR_OK; } } else { return ERR_OBJECT_NOT_FOUND; } } }
int Connect2Server(char* ip, char* port) { int server; struct addrinfo *temp_ai, *servinfo; int aierror = getaddrinfo(ip, port, &hints, &servinfo); if (aierror != 0) fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(aierror)); for(temp_ai = servinfo; temp_ai != NULL; temp_ai = temp_ai->ai_next) { //create socket if ((server = socket(temp_ai->ai_family, temp_ai->ai_socktype, temp_ai->ai_protocol)) == -1){ perror("Client: socket error!"); continue; } //connect to server if (connect(server, temp_ai->ai_addr, temp_ai->ai_addrlen) == -1) { close(server); perror("Client: connect error!"); continue; } break; } if (temp_ai == NULL) { fprintf(stderr, "Failed to connect!\n"); exit(1); } char RemoteIP[INET6_ADDRSTRLEN]; inet_ntop(temp_ai->ai_family, get_address((struct sockaddr *)temp_ai->ai_addr), RemoteIP, sizeof(RemoteIP)); printf("Connected to Server (%s:%s)\n", RemoteIP, port); freeaddrinfo(servinfo); // Successfully connected to server return server; }
void read_flash() { #ifndef PLATFORM_LINUX uint16_t i; void *addr; uint16_t word; flash_enable_rww(); // Make sure the RWW section is enabled /* Get the flash page address. */ addr = get_address(); for(i = 0; i < PAGESIZE; i+=2) { word = flash_read_word(addr); mcs_send((uint8_t)(word >> 8)); mcs_send((uint8_t)word); addr += 2; } mos_uart_close(0); mos_uart_open(0); mcs_send(FLASH_READ_COMPLETE); #else //TODO: linux program read goes here #endif }