From e98f440a8171faa03f98d93d6c4a346f4014bc52 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 20 Jun 2024 12:50:08 +0200 Subject: [PATCH 1/7] Add prefix for long paths. --- src/mono/mono/component/debugger-agent.c | 2 +- src/mono/mono/eglib/gfile.c | 11 ++++++++--- src/mono/mono/eventpipe/ds-rt-mono.c | 4 ++-- src/mono/mono/metadata/lock-tracer.c | 2 +- src/mono/mono/metadata/seq-points-data.c | 4 ++-- src/mono/mono/metadata/sgen-new-bridge.c | 2 +- src/mono/mono/metadata/threads.c | 2 +- src/mono/mono/mini/aot-compiler.c | 2 +- src/mono/mono/mini/driver.c | 2 +- src/mono/mono/mini/graph.c | 2 +- src/mono/mono/mini/helpers.c | 2 +- src/mono/mono/mini/mini-ppc.c | 2 +- src/mono/mono/mini/mini-runtime.c | 6 +++--- src/mono/mono/profiler/aot.c | 2 +- src/mono/mono/profiler/coverage.c | 4 ++-- src/mono/mono/profiler/log.c | 2 +- src/mono/mono/profiler/mprof-report.c | 4 ++-- src/mono/mono/sgen/sgen-debug.c | 2 +- src/mono/mono/sgen/sgen-gc.c | 2 +- .../mono/tests/metadata-verifier/gen-md-tests.c | 4 ++-- src/mono/mono/utils/mono-cgroup.c | 14 +++++++------- src/mono/mono/utils/mono-dl.c | 2 +- src/mono/mono/utils/mono-filemap.c | 7 ++++++- src/mono/mono/utils/mono-hwcap-arm.c | 2 +- src/mono/mono/utils/mono-log-common.c | 2 +- src/mono/mono/utils/mono-sha1.c | 2 +- src/mono/mono/utils/mono-threads-android.c | 2 +- src/mono/wasi/runtime/driver.c | 4 ++-- .../external/brotli/fuzz/run_decode_fuzzer.c | 2 +- src/native/external/brotli/tools/brotli.c | 6 +++--- src/native/external/libunwind/tests/crasher.c | 6 +++--- src/native/external/zlib-intel/crc32.c | 2 +- src/native/external/zlib-intel/trees.c | 2 +- src/native/external/zlib/crc32.c | 2 +- src/native/external/zlib/trees.c | 2 +- src/native/libs/System.Native/pal_mount.c | 2 +- .../System.Security.Cryptography.Native/pal_x509.c | 2 +- 37 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/mono/mono/component/debugger-agent.c b/src/mono/mono/component/debugger-agent.c index 088a8545d6df0..27b0937d34ec7 100644 --- a/src/mono/mono/component/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -819,7 +819,7 @@ mono_debugger_agent_init_internal (void) disconnected = TRUE; if (agent_config.log_file) { - log_file = fopen (agent_config.log_file, "w+"); + log_file = g_fopen (agent_config.log_file, "w+"); if (!log_file) { PRINT_ERROR_MSG ("Unable to create log file '%s': %s.\n", agent_config.log_file, strerror (errno)); exit (1); diff --git a/src/mono/mono/eglib/gfile.c b/src/mono/mono/eglib/gfile.c index 5720a54a71265..e59f5e75332ed 100644 --- a/src/mono/mono/eglib/gfile.c +++ b/src/mono/mono/eglib/gfile.c @@ -127,10 +127,14 @@ g_fopen (const gchar *path, const gchar *mode) return NULL; #ifdef HOST_WIN32 - if (is_ascii_string (path) && is_ascii_string (mode)) { - fp = fopen (path, mode); + gchar *path_mod; + path_mod = g_malloc(strlen(path) + 5); + strcpy(path_mod, "\\\\?\\"); + strcat(path_mod, path); + if (is_ascii_string (path_mod) && is_ascii_string (mode)) { + fp = fopen (path_mod, mode); } else { - gunichar2 *wPath = g_utf8_to_utf16 (path, -1, 0, 0, 0); + gunichar2 *wPath = g_utf8_to_utf16 (path_mod, -1, 0, 0, 0); gunichar2 *wMode = g_utf8_to_utf16 (mode, -1, 0, 0, 0); if (!wPath || !wMode) @@ -140,6 +144,7 @@ g_fopen (const gchar *path, const gchar *mode) g_free (wPath); g_free (wMode); } + g_free (path_mod); #else fp = fopen (path, mode); #endif diff --git a/src/mono/mono/eventpipe/ds-rt-mono.c b/src/mono/mono/eventpipe/ds-rt-mono.c index 58e8754f4290c..672e5c826dbc6 100644 --- a/src/mono/mono/eventpipe/ds-rt-mono.c +++ b/src/mono/mono/eventpipe/ds-rt-mono.c @@ -128,9 +128,9 @@ ipc_get_process_id_disambiguation_key ( char stat_file_name [64]; snprintf (stat_file_name, sizeof (stat_file_name), "/proc/%d/stat", process_id); - FILE *stat_file = fopen (stat_file_name, "r"); + FILE *stat_file = g_fopen (stat_file_name, "r"); if (!stat_file) { - EP_ASSERT (!"Failed to get start time of a process, fopen failed."); + EP_ASSERT (!"Failed to get start time of a process, g_fopen failed."); return false; } diff --git a/src/mono/mono/metadata/lock-tracer.c b/src/mono/mono/metadata/lock-tracer.c index 13283f13de5d0..40326e6a2a676 100644 --- a/src/mono/mono/metadata/lock-tracer.c +++ b/src/mono/mono/metadata/lock-tracer.c @@ -80,7 +80,7 @@ mono_locks_tracer_init (void) return; name = g_strdup_printf ("locks.%d", getpid ()); - trace_file = fopen (name, "w+"); + trace_file = g_fopen (name, "w+"); g_free (name); #ifdef TARGET_OSX diff --git a/src/mono/mono/metadata/seq-points-data.c b/src/mono/mono/metadata/seq-points-data.c index b5e50eea05685..2d43c724e587f 100644 --- a/src/mono/mono/metadata/seq-points-data.c +++ b/src/mono/mono/metadata/seq-points-data.c @@ -395,7 +395,7 @@ mono_seq_point_data_read (SeqPointData *data, char *path) long fsize; FILE *f; - f = fopen (path, "r"); + f = g_fopen (path, "r"); if (!f) return FALSE; @@ -440,7 +440,7 @@ mono_seq_point_data_write (SeqPointData *data, char *path) FILE *f; int i, size = 0; - f = fopen (path, "w+"); + f = g_fopen (path, "w+"); if (!f) return FALSE; diff --git a/src/mono/mono/metadata/sgen-new-bridge.c b/src/mono/mono/metadata/sgen-new-bridge.c index cddaee8bff759..d75f4c8448f4a 100644 --- a/src/mono/mono/metadata/sgen-new-bridge.c +++ b/src/mono/mono/metadata/sgen-new-bridge.c @@ -622,7 +622,7 @@ dump_graph (void) int edge_id = 0; sprintf (filename, "%s.%d.gexf", dump_prefix, counter++); - file = fopen (filename, "w"); + file = g_fopen (filename, "w"); if (file == NULL) { fprintf (stderr, "Warning: Could not open bridge dump file `%s` for writing: %s\n", filename, strerror (errno)); diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index 22a7760450e84..f4c8ae70d0cff 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -3127,7 +3127,7 @@ mono_threads_perform_thread_dump (void) strftime(time_str, sizeof(time_str), MONO_STRFTIME_F "_" MONO_STRFTIME_T, &tod); ms = tv.tv_usec / 1000; g_string_append_printf (path, "%s/%s.%03ld.tdump", thread_dump_dir, time_str, ms); - output_file = fopen (path->str, "w"); + output_file = g_fopen (path->str, "w"); g_string_free (path, TRUE); } if (output_file == NULL) { diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 119b945ee9fa1..c82c730cccbcb 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -15705,7 +15705,7 @@ compile_assemblies_in_child (MonoAotOptions *aot_opts, MonoAssembly **assemblies #ifdef HOST_WIN32 response_fname = g_build_filename (aot_opts->temp_path, "temp.rsp", (const char*)NULL); g_assert (response_fname); - response = fopen (response_fname, "w"); + response = g_fopen (response_fname, "w"); g_assert (response); #endif diff --git a/src/mono/mono/mini/driver.c b/src/mono/mono/mini/driver.c index f5a25b152d796..30411536df1cb 100644 --- a/src/mono/mono/mini/driver.c +++ b/src/mono/mono/mini/driver.c @@ -2091,7 +2091,7 @@ mono_main (int argc, char* argv[]) fprintf (stderr, "error: --statfile requires a filename argument\n"); return 1; } - mini_stats_fd = fopen (argv [++i], "w+"); + mini_stats_fd = g_fopen (argv [++i], "w+"); } else if (strncmp (argv [i], "--optimize=", 11) == 0) { opt = parse_optimizations (opt, argv [i] + 11, TRUE); } else if (strncmp (argv [i], "-O=", 3) == 0) { diff --git a/src/mono/mono/mini/graph.c b/src/mono/mono/mini/graph.c index 0ebc434c3e29b..eac96252fa28c 100644 --- a/src/mono/mono/mini/graph.c +++ b/src/mono/mono/mini/graph.c @@ -204,7 +204,7 @@ mono_draw_graph (MonoCompile *cfg, MonoGraphOptions draw_options) FILE *fp; fn = "/tmp/minidtree.graph"; - fp = fopen (fn, "w+"); + fp = g_fopen (fn, "w+"); g_assert (fp); switch (draw_options) { diff --git a/src/mono/mono/mini/helpers.c b/src/mono/mono/mini/helpers.c index e3860045d244c..240e559775c3e 100644 --- a/src/mono/mono/mini/helpers.c +++ b/src/mono/mono/mini/helpers.c @@ -131,7 +131,7 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id) #ifdef HOST_WIN32 as_file = g_strdup_printf ("%s/test.s", tmp); - if (!(ofd = fopen (as_file, "w"))) + if (!(ofd = g_fopen (as_file, "w"))) g_assert_not_reached (); #else i = g_file_open_tmp (NULL, &as_file, NULL); diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index a5c1fbb2f9865..b29393684be59 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -575,7 +575,7 @@ mono_arch_init (void) AuxVec vec [MAX_AUX_ENTRIES]; int i, vec_entries = 0; /* sadly this will work only with 2.6 kernels... */ - FILE* f = fopen ("/proc/self/auxv", "rb"); + FILE* f = g_fopen ("/proc/self/auxv", "rb"); if (f) { vec_entries = fread (&vec, sizeof (AuxVec), MAX_AUX_ENTRIES, f); diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index e99e464fb8c85..208517373db4b 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -1990,7 +1990,7 @@ mono_enable_jit_map (void) char name [64]; g_snprintf (name, sizeof (name), "/tmp/perf-%d.map", getpid ()); unlink (name); - perf_map_file = fopen (name, "w"); + perf_map_file = g_fopen (name, "w"); } } @@ -2115,7 +2115,7 @@ mono_enable_jit_dump (void) g_snprintf (name, sizeof (name), "/tmp/jit-%d.dump", perf_dump_pid); unlink (name); - perf_dump_file = fopen (name, "w+"); + perf_dump_file = g_fopen (name, "w+"); add_file_header_info (&header); if (perf_dump_file) { @@ -3151,7 +3151,7 @@ mono_set_bisect_methods (guint32 opt, const char *method_list_filename) bisect_methods_hash = g_hash_table_new (g_str_hash, g_str_equal); g_assert (bisect_methods_hash); - file = fopen (method_list_filename, "r"); + file = g_fopen (method_list_filename, "r"); g_assert (file); while (fgets (method_name, sizeof (method_name), file)) { diff --git a/src/mono/mono/profiler/aot.c b/src/mono/mono/profiler/aot.c index f9298e725584b..f5b47a6bcfcf7 100644 --- a/src/mono/mono/profiler/aot.c +++ b/src/mono/mono/profiler/aot.c @@ -384,7 +384,7 @@ mono_profiler_init_aot (const char *desc) } else if (*aot_profiler.outfile_name == '#') { aot_profiler.outfile = fdopen (strtol (aot_profiler.outfile_name + 1, NULL, 10), "a"); } else { - aot_profiler.outfile = fopen (aot_profiler.outfile_name, "w"); + aot_profiler.outfile = g_fopen (aot_profiler.outfile_name, "w"); } if (!aot_profiler.outfile && aot_profiler.outfile_name) { diff --git a/src/mono/mono/profiler/coverage.c b/src/mono/mono/profiler/coverage.c index d692caf60c3b5..b64441dc0a196 100644 --- a/src/mono/mono/profiler/coverage.c +++ b/src/mono/mono/profiler/coverage.c @@ -836,7 +836,7 @@ get_file_content (const gchar *filename) int res, offset = 0; FILE *stream; - stream = fopen (filename, "r"); + stream = g_fopen (filename, "r"); if (stream == NULL) return NULL; @@ -1170,7 +1170,7 @@ mono_profiler_init_coverage (const char *desc) } else if (*coverage_config.output_filename == '#') { coverage_profiler.file = fdopen (strtol (coverage_config.output_filename + 1, NULL, 10), "a"); } else { - coverage_profiler.file = fopen (coverage_config.output_filename, "w"); + coverage_profiler.file = g_fopen (coverage_config.output_filename, "w"); } if (!coverage_profiler.file) { diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index 9d4304faae3ec..22e4cb9037dec 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -3602,7 +3602,7 @@ create_profiler (const char *args, const char *filename, GPtrArray *filters) int fd = strtol (nf + 1, NULL, 10); log_profiler.file = fdopen (fd, "a"); } else - log_profiler.file = fopen (nf, "wb"); + log_profiler.file = g_fopen (nf, "wb"); if (!log_profiler.file) { mono_profiler_printf_err ("Could not create log profiler output file '%s': %s", nf, g_strerror (errno)); diff --git a/src/mono/mono/profiler/mprof-report.c b/src/mono/mono/profiler/mprof-report.c index 35c88fe0a2fd9..59a785c67ec7f 100644 --- a/src/mono/mono/profiler/mprof-report.c +++ b/src/mono/mono/profiler/mprof-report.c @@ -3232,7 +3232,7 @@ load_file (char *name) if (strcmp (name, "-") == 0) ctx->file = stdin; else - ctx->file = fopen (name, "rb"); + ctx->file = g_fopen (name, "rb"); if (!ctx->file) { printf ("Cannot open file: %s\n", name); exit (1); @@ -4070,7 +4070,7 @@ main (int argc, char *argv[]) reports = val; } else if (strncmp ("--out=", argv [i], 6) == 0) { const char *val = argv [i] + 6; - outfile = fopen (val, "w"); + outfile = g_fopen (val, "w"); if (!outfile) { printf ("Cannot open output file: %s\n", val); return 1; diff --git a/src/mono/mono/sgen/sgen-debug.c b/src/mono/mono/sgen/sgen-debug.c index ea2caeba2b693..71748eb048970 100644 --- a/src/mono/mono/sgen/sgen-debug.c +++ b/src/mono/mono/sgen/sgen-debug.c @@ -963,7 +963,7 @@ dump_object_callback (GCObject *obj, size_t size, gboolean dump_location) void sgen_debug_enable_heap_dump (const char *filename) { - heap_dump_file = fopen (filename, "w"); + heap_dump_file = g_fopen (filename, "w"); if (heap_dump_file) { fprintf (heap_dump_file, "\n"); sgen_pin_stats_enable (); diff --git a/src/mono/mono/sgen/sgen-gc.c b/src/mono/mono/sgen/sgen-gc.c index 705b8168ed36f..a7d03eb8c6821 100644 --- a/src/mono/mono/sgen/sgen-gc.c +++ b/src/mono/mono/sgen/sgen-gc.c @@ -3753,7 +3753,7 @@ sgen_gc_init (void) opt++; if (opt [0]) { char *rf = g_strdup_printf ("%s.%d", opt, mono_process_current_pid ()); - sgen_gc_debug_file = fopen (rf, "wb"); + sgen_gc_debug_file = g_fopen (rf, "wb"); if (!sgen_gc_debug_file) sgen_gc_debug_file = stderr; g_free (rf); diff --git a/src/mono/mono/tests/metadata-verifier/gen-md-tests.c b/src/mono/mono/tests/metadata-verifier/gen-md-tests.c index 0f1efd15849b5..3221004e326e1 100644 --- a/src/mono/mono/tests/metadata-verifier/gen-md-tests.c +++ b/src/mono/mono/tests/metadata-verifier/gen-md-tests.c @@ -244,7 +244,7 @@ test_validity_name (int validity) static char* read_whole_file_and_close (const char *name, int *file_size) { - FILE *file = fopen (name, "ro"); + FILE *file = g_fopen (name, "ro"); char *res; int fsize; @@ -592,7 +592,7 @@ process_test_entry (test_set_t *test_set, test_entry_t *entry) file_name = make_test_name (entry, test_set); - f = fopen (file_name, "wo"); + f = g_fopen (file_name, "wo"); fwrite (entry->data, entry->data_size, 1, f); fclose (f); diff --git a/src/mono/mono/utils/mono-cgroup.c b/src/mono/mono/utils/mono-cgroup.c index 4c58f53257b97..1c3c88e50b6eb 100644 --- a/src/mono/mono/utils/mono-cgroup.c +++ b/src/mono/mono/utils/mono-cgroup.c @@ -126,7 +126,7 @@ readMemoryValueFromFile(const char* filename, size_t* val) FILE *file = NULL; if (val != NULL) { - file = fopen (filename, "r"); + file = g_fopen (filename, "r"); if (file != NULL) { if (getline (&line, &lineLen, file) != -1) { errno = 0; @@ -337,7 +337,7 @@ findHierarchyMount(gboolean (*is_subsystem)(const char *), char** pmountpath, ch char *mountpath = NULL; char *mountroot = NULL; - FILE *mountinfofile = fopen (PROC_MOUNTINFO_FILENAME, "r"); + FILE *mountinfofile = g_fopen (PROC_MOUNTINFO_FILENAME, "r"); if (mountinfofile == NULL) goto done; @@ -432,7 +432,7 @@ findCGroupPathForSubsystem(gboolean (*is_subsystem)(const char *)) char *cgroup_path = NULL; gboolean result = FALSE; - FILE *cgroupfile = fopen (PROC_CGROUP_FILENAME, "r"); + FILE *cgroupfile = g_fopen (PROC_CGROUP_FILENAME, "r"); if (cgroupfile == NULL) goto done; @@ -568,7 +568,7 @@ getCGroupMemoryUsage(size_t *val, const char *filename, const char *inactiveFile if (asprintf (&stat_filename, "%s%s", s_memory_cgroup_path, CGROUP_MEMORY_STAT_FILENAME) < 0) return FALSE; - FILE *stat_file = fopen (stat_filename, "r"); + FILE *stat_file = g_fopen (stat_filename, "r"); free (stat_filename); if (stat_file == NULL) return FALSE; @@ -689,7 +689,7 @@ mono_get_memory_used(size_t *val) return TRUE; // process resident set size. - FILE* file = fopen (PROC_STATM_FILENAME, "r"); + FILE* file = g_fopen (PROC_STATM_FILENAME, "r"); if (file != NULL && getline (&line, &linelen, file) != -1) { char* context = NULL; char* strTok = strtok_r (line, " ", &context); @@ -799,7 +799,7 @@ getCGroup2CpuLimit(guint32 *val) if (asprintf (&filename, "%s%s", s_cpu_cgroup_path, CGROUP2_CPU_MAX_FILENAME) < 0) return FALSE; - file = fopen (filename, "r"); + file = g_fopen (filename, "r"); if (file == NULL) goto done; @@ -922,7 +922,7 @@ readLongLongValueFromFile(const char *filename, long long *val) if (val == NULL) return FALSE; - FILE *file = fopen (filename, "r"); + FILE *file = g_fopen (filename, "r"); if (file == NULL) return FALSE; diff --git a/src/mono/mono/utils/mono-dl.c b/src/mono/mono/utils/mono-dl.c index b772f869d31b6..a1e309503ee04 100644 --- a/src/mono/mono/utils/mono-dl.c +++ b/src/mono/mono/utils/mono-dl.c @@ -118,7 +118,7 @@ get_dl_name_from_libtool (const char *libtool_file) FILE* file; char buf [512]; char *line, *dlname = NULL, *libdir = NULL, *installed = NULL; - if (!(file = fopen (libtool_file, "r"))) + if (!(file = g_fopen (libtool_file, "r"))) return NULL; while ((line = fgets (buf, 512, file))) { while (*line && isspace (*line)) diff --git a/src/mono/mono/utils/mono-filemap.c b/src/mono/mono/utils/mono-filemap.c index 0c4ac46a5b497..01bc6255f4f9c 100644 --- a/src/mono/mono/utils/mono-filemap.c +++ b/src/mono/mono/utils/mono-filemap.c @@ -28,12 +28,17 @@ MonoFileMap * mono_file_map_open (const char* name) { #ifdef WIN32 - gunichar2 *wname = g_utf8_to_utf16 (name, -1, 0, 0, 0); + gchar *name_mod; + name_mod = g_malloc(strlen(name) + 5); + strcpy(name_mod, "\\\\?\\"); + strcat(name_mod, name); + gunichar2 *wname = g_utf8_to_utf16 (name_mod, -1, 0, 0, 0); MonoFileMap *result; if (wname == NULL) return NULL; result = (MonoFileMap *) _wfopen ((wchar_t *) wname, L"rb"); + g_free (name_mod); g_free (wname); return result; #else diff --git a/src/mono/mono/utils/mono-hwcap-arm.c b/src/mono/mono/utils/mono-hwcap-arm.c index 47e44d14c2fcf..e0414f2333f8b 100644 --- a/src/mono/mono/utils/mono-hwcap-arm.c +++ b/src/mono/mono/utils/mono-hwcap-arm.c @@ -172,7 +172,7 @@ mono_hwcap_arch_init (void) char buf [512]; char *line; - FILE *file = fopen ("/proc/cpuinfo", "r"); + FILE *file = g_fopen ("/proc/cpuinfo", "r"); if (file) { while ((line = fgets (buf, 512, file))) { diff --git a/src/mono/mono/utils/mono-log-common.c b/src/mono/mono/utils/mono-log-common.c index 605df83d4d05a..79aa64561d482 100644 --- a/src/mono/mono/utils/mono-log-common.c +++ b/src/mono/mono/utils/mono-log-common.c @@ -71,7 +71,7 @@ mono_log_open_logfile(const char *path, void *userData) logFile = stdout; } else { #ifndef HOST_WIN32 - logFile = fopen(path, "w"); + logFile = g_fopen(path, "w"); #else gunichar2 *wPath = g_utf8_to_utf16(path, -1, 0, 0, 0); if (wPath != NULL) { diff --git a/src/mono/mono/utils/mono-sha1.c b/src/mono/mono/utils/mono-sha1.c index 6f05124a74988..eb127aee05e7f 100644 --- a/src/mono/mono/utils/mono-sha1.c +++ b/src/mono/mono/utils/mono-sha1.c @@ -315,7 +315,7 @@ mono_sha1_get_digest_from_file (const gchar *filename, guchar digest [20]) FILE *fp; mono_sha1_init (&ctx); - fp = fopen(filename, "r"); + fp = g_fopen(filename, "r"); if (!fp) { return; } diff --git a/src/mono/mono/utils/mono-threads-android.c b/src/mono/mono/utils/mono-threads-android.c index fa3070a2e3e9b..7eb85b5fd99f5 100644 --- a/src/mono/mono/utils/mono-threads-android.c +++ b/src/mono/mono/utils/mono-threads-android.c @@ -17,7 +17,7 @@ static void slow_get_thread_bounds (guint8 *current, guint8 **staddr, size_t *stsize) { char buff [1024]; - FILE *f = fopen ("/proc/self/maps", "r"); + FILE *f = g_fopen ("/proc/self/maps", "r"); if (!f) g_error ("Could not determine thread bounds, failed to open /proc/self/maps"); diff --git a/src/mono/wasi/runtime/driver.c b/src/mono/wasi/runtime/driver.c index 80e831bb29cea..788dcbb890691 100644 --- a/src/mono/wasi/runtime/driver.c +++ b/src/mono/wasi/runtime/driver.c @@ -174,7 +174,7 @@ void load_icu_data (void) char filename[256]; sprintf(filename, "./icudt.dat"); - fileptr = fopen(filename, "rb"); + fileptr = g_fopen(filename, "rb"); if (fileptr == 0) { printf("Failed to load %s\n", filename); fflush(stdout); @@ -378,7 +378,7 @@ void add_assembly(const char* base_dir, const char *name) { sprintf(filename, "%s/%s", base_dir, name); // printf("Loading %s...\n", filename); - fileptr = fopen(filename, "rb"); + fileptr = g_fopen(filename, "rb"); if (fileptr == 0) { printf("Failed to load %s\n", filename); fflush(stdout); diff --git a/src/native/external/brotli/fuzz/run_decode_fuzzer.c b/src/native/external/brotli/fuzz/run_decode_fuzzer.c index c84f98a32b0c9..c3500f34afdb6 100644 --- a/src/native/external/brotli/fuzz/run_decode_fuzzer.c +++ b/src/native/external/brotli/fuzz/run_decode_fuzzer.c @@ -19,7 +19,7 @@ int main(int argc, char* *argv) { exit(EXIT_FAILURE); } - FILE* f = fopen(argv[1], "r"); + FILE* f = g_fopen(argv[1], "r"); if (!f) { fprintf(stderr, "Failed to open input file."); exit(EXIT_FAILURE); diff --git a/src/native/external/brotli/tools/brotli.c b/src/native/external/brotli/tools/brotli.c index 7c678d3d8fa55..cfe9f0755a4a6 100644 --- a/src/native/external/brotli/tools/brotli.c +++ b/src/native/external/brotli/tools/brotli.c @@ -49,7 +49,7 @@ #define utimbuf _utimbuf #define utime _utime -#define fopen ms_fopen +#define g_fopen ms_fopen #define open ms_open #define chmod(F, P) (0) @@ -593,7 +593,7 @@ static BROTLI_BOOL OpenInputFile(const char* input_path, FILE** f) { *f = fdopen(MAKE_BINARY(STDIN_FILENO), "rb"); return BROTLI_TRUE; } - *f = fopen(input_path, "rb"); + *f = g_fopen(input_path, "rb"); if (!*f) { fprintf(stderr, "failed to open input file [%s]: %s\n", PrintablePath(input_path), strerror(errno)); @@ -627,7 +627,7 @@ static BROTLI_BOOL OpenOutputFile(const char* output_path, FILE** f, } static int64_t FileSize(const char* path) { - FILE* f = fopen(path, "rb"); + FILE* f = g_fopen(path, "rb"); int64_t retval; if (f == NULL) { return -1; diff --git a/src/native/external/libunwind/tests/crasher.c b/src/native/external/libunwind/tests/crasher.c index e19e2d691ed31..23efa520cccc7 100644 --- a/src/native/external/libunwind/tests/crasher.c +++ b/src/native/external/libunwind/tests/crasher.c @@ -18,8 +18,8 @@ void write_maps(char *fname) char buf[512], path[128]; char exec; uintmax_t addr; - FILE *maps = fopen("/proc/self/maps", "r"); - FILE *out = fopen(fname, "w"); + FILE *maps = g_fopen("/proc/self/maps", "r"); + FILE *out = g_fopen(fname, "w"); if (!maps || !out) exit(EXIT_FAILURE); @@ -50,7 +50,7 @@ write_maps(char *fname) int mib[4], error; size_t len; - out = fopen(fname, "w"); + out = g_fopen(fname, "w"); if (out == NULL) exit(EXIT_FAILURE); diff --git a/src/native/external/zlib-intel/crc32.c b/src/native/external/zlib-intel/crc32.c index 49c4f1b828e52..28066e1462fe8 100644 --- a/src/native/external/zlib-intel/crc32.c +++ b/src/native/external/zlib-intel/crc32.c @@ -322,7 +322,7 @@ local void make_crc_table() z_crc_t ltl[8][256]; z_word_t big[8][256]; - out = fopen("crc32.h", "w"); + out = g_fopen("crc32.h", "w"); if (out == NULL) return; /* write out little-endian CRC table to crc32.h */ diff --git a/src/native/external/zlib-intel/trees.c b/src/native/external/zlib-intel/trees.c index f78b7d8c63eae..b72f297a74454 100644 --- a/src/native/external/zlib-intel/trees.c +++ b/src/native/external/zlib-intel/trees.c @@ -321,7 +321,7 @@ local void tr_static_init() void gen_trees_header() { - FILE *header = fopen("trees.h", "w"); + FILE *header = g_fopen("trees.h", "w"); int i; Assert (header != NULL, "Can't open trees.h"); diff --git a/src/native/external/zlib/crc32.c b/src/native/external/zlib/crc32.c index 6c38f5c04c6a8..fda6659b471d5 100644 --- a/src/native/external/zlib/crc32.c +++ b/src/native/external/zlib/crc32.c @@ -349,7 +349,7 @@ local void make_crc_table(void) { z_crc_t ltl[8][256]; z_word_t big[8][256]; - out = fopen("crc32.h", "w"); + out = g_fopen("crc32.h", "w"); if (out == NULL) return; /* write out little-endian CRC table to crc32.h */ diff --git a/src/native/external/zlib/trees.c b/src/native/external/zlib/trees.c index 979ae4100a02e..db4694db0d0d1 100644 --- a/src/native/external/zlib/trees.c +++ b/src/native/external/zlib/trees.c @@ -385,7 +385,7 @@ local void tr_static_init(void) { ((i) % (width) == (width) - 1 ? ",\n" : ", ")) void gen_trees_header(void) { - FILE *header = fopen("trees.h", "w"); + FILE *header = g_fopen("trees.h", "w"); int i; Assert (header != NULL, "Can't open trees.h"); diff --git a/src/native/libs/System.Native/pal_mount.c b/src/native/libs/System.Native/pal_mount.c index 2453bdfe9ede3..1ef22c50ff198 100644 --- a/src/native/libs/System.Native/pal_mount.c +++ b/src/native/libs/System.Native/pal_mount.c @@ -49,7 +49,7 @@ int32_t SystemNative_GetAllMountPoints(MountPointFound onFound, void* context) #elif HAVE_SYS_MNTENT_H int result = -1; - FILE* fp = fopen("/proc/mounts", MNTOPT_RO); + FILE* fp = g_fopen("/proc/mounts", MNTOPT_RO); if (fp != NULL) { char buffer[STRING_BUFFER_SIZE] = {0}; diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c index d75feeb334ac1..ac9c01b23f156 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c @@ -487,7 +487,7 @@ static X509* ReadNextPublicCert(DIR* dir, X509Stack* tmpStack, char* pathTmp, si // if d_name was full-length it might not have a trailing null. nextFileWrite[len] = 0; - FILE* fp = fopen(pathTmp, "r"); + FILE* fp = g_fopen(pathTmp, "r"); if (fp != NULL) { From 7cee4bfc9c8cef4e7efe5b5a3d3843f2b952c1f7 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 20 Jun 2024 12:52:09 +0200 Subject: [PATCH 2/7] Add test. --- .../wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index fc22d03b303bc..fa36ce10e87b7 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -92,6 +92,17 @@ public void DefaultTemplate_AOT_WithWorkload(string config, bool testUnicode) BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.AOT), "-p:RunAOTCompilation=true"); } + [Fact] + public void DefaultTemplate_AOT_WithWorkload_LongPath() + { + string config = "Release"; + string id = $"blz_aot_{config}_{GetRandomId()}_TEST_OF_EXTREMELY_LONG_PATH"; + CreateBlazorWasmTemplateProject(id); + + BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack)); + BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.AOT), "-p:RunAOTCompilation=true -p:WasmNativeStrip=false"); + } + [Theory] [InlineData("Debug", false)] [InlineData("Release", false)] From 8e364670c1978527267a82b4a03044b359d74861 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 20 Jun 2024 16:32:17 +0200 Subject: [PATCH 3/7] Only abs paths --- src/mono/mono/eglib/gfile.c | 12 +++++++++--- src/mono/mono/utils/mono-filemap.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/eglib/gfile.c b/src/mono/mono/eglib/gfile.c index e59f5e75332ed..d0cc1e64f41d1 100644 --- a/src/mono/mono/eglib/gfile.c +++ b/src/mono/mono/eglib/gfile.c @@ -128,9 +128,15 @@ g_fopen (const gchar *path, const gchar *mode) #ifdef HOST_WIN32 gchar *path_mod; - path_mod = g_malloc(strlen(path) + 5); - strcpy(path_mod, "\\\\?\\"); - strcat(path_mod, path); + if (g_path_is_absolute (path)) { + path_mod = g_malloc(strlen(path) + 5); + strcpy(path_mod, "\\\\?\\"); + strcat(path_mod, path); + } else { + path_mod = g_malloc(strlen(path)); + strcpy(path_mod, path); + } + if (is_ascii_string (path_mod) && is_ascii_string (mode)) { fp = fopen (path_mod, mode); } else { diff --git a/src/mono/mono/utils/mono-filemap.c b/src/mono/mono/utils/mono-filemap.c index 01bc6255f4f9c..6d2eea10d30f3 100644 --- a/src/mono/mono/utils/mono-filemap.c +++ b/src/mono/mono/utils/mono-filemap.c @@ -27,11 +27,16 @@ MonoFileMap * mono_file_map_open (const char* name) { -#ifdef WIN32 +#ifdef HOST_WIN32 gchar *name_mod; - name_mod = g_malloc(strlen(name) + 5); - strcpy(name_mod, "\\\\?\\"); - strcat(name_mod, name); + if (g_path_is_absolute (name)) { + name_mod = g_malloc(strlen(name) + 5); + strcpy(name_mod, "\\\\?\\"); + strcat(name_mod, name); + } else { + name_mod = g_malloc(strlen(name)); + strcpy(name_mod, name); + } gunichar2 *wname = g_utf8_to_utf16 (name_mod, -1, 0, 0, 0); MonoFileMap *result; From 36222427b17607ef9b3bbabe1b390330854ec102 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 20 Jun 2024 17:04:24 +0200 Subject: [PATCH 4/7] Fix "call to undeclared function 'g_fopen`" --- src/native/libs/System.Security.Cryptography.Native/pal_x509.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c index ac9c01b23f156..d75feeb334ac1 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c @@ -487,7 +487,7 @@ static X509* ReadNextPublicCert(DIR* dir, X509Stack* tmpStack, char* pathTmp, si // if d_name was full-length it might not have a trailing null. nextFileWrite[len] = 0; - FILE* fp = g_fopen(pathTmp, "r"); + FILE* fp = fopen(pathTmp, "r"); if (fp != NULL) { From 1cf58247bed42eebe78949cee98223f7b453b04b Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 20 Jun 2024 18:00:08 +0200 Subject: [PATCH 5/7] Same fix --- src/mono/wasi/runtime/driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasi/runtime/driver.c b/src/mono/wasi/runtime/driver.c index 788dcbb890691..80e831bb29cea 100644 --- a/src/mono/wasi/runtime/driver.c +++ b/src/mono/wasi/runtime/driver.c @@ -174,7 +174,7 @@ void load_icu_data (void) char filename[256]; sprintf(filename, "./icudt.dat"); - fileptr = g_fopen(filename, "rb"); + fileptr = fopen(filename, "rb"); if (fileptr == 0) { printf("Failed to load %s\n", filename); fflush(stdout); @@ -378,7 +378,7 @@ void add_assembly(const char* base_dir, const char *name) { sprintf(filename, "%s/%s", base_dir, name); // printf("Loading %s...\n", filename); - fileptr = g_fopen(filename, "rb"); + fileptr = fopen(filename, "rb"); if (fileptr == 0) { printf("Failed to load %s\n", filename); fflush(stdout); From 43e4b449e359d58ef155a09c0ec9cfc9f1f70005 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Fri, 21 Jun 2024 09:13:21 +0200 Subject: [PATCH 6/7] @ChrisDenton's feedback --- src/mono/mono/eglib/gfile.c | 14 +++++++++++--- src/mono/mono/utils/mono-filemap.c | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/eglib/gfile.c b/src/mono/mono/eglib/gfile.c index d0cc1e64f41d1..7784d9d91df82 100644 --- a/src/mono/mono/eglib/gfile.c +++ b/src/mono/mono/eglib/gfile.c @@ -129,9 +129,17 @@ g_fopen (const gchar *path, const gchar *mode) #ifdef HOST_WIN32 gchar *path_mod; if (g_path_is_absolute (path)) { - path_mod = g_malloc(strlen(path) + 5); - strcpy(path_mod, "\\\\?\\"); - strcat(path_mod, path); + // Check if it's a network path + if (path[0] == '\\' && path[1] == '\\') { + path_mod = g_malloc(strlen(path) + 8 - 2); + strcpy(path_mod, "\\\\?\\UNC\\"); + strcat(path_mod, path + 2); + } + else{ + path_mod = g_malloc(strlen(path) + 5); + strcpy(path_mod, "\\\\?\\"); + strcat(path_mod, path); + } } else { path_mod = g_malloc(strlen(path)); strcpy(path_mod, path); diff --git a/src/mono/mono/utils/mono-filemap.c b/src/mono/mono/utils/mono-filemap.c index 6d2eea10d30f3..b780bc8c59fd4 100644 --- a/src/mono/mono/utils/mono-filemap.c +++ b/src/mono/mono/utils/mono-filemap.c @@ -30,9 +30,18 @@ mono_file_map_open (const char* name) #ifdef HOST_WIN32 gchar *name_mod; if (g_path_is_absolute (name)) { - name_mod = g_malloc(strlen(name) + 5); - strcpy(name_mod, "\\\\?\\"); - strcat(name_mod, name); + + // Check if it's a network path + if (name[0] == '\\' && name[1] == '\\') { + name_mod = g_malloc(strlen(name) + 8 - 2); + strcpy(name_mod, "\\\\?\\UNC\\"); + strcat(name_mod, name + 2); + } + else{ + name_mod = g_malloc(strlen(name) + 5); + strcpy(name_mod, "\\\\?\\"); + strcat(name_mod, name); + } } else { name_mod = g_malloc(strlen(name)); strcpy(name_mod, name); From dd5c98be90e4e4119b62462deddd7af7e7fd1ad5 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 24 Jun 2024 16:30:20 +0200 Subject: [PATCH 7/7] Debugging --- src/mono/mono/metadata/loader.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/metadata/loader.c b/src/mono/mono/metadata/loader.c index 467fe0e668c07..875a252c95d22 100644 --- a/src/mono/mono/metadata/loader.c +++ b/src/mono/mono/metadata/loader.c @@ -1195,9 +1195,18 @@ mono_get_method_checked (MonoImage *image, guint32 token, MonoClass *klass, Mono return result; - result = mono_get_method_from_token (image, token, klass, context, &used_context, error); + result = mono_get_method_from_token (image, token, klass, context, &used_context, error); // WHY the 1st call returns NULL when the 2nd does not? if (!result) - return NULL; + { + g_print("mono_get_method_checked it seems result was NULL, check: result is %sNULL.\n", result == NULL ? "" : "not "); + result = mono_get_method_from_token (image, token, klass, context, &used_context, error); + if (!result) + { + g_print("mono_get_method_checked after re-call it stayed NULL\n"); + return NULL; + } + g_print("mono_get_method_checked after re-call with logging: result is %sNULL.\n", result == NULL ? "" : "not "); + } mono_image_lock (image); if (!used_context && !result->is_inflated) { @@ -1941,7 +1950,7 @@ mono_method_signature_internal_slow (MonoMethod *m) if (sig) return sig; char *type_name = mono_type_get_full_name (m->klass); - g_warning ("Could not load signature of %s:%s due to: %s", type_name, m->name, mono_error_get_message (error)); + g_warning ("Could not load signature of %s:%s due to: %s", type_name, m->name, mono_error_get_message (error)); // HERE g_free (type_name); mono_error_cleanup (error); return NULL;