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

Blocking on /dev/urandom #310

Closed
clementgallet opened this issue Mar 5, 2020 · 3 comments
Closed

Blocking on /dev/urandom #310

clementgallet opened this issue Mar 5, 2020 · 3 comments

Comments

@clementgallet
Copy link
Owner

Seen on Dead Cells, but other games will be affected. We need to hook when the game is reading into /dev/urandom, for now we create a file on memory and fill it with deterministic stuff (using system time so we can manipulate its content). However, /dev/urandom is supposed to be non-blocking, so we must feed enough bytes to the game, which is not the case for Dead Cells.

@kitlith
Copy link
Contributor

kitlith commented Mar 6, 2020

so, there's fopencookie, which allows us to create our own FILE* stream defined with callbacks -- we could probably emulate urandom with that. However, i don't think that helps with the posix side of things. Perhaps we could emulate it with pipe/socketpair, since those give us fds?

@clementgallet
Copy link
Owner Author

For posix functions, looking at fcntl man page, I can see two possibilities:

  • use a pipe with a small buffer, set O_ASYNC on the fd and F_SETOWN, so that the kernel will send a SIGIO signal to the process when data can be written to the pipe.
  • use F_NOTIFY on a file with DN_ACCESS, which will send a SIGIO signal when the file is accessed.

I feel the first solution is better.

@clementgallet
Copy link
Owner Author

Implemented the first solution.

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

No branches or pull requests

2 participants