IsBadReadPtr analogue on Unix

后端 未结 4 1641
执念已碎
执念已碎 2020-12-21 18:13

Is there a function analogous to IsBadReadPtr in Unix? At least some functionalities of IsBadReadPtr? I want to write a procedure which would react if something bad happens

4条回答
  •  情歌与酒
    2020-12-21 18:54

    I ran into the same issue trying to read a 'pixel' from a framebuffer while running Ubuntu from within a virtualbox. There seemed to be no secure way to check access without crashing or acutally hanging gdb. The suggestion made by StasM hinted me towards to following working 'local' solution using fork.

    void *some_address;
    int pid = fork();
    if (pid== 0)
    {
        someaddress[0] = some_address[0];
        _exit(123);
    }
    bool access_ok = true;
    int status;
    int result = waitpid(pid, &status, 0);
    if (result == -1 || WIFEXITED(status) == 0 || WEXITSTATUS(status) != 123)
    {
        access_ok = false;
    }
    

提交回复
热议问题