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

Dev utils tokyo 5 dm perms #13

Open
wants to merge 186 commits into
base: dm-cpi-memory-perm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
eb69052
save 2023y07m28d06h21m43s433313277ns
ryoqun Jul 28, 2023
5d4541d
save 2023y07m28d06h22m01s774904507ns
ryoqun Jul 28, 2023
8bb70e3
save 2023y07m28d06h23m57s444273856ns
ryoqun Jul 28, 2023
58b3891
save 2023y07m28d06h24m17s178500970ns
ryoqun Jul 28, 2023
abf452a
save 2023y07m28d06h28m17s811365537ns
ryoqun Jul 28, 2023
bdd5fc4
save 2023y07m28d06h28m36s072576954ns
ryoqun Jul 28, 2023
a4283b1
save 2023y07m28d06h28m54s504500751ns
ryoqun Jul 28, 2023
4643079
save 2023y07m28d06h31m15s379322004ns
ryoqun Jul 28, 2023
848bcf9
save 2023y07m28d06h31m23s250190331ns
ryoqun Jul 28, 2023
a47cf91
save 2023y07m28d06h31m32s714918387ns
ryoqun Jul 28, 2023
247da4b
save 2023y07m28d06h31m43s277634046ns
ryoqun Jul 28, 2023
2e634c2
save 2023y07m28d06h33m24s345954860ns
ryoqun Jul 28, 2023
12af21f
save 2023y07m28d06h36m12s840661418ns
ryoqun Jul 28, 2023
a6991ab
save 2023y07m28d06h43m43s720651718ns
ryoqun Jul 28, 2023
888b888
save 2023y07m28d06h44m33s956829950ns
ryoqun Jul 28, 2023
15a9be8
save 2023y07m28d06h52m21s595520387ns
ryoqun Jul 28, 2023
36d3504
save 2023y07m28d06h53m31s882195368ns
ryoqun Jul 28, 2023
f434fe8
save 2023y07m28d06h57m39s857877030ns
ryoqun Jul 28, 2023
4b1a69c
save 2023y07m28d07h04m16s041315668ns
ryoqun Jul 28, 2023
44c246a
save 2023y07m28d07h04m50s142936784ns
ryoqun Jul 28, 2023
06ff98b
save 2023y07m28d07h05m50s365005184ns
ryoqun Jul 28, 2023
d47a96b
save 2023y07m28d07h07m34s719597562ns
ryoqun Jul 28, 2023
2057a54
save 2023y07m28d07h09m32s699809534ns
ryoqun Jul 28, 2023
609e283
save 2023y07m28d07h13m44s663107003ns
ryoqun Jul 28, 2023
dc22236
save 2023y07m28d07h14m06s413878210ns
ryoqun Jul 28, 2023
231cb5f
save 2023y07m28d07h14m15s366534391ns
ryoqun Jul 28, 2023
f46a34d
save 2023y07m28d07h15m07s643802352ns
ryoqun Jul 28, 2023
c4cea00
save 2023y07m28d07h15m14s986987519ns
ryoqun Jul 28, 2023
1f386d0
save 2023y07m28d07h15m26s331213456ns
ryoqun Jul 28, 2023
4dfe2ee
save 2023y07m28d07h16m22s073538886ns
ryoqun Jul 28, 2023
6aaa633
save 2023y07m28d07h16m47s639532354ns
ryoqun Jul 28, 2023
4aa787b
save 2023y07m28d07h18m21s765467994ns
ryoqun Jul 28, 2023
2a55276
save 2023y07m28d07h19m27s721246461ns
ryoqun Jul 28, 2023
7db94ce
save 2023y07m28d07h21m21s403730565ns
ryoqun Jul 28, 2023
0a0c2e6
save 2023y07m28d07h22m50s480100921ns
ryoqun Jul 28, 2023
5a1677c
save 2023y07m28d07h24m09s782253297ns
ryoqun Jul 28, 2023
1b5213f
save 2023y07m28d07h26m30s880125815ns
ryoqun Jul 28, 2023
c183ceb
save 2023y07m28d07h48m17s158502671ns
ryoqun Jul 28, 2023
86c20b9
save 2023y07m28d07h49m31s313402035ns
ryoqun Jul 28, 2023
1c5df8b
save 2023y07m28d07h51m33s470611560ns
ryoqun Jul 28, 2023
5f4f10e
save 2023y07m28d07h54m53s328950385ns
ryoqun Jul 28, 2023
4e5574b
save 2023y07m28d07h55m05s097453443ns
ryoqun Jul 28, 2023
ce33c08
save 2023y07m28d07h56m51s251528037ns
ryoqun Jul 28, 2023
83d423d
save 2023y07m28d14h26m33s021709965ns
ryoqun Jul 28, 2023
2e61c81
save 2023y07m28d14h31m10s265768122ns
ryoqun Jul 28, 2023
fcffc14
save 2023y07m28d14h31m29s277650768ns
ryoqun Jul 28, 2023
c320db7
save 2023y07m28d14h32m00s989804023ns
ryoqun Jul 28, 2023
ae44b7e
save 2023y07m28d14h34m09s858490056ns
ryoqun Jul 28, 2023
197909f
save 2023y07m28d14h37m55s220367008ns
ryoqun Jul 28, 2023
192f22c
save 2023y07m28d14h38m01s206181808ns
ryoqun Jul 28, 2023
176490a
save 2023y07m28d14h39m17s843699112ns
ryoqun Jul 28, 2023
fc30904
save 2023y07m28d14h43m00s378715264ns
ryoqun Jul 28, 2023
5452b09
save 2023y07m28d14h43m49s647796971ns
ryoqun Jul 28, 2023
265ad59
save 2023y07m28d14h47m26s152761169ns
ryoqun Jul 28, 2023
09093c1
save 2023y07m28d14h47m43s184468519ns
ryoqun Jul 28, 2023
c742398
save 2023y07m28d14h48m34s065914751ns
ryoqun Jul 28, 2023
d82993b
save 2023y07m28d14h48m47s894117491ns
ryoqun Jul 28, 2023
363caac
save 2023y07m28d14h50m27s595947293ns
ryoqun Jul 28, 2023
08a42fd
save 2023y07m28d14h51m30s430084864ns
ryoqun Jul 28, 2023
8bb49e7
save 2023y07m28d14h58m34s697149087ns
ryoqun Jul 28, 2023
911bd8d
save 2023y07m28d15h04m59s790937103ns
ryoqun Jul 28, 2023
913b148
save 2023y07m28d15h06m56s664800377ns
ryoqun Jul 28, 2023
b7dd2e5
save 2023y07m28d15h08m08s894261156ns
ryoqun Jul 28, 2023
ffc735f
save 2023y07m28d15h08m52s347902675ns
ryoqun Jul 28, 2023
e45ff00
save 2023y07m28d15h10m04s575800548ns
ryoqun Jul 28, 2023
38d8f57
save 2023y07m28d15h11m57s441985952ns
ryoqun Jul 28, 2023
a36f6da
save 2023y07m28d15h13m05s480327664ns
ryoqun Jul 28, 2023
311c0cf
save 2023y07m28d15h14m06s691729257ns
ryoqun Jul 28, 2023
4004754
save 2023y07m28d15h16m01s806365628ns
ryoqun Jul 28, 2023
d95ec2c
save 2023y07m28d15h19m14s280571385ns
ryoqun Jul 28, 2023
4651777
save 2023y07m28d15h20m40s283731336ns
ryoqun Jul 28, 2023
face419
save 2023y07m28d15h22m17s703241697ns
ryoqun Jul 28, 2023
bbebfbd
save 2023y07m28d15h26m07s197002617ns
ryoqun Jul 28, 2023
2b4a930
save 2023y07m28d15h26m16s036402748ns
ryoqun Jul 28, 2023
dcc789f
save 2023y07m28d15h26m34s164569768ns
ryoqun Jul 28, 2023
7361077
save 2023y07m28d15h28m13s135645866ns
ryoqun Jul 28, 2023
efbffcd
save 2023y07m28d15h28m25s248069264ns
ryoqun Jul 28, 2023
a6dab92
save 2023y07m28d15h30m57s523298572ns
ryoqun Jul 28, 2023
6142f20
save 2023y07m28d15h31m05s536543493ns
ryoqun Jul 28, 2023
0a979ee
save 2023y07m28d15h32m11s349568642ns
ryoqun Jul 28, 2023
fb0ef00
save 2023y07m28d15h34m21s120854871ns
ryoqun Jul 28, 2023
3ad6e8f
save 2023y07m28d15h35m32s664771489ns
ryoqun Jul 28, 2023
5bb7e32
save 2023y07m28d15h36m14s293724809ns
ryoqun Jul 28, 2023
d6acfd5
save 2023y07m29d03h15m26s515490719ns
ryoqun Jul 29, 2023
3cbb731
save 2023y07m29d03h19m16s262632523ns
ryoqun Jul 29, 2023
051d758
save 2023y07m29d03h20m02s947161821ns
ryoqun Jul 29, 2023
70f2140
save 2023y07m29d03h20m47s900064623ns
ryoqun Jul 29, 2023
eaf4f63
save 2023y07m29d03h26m13s732453308ns
ryoqun Jul 29, 2023
419febd
save 2023y07m29d03h28m51s199572136ns
ryoqun Jul 29, 2023
cd457bd
save 2023y07m29d03h29m57s535576656ns
ryoqun Jul 29, 2023
9d45b15
save 2023y07m29d03h32m46s480629421ns
ryoqun Jul 29, 2023
53e97ef
save 2023y07m29d03h39m59s552675321ns
ryoqun Jul 29, 2023
77a144d
save 2023y07m29d03h49m55s322566792ns
ryoqun Jul 29, 2023
ef33831
save 2023y07m29d03h57m36s896099263ns
ryoqun Jul 29, 2023
e47a4b6
save 2023y07m29d03h57m44s996575542ns
ryoqun Jul 29, 2023
afc3b5a
save 2023y07m29d03h57m52s333221527ns
ryoqun Jul 29, 2023
3101b0f
save 2023y07m29d04h01m25s149686370ns
ryoqun Jul 29, 2023
d252023
save 2023y07m29d04h04m15s183490291ns
ryoqun Jul 29, 2023
926361a
save 2023y07m29d04h05m20s524598720ns
ryoqun Jul 29, 2023
6a36666
save 2023y07m29d04h05m40s300406377ns
ryoqun Jul 29, 2023
bcefcf0
save 2023y07m29d04h06m44s459445828ns
ryoqun Jul 29, 2023
03a2491
save 2023y07m29d04h07m07s824230324ns
ryoqun Jul 29, 2023
32249dd
save 2023y07m29d04h07m15s158145708ns
ryoqun Jul 29, 2023
da5e17f
save 2023y07m29d04h09m32s094823844ns
ryoqun Jul 29, 2023
42cf40e
save 2023y07m29d04h10m45s622104513ns
ryoqun Jul 29, 2023
ce98c18
save 2023y07m29d04h12m27s061307524ns
ryoqun Jul 29, 2023
4c06ced
save 2023y07m29d04h12m44s133806986ns
ryoqun Jul 29, 2023
56ff291
save 2023y07m29d04h14m50s713251620ns
ryoqun Jul 29, 2023
a3e2e02
save 2023y07m29d04h14m56s526890934ns
ryoqun Jul 29, 2023
f10ded8
save 2023y07m29d04h16m57s984454602ns
ryoqun Jul 29, 2023
da3af85
save 2023y07m29d04h17m08s358119513ns
ryoqun Jul 29, 2023
32eca01
save 2023y07m29d04h17m17s110655691ns
ryoqun Jul 29, 2023
683107e
save 2023y07m29d04h17m24s501854806ns
ryoqun Jul 29, 2023
1fa6e2a
save 2023y07m29d04h18m55s305135587ns
ryoqun Jul 29, 2023
6be3287
save 2023y07m29d04h24m54s028484002ns
ryoqun Jul 29, 2023
169321b
save 2023y07m29d04h25m38s479016646ns
ryoqun Jul 29, 2023
0a6c47c
save 2023y07m29d04h27m56s440728820ns
ryoqun Jul 29, 2023
3cb8618
save 2023y07m29d04h31m45s835102161ns
ryoqun Jul 29, 2023
0c5b846
save 2023y07m29d04h34m00s121600960ns
ryoqun Jul 29, 2023
e801f76
save 2023y07m29d04h35m02s863095700ns
ryoqun Jul 29, 2023
eff583b
save 2023y07m29d04h38m36s982285284ns
ryoqun Jul 29, 2023
4fcf795
save 2023y07m29d04h44m09s180979571ns
ryoqun Jul 29, 2023
2f30979
save 2023y07m29d04h45m22s147275765ns
ryoqun Jul 29, 2023
3cfc6ff
save 2023y07m29d04h50m29s951144809ns
ryoqun Jul 29, 2023
0df3dab
save 2023y07m29d04h59m43s106675487ns
ryoqun Jul 29, 2023
dece191
save 2023y07m29d05h03m03s924250288ns
ryoqun Jul 29, 2023
aa9db90
save 2023y07m29d05h03m56s877114598ns
ryoqun Jul 29, 2023
7c779db
save 2023y07m29d05h05m38s854166460ns
ryoqun Jul 29, 2023
4aff53e
save 2023y07m29d05h05m55s878226577ns
ryoqun Jul 29, 2023
fbd195b
save 2023y07m29d05h06m05s845686312ns
ryoqun Jul 29, 2023
f806bb8
save 2023y07m29d05h10m39s228849039ns
ryoqun Jul 29, 2023
c0966f8
save 2023y07m29d05h12m04s554536668ns
ryoqun Jul 29, 2023
1367f22
save 2023y07m29d05h13m11s390465585ns
ryoqun Jul 29, 2023
6752a1f
save 2023y07m29d05h21m52s707752200ns
ryoqun Jul 29, 2023
b856535
save 2023y07m29d05h23m31s362436474ns
ryoqun Jul 29, 2023
5e77461
save 2023y07m29d05h24m39s493437732ns
ryoqun Jul 29, 2023
6d4d237
save 2023y07m30d12h26m49s485069832ns
ryoqun Jul 30, 2023
6936148
save 2023y07m30d12h27m31s377171416ns
ryoqun Jul 30, 2023
f794fca
save 2023y07m30d12h27m58s039202454ns
ryoqun Jul 30, 2023
b9156d9
save 2023y07m30d12h30m43s368143054ns
ryoqun Jul 30, 2023
9fc8006
save 2023y07m30d12h31m16s935532633ns
ryoqun Jul 30, 2023
83c4938
save 2023y07m30d12h31m35s352132040ns
ryoqun Jul 30, 2023
ba88847
save 2023y07m30d12h31m50s285861618ns
ryoqun Jul 30, 2023
957e9aa
save 2023y07m30d12h33m08s162151536ns
ryoqun Jul 30, 2023
404c259
save 2023y07m30d12h33m22s809343687ns
ryoqun Jul 30, 2023
e1f4e17
save 2023y07m30d12h39m23s759879640ns
ryoqun Jul 30, 2023
134b381
save 2023y07m30d12h40m57s978214723ns
ryoqun Jul 30, 2023
cb86113
save 2023y07m30d12h50m43s742550615ns
ryoqun Jul 30, 2023
94827d9
save 2023y07m30d12h53m07s861866926ns
ryoqun Jul 30, 2023
90b0b06
save 2023y07m30d13h21m58s795732065ns
ryoqun Jul 30, 2023
37a9ea6
save 2023y07m30d13h22m56s520766994ns
ryoqun Jul 30, 2023
b04796f
save 2023y07m30d13h28m54s081454446ns
ryoqun Jul 30, 2023
8f3a91c
save 2023y07m30d13h29m44s561188110ns
ryoqun Jul 30, 2023
f58d887
save 2023y07m30d13h30m27s070592043ns
ryoqun Jul 30, 2023
fcfa15f
save 2023y07m30d13h36m34s719666960ns
ryoqun Jul 30, 2023
02fa3fe
save 2023y07m30d13h36m49s580302919ns
ryoqun Jul 30, 2023
cf11cb7
save 2023y07m30d13h40m58s403543668ns
ryoqun Jul 30, 2023
c9121d3
save 2023y07m30d13h41m59s970323501ns
ryoqun Jul 30, 2023
ee3e4d0
save 2023y07m30d13h42m35s289849316ns
ryoqun Jul 30, 2023
9947405
save 2023y07m30d13h42m48s096463155ns
ryoqun Jul 30, 2023
7100a23
save 2023y07m30d13h43m01s007515332ns
ryoqun Jul 30, 2023
9429f3c
save 2023y07m30d13h53m18s973116575ns
ryoqun Jul 30, 2023
22e8227
save 2023y07m30d14h30m23s756293207ns
ryoqun Jul 30, 2023
d0aabfa
save 2023y07m30d14h31m45s110978040ns
ryoqun Jul 30, 2023
127b358
save 2023y07m30d14h35m04s717428954ns
ryoqun Jul 30, 2023
70c2c78
save 2023y07m30d14h35m30s316172500ns
ryoqun Jul 30, 2023
834a571
save 2023y07m30d14h36m04s981984327ns
ryoqun Jul 30, 2023
0be322c
save 2023y07m30d14h38m11s864492304ns
ryoqun Jul 30, 2023
0774cf2
save 2023y07m30d14h41m37s341844633ns
ryoqun Jul 30, 2023
e45e905
save 2023y07m30d14h43m38s130706543ns
ryoqun Jul 30, 2023
64323ef
save 2023y07m30d14h47m21s270680202ns
ryoqun Jul 30, 2023
a8b1b58
save 2023y07m30d14h52m28s294434791ns
ryoqun Jul 30, 2023
e7035d3
save 2023y07m30d14h53m32s565872330ns
ryoqun Jul 30, 2023
1549b4b
save 2023y07m30d14h54m11s588581990ns
ryoqun Jul 30, 2023
3f34a55
save 2023y07m30d14h54m30s675311600ns
ryoqun Jul 30, 2023
672ffd3
save 2023y07m30d14h56m07s826695479ns
ryoqun Jul 30, 2023
974a00f
save 2023y07m30d15h01m27s793036654ns
ryoqun Jul 30, 2023
81ac180
save 2023y07m30d15h06m18s649309037ns
ryoqun Jul 30, 2023
645aa3d
save 2023y07m31d05h59m59s341460720ns
ryoqun Jul 31, 2023
0208cdd
save 2023y07m31d06h43m06s060132190ns
ryoqun Jul 31, 2023
fad3d49
save 2023y07m31d06h44m06s000579771ns
ryoqun Jul 31, 2023
2c2043b
save 2023y07m31d06h46m45s571531256ns
ryoqun Jul 31, 2023
4f85812
save 2023y07m31d06h53m27s425813924ns
ryoqun Jul 31, 2023
f87729b
save 2023y07m31d06h54m47s711776014ns
ryoqun Jul 31, 2023
0beb96f
save 2023y07m31d06h57m07s634894577ns
ryoqun Jul 31, 2023
975a6f0
save 2023y07m31d06h59m40s891440918ns
ryoqun Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions program-runtime/src/stable_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ pub fn program_invoke(
program_id: &Pubkey,
invoke_depth: usize,
) {
ic_logger_msg!(
/*ic_logger_msg!(
log_collector,
"Program {} invoke [{}]",
program_id,
invoke_depth
);
*/
}

/// Log a message from the program itself.
Expand Down Expand Up @@ -91,7 +92,7 @@ pub fn program_return(
/// "Program <address> success"
/// ```
pub fn program_success(log_collector: &Option<Rc<RefCell<LogCollector>>>, program_id: &Pubkey) {
ic_logger_msg!(log_collector, "Program {} success", program_id);
//ic_logger_msg!(log_collector, "Program {} success", program_id);
}

/// Log program execution failure
Expand Down
11 changes: 11 additions & 0 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,22 @@ pub fn create_vm<'a, 'b>(
.touch(index_in_transaction as IndexOfAccount)
.map_err(|_| ())?;

use solana_sdk::account::ReadableAccount;
log::warn!("cow {index_in_transaction} is_shared: {} len: {}, capacity: {}", account.is_shared(), account.data().len(), account.capacity());
if account.is_shared() {
// See BorrowedAccount::make_data_mut() as to why we reserve extra
// MAX_PERMITTED_DATA_INCREASE bytes here.
account.reserve(MAX_PERMITTED_DATA_INCREASE);
let dst = account
.spare_data_capacity_mut();
let mut r = 0x77;
for d in dst {
d.write(r);
r = r.wrapping_add(1);
}
//unsafe { std::ptr::write_bytes(dst, 0x77, 200) };
}
log::warn!("cow {index_in_transaction} new capacity: {}", account.capacity());
Ok(account.data_as_mut_slice().as_mut_ptr() as u64)
})),
)?;
Expand Down
30 changes: 26 additions & 4 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn check_account_info_pointer(
field: &str,
) -> Result<(), Error> {
if vm_addr != expected_vm_addr {
debug!(
log::warn!(
"Invalid account info pointer `{}': {:#x} != {:#x}",
field, vm_addr, expected_vm_addr
);
Expand All @@ -41,6 +41,17 @@ enum VmValue<'a, 'b, T> {
}

impl<'a, 'b, T> VmValue<'a, 'b, T> {
fn debug(&self) -> String {
match self {
VmValue::VmAddress {
vm_addr,
memory_mapping,
check_aligned,
} => format!("VmValue::VmAddress: {vm_addr:x}"),
VmValue::Translated(addr) => format!("VmValue::Translated: {addr:p}"),
}
}

fn get(&self) -> Result<&T, Error> {
match self {
VmValue::VmAddress {
Expand Down Expand Up @@ -1137,6 +1148,8 @@ fn cpi_common<S: SyscallInvokeSigned>(
}
}

log::warn!("update_caller_account loop start!");
defer!(log::warn!("update_caller_account loop end!"));
for (index_in_caller, caller_account) in accounts.iter_mut() {
if let Some(caller_account) = caller_account {
let mut callee_account = instruction_context
Expand Down Expand Up @@ -1178,9 +1191,11 @@ fn update_callee_account(
callee_account.set_lamports(*caller_account.lamports)?;
}

let prev_len = callee_account.get_data().len();
let post_len = *caller_account.ref_to_len_in_vm.get()? as usize;
log::warn!("update_callee_account() begin! prev_len: {prev_len} post_len: {post_len} direct_mapping: {direct_mapping} {}", caller_account.ref_to_len_in_vm.debug());
defer!(log::warn!("update_callee_account() end!"));
if direct_mapping {
let prev_len = callee_account.get_data().len();
let post_len = *caller_account.ref_to_len_in_vm.get()? as usize;
match callee_account
.can_data_be_resized(post_len)
.and_then(|_| callee_account.can_data_be_changed())
Expand Down Expand Up @@ -1337,6 +1352,7 @@ fn update_caller_account(
// memory), so that the account's memory region never points to an
// invalid address.
let min_capacity = caller_account.original_data_len;
log::warn!("callee_capacity: {} < min_capacity: {} => {}", callee_account.capacity(), min_capacity, callee_account.capacity() < min_capacity);
if callee_account.capacity() < min_capacity {
callee_account.reserve(min_capacity.saturating_sub(callee_account.capacity()))?;
zero_all_spare_capacity = true;
Expand All @@ -1348,6 +1364,7 @@ fn update_caller_account(
// spaces are fixed so we don't need to update the MemoryRegion's
// length.
let callee_ptr = callee_account.get_data().as_ptr() as u64;
log::warn!("region.host_addr: {}, callee_ptr: {} => {}", region.host_addr.get(), callee_ptr, region.host_addr.get() != callee_ptr);
if region.host_addr.get() != callee_ptr {
region.host_addr.set(callee_ptr);
zero_all_spare_capacity = true;
Expand All @@ -1358,6 +1375,8 @@ fn update_caller_account(
let prev_len = *caller_account.ref_to_len_in_vm.get()? as usize;
let post_len = callee_account.get_data().len();
let realloc_bytes_used = post_len.saturating_sub(caller_account.original_data_len);
log::warn!("update_caller_account() begin! prev_len: {prev_len} post_len: {post_len} realloc_bytes_used: {realloc_bytes_used} zero_all_spare_capacity: {zero_all_spare_capacity}! original_data_len: {}", caller_account.original_data_len);
defer!(log::warn!("update_caller_account() end!"));
if prev_len != post_len {
let max_increase = if direct_mapping && !invoke_context.get_check_aligned() {
0
Expand Down Expand Up @@ -1401,15 +1420,17 @@ fn update_caller_account(
prev_len
}
.saturating_sub(post_len);
log::warn!("spare1: {:02x?}", unsafe { std::mem::transmute::<_, Option<&[u8]>>(callee_account.spare_data_capacity_mut()?.get(..50))});
if spare_len > 0 {
let dst = callee_account
.spare_data_capacity_mut()?
.get_mut(..spare_len)
.ok_or_else(|| Box::new(InstructionError::AccountDataTooSmall))?
.as_mut_ptr();
// Safety: we check bounds above
unsafe { ptr::write_bytes(dst, 0, spare_len) };
unsafe { ptr::write_bytes(dst, 0x11, spare_len) };
}
log::warn!("spare2: {:02x?}", unsafe { std::mem::transmute::<_, Option<&[u8]>>(callee_account.spare_data_capacity_mut()?.get(..50))});

// Here we zero the realloc region.
//
Expand Down Expand Up @@ -1483,6 +1504,7 @@ fn update_caller_account(
)?;
}
// this is the len field in the AccountInfo::data slice
log::warn!("update: direct_mapping: {:?} {:?} len change: {prev_len} => {post_len}!", direct_mapping, caller_account.ref_to_len_in_vm.debug());
*caller_account.ref_to_len_in_vm.get_mut()? = post_len as u64;

// this is the len field in the serialized parameters
Expand Down
45 changes: 2 additions & 43 deletions programs/sbf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,51 +63,10 @@ fn main() {
let install_dir = "target/".to_string() + &env::var("PROFILE").unwrap() + "/sbf";

let rust_programs = [
"128bit",
"alloc",
"alt_bn128",
"big_mod_exp",
"call_depth",
"caller_access",
"curve25519",
"custom_heap",
"dep_crate",
"deprecated_loader",
"dup_accounts",
"error_handling",
"log_data",
"external_spend",
"finalize",
"get_minimum_delegation",
"inner_instruction_alignment_check",
"instruction_introspection",
"invoke",
"invoke_and_error",
"invoke_and_ok",
"invoke_and_return",
"invoked",
"iter",
"many_args",
"mem",
"membuiltins",
"noop",
"panic",
"param_passing",
"rand",
//"invoked",
"realloc",
"realloc_invoke",
"ro_modify",
"ro_account_modify",
"sanity",
"secp256k1_recover",
"sha",
"sibling_inner_instruction",
"sibling_instruction",
"simulation",
"spoof1",
"spoof1_system",
"upgradeable",
"upgraded",
//"realloc_invoke",
];
for program in rust_programs.iter() {
println!("cargo:warning=(not a warning) Building Rust-based on-chain programs: solana_sbf_rust_{program}");
Expand Down
1 change: 1 addition & 0 deletions programs/sbf/rust/invoke/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub const TEST_CPI_INVALID_LAMPORTS_POINTER: u8 = 36;
pub const TEST_CPI_INVALID_DATA_POINTER: u8 = 37;
pub const TEST_CPI_CHANGE_ACCOUNT_DATA_MEMORY_ALLOCATION: u8 = 38;
pub const TEST_WRITE_ACCOUNT: u8 = 39;
pub const SELF_CPI: u8 = 40;

pub const MINT_INDEX: usize = 0;
pub const ARGUMENT_INDEX: usize = 1;
Expand Down
143 changes: 112 additions & 31 deletions programs/sbf/rust/invoke/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,56 +851,112 @@ fn process_instruction(
let target_account = &accounts[target_account_index];
let realloc_program_id = accounts[REALLOC_PROGRAM_INDEX].key;
let invoke_program_id = accounts[INVOKE_PROGRAM_INDEX].key;
account.realloc(0, false).unwrap();
account.assign(realloc_program_id);
target_account.realloc(0, false).unwrap();
target_account.assign(realloc_program_id);
//account.realloc(0, false).unwrap();
//account.assign(realloc_program_id);
//target_account.realloc(50, false).unwrap();
let target_len = target_account.data.borrow().len();
//msg!("target realloc to {}", target_len);
//target_account.data.borrow_mut()[2] = 0;
//target_account.assign(realloc_program_id);
let orig_target_account_data = target_account.data.clone();
msg!("data+spare: {:02x?}", unsafe { slice::from_raw_parts(account.data.borrow().as_ptr(), 100) });
msg!("data+spare: {:02x?}", unsafe { slice::from_raw_parts(target_account.data.borrow().as_ptr(), 100) });
//msg!("data+spare: {:02x?}", unsafe { slice::from_raw_parts(orig_target_account_data.borrow().as_ptr(), 100) });
msg!("len: {}", account.data.borrow().len());
//msg!("len: {}", target_account.data.borrow().len());
//msg!("len: {}", orig_target_account_data.borrow().len());

let rc_box_addr =
target_account.data.borrow_mut().as_mut_ptr() as *mut RcBox<RefCell<&mut [u8]>>;
let rc_box_size = mem::size_of::<RcBox<RefCell<&mut [u8]>>>();
account.data.borrow_mut().as_mut_ptr() as *mut RcBox<RefCell<&mut [u8]>>;
let rc_box = RcBox {
strong: 1,
weak: 0,
// The difference with
// TEST_FORBID_LEN_UPDATE_AFTER_OWNERSHIP_CHANGE_MOVING_DATA_POINTER
// is that we don't move the data pointer past the
// RcBox. This is needed to avoid the "Invalid account
// info pointer" check when direct mapping is enabled.
// This also means we don't need to update the
// serialized len like we do in the other test.
value: unsafe { RefCell::new(slice::from_raw_parts_mut(
target_account.data.borrow_mut().as_mut_ptr(),
target_len,
)) },
};
unsafe {
std::ptr::write(
rc_box_addr,
RcBox {
strong: 1,
weak: 0,
// The difference with
// TEST_FORBID_LEN_UPDATE_AFTER_OWNERSHIP_CHANGE_MOVING_DATA_POINTER
// is that we don't move the data pointer past the
// RcBox. This is needed to avoid the "Invalid account
// info pointer" check when direct mapping is enabled.
// This also means we don't need to update the
// serialized len like we do in the other test.
value: RefCell::new(slice::from_raw_parts_mut(
account.data.borrow_mut().as_mut_ptr(),
0,
)),
},
);
}
rc_box,
)
};

let rc_box2 = RcBox {
strong: 1,
weak: 0,
// The difference with
// TEST_FORBID_LEN_UPDATE_AFTER_OWNERSHIP_CHANGE_MOVING_DATA_POINTER
// is that we don't move the data pointer past the
// RcBox. This is needed to avoid the "Invalid account
// info pointer" check when direct mapping is enabled.
// This also means we don't need to update the
// serialized len like we do in the other test.
value: unsafe { RefCell::new(slice::from_raw_parts_mut(
target_account.data.borrow_mut().as_mut_ptr(),
target_len,
)) },
};
let rc_box_size = mem::size_of::<RcBox<RefCell<&mut [u8]>>>();

let serialized_len_ptr =
unsafe { account.data.borrow_mut().as_mut_ptr().offset(-8) as *mut u64 };
let serialized_len_ptr2 =
unsafe { target_account.data.borrow_mut().as_mut_ptr().offset(-8) as *mut u64 };
// Place a RcBox<RefCell<&mut [u8]>> in the account data. This
// allows us to test having CallerAccount::ref_to_len_in_vm in an
// account region.
unsafe {
std::ptr::write(
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
&target_account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
Rc::from_raw(((rc_box_addr as usize) + mem::size_of::<usize>() * 2) as *mut _),
);
}
Comment on lines 869 to 922
Copy link
Owner Author

Choose a reason for hiding this comment

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

here 1/2

//msg!("ptr: {:p}", &rc_box);
/*
unsafe {
std::ptr::write(
&account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
Rc::from_raw(((&rc_box as *const _) as usize + mem::size_of::<usize>() * 2) as *mut _),
);
}
*/
/*
unsafe {
std::ptr::write(
&target_account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
Rc::from_raw(((&rc_box as *const _) as usize + mem::size_of::<usize>() * 2) as *mut _),
);
}
*/
/*
unsafe {
std::ptr::write(
&target_account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
Rc::from_raw(((&rc_box as *const _) as usize + mem::size_of::<usize>() * 2) as *mut _),
);
}
*/

let mut instruction_data = vec![REALLOC, 0];
instruction_data.extend_from_slice(&rc_box_size.to_le_bytes());
let mut instruction_data = vec![SELF_CPI, 0, 0, 0];
//let mut instruction_data = vec![REALLOC, 0];
//instruction_data.extend_from_slice(&rc_box_size.to_le_bytes());

// check that the account is empty before we CPI
assert_eq!(account.data_len(), 0);
//assert_eq!(account.data_len(), 0);

invoke(
&create_instruction(
*realloc_program_id,
*program_id,
//*realloc_program_id,
&[
(accounts[ARGUMENT_INDEX].key, true, false),
(target_account.key, true, false),
Expand All @@ -912,8 +968,16 @@ fn process_instruction(
accounts,
)
.unwrap();

unsafe { *serialized_len_ptr = rc_box_size as u64 };
msg!("CPI SUCCESS!");
msg!("data+spare: {:02x?}", unsafe { slice::from_raw_parts(account.data.borrow().as_ptr(), 100) });
msg!("data+spare: {:02x?}", unsafe { slice::from_raw_parts(target_account.data.borrow().as_ptr(), 100) });
//msg!("data+spare: {:02x?}", unsafe { slice::from_raw_parts(orig_target_account_data.borrow().as_ptr(), 100) });
msg!("len: {}", account.data.borrow().len());
//msg!("len: {}", target_account.data.borrow().len());
//msg!("len: {}", orig_target_account_data.borrow().len());

//unsafe { *serialized_len_ptr = 40 as u64 };
//unsafe { *serialized_len_ptr2 = rc_box_size as u64 /*+ 1*/};
// hack to avoid dropping the RcBox, which is supposed to be on the
// heap but we put it into account data. If we don't do this,
// dropping the Rc will cause
Expand All @@ -925,7 +989,24 @@ fn process_instruction(
Rc::new(RefCell::new(&mut [])),
);
}
}
unsafe {
std::ptr::write(
&target_account.data as *const _ as usize as *mut Rc<RefCell<&mut [u8]>>,
Rc::new(RefCell::new(&mut [])),
);
}
},
SELF_CPI => {
msg!("SELF CPI");
let account = &accounts[0];
//msg!("self-cpi-pre: {:02x?}", unsafe { slice::from_raw_parts(account.data.borrow().as_ptr(), 100) });
//account.data.borrow_mut()[32] = 0x99;
account.data.borrow_mut()[32] = 0x5;
Copy link
Owner Author

Choose a reason for hiding this comment

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

here 2/2

//msg!("self-cpi-post: {:02x?}", unsafe { slice::from_raw_parts(account.data.borrow().as_ptr(), 100) });
let target_account = &accounts[1];
target_account.data.borrow_mut()[0] = 0x88;
target_account.realloc(5, false).unwrap();
},
TEST_ALLOW_WRITE_AFTER_OWNERSHIP_CHANGE_TO_CALLER => {
msg!("TEST_ALLOW_WRITE_AFTER_OWNERSHIP_CHANGE_TO_CALLER");
const INVOKE_PROGRAM_INDEX: usize = 3;
Expand Down
Loading