dlsym

pthread_cond_broadcast broken with dlsym?

余生颓废 提交于 2019-12-07 05:48:54
问题 I am trying to interpose calls to pthread_cond_broadcast using LD_PRELOAD mechanism. My interposed pthread_cond_broadcast function just calls the original pthread_cond_broadcast. However, for a very simple pthread code where both pthread_cond_wait and pthread_cond_broadcast get invoked, I either end up with a segfault in glibc (for glibc 2.11.1) or the program hangs (for glibc 2.15). Any clues on that is going on? The interposition code (that gets compiled as a shared library): #define _GNU

How to use dlsym reliably when you have duplicated symbols?

我是研究僧i 提交于 2019-12-07 03:11:55
问题 Good evening, I'm currently working on a Plugin system in C++/Linux based on the Plux.net model. To keep it simple, I basicly declare a symbol (lets call it pluginInformation) with extern C (to unmangle) and my plugin manager look for that symbol in the pre configured imports (.so). The thing is that the main application declares the same symbol, not only that but any dependency it have may have the symbol aswell. (since in this pluginInformation, modules can publish plugs and/or slots). So

Propagating exceptions through dlsym cython

你说的曾经没有我的故事 提交于 2019-12-06 07:18:52
I am unable to propagate exceptions through dlsym. I use dlsym to load a cythonized python file. I made a minimal working example below so you can try it yourself: I have a pyx file, c_fun.pyx, which I compile to a C file using Cython. Then I'm using dlsym to load in the so file in another program, say use_fun.c++. You can use ./compile.sh to compile the files. On executing ./test, the program crashes with a segmentation fault. #c_fun.pyx: cdef public double _myfunction(double x) except*: a=1/0 # This does not propagate an exception. Comment to make the example work return x**2-x # This works.

Calling function by name using dlsym in iOS

六月ゝ 毕业季﹏ 提交于 2019-12-06 06:51:39
问题 Can't I call a function by name in iOS? I have a C function called getstring . I am calling it as follows: void* handle = dlopen(NULL, RTLD_NOW); if (handle) { fp func = dlsym(handle, "getstring"); if (!func) responseField.text = [NSString stringWithUTF8String:dlerror()]; else { char* tmpStr = func(); responseField.text = [NSString stringWithUTF8String:tmpStr]; } } else { responseField.text = [NSString stringWithUTF8String:dlerror()]; } When this executes, responseFiled.text is set to dlsym(.

Ansi C patch using dlsym compiles OK under linux but fails on Mac Os X

我只是一个虾纸丫 提交于 2019-12-06 06:28:58
问题 I have build a little patch to append to a certain application and trace the invocations of some functions. Among them, malloc() and open(). I am using dlsym to store the pointer to the original symbol and replace the function name with my own. It compiles -and works- perfectly under linux. Here's the code: #define _GNU_SOURCE #include <stdint.h> #include <stdio.h> #include <string.h> #include <stdarg.h> #include <dlfcn.h> /** * Interponemos nuestra funcion open * * @param char* filename *

pthread_cond_broadcast broken with dlsym?

一笑奈何 提交于 2019-12-05 10:02:57
I am trying to interpose calls to pthread_cond_broadcast using LD_PRELOAD mechanism. My interposed pthread_cond_broadcast function just calls the original pthread_cond_broadcast. However, for a very simple pthread code where both pthread_cond_wait and pthread_cond_broadcast get invoked, I either end up with a segfault in glibc (for glibc 2.11.1) or the program hangs (for glibc 2.15). Any clues on that is going on? The interposition code (that gets compiled as a shared library): #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <dlfcn.h> static int (*orig

How to use dlsym reliably when you have duplicated symbols?

走远了吗. 提交于 2019-12-05 07:58:38
Good evening, I'm currently working on a Plugin system in C++/Linux based on the Plux.net model. To keep it simple, I basicly declare a symbol (lets call it pluginInformation) with extern C (to unmangle) and my plugin manager look for that symbol in the pre configured imports (.so). The thing is that the main application declares the same symbol, not only that but any dependency it have may have the symbol aswell. (since in this pluginInformation, modules can publish plugs and/or slots). So when my PluginManager starts, it first try to find the symbol in the main program (passing NULL to

Casting when using dlsym()

烈酒焚心 提交于 2019-12-05 07:16:48
I'm using dlsym() in C and I have a question whether the return value of dlsym() should be explicitly cast or if it is implicitly cast correctly. Here is the function: double (*(compile)(void))(double x, double y) { if (system("scan-build clang -fPIC -shared -g -Wall -Werror -pedantic " "-std=c11 -O0 -lm foo.c -o foo.so") != 0) { exit(EXIT_FAILURE); } void *handle; handle = dlopen("./foo.so", RTLD_LAZY); if (!handle) { printf("Failed to load foo.so: %s\n", dlerror()); exit(EXIT_FAILURE); } foo f; f = (foo)dlsym(handle, "foo"); if (!f) { printf("Failed to find symbol foo in foo.so: %s\n",

Calling function by name using dlsym in iOS

守給你的承諾、 提交于 2019-12-04 13:38:55
Can't I call a function by name in iOS? I have a C function called getstring . I am calling it as follows: void* handle = dlopen(NULL, RTLD_NOW); if (handle) { fp func = dlsym(handle, "getstring"); if (!func) responseField.text = [NSString stringWithUTF8String:dlerror()]; else { char* tmpStr = func(); responseField.text = [NSString stringWithUTF8String:tmpStr]; } } else { responseField.text = [NSString stringWithUTF8String:dlerror()]; } When this executes, responseFiled.text is set to dlsym(...): symbol not found . This means dlopen works but not dlsym . I dumped the symbols in the binary

Ansi C patch using dlsym compiles OK under linux but fails on Mac Os X

随声附和 提交于 2019-12-04 13:10:37
I have build a little patch to append to a certain application and trace the invocations of some functions. Among them, malloc() and open(). I am using dlsym to store the pointer to the original symbol and replace the function name with my own. It compiles -and works- perfectly under linux. Here's the code: #define _GNU_SOURCE #include <stdint.h> #include <stdio.h> #include <string.h> #include <stdarg.h> #include <dlfcn.h> /** * Interponemos nuestra funcion open * * @param char* filename * @param int flags **/ int open(char * filename, int flags) { static int (*real_open)(char*, int) = NULL;