-
-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add Rust bindings to MicroPython and trezorhal
core: Remove dangling module decls core: Use new Cargo feature resolver, use external MacOS debug info core: Rust docs improvements core: Upgrade bindgen core: Add test target to Rust ci: build rust sources build(core): .ARM.exidx.text.__aeabi_ui2f in t1 firmware size It's an unwind table for softfloat function inserted by rustc, probably can be removed to save 8 bytes: /~https://github.com/rust-embedded/cortex-m-rt/blob/599c58db70c5dd4eb1dfb92e1dad7c80ed848937/link.x.in#L175-L182 scons: Remove dead code core: Move Rust target to build/rust core: Replace extern with a FFI version core: Add some explanatory Rust comments core: Use correct path for the Rust lib core: Remove Buffer::as_mut() Mutable buffer access needs MP_BUFFER_WRITE flag. TBD in the Protobuf PR. core: Improve docs for micropython::Buffer core: Minor Rust docs changes core: Rewrite trezor_obj_get_ll_checked core: Fix incorrect doc comment core: Remove cc from deps fixup! core: Rewrite trezor_obj_get_ll_checked core: update safety comments
- Loading branch information
Showing
38 changed files
with
2,151 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rust FFI for MicroPython. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of the Trezor project, https://trezor.io/ | ||
* | ||
* Copyright (c) SatoshiLabs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <string.h> | ||
|
||
#include "memzero.h" | ||
#include "py/objint.h" | ||
|
||
static bool mpz_as_ll_checked(const mpz_t *i, long long *value) { | ||
// Analogue of `mpz_as_int_checked` from mpz.c | ||
|
||
unsigned long long val = 0; | ||
mpz_dig_t *d = i->dig + i->len; | ||
|
||
while (d-- > i->dig) { | ||
if (val > (~0x8000000000000000 >> MPZ_DIG_SIZE)) { | ||
// will overflow | ||
*value = 0; | ||
return false; | ||
} | ||
val = (val << MPZ_DIG_SIZE) | *d; | ||
} | ||
|
||
if (i->neg != 0) { | ||
val = -val; | ||
} | ||
|
||
*value = val; | ||
return true; | ||
} | ||
|
||
bool trezor_obj_get_ll_checked(mp_obj_t obj, long long *value) { | ||
if (mp_obj_is_small_int(obj)) { | ||
// Value is fitting in a small int range. Return it directly. | ||
*value = MP_OBJ_SMALL_INT_VALUE(obj); | ||
return true; | ||
|
||
} else if (mp_obj_is_type(obj, &mp_type_int)) { | ||
// Value is not fitting into small int range, but is an integer. | ||
mp_obj_int_t *self = MP_OBJ_TO_PTR(obj); | ||
// Try to get the long long value out of the MPZ struct. | ||
return mpz_as_ll_checked(&self->mpz, value); | ||
} else { | ||
// Value is not integer. | ||
*value = 0; | ||
return false; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
target-dir = "../../build/rust" |
Oops, something went wrong.