diff --git a/js/src/xpconnect/Makefile.in b/js/src/xpconnect/Makefile.in index 32b5e6a3cde3..34796d3e8865 100644 --- a/js/src/xpconnect/Makefile.in +++ b/js/src/xpconnect/Makefile.in @@ -26,23 +26,40 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk +DIRS = md + +LIBRARY_NAME=xpconnect +MODULE=xpconnect + +CFLAGS += -DJSFILE -DEXPORT_XPC_API -DJS_THREADSAFE + CPPSRCS= \ xpt_cpp.cpp \ nsXPConnect.cpp \ xpcarbitrary.cpp \ xpccontext.cpp \ xpcconvert.cpp \ - xpcinvoke.cpp \ xpclog.cpp \ xpcmaps.cpp \ xpcnsid.cpp \ - xpcstubs.cpp \ xpcwrappedjs.cpp \ xpcwrappedjsclass.cpp \ xpcwrappednative.cpp \ xpcwrappednativeclass.cpp \ $(NULL) -LIBRARY_NAME=xpconnect +EXPORTS = \ + nsIXPCScriptable.h \ + nsIInterfaceInfo.h \ + nsIInterfaceInfoManager.h \ + nsIXPConnect.h \ + xpclog.h \ + $(NULL) + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) include $(topsrcdir)/config/rules.mk + +INCLUDES += -I$(srcdir) + +# MD_LIBRARY = md/unix/libxpcmd.a diff --git a/js/src/xpconnect/md/Makefile.in b/js/src/xpconnect/md/Makefile.in new file mode 100644 index 000000000000..ca442cda21a7 --- /dev/null +++ b/js/src/xpconnect/md/Makefile.in @@ -0,0 +1,31 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +DEPTH=../../../.. + +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/config.mk + +DIRS = unix + +include $(topsrcdir)/config/rules.mk diff --git a/js/src/xpconnect/md/unix/Makefile.in b/js/src/xpconnect/md/unix/Makefile.in new file mode 100644 index 000000000000..f4ae4d46ba76 --- /dev/null +++ b/js/src/xpconnect/md/unix/Makefile.in @@ -0,0 +1,44 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +DEPTH=../../../../.. + +topsrcdir = @top_srcdir@ +VPATH = @srcdir@ +srcdir = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/config.mk + +CFLAGS += -DJSFILE -DEXPORT_XPC_API -DJS_THREADSAFE + +LIBRARY_NAME = xpcmd + +MODULE = xpconnect + +ifeq ($(OS_ARCH), Linux) +CPPSRCS= \ + xpcinvoke_linux_x86.cpp \ + xpcstubs_linux_x86.cpp \ + $(NULL) +endif + +include $(topsrcdir)/config/rules.mk + +INCLUDES += -I$(srcdir)/../.. diff --git a/js/src/xpconnect/md/unix/xpcinvoke_linux_x86.cpp b/js/src/xpconnect/md/unix/xpcinvoke_linux_x86.cpp index 9e6a935f529d..4efec7791870 100644 --- a/js/src/xpconnect/md/unix/xpcinvoke_linux_x86.cpp +++ b/js/src/xpconnect/md/unix/xpcinvoke_linux_x86.cpp @@ -23,7 +23,7 @@ // Remember that these 'words' are 32bit DWORDS #if !defined(LINUX) -#error "This code is for Linux x86 only +#error "This code is for Linux x86 only" #endif static uint32 diff --git a/js/src/xpconnect/md/unix/xpcstubs_linux_x86.cpp b/js/src/xpconnect/md/unix/xpcstubs_linux_x86.cpp new file mode 100644 index 000000000000..9f6bc9bc3e9d --- /dev/null +++ b/js/src/xpconnect/md/unix/xpcstubs_linux_x86.cpp @@ -0,0 +1,212 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* Implement shared vtbl methods for WrappedJS. */ + +#include "xpcprivate.h" + +#if !defined(LINUX) +#error "This code is for Linux x86 only" +#endif + +// XXX quick to get it compiling - but not working +#if 0 +static nsresult __stdcall +PrepareAndDispatch(nsXPCWrappedJS* self, uint32 methodIndex, + uint32* args, uint32* stackBytesToPop) +{ +#define PARAM_BUFFER_COUNT 32 + + nsXPCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; + nsXPCMiniVariant* dispatchParams = NULL; + nsXPCWrappedJSClass* clazz; + nsIInterfaceInfo* iface_info; + const nsXPTMethodInfo* info; + uint8 paramCount; + uint8 i; + nsresult result = NS_ERROR_FAILURE; + + // If anything fails before stackBytesToPop can be set then + // the failure is completely catastrophic! + + NS_ASSERTION(self,"no self"); + + clazz = self->GetClass(); + NS_ASSERTION(clazz,"no class"); + + iface_info = clazz->GetInterfaceInfo(); + NS_ASSERTION(iface_info,"no interface info"); + + iface_info->GetMethodInfo(uint16(methodIndex), &info); + NS_ASSERTION(info,"no interface info"); + + paramCount = info->GetParamCount(); + + // setup variant array pointer + if(paramCount > PARAM_BUFFER_COUNT) + dispatchParams = new nsXPCMiniVariant[paramCount]; + else + dispatchParams = paramBuffer; + NS_ASSERTION(dispatchParams,"no place for params"); + + uint32* ap = args; + for(i = 0; i < paramCount; i++, ap++) + { + const nsXPTParamInfo& param = info->GetParam(i); + const nsXPTType& type = param.GetType(); + nsXPCMiniVariant* dp = &dispatchParams[i]; + + if(param.IsOut() || !type.IsArithmetic()) + { + dp->val.p = (void*) *ap; + continue; + } + // else + switch(type) + { + case nsXPTType::T_I8 : dp->val.i8 = *((int8*) ap); break; + case nsXPTType::T_I16 : dp->val.i16 = *((int16*) ap); break; + case nsXPTType::T_I32 : dp->val.i32 = *((int32*) ap); break; + case nsXPTType::T_I64 : dp->val.i64 = *((int64*) ap); ap++; break; + case nsXPTType::T_U8 : dp->val.u8 = *((uint8*) ap); break; + case nsXPTType::T_U16 : dp->val.u16 = *((uint16*) ap); break; + case nsXPTType::T_U32 : dp->val.u32 = *((uint32*) ap); break; + case nsXPTType::T_U64 : dp->val.u64 = *((uint64*) ap); ap++; break; + case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break; + case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break; + case nsXPTType::T_BOOL : dp->val.b = *((PRBool*) ap); break; + case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break; + case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*)ap); break; + default: + NS_ASSERTION(0, "bad type"); + break; + } + } + *stackBytesToPop = ((uint32)ap) - ((uint32)args); + + result = clazz->CallMethod(self, (uint16)methodIndex, info, dispatchParams); + + if(dispatchParams != paramBuffer) + delete [] dispatchParams; + + return result; +} + +static __declspec(naked) void SharedStub(void) +{ + __asm { + push ebp // set up simple stack frame + mov ebp, esp // stack has: ebp/vtbl_index/retaddr/this/args + push ecx // make room for a ptr + lea eax, [ebp-4] // pointer to stackBytesToPop + push eax + lea ebx, [ebp+16] // pointer to args + push ebx + mov edx, [ebp+4] // vtbl_index + push edx + mov eax, [ebp+12] // this + push eax + call PrepareAndDispatch + mov edx, [ebp+8] // return address + mov ecx, [ebp-4] // stackBytesToPop + add ecx, 12 // for this, the index, and ret address + mov esp, ebp + pop ebp + add esp, ecx // fix up stack pointer + jmp edx // simulate __stdcall return + } +} + +// these macros get expanded (many times) in the file #included below +#define STUB_ENTRY(n) \ +__declspec(naked) nsresult __stdcall nsXPCWrappedJS::Stub##n() \ +{ __asm push n __asm jmp SharedStub } + +#define SENTINEL_ENTRY(n) \ +nsresult __stdcall nsXPCWrappedJS::Sentinel##n() \ +{ \ + NS_ASSERTION(0,"nsXPCWrappedJS::Sentinel called"); \ + return NS_ERROR_NOT_IMPLEMENTED; \ +} + +#pragma warning(disable : 4035) // OK to have no return value +#include "xpcstubsdef.inc" +#pragma warning(default : 4035) // restore default + +// XXX quick to get it compiling - but not working +nsresult nsXPCWrappedJS::Stub##n() \ +{ \ + return NS_ERROR_NOT_IMPLEMENTED; \ +} + +#endif + +static nsresult +PrepareAndDispatch(nsXPCWrappedJS* self, uint32 methodIndex, uint32* args) +{ + printf("PrepareAndDispatch called with methodIndex = %d\n", (int)methodIndex); + return NS_ERROR_FAILURE; +} + +static nsresult SharedStub(void) +{ + void* method = PrepareAndDispatch; + nsresult result; + __asm__ __volatile__( + "leal 0x14(%%ebp), %%edx\n\t" /* args */ + "pushl %%edx\n\t" + "movl 0x08(%%ebp), %%ecx\n\t" /* vtbl index */ + "pushl %%ecx\n\t" + "movl 0x10(%%ebp), %%edx\n\t" /* this */ + "pushl %%edx\n\t" + "movl %1, %%eax\n\t" /* PrepareAndDispatch */ + "call *%%eax\n\t" + "addl $0x0c, %%esp\n\t" + "movl %%eax, %0" + : "=g" (result) /* %0 */ + : "g" (method) /* %1 */ + : "ax", "dx", "cx", "memory" ); + return result; +} + +// these macros get expanded (many times) in the file #included below +#define STUB_ENTRY(n) \ +nsresult nsXPCWrappedJS::Stub##n() \ +{ \ + void* stub = SharedStub; \ + __asm__ __volatile__( \ + "popl %%ebp\n\t" \ + "pushl $"#n"\n\t" \ + "call *%%edx\n\t" \ + "addl $8, %%esp\n\t" \ + "leave\n\t" \ + "ret\n\t" \ + : \ + : "d" (stub) \ + : "ax", "memory" ); \ + return 0; /* just to avoid warning */ \ +} + +#define SENTINEL_ENTRY(n) \ +nsresult nsXPCWrappedJS::Sentinel##n() \ +{ \ + NS_ASSERTION(0,"nsXPCWrappedJS::Sentinel called"); \ + return NS_ERROR_NOT_IMPLEMENTED; \ +} + +#include "xpcstubsdef.inc" diff --git a/js/src/xpconnect/md/win32/xpcinvoke.cpp b/js/src/xpconnect/md/win32/xpcinvoke.cpp index 992825f5fbe6..1b7ce1af8f8b 100644 --- a/js/src/xpconnect/md/win32/xpcinvoke.cpp +++ b/js/src/xpconnect/md/win32/xpcinvoke.cpp @@ -21,7 +21,7 @@ #include "xpcprivate.h" #ifndef WIN32 -#error "This code is for Win32 only +#error "This code is for Win32 only" #endif // Remember that on Win32 these 'words' are 32bit DWORDS diff --git a/js/src/xpconnect/md/win32/xpcstubs.cpp b/js/src/xpconnect/md/win32/xpcstubs.cpp index df875fa8756e..657d102f400d 100644 --- a/js/src/xpconnect/md/win32/xpcstubs.cpp +++ b/js/src/xpconnect/md/win32/xpcstubs.cpp @@ -21,7 +21,7 @@ #include "xpcprivate.h" #ifndef WIN32 -#error "This code is for Win32 only +#error "This code is for Win32 only" #endif static nsresult __stdcall diff --git a/js/src/xpconnect/test/Makefile.in b/js/src/xpconnect/test/Makefile.in new file mode 100644 index 000000000000..2cfebd643684 --- /dev/null +++ b/js/src/xpconnect/test/Makefile.in @@ -0,0 +1,69 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +VPATH = @srcdir@ +srcdir = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = TestXPC + +CPPSRCS = \ + TestXPC.cpp \ + $(NULL) + +include $(topsrcdir)/config/config.mk + +CFLAGS += -DJS_THREADSAFE -DJSFILE + + +LDFLAGS = \ + -L$(DIST)/bin \ + -ljs \ + -lxpcom \ + -lxpconnect \ + -lxpcmd \ + -lreg \ + -lmozutil \ + $(NSPR_LIBS) \ + $(NULL) + + +PROGS = $(OBJDIR)/TestXPC + +TEST_FILES = testxpc.js + +TARGETS= $(PROGS) + +include $(topsrcdir)/config/rules.mk + +INCLUDES += -I$(PUBLIC)/xpcom -I$(PUBLIC)/js -I$(PUBLIC)/xpconnect \ + -I$(PUBLIC)/raptor -I../../../../xpcom/src + +#$(PROGS): $(OBJS) +# @$(MAKE_OBJDIR) +# $(CC) -o $@ $(OBJS) $(LD_FLAGS) -L$(DIST)/lib $(LIBS) $(OS_LIBS) + +export:: $(TARGETS) + $(INSTALL) $(PROGS) $(DIST)/bin + $(INSTALL) $(TEST_FILES) $(DIST)/bin + +clobber:: + rm -f $(DIST)/bin/TestXPC + rm -f $(PROGS) $(OBJS) diff --git a/js/src/xpconnect/test/TestXPC.cpp b/js/src/xpconnect/test/TestXPC.cpp index 22eca7f0e50a..c837855cdddb 100644 --- a/js/src/xpconnect/test/TestXPC.cpp +++ b/js/src/xpconnect/test/TestXPC.cpp @@ -152,7 +152,8 @@ MyScriptable::MyScriptable() NS_ADDREF_THIS(); } -NS_IMPL_ISUPPORTS(MyScriptable,NS_IXPCSCRIPTABLE_IID); +static NS_DEFINE_IID(kMyScriptableIID, NS_IXPCSCRIPTABLE_IID); +NS_IMPL_ISUPPORTS(MyScriptable, kMyScriptableIID); // XPC_IMPLEMENT_FORWARD_IXPCSCRIPTABLE(MyScriptable); XPC_IMPLEMENT_FORWARD_CREATE(MyScriptable); @@ -297,7 +298,8 @@ private: nsIAllocator* mAllocator; }; -NS_IMPL_ISUPPORTS(MyEcho, NS_IECHO_IID); +static NS_DEFINE_IID(kMyEchoIID, NS_IECHO_IID); +NS_IMPL_ISUPPORTS(MyEcho, kMyEchoIID); MyEcho::MyEcho() : mReciever(NULL) diff --git a/js/src/xpconnect/xpt_cpp.cpp b/js/src/xpconnect/xpt_cpp.cpp index e21cff22a3d2..61d08d1eb241 100644 --- a/js/src/xpconnect/xpt_cpp.cpp +++ b/js/src/xpconnect/xpt_cpp.cpp @@ -569,7 +569,8 @@ InterfaceInfoImpl::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info) } // else... - *info = NS_STATIC_CAST(nsXPTMethodInfo*, &mEntry->interface_descriptor->method_descriptors[index-mMethodBaseIndex]); + *info = NS_REINTERPRET_CAST(nsXPTMethodInfo*, + &mEntry->interface_descriptor->method_descriptors[index-mMethodBaseIndex]); return NS_OK; } @@ -589,6 +590,7 @@ InterfaceInfoImpl::GetConstant(uint16 index, const nsXPTConstant** constant) } // else... - *constant = NS_STATIC_CAST(nsXPTConstant*,&mEntry->interface_descriptor->const_descriptors[index-mConstantBaseIndex]); + *constant = NS_REINTERPRET_CAST(nsXPTConstant*, + &mEntry->interface_descriptor->const_descriptors[index-mConstantBaseIndex]); return NS_OK; }