Attempting To Read or Write Protected Memory?

Topics: User Forum
Sep 15, 2006 at 1:23 AM
I am currently developing a chat server for Ares P2P in vb.net and I have been struggling with embedding SpiderMonkey into it for some time now. I am taking a rather different approach to actually initializing the runtime and loading the scripts. but I am still following the same basic procedure to do so.. the runtime seems to initialize with a problem, it is during the loading of the script that I begin running into this problem. I am trying to assign a "globalClass" JSClass that has members such as alert, print, topic, hostname, sendPM and many objects like String, Array, Math, and more that the server actually displays to the chatroom, or to a given user. I have implemented a method named "JSFinalize" which has a different routine then actually destroying the runtime.. and is as follows...
Public Shared Sub JS_Finalize(ByVal cx As IntPtr, ByVal obj As IntPtr, ByVal name As String)
Dim attrsp As IntPtr = IntPtr.Zero
Dim foundp As IntPtr = IntPtr.Zero
JS.JS_GetPropertyAttributes(cx, obj, name, attrsp, foundp)
Dim attr As Int32 = (JS.JSPROPPERMANENT & JS.JSPROPREADONLY)
JS.JS_SetPropertyAttributes(cx, obj, name, Convert.ToUInt32(attr), foundp)
End Sub
now I am however fairly new to spidermonkey but I seem to get the basic Idea down. If you could privide me with information as to why that is throwing this exception or would like to see my "JS_InitScript" method to see exactly how I am implementing this routine I would be glad to post again.
Thanks in advance.
Ryan
Sep 15, 2006 at 1:24 AM
small error there..
"the runtime seems to initialize with a problem," should say "without a problem".. oopsie
Coordinator
Sep 15, 2006 at 8:49 PM
This discussion has been copied to Work Item 3291. You may wish to continue further discussion there.
Coordinator
Sep 15, 2006 at 9:04 PM
Hi Ryan.

Often enough SpiderMonkey does allow you to pass into null pointers. This time that is not the case-- the two paramters you skipped on are for output. What I've done below is allocated unmanaged memory for the engine to write into. That squashes your exceptions. Excuse the C# but my stubs are all written in it:

public static void JS_Finalize(IntPtr cx, IntPtr obj, string name)
{
IntPtr attrsp = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UInt32)));
IntPtr foundp = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bool)));
JS.JS_GetPropertyAttributes(cx, obj, Marshal.StringToHGlobalAnsi(name), attrsp, foundp);
Int32 attr = (JS.JSPROPPERMANENT & JS.JSPROPREADONLY);
JS.JS_SetPropertyAttributes(cx, obj, name, Convert.ToUInt32(attr), foundp);
}