5

Is there a way to GetModuleHandle(NULL) on Linux to be able to pass that handle into dlsym 3

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
user877329
  • 6,717
  • 8
  • 46
  • 88

2 Answers2

11

The documentation for dlopen(3) states:

The function dlopen() loads the dynamic library file named by the null-terminated string filename and returns an opaque "handle" for the dynamic library. If filename is NULL, then the returned handle is for the main program.

Therefore, you can use the value returned by dlopen(NULL) as the handle argument to dlsym().

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
2

dlopen(NULL) will give you a handle for the executable.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358