DynamoRIO / DynamoRIO/dynamorio

Function wrapping is unreliable when using drwrap_skip_call

Open
#2,298 11 comments 0 reactions 0 assignees View on GitHub
Bug-Assert Component-Extension help wanted Hotlist-Release
Dominant language
C
Stars
3.2k
Forks
629
Avg merge
2d 15h
Merged PRs (30d)
31

Description

Function wrapping in drwrap extension seems to be unreliable, possibly when combined with `drwrap_skip_call` feature.

Here is my drwrap client code (contained in `nop.c`),

```
#include "dr_api.h"
#include "utils.h"
#include "drwrap.h"
#include "drmgr.h"
#include

void wrap_pre_sleep(void *wrapcxt, OUT void **user_data)
{
unsigned long int status = 0;

drwrap_skip_call(wrapcxt, (void *) status, 0);
}

static void module_load_event(void *drcontext, const module_data_t * mod, bool loaded)
{
bool ok;

app_pc towrap = (app_pc) dr_get_proc_address(mod->handle, "sleep");
if (towrap != NULL) {
ok = drwrap_wrap(towrap, wrap_pre_sleep, NULL);
}
}

DR_EXPORT void
dr_init(client_id_t id)
{
drmgr_init();
drwrap_init();
drmgr_register_module_load_event(module_load_event);
}
```

Here is my application code (contained in `application.c`),

```
#include
#include

int main()
{
while (1) {
fprintf(stderr, ".");
sleep(256); // we will try to nop this
}

return 0;
}
```

Expected behavior,

```
$ ./bin64/drrun -c api/bin/libnop.so -- ../application
......... (this should keep printing without any long pauses)
```

`sleep` from `application.c` should never be called.

Actual behavior,

```
$ ./bin64/drrun -c api/bin/libnop.so -- ../application
.................................................................(long pause occurs here)
```

Sometimes the original wrapped function `sleep` is called, which is not expected!

This outcome is very puzzling to me, and I can't explain it. Hopefully, this is not a bug / limitation in DynamoRIO.

All this code is available at https://github.com/kholia/dynamorio/tree/missed-call-wrapping for testing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.