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

wasi: Implement random_get function #241

Merged
merged 12 commits into from
Feb 15, 2022

Conversation

r8d8
Copy link
Contributor

@r8d8 r8d8 commented Feb 14, 2022

Fixed sign-off from original PR #237

r8d8 added 5 commits February 14, 2022 14:04
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Signed-off-by: r8d8 <ckryvomaz@gmail.com>
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
* Remove random generator from WASM structure.
* Adjust formatting and naming.

Signed-off-by: r8d8 <ckryvomaz@gmail.com>
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Use pseudo-random source in tests.

Signed-off-by: r8d8 <ckryvomaz@gmail.com>
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
@r8d8 r8d8 marked this pull request as draft February 14, 2022 12:09
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
@r8d8 r8d8 marked this pull request as ready for review February 14, 2022 13:27
wasi/wasi.go Outdated Show resolved Hide resolved
wasi/wasi.go Outdated Show resolved Hide resolved
wasi/wasi.go Outdated Show resolved Hide resolved
wasi/wasi_test.go Outdated Show resolved Hide resolved
wasi/wasi_test.go Outdated Show resolved Hide resolved
wasi/wasi.go Outdated
random_bytes := make([]byte, bufLen)
_, err := a.randSource.Read(random_bytes)
if err != nil {
return ErrnoInval
Copy link
Member

Choose a reason for hiding this comment

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

ErronoInval is for invalid arguments right? Is this the correct error for here?

Copy link
Member

@mathetake mathetake Feb 14, 2022

Choose a reason for hiding this comment

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

I would recommend take a look at spec and also WASI-libc and see how other impl(e.g. Wasm time) handle errors

Copy link
Contributor Author

@r8d8 r8d8 Feb 15, 2022

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI for bad memory offsets, we discussed offline to use ErrnoFault. Main thing is to document what is used and be consistent even if no one else is :D

Later, people can argue validly with these choices and probably we need to raise an issue on the wasi spec as it is underspecified. Main thing now is to document what you do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@codefromthecrypt thanks for info.
So, for invalid buf, bufLen return error is ErrnoFault. Am I getting right?
And how to deal with errors from random source ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ErrnoIO for the source is fine for now. we can change it easily later if we find a most standard code

Copy link
Contributor

Choose a reason for hiding this comment

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

I found the issue that has been punted quite a while so far WebAssembly/WASI#215

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error codes stuff gets you confused even more in functions that a more compilated than random_get. Spec need to address it.

Copy link
Contributor

Choose a reason for hiding this comment

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

totally agree. appreciate if you can make your case on the spec issue because it was 2 years already so somehow they aren't prioritizing. maybe if more scream they will 🤷

Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
r8d8 added 3 commits February 15, 2022 10:06
Remove random source interface, use functor instead
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

nearly there!

wasi/testdata/random.wat Outdated Show resolved Hide resolved
wasi/wasi_test.go Show resolved Hide resolved
@codefromthecrypt
Copy link
Contributor

drift alert and apologies for it (again blush) #246

if you need help resolving conflicts ask and I can do that for you.

Add test case for random source error

Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

Thanks for the great work.

Signed-off-by: Constantine Kryvomaz <ckryvomaz@gmail.com>
@r8d8
Copy link
Contributor Author

r8d8 commented Feb 15, 2022

Thanks for patience @codefromthecrypt @mathetake

@mathetake mathetake merged commit 121e0e5 into tetratelabs:main Feb 15, 2022
@mathetake
Copy link
Member

Thank you for you contribution! 💯🙌🏄‍♂️ @r8d8

@codefromthecrypt
Copy link
Contributor

ps if you are using something besides tinygo and/or need a WASI API not defined here, please pipe up in the issue #271

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.

3 participants