Skip to content

Commit 7141d7e

Browse files
committed
upd
1 parent 5f3adb3 commit 7141d7e

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

os/linux/c/routines.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ void *get_base(void) {
184184
return addr;
185185
}
186186

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+
187205
int read_line(int fd, char *buf, int buflen) {
188206
int len;
189207

@@ -261,7 +279,7 @@ void *get_module_handle1(const char *module) {
261279
break;
262280
}
263281
}
264-
close(maps);
282+
_close(maps);
265283
return base;
266284
}
267285

0 commit comments

Comments
 (0)