Skip to content

Commit 15ca628

Browse files
ports(mlibc): tag memory locations on library load
Signed-off-by: Anhad Singh <[email protected]>
1 parent 7dd50be commit 15ca628

File tree

4 files changed

+116
-8
lines changed

4 files changed

+116
-8
lines changed

patches/fox/jinx-working-patch.patch

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ index ce0f651..189b5e8 100644
2222
saved_cppflags="${CXXFLAGS}"
2323
CXXFLAGS="${CXXFLAGS} -DHAVE_XFT_H=1 $XFTCFLAGS"
2424
X_BASE_LIBS="${X_BASE_LIBS} $XFTLIBS"
25-
25+
diff --git fox-clean/include/FXStream.h fox-workdir/include/FXStream.h
26+
index 41fe97a..b483556 100644
27+
--- fox-clean/include/FXStream.h
28+
+++ fox-workdir/include/FXStream.h
29+
@@ -52,9 +52,9 @@ enum FXStreamStatus {
30+
31+
/// Stream seeking
32+
enum FXWhence {
33+
- FXFromStart=0, /// Seek from start position
34+
- FXFromCurrent=1, /// Seek from current position
35+
- FXFromEnd=2 /// Seek from end position
36+
+ FXFromStart=3, /// Seek from start position (SEEK_SET)
37+
+ FXFromCurrent=1, /// Seek from current position (SEEK_CUR)
38+
+ FXFromEnd=2 /// Seek from end position (SEEK_END)
39+
};
40+
41+

patches/mlibc/jinx-working-patch.patch

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
diff --git mlibc-clean/meson.build mlibc-workdir/meson.build
2+
index 905fbb9..6da45e0 100644
3+
--- mlibc-clean/meson.build
4+
+++ mlibc-workdir/meson.build
5+
@@ -213,7 +213,7 @@ elif host_machine.system() == 'aero'
6+
rtld_include_dirs += include_directories('sysdeps/aero/include')
7+
libc_include_dirs += include_directories('sysdeps/aero/include')
8+
internal_conf.set10('MLIBC_MAP_DSO_SEGMENTS', true)
9+
- internal_conf.set10('MLIBC_MAP_FILE_WINDOWS', true)
10+
+ internal_conf.set10('MLIBC_MAP_FILE_WINDOWS', false)
11+
subdir('sysdeps/aero')
12+
elif host_machine.system() == 'managarm'
13+
# TODO: Adopt the include_directories() commands from the managarm meson.build.
114
diff --git mlibc-clean/options/glibc/generic/execinfo.cpp mlibc-workdir/options/glibc/generic/execinfo.cpp
215
index 3474615..d06f130 100644
316
--- mlibc-clean/options/glibc/generic/execinfo.cpp
@@ -15,11 +28,69 @@ index 3474615..d06f130 100644
1528
}
1629

