Пример #1
0
void vmem_unmapfile()
{
    dbg_printf("vmem_unmapfile()\n");

    vmem_decommit(preserve,preserve_size);
    vmem_release(preserve,preserve_size);
    preserve = NULL;
    preserve_size = 0;

#if 0
    if (pview)
    {   int i;

        i = UnmapViewOfFile(pview);
        dbg_printf("i = x%x\n",i);
        if (i == FALSE)
            os_error();
    }
#else
    // Note that under Windows 95, UnmapViewOfFile() seems to return random
    // values, not TRUE or FALSE.
    if (pview && UnmapViewOfFile(pview) == FALSE)
        os_error();
#endif
    pview = NULL;

    if (hFileMap != NULL && CloseHandle(hFileMap) != TRUE)
        os_error();
    hFileMap = NULL;

    if (hFile != INVALID_HANDLE_VALUE && CloseHandle(hFile) != TRUE)
        os_error();
    hFile = INVALID_HANDLE_VALUE;
}
Пример #2
0
static void
umem_release(void)
{
#ifdef ZVM_ENABLE
	umem_cache_t *cp;

	vmem_release();
	vmem_sbrk_release();

	umem_release_log_header(umem_slab_log);
	umem_release_log_header(umem_failure_log);
	umem_release_log_header(umem_content_log);
	umem_release_log_header(umem_transaction_log);

	for (cp = umem_null_cache.cache_next; cp != &umem_null_cache;
	    cp = cp->cache_next)
		umem_release_cache(cp);
	umem_release_cache(&umem_null_cache);

	(void) mutex_unlock(&umem_flags_lock);
	(void) mutex_unlock(&umem_update_lock);
	(void) mutex_unlock(&umem_cache_lock);
	(void) mutex_unlock(&umem_init_lock);
#endif //ZVM_ENABLE
}
Пример #3
0
void *vmem_mapfile(const char *filename,void *ptr,unsigned long size,int flag)
{
    OSVERSIONINFO OsVerInfo;

    OsVerInfo.dwOSVersionInfoSize = sizeof(OsVerInfo);
    GetVersionEx(&OsVerInfo);

    dbg_printf("vmem_mapfile(filename = '%s', ptr = %p, size = x%lx, flag = %d)\n",filename,ptr,size,flag);

    hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
                        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
        goto L1;                        // failure
    dbg_printf(" file created\n");

    // Windows 95 does not implement PAGE_WRITECOPY (unfortunately treating
    // it just like PAGE_READWRITE).
    if (flag == 1 && OsVerInfo.dwPlatformId == 1)       // Windows 95, 98, ME
        hFileMap = NULL;
    else
        hFileMap = CreateFileMapping(hFile,NULL,
                (flag == 1) ? PAGE_WRITECOPY : PAGE_READWRITE,0,size,NULL);

    if (hFileMap == NULL)               // mapping failed
    {
#if 1
        // Win32s seems to always fail here.
        DWORD nbytes;

        dbg_printf(" mapping failed\n");
        // If it was NT failing, assert.
        assert(OsVerInfo.dwPlatformId != VER_PLATFORM_WIN32_NT);

        // To work around, just read the file into memory.
        assert(flag == 1);
        preserve = vmem_reserve(ptr,size);
        if (!preserve)
            goto L2;
        if (!vmem_commit(preserve,size))
        {
            vmem_release(preserve,size);
            preserve = NULL;
            goto L2;
        }
        preserve_size = size;
        if (!ReadFile(hFile,preserve,size,&nbytes,NULL))
            os_error();
        assert(nbytes == size);
        if (CloseHandle(hFile) != TRUE)
            os_error();
        hFile = INVALID_HANDLE_VALUE;
        return preserve;
#else
        // Instead of working around, we should find out why it failed.
        os_error();
#endif
    }
    else
    {
        dbg_printf(" mapping created\n");
        pview = MapViewOfFileEx(hFileMap,flag ? FILE_MAP_COPY : FILE_MAP_WRITE,
                0,0,size,ptr);
        if (pview == NULL)                      // mapping view failed
        {   //os_error();
            goto L3;
        }
    }
    dbg_printf(" pview = %p\n",pview);

    return pview;

Terminate:
    if (UnmapViewOfFile(pview) == FALSE)
        os_error();
    pview = NULL;
L3:
    if (CloseHandle(hFileMap) != TRUE)
        os_error();
    hFileMap = NULL;
L2:
    if (CloseHandle(hFile) != TRUE)
        os_error();
    hFile = INVALID_HANDLE_VALUE;
L1:
    return NULL;                        // failure
}
Пример #4
0
static void
umem_do_release(int as_child)
{
	umem_cache_t *cp;
	int cleanup_update = 0;

	/*
	 * Clean up the update state if we are the child process and
	 * another thread was processing updates.
	 */
	if (as_child) {
		if (umem_update_thr != thr_self()) {
			umem_update_thr = 0;
			cleanup_update = 1;
		}
		if (umem_st_update_thr != thr_self()) {
			umem_st_update_thr = 0;
			cleanup_update = 1;
		}
	}

	if (cleanup_update) {
		umem_reaping = UMEM_REAP_DONE;

		for (cp = umem_null_cache.cache_next; cp != &umem_null_cache;
		    cp = cp->cache_next) {
			if (cp->cache_uflags & UMU_NOTIFY)
				cp->cache_uflags &= ~UMU_NOTIFY;

			/*
			 * If the cache is active, we just re-add it to
			 * the update list.  This will re-do any active
			 * updates on the cache, but that won't break
			 * anything.
			 *
			 * The worst that can happen is a cache has
			 * its magazines rescaled twice, instead of once.
			 */
			if (cp->cache_uflags & UMU_ACTIVE) {
				umem_cache_t *cnext, *cprev;

				ASSERT(cp->cache_unext == NULL &&
				    cp->cache_uprev == NULL);

				cp->cache_uflags &= ~UMU_ACTIVE;
				cp->cache_unext = cnext = &umem_null_cache;
				cp->cache_uprev = cprev =
				    umem_null_cache.cache_uprev;
				cnext->cache_uprev = cp;
				cprev->cache_unext = cp;
			}
		}
	}

	umem_release_log_header(umem_slab_log);
	umem_release_log_header(umem_failure_log);
	umem_release_log_header(umem_content_log);
	umem_release_log_header(umem_transaction_log);

	for (cp = umem_null_cache.cache_next; cp != &umem_null_cache;
	    cp = cp->cache_next)
		umem_release_cache(cp);
	umem_release_cache(&umem_null_cache);

	(void) mutex_unlock(&umem_flags_lock);
	(void) mutex_unlock(&umem_update_lock);
	(void) mutex_unlock(&umem_cache_lock);

	vmem_sbrk_release();
	vmem_release();

	(void) mutex_unlock(&umem_init_lock);
}