- split up lib/res into file, graphics and sound.
- wposix.cpp: initial support for MEM_RESERVE and MEM_COMMIT semantics in mmap - cstr: removed no longer necessary serialization header - xmlutils: wrap new() calls in nommgr/mmgr; allows tracking other allocs in this file. - add u64_from_u32 - various minor comments/improvements. This was SVN commit r2604.
This commit is contained in:
parent
ac034f3733
commit
4aa740bff5
@ -2,7 +2,7 @@
|
||||
#define _MAPREADER_H
|
||||
|
||||
#include "MapIO.h"
|
||||
#include "res/handle.h"
|
||||
#include "lib/res/handle.h"
|
||||
#include "CStr.h"
|
||||
#include "LightEnv.h"
|
||||
#include "FileUnpacker.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib/types.h"
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
#include "MapWriter.h"
|
||||
#include "MapReader.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "ogl.h"
|
||||
#include "res/res.h"
|
||||
#include "lib/res/res.h"
|
||||
#include "Material.h"
|
||||
#include "Player.h"
|
||||
#include "Game.h"
|
||||
|
@ -9,7 +9,7 @@
|
||||
#ifndef _MINIPATCH_H
|
||||
#define _MINIPATCH_H
|
||||
|
||||
#include "res/handle.h"
|
||||
#include "lib/res/handle.h"
|
||||
|
||||
class CPatch;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "SkeletonAnimDef.h"
|
||||
#include "SkeletonAnimManager.h"
|
||||
#include "MeshManager.h"
|
||||
#include "lib/res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
#include "Profile.h"
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "ps/Xeromyces.h"
|
||||
#include "ps/XMLWriter.h"
|
||||
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "res/res.h"
|
||||
#include "lib/res/res.h"
|
||||
#include "Model.h"
|
||||
#include "CLogger.h"
|
||||
#include "SkeletonAnimManager.h"
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "Sprite.h"
|
||||
#include "Renderer.h"
|
||||
#include "ogl.h"
|
||||
#include "res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
|
||||
CSprite::CSprite() :
|
||||
m_texture(NULL)
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "res/ogl_tex.h"
|
||||
#include "res/mem.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
#include "lib/res/mem.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "Terrain.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#ifndef _TEXTURE_H
|
||||
#define _TEXTURE_H
|
||||
|
||||
#include "res/handle.h"
|
||||
#include "lib/res/handle.h"
|
||||
#include "CStr.h"
|
||||
|
||||
class CTexture
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "ogl.h"
|
||||
#include "res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
|
||||
#include "CLogger.h"
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "res/handle.h"
|
||||
#include "lib/res/handle.h"
|
||||
#include "CStr.h"
|
||||
|
||||
#include "TextureManager.h"
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "TerrainProperties.h"
|
||||
|
||||
#include "lib/res/res.h"
|
||||
#include "lib/res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/timer.h"
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "res/handle.h"
|
||||
#include "lib/res/handle.h"
|
||||
|
||||
#include "CStr.h"
|
||||
#include "Singleton.h"
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "res/res.h"
|
||||
#include "lib/res/res.h"
|
||||
#include "Model.h"
|
||||
#include "UnitManager.h"
|
||||
#include "Unit.h"
|
||||
|
@ -10,7 +10,7 @@ gee@pyro.nu
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "lib/res/unifont.h"
|
||||
#include "lib/res/graphics/unifont.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
|
@ -28,7 +28,7 @@ gee@pyro.nu
|
||||
#include "GUIutil.h"
|
||||
|
||||
#include "Overlay.h"
|
||||
#include "lib/res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
|
@ -13,7 +13,7 @@ gee@pyro.nu
|
||||
|
||||
// TODO Gee: new
|
||||
#include "OverlayText.h"
|
||||
#include "lib/res/unifont.h"
|
||||
#include "lib/res/graphics/unifont.h"
|
||||
|
||||
#include "ps/Hotkey.h"
|
||||
|
||||
|
@ -292,6 +292,14 @@ u32 u64_lo(u64 x)
|
||||
return (u32)(x & 0xffffffff);
|
||||
}
|
||||
|
||||
u64 u64_from_u32(u32 hi, u32 lo)
|
||||
{
|
||||
u64 x = (u64)hi;
|
||||
x <<= 32;
|
||||
x |= lo;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// input in [0, 1); convert to u8 range
|
||||
|
@ -350,6 +350,8 @@ extern uintptr_t round_up(uintptr_t val, uintptr_t multiple);
|
||||
extern u32 u64_hi(u64 x);
|
||||
extern u32 u64_lo(u64 x);
|
||||
|
||||
extern u64 u64_from_u32(u32 hi, u32 lo);
|
||||
|
||||
|
||||
extern u16 fp_to_u16(double in);
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
// remove all of mmgr.h's memory allocation "hooks" -
|
||||
// but only if we actually defined them!
|
||||
#if CONFIG_USE_MMGR || HAVE_VC_DEBUG_ALLOC
|
||||
|
||||
#undef new
|
||||
#undef delete
|
||||
#undef malloc
|
||||
#undef calloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
|
||||
#undef strdup
|
||||
#undef wcsdup
|
||||
#undef getcwd
|
||||
|
||||
# undef new
|
||||
# undef delete
|
||||
# undef malloc
|
||||
# undef calloc
|
||||
# undef realloc
|
||||
# undef free
|
||||
# undef strdup
|
||||
# undef wcsdup
|
||||
# undef getcwd
|
||||
#endif
|
||||
|
||||
// sanity check
|
||||
#ifdef new
|
||||
#error "nommgr.h - something is wrong, new is still defined"
|
||||
#endif
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "file.h"
|
||||
#include "detect.h"
|
||||
#include "adts.h"
|
@ -33,7 +33,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "zip.h"
|
||||
#include "file.h"
|
||||
#include "adts.h"
|
@ -1,5 +1,6 @@
|
||||
// virtual file system - transparent access to files in archives;
|
||||
// allows multiple mount points
|
||||
// this is the public interface.
|
||||
//
|
||||
// Copyright (c) 2004 Jan Wassenberg
|
||||
//
|
||||
@ -21,7 +22,6 @@
|
||||
|
||||
[KEEP IN SYNC WITH WIKI!]
|
||||
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
@ -47,9 +47,8 @@ Games typically encompass thousands of files. Such heavy loads expose
|
||||
|
||||
The solution is to put all files in archives: internal fragmentation is
|
||||
eliminated since they are packed end-to-end; open is much faster;
|
||||
seeks are avoided by arranging in order of access.
|
||||
|
||||
For more information, see 'Archive Details' below.
|
||||
seeks are avoided by arranging in order of access. For more information,
|
||||
see 'Archive Details' below.
|
||||
|
||||
Note that a good file system (Reiser3 comes close) could also deliver the
|
||||
above. However, this code is available now on all platforms; there is
|
||||
@ -67,11 +66,12 @@ Since decreases in edit cycle time improve productivity, we want changes to
|
||||
files to be picked up immediately. To that end, we support hotloading -
|
||||
as soon as the OS reports changes, all Handle objects that ensued from that
|
||||
file are reloaded.
|
||||
|
||||
The VFS's part in this is registering "watches" that report changes to
|
||||
any mounted real directory. Since the file notification backend
|
||||
(currently SGI FAM and a Win32 port) cannot watch an entire directory tree,
|
||||
we need to do so for every single directory. The VFS traverses and
|
||||
stores data for them anyway, we do so here.
|
||||
we need to do so for every single directory. The VFS traverses each and
|
||||
stores information anyway, so we do that here.
|
||||
|
||||
|
||||
Modding
|
||||
@ -186,9 +186,9 @@ Decompression is free because it is done in parallel with IOs.
|
||||
#ifndef __VFS_H__
|
||||
#define __VFS_H__
|
||||
|
||||
#include "handle.h" // Handle def
|
||||
#include "posix.h" // struct stat
|
||||
#include "file.h" // file open flags
|
||||
#include "../handle.h" // Handle def
|
||||
#include "lib/posix.h" // struct stat
|
||||
#include "file.h" // file open flags
|
||||
|
||||
// make the VFS tree ready for use. must be called before all other
|
||||
// functions below unless explicitly mentioned to be allowed.
|
@ -4,7 +4,7 @@
|
||||
#include "vfs_path.h"
|
||||
#include "vfs_tree.h"
|
||||
#include "zip.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
|
||||
struct Stats
|
||||
{
|
@ -1,8 +1,6 @@
|
||||
#ifndef VFS_MOUNT_H__
|
||||
#define VFS_MOUNT_H__
|
||||
|
||||
#include "handle.h"
|
||||
|
||||
extern void mount_init();
|
||||
extern void mount_shutdown();
|
||||
|
@ -8,10 +8,10 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "vfs_path.h"
|
||||
#include "vfs_tree.h"
|
||||
#include "hotload.h" // see NO_DIR_WATCH
|
||||
#include "../hotload.h" // see NO_DIR_WATCH
|
||||
|
||||
|
||||
// we add/cancel directory watches from the VFS mount code for convenience -
|
@ -36,7 +36,7 @@
|
||||
|
||||
#include "lib.h"
|
||||
#include "zip.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "byte_order.h"
|
||||
|
||||
#include "timer.h"
|
@ -19,7 +19,7 @@
|
||||
#ifndef ZIP_H__
|
||||
#define ZIP_H__
|
||||
|
||||
#include "handle.h"
|
||||
#include "../handle.h"
|
||||
#include "file.h" // FileCB for zip_enum
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "lib/ogl.h"
|
||||
#include "sysdep/sysdep.h" // sys_cursor_*
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "ogl_tex.h"
|
||||
#include "cursor.h"
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib.h"
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
|
||||
// must come before jpeg-6b headers.
|
@ -1,6 +1,6 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "ogl.h"
|
||||
#include "tex.h"
|
||||
#include "ogl_tex.h"
|
@ -1,7 +1,7 @@
|
||||
#ifndef OGL_TEX_H__
|
||||
#define OGL_TEX_H__
|
||||
|
||||
#include "handle.h"
|
||||
#include "../handle.h"
|
||||
|
||||
// load and return a handle to the texture given in <fn>.
|
||||
// supports RAW, BMP, JP2, PNG, TGA, DDS
|
@ -25,7 +25,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "tex.h"
|
||||
#include "byte_order.h"
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef __TEX_H__
|
||||
#define __TEX_H__
|
||||
|
||||
#include "handle.h"
|
||||
#include "../handle.h"
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ Unicode OpenGL texture font
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "../res.h"
|
||||
#include "ogl.h"
|
||||
#include "ogl_tex.h"
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <stdarg.h> // va_list
|
||||
|
||||
#include "handle.h"
|
||||
#include "../handle.h"
|
||||
|
||||
// Load and return a handle to the font defined
|
||||
// in fn+".fnt" with texture fn+".tga"
|
@ -19,7 +19,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "h_mgr.h"
|
||||
|
||||
|
||||
#include <limits.h> // CHAR_BIT
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "h_mgr.h"
|
||||
#include "mem.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "res.h"
|
||||
#include "file.h" // file_make_native_path, file_invalidate_cache
|
||||
#include "file/file.h" // file_make_native_path, file_invalidate_cache
|
||||
#include "timer.h"
|
||||
#include "hotload.h" // we implement that interface
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// common headers needed by lib/res code
|
||||
|
||||
#include "h_mgr.h"
|
||||
#include "vfs.h"
|
||||
#include "file/vfs.h"
|
||||
#include "mem.h"
|
||||
|
@ -18,9 +18,6 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "res/res.h"
|
||||
#include "res/snd.h"
|
||||
|
||||
#include <sstream> // to extract snd_open's definition file contents
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -45,6 +42,10 @@
|
||||
# include "sysdep/win/win_internal.h"
|
||||
#endif
|
||||
|
||||
#include "../res.h"
|
||||
#include "snd.h"
|
||||
|
||||
|
||||
|
||||
#define OGG_HACK
|
||||
#include "ogghack.h"
|
@ -19,7 +19,7 @@
|
||||
#ifndef SND_H__
|
||||
#define SND_H__
|
||||
|
||||
#include "handle.h"
|
||||
#include "../handle.h"
|
||||
|
||||
/*
|
||||
|
@ -81,15 +81,17 @@ enum ErrorReaction
|
||||
ER_EXIT
|
||||
};
|
||||
|
||||
extern ErrorReaction display_error_impl(const wchar_t* text, int flags);
|
||||
|
||||
extern ErrorReaction display_error(const wchar_t* text, int flags,
|
||||
extern ErrorReaction display_error(const wchar_t* description, int flags,
|
||||
uint skip, void* context, const char* file, int line);
|
||||
|
||||
// convenience version, in case the advanced parameters aren't needed.
|
||||
// done this way instead of with default values so that it also works in C.
|
||||
#define DISPLAY_ERROR(text) display_error(text, 0, 0, 0, __FILE__, __LINE__)
|
||||
|
||||
// internal use only (used by display_error)
|
||||
extern ErrorReaction display_error_impl(const wchar_t* text, int flags);
|
||||
|
||||
|
||||
|
||||
extern void display_msg(const char* caption, const char* msg);
|
||||
extern void wdisplay_msg(const wchar_t* caption, const wchar_t* msg);
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "detect.h"
|
||||
#include "lib.h"
|
||||
#include "lib/res/file.h" // file_enum
|
||||
#include "lib/res/file/file.h" // file_enum
|
||||
|
||||
#include "win_internal.h"
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "lib.h"
|
||||
#include "win_internal.h"
|
||||
#include "lib/res/file.h" // file_is_subpath
|
||||
#include "lib/res/file/file.h" // file_is_subpath
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// misc. POSIX routines for Win32
|
||||
//
|
||||
// Copyright (c) 2004 Jan Wassenberg
|
||||
// Copyright (c) 2004-2005 Jan Wassenberg
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
@ -16,23 +16,20 @@
|
||||
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
||||
// http://www.stud.uni-karlsruhe.de/~urkt/
|
||||
|
||||
// collection of hacks :P
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "posix.h"
|
||||
#include "win_internal.h"
|
||||
#include "sysdep/cpu.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
// cast intptr_t to HANDLE; centralized for easier changing, e.g. avoiding
|
||||
// warnings. i = -1 converts to INVALID_HANDLE_VALUE (same value).
|
||||
static HANDLE cast_to_HANDLE(intptr_t i)
|
||||
static HANDLE HANDLE_from_intptr(intptr_t i)
|
||||
{
|
||||
return (HANDLE)((char*)0 + i);
|
||||
}
|
||||
@ -75,10 +72,6 @@ int open(const char* fn, int oflag, ...)
|
||||
int fd = _open(fn, oflag, mode);
|
||||
WIN_RESTORE_LAST_ERROR;
|
||||
|
||||
#if CONFIG_PARANOIA
|
||||
debug_printf("open %s = %d\n", fn, fd);
|
||||
#endif
|
||||
|
||||
// cases when we don't want to open a second AIO-capable handle:
|
||||
// .. stdin/stdout/stderr
|
||||
if(fd <= 2)
|
||||
@ -93,7 +86,7 @@ debug_printf("open %s = %d\n", fn, fd);
|
||||
|
||||
// none of the above apply; now re-open the file.
|
||||
// note: this is possible because _open defaults to DENY_NONE sharing.
|
||||
aio_reopen(fd, fn, oflag);
|
||||
WARN_ERR(aio_reopen(fd, fn, oflag));
|
||||
|
||||
no_aio:
|
||||
|
||||
@ -110,17 +103,13 @@ no_aio:
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
#if CONFIG_PARANOIA
|
||||
debug_printf("close %d\n", fd);
|
||||
#endif
|
||||
|
||||
debug_assert(3 <= fd && fd < 256);
|
||||
|
||||
// note: there's no good way to notify us that <fd> wasn't opened for
|
||||
// AIO, so we could skip aio_close. storing a bit in the fd is evil and
|
||||
// a fd -> info map is redundant (waio already has one).
|
||||
// therefore, we require aio_close to fail gracefully.
|
||||
aio_close(fd);
|
||||
WARN_ERR(aio_close(fd));
|
||||
|
||||
return _close(fd);
|
||||
}
|
||||
@ -144,7 +133,7 @@ int write(int fd, void* buf, size_t nbytes)
|
||||
|
||||
int ioctl(int fd, int op, int* data)
|
||||
{
|
||||
const HANDLE h = cast_to_HANDLE(_get_osfhandle(fd));
|
||||
const HANDLE h = HANDLE_from_intptr(_get_osfhandle(fd));
|
||||
|
||||
switch(op)
|
||||
{
|
||||
@ -351,13 +340,13 @@ struct WDIR
|
||||
// low-level routine).
|
||||
|
||||
static WDIR global_wdir;
|
||||
static uintptr_t global_wdir_in_use;
|
||||
static uintptr_t global_wdir_is_in_use;
|
||||
|
||||
// zero-initializes the WDIR (code below relies on this)
|
||||
static inline WDIR* wdir_alloc()
|
||||
{
|
||||
// successfully reserved the global instance
|
||||
if(CAS(&global_wdir_in_use, 0, 1))
|
||||
if(CAS(&global_wdir_is_in_use, 0, 1))
|
||||
{
|
||||
memset(&global_wdir, 0, sizeof(global_wdir));
|
||||
return &global_wdir;
|
||||
@ -368,7 +357,7 @@ static inline WDIR* wdir_alloc()
|
||||
static inline void wdir_free(WDIR* d)
|
||||
{
|
||||
if(d == &global_wdir)
|
||||
global_wdir_in_use = 0;
|
||||
global_wdir_is_in_use = 0;
|
||||
else
|
||||
free(d);
|
||||
}
|
||||
@ -452,7 +441,7 @@ int readdir_stat_np(DIR* d_, struct stat* s)
|
||||
WDIR* d = (WDIR*)d_;
|
||||
|
||||
memset(s, 0, sizeof(struct stat));
|
||||
s->st_size = (off_t)((((u64)d->fd.nFileSizeHigh) << 32) | d->fd.nFileSizeLow);
|
||||
s->st_size = (off_t)u64_from_u32(d->fd.nFileSizeHigh, d->fd.nFileSizeLow);
|
||||
s->st_mode = (d->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
|
||||
s->st_mtime = filetime_to_time_t(&d->fd.ftLastWriteTime);
|
||||
return 0;
|
||||
@ -572,48 +561,58 @@ int mprotect(void* addr, size_t len, int prot)
|
||||
}
|
||||
|
||||
|
||||
// called when flags & MAP_ANONYMOUS
|
||||
static int map_mem(void* start, size_t len, int prot, int flags, int fd, void** pp)
|
||||
{
|
||||
// sanity checks. we don't care about these but enforce them to
|
||||
// ensure callers are compatible with mmap.
|
||||
// .. MAP_ANONYMOUS is documented to require this.
|
||||
debug_assert(fd == -1);
|
||||
// .. if MAP_SHARED, writes are to change "the underlying [mapped]
|
||||
// object", but there is none here (we're backed by the page file).
|
||||
debug_assert(flags & MAP_PRIVATE);
|
||||
|
||||
// see explanation at MAP_NORESERVE definition.
|
||||
DWORD flAllocationType = (flags & MAP_NORESERVE)? MEM_RESERVE : MEM_COMMIT;
|
||||
DWORD flProtect = win32_prot(prot);
|
||||
void* p = VirtualAlloc(start, len, flAllocationType, flProtect);
|
||||
if(!p)
|
||||
return ERR_NO_MEM;
|
||||
*pp = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// given mmap prot and flags, output protection/access values for use with
|
||||
// CreateFileMapping / MapViewOfFile. they only support read-only,
|
||||
// read/write and copy-on-write, so we dumb it down to that and later
|
||||
// set the correct (and more restrictive) permission via mprotect.
|
||||
static int mmap_access(int prot, int flags, DWORD& flProtect, DWORD& dwAccess, SECURITY_ATTRIBUTES*& psec)
|
||||
static int map_file_access(int prot, int flags, DWORD& flProtect, DWORD& dwAccess)
|
||||
{
|
||||
SECURITY_ATTRIBUTES* saved_psec = psec;
|
||||
|
||||
// assume read-only with default security; other cases handled below.
|
||||
// assume read-only; other cases handled below.
|
||||
flProtect = PAGE_READONLY;
|
||||
dwAccess = FILE_MAP_READ;
|
||||
psec = 0;
|
||||
// we go to a bit of trouble and return a NULL pointer in the
|
||||
// default case; this is more efficient.
|
||||
|
||||
if(prot & PROT_WRITE)
|
||||
{
|
||||
flProtect = PAGE_READWRITE;
|
||||
dwAccess = FILE_MAP_WRITE; // read and write
|
||||
|
||||
// determine write behavior: (whether they change the underlying file)
|
||||
switch(flags & (MAP_SHARED|MAP_PRIVATE))
|
||||
{
|
||||
// .. POSIX says asking for both isn't allowed.
|
||||
case MAP_SHARED|MAP_PRIVATE:
|
||||
return ERR_INVALID_PARAM;
|
||||
// .. changes are written to file and shared between processes.
|
||||
// .. changes are written to file.
|
||||
case MAP_SHARED:
|
||||
psec = saved_psec;
|
||||
psec->nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
psec->lpSecurityDescriptor = 0;
|
||||
psec->bInheritHandle = TRUE;
|
||||
flProtect = PAGE_READWRITE;
|
||||
dwAccess = FILE_MAP_WRITE; // read and write
|
||||
break;
|
||||
// .. copy-on-write mapping; writes do not affect the file or
|
||||
// other processes.
|
||||
// .. copy-on-write mapping; writes do not affect the file.
|
||||
case MAP_PRIVATE:
|
||||
flProtect = PAGE_WRITECOPY;
|
||||
dwAccess = FILE_MAP_COPY;
|
||||
break;
|
||||
// .. changes are written to file but the handle isn't shareable.
|
||||
// .. either none or both of the flags are set. the latter is
|
||||
// definitely illegal according to POSIX and some man pages
|
||||
// say exactly one must be set, so abort.
|
||||
default:
|
||||
break;
|
||||
return ERR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,80 +620,88 @@ static int mmap_access(int prot, int flags, DWORD& flProtect, DWORD& dwAccess, S
|
||||
}
|
||||
|
||||
|
||||
void* mmap(void* user_start, size_t len, int prot, int flags, int fd, off_t ofs)
|
||||
static int map_file(void* start, size_t len, int prot, int flags,
|
||||
int fd, off_t ofs, void** pp)
|
||||
{
|
||||
{
|
||||
debug_assert(fd != -1); // handled by mmap_mem
|
||||
|
||||
WIN_SAVE_LAST_ERROR;
|
||||
int err;
|
||||
|
||||
// assume fd = -1 (requesting mapping backed by page file),
|
||||
// so that we notice invalid file handles below.
|
||||
HANDLE hFile = INVALID_HANDLE_VALUE;
|
||||
if(fd != -1)
|
||||
{
|
||||
hFile = cast_to_HANDLE(_get_osfhandle(fd));
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
debug_warn("mmap: invalid file handle");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
HANDLE hFile = HANDLE_from_intptr(_get_osfhandle(fd));
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
return ERR_INVALID_PARAM;
|
||||
|
||||
// if MAP_FIXED, user_start is the start address; otherwise,
|
||||
// MapViewOfFileEx will choose an address.
|
||||
void* start = 0;
|
||||
if(flags & MAP_FIXED)
|
||||
{
|
||||
start = user_start;
|
||||
if(start == 0) // debug_assert below would fire
|
||||
goto fail;
|
||||
}
|
||||
// MapViewOfFileEx will fail if the "suggested" base address is
|
||||
// nonzero but cannot be honored, so wipe out <start> unless MAP_FIXED.
|
||||
if(!(flags & MAP_FIXED))
|
||||
start = 0;
|
||||
|
||||
// choose protection and access rights for CreateFileMapping /
|
||||
// MapViewOfFile. these are weaker than what PROT_* allows and
|
||||
// are augmented below by subsequently mprotect-ing.
|
||||
DWORD flProtect; DWORD dwAccess;
|
||||
SECURITY_ATTRIBUTES sec_; SECURITY_ATTRIBUTES* psec = &sec_;
|
||||
err = mmap_access(prot, flags, flProtect, dwAccess, psec);
|
||||
if(err < 0)
|
||||
goto fail;
|
||||
RETURN_ERR(map_file_access(prot, flags, flProtect, dwAccess));
|
||||
|
||||
// enough foreplay; now actually map.
|
||||
// .. split size/offset into 32 bit values for the API.
|
||||
// careful! C++ doesn't allow shifting 32-bit types by 32 bits.
|
||||
const DWORD len_hi = u64_hi(len), len_lo = u64_lo(len);
|
||||
const DWORD ofs_hi = u64_hi(ofs), ofs_lo = u64_lo(ofs);
|
||||
const HANDLE hMap = CreateFileMapping(hFile, psec, flProtect, len_hi, len_lo, (LPCSTR)0);
|
||||
const HANDLE hMap = CreateFileMapping(hFile, 0, flProtect, 0, 0, (LPCSTR)0);
|
||||
// .. create failed; bail now to avoid overwriting the last error value.
|
||||
if(!hMap)
|
||||
goto fail;
|
||||
void* addr = MapViewOfFileEx(hMap, dwAccess, ofs_hi, ofs_lo, (SIZE_T)len, start);
|
||||
return ERR_NO_MEM;
|
||||
const DWORD ofs_hi = u64_hi(ofs), ofs_lo = u64_lo(ofs);
|
||||
void* p = MapViewOfFileEx(hMap, dwAccess, ofs_hi, ofs_lo, (SIZE_T)len, start);
|
||||
// .. make sure we got the requested address if MAP_FIXED was passed.
|
||||
debug_assert(!(flags & MAP_FIXED) || (addr == start));
|
||||
debug_assert(!(flags & MAP_FIXED) || (p == start));
|
||||
// .. free the mapping object now, so that we don't have to hold on to its
|
||||
// handle until munmap(). it's not actually released yet due to the
|
||||
// reference held by MapViewOfFileEx (if it succeeded).
|
||||
CloseHandle(hMap);
|
||||
// .. map failed; bail now to avoid "restoring" the last error value.
|
||||
if(!addr)
|
||||
goto fail;
|
||||
if(!p)
|
||||
return ERR_NO_MEM;
|
||||
|
||||
// slap on correct (more restrictive) permissions.
|
||||
WARN_ERR(mprotect(addr, len, prot));
|
||||
WARN_ERR(mprotect(p, len, prot));
|
||||
|
||||
WIN_RESTORE_LAST_ERROR;
|
||||
return addr;
|
||||
*pp = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void* mmap(void* start, size_t len, int prot, int flags, int fd, off_t ofs)
|
||||
{
|
||||
void* p;
|
||||
int err;
|
||||
if(flags & MAP_ANONYMOUS)
|
||||
err = map_mem(start, len, prot, flags, fd, &p);
|
||||
else
|
||||
err = map_file(start, len, prot, flags, fd, ofs, &p);
|
||||
if(err < 0)
|
||||
{
|
||||
WARN_ERR(err);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
fail:
|
||||
return (void*)MAP_FAILED;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
int munmap(void* start, size_t UNUSED(len))
|
||||
{
|
||||
// UnmapViewOfFile checks if start was returned by MapViewOfFile*;
|
||||
// if not, it will fail.
|
||||
BOOL ok = UnmapViewOfFile(start);
|
||||
return ok? 0 : -1;
|
||||
if(!ok)
|
||||
// VirtualFree requires dwSize to be 0 (entire region is released).
|
||||
ok = VirtualFree(start, 0, MEM_RELEASE);
|
||||
|
||||
// both failed
|
||||
if(!ok)
|
||||
{
|
||||
debug_warn("munmap failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -203,9 +203,20 @@ extern int readdir_stat_np(DIR*, struct stat*);
|
||||
#define PROT_EXEC 0x04
|
||||
|
||||
// mmap flags
|
||||
#define MAP_SHARED 0x01 // share changes across processes
|
||||
#define MAP_PRIVATE 0x02 // private copy-on-write mapping
|
||||
#define MAP_SHARED 0x01 // writes change the underlying file
|
||||
#define MAP_PRIVATE 0x02 // writes do not affect the file (copy-on-write)
|
||||
#define MAP_FIXED 0x04
|
||||
// .. non-portable
|
||||
#define MAP_ANONYMOUS 0x10
|
||||
#define MAP_NORESERVE 0x20
|
||||
|
||||
// note: we need a means of only "reserving" virtual address ranges
|
||||
// for the fixed-address expandable array mechanism. the non-portable
|
||||
// MAP_NORESERVE flag says that no space in the page file need be reserved.
|
||||
// the caller can still try to access the entire mapping, but might get
|
||||
// SIGBUS if there isn't enough room to commit a page. Linux currently
|
||||
// doesn't commit mmap-ed regions anyway, but we specify this flag to
|
||||
// make sure of that in the future.
|
||||
|
||||
#define MAP_FAILED 0
|
||||
|
||||
|
@ -18,10 +18,10 @@
|
||||
#include "lib/timer.h"
|
||||
#include "lib/input.h"
|
||||
#include "lib/res/res.h"
|
||||
#include "lib/res/tex.h"
|
||||
#include "lib/res/snd.h"
|
||||
#include "lib/res/hotload.h"
|
||||
#include "lib/res/cursor.h"
|
||||
#include "lib/res/hotload.h" // xxx
|
||||
#include "lib/res/sound/snd.h"
|
||||
#include "lib/res/graphics/tex.h"
|
||||
#include "lib/res/graphics/cursor.h"
|
||||
|
||||
#include "ps/Profile.h"
|
||||
#include "ps/ProfileViewer.h"
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "Network/Client.h"
|
||||
#include "Network/Server.h"
|
||||
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
#include "Interact.h"
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
#include "res/unifont.h"
|
||||
#include "lib/res/graphics/unifont.h"
|
||||
#include "ogl.h"
|
||||
#include "lib.h"
|
||||
#include "sdl.h"
|
||||
|
@ -64,8 +64,6 @@ enum PS_TRIM_MODE { PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH };
|
||||
#include <string>
|
||||
#include "ps/utf16string.h"
|
||||
|
||||
#include "Network/Serialization.h"
|
||||
|
||||
class CStr8;
|
||||
class CStrW;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "CVFSFile.h"
|
||||
|
||||
#include "lib/res/mem.h"
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
#define LOG_CATEGORY "file"
|
||||
|
@ -4,11 +4,9 @@
|
||||
#include "Parser.h"
|
||||
#include "ConfigDB.h"
|
||||
#include "CLogger.h"
|
||||
#include "res/vfs.h"
|
||||
#include "res/file.h"
|
||||
#include "res/mem.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
#include "lib/res/mem.h"
|
||||
#include "scripting/ScriptingHost.h"
|
||||
#include "lib/types.h"
|
||||
|
||||
#define LOG_CATEGORY "config"
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "FileUnpacker.h"
|
||||
#include "res/res.h"
|
||||
#include "lib/res/res.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CFileUnpacker constructor
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "Font.h"
|
||||
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "lib/res/unifont.h"
|
||||
#include "lib/res/graphics/unifont.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#define LOG_CATEGORY "graphics"
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "ProfileViewer.h"
|
||||
#include "Profile.h"
|
||||
#include "Renderer.h"
|
||||
#include "res/unifont.h"
|
||||
#include "lib/res/graphics/unifont.h"
|
||||
#include "Hotkey.h"
|
||||
|
||||
bool profileVisible = false;
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "VFSUtil.h"
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/vfs_path.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
#include "CLogger.h"
|
||||
#define LOG_CATEGORY "vfs"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "ps/CStr.h"
|
||||
#include "res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
namespace VFSUtil
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
XMLUtils.h - Xerces wrappers & convenience functions
|
||||
XML.h - Xerces wrappers & convenience functions
|
||||
|
||||
AUTHOR : Simon Brenner <simon@wildfiregames.com>, <simon.brenner@home.se>
|
||||
EXAMPLE :
|
||||
|
@ -1,15 +1,12 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "nommgr.h"
|
||||
#include "XML.h"
|
||||
#include "nommgr.h" // undefine 'new' a lot, because Xerces doesn't like it
|
||||
|
||||
#include "CStr.h"
|
||||
#include "CLogger.h"
|
||||
#include "posix.h" // ptrdiff_t
|
||||
|
||||
#include "res/vfs.h"
|
||||
#include "res/mem.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
#include "lib/res/mem.h"
|
||||
|
||||
#define LOG_CATEGORY "xml"
|
||||
|
||||
@ -89,8 +86,10 @@ BinInputStream *CVFSInputSource::makeStream() const
|
||||
{
|
||||
if (m_pBuffer > 0)
|
||||
{
|
||||
#include "nommgr.h"
|
||||
return new BinMemInputStream((XMLByte *)m_pBuffer, (unsigned int)m_BufferSize,
|
||||
BinMemInputStream::BufOpt_Reference);
|
||||
#include "mmgr.h"
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
@ -111,7 +110,9 @@ const char *prevpathcomp(const char *end, const char *beginning)
|
||||
InputSource *CVFSEntityResolver::resolveEntity(const XMLCh *const UNUSED(publicId),
|
||||
const XMLCh *const systemId)
|
||||
{
|
||||
#include "nommgr.h"
|
||||
CVFSInputSource *ret=new CVFSInputSource();
|
||||
#include "mmgr.h"
|
||||
char *path=XMLString::transcode(systemId);
|
||||
char *orgpath=path;
|
||||
|
||||
@ -156,8 +157,9 @@ InputSource *CVFSEntityResolver::resolveEntity(const XMLCh *const UNUSED(publicI
|
||||
path=abspath;
|
||||
}
|
||||
|
||||
// janwas: removed for less spew
|
||||
// LOG(NORMAL, LOG_CATEGORY, "EntityResolver: path \"%s\" translated to \"%s\"", orgpath, path);
|
||||
// janwas: less spew
|
||||
|
||||
|
||||
char *pos=path;
|
||||
if ((pos=strchr(pos, '\\')) != NULL)
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "XMLWriter.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
// TODO (maybe): Write to the VFS handle frequently, instead of buffering
|
||||
// the entire file, so that large files get written faster.
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "ps/Xeromyces.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "lib/res/vfs.h"
|
||||
#include "lib/res/file/vfs.h"
|
||||
|
||||
#define ZLIB_DLL
|
||||
#include "zlib.h" // for crc32
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include "res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
#include "Renderer.h"
|
||||
#include "TransparencyRenderer.h"
|
||||
#include "PlayerRenderer.h"
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include "Pyrogenesis.h"
|
||||
#include "res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
#include "Renderer.h"
|
||||
#include "PatchRData.h"
|
||||
#include "AlphaMapCalculator.h"
|
||||
|
@ -34,9 +34,9 @@
|
||||
#include "ModelDef.h"
|
||||
|
||||
#include "ogl.h"
|
||||
#include "res/mem.h"
|
||||
#include "res/tex.h"
|
||||
#include "res/ogl_tex.h"
|
||||
#include "lib/res/mem.h"
|
||||
#include "lib/res/graphics/tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define LOG_CATEGORY "graphics"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#define _VERTEXBUFFER_H
|
||||
|
||||
#include "lib.h"
|
||||
#include "res/ogl_tex.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "Profile.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
#include "res/res.h"
|
||||
#include "lib/res/res.h"
|
||||
|
||||
|
||||
#ifdef NDEBUG
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "JSI_Sound.h"
|
||||
#include "Vector3D.h"
|
||||
|
||||
#include "lib/res/snd.h"
|
||||
#include "lib/res/sound/snd.h"
|
||||
#include "lib/res/h_mgr.h" // h_filename
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user