Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce signal intercepting example #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GBuella
Copy link
Contributor

@GBuella GBuella commented Sep 2, 2017

It is a nice first attempt to demonstrate the idea, far from complete.

To give it a try, start the dummy program which installs a signal handler:

LD_LIBRARY_PATH=./examples LD_PRELOAD=libsignal_interceptor.so ./examples/signaller

Send it a USR1 signal, and see what happens.

Ref: #4


This change is Reviewable

@GBuella
Copy link
Contributor Author

GBuella commented Sep 8, 2017

BTW, this can be used to handle nasty pointers pass to pmemfile via syscall interfaces, e.g.:

thread_local sigjmp_buf user_pointer_jmb_buf;
thread_local bool jump_back_to_pmemfile;

pmemfile_write(pfp, file, buf, size)
{

  ssize_t result;
  jump_back_to_pmemfile = true;

  if (sigsetjmp(user_pointer_jmb_buf, 0) == 0) {
     memcpy(buf, pmemfile_block, size);
     result = size;
  } else {
    result = -EFAULT;
  }
  jump_back_to_pmemfile = false;
  return result;
}

signal_hook(int sig, siginfo_t *info, void *arg)
{
   if (sig == SIGSEGV && jump_back_to_pmemfile) {
      /* fault due to pointer from user */
      siglongjmp(user_pointer_jmb_buf, 1);
   }
}

@krzycz
Copy link
Contributor

krzycz commented Sep 11, 2017

So, this info could be added to the source file and/or to some README.


Reviewed 3 of 3 files at r1.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@sarahjelinek
Copy link
Contributor

This build fails. Not quite sure why.

@GBuella
Copy link
Contributor Author

GBuella commented Sep 11, 2017

I think there is something really wrong with the docker related scripts, which wasn't manifested until #48 was merged.
It might be a good a idea to copy docker build scripts from the pmemfile repo.

It is a nice first attempt to demonstrate the idea, far from complete.

To give it a try, start the dummy program which installs a signal handler:

LD_LIBRARY_PATH=./examples LD_PRELOAD=libsignal_interceptor.so ./examples/signaller

Send it a USR! signal, and see what happens.
@codecov-io
Copy link

codecov-io commented Sep 13, 2017

Codecov Report

Merging #46 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #46   +/-   ##
=======================================
  Coverage   69.71%   69.71%           
=======================================
  Files          19       19           
  Lines        1433     1433           
  Branches      391      391           
=======================================
  Hits          999      999           
  Misses        235      235           
  Partials      199      199
Flag Coverage Δ
#pmemfile_tests 65.67% <ø> (ø) ⬆️
#regular_tests 56.38% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e15d384...154f91f. Read the comment docs.

static const char busy_msg[] = "Sorry, I'm busy!\n";
syscall_no_intercept(SYS_write, 2, busy_msg, strlen(busy_msg));

/* XXX Another signal can arrive here, and that makes me a sad panda. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use atomic and increase it before filling deferred_queue? That should solve this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would solve this.
But, after I made this PR, I realized it is not easy to prove correctness under all circumstances. A signal can arrive anytime, while serving rt_sigaction, while executing the deferred signals, while executing a signal that arrived while handling a deferred signal... And what if the user installed a signal handler which writes to some log on segfault, or mmap's something into memory on segfault, to be able to continue -- we just defer such a signal, and try to resume instead, which doesn't work.
So, there are a lot of details to work out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants