Пример #1
0
static lc_locked_lock_t *lc_core_alloc(lc_thread_t* thr)
{
    int i;
    lc_alloc_chunk_t* chunk;
    lc_free_block_t* fbs;
    chunk = (lc_alloc_chunk_t*) malloc(sizeof(lc_alloc_chunk_t));
    if (!chunk) {
        ERTS_INTERNAL_ERROR("Lock checker failed to allocate memory!");
    }
    chunk->next = thr->chunks;
    thr->chunks = chunk;

    fbs = chunk->array;
    for (i = 1; i < ERTS_LC_FB_CHUNK_SIZE - 1; i++) {
#ifdef DEBUG
	sys_memset((void *) &fbs[i], 0xdf, sizeof(lc_free_block_t));
#endif
	fbs[i].next = &fbs[i+1];
    }
#ifdef DEBUG
    sys_memset((void *) &fbs[ERTS_LC_FB_CHUNK_SIZE-1],
	   0xdf, sizeof(lc_free_block_t));
#endif
    fbs[ERTS_LC_FB_CHUNK_SIZE-1].next = thr->free_blocks;
    thr->free_blocks = &fbs[1];
    return &fbs[0].lock;
}
Пример #2
0
/**
 * spr_init: initialize vdp sprites and allocation tables
 */
void spr_init(char spritesize, char zoom)
{
	vdp_init_hw_sprites(spritesize, zoom);
	// set all atributes out of screen
	vdp_memset(vdp_base_spatr_grp1, sizeof(struct vdp_hw_sprite) * vdp_hw_max_sprites, 212);
	sys_memset(spr_attr_valloc, 1, vdp_hw_max_sprites);
	sys_memset(spr_patt_valloc, 1, vdp_hw_max_patterns);
}
Пример #3
0
static int __config_init( void )
{
    OSH_ERROR status = OSH_ERR_NONE;
    char temp_buf[1024];
    static int global_test_rc = 0;

    sys_memset(&osh_config, 0, sizeof(osh_config));

    osh_config.active = 0;
    if (gethostname(osh_config.hostname, sizeof(osh_config.hostname)) != 0)
    {
        sys_strcpy(osh_config.hostname, "localhost");
    }
    osh_config.my_pe = INVALID_PE;
    osh_config.num_pe = INVALID_PE;
    osh_config.rc = &global_test_rc; /*NULL*/
    /* 
     * Seed the random-number generator with current time so that
     * the numbers will be different every time we run.
     */
    osh_config.timer = (unsigned int)time( NULL );
    srand( osh_config.timer );

    PE_LIST_SET(DEFAULT_PE, osh_config.exec_mode.log_pe_list);
    osh_config.exec_mode.out_level = LOG_INFO;
    osh_config.exec_mode.out_file = stdout;

    osh_config.exec_mode.log_level = LOG_NONE;
    osh_config.exec_mode.log_file = NULL;
    sys_snprintf_safe(temp_buf, sizeof(temp_buf), "%s_%s_%04d.log", MODULE_NAME, osh_config.hostname, getpid());
    osh_config.exec_mode.log_file_name = sys_strdup(temp_buf);

    return status;
}
Пример #4
0
static ERTS_INLINE void lc_free(lc_thread_t* thr, lc_locked_lock_t *p)
{
    lc_free_block_t *fb = (lc_free_block_t *) p;
#ifdef DEBUG
    sys_memset((void *) p, 0xdf, sizeof(lc_free_block_t));
#endif
    fb->next = thr->free_blocks;
    thr->free_blocks = fb;
}
Пример #5
0
/*===========================================================================*
 *				alloc_pages				     *
 *===========================================================================*/
