Skip to content

Commit aa004ef

Browse files
committed
Try fixing some Windows issues
1 parent d2893c9 commit aa004ef

13 files changed

Lines changed: 74 additions & 49 deletions

File tree

build.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ pub fn build(b: *std.Build) !void {
2323
}
2424

2525
var c_source_files = std.ArrayListUnmanaged([]const u8){};
26-
try c_source_files.appendSlice(b.allocator, &.{
27-
"bootstrap.c",
28-
"runtimes/globals.c",
29-
});
26+
try c_source_files.append(b.allocator, "bootstrap.c");
3027

3128
const lib = b.addLibrary(.{
3229
.linkage = .dynamic,
@@ -57,6 +54,7 @@ pub fn build(b: *std.Build) !void {
5754
lib_mod.addCSourceFiles(.{
5855
.root = b.path("src"),
5956
.files = c_source_files.items,
57+
.flags = &.{ "-Wall", "-Werror" },
6058
});
6159

6260
lib_mod.addIncludePath(b.path("src"));

src/bootstrap.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ void mono_doorstop_bootstrap(void *mono_domain) {
5656
free(norm_assembly_dir);
5757

5858
LOG("Opening assembly: %s", config.target_assembly);
59-
void *file = fopen(config.target_assembly, "r");
59+
void *file = fopen_custom(config.target_assembly, TSTR("r"));
6060
if (!file) {
6161
log_err("Failed to open assembly: %s", config.target_assembly);
6262
return;
6363
}
6464

6565
size_t size = get_file_size(file);
6666
void *data = malloc(size);
67-
fread(data, size, 1, file);
68-
fclose(file);
67+
fread_custom(data, size, 1, file);
68+
fclose_custom(file);
6969

7070
LOG("Opened Assembly DLL (%d bytes); opening its main image", size);
7171

@@ -83,7 +83,7 @@ void mono_doorstop_bootstrap(void *mono_domain) {
8383
LOG("Image opened; loading included assembly");
8484

8585
s = MONO_IMAGE_OK;
86-
void *assembly = mono.assembly_load_from_full(image, dll_path, &s, FALSE);
86+
mono.assembly_load_from_full(image, dll_path, &s, FALSE);
8787
free(dll_path);
8888
if (s != MONO_IMAGE_OK) {
8989
log_err("Failed to load assembly: %s. Got result: %d",
@@ -262,7 +262,6 @@ void il2cpp_doorstop_bootstrap() {
262262
char *app_path_n = narrow(app_path);
263263

264264
char_t *target_dir = get_folder_name(config.target_assembly);
265-
char *target_dir_n = narrow(target_dir);
266265
char_t *target_name = get_file_name(config.target_assembly, FALSE);
267266
char *target_name_n = narrow(target_name);
268267

@@ -338,7 +337,7 @@ void hook_mono_jit_parse_options(int argc, char **argv) {
338337

339338
const char_t *mono_debug_address = config.mono_debug_address;
340339
if (!mono_debug_address) {
341-
mono_debug_address = "127.0.0.1:10000";
340+
mono_debug_address = TSTR("127.0.0.1:10000");
342341
}
343342
size_t debug_args_len =
344343
STR_LEN(MONO_DEBUG_ARG_START) + strlen(mono_debug_address);
@@ -398,11 +397,11 @@ void *hook_mono_image_open_from_data_with_name(void *data,
398397
strcat(new_full_path, name_file);
399398

400399
if (file_exists(new_full_path)) {
401-
void *file = fopen(new_full_path, "r");
400+
void *file = fopen_custom(new_full_path, TSTR("r"));
402401
size_t size = get_file_size(file);
403402
void *buf = malloc(size);
404-
fread(buf, 1, size, file);
405-
fclose(file);
403+
fread_custom(buf, 1, size, file);
404+
fclose_custom(file);
406405
result = mono.image_open_from_data_with_name(buf, size, need_copy,
407406
status, refonly, name);
408407
if (need_copy)

src/crt.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#define ENV32
1414
#endif
1515

16+
#define TSTR(t) L##t
17+
18+
void *fopen_custom(const char_t *filename, const char_t *mode);
19+
size_t fread_custom(void *ptr, size_t size, size_t count, void *stream);
20+
int fclose_custom(void *stream);
21+
1622
#elif defined(__APPLE__) || defined(__linux__)
1723
#define _GNU_SOURCE
1824
#include <dlfcn.h>
@@ -24,6 +30,21 @@
2430
#include <sys/stat.h>
2531
#include <unistd.h>
2632

33+
#define TSTR(t) t
34+
35+
#pragma clang diagnostic push
36+
#pragma clang diagnostic ignored "-Wunused"
37+
static void *fopen_custom(const char *filename, const char *mode) {
38+
return fopen(filename, mode);
39+
}
40+
41+
static size_t fread_custom(void *ptr, size_t size, size_t count, void *stream) {
42+
return fread(ptr, size, count, stream);
43+
}
44+
45+
static int fclose_custom(void *stream) { return fclose(stream); }
46+
#pragma clang diagnostic pop
47+
2748
#if defined(__APPLE__)
2849
#include <mach-o/dyld.h>
2950
#endif

src/nix/entrypoint.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int fclose_hook(FILE *stream) {
5050
// to console
5151
if (stream == stdout)
5252
return F_OK;
53-
return fclose(stream);
53+
return fclose_custom(stream);
5454
}
5555

5656
char_t *default_boot_config_path = NULL;
@@ -69,8 +69,8 @@ FILE *fopen64_hook(const char *filename, const char *mode) {
6969
}
7070
#endif
7171

72-
FILE *fopen_hook(char *filename, char *mode) {
73-
char *actual_file_name = filename;
72+
FILE *fopen_hook(const char *filename, const char *mode) {
73+
const char *actual_file_name = filename;
7474

7575
if (strcmp(filename, default_boot_config_path) == 0) {
7676
actual_file_name = config.boot_config_override;

src/nix/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ char *normalize_path(char *pwd, const char *src, char *res) {
109109
return res;
110110
}
111111

112-
char_t *get_full_path(char_t *path) {
112+
char_t *get_full_path(const char_t *path) {
113113
char_t *full_path = (char_t *)calloc(MAX_PATH + 1, sizeof(char_t));
114114
char_t *cwd_str = getcwd(NULL, MAX_PATH);
115115
normalize_path(cwd_str, path, full_path);
@@ -121,7 +121,7 @@ char_t *get_full_path(char_t *path) {
121121
return full_path;
122122
}
123123

124-
char_t *get_folder_name(char_t *path) {
124+
char_t *get_folder_name(const char_t *path) {
125125
char_t *path_copy = (char_t *)calloc(MAX_PATH + 1, sizeof(char_t));
126126
strcpy(path_copy, path);
127127
char_t *folder = dirname(path_copy);
@@ -131,7 +131,7 @@ char_t *get_folder_name(char_t *path) {
131131
return result;
132132
}
133133

134-
char_t *get_file_name(char_t *path, bool_t with_ext) {
134+
char_t *get_file_name(const char_t *path, bool_t with_ext) {
135135
char_t *path_copy = (char_t *)calloc(MAX_PATH + 1, sizeof(char_t));
136136
strcpy(path_copy, path);
137137
char_t *file = basename(path_copy);

src/root.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub const std_options = std.Options{
1414
comptime {
1515
_ = @import("config.zig");
1616
_ = logging;
17+
_ = @import("runtimes/globals.zig");
1718
if (builtin.os.tag == .windows) {
1819
_ = @import("windows/proxy/proxy.zig");
1920
}

src/runtimes/func_import.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ typedef struct {
3232

3333
extern S(IMPORT_PREFIX) IMPORT_PREFIX;
3434

35+
#pragma clang diagnostic push
36+
#pragma clang diagnostic ignored "-Wunused"
3537
static void LOADER_FUNC_NAME(void *lib) {
3638
#define DEF_CALL(retType, name, ...) \
3739
IMPORT_PREFIX.name = (name##_t)dlsym(lib, STR(CAT(IMPORT_PREFIX, _, name)));
3840
#include IMPORT_LIB
3941
#undef DEF_CALL
4042
}
43+
#pragma clang diagnostic pop
4144

42-
#undef DEFINE_CALLS
45+
#undef DEFINE_CALLS

src/runtimes/globals.c

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/runtimes/globals.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const builtin = @import("builtin");
2+
3+
const coreclr = @cImport(@cInclude("runtimes/coreclr.h"));
4+
const il2cpp = @cImport(@cInclude("runtimes/il2cpp.h"));
5+
const mono = @cImport(@cInclude("runtimes/mono.h"));
6+
7+
var coreclr_addrs: coreclr.coreclr_struct = .{};
8+
var il2cpp_addrs: il2cpp.il2cpp_struct = .{};
9+
var mono_addrs: mono.mono_struct = .{};
10+
11+
comptime {
12+
@export(&coreclr_addrs, .{ .name = "coreclr" });
13+
@export(&il2cpp_addrs, .{ .name = "il2cpp" });
14+
@export(&mono_addrs, .{ .name = "mono" });
15+
}

src/util/util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ size_t get_module_path(void *module, char_t **result, size_t *size,
8181
* @param path Path to resolve relative path for.
8282
* @return char_t* Absolute path to the given path.
8383
*/
84-
char_t *get_full_path(char_t *path);
84+
char_t *get_full_path(const char_t *path);
8585

8686
/**
8787
* @brief Get the directory name of the given path.
@@ -94,7 +94,7 @@ char_t *get_full_path(char_t *path);
9494
* @param path Full path to get directory name of.
9595
* @return char_t* Directory part of the path (part before last path separator).
9696
*/
97-
char_t *get_folder_name(char_t *path);
97+
char_t *get_folder_name(const char_t *path);
9898

9999
/**
100100
* @brief Get the file name from the full path
@@ -105,7 +105,7 @@ char_t *get_folder_name(char_t *path);
105105
* @param with_ext Whether to include file extension or not.
106106
* @return char_t* File name part of the path.
107107
*/
108-
char_t *get_file_name(char_t *path, bool_t with_ext);
108+
char_t *get_file_name(const char_t *path, bool_t with_ext);
109109

110110
/**
111111
* @brief Check if a file exists.

0 commit comments

Comments
 (0)