1730
char **backtrace_symbols(void *const *, int) {
31+
diff --git mlibc-clean/options/rtld/generic/linker.cpp mlibc-workdir/options/rtld/generic/linker.cpp
32+
index b5f42af..569a8c2 100644
33+
--- mlibc-clean/options/rtld/generic/linker.cpp
34+
+++ mlibc-workdir/options/rtld/generic/linker.cpp
35+
@@ -27,7 +27,7 @@ uintptr_t libraryBase = 0x41000000;
36+
37+
constexpr bool verbose = false;
38+
constexpr bool stillSlightlyVerbose = false;
39+
-constexpr bool logBaseAddresses = false;
40+
+constexpr bool logBaseAddresses = true;
41+
constexpr bool logRpath = false;
42+
constexpr bool logLdPath = false;
43+
constexpr bool eagerBinding = true;
44+
@@ -470,6 +470,7 @@ frg::expected<LinkerError, void> ObjectRepository::_fetchFromFile(SharedObject *
45+
__ensure(!(object->baseAddress & (hugeSize - 1)));
46+
47+
highest_address = (highest_address + mlibc::page_size - 1) & ~(mlibc::page_size - 1);
48+
+ size_t tagSize = highest_address - object->baseAddress;
49+
50+
#if MLIBC_MMAP_ALLOCATE_DSO
51+
void *mappedAddr = nullptr;
52+
@@ -492,9 +493,12 @@ frg::expected<LinkerError, void> ObjectRepository::_fetchFromFile(SharedObject *
53+
libraryBase += (highest_address + (hugeSize - 1)) & ~(hugeSize - 1);
54+
#endif
55+
56+
- if(verbose || logBaseAddresses)
57+
+ if(verbose || logBaseAddresses) {
58+
+ mlibc::sys_tag_memory((void *)object->baseAddress, tagSize, object->name.data());
59+
+
60+
mlibc::infoLogger() << "rtld: Loading " << object->name
61+
<< " at " << (void *)object->baseAddress << frg::endlog;
62+
+ }
63+
64+
// Load all segments.
65+
constexpr size_t pageSize = 0x1000;
66+
diff --git mlibc-clean/options/rtld/include/mlibc/rtld-sysdeps.hpp mlibc-workdir/options/rtld/include/mlibc/rtld-sysdeps.hpp
67+
index 6f42d41..3e37a1d 100644
68+
--- mlibc-clean/options/rtld/include/mlibc/rtld-sysdeps.hpp
69+
+++ mlibc-workdir/options/rtld/include/mlibc/rtld-sysdeps.hpp
70+
@@ -5,6 +5,7 @@ namespace [[gnu::visibility("hidden")]] mlibc {
71+
72+
int sys_tcb_set(void *pointer);
73+
74+
+[[gnu::weak]] int sys_tag_memory(void *ptr, size_t size, char *tag);
75+
[[gnu::weak]] int sys_vm_readahead(void *pointer, size_t size);
76+
77+
} // namespace mlibc
1878
diff --git mlibc-clean/sysdeps/aero/generic/aero.cpp mlibc-workdir/sysdeps/aero/generic/aero.cpp
19-
index 80f9c6f..897986d 100644
79+
index 80f9c6f..85031cd 100644
2080
--- mlibc-clean/sysdeps/aero/generic/aero.cpp
2181
+++ mlibc-workdir/sysdeps/aero/generic/aero.cpp
22-
@@ -200,14 +200,19 @@ int sys_getcwd(char *buffer, size_t size) {
82+
@@ -62,6 +62,10 @@ static frg::vector<Slice, MemoryAllocator> create_slice(char *const arg[]) {
83+
}
84+
85+
namespace mlibc {
86+
+int sys_tag_memory(void *ptr, size_t size, char *tag) {
87+
+ return syscall(SYS_DEBUG, ptr, size, tag, strlen(tag));
88+
+}
89+
+
90+
int sys_uname(struct utsname *buf) {
91+
auto result = syscall(SYS_UNAME, buf);
92+
93+
@@ -200,14 +204,19 @@ int sys_getcwd(char *buffer, size_t size) {
2394
return 0;
2495
}
2596

@@ -46,7 +117,7 @@ index 80f9c6f..897986d 100644
46117

47118
int sys_gethostname(char *buffer, size_t bufsize) {
48119
diff --git mlibc-clean/sysdeps/aero/generic/filesystem.cpp mlibc-workdir/sysdeps/aero/generic/filesystem.cpp
49-
index 95c49b9..9416be7 100644
120+
index 95c49b9..8777468 100644
50121
--- mlibc-clean/sysdeps/aero/generic/filesystem.cpp
51122
+++ mlibc-workdir/sysdeps/aero/generic/filesystem.cpp
52123
@@ -69,13 +69,14 @@ int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) {
@@ -70,3 +141,24 @@ index 95c49b9..9416be7 100644
70141
return 0;
71142
}
72143

144+
@@ -124,6 +125,20 @@ int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags,
145+
return 0;
146+
}
147+
148+
+int sys_statfs(const char *path, struct statfs *buf) {
149+
+ __ensure(!syscall(SYS_BACKTRACE));
150+
+ __ensure(!"statfs");
151+
+ memset(buf, 0, sizeof(struct statfs));
152+
+ return 0;
153+
+}
154+
+
155+
+int sys_fstatfs(int fd, struct statfs *buf) {
156+
+ __ensure(!syscall(SYS_BACKTRACE));
157+
+ mlibc::infoLogger() << "fstatfs" << frg::endlog;
158+
+ memset(buf, 0, sizeof(struct statfs));
159+
+ return 0;
160+
+}
161+
+
162+
int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
163+
auto sys_res = syscall(SYS_IOCTL, fd, request, arg);
164+

recipes/mlibc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name=mlibc
2-
version=71d6b326e31b88796088690278ce31bb8e9fc994
2+
version=7b67d09bde0be6d53284d1583058483e1687880c
33
revision=1
44
tarball_url="https://github.com/managarm/mlibc/archive/${version}.tar.gz"
5-
tarball_blake2b="b2fc2178bf9a26191a78866272da2ff6cb2b547cb3fdd5fe28f4280d5bbf98a929e9920e5c05a25ed340af8d29d45265e148eba6d31490a7a6796adfcb2158d6"
5+
tarball_blake2b="a18b4fe6ab839088079f5cdcf1d35831ac9f3d25408118f5ddce280d595b730d1cbf7d4869a2da24f4df4edce7d250042acfea67f20266cc7a157db2e1d7c1ed"
66
imagedeps="meson ninja"
77
hostdeps="gcc pkg-config libgcc-binaries"
88
builddeps="cxxshim frigg linux-headers"

userland/tests/utest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,8 @@ void abstract_test_case::register_case(abstract_test_case *tcp) {
762762
}
763763

764764
int main() {
765-
// Go through all tests and run them.
766-
for(abstract_test_case *tcp : test_case_ptrs()) {
765+
// Go through all tests and run them.
766+
for(abstract_test_case *tcp : test_case_ptrs()) {
767767
std::cout << "tests: Running " << tcp->name() << std::endl;
768768
tcp->run();
769769
}

0 commit comments

Comments
 (0)