MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / maybe_disable_filesystem

Function maybe_disable_filesystem

tools/emscripten.py:54–89  ·  view source on GitHub ↗

Disables filesystem if only a limited subset of syscalls is used. Our syscalls are static, and so if we see a very limited set of them - in particular, no open() syscall and just simple writing - then we don't need full filesystem support. If FORCE_FILESYSTEM is set, we can't do this. We also

(imports)

Source from the content-addressed store, hash-verified

52
53
54def maybe_disable_filesystem(imports):
55 """Disables filesystem if only a limited subset of syscalls is used.
56
57 Our syscalls are static, and so if we see a very limited set of them - in particular,
58 no open() syscall and just simple writing - then we don't need full filesystem support.
59 If FORCE_FILESYSTEM is set, we can't do this. We also don't do it if INCLUDE_FULL_LIBRARY, since
60 not including the filesystem would mean not including the full JS libraries, and the same for
61 MAIN_MODULE=1 since a side module might need the filesystem.
62 """
63 if any(settings[s] for s in ('FORCE_FILESYSTEM', 'INCLUDE_FULL_LIBRARY')):
64 return
65 if settings.MAIN_MODULE == 1:
66 return
67
68 if settings.FILESYSTEM == 0:
69 # without filesystem support, it doesn't matter what syscalls need
70 settings.SYSCALLS_REQUIRE_FILESYSTEM = 0
71 else:
72 # TODO(sbc): Find a better way to identify wasi syscalls
73 syscall_prefixes = ('__syscall_', 'fd_')
74 side_module_imports = [shared.demangle_c_symbol_name(s) for s in settings.SIDE_MODULE_IMPORTS]
75 all_imports = set(imports).union(side_module_imports)
76 syscalls = {d for d in all_imports if d.startswith(syscall_prefixes) or d == 'path_open'}
77 # check if the only filesystem syscalls are in: close, ioctl, llseek, write
78 # (without open, etc.. nothing substantial can be done, so we can disable
79 # extra filesystem support in that case)
80 if syscalls.issubset({
81 '__syscall_ioctl',
82 'fd_seek',
83 'fd_write',
84 'fd_close',
85 'fd_fdstat_get',
86 }):
87 if DEBUG:
88 logger.debug('very limited syscalls (%s) so disabling full filesystem support', ', '.join(str(s) for s in syscalls))
89 settings.SYSCALLS_REQUIRE_FILESYSTEM = 0
90
91
92def is_int(x):

Callers 1

update_settings_glueFunction · 0.85

Calls 2

setFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected