Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dm/gfx/vk/hle_vk.m
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ static void rec_clear(VkCommandBuffer cb, VkImage im, int ds, const VkClearValue
// The occlusion query running counts the render encoder there is, each from a slot of its own in the submit's visibility buffer. It may have begun outside a render pass (Vulkan lets a query span
// from before a pass to after it: Super Mario 3D All-Stars' Sunshine, Hagi's GX) and a pass's encoder may be split for a copy: every encoder started while it runs gets a slot
static void occ_start(rs_t *s) {
subq_t *q = s->sq; if (!s->aq || !s->re) return;
subq_t *q = s->sq; if (!q || !s->aq || !s->re) return;
if (q->nvis == q->cap) { RED1("occlusion query: more encoders than the visibility buffer has slots"); return; }
q->occ[q->nvis] = (occ_t){s->aq, s->aq_first, q->nvis};
[s->re setVisibilityResultMode:MTLVisibilityResultModeCounting offset:q->nvis * 8]; q->nvis++;
Expand Down
5 changes: 3 additions & 2 deletions dm/host/hle_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ typedef struct { char name[16]; uint64_t base, size, pre; } jit_region;
// jit.img is the code memory's first part (mapped read + execute at the layout's base, loader.c; on iOS the executable's __TEXT,__dm<tag>_jit section, as the modules are embedded),
// jit.tsv the requests by key (where each one's code lies in the image, its output and the output's host addresses to relocate) and jit.out the outputs
typedef struct { char key[33]; uint64_t cmd, code_off, code_size, ro_off, ro_size, out_off, out_size; int ret; uint32_t nrel; uint64_t *rel_at, *rel_off; int *rel_mod; } jit_req;
static void *jit_realloc(void *p, size_t bytes) { void *grown = realloc(p, bytes); if (!grown) die("jit: no memory for the request table"); return grown; } // never NULL: the caller keeps its old block until this succeeds
static jit_req *g_req; static int g_nreq; static const uint8_t *g_out; static size_t g_out_len; static uint64_t g_img_size, g_layout_rx, g_layout_ro;
static void jit_serve_load(const char *dir) {
char path[1100]; snprintf(path, sizeof path, "%s/jit.tsv", dir);
Expand All @@ -119,7 +120,7 @@ static void jit_serve_load(const char *dir) {
unsigned oe, oc, os2;
if (sscanf(line, "outcode\t%u\t%x\t%x\t%x", &kc, &oe, &oc, &os2) == 4 && kc < 8) { g_outcode[kc].set = 1; g_outcode[kc].entries = oe; g_outcode[kc].count = oc; g_outcode[kc].size = os2; continue; }
if (strncmp(line, "req\t", 4)) continue;
g_req = realloc(g_req, (size_t)(g_nreq + 1) * sizeof *g_req); jit_req *r = &g_req[g_nreq++]; memset(r, 0, sizeof *r);
g_req = jit_realloc(g_req, (size_t)(g_nreq + 1) * sizeof *g_req); jit_req *r = &g_req[g_nreq++]; memset(r, 0, sizeof *r);
char rel[16]; unsigned long long co, cs, roo, ros, oo, os; int off = 0;
if (sscanf(line, "req\t%32s\t%llu\t%llx\t%llx\t%llx\t%llx\t%d\t%llx\t%llx\t%n", r->key, (unsigned long long *)&r->cmd, &co, &cs, &roo, &ros, &r->ret, &oo, &os, &off) < 9 || !off) die("%s: bad row", path);
r->code_off = co; r->code_size = cs; r->ro_off = roo; r->ro_size = ros; r->out_off = oo; r->out_size = os;
Expand All @@ -128,7 +129,7 @@ static void jit_serve_load(const char *dir) {
unsigned long long at, ro2; char nm[17]; int k = 0;
if (sscanf(q, "%llx=%16[^+]+%llx%n", &at, nm, &ro2, &k) != 3) die("%s: bad relocation in %s", path, r->key);
int mi = -1; if (strcmp(nm, "jit_rx")) { for (int i = 0; i < g_nmod; i++) if (!strcmp(g_mod[i].name, nm)) mi = i; if (mi < 0) die("%s: relocation into %s, which is not loaded", path, nm); }
r->rel_at = realloc(r->rel_at, (r->nrel + 1) * 8); r->rel_off = realloc(r->rel_off, (r->nrel + 1) * 8); r->rel_mod = realloc(r->rel_mod, (r->nrel + 1) * sizeof(int));
r->rel_at = jit_realloc(r->rel_at, (r->nrel + 1) * 8); r->rel_off = jit_realloc(r->rel_off, (r->nrel + 1) * 8); r->rel_mod = jit_realloc(r->rel_mod, (r->nrel + 1) * sizeof(int));
r->rel_at[r->nrel] = at; r->rel_off[r->nrel] = ro2; r->rel_mod[r->nrel] = mi; r->nrel++;
q += k; if (*q == ',') q++;
}
Expand Down
1 change: 1 addition & 0 deletions dm/host/hle_oe.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void dm_oe_execute(int index, const void *param, size_t n) {
FILE *fp = fopen(pf, "rb"); char *rows2 = NULL;
if (fp) {
fseek(fp, 0, SEEK_END); long sz = ftell(fp); fseek(fp, 0, SEEK_SET);
if (sz < 0) { LOG("[RED] oe::ExecuteProgram: cannot size DM_PROGRAMS %s", pf); sz = 0; } // ftell failed: read it as empty, not as SIZE_MAX bytes
tsv = calloc(1, (size_t)sz + 1); rows2 = calloc(1, (size_t)sz + 1);
if (fread(tsv, 1, (size_t)sz, fp) != (size_t)sz) tsv[0] = 0;
memcpy(rows2, tsv, (size_t)sz); fclose(fp);
Expand Down
10 changes: 6 additions & 4 deletions dm/host/web_apple.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ - (void)userContentController:(WKUserContentController *)uc didReceiveScriptMess
int front_web_touch(void) { return g_touch; }

static NSString *json(NSString *s) { // a JavaScript string literal
NSData *d = [NSJSONSerialization dataWithJSONObject:@[s ?: @""] options:0 error:nil];
NSData *d = [NSJSONSerialization dataWithJSONObject:@[s ?: @""] options:0 error:nil]; if (!d) return @"\"\"";
NSString *a = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
return [a substringWithRange:NSMakeRange(1, a.length - 2)];
}
Expand Down Expand Up @@ -287,7 +287,7 @@ - (void)serve:(id<WKURLSchemeTask>)t {
NSString *f = [_dir stringByAppendingPathComponent:rel]; NSData *d = nil;
if ([rel isEqualToString:@"__dm_font/nintendo_ext.ttf"]) { // the Nintendo extension font (button icons): the host's stand-in, as the shared font service gives it (hle_sdk16.c)
const char *e = getenv("DM_SHARED_FONT_EXT"), *fd = getenv("DM_FONT_DIR");
f = e ? @(e) : fd ? [@(fd) stringByAppendingPathComponent:@"nintendo_ext.ttf"] : @"";
f = (e ? @(e) : fd ? [@(fd) stringByAppendingPathComponent:@"nintendo_ext.ttf"] : @"") ?: @""; // @(...) is nil for bytes that are not UTF-8
d = [NSData dataWithContentsOfFile:f];
} else if (rel.length && ![rel containsString:@".."] && [f hasPrefix:_dir]) {
d = [NSData dataWithContentsOfFile:f];
Expand All @@ -300,6 +300,7 @@ - (void)serve:(id<WKURLSchemeTask>)t {
}
NSHTTPURLResponse *r = [[NSHTTPURLResponse alloc] initWithURL:u statusCode:d ? 200 : 404 HTTPVersion:@"HTTP/1.1"
headerFields:@{@"Content-Type": mime(f.pathExtension), @"Content-Length": [NSString stringWithFormat:@"%lu", (unsigned long)d.length]}];
if (!r) { [t didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil]]; return; } // no response without a URL
if (!d) LOG("[RED] web: the page asked for %s, which its document does not have", u.absoluteString.UTF8String);
[t didReceiveResponse:r]; [t didReceiveData:d ?: [NSData data]]; [t didFinish];
}
Expand Down Expand Up @@ -372,7 +373,8 @@ int front_web_open(const char *dir, const char *path, const char *callback, int
front_web_attach(box);
[box place];
NSString *q = [p stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLFragmentAllowedCharacterSet];
[box.web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[@"dmweb://doc/" stringByAppendingString:q]]]];
NSURL *doc = [NSURL URLWithString:[@"dmweb://doc/" stringByAppendingString:q ?: @""]];
if (doc) [box.web loadRequest:[NSURLRequest requestWithURL:doc]]; else LOG("[RED] web: %s is not an address", p.UTF8String);
if (!hidden) { box.shown = YES; g_touch = 1; [box setHiddenState:NO]; [box startInput]; }
});
return 0;
Expand All @@ -398,7 +400,7 @@ void front_web_shot(const char *path) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!g_box) { LOG("webshot: no page"); return; }
[g_box.web takeSnapshotWithConfiguration:nil completionHandler:^(NSImage *im, NSError *e) {
NSBitmapImageRep *r = im ? [[NSBitmapImageRep alloc] initWithData:im.TIFFRepresentation] : nil;
NSData *tiff = im.TIFFRepresentation; NSBitmapImageRep *r = tiff ? [[NSBitmapImageRep alloc] initWithData:tiff] : nil;
NSData *d = [r representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
if (![d writeToFile:p atomically:YES]) LOG("[RED] webshot: nothing written to %s (%s)", p.UTF8String, e.localizedDescription.UTF8String ?: "-");
}];
Expand Down
2 changes: 1 addition & 1 deletion dm/tools/lint_c_baseline.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ dm/gfx/tests/t_zskip.m clang-analyzer-osx.cocoa.RetainCount 1
dm/gfx/vk/hle_vk.m bugprone-suspicious-memory-comparison 1
dm/gfx/vk/hle_vk.m bugprone-suspicious-realloc-usage 2
dm/gfx/vk/hle_vk.m clang-analyzer-core.uninitialized.Assign 1
dm/gfx/vk/hle_vk.m clang-analyzer-security.ArrayBound 2
dm/gfx/vk/hle_vk.m clang-analyzer-security.ArrayBound 1
dm/gfx/vk/hle_vk.m clang-analyzer-unix.Malloc 1
dm/gfx/vk/hle_vk.m misc-misplaced-const 5
dm/host/haptics_apple.m clang-analyzer-nullability.NullablePassedToNonnull 1
Expand Down
Loading