Execution Contexts

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, LCMark

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Execution Contexts

Post by mickpitkin92 » Thu May 02, 2013 7:51 pm

Hey guys, I just remembered something I read in the Documentation and thought it would be relevant, the ExecutionContexts is a feature I particularly use in debugging, its a nice thing to have for an error reporting dialog and I remember reading in the Documentation that it may not be present in future versions of LiveCode and I wanted to ask if there is any plans to remove it as I personally find it hella useful.

Plus I've actually managed to make use of a little security function that traverses the ExecutionContexts to build a little security system for my APIs. So an API function calls SppCanAccessAPIFunction() and the aformentioned function then does a little bit of checking to determine what kind of security context to enforce on the public API. Makes for a neat little security system on my APIs.

Kind regards.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: Execution Contexts

Post by LCMark » Thu May 02, 2013 8:35 pm

I take it that it is only the immediate caller that you check in your APIs?

If so, how about a context-local property 'the caller' - returning a long id to the object making the call...

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Execution Contexts

Post by mwieder » Thu May 02, 2013 8:37 pm

Not to worry. Just about everything I've got would break if we removed it. And you're aware that the format is different if there are behavior objects involved, right? There's an extra parameter at the end of the line that specifies the object.

Your security function sounds awesome. Care to share the code?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Execution Contexts

Post by Dixie » Thu May 02, 2013 8:37 pm

Ask support... support@runrev.com

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Execution Contexts

Post by mickpitkin92 » Thu May 02, 2013 8:45 pm

Basically the private function SecpCanUserAccessAPIFunction (It turns out I was using Secp rather than Spp, ma bad) does a check, it places Item -2 of line -2 of the execution contexts into a variable named tFunctionName and then does a check against a list of functions that require a security check before continuing and performs the security check so effectively say I have a security sensitive API function called KiShutdownSystem() which performs a shutdown of the application.

It should only be called by callers who have a user account of SYSTEM and thus KiShutdownSystem() first calls SecpCanUserAccessAPIFunction() which performs a check so ultimately something like this:

Code: Select all

Function KiShutdownSystem
   If SecpCanUserAccessAPIFunction() = False Then
      Return -1 // Access denied.
   .. continue on with other checks
End KiShutdownSystem
Private Function SecpCanUserAccessAPIFunction
   Put Item -2 Of Line -2 Of The ExecutionContexts Into tFunctionName
   .. continue with security check.
End SecpCanUserAccessAPIFunction
Basically the functions rely on the ExecutionContexts and I just want to know if the team plans to follow on with the decision to nerf it completely in the future as I think it is a pretty nifty little property. Plus again, it's useful in an ErrorDialog message when you are sending an error report to the developer.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: Execution Contexts

Post by LCMark » Thu May 02, 2013 8:45 pm

@Dixie: Well, you could ask support, but Heather would only end up asking me anyway ;)

In any case, I can't see 'the executionContexts' going anywhere - but it would be better if more specific features were introduced to allow people to do what they currently use it for. That property has always been 'subject to change' (although not wildly) in order to support the interactive debugger. However, it's not changed much at all in the last 10 years, so I can't see it changing much in future.

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Execution Contexts

Post by mickpitkin92 » Thu May 02, 2013 8:49 pm

The forum wouldn't let me just explain my happiness with a simple Yes, so I feel the need to document it in a way that would allow me to explain it in a lengthier message.

This was sufficient. XD
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Execution Contexts

Post by mwieder » Thu May 02, 2013 8:50 pm

One of my longer-term goals is to be able to grab the stack frame *before* a line gets executed, rather than after.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Execution Contexts

Post by mwieder » Thu May 02, 2013 8:51 pm

The forum wouldn't let me just explain my happiness with a simple Yes
LOL
You cannot make another post so soon after your last.
<sigh>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Execution Contexts

Post by mwieder » Thu May 02, 2013 9:00 pm

That "item -2" is going to get you into trouble with behavior objects, where you'll find what you're looking for in item -3. Here's how I resolve "the target" given the fact that a line in the executionContexts may have 3 or 4 parameters, with there being a fourth parameter only if the code is in a behavior object. You may want to do something similar.

Code: Select all

/**
 * ----------------------------------------
 * debuggerResolveTarget
 *
 * handle parentScripts properly
 *
 * @param pTarget : the default target
 * @param pContextLine : last item is actual target *unless* it's a number (parentScripts)
 * ----------------------------------------
 */
private function debuggerResolveTarget pTarget, pContextLine
    set the itemdelimiter to comma
    if the number of items of pContextLine > 3 then
        if item -1 of pContextLine is not a number then
            put item -1 of pContextLine into pTarget
        end if
    end if
    return pTarget
end debuggerResolveTarget

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Execution Contexts

Post by mickpitkin92 » Thu May 02, 2013 9:06 pm

Are you sure? The security check function is implemented in the same stack as the public API, for example the KiShutdownSystem() function is defined in the stack script of stack Ntoskrnl and so is the SecpCanUserAccessAPIFunction() private function, thus when the EC returns it returns the value:

Stack "Ntoskrnl",KiShutdownSystem,761
Stack "Ntoskrnl",SecpCanUserAccessAPIFunction,1421

There are no behavior objects in the middle, its a straight jump from one function to another.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: Execution Contexts

Post by LCMark » Thu May 02, 2013 9:10 pm

mwieder wrote:One of my longer-term goals is to be able to grab the stack frame *before* a line gets executed, rather than after.
Don't you have this information already? You get a 'trace' message before a line of script is executed, so that would be the context before the next line, and after the previous. (I might be misunderstanding what you mean, of course...)

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Execution Contexts

Post by mwieder » Thu May 02, 2013 9:19 pm

@Mike- no, you're fine as long as you're not dealing with code in a behavior object. In that case you'll see another parameter after the line number, and so the function name you're looking for will end up in item -3 instead of -2. If you're not looking at a function in a behavior object then there's no problem.

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Execution Contexts

Post by mickpitkin92 » Thu May 02, 2013 9:25 pm

Hmm, so would using "Put Item 2 Of Line -2 Of The ExecutionContexts" not work better as it doesn't appear like a new parameter being introduced would affect it then, I may expand on the functionality in the future to allow the security system to perform a check on behalf of API functions in other components but for the time being this is good for my public API.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Execution Contexts

Post by mwieder » Thu May 02, 2013 9:32 pm

Where you may run into trouble there is that there's (currently at least) no restriction on object names containing commas. If you run up against a stack named "one,two,three" then trying to pull item 2 of that will cause unpredictable results. And I hate those.

Post Reply

Return to “Engine Contributors”