void print_stack() { OBJECT_PTR rest = reg_current_stack; while(rest != NIL) { OBJECT_PTR frame = car(rest); uintptr_t ptr = frame & POINTER_MASK; printf("---- begin frame %0x----\n", frame); printf("Next expression: "); print_object(get_heap(ptr,1)); printf("\n"); printf("Env: "); print_object(get_heap(ptr,2)); printf("\n"); printf("Value rib: "); print_object(get_heap(ptr,3)); printf("\n"); printf("---- end frame %0x----\n", frame); rest = cdr(rest); } }
void print_backtrace() { OBJECT_PTR rest = (debug_mode ? debug_execution_stack : reg_current_stack); int i=0; //to skip the two elements //corresponding to (throw ..) rest = cdr(cdr(rest)); while(rest != NIL) { //print_object(car(rest)); print_object(cdr(get_heap(car(rest) & POINTER_MASK, 1))); printf("\n"); i++; if((i % 20) == 0) { char c; fprintf(stdout, "--- Press any key to continue (q to abort) ---"); c = getchar(); if(c == 'q') return; } rest = cdr(rest); } }
int radeon_mem_init_heap( DRM_IOCTL_ARGS ) { DRM_DEVICE; drm_radeon_private_t *dev_priv = dev->dev_private; drm_radeon_mem_init_heap_t initheap; struct mem_block **heap; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL( initheap, (drm_radeon_mem_init_heap_t *)data, sizeof(initheap) ); heap = get_heap( dev_priv, initheap.region ); if (!heap) return DRM_ERR(EFAULT); if (*heap) { DRM_ERROR("heap already initialized?"); return DRM_ERR(EFAULT); } return init_heap( heap, initheap.start, initheap.size ); }
int radeon_mem_free( DRM_IOCTL_ARGS ) { DRM_DEVICE; drm_radeon_private_t *dev_priv = dev->dev_private; drm_radeon_mem_free_t memfree; struct mem_block *block, **heap; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL( memfree, (drm_radeon_mem_free_t *)data, sizeof(memfree) ); heap = get_heap( dev_priv, memfree.region ); if (!heap || !*heap) return DRM_ERR(EFAULT); block = find_block( *heap, memfree.region_offset ); if (!block) return DRM_ERR(EFAULT); if (block->pid != DRM_CURRENTPID) return DRM_ERR(EPERM); free_block( block ); return 0; }
STATIC mp_obj_t mod_uheapq_heapify(mp_obj_t heap_in) { mp_obj_list_t *heap = get_heap(heap_in); for (mp_uint_t i = heap->len / 2; i > 0;) { heap_siftup(heap, --i); } return mp_const_none; }
int i915_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv) { drm_i915_private_t *dev_priv = dev->dev_private; drm_i915_mem_alloc_t *alloc = data; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("called with no initialization\n"); return -EINVAL; } heap = get_heap(dev_priv, alloc->region); if (!heap || !*heap) return -EFAULT; if (alloc->alignment < 12) alloc->alignment = 12; block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv); if (!block) return -ENOMEM; mark_block(dev, block, 1); if (DRM_COPY_TO_USER(alloc->region_offset, &block->start, sizeof(int))) { DRM_ERROR("copy_to_user\n"); return -EFAULT; } return 0; }
int i915_mem_destroy_heap( DRM_IOCTL_ARGS ) { DRM_DEVICE; drm_i915_private_t *dev_priv = dev->dev_private; drm_i915_mem_destroy_heap_t destroyheap; struct mem_block **heap; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL( destroyheap, (drm_i915_mem_destroy_heap_t *)data, sizeof(destroyheap) ); heap = get_heap( dev_priv, destroyheap.region ); if (!heap) { DRM_ERROR("get_heap failed"); return DRM_ERR(EFAULT); } if (!*heap) { DRM_ERROR("heap not initialized?"); return DRM_ERR(EFAULT); } i915_mem_takedown( heap ); return 0; }
int i915_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_mem_free *memfree = data; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return -EINVAL; } heap = get_heap(dev_priv, memfree->region); if (!heap || !*heap) return -EFAULT; block = find_block(*heap, memfree->region_offset); if (!block) return -EFAULT; if (block->file_priv != file_priv) return -EPERM; mark_block(dev, block, 0); free_block(block); return 0; }
void coroutine_impl::deallocate(coroutine_impl* p) { std::size_t const heap_num = std::size_t(p->get_thread_id()) / 32; //-V112 std::ptrdiff_t const stacksize = p->get_stacksize(); get_heap(heap_num, stacksize).deallocate(p); }
int i915_mem_destroy_heap( struct drm_device *dev, void *data, struct drm_file *file_priv ) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_mem_destroy_heap *destroyheap = data; struct mem_block **heap; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return -EINVAL; } heap = get_heap( dev_priv, destroyheap->region ); if (!heap) { DRM_ERROR("get_heap failed"); return -EFAULT; } if (!*heap) { DRM_ERROR("heap not initialized?"); return -EFAULT; } i915_mem_takedown( heap ); return 0; }
Array::Array(const Array& other) : m_imp(0) { if (!other.valid()) return; m_imp = new ArrayImp(other.get_heap(), other.get_ext_heap(), other.type()); if (other.empty()) return; if (m_imp->type.isPod()) { m_imp->data = other.m_imp->data; } else { m_imp->data.resize(other.m_imp->data.size()); byte *p = m_imp->data.data(); for (Array::const_iterator itr = other.begin(); itr != other.end(); ++itr) { //TODO: exception safe code CommonObject obj(m_imp->type, p); m_imp->type.methods().construct(obj, get_heap(), get_ext_heap()); m_imp->type.methods().assign(*itr, obj); p += m_imp->type.payload(); } } }
void Array::resize(std::size_t s) { AIO_PRE_CONDITION(valid()); Type t = type(); TypeMethods& methods = t.methods(); std::size_t new_size = s * type().payload(); if (s < size()) { if (!t.isPod()) { for (byte* p = m_imp->data.data() + m_imp->data.size() - type().payload() ; p >= m_imp->data.data() + new_size; p -= type().payload()) { methods.destruct(CommonObject(t, p)); } } m_imp->data.resize(new_size); } if(s > size()) { std::size_t old_size = m_imp->data.size(); m_imp->data.resize(new_size); //TODO: need exception safe for (byte* p = m_imp->data.data() + old_size ; p != m_imp->data.data() + m_imp->data.size(); p += type().payload()) { methods.construct(CommonObject(t, p), get_heap(), get_ext_heap()); } } }
OBJECT_PTR eval_sub_array(OBJECT_PTR array, OBJECT_PTR start, OBJECT_PTR length) { OBJECT_PTR ret; int st = get_int_value(start); int len = get_int_value(length); uintptr_t *raw_ptr; uintptr_t orig_ptr, ptr; int i; //see comment in main.c for why we're not using object_alloc() //posix_memalign((void **)&raw_ptr, 16, sizeof(unsigned int *)); //*((int *)raw_ptr) = len; orig_ptr = array & POINTER_MASK; ptr = object_alloc(len + 1, ARRAY_TAG); //set_heap(ptr, 0, convert_int_to_object(len)); //set_heap(ptr, 0, (uintptr_t)raw_ptr + INTEGER_TAG); *((uintptr_t *)ptr) = len; for(i=1; i<=len; i++) set_heap(ptr, i, get_heap(orig_ptr, st + i)); ret = ptr; log_function_exit("eval_sub_array"); return ret + ARRAY_TAG; }
coroutine_impl* coroutine_impl::allocate( thread_id_repr_type id, std::ptrdiff_t stacksize) { // start looking at the matching heap std::size_t const heap_num = std::size_t(id) / 32; //-V112 std::size_t const heap_count = get_heap_count(stacksize); // look through all heaps to find an available coroutine object coroutine_impl* p = get_heap(heap_num, stacksize).allocate(); if (!p) { for (std::size_t i = 1; i != heap_count && !p; ++i) { p = get_heap(heap_num + i, stacksize).allocate(); } } return p; }
void Array::push_back(ConstCommonObject obj) { AIO_PRE_CONDITION(valid()); AIO_PRE_CONDITION(obj.type() == type()); std::size_t old_size = m_imp->data.size(); //TODO:not safe if object hold a pointer to itself. m_imp->data.resize(old_size + type().payload()); byte* p = m_imp->data.data() + old_size; if (!type().isPod()) type().methods().construct(CommonObject(type(), p), get_heap(), get_ext_heap()); type().methods().assign(obj, CommonObject(type(), p) ); }
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) { mp_obj_list_t *heap = get_heap(heap_in); if (heap->len == 0) { nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap")); } mp_obj_t item = heap->items[0]; heap->len -= 1; heap->items[0] = heap->items[heap->len]; heap->items[heap->len] = MP_OBJ_NULL; // so we don't retain a pointer if (heap->len) { heap_siftup(heap, 0); } return item; }
void Array::insert(Array::iterator pos, ConstCommonObject obj) { AIO_PRE_CONDITION(valid()); std::size_t s = size(); Type t = type(); std::size_t idx = (pos - begin()) * t.payload(); //TODO:not safe if object hold a pointer to itself. m_imp->data.insert(m_imp->data.begin() + idx, t.payload(), byte()); if (!type().isPod()) type().methods().construct(CommonObject(type(), m_imp->data.data() + idx), get_heap(), get_ext_heap()); type().methods().assign(obj, CommonObject(type(), m_imp->data.data() + idx) ); AIO_POST_CONDITION(size() == s + 1); }
Term Process::spawn(MFArity& mfa, Term* args) { // Check that we aren't on any scheduler yet G_ASSERT(false == pid_.is_pid()); initial_call_ = mfa; // Set regs to M,F,A and jump to apply_mfargs_ ctx_.arg_regs_[0] = mfa.mod; ctx_.arg_regs_[1] = mfa.fun; ctx_.arg_regs_[2] = term::build_list(get_heap(), args, args + mfa.arity); ctx_.live = 0; // Precondition: Registers should be set to execute apply call ctx_.set_cp(vm_.premade_instr(PremadeIndex::Normal_exit_)); ctx_.set_ip(vm_.premade_instr(PremadeIndex::Apply_mfargs_)); Std::fmt("Process::jump_to_mfa -> " FMT_0xHEX "\n", (Word)ctx_.ip()); vm_.scheduler().add_new_runnable(this); return get_pid(); }
int radeon_mem_alloc( DRM_IOCTL_ARGS ) { DRM_DEVICE; drm_radeon_private_t *dev_priv = dev->dev_private; drm_radeon_mem_alloc_t alloc; struct mem_block *block, **heap; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL( alloc, (drm_radeon_mem_alloc_t *)data, sizeof(alloc) ); heap = get_heap( dev_priv, alloc.region ); if (!heap || !*heap) return DRM_ERR(EFAULT); /* Make things easier on ourselves: all allocations at least * 4k aligned. */ if (alloc.alignment < 12) alloc.alignment = 12; block = alloc_block( *heap, alloc.size, alloc.alignment, DRM_CURRENTPID ); if (!block) return DRM_ERR(ENOMEM); if ( DRM_COPY_TO_USER( alloc.region_offset, &block->start, sizeof(int) ) ) { DRM_ERROR( "copy_to_user\n" ); return DRM_ERR(EFAULT); } return 0; }
int i915_mem_init_heap(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_mem_init_heap *initheap = data; struct mem_block **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return -EINVAL; } heap = get_heap(dev_priv, initheap->region); if (!heap) return -EFAULT; if (*heap) { DRM_ERROR("heap already initialized?"); return -EFAULT; } return init_heap(heap, initheap->start, initheap->size); }
int i915_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_mem_alloc *alloc = data; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return -EINVAL; } heap = get_heap(dev_priv, alloc->region); if (!heap || !*heap) return -EFAULT; /* Make things easier on ourselves: all allocations at least * 4k aligned. */ if (alloc->alignment < 12) alloc->alignment = 12; block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv); if (!block) return -ENOMEM; mark_block(dev, block, 1); if (DRM_COPY_TO_USER(alloc->region_offset, &block->start, sizeof(int))) { DRM_ERROR("copy_to_user\n"); return -EFAULT; } return 0; }
Term Process::error(Term reason, const char* str) { Term err = term::build_string(get_heap(), str); return error(reason, err); }
Term Process::error(Term error_tag, Term reason) { term::TupleBuilder tb(get_heap(), 2); tb.add(error_tag); tb.add(reason); return fail(proc::FailType::Error, tb.make_tuple()); }
/* * Function: art_thread() * File: main.c * Project: ArtemisPS3-PRX * Description: Artemis PRX Thread start * Interprets user input and calls art_process() * Arguments: * arg: * Return: void */ static void art_thread(uint64_t arg) { int GameProcessID = 0, lastGameProcessID = 0; printf("Artemis PS3 :::: Thread Started!\n"); sys_timer_sleep(10); sys_ppu_thread_yield(); CellPadData data; CellPadInfo2 info; int delay = 0, delay2 = 0, hasDisplayed = 0, fd = 0; while (1) { if (exitThread) { destroy_heap(); exitThread = 0; { sys_ppu_thread_exit(0); } { return; } } GameProcessID = GetGameProcessID(); if (GameProcessID != 0) { if (!check_turnoff()) //exit { printf("Artemis PS3 :::: Process Exited\n"); destroy_heap(); attachedPID = 0; } else { if (GameProcessID != lastGameProcessID) { for (int x = 0; x < (10 * 100); x++) //10 second delay { sys_timer_usleep(10000); sys_ppu_thread_yield(); } show_msg((char *)"Artemis PS3\nStart To Attach"); } cellPadGetInfo2(&info); if (info.port_status[0] && (cellPadGetData(0, &data) | 1) && data.len > 0) { uint32_t pad = data.button[2] | (data.button[3] << 8); if (attachedPID) // Run codes { art_process(0); } if (pad & PAD_START) { attachedPID = GameProcessID; if (attachedPID) { show_msg((char *)"Artemis PS3\nAttached and Wrote"); printf("Artemis PS3 :::: Attached to 0x%08X\n", attachedPID); if (get_heap() == 0) create_heap(1); check_syscall_api(); art_process(1); while ((cellPadGetData(0, &data) | 1) && data.len > 0) { if (!((data.button[2] | (data.button[3] << 8)) & PAD_START)) break; sys_timer_usleep(1000000); sys_ppu_thread_yield(); } } else { show_msg((char *)"Artemis PS3\nFailed to Attach"); } } else if (pad & PAD_SELECT && attachedPID) { show_msg((char *)"Artemis PS3\nDetached"); reset_heap(); attachedPID = 0; } } sys_timer_usleep(100 * 1000); //0.1 second delay } } else { if (attachedPID) // Disconnect { printf("Artemis PS3 :::: Process Exited\n"); destroy_heap(); attachedPID = 0; } else sys_timer_usleep(3 * 1000 * 1000); //3 second delay } lastGameProcessID = GameProcessID; sys_timer_usleep(1668); sys_ppu_thread_yield(); } destroy_heap(); sys_ppu_thread_exit(0); }
void gc_orig(BOOLEAN force, BOOLEAN clear_black) { static unsigned long count = 0; if(!can_do_gc) return; //no new objects were created since the //last GC cycle, so nothing to do. if(is_set_empty(WHITE)) return; //do GC every GC_FREQUENCYth time called if((count % GC_FREQUENCY) != 0) return; //printf("Entering GC cycle... "); unsigned int dealloc_words = memory_deallocated(); //assert(is_set_empty(GREY)); build_grey_set(); assert(!is_set_empty(GREY)); while(!is_set_empty(GREY)) { OBJECT_PTR obj = get_an_object_from_grey(); assert(is_dynamic_memory_object(obj)); //FUNCTION2 and MACRO2 objects are handled //by handling their undelying CONS objects if(!IS_FUNCTION2_OBJECT(obj) && !IS_MACRO2_OBJECT(obj)) insert_node(BLACK, obj); remove_node(GREY, obj); if(IS_CONS_OBJECT(obj)) { move_from_white_to_grey(car(obj)); move_from_white_to_grey(cdr(obj)); } else if(IS_CLOSURE_OBJECT(obj) || IS_MACRO_OBJECT(obj)) { move_from_white_to_grey(get_env_list(obj)); move_from_white_to_grey(get_params_object(obj)); move_from_white_to_grey(get_body_object(obj)); move_from_white_to_grey(get_source_object(obj)); } else if(IS_ARRAY_OBJECT(obj)) { uintptr_t ptr = extract_ptr(obj); //OBJECT_PTR length_obj = get_heap(ptr, 0); //move_from_white_to_grey(length_obj); //int len = get_int_value(length_obj); int len = *((OBJECT_PTR *)ptr); int i; for(i=1; i<=len; i++) move_from_white_to_grey(get_heap(ptr, i)); } else if(IS_CONTINUATION_OBJECT(obj)) move_from_white_to_grey(get_heap(extract_ptr(obj), 0)); else if(IS_FUNCTION2_OBJECT(obj) || IS_MACRO2_OBJECT(obj)) { OBJECT_PTR cons_equiv = cons_equivalent(obj); //move_from_white_to_grey(car(cons_equiv)); //move_from_white_to_grey(cdr(cons_equiv)); move_from_white_to_grey(cons_equiv); } } //end of while(!is_set_empty(GREY)) free_white_set_objects(); assert(is_set_empty(GREY)); assert(is_set_empty(WHITE)); assert(!is_set_empty(BLACK)); /* if(clear_black) */ /* recreate_black(); */ /* if(clear_black) */ /* assert(is_set_empty(BLACK)); */ //printf("%d words deallocated in current GC cycle\n", memory_deallocated() - dealloc_words); }
STATIC mp_obj_t mod_uheapq_heappush(mp_obj_t heap_in, mp_obj_t item) { mp_obj_list_t *heap = get_heap(heap_in); mp_obj_list_append(heap_in, item); heap_siftdown(heap, 0, heap->len - 1); return mp_const_none; }