Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • D dynamorio
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,467
    • Issues 1,467
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 44
    • Merge requests 44
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • DynamoRIO
  • dynamorio
  • Issues
  • #2298
Closed
Open
Issue created Mar 17, 2017 by Administrator@rootContributor

Function wrapping is unreliable when using drwrap_skip_call

Created by: kholia

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 <stdio.h>

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 <stdio.h>
#include <unistd.h>

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.

Assignee
Assign to
Time tracking