static phys_bytes alloc_pages(int pages, int memflags)
{
	phys_bytes boundary16 = 16 * 1024 * 1024 / VM_PAGE_SIZE;
	phys_bytes boundary1  =  1 * 1024 * 1024 / VM_PAGE_SIZE;
	phys_bytes mem = NO_MEM, i;	/* page number */
	int maxpage = NUMBER_PHYSICAL_PAGES - 1;
	static int lastscan = -1;
	int startscan, run_length;

	if(memflags & PAF_LOWER16MB)
		maxpage = boundary16 - 1;
	else if(memflags & PAF_LOWER1MB)
		maxpage = boundary1 - 1;
	else {
		/* no position restrictions: check page cache */
		if(pages == 1) {
			while(free_page_cache_size > 0) {
				i = free_page_cache[free_page_cache_size-1];
				if(page_isfree(i)) {
					free_page_cache_size--;
					mem = i;
					assert(mem != NO_MEM);
					run_length = 1;
					break;
				}
				free_page_cache_size--;
			}
		}
	}

	if(lastscan < maxpage && lastscan >= 0)
		startscan = lastscan;
	else	startscan = maxpage;

	if(mem == NO_MEM)
		mem = findbit(0, startscan, pages, memflags, &run_length);
	if(mem == NO_MEM)
		mem = findbit(0, maxpage, pages, memflags, &run_length);
	if(mem == NO_MEM)
		return NO_MEM;

	/* remember for next time */
	lastscan = mem;

	for(i = mem; i < mem + pages; i++) {
		UNSET_BIT(free_pages_bitmap, i);
	}

	if(memflags & PAF_CLEAR) {
		int s;
		if ((s= sys_memset(NONE, 0, CLICK_SIZE*mem,
			VM_PAGE_SIZE*pages)) != OK) 
			panic("alloc_mem: sys_memset failed: %d", s);
	}

	return mem;
}
Пример #6
0
/**
 * sys_malloc
 *
 * @brief
 *    Allocate memory for new category object and set initial values.
 *
 * @param[in]    size           This is a size of memory to allocate.
 *
 * @retval pointer to the allocated memory - on success
 * @retval NULL - on failure
 ***************************************************************************/
void *sys_malloc(size_t size)
{
	void *p = NULL;

	p = malloc(size);
	if (p)
		sys_memset(p, 0, size);

	return p;
}
Пример #7
0
Sint64 efile_pwritev(efile_data_t *d, Sint64 offset, SysIOVec *iov, int iovlen) {
    efile_win_t *w = (efile_win_t*)d;

    OVERLAPPED overlapped;

    sys_memset(&overlapped, 0, sizeof(overlapped));
    overlapped.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
    overlapped.Offset = offset & 0xFFFFFFFF;

    return internal_sync_io(w, WriteFile, iov, iovlen, &overlapped);
}
Пример #8
0
static void
node_table_free(void *venp)
{
    ErlNode *enp = (ErlNode *) venp;

    ERTS_SMP_LC_ASSERT(enp != erts_this_node || erts_thr_progress_is_blocking());

    erts_deref_dist_entry(enp->dist_entry);
#ifdef DEBUG
    sys_memset(venp, 0x55, sizeof(ErlNode));
#endif
    erts_free(ERTS_ALC_T_NODE_ENTRY, venp);

    ASSERT(node_entries > 0);
    node_entries--;
}
Пример #9
0
/*===========================================================================*
 *				free_pages				     *
 *===========================================================================*/
static void free_pages(phys_bytes pageno, int npages)
{
	int i, lim = pageno + npages - 1;

#if JUNKFREE
       if(sys_memset(NONE, 0xa5a5a5a5, VM_PAGE_SIZE * pageno,
               VM_PAGE_SIZE * npages) != OK)
                       panic("free_pages: sys_memset failed");
#endif

	for(i = pageno; i <= lim; i++) {
		SET_BIT(free_pages_bitmap, i);
		if(free_page_cache_size < PAGE_CACHE_MAX) {
			free_page_cache[free_page_cache_size++] = i;
		}
	}
}
Пример #10
0
static void
node_table_free(void *venp)
{
    ErlNode *enp = (ErlNode *) venp;

    if(enp == erts_this_node)
	return;

    erts_deref_dist_entry(enp->dist_entry);
#ifdef DEBUG
    sys_memset(venp, 0x55, sizeof(ErlNode));
#endif
    erts_free(ERTS_ALC_T_NODE_ENTRY, venp);

    ASSERT(node_entries > 1);
    node_entries--;
}
Пример #11
0
static void
dist_table_free(void *vdep)
{
    DistEntry *dep = (DistEntry *) vdep;

    if(dep == erts_this_dist_entry)
	return;

    ASSERT(is_nil(dep->cid));
    ASSERT(dep->nlinks == NULL);
    ASSERT(dep->node_links == NULL);
    ASSERT(dep->monitors == NULL);

    /* Link out */

    /* All dist entries about to be removed are "not connected" */

    if(dep->prev) {
	ASSERT(is_in_de_list(dep, erts_not_connected_dist_entries));
	dep->prev->next = dep->next;
    }
    else {
	ASSERT(erts_not_connected_dist_entries == dep);
	erts_not_connected_dist_entries = dep->next;
    }

    if(dep->next)
	dep->next->prev = dep->prev;

    ASSERT(erts_no_of_not_connected_dist_entries > 0);
    erts_no_of_not_connected_dist_entries--;

    ASSERT(!dep->cache);
    erts_smp_rwmtx_destroy(&dep->rwmtx);
    erts_smp_mtx_destroy(&dep->lnk_mtx);
    erts_smp_mtx_destroy(&dep->qlock);

#ifdef DEBUG
    sys_memset(vdep, 0x77, sizeof(DistEntry));
#endif
    erts_free(ERTS_ALC_T_DIST_ENTRY, (void *) dep);

    ASSERT(dist_entries > 1);
    dist_entries--;
}
Пример #12
0
/**
 * spr_show: finds a gap to allocate the attribute set
 */
