Fixed crash in MemoryUtils::ResolveSymbol() on OS X Lion (10.7) (bug 4951, r=dvander).
authorScott Ehlert <ds@alliedmods.net>
Wed Jun 15 16:02:05 2011 -0500 (2011-06-15)
changeset 3295598bf07e4d51
parent 3294 eb106d53ce40
child 3296 ea7a39d638f2
Fixed crash in MemoryUtils::ResolveSymbol() on OS X Lion (10.7) (bug 4951, r=dvander).
core/logic/AMBuilder
core/logic/MemoryUtils.cpp
core/logic/MemoryUtils.h
core/logic/common_logic.cpp
     1.1 --- a/core/logic/AMBuilder	Sun Jun 05 23:13:25 2011 -0400
     1.2 +++ b/core/logic/AMBuilder	Wed Jun 15 16:02:05 2011 -0500
     1.3 @@ -12,6 +12,8 @@
     1.4  
     1.5  if AMBuild.target['platform'] == 'linux':
     1.6  	compiler['POSTLINKFLAGS'].append('-lpthread')
     1.7 +if AMBuild.target['platform'] == 'darwin':
     1.8 +	compiler['POSTLINKFLAGS'].extend(['-framework', 'CoreServices'])
     1.9  
    1.10  extension = AMBuild.AddJob('sourcemod.logic')
    1.11  binary = Cpp.LibraryBuilder('sourcemod.logic', AMBuild, extension, compiler)
     2.1 --- a/core/logic/MemoryUtils.cpp	Sun Jun 05 23:13:25 2011 -0400
     2.2 +++ b/core/logic/MemoryUtils.cpp	Wed Jun 15 16:02:05 2011 -0500
     2.3 @@ -2,7 +2,7 @@
     2.4   * vim: set ts=4 sw=4 tw=99 noet :
     2.5   * =============================================================================
     2.6   * SourceMod
     2.7 - * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
     2.8 + * Copyright (C) 2004-2011 AlliedModders LLC.  All rights reserved.
     2.9   * =============================================================================
    2.10   *
    2.11   * This program is free software; you can redistribute it and/or modify it under
    2.12 @@ -36,11 +36,26 @@
    2.13  #define PAGE_SIZE			4096
    2.14  #define PAGE_ALIGN_UP(x)	((x + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
    2.15  #endif
    2.16 +
    2.17  #ifdef PLATFORM_APPLE
    2.18 +#include <AvailabilityMacros.h>
    2.19 +#include <mach/task.h>
    2.20  #include <mach-o/dyld_images.h>
    2.21  #include <mach-o/loader.h>
    2.22  #include <mach-o/nlist.h>
    2.23 -#endif
    2.24 +
    2.25 +/* Define things from 10.6 SDK for older SDKs */
    2.26 +#ifndef MAC_OS_X_VERSION_10_6
    2.27 +struct task_dyld_info
    2.28 +{
    2.29 +	mach_vm_address_t all_image_info_addr;
    2.30 +	mach_vm_size_t all_image_info_size;
    2.31 +};
    2.32 +typedef struct task_dyld_info task_dyld_info_data_t;
    2.33 +#define TASK_DYLD_INFO 17
    2.34 +#define TASK_DYLD_INFO_COUNT (sizeof(task_dyld_info_data_t) / sizeof(natural_t))
    2.35 +#endif // MAC_OS_X_VERSION_10_6
    2.36 +#endif // PLATFORM_APPLE
    2.37  
    2.38  MemoryUtils g_MemUtils;
    2.39  
    2.40 @@ -48,12 +63,25 @@
    2.41  {
    2.42  #ifdef PLATFORM_APPLE
    2.43  
    2.44 +	Gestalt(gestaltSystemVersionMajor, &m_OSXMajor);
    2.45 +	Gestalt(gestaltSystemVersionMinor, &m_OSXMinor);
    2.46 +
    2.47  	/* Get pointer to struct that describes all loaded mach-o images in process */
    2.48 -	struct nlist list[2];
    2.49 -	memset(list, 0, sizeof(list));
    2.50 -	list[0].n_un.n_name = (char *)"_dyld_all_image_infos";
    2.51 -	nlist("/usr/lib/dyld", list);
    2.52 -	m_ImageList = (struct dyld_all_image_infos *)list[0].n_value;
    2.53 +	if (m_OSXMajor == 10 && m_OSXMinor >= 6 || m_OSXMajor > 10)
    2.54 +	{
    2.55 +		task_dyld_info_data_t dyld_info;
    2.56 +		mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
    2.57 +		task_info(mach_task_self(), TASK_DYLD_INFO, (task_info_t)&dyld_info, &count);
    2.58 +		m_ImageList = (struct dyld_all_image_infos *)dyld_info.all_image_info_addr;
    2.59 +	}
    2.60 +	else
    2.61 +	{
    2.62 +		struct nlist list[2];
    2.63 +		memset(list, 0, sizeof(list));
    2.64 +		list[0].n_un.n_name = (char *)"_dyld_all_image_infos";
    2.65 +		nlist("/usr/lib/dyld", list);
    2.66 +		m_ImageList = (struct dyld_all_image_infos *)list[0].n_value;
    2.67 +	}
    2.68  
    2.69  #endif
    2.70  }
     3.1 --- a/core/logic/MemoryUtils.h	Sun Jun 05 23:13:25 2011 -0400
     3.2 +++ b/core/logic/MemoryUtils.h	Wed Jun 15 16:02:05 2011 -0500
     3.3 @@ -2,7 +2,7 @@
     3.4   * vim: set ts=4 sw=4 tw=99 noet :
     3.5   * =============================================================================
     3.6   * SourceMod
     3.7 - * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
     3.8 + * Copyright (C) 2004-2011 AlliedModders LLC.  All rights reserved.
     3.9   * =============================================================================
    3.10   *
    3.11   * This program is free software; you can redistribute it and/or modify it under
    3.12 @@ -41,6 +41,10 @@
    3.13  
    3.14  using namespace SourceMod;
    3.15  
    3.16 +#ifdef PLATFORM_APPLE
    3.17 +#include <CoreServices/CoreServices.h>
    3.18 +#endif
    3.19 +
    3.20  struct DynLibInfo
    3.21  {
    3.22  	void *baseAddress;
    3.23 @@ -75,6 +79,8 @@
    3.24  	CVector<LibSymbolTable *> m_SymTables;
    3.25  #ifdef PLATFORM_APPLE
    3.26  	struct dyld_all_image_infos *m_ImageList;
    3.27 +	SInt32 m_OSXMajor;
    3.28 +	SInt32 m_OSXMinor;
    3.29  #endif
    3.30  #endif
    3.31  };
     4.1 --- a/core/logic/common_logic.cpp	Sun Jun 05 23:13:25 2011 -0400
     4.2 +++ b/core/logic/common_logic.cpp	Wed Jun 15 16:02:05 2011 -0500
     4.3 @@ -33,12 +33,12 @@
     4.4  #include <sm_platform.h>
     4.5  #include <string.h>
     4.6  #include "common_logic.h"
     4.7 -#include "ThreadSupport.h"
     4.8  #include "TextParsers.h"
     4.9  #include "Profiler.h"
    4.10  #include "sm_crc32.h"
    4.11  #include "MemoryUtils.h"
    4.12  #include "stringutil.h"
    4.13 +#include "ThreadSupport.h"
    4.14  #include "Translator.h"
    4.15  #include "GameConfigs.h"
    4.16