I looked at the PTP buffer functions some on
D10.
As srsa_4c mentioned earlier, the first ComMemMan function (d10 sub_FF8C9114) allocates a 1 MB uncached exmem buffer.
This appears to be done in PTP startup, it's already allocated once a chdkptp connection is established.
On
d10 (without CHDK exmem enabled) the buffer address is
0x43E42E00 0x43E02E00
Comments in makefile.inc indicate the video buffer starts at 0x43F02E00, exactly 1MB after the start of the PTP buffer. This raises the question of whether some exmem types automatically stay clear of the video buffer.
The second ComMemMan (d10 sub_FF8C91A4) function frees the exmem buffer.
The third (d10 sub_FF8C922😎 is called by individual PTP functions that need a buffer. My impression is the big exmem buffer is split up into 7 "slots" used for different things. The main buffer for SendObject is slot 4 (edit: or 5, for dryos 43 through 52).
sub_FF8C9374 appears to return a size for each slot
con 1> =return call_func_ptr(0xFF8C9374,0)
2:return:8192
con 2> =return call_func_ptr(0xFF8C9374,1)
3:return:2048
con 3> =return call_func_ptr(0xFF8C9374,2)
4:return:16384
con 4> =return call_func_ptr(0xFF8C9374,3)
5:return:235520
con 5> =return call_func_ptr(0xFF8C9374,4)
6:return:524288
con 6> =return call_func_ptr(0xFF8C9374,5)
7:return:0
con 7> =return call_func_ptr(0xFF8C9374,6)
sub_FF9F6B28 is used by the SendObject code. It allocates slot 4 if needed (using the size from sub_FF8C9374 above), and returns the address. In my testing it was always
the start of the exmem buffer 0x43e42e00.
This suggests that it would be fairly easy to use the stock Canon buffer, at least where it doesn't conflict with video stuff. Only one PTP operation can be in progress at a given time, so I think there's little risk of conflicting with Canon firmware code for slot 4. (other slots are used by other parts of the PTP code, e.g. something in BulkTrns.c uses slot 1)
Test patch for
D10 attached. Unsurprisingly, the various msgtest tests work fine with this, since the buffer is uncached and far larger than usable message sizes.
It's probably not practical switch all ports to this approach. My current thought platform specific functions that fall back to malloc in the default case, but for cameras without a dedicated buffer, it's desirable to transfer directly to the destination address for script messages.
edit:
The same approach works for
A540 using
NHSTUB(get_ptp_buf_size, 0xFFE38264)
NHSTUB(get_ptp_file_buf, 0xFFE5749😎