byte spr_show(struct spr_sprite_def *sp)
{
	byte i, idx, n, f = 0;
	n = sp->pattern_set->n_planes;
	if (sp->pattern_set->size == SPR_SIZE_16x32)
		n = n * 2;
	for (i = 0; i < vdp_hw_max_sprites - 1; i++) {
		f = f * spr_attr_valloc[i] + spr_attr_valloc[i];
		if (f == n) {
			idx = i - n + 1;
			sys_memset(&spr_attr_valloc[idx], 0, n);
			sp->aidx = idx;
			spr_update(sp);
			return true;
		}
	}
	return false;
}
Пример #13
0
Sint64 efile_writev(efile_data_t *d, SysIOVec *iov, int iovlen) {
    efile_win_t *w = (efile_win_t*)d;

    OVERLAPPED __overlapped, *overlapped;
    Uint64 bytes_written;

    if(w->common.modes & EFILE_MODE_APPEND) {
        overlapped = &__overlapped;

        sys_memset(overlapped, 0, sizeof(*overlapped));
        overlapped->OffsetHigh = 0xFFFFFFFF;
        overlapped->Offset = 0xFFFFFFFF;
    } else {
        overlapped = NULL;
    }

    return internal_sync_io(w, WriteFile, iov, iovlen, overlapped);
}
Пример #14
0
/**
 * spr_valloc_pattern_set:
 *		finds a gap to allocate a pattern set
 */
byte spr_valloc_pattern_set(struct spr_sprite_pattern_set *ps)
{
	uint npat;
	byte i, idx, f = 0;

	npat = ps->n_planes * ps->n_dirs * ps->n_anim_steps * ps->size;

	for (i = 0; i < vdp_hw_max_patterns - 1; i++) {
		f = f * spr_patt_valloc[i] + spr_patt_valloc[i];
		if (f == npat) {
			idx = i - npat + 1;
			sys_memset(&spr_patt_valloc[idx], 0, npat);
			vdp_copy_to_vram(ps->patterns, vdp_base_sppat_grp1 + idx * 8, npat * 8);
			ps->pidx = idx;
			return true;
		}
	}
	return false;
}
Пример #15
0
/**
 * sys_hostdate
 *
 * @brief
 *    Return a string with host date. Should be freed with sys_free().
 *
 * @retval Host date - on success
 * @retval NULL - on failure
 ***************************************************************************/
char *sys_hostdate(void)
{
	char tmp_buf[256];
	char* host_date = NULL;
	time_t t;
	struct tm *tmp;

	sys_memset(tmp_buf, 0, sizeof(tmp_buf));

	t = time(NULL);
	tmp = localtime(&t);
	sys_snprintf_safe( tmp_buf, sizeof(tmp_buf), "%02d.%02d.%04d %02d:%02d:%02d",
			tmp->tm_mday, tmp->tm_mon + 1, tmp->tm_year + 1900,
			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);

	host_date = sys_strdup(tmp_buf);

	return host_date;
}
Пример #16
0
static void shift_overlapped(OVERLAPPED *overlapped, DWORD shift) {
    LARGE_INTEGER offset;

    ASSERT(shift >= 0);

    offset.HighPart = overlapped->OffsetHigh;
    offset.LowPart = overlapped->Offset;

    /* ~(Uint64)0 is a magic value ("append to end of file") which needs to be
     * preserved. Other positions resulting in overflow would have errored out
     * just prior to this point. */
    if(offset.QuadPart != ERTS_UINT64_MAX) {
        offset.QuadPart += shift;
    }

    /* All unused fields must be zeroed for the next call. */
    sys_memset(overlapped, 0, sizeof(*overlapped));
    overlapped->OffsetHigh = offset.HighPart;
    overlapped->Offset = offset.LowPart;
}
Пример #17
0
static int cow_block(struct vmproc *vmp, struct vir_region *region,
	struct phys_region *ph, u16_t clearend)
{
	int r;

	if((r=mem_cow(region, ph, MAP_NONE, MAP_NONE)) != OK) {
		printf("mappedfile_pagefault: COW failed\n");
		return r;
	}

	/* After COW we are a normal piece of anonymous memory. */
	ph->memtype = &mem_type_anon;

