static errno_t startSync( phantom_disk_partition_t *p, void *to, long blockNo, int nBlocks, int isWrite ) { assert( p->block_size < PAGE_SIZE ); SHOW_FLOW( 3, "blk %d", blockNo ); pager_io_request rq; pager_io_request_init( &rq ); rq.phys_page = (physaddr_t)phystokv(to); // why? redundant? rq.disk_page = blockNo; rq.blockNo = blockNo; rq.nSect = nBlocks; rq.rc = 0; if(isWrite) rq.flag_pageout = 1; else rq.flag_pagein = 1; STAT_INC_CNT(STAT_CNT_BLOCK_SYNC_IO); STAT_INC_CNT( STAT_CNT_DISK_Q_SIZE ); // Will decrement on io done void *va; hal_pv_alloc( &rq.phys_page, &va, nBlocks * p->block_size ); errno_t ret = EINVAL; if(isWrite) memcpy( va, to, nBlocks * p->block_size ); int ei = hal_save_cli(); hal_spin_lock(&(rq.lock)); rq.flag_sleep = 1; // Don't return until done rq.sleep_tid = GET_CURRENT_THREAD()->tid; SHOW_FLOW0( 3, "start io" ); if( (ret = p->asyncIo( p, &rq )) ) { rq.flag_sleep = 0; hal_spin_unlock(&(rq.lock)); if( ei ) hal_sti(); //return ret; goto ret; } thread_block( THREAD_SLEEP_IO, &(rq.lock) ); SHOW_FLOW0( 3, "unblock" ); if( ei ) hal_sti(); if(!isWrite) memcpy( to, va, nBlocks * p->block_size ); ret = rq.rc; //return partAsyncIo( p, &rq ); //return p->asyncIo( p, rq ); ret: hal_pv_free( rq.phys_page, va, nBlocks * p->block_size ); return ret; }
void disk_page_io_release(disk_page_io *me) { if( me->req.flag_pagein || me->req.flag_pageout ) panic("disk_page_cacher_release: operation is in progress"); if(!me->mem_allocated) return; hal_pv_free( me->req.phys_page, me->mem, PAGE_SIZE ); me->mem_allocated = 0; }
// Called on proc death in proc mutex, so - interlocked static void uu_unlink_exe_module( struct exe_module *em ) { assert(em); assert(em->refcount > 0); em->refcount--; if(em->refcount > 0) return; hal_pv_free( em->pa, em->mem_start, em->mem_size ); free(em); }
int do_test_physmem(const char *test_parm) { (void) test_parm; #if !defined(ARCH_arm) void *va; physaddr_t pa; char buf[MSIZE]; hal_pv_alloc( &pa, &va, MSIZE ); test_check_true( va != 0 ); test_check_true( pa != 0 ); memset( va, 0, MSIZE ); memcpy_p2v( buf, pa, MSIZE ); if( memnotchar( buf, 0, MSIZE ) ) test_fail_msg( EINVAL, "not 0"); memset( buf, 0xFF, MSIZE ); memcpy_v2p( pa, buf, MSIZE ); if( memnotchar( va, 0xFF, MSIZE ) ) test_fail_msg( EINVAL, "not 1"); memset( va, 0, MSIZE ); memcpy_v2p( pa, "AAA", 3 ); if( memnotchar( va, 'A', 3 ) ) test_fail_msg( EINVAL, "not A"); if( memnotchar( va+3, 0, MSIZE-3 ) ) test_fail_msg( EINVAL, "not A0"); memset( va, 0, MSIZE ); memcpy_v2p( pa+10, "BBB", 3 ); if( memnotchar( va+10, 'B', 3 ) ) test_fail_msg( EINVAL, "not B"); if( memnotchar( va, 0, 10 ) ) test_fail_msg( EINVAL, "not B0-"); if( memnotchar( va+13, 0, MSIZE-13 ) ) test_fail_msg( EINVAL, "not B0+"); // Cross page memset( va, 0, MSIZE ); #define SH (4096-4) memcpy_v2p( pa+SH, "EEEEEEEE", 8 ); if( memnotchar( va+SH, 'E', 8 ) ) test_fail_msg( EINVAL, "not E"); if( memnotchar( va, 0, SH ) ) test_fail_msg( EINVAL, "not E0-"); if( memnotchar( va+SH+8, 0, MSIZE-SH-8 ) ) test_fail_msg( EINVAL, "not E0+"); #if 0 // not impl memset( va, 0, MSIZE ); memset( va+20, 'C', 3 ); memcpy_p2v( buf, pa+20, 3 ); if( memnotchar( buf, 'C', 3 ) ) test_fail_msg( EINVAL, "not C"); #endif hal_pv_free( pa, va, MSIZE ); #endif //!defined(ARCH_arm) return 0; }