Sanitizer fixes (#2280)

This commit is contained in:
Tim Sylvester
2024-04-29 06:33:08 -07:00
committed by GitHub
parent 6ebbc3dd6a
commit cd9727b06f
14 changed files with 85 additions and 37 deletions

View File

@@ -4,10 +4,11 @@
#include <mbgl/mtl/context.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <Metal/Metal.hpp>
#include <cassert>
#include <stdexcept>
#include <type_traits>
#include <Metal/Metal.hpp>
namespace mbgl {
namespace mtl {

View File

@@ -1,11 +1,15 @@
#include "metal_backend.h"
#include <mbgl/mtl/mtl_fwd.hpp>
#include <mbgl/mtl/renderable_resource.hpp>
#include <Metal/Metal.hpp>
#include <QuartzCore/CAMetalLayer.hpp>
namespace mbgl {
using namespace mtl;
class MetalRenderableResource final: public mtl::RenderableResource {
public:
MetalRenderableResource(MetalBackend &backend):
@@ -92,17 +96,17 @@ public:
return renderPassDescriptor;
}
NS::SharedPtr<CA::MetalLayer> getSwapchain() {
const CAMetalLayerPtr& getSwapchain() const {
return swapchain;
}
private:
MetalBackend &rendererBackend;
NS::SharedPtr<MTL::CommandQueue> commandQueue;
NS::SharedPtr<MTL::CommandBuffer> commandBuffer;
NS::SharedPtr<MTL::RenderPassDescriptor> renderPassDescriptor;
NS::SharedPtr<CA::MetalDrawable> surface;
NS::SharedPtr<CA::MetalLayer> swapchain;
MTLCommandQueuePtr commandQueue;
MTLCommandBufferPtr commandBuffer;
MTLRenderPassDescriptorPtr renderPassDescriptor;
CAMetalDrawablePtr surface;
CAMetalLayerPtr swapchain;
gfx::Texture2DPtr depthTexture;
gfx::Texture2DPtr stencilTexture;
mbgl::Size size;

View File

@@ -123,6 +123,7 @@ apple_xcframework(
data = glob([
"resources/*.lproj/**",
"resources/*.xcassets/**",
"resources/metal-cpp-ignores.txt",
]),
infoplists = ["info_plist"],
ios = {
@@ -159,6 +160,7 @@ apple_resource_bundle(
resources = glob([
"resources/*.lproj/**",
"resources/*.xcassets/**",
"resources/metal-cpp-ignores.txt",
]),
visibility = ["//visibility:public"],
)

View File

@@ -3,14 +3,30 @@
#import "MBXAppDelegate.h"
#import "MBXViewController.h"
#if __has_feature(undefined_behavior_sanitizer) || defined(__SANITIZE_UNDEFINED_BEHAVIOR__)
#import "sanitizer/ubsan_interface.h"
const char* __ubsan_default_options(void) {
static char default_opts[2 * PATH_MAX];
NSString* path = [[NSBundle bundleForClass:[MBXAppDelegate class]] pathForResource:@"metal-cpp-ignores" ofType:@"txt" inDirectory:@"Mapbox.bundle"];
NSString* opts = @"print_stacktrace=1,halt_on_error=1,report_error_type=1,verbosity=0"; // add ',help=1' to see available options
if (path) {
opts = [opts stringByAppendingFormat:@",suppressions=%@", path];
}
NSLog(@"Using ubsan options: %@", opts);
bzero(default_opts, sizeof(default_opts));
strncpy(default_opts, [opts UTF8String], sizeof(default_opts) - 1);
return default_opts;
}
#endif
@interface MBXAppDelegate()
@end
@implementation MBXAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifndef MLN_LOGGING_DISABLED
[MLNLoggingConfiguration sharedConfiguration].loggingLevel = MLNLoggingLevelFault;
#endif

View File

@@ -0,0 +1,7 @@
# metal-cpp uses calls through null pointers
# Note that the code must be compiled with `-fsanitize-recover=null` for this to work.
null:vendor/metal-cpp/*
# `NS::String*` implicit cast to `NS::Object*` in Context::createProgram
alignment:src/mbgl/mtl/context.cpp