	if(clearend) {
		phys_bytes phaddr = ph->ph->phys, po = VM_PAGE_SIZE-clearend;
		assert(clearend < VM_PAGE_SIZE);
		phaddr += po;
		if(sys_memset(NONE, 0, phaddr, clearend) != OK) {
			panic("cow_block: clearend failed\n");
		}
	}

	return OK;
}
Пример #18
0
int libexec_clear_sys_memset(struct exec_info *execi, off_t vaddr, size_t len)
{
	return sys_memset(execi->proc_e, 0, vaddr, len);
}
Пример #19
0
void spr_vfree_pattern_set(struct spr_sprite_pattern_set *ps)
{
	byte npat;
	npat = ps->n_planes * ps->n_dirs * ps->n_anim_steps * ps->size;
	sys_memset(&spr_patt_valloc[ps->pidx], 1, npat);	
}
Пример #20
0
posix_errno_t efile_read_info(const efile_path_t *path, int follow_links, efile_fileinfo_t *result) {
    BY_HANDLE_FILE_INFORMATION native_file_info;
    DWORD attributes;
    int is_link;

    sys_memset(&native_file_info, 0, sizeof(native_file_info));
    is_link = 0;

    attributes = GetFileAttributesW((WCHAR*)path->data);

    if(attributes == INVALID_FILE_ATTRIBUTES) {
        DWORD last_error = GetLastError();

        /* Querying a network share root fails with ERROR_BAD_NETPATH, so we'll
         * fake it as a directory just like local roots. */
        if(!is_path_root(path) || last_error != ERROR_BAD_NETPATH) {
            return windows_to_posix_errno(last_error);
        }

        attributes = FILE_ATTRIBUTE_DIRECTORY;
    } else if(is_path_root(path)) {
        /* Local (or mounted) roots can be queried with GetFileAttributesW but
         * lack support for GetFileInformationByHandle, so we'll skip that
         * part. */
    } else {
        HANDLE handle;

        if(attributes & FILE_ATTRIBUTE_REPARSE_POINT) {
            is_link = is_name_surrogate(path);
        }

        if(follow_links && is_link) {
            posix_errno_t posix_errno;
            efile_path_t resolved_path;

            posix_errno = internal_read_link(path, &resolved_path);

            if(posix_errno != 0) {
                return posix_errno;
            }

            return efile_read_info(&resolved_path, 0, result);
        }

        handle = CreateFileW((const WCHAR*)path->data, GENERIC_READ,
            FILE_SHARE_FLAGS, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
            NULL);

        /* The old driver never cared whether this succeeded. */
        if(handle != INVALID_HANDLE_VALUE) {
            GetFileInformationByHandle(handle, &native_file_info);
            CloseHandle(handle);
        }

        FILETIME_TO_EPOCH(result->m_time, native_file_info.ftLastWriteTime);
        FILETIME_TO_EPOCH(result->a_time, native_file_info.ftLastAccessTime);
        FILETIME_TO_EPOCH(result->c_time, native_file_info.ftCreationTime);

        if(result->m_time == -EPOCH_DIFFERENCE) {
            /* Default to 1970 just like the old driver. */
            result->m_time = 0;
        }

        if(result->a_time == -EPOCH_DIFFERENCE) {
            result->a_time = result->m_time;
        }

        if(result->c_time == -EPOCH_DIFFERENCE) {
            result->c_time = result->m_time;
        }
    }

    if(is_link) {
        result->type = EFILE_FILETYPE_SYMLINK;
        /* This should be _S_IFLNK, but the old driver always set
         * non-directories to _S_IFREG. */
        result->mode |= _S_IFREG;
    } else if(attributes & FILE_ATTRIBUTE_DIRECTORY) {
        result->type = EFILE_FILETYPE_DIRECTORY;
        result->mode |= _S_IFDIR | _S_IEXEC;
    } else {
        if(is_executable_file(path)) {
            result->mode |= _S_IEXEC;
        }

        result->type = EFILE_FILETYPE_REGULAR;
        result->mode |= _S_IFREG;
    }

    if(!(attributes & FILE_ATTRIBUTE_READONLY)) {
        result->access = EFILE_ACCESS_READ | EFILE_ACCESS_WRITE;
        result->mode |= _S_IREAD | _S_IWRITE;
    } else {
        result->access = EFILE_ACCESS_READ;
        result->mode |= _S_IREAD;
    }

    /* Propagate user mode-bits to group/other fields */
    result->mode |= (result->mode & 0700) >> 3;
    result->mode |= (result->mode & 0700) >> 6;

    result->size =
        ((Uint64)native_file_info.nFileSizeHigh << 32ull) |
        (Uint64)native_file_info.nFileSizeLow;

    result->links = MAX(1, native_file_info.nNumberOfLinks);

    result->major_device = get_drive_number(path);
    result->minor_device = 0;
    result->inode = 0;
    result->uid = 0;
    result->gid = 0;

    return 0;
}
Пример #21
0
void do_xref_map()
{
   int_type pos;
   int knt,nnn,nnn_less,iii,jjj,kkk,iii_src,iii_dest,new_iii;
   size_t eachsize;
   cross_reference_entry_type *item_arr;
   cross_reference_entry_type *item_iii;
   cross_reference_entry_type *item_jjj;
   char blankname[XREF_IDENT_MAXNCH_P];
   static char newline_fmt[] = "\n";
   static char name_fmt[] = "%s%s   ";
   static char pos_fmt[] = "%d c%d%s";
   char enkpos[XREF_IDENT_MAXNCH_P+25];
   char last_refcode,curr_refcode;
   Boolean undcl,unset,unuse,special;
   /*-------------------------------------------------------*/
   if (!xref_map) return;
   list_page_need_test_only(32000);
   sys_memset(blankname,(int) ' ',(size_t) XREF_ID_TRUNC_NCH);
   *(blankname+XREF_ID_TRUNC_NCH) = '\0';
   /*--------------------------------------------   size the file */
   pos=ftell(xreffile);
   knt=eachsize=sizeof(cross_reference_entry_type);
   knt=(int) (pos/((int_type) knt));
   /*--------------------------------------------   close & re-open to read */
   fclose(xreffile);
   xreffile=open_binary_input_file(xref_filename);
   /*--------------------------------------------   allocate */
   item_arr = (cross_reference_entry_type *) calloc((size_t) knt,eachsize);
   if (item_arr==((cross_reference_entry_type *) NULL)) return;
   /*--------------------------------------------   read file */
   nnn=fread(item_arr,eachsize,(size_t) knt,xreffile);
   if (nnn!=knt) goto free_point;
   /*--------------------------------------------   sort */
   qsort((char *) item_arr,(size_t) knt,eachsize,cmp_xref_entries);
   /*--------------------------------------------   remove duplicates */
   for (nnn_less=nnn-1,iii_src=iii_dest=0;iii_src<nnn;++iii_dest){
      if (iii_src != iii_dest)
         sys_memcpy(item_arr+iii_dest,item_arr+iii_src,eachsize);
      while ((iii_src<nnn) &&
             (memcmp(item_arr+iii_dest,item_arr+iii_src,eachsize)==0))
         ++iii_src;}
   nnn=iii_dest;
   /*--------------------------------------------   print_map */
   for (iii=0;iii<nnn;++iii){
      item_iii = item_arr + iii;
      undcl=unset=unuse=TRUE;
      last_refcode = (*item_iii).refcode;
      NEW_XREF_LINE((*item_iii).name,xref_label(last_refcode));
      special = (Boolean) (*(*item_iii).name == '<');
      for (new_iii=iii-1,jjj=iii,kkk=0;jjj<nnn;++jjj,++kkk){
         new_iii=jjj;
         item_jjj = item_arr + jjj;
         curr_refcode = (*item_jjj).refcode;
         if (memcmp((*item_iii).name,(*item_jjj).name,XREF_ID_TRUNC_NCH)==0){
            XREF_FIX_UNSET_ETC(curr_refcode);
            if (last_refcode != curr_refcode){
               kkk=0;
               NEW_XREF_LINE(blankname,xref_label(curr_refcode));}
            if ((kkk>0)&&((kkk%5)==0)){
               NEW_XREF_LINE(blankname,"   ");}
            sprintf(enkpos,pos_fmt,
                    (int) (*item_jjj).linnum,(int) ((*item_jjj).pos+1),
                    blankname);
            *(enkpos+10) = '\0';
            fprintf(listfile,"%s",enkpos);}
         else{
            new_iii=jjj-1;
            jjj=nnn;}
         last_refcode = curr_refcode;}
      iii=new_iii;
      if (undcl && (!special)) { NEW_XREF_LINE(blankname,"*** UNDCL ***"); }
      if (unset && (!special)) { NEW_XREF_LINE(blankname,"*** UNSET ***"); }
      if (unuse && (!special)) { NEW_XREF_LINE(blankname,"*** UNUSE ***"); }
      fprintf(listfile,"\n");
      list_page_need_test_only(5); list_page_need(1);}
   /*--------------------------------------------   free */
free_point:
   free(item_arr);
   /*-------------------------------------------------------*/
}