~ubuntu-branches/ubuntu/gutsy/virtualbox-ose/gutsy

« back to all changes in this revision

Viewing changes to src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/os2/xptcstubs_os2.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-09-08 16:44:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070908164458-wao29470vqtr8ksy
Tags: upstream-1.5.0-dfsg2
ImportĀ upstreamĀ versionĀ 1.5.0-dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public License Version
 
7
 * 1.1 (the "License"); you may not use this file except in compliance with
 
8
 * the License. You may obtain a copy of the License at
 
9
 * http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the License is distributed on an "AS IS" basis,
 
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
 * for the specific language governing rights and limitations under the
 
14
 * License.
 
15
 *
 
16
 * The Original Code is mozilla.org Code.
 
17
 *
 
18
 * The Initial Developer of the Original Code is
 
19
 * Netscape Communications Corporation.
 
20
 * Portions created by the Initial Developer are Copyright (C) 1999
 
21
 * the Initial Developer. All Rights Reserved.
 
22
 *
 
23
 * Contributor(s):
 
24
 *   John Fairhurst <john_fairhurst@iname.com>
 
25
 *   Henry Sobotka <sobotka@axess.com> added VAC++ support
 
26
 *   and fixed emx asm to work with gcc 2.95.2 (Jan. 2000)
 
27
 *
 
28
 * Alternatively, the contents of this file may be used under the terms of
 
29
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 
30
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
31
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
32
 * of those above. If you wish to allow use of your version of this file only
 
33
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
34
 * use your version of this file under the terms of the MPL, indicate your
 
35
 * decision by deleting the provisions above and replace them with the notice
 
36
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
37
 * the provisions above, a recipient may use your version of this file under
 
38
 * the terms of any one of the MPL, the GPL or the LGPL.
 
39
 *
 
40
 * ***** END LICENSE BLOCK ***** */
 
41
 
 
42
/* Implement shared vtbl methods */
 
43
 
 
44
#include "xptcprivate.h"
 
45
 
 
46
#if !defined (__EMX__) && !defined(__IBMCPP__)
 
47
#error "This code is only for OS/2"
 
48
#endif
 
49
 
 
50
// Procedure in xptcall_vacpp.asm
 
51
#ifdef XP_OS2_VACPP
 
52
extern nsresult SetEntryFromIndex(int stubidx);
 
53
#endif
 
54
 
 
55
#ifdef XP_OS2_VACPP
 
56
nsresult
 
57
PrepareAndDispatch( nsXPTCStubBase *self, PRUint32 methodIndex,
 
58
                    PRUint32 *args)
 
59
#else
 
60
static nsresult
 
61
PrepareAndDispatch( nsXPTCStubBase *self, PRUint32 methodIndex,
 
62
                    PRUint32 *args)
 
63
#endif
 
64
{
 
65
#define PARAM_BUFFER_COUNT     16
 
66
 
 
67
    nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
 
68
    nsXPTCMiniVariant* dispatchParams = NULL;
 
69
    nsIInterfaceInfo* iface_info = NULL;
 
70
    const nsXPTMethodInfo* info;
 
71
    PRUint8 paramCount;
 
72
    PRUint8 i;
 
73
    nsresult result = NS_ERROR_FAILURE;
 
74
 
 
75
    // If anything fails before stackBytesToPop can be set then
 
76
    // the failure is completely catastrophic!
 
77
 
 
78
    NS_ASSERTION(self,"no self");
 
79
 
 
80
    self->GetInterfaceInfo(&iface_info);
 
81
    NS_ASSERTION(iface_info,"no interface info");
 
82
 
 
83
    iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
 
84
    NS_ASSERTION(info,"no interface info");
 
85
 
 
86
    paramCount = info->GetParamCount();
 
87
 
 
88
#ifdef XP_OS2_VACPP
 
89
    /* If paramCount is > 0, write out the EDX pointer to the
 
90
       space on the stack args[0]. args[-4] is the space on
 
91
       the stack where it was pushed */
 
92
    if (paramCount) {
 
93
        args[0] = args[-4];
 
94
 
 
95
        /* If this is the second parameter, or if the first parameter is an
 
96
           8 byte long long, write out the ECX pointer to the space on the
 
97
           stack args[1]. args[-3] is the space on the stack where it was
 
98
           pushed */
 
99
        nsXPTType type = info->GetParam(0).GetType();
 
100
        if( paramCount > 1 ||
 
101
            type == nsXPTType::T_I64 || type == nsXPTType::T_U64 )
 
102
        {
 
103
            args[1] = args[-3];
 
104
        }            
 
105
    }
 
106
#endif
 
107
 
 
108
    // setup variant array pointer
 
109
    if(paramCount > PARAM_BUFFER_COUNT)
 
110
        dispatchParams = new nsXPTCMiniVariant[paramCount];
 
111
    else
 
112
        dispatchParams = paramBuffer;
 
113
    NS_ASSERTION(dispatchParams,"no place for params");
 
114
 
 
115
    PRUint32* ap = args;
 
116
    for(i = 0; i < paramCount; i++, ap++)
 
117
    {
 
118
        const nsXPTParamInfo& param = info->GetParam(i);
 
119
        const nsXPTType& type = param.GetType();
 
120
        nsXPTCMiniVariant* dp = &dispatchParams[i];
 
121
 
 
122
        if(param.IsOut() || !type.IsArithmetic())
 
123
        {
 
124
            dp->val.p = (void*) *ap;
 
125
            continue;
 
126
        }
 
127
        // else
 
128
        switch(type)
 
129
        {
 
130
        case nsXPTType::T_I8     : dp->val.i8  = *((PRInt8*)  ap);       break;
 
131
        case nsXPTType::T_I16    : dp->val.i16 = *((PRInt16*) ap);       break;
 
132
        case nsXPTType::T_I32    : dp->val.i32 = *((PRInt32*) ap);       break;
 
133
        case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
 
134
        case nsXPTType::T_U8     : dp->val.u8  = *((PRUint8*) ap);       break;
 
135
        case nsXPTType::T_U16    : dp->val.u16 = *((PRUint16*)ap);       break;
 
136
        case nsXPTType::T_U32    : dp->val.u32 = *((PRUint32*)ap);       break;
 
137
        case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
 
138
        case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
 
139
        case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
 
140
        case nsXPTType::T_BOOL   : dp->val.b   = *((PRBool*)  ap);       break;
 
141
        case nsXPTType::T_CHAR   : dp->val.c   = *((char*)    ap);       break;
 
142
        case nsXPTType::T_WCHAR  : dp->val.wc  = *((wchar_t*) ap);       break;
 
143
        default:
 
144
            NS_ASSERTION(0, "bad type");
 
145
            break;
 
146
        }
 
147
    }
 
148
 
 
149
    result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
 
150
 
 
151
    NS_RELEASE(iface_info);
 
152
 
 
153
    if(dispatchParams != paramBuffer)
 
154
        delete [] dispatchParams;
 
155
 
 
156
    return result;
 
157
}
 
158
 
 
159
#ifdef XP_OS2_VACPP
 
160
 
 
161
#define STUB_ENTRY(n)
 
162
 
 
163
#else
 
164
 
 
165
#define STUB_ENTRY(n) \
 
166
nsresult nsXPTCStubBase::Stub##n() \
 
167
{ \
 
168
  register nsresult (*method) (nsXPTCStubBase *, PRUint32, PRUint32 *) = PrepareAndDispatch; \
 
169
  int temp0, temp1; \
 
170
  register nsresult result; \
 
171
  __asm__ __volatile__( \
 
172
    "leal   0x0c(%%ebp), %%ecx\n\t"    /* args */ \
 
173
    "pushl  %%ecx\n\t" \
 
174
    "pushl  $"#n"\n\t"                 /* method index */ \
 
175
    "movl   0x08(%%ebp), %%ecx\n\t"    /* this */ \
 
176
    "pushl  %%ecx\n\t" \
 
177
    "call   *%%edx\n\t"                /* PrepareAndDispatch */ \
 
178
    "addl   $12, %%esp" \
 
179
    : "=a" (result),    /* %0 */ \
 
180
      "=&c" (temp0),    /* %1 */ \
 
181
      "=d" (temp1)      /* %2 */ \
 
182
    : "2" (method)      /* %2 */ \
 
183
    : "memory" ); \
 
184
    return result; \
 
185
}
 
186
#endif
 
187
 
 
188
#define SENTINEL_ENTRY(n) \
 
189
nsresult nsXPTCStubBase::Sentinel##n() \
 
190
{ \
 
191
    NS_ASSERTION(0,"nsXPCWrappedJS::Sentinel called"); \
 
192
    return NS_ERROR_NOT_IMPLEMENTED; \
 
193
}
 
194
 
 
195
#include "xptcstubsdef.inc"