-
Notifications
You must be signed in to change notification settings - Fork 201
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
Compiler accepts returning allocated types from kernel #1967
Comments
Also holds if I modify the types to from artiq.experiment import *
class BadString(EnvExperiment):
def build(self):
self.setattr_device('core')
@rpc
def get_string_rpc(self) -> TBytes:
return bytes('a string', encoding='utf-8')
@kernel
def get_string(self) -> TBytes:
self.core.reset()
my_str = self.get_string_rpc()
# print(my_str)
return my_str
def run(self):
print(self.get_string().decode('utf-8')) Output: However if I uncomment the
Then, removing the
|
And it gets weirder! (I might be having too much fun with this.) If I iterate over the bytes in-kernel and print them individually it changes the return value! from artiq.experiment import *
class BadString(EnvExperiment):
def build(self):
self.setattr_device('core')
@rpc
def get_string_rpc(self) -> TBytes:
return bytes('a string', encoding='utf-8')
@kernel
def get_string(self) -> TBytes:
self.core.reset()
my_str = self.get_string_rpc()
print(my_str)
for b in my_str:
print(int(b))
return my_str
def run(self):
my_str = self.get_string()
print(my_str)
for b in my_str:
print(int(b)) output:
|
Most likely an allocation size isn't computed correctly somewhere (firmware and/or compiler) and receiving the string corrupts memory. |
Maybe related to #1934? |
After some research, found out |
Given how the compiler is implemented currently, returning a string from a kernel can't work, and neither for any other "allocated" type (arrays/lists), as the backing allocation for the elements is on the stack frame of If you can make |
Checked latest master, and the crash is not being reproduced anymore. Though bytes/str corruption still persists.
As for me, it still looks like a legitimate code, I'm not sure that the compiler should not accept it. |
Right, this doesn't actually have to do with RPC but with returning a string from a kernel function.
Remember that in kernels we don't have a heap. |
Also see #1298. |
Bug Report
One-Line Summary
String RPC return values (and/or kernel return values?) seem to be getting corrupted, which can indirectly cause a kernel panic.
Issue Details
Steps to Reproduce
Run the following experiment:
Expected Behavior
Prints
a string
to the console.Actual (undesired) Behavior
Prints
ring
to the console. And if you uncomment theprint
statement in the kernel it causes a kernel panic with the following message:And on the host side:
Strangely, it prints the correct string before panicking. It almost looks like the components work fine independently -- printing a string literal from the kernel works fine, as does returning a string literal from the kernel, and based on the above output it seems that the RPC return value is at least mostly correct when received in the kernel (possibly with some extra non-printable byte(s) that cause the panic?) -- but when used in conjunction this issue appears.
Your System (omit irrelevant parts)
The text was updated successfully, but these errors were encountered: