Posts
4734
Following
319
Followers
489
Linux kernel hacker and maintainer etc.

OpenPGP: 3AB05486C7752FE1
@diondokter @ekuber

~/work/github.com/jarkkojs/tpm2_library main*
❯ scripts/rustc-error.py tpm2_protocol tpm2_protocol/src/lib.rs message/mod.rs

error[E0412]: cannot find type `TpmNvUndefineSpaceSpecialCommand` in this scope
--> tpm2_protocol/src/message/mod.rs:65:6
|
65 | (TpmNvUndefineSpaceSpecialCommand, TpmNvUndefineSpaceSpecialResponse, NvUndefineSpaceSpecial),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `TpmNvUndefineSpaceSpecialResponse`
|
::: tpm2_protocol/src/macro/struct.rs:93:9
|
93 | pub struct $name {
| ---------------- similarly named struct `TpmNvUndefineSpaceSpecialResponse` defined here
|
::: tpm2_protocol/src/macro/mod.rs:174:25
|
174 | $( $variant($cmd), )*
| ---- due to this macro variable
1
0
0
@diondokter @ekuber I did some reseach and unfortunately rustc works like that :-/

well what can you do...
1
0
0
@ekuber @diondokter but yeah it's a workaround i manage to do refactorizations about 10x slower than with C and more error prone with the same factor :-) quite bad tho
1
0
0
@ekuber @diondokter of course i use less as workaround for crappy compilation flow or actually head -100 or similar
1
0
0
@TalesFromTheArmchair nope but it looks interesting, thanks :-)
0
0
0
@ekuber @diondokter can you make it stop on the first error catched? that would pretty much sort my issues.
1
0
0
@Netux yeah, so would hard to apply to the context let's put it that way :-)
1
0
1
And noticed a bug in that message that has gone unnoticed :-) with_sessions should be true also for the response.
0
0
0

Jarkko Sakkinen

Edited 16 days ago

I learned a new thing in macro_rules! i.e., pattern matching:

tpm_struct! {
    #[derive(Debug, Default, PartialEq, Eq, Clone)]
    kind: Command,
    name: TpmStartAuthSessionCommand,
    cc: TpmCc::StartAuthSession,
    no_sessions: true,
    with_sessions: true,
    handles: {
        pub tpm_key: crate::data::TpmiDhObject,
        pub bind: crate::data::TpmiDhObject,
    },
    parameters: {
        pub nonce_caller: Tpm2bNonce,
        pub encrypted_salt: Tpm2b,
        pub session_type: TpmSe,
        pub symmetric: TpmtSymDefObject,
        pub auth_hash: TpmAlgId,
    }
}

tpm_struct! {
    #[derive(Debug, Default, PartialEq, Eq, Clone)]
    kind: Response,
    name: TpmStartAuthSessionResponse,
    cc: TpmCc::StartAuthSession,
    no_sessions: true,
    with_sessions: true,
    handles: {
        pub session_handle: TpmSession,
    },
    parameters: {
        pub nonce_tpm: Tpm2bNonce,
    }
}
1
0
1

Jarkko Sakkinen

Edited 18 days ago
I can do this:

rustc --crate-type lib --crate-name tpm2_protocol tpm2_protocol/src/lib.rs --edition=2021 --emit=mir

Cool. Can I compile a single file from a crate project? This would be great when doing large refactor and not get your terminal DOS'd :-)

It's pain really. ATM, I'm refactoring out a macro called "tpm_response!" (it is replaced with pre-existing "tpm_struct!" that is extended) and I need to do similar changes to few dozen files.

I'd like to:

1. Do the edit to a single file.
2. Try if that file compiles.
3. Move on to next files.

Lack of knowledge with this makes refactors in Rust living hell TBH ...

Some constrains in my project that might help (possibly):

1. no_std
2. no deps
3. no alloc

Another way to express this: what is "gcc -c" of rustc?

#rust
3
1
1
@diondokter I can try this and share the results :-) I have to say that I don't know but I'll test this thanks.
1
0
0
@liiwi OK so there is clobber_api(), which is new to me but I have no idea if that can be used with naked...
0
0
0
@diondokter

[I edited the message had to think a bit what I meant.]

OK so, this would stdcall in C:

int __attribute__((__stdcall__)) foo() { asm(" ...

This would be naked stdcall

__attribute__((__naked__)) int __attribute__((__stdcall__)) foo() { asm(" ...

So you're correct saying that in naked version you do what you want but the difference is that you're telling GCC that "I will use stdcall". This makes the function compile equally well in Linux and Windows.

GCC won't create epilogue and prologue for you but it will make the assumptions based on stdcall how you've organized the function from callers perspective. I don't know how to do this in Rust.
1
0
0

Jarkko Sakkinen

Edited 18 days ago
Can you specify calling convention for assembly (with asm, global_asm etc.)? I mean things like stdcall and cdecl in C and GCC...

I could not find anything and it'd be a huge limitation...

#rust #assembly
2
2
1

[video] Blastromen (a.k.a. Sami Koskivaara & Mika Rosenberg) - Live @ Hellsinki Industrial Festival, Tiivistämö, Helsinki, Finland, 8 November 2024.

https://www.youtube.com/watch?v=g10owNrqthA

0
2
0
Edited 19 days ago

Real or @NanoRaptor

Well this an IBM 5120 https://en.wikipedia.org/wiki/IBM_5120 a preliminary system to the IBM PC.

1
2
0

Jarkko Sakkinen

Very cool, I start to participate to tpm-rs meetings :-) My project is not a conflicting entity, it's just the protocol layer isolated and made for import (a design choice driven by kernel ofc).

I was just worried what are the thoughts when I come from the woods and say that here's 7000 lines of source code, please repeal and replace but initial feedback is actually quite positive.

For kernel (and tpm-rs) if/when kernel has TPM2 support on Rust side the model could be a bit similar as it is for ACPICA. You have a fast policy-free upstream that tracks the protocol spec as it develops and import cycle.

Would be great to see tpm-rs story to continue but obviously they make their choices.
0
1
1
@teotwaki not for all projects but for basic protocol implementations that you want translate to any environment, it's really useful to focus on this type of robustness.

E.g., for zmodem2 I'm redesigning it as something that walks and talks stream trait implementation but is not such [1]. Then in my example apps I'll migrate them to Tokio and demonstrate how to wrap it for that use and purpose.

With traits, when I use them, my strategy is usually pick stuff that gets the first iteration done fastest. Then I start to drop over time stuff that maturizes and keep only the essential traits. If you have stable code, the benefit of productivity in the first phase starts to degenerate into something that can get in the way of bug fixes etc.

[1] https://docs.rs/futures/latest/futures/stream/
0
0
0
Show older