int appfs_mem_getinfo(const devfs_handle_t * handle, void * ctl){ DECLARE_APPFS_CONFIG(); mem_info_t * info = ctl; if( ctl == 0 ){ return SYSFS_SET_RETURN(EINVAL); } info->flash_pages = get_memory_page_count(config, MEM_FLAG_IS_FLASH); info->flash_size = get_memory_size(config, MEM_FLAG_IS_FLASH); info->ram_pages = get_memory_page_count(config, MEM_FLAG_IS_RAM); info->ram_size = get_memory_size(config, MEM_FLAG_IS_RAM); info->system_ram_page = config->system_ram_page; info->usage = config->usage; info->usage_size = config->usage_size; return 0; }
static void cpu_pci_domain_set_resources(device_t dev) { u32 pci_tolm = find_pci_tolm(dev->link_list); unsigned long tomk = 0, tolmk; int idx; tomk = get_memory_size(); printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n", tomk, tomk / 1024); /* Compute the top of Low memory */ tolmk = pci_tolm >> 10; if (tolmk >= tomk) { /* The PCI hole does not overlap the memory. */ tolmk = tomk; } /* Report the memory regions. */ idx = 10; ram_resource(dev, idx++, 0, 640); ram_resource(dev, idx++, 768, tolmk - 768); set_top_of_ram(tomk * 1024); assign_resources(dev->link_list); }
static int hw_dev_open(int dev_index) { struct sr_dev_inst *sdi; struct context *ctx; int ret; if (!(sdi = zp_open_dev(dev_index))) { sr_err("zp: unable to open device"); return SR_ERR; } /* TODO: Note: sdi is retrieved in zp_open_dev(). */ if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } ret = libusb_set_configuration(ctx->usb->devhdl, USB_CONFIGURATION); if (ret < 0) { sr_err("zp: Unable to set USB configuration %d: %d", USB_CONFIGURATION, ret); return SR_ERR; } ret = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE); if (ret != 0) { sr_err("zp: Unable to claim interface: %d", ret); return SR_ERR; } analyzer_reset(ctx->usb->devhdl); analyzer_initialize(ctx->usb->devhdl); analyzer_set_memory_size(MEMORY_SIZE_512K); // analyzer_set_freq(g_freq, g_freq_scale); analyzer_set_trigger_count(1); // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger) // * get_memory_size(g_memory_size)) / 100) >> 2); analyzer_set_ramsize_trigger_address( (100 * get_memory_size(MEMORY_SIZE_512K) / 100) >> 2); #if 0 if (g_double_mode == 1) analyzer_set_compression(COMPRESSION_DOUBLE); else if (g_compression == 1) analyzer_set_compression(COMPRESSION_ENABLE); else #endif analyzer_set_compression(COMPRESSION_NONE); if (ctx->cur_samplerate == 0) { /* Samplerate hasn't been set. Default to the slowest one. */ if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE, &samplerates.list[0]) == SR_ERR) return SR_ERR; } return SR_OK; }
SR_PRIV void set_triggerbar(struct dev_context *devc) { unsigned int ramsize, n, triggerbar; ramsize = get_memory_size(devc->memory_size) / 4; if (devc->trigger) { n = ramsize; if (devc->max_memory_size < n) n = devc->max_memory_size; if (devc->limit_samples < n) n = devc->limit_samples; n = n * devc->capture_ratio / 100; if (n > ramsize - 8) triggerbar = ramsize - 8; else triggerbar = n; } else { triggerbar = 0; } analyzer_set_triggerbar_address(triggerbar); analyzer_set_ramsize_trigger_address(ramsize - triggerbar); sr_dbg("triggerbar_address = %d(0x%x)", triggerbar, triggerbar); sr_dbg("ramsize_triggerbar_address = %d(0x%x)", ramsize - triggerbar, ramsize - triggerbar); }
/* * Class: sharedmemory_SharedMemory * Method: get_memory_size * Signature: (Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_sharedmemory_SharedMemory_get_1memory_1size (JNIEnv *env, jobject obj, jstring descriptor) { long ret = -1; const char* desc = (*env)->GetStringUTFChars( env, descriptor , NULL ) ; ret = get_memory_size(desc); (*env)->ReleaseStringUTFChars(env, descriptor ,desc); return ret; }
// Hooks free function void free(void *ptr) { extern void __free(void *); static size_t get_memory_size(void *ptr); size_t size; size = get_memory_size(ptr); malloc_mem_monitor -= size; __free(ptr); }
void mem_init(){ mem_size = get_memory_size(); mem_table_size = (mem_size-MEM_USEABLE_ADDRESS)/(4*1024)/8; mem_table = (uint8_t *)MEM_TABLE_ADDRESS; mem_list = (mem_list_t *)MEM_LIST_ADDRESS; for(int i = 0;i<mem_table_size;i++){ mem_table[i] = 0; } for(int i = 0;i<MEM_LIST_LENGTH;i++){ (mem_list + i)->address = 0; } }
/* * Class: sharedmemory_SharedMemory * Method: map_existing_memory * Signature: (Ljava/lang/String;)Ljava/nio/ByteBuffer; */ JNIEXPORT jobject JNICALL Java_sharedmemory_SharedMemory_map_1existing_1memory (JNIEnv *env, jobject obj, jstring descriptor) { jobject ret = NULL; char* memory; long size = 0; const char* desc = (*env)->GetStringUTFChars( env, descriptor , NULL ) ; size = get_memory_size(desc); memory = map_memory(desc, size); ret = (*env)->NewDirectByteBuffer(env, (void*) memory, size); (*env)->ReleaseStringUTFChars(env, descriptor ,desc); return ret; }
static int rdc_get_smbios_data16(int handle, unsigned long *current) { struct smbios_type16 *t = (struct smbios_type16 *)*current; int len = sizeof(struct smbios_type16); memset(t, 0, sizeof(struct smbios_type16)); t->type = SMBIOS_PHYS_MEMORY_ARRAY; t->handle = handle; t->length = len - 2; t->location = 3; /* Location: System Board */ t->use = 3; /* System memory */ t->memory_error_correction = 3; /* No error correction */ t->maximum_capacity = get_memory_size(); *current += len; return len; }
DownloadFlowController *DownloadFlowController::get_instance(apr_shm_t *shm) { DownloadFlowController *flow_controller; #ifdef DEBUG if (apr_shm_size_get(shm) != get_memory_size()) { THROW(MESSAGE_SHM_SIZE_INVALID); } #endif flow_controller = reinterpret_cast<DownloadFlowController *>(apr_shm_baseaddr_get(shm)); new(flow_controller) DownloadFlowController; return flow_controller; }
SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples) { devc->limit_samples = samples; if (samples <= 2 * 1024) devc->memory_size = MEMORY_SIZE_8K; else if (samples <= 16 * 1024) devc->memory_size = MEMORY_SIZE_64K; else if (samples <= 32 * 1024 || devc->max_memory_size <= 32 * 1024) devc->memory_size = MEMORY_SIZE_128K; else devc->memory_size = MEMORY_SIZE_512K; sr_info("Setting memory size to %dK.", get_memory_size(devc->memory_size) / 1024); analyzer_set_memory_size(devc->memory_size); return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct sr_usb_dev_inst *usb; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; unsigned int samples_read; int res; unsigned int packet_num, n; unsigned char *buf; unsigned int status; unsigned int stop_address; unsigned int now_address; unsigned int trigger_address; unsigned int trigger_offset; unsigned int triggerbar; unsigned int ramsize_trigger; unsigned int memory_size; unsigned int valid_samples; unsigned int discard; int trigger_now; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; if (!(devc = sdi->priv)) { sr_err("%s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } if (configure_channels(sdi) != SR_OK) { sr_err("Failed to configure channels."); return SR_ERR; } usb = sdi->conn; set_triggerbar(devc); /* Push configured settings to device. */ analyzer_configure(usb->devhdl); analyzer_start(usb->devhdl); sr_info("Waiting for data."); analyzer_wait_data(usb->devhdl); status = analyzer_read_status(usb->devhdl); stop_address = analyzer_get_stop_address(usb->devhdl); now_address = analyzer_get_now_address(usb->devhdl); trigger_address = analyzer_get_trigger_address(usb->devhdl); triggerbar = analyzer_get_triggerbar_address(); ramsize_trigger = analyzer_get_ramsize_trigger_address(); n = get_memory_size(devc->memory_size); memory_size = n / 4; sr_info("Status = 0x%x.", status); sr_info("Stop address = 0x%x.", stop_address); sr_info("Now address = 0x%x.", now_address); sr_info("Trigger address = 0x%x.", trigger_address); sr_info("Triggerbar address = 0x%x.", triggerbar); sr_info("Ramsize trigger = 0x%x.", ramsize_trigger); sr_info("Memory size = 0x%x.", memory_size); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); /* Check for empty capture */ if ((status & STATUS_READY) && !stop_address) { packet.type = SR_DF_END; sr_session_send(cb_data, &packet); return SR_OK; } if (!(buf = g_try_malloc(PACKET_SIZE))) { sr_err("Packet buffer malloc failed."); return SR_ERR_MALLOC; } /* Check if the trigger is in the samples we are throwing away */ trigger_now = now_address == trigger_address || ((now_address + 1) % memory_size) == trigger_address; /* * STATUS_READY doesn't clear until now_address advances past * addr 0, but for our logic, clear it in that case */ if (!now_address) status &= ~STATUS_READY; analyzer_read_start(usb->devhdl); /* Calculate how much data to discard */ discard = 0; if (status & STATUS_READY) { /* * We haven't wrapped around, we need to throw away data from * our current position to the end of the buffer. * Additionally, the first two samples captured are always * bogus. */ discard += memory_size - now_address + 2; now_address = 2; } /* If we have more samples than we need, discard them */ valid_samples = (stop_address - now_address) % memory_size; if (valid_samples > ramsize_trigger + triggerbar) { discard += valid_samples - (ramsize_trigger + triggerbar); now_address += valid_samples - (ramsize_trigger + triggerbar); } sr_info("Need to discard %d samples.", discard); /* Calculate how far in the trigger is */ if (trigger_now) trigger_offset = 0; else trigger_offset = (trigger_address - now_address) % memory_size; /* Recalculate the number of samples available */ valid_samples = (stop_address - now_address) % memory_size; /* Send the incoming transfer to the session bus. */ samples_read = 0; for (packet_num = 0; packet_num < n / PACKET_SIZE; packet_num++) { unsigned int len; unsigned int buf_offset; res = analyzer_read_data(usb->devhdl, buf, PACKET_SIZE); sr_info("Tried to read %d bytes, actually read %d bytes.", PACKET_SIZE, res); if (discard >= PACKET_SIZE / 4) { discard -= PACKET_SIZE / 4; continue; } len = PACKET_SIZE - discard * 4; buf_offset = discard * 4; discard = 0; /* Check if we've read all the samples */ if (samples_read + len / 4 >= valid_samples) len = (valid_samples - samples_read) * 4; if (!len) break; if (samples_read < trigger_offset && samples_read + len / 4 > trigger_offset) { /* Send out samples remaining before trigger */ packet.type = SR_DF_LOGIC; packet.payload = &logic; logic.length = (trigger_offset - samples_read) * 4; logic.unitsize = 4; logic.data = buf + buf_offset; sr_session_send(cb_data, &packet); len -= logic.length; samples_read += logic.length / 4; buf_offset += logic.length; } if (samples_read == trigger_offset) { /* Send out trigger */ packet.type = SR_DF_TRIGGER; packet.payload = NULL; sr_session_send(cb_data, &packet); } /* Send out data (or data after trigger) */ packet.type = SR_DF_LOGIC; packet.payload = &logic; logic.length = len; logic.unitsize = 4; logic.data = buf + buf_offset; sr_session_send(cb_data, &packet); samples_read += len / 4; } analyzer_read_stop(usb->devhdl); g_free(buf); packet.type = SR_DF_END; sr_session_send(cb_data, &packet); return SR_OK; }
/* given a xa_instance_t struct with the xc_handle and the * domain_id filled in, this function will fill in the rest * of the values using queries to libxc. */ int helper_init (xa_instance_t *instance) { int ret = XA_SUCCESS; uint32_t local_offset = 0; unsigned char *memory = NULL; if (XA_MODE_XEN == instance->mode){ #ifdef ENABLE_XEN /* init instance->m.xen.xc_handle */ if (xc_domain_getinfo( instance->m.xen.xc_handle, instance->m.xen.domain_id, 1, &(instance->m.xen.info) ) != 1){ fprintf(stderr, "ERROR: Failed to get domain info\n"); ret = xa_report_error(instance, 0, XA_ECRITICAL); if (XA_FAILURE == ret) goto error_exit; } xa_dbprint("--got domain info.\n"); /* find the version of xen that we are running */ init_xen_version(instance); #endif /* ENABLE_XEN */ } /* read in configure file information */ if (read_config_file(instance) == XA_FAILURE){ ret = xa_report_error(instance, 0, XA_EMINOR); if (XA_FAILURE == ret) goto error_exit; } /* determine the page sizes and layout for target OS */ if (XA_MODE_XEN == instance->mode){ #ifdef ENABLE_XEN if (get_page_info_xen(instance) == XA_FAILURE){ fprintf(stderr, "ERROR: memory layout not supported\n"); ret = xa_report_error(instance, 0, XA_ECRITICAL); if (XA_FAILURE == ret) goto error_exit; } #endif /* ENABLE_XEN */ } else{ /*TODO add memory layout discovery here for file */ instance->hvm = 1; /* assume nonvirt image or hvm image for now */ instance->pae = 0; /* assume no pae for now */ } xa_dbprint("--got memory layout.\n"); /* setup the correct page offset size for the target OS */ init_page_offset(instance); if (XA_MODE_XEN == instance->mode){ #ifdef ENABLE_XEN /* init instance->hvm */ instance->hvm = xa_ishvm(instance->m.xen.domain_id); #ifdef XA_DEBUG if (instance->hvm){ xa_dbprint("**set instance->hvm to true (HVM).\n"); } else{ xa_dbprint("**set instance->hvm to false (PV).\n"); } #endif /* XA_DEBUG */ #endif /* ENABLE_XEN */ } /* get the memory size */ if (get_memory_size(instance) == XA_FAILURE){ fprintf(stderr, "ERROR: Failed to get memory size.\n"); ret = xa_report_error(instance, 0, XA_ECRITICAL); if (XA_FAILURE == ret) goto error_exit; } /* setup OS specific stuff */ if (instance->os_type == XA_OS_LINUX){ ret = linux_init(instance); } else if (instance->os_type == XA_OS_WINDOWS){ ret = windows_init(instance); } error_exit: return ret; }
static void *thread_main_loop(void *_state) { struct thread_state *state = (struct thread_state *)_state; struct packet *pkt = NULL; sigset_t set; #ifdef HAKA_MEMCHECK int64 pkt_count=0; const int mem_rate=10; #endif thread_setid(state->thread_id); if (!state->pool->single) { /* Block all signal to let the main thread handle them */ sigfillset(&set); sigdelset(&set, SIGSEGV); sigdelset(&set, SIGILL); sigdelset(&set, SIGFPE); if (!thread_sigmask(SIG_BLOCK, &set, NULL)) { LOG_FATAL(core, "%s", clear_error()); barrier_wait(&state->pool->thread_start_sync); state->state = STATE_ERROR; return NULL; } if (!timer_init_thread()) { LOG_FATAL(core, "%s", clear_error()); barrier_wait(&state->pool->thread_start_sync); state->state = STATE_ERROR; return NULL; } /* To make sure we can still cancel even if some thread are locked in * infinite loops */ if (!thread_setcanceltype(THREAD_CANCEL_ASYNCHRONOUS)) { LOG_FATAL(core, "%s", clear_error()); barrier_wait(&state->pool->thread_start_sync); state->state = STATE_ERROR; return NULL; } if (!init_thread_lua_state(state)) { barrier_wait(&state->pool->thread_start_sync); state->state = STATE_ERROR; return NULL; } } state->engine = engine_thread_init(state->lua->L, state->thread_id); engine_thread_update_status(state->engine, THREAD_RUNNING); packet_init(state->capture); if (!state->pool->single) { if (!barrier_wait(&state->pool->thread_start_sync)) { LOG_FATAL(core, "%s", clear_error()); state->state = STATE_ERROR; engine_thread_update_status(state->engine, THREAD_DEFUNC); return NULL; } } if (!state->pool->single) { if (!barrier_wait(&state->pool->thread_sync)) { LOG_FATAL(core, "%s", clear_error()); state->state = STATE_ERROR; engine_thread_update_status(state->engine, THREAD_DEFUNC); return NULL; } } lua_state_trigger_haka_event(state->lua, "started"); engine_thread_update_status(state->engine, THREAD_WAITING); while (packet_receive(state->engine, &pkt) == 0) { engine_thread_update_status(state->engine, THREAD_RUNNING); /* The packet can be NULL in case of failure in packet receive */ if (pkt) { filter_wrapper(state, pkt); pkt = NULL; } lua_state_runinterrupt(state->lua); engine_thread_check_remote_launch(state->engine); if (state->pool->attach_debugger > state->attach_debugger) { luadebug_debugger_start(state->lua->L, true); state->attach_debugger = state->pool->attach_debugger; } engine_thread_update_status(state->engine, THREAD_WAITING); #ifdef HAKA_MEMCHECK if (((pkt_count++) % mem_rate) == 0) { size_t vmsize, rss; if (!get_memory_size(&vmsize, &rss)) { LOG_ERROR(core, "cannot get memory report: %s", clear_error()); } else { const size_t luasize = lua_gc(state->lua->L, LUA_GCCOUNT, 0); LOG_DEBUG(core, "memory report: thread=%d vmsize=%zd rsssize=%zd luasize=%zd", engine_thread_id(state->engine), vmsize, rss, luasize); } } #endif if (state->pool->stop) { break; } } state->state = STATE_FINISHED; engine_thread_update_status(state->engine, THREAD_STOPPED); return NULL; }