LCDMsg and eventproc issues - CHDK Releases - CHDK Forum

LCDMsg and eventproc issues

  • 6 Replies
  • 6300 Views
*

Offline srsa_4c

  • ******
  • 4451
LCDMsg and eventproc issues
« on: 09 / May / 2014, 15:54:15 »
Advertisements
I'm experimenting with the LCDMsg event procedures over ptp (a3200, a3400, g10).
con> =return call_event_proc("UI.CreatePublic")
1:return:917724
con 1> =return call_event_proc("LCDMsg_Create",300,300,"foo")
2:return:0

So far, everything is OK (note that the text may not show up, try entering the Canon menu to force a buffer flip).
Now I'd like to change an existing text on screen with LCDMsg_SetStr.
Depending on camera, either
con 4> =call_event_proc("LCDMsg_SetStr",0,"bar")
or
con 6> =return call_event_proc("LCDMsg_SetStr",0,"bar")
makes it crash (exception 0xC, PC gets set to some junk value, task_PhySw). Is this supposed to work or am I missing something?
The CBasic dumper script has usage examples for the LCDMsg event procedures.


edit:
As usual, I was wrong. The CBasic example clearly shows that an allocated string is required as parameter for LCDMsg_SetStr. So, there's no bug.
« Last Edit: 18 / May / 2014, 18:18:56 by srsa_4c »

*

Offline srsa_4c

  • ******
  • 4451
Re: LCDMsg and eventproc issues
« Reply #1 on: 18 / May / 2014, 18:18:13 »
I'm reporting this again because it really feels like a bug.
I'm using the LCDMsg event procedures for this, but the problem might be generic.
In CHDKPTP:
Code: [Select]
___> c
connected: Canon PowerShot A3200 IS, max packet size 512
con> =return call_event_proc("UI.CreatePublic")
1:return:1041352
con 1> =return call_event_proc("LCDMsg_Create",0,0,"foo",2)
2:return:0
con 2> =return call_event_proc("LCDMsg_SetStr",0,"bar",0)
3:return:0
con 3> =return call_event_proc("LCDMsg_SetStr",0,"baz")
unexpected return code 0x2ff
ERROR: ptp error
Note that LCDMsg_SetStr expects two arguments. If I only give 2 arguments, the call will crash the camera with a 0xc exception. If I add another dummy arg, it will succeed. I suspect that the assembly helper in lib/armutil/callfunc.S has an issue with certain (number of) parameters(?)
CHDK is the most recent 1.3 from the autobuild, but I reproduced this on older revisions and other cameras.

*

Offline nafraf

  • *****
  • 1308
Re: LCDMsg and eventproc issues
« Reply #2 on: 18 / May / 2014, 19:20:37 »
Note that LCDMsg_SetStr expects two arguments. If I only give 2 arguments, the call will crash the camera with a 0xc exception. If I add another dummy arg, it will succeed. I suspect that the assembly helper in lib/armutil/callfunc.S has an issue with certain (number of) parameters(?)
with certain type of parameters? With two integer arguments it works:
Code: [Select]
connected: Canon PowerShot A495, max packet size 512
con> =return call_event_proc("UI.CreatePublic")
2:return:911664
con 2> =return call_event_proc("LCDMsg_Create",100,100,"foo",0x59)
3:return:0
con 3> =return call_event_proc("LCDMsg_SwDisp",0,0)
4:return:0
con 4> =return call_event_proc("LCDMsg_SwDisp",0,1)
5:return:0
con 5> =return call_event_proc("LCDMsg_SetStr",0,"xyz")
unexpected return code 0x2ff
ERROR: ptp error
"foo" turned into "FAILED" on screen before camera crash.
« Last Edit: 18 / May / 2014, 19:25:21 by nafraf »

*

Offline srsa_4c

  • ******
  • 4451
Re: LCDMsg and eventproc issues
« Reply #3 on: 19 / May / 2014, 11:29:56 »
"foo" turned into "FAILED" on screen before camera crash.
That means the string parameter's check failed, so that parameter got trashed (in addition to the stack or LR which is causing the crash later). My romlogs show LR pointing inside the "givesemaphore_low" kernel function at the time of exception (PC is clearly wrong). Not sure how to proceed, perhaps one could create a special function, export it as an eventproc, and dump debug data from there...

*

Offline reyalp

  • ******
  • 14125
Re: LCDMsg and eventproc issues
« Reply #4 on: 19 / May / 2014, 23:06:03 »
I split this into a new thread since it looks like it might involve substantial discussion.

FWIW, when I created callfunc.S I created some test code (callfunc_test.c) to check it with a range of different arguments.

You can also call an eventproc like Printf (or sprintf) with as many you want. From call_event_procs point of view, a vararg function is no different from any other.

Looking at the disassembly of LCDMsg_SetStr for D10 it looks like the actual ASM code only takes one argument. The event proc system may be re-arranging them somehow.
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 14125
Re: LCDMsg and eventproc issues
« Reply #5 on: 19 / May / 2014, 23:41:43 »
Example:
Code: [Select]
=return call_event_proc('System.Create')
1:return:0
=return call_event_proc('AllocateMemory',100)
2:return:2412080
=return call_event_proc('sprintf',2412080,'hello world')
3:return:11
=local t={} local p=2412080 while true do c=peek(p,1) if c==0 then break end table.insert(t,string.char(c)) p=p+1 end return table.concat(t)
6:return:'hello world'
=return call_event_proc('sprintf',2412080,'hello %s','another world')
9:return:19
=local t={} local p=2412080 while true do c=peek(p,1) if c==0 then break end table.insert(t,string.char(c)) p=p+1 end return table.concat(t)
10:return:'hello another world'
=return call_event_proc('sprintf',2412080,'hello %s %d','world',2)
11:return:13
=local t={} local p=2412080 while true do c=peek(p,1) if c==0 then break end table.insert(t,string.char(c)) p=p+1 end return table.concat(t)
12:return:'hello world 2'
=return call_event_proc('sprintf',2412080,'hello %s %d %d %d %d','world',1,2,3,4)
13:return:19
con 13> =local t={} local p=2412080 while true do c=peek(p,1) if c==0 then break end table.insert(t,string.char(c)) p=p+1 end return table.concat(t)
14:return:'hello world 1 2 3 4'
So I think call_event_proc works with 1 to 6 arguments, although it's possible there is some problem that only shows up in certain circumstances
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 4451
Re: LCDMsg and eventproc issues
« Reply #6 on: 20 / May / 2014, 16:59:20 »
Don't have time to check it right now, but it might be worth taking a look at how LCDMsg_SetStr is registered (is it 'registered' or 'exported'). It does expect 2 arguments - all LCDMsg event procedures (except LCDMsg_Create) need the msg ID as their first argument.


late edit:
As it turned out, LCDMsg_SetStr expects a NULL as last argument. If the closing NULL is not there, it will try to append additional strings and corrupt the stack.
Some versions of this eventproc have this bug, some do not.
« Last Edit: 01 / October / 2018, 12:59:31 by srsa_4c »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal