comments/cosmetics;
fix UNREACHABLE def on unix; string_s: use HAVE_STRING_S; wdbg_sym: fix option set code; explain why search path isn't needed WriteScreenshot: make sure there's enough mem; use Handle to free mem (more efficient+less error prone) This was SVN commit r2779.
This commit is contained in:
parent
0bda64f8e4
commit
609be94b8c
@ -295,6 +295,8 @@
|
||||
#endif
|
||||
|
||||
// safe string functions: strcpy_s et al.
|
||||
// these are always available to users: if not provided by the CRT, we
|
||||
// implement them ourselves. this flag is only used to skip our impl.
|
||||
#if MSC_VERSION >= 1400
|
||||
# define HAVE_STRING_S 1
|
||||
#else
|
||||
|
@ -294,12 +294,13 @@ enum LibError
|
||||
// .. wrapped around the parameter name, e.g. void f(int UNUSED(x))
|
||||
#define UNUSED(param)
|
||||
|
||||
// indicates a piece of code cannot be reached (e.g. because all
|
||||
// control paths before it end up returning). this is mostly for
|
||||
// human benefit, but it may also help optimization.
|
||||
#if MSC_VERSION
|
||||
#define UNREACHABLE __assume(0)
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNREACHABLE 0
|
||||
# define UNREACHABLE __assume(0)
|
||||
#else
|
||||
# define UNREACHABLE
|
||||
#endif
|
||||
|
||||
#define ARRAY_SIZE(name) (sizeof(name) / sizeof(name[0]))
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef VFS_MOUNT_H__
|
||||
#define VFS_MOUNT_H__
|
||||
|
||||
#include "file.h"
|
||||
#include "zip.h"
|
||||
|
||||
extern void mount_init();
|
||||
extern void mount_shutdown();
|
||||
|
||||
@ -21,10 +24,6 @@ enum MountType
|
||||
};
|
||||
|
||||
|
||||
struct TFile;
|
||||
#include "file.h"
|
||||
#include "zip.h"
|
||||
|
||||
struct XIo
|
||||
{
|
||||
enum MountType type; // internal use only
|
||||
@ -37,6 +36,8 @@ struct XIo
|
||||
};
|
||||
|
||||
|
||||
struct TFile;
|
||||
|
||||
struct XFile
|
||||
{
|
||||
enum MountType type; // internal use only
|
||||
|
@ -1,12 +1,14 @@
|
||||
#ifndef STRINGS_S_H__
|
||||
#define STRINGS_S_H__
|
||||
#ifndef STRING_S_H__
|
||||
#define STRING_S_H__
|
||||
|
||||
#include "posix_types.h" // size_t
|
||||
#include "config.h"
|
||||
|
||||
// these are already shipped with VC2005
|
||||
#if MSC_VERSION < 1400
|
||||
// only declare these functions if using our implementation
|
||||
// (otherwise, we risk incompatibilities)
|
||||
#if !HAVE_STRING_S
|
||||
|
||||
// Conflicts with glibc definitions
|
||||
// (conflicts with glibc definitions)
|
||||
#if !OS_UNIX
|
||||
// return length [in characters] of a string, not including the trailing
|
||||
// null character. to protect against access violations, only the
|
||||
@ -52,7 +54,6 @@ extern int wcsncat_s(wchar_t* dst, size_t max_dst_chars, const wchar_t* src, siz
|
||||
extern int strcat_s(char* dst, size_t max_dst_chars, const char* src);
|
||||
extern int wcscat_s(wchar_t* dst, size_t max_dst_chars, const wchar_t* src);
|
||||
|
||||
#endif // #if !HAVE_STRING_S
|
||||
|
||||
#endif // #if MSC_VERSION < 1400
|
||||
|
||||
#endif // #ifndef STRINGS_S_H__
|
||||
#endif // #ifndef STRING_S_H__
|
||||
|
@ -125,8 +125,6 @@ static ULONG64 mod_base;
|
||||
// for StackWalk64; taken from PE header by wdbg_init.
|
||||
static WORD machine;
|
||||
|
||||
static const STACKFRAME64* current_stackframe64;
|
||||
|
||||
// call on-demand (allows handling exceptions raised before win.cpp
|
||||
// init functions are called); no effect if already initialized.
|
||||
static int sym_init()
|
||||
@ -138,10 +136,24 @@ static int sym_init()
|
||||
|
||||
hProcess = GetCurrentProcess();
|
||||
|
||||
SymSetOptions(SYMOPT_DEFERRED_LOADS/*/*|SYMOPT_DEBUG*/);
|
||||
// loads symbols for all active modules.
|
||||
BOOL ok = SymInitialize(hProcess, 0, TRUE);
|
||||
debug_assert(ok);
|
||||
// set options
|
||||
// notes:
|
||||
// - can be done before SymInitialize; we do so in case
|
||||
// any of the options affect it.
|
||||
// - do not set directly - that would zero any existing flags.
|
||||
DWORD opts = SymGetOptions();
|
||||
opts |= SYMOPT_DEFERRED_LOADS; // the "fastest, most efficient way"
|
||||
//opts |= SYMOPT_DEBUG; // lots of debug spew in output window
|
||||
SymSetOptions(opts);
|
||||
|
||||
// initialize dbghelp.
|
||||
// .. request symbols from all currently active modules be loaded.
|
||||
const BOOL fInvadeProcess = TRUE;
|
||||
// .. use default *symbol* search path. we don't use this to locate
|
||||
// our PDB file because its absolute path is stored inside the EXE.
|
||||
const char* UserSearchPath = 0;
|
||||
BOOL ok = SymInitialize(hProcess, UserSearchPath, fInvadeProcess);
|
||||
WARN_IF_FALSE(ok);
|
||||
|
||||
mod_base = SymGetModuleBase64(hProcess, (u64)&sym_init);
|
||||
IMAGE_NT_HEADERS* header = ImageNtHeader((void*)mod_base);
|
||||
@ -882,7 +894,7 @@ static int dump_array(const u8* p,
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const STACKFRAME64* current_stackframe64;
|
||||
|
||||
static int determine_symbol_address(DWORD id, DWORD UNUSED(type_id), const u8** pp)
|
||||
{
|
||||
|
@ -638,12 +638,12 @@ static int mmap_mem(void* start, size_t len, int prot, int flags, int fd, void**
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
BOOL ok = VirtualQuery(start, &mbi, len);
|
||||
debug_assert(ok); // todo4
|
||||
debug_assert(ok); // todo4
|
||||
DWORD state = mbi.State;
|
||||
if(state == MEM_COMMIT)
|
||||
{
|
||||
ok = VirtualFree(start, len, MEM_DECOMMIT);
|
||||
debug_assert(ok);
|
||||
debug_assert(ok);
|
||||
*pp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ static i64 ticks_lk()
|
||||
{
|
||||
LARGE_INTEGER i;
|
||||
BOOL ok = QueryPerformanceCounter(&i);
|
||||
debug_assert(ok); // shouldn't fail if it was chosen above
|
||||
WARN_IF_FALSE(ok); // shouldn't fail if it was chosen above
|
||||
return i.QuadPart;
|
||||
}
|
||||
#endif
|
||||
|
@ -191,7 +191,13 @@ void WriteScreenshot(const char* extension)
|
||||
|
||||
const size_t img_size = w * h * bpp/8;
|
||||
const size_t hdr_size = tex_hdr_size(fn);
|
||||
void* data = mem_alloc(hdr_size+img_size, FILE_BLOCK_SIZE);
|
||||
Handle img_hm;
|
||||
void* data = mem_alloc(hdr_size+img_size, FILE_BLOCK_SIZE, 0, &img_hm);
|
||||
if(!data)
|
||||
{
|
||||
debug_warn("not enough memory to write screenshot");
|
||||
return;
|
||||
}
|
||||
GLvoid* img = (u8*)data + hdr_size;
|
||||
|
||||
|
||||
@ -200,5 +206,5 @@ void WriteScreenshot(const char* extension)
|
||||
if(tex_write(fn, w, h, bpp, flags, img) < 0)
|
||||
debug_warn("WriteScreenshot: tex_write failed");
|
||||
|
||||
mem_free(img);
|
||||
mem_free_h(img_hm);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user