We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f3adb3 commit 7141d7eCopy full SHA for 7141d7e
1 file changed
os/linux/c/routines.c
@@ -184,6 +184,24 @@ void *get_base(void) {
184
return addr;
185
}
186
187
+void *get_base2(void) {
188
+ uint64_t *fs, base;
189
+
190
+ // retrieve the address of _nl_C_LC_CTYPE_class
191
+ asm ("mov %%fs:0xffffffffffffffb0,%%rax":"=a"(fs));
192
193
+ base = (uint64_t)fs;
194
195
+ // align down
196
+ base &= -4096;
197
198
+ // equal to ELF?
199
+ while (*(uint32_t*)base != 0x464c457fUL) {
200
+ base -= 4096;
201
+ }
202
+ return (void*)base;
203
+}
204
205
int read_line(int fd, char *buf, int buflen) {
206
int len;
207
@@ -261,7 +279,7 @@ void *get_module_handle1(const char *module) {
261
279
break;
262
280
263
281
264
- close(maps);
282
+ _close(maps);
265
283
return base;
266
284
267
285
0 commit comments