/* ----------------------------------------------------------------------- */ void mmu_load_env() { void *ptr = valloc_(8 * _Mb_); // alloc_init((size_t)malloc(2 * _Mb_), 2 * _Mb_); kSYS.mspace_ = KALLOC(kMemSpace_t); kSYS.scheduler_ = KALLOC(kScheduler_t); memset (ptr, 0, 8 * _Mb_); area_init(kSYS.mspace_, (size_t)ptr, 8 * _Mb_); }
static void test_blkdev_imfs_read_and_write(void) { rtems_status_code sc; int rv; ramdisk *rd; int fd; off_t off; rd = ramdisk_allocate(area_a, BLOCK_SIZE, BLOCK_COUNT, false); rtems_test_assert(rd != NULL); ramdisk_enable_free_at_delete_request(rd); sc = rtems_blkdev_create( rda, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd ); ASSERT_SC(sc); fd = open(rda, O_RDWR); rtems_test_assert(fd >= 0); area_init(area_a); area_read(fd, area_b); area_compare(area_a, area_b, true); off = lseek(fd, 0, SEEK_SET); rtems_test_assert(off == 0); area_init(area_b); area_write(fd, area_b); area_compare(area_a, area_b, false); rv = close(fd); rtems_test_assert(rv == 0); rv = unlink(rda); rtems_test_assert(rv == 0); area_compare(area_a, area_b, true); }
/* test functions */ static int test_area (AREA_CREATE_INFO * info, int nthreads, void *(*proc) (void *)) { #define MAX_THREADS 64 AREA *area = NULL; pthread_t threads[MAX_THREADS]; char msg[256]; int i; assert (info != NULL); sprintf (msg, "%s(size:%d, count:%d), %d threads", info->name, info->entry_size, info->alloc_cnt, nthreads); begin (msg); /* initialization */ if (nthreads > MAX_THREADS) { return fail ("too many threads"); } /* initialization */ area_init (); area = area_create (info->name, info->entry_size, info->alloc_cnt); if (area == NULL) { return fail ("area create fail"); } /* multithreaded test */ for (i = 0; i < nthreads; i++) { if (pthread_create (&threads[i], NULL, proc, (void *) area) != NO_ERROR) { return fail ("thread create"); } } for (i = 0; i < nthreads; i++) { void *retval; pthread_join (threads[i], &retval); if (retval != NO_ERROR) { return fail ("thread proc error"); } } /* results */ { AREA_BLOCKSET_LIST *blockset; AREA_BLOCK *block; int i, j, blockset_cnt = 0, block_cnt = 0, chunk_count; for (blockset = area->blockset_list; blockset != NULL; blockset = blockset->next) { for (i = 0; i < blockset->used_count; i++) { block = blockset->items[i]; assert (block != NULL); chunk_count = CEIL_PTVDIV (block->bitmap.entry_count, LF_BITFIELD_WORD_SIZE); for (j = 0; j < chunk_count; j++) { if (block->bitmap.bitfield[j]) { return fail ("check bitmap status"); } } block_cnt++; } blockset_cnt++; } printf (" Used %3d blocks(%2d blocksets). ", block_cnt, blockset_cnt); } /* destory */ area_destroy (area); area_final (); return success (); #undef MAX_THREADS }
/* ----------------------------------------------------------------------- */ void mmu_map_userspace(kMemSpace_t *sp) { void *ptr = valloc_(8 * _Mb_); memset (ptr, 0, 8 * _Mb_); area_init(sp, (size_t)ptr, 8 * _Mb_); }