Last active
December 14, 2019 22:24
-
-
Save Jongy/381781dc8abf0e9b269a3130edb9294d to your computer and use it in GitHub Desktop.
/dev/null tricks using my Linux kernel MicroPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file_operations = partial_struct("file_operations") | |
null_fops = file_operations(null_fops) | |
from kernel_ffi import callback | |
def my_read_null(file, buf, count, ppos): | |
pos = p64(ppos) | |
b = "who said /dev/null must be empty?\n"[pos:] | |
l = min(len(b), count) | |
memcpy(buf, b, l) | |
p64(ppos, pos + l) | |
return l | |
c = callback(my_read_null) | |
null_fops.read = c.ptr() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment