~ubuntu-branches/ubuntu/feisty/firefox/feisty-security

« back to all changes in this revision

Viewing changes to xpcom/reflect/xptcall/src/md/unix/xptcinvoke_openbsd_amd64.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2007-10-19 01:09:21 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20071019010921-8sglgxbi6kj1pemg
Tags: 2.0.0.8+1nobinonly-0ubuntu1
* New security/stability upstream release (v2.0.0.8)
* MFSA 2007-29 aka CVE-2007-5339 (browser), CVE-2007-5340 (javascript)
* MFSA 2007-30 aka CVE-2007-1095
* MFSA 2007-31 aka CVE-2007-2292
* MFSA 2007-32 aka CVE-2007-3511, CVE-2006-2894
* MFSA 2007-33 aka CVE-2007-5334
* MFSA 2007-34 aka CVE-2007-5337
* MFSA 2007-35 aka CVE-2007-5338
* MFSA 2007-36 aka CVE-2007-4841 (windows only)

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
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 
27
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the MPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the MPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
// Platform specific code to invoke XPCOM methods on native objects
 
40
 
 
41
#include "xptcprivate.h"
 
42
 
 
43
// 6 integral parameters are passed in registers
 
44
const PRUint32 GPR_COUNT = 6;
 
45
 
 
46
// 8 floating point parameters are passed in SSE registers
 
47
const PRUint32 FPR_COUNT = 8;
 
48
 
 
49
// Remember that these 'words' are 64-bit long
 
50
static inline void
 
51
invoke_count_words(PRUint32 paramCount, nsXPTCVariant * s,
 
52
                   PRUint32 & nr_gpr, PRUint32 & nr_fpr, PRUint32 & nr_stack)
 
53
{
 
54
    nr_gpr = 1; // skip one GP register for 'that'
 
55
    nr_fpr = 0;
 
56
    nr_stack = 0;
 
57
 
 
58
    /* Compute number of eightbytes of class MEMORY.  */
 
59
    for (uint32 i = 0; i < paramCount; i++, s++) {
 
60
        if (!s->IsPtrData()
 
61
            && (s->type == nsXPTType::T_FLOAT || s->type == nsXPTType::T_DOUBLE)) {
 
62
            if (nr_fpr < FPR_COUNT)
 
63
                nr_fpr++;
 
64
            else
 
65
                nr_stack++;
 
66
        }
 
67
        else {
 
68
            if (nr_gpr < GPR_COUNT)
 
69
                nr_gpr++;
 
70
            else
 
71
                nr_stack++;
 
72
        }
 
73
    }
 
74
}
 
75
 
 
76
static void
 
77
invoke_copy_to_stack(PRUint64 * d, PRUint32 paramCount, nsXPTCVariant * s,
 
78
                     PRUint64 * gpregs, double * fpregs)
 
79
{
 
80
    PRUint32 nr_gpr = 1; // skip one GP register for 'that'
 
81
    PRUint32 nr_fpr = 0;
 
82
    PRUint64 value;
 
83
 
 
84
    for (uint32 i = 0; i < paramCount; i++, s++) {
 
85
        if (s->IsPtrData())
 
86
            value = (PRUint64) s->ptr;
 
87
        else {
 
88
            switch (s->type) {
 
89
            case nsXPTType::T_FLOAT:                                break;
 
90
            case nsXPTType::T_DOUBLE:                               break;
 
91
            case nsXPTType::T_I8:     value = s->val.i8;            break;
 
92
            case nsXPTType::T_I16:    value = s->val.i16;           break;
 
93
            case nsXPTType::T_I32:    value = s->val.i32;           break;
 
94
            case nsXPTType::T_I64:    value = s->val.i64;           break;
 
95
            case nsXPTType::T_U8:     value = s->val.u8;            break;
 
96
            case nsXPTType::T_U16:    value = s->val.u16;           break;
 
97
            case nsXPTType::T_U32:    value = s->val.u32;           break;
 
98
            case nsXPTType::T_U64:    value = s->val.u64;           break;
 
99
            case nsXPTType::T_BOOL:   value = s->val.b;             break;
 
100
            case nsXPTType::T_CHAR:   value = s->val.c;             break;
 
101
            case nsXPTType::T_WCHAR:  value = s->val.wc;            break;
 
102
            default:                  value = (PRUint64) s->val.p;  break;
 
103
            }
 
104
        }
 
105
 
 
106
        if (!s->IsPtrData() && s->type == nsXPTType::T_DOUBLE) {
 
107
            if (nr_fpr < FPR_COUNT)
 
108
                fpregs[nr_fpr++] = s->val.d;
 
109
            else {
 
110
                *((double *)d) = s->val.d;
 
111
                d++;
 
112
            }
 
113
        }
 
114
        else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) {
 
115
            if (nr_fpr < FPR_COUNT)
 
116
                // The value in %xmm register is already prepared to
 
117
                // be retrieved as a float. Therefore, we pass the
 
118
                // value verbatim, as a double without conversion.
 
119
                fpregs[nr_fpr++] = s->val.d;
 
120
            else {
 
121
                *((float *)d) = s->val.f;
 
122
                d++;
 
123
            }
 
124
        }
 
125
        else {
 
126
            if (nr_gpr < GPR_COUNT)
 
127
                gpregs[nr_gpr++] = value;
 
128
            else
 
129
                *d++ = value;
 
130
        }
 
131
    }
 
132
}
 
133
 
 
134
extern "C"
 
135
XPTC_PUBLIC_API(nsresult)
 
136
XPTC_InvokeByIndex(nsISupports * that, PRUint32 methodIndex,
 
137
                   PRUint32 paramCount, nsXPTCVariant * params)
 
138
{
 
139
    PRUint32 nr_gpr, nr_fpr, nr_stack;
 
140
    invoke_count_words(paramCount, params, nr_gpr, nr_fpr, nr_stack);
 
141
    
 
142
    // Stack, if used, must be 16-bytes aligned
 
143
    if (nr_stack)
 
144
        nr_stack = (nr_stack + 1) & ~1;
 
145
 
 
146
    // Load parameters to stack, if necessary
 
147
    PRUint64 *stack = (PRUint64 *) __builtin_alloca(nr_stack * 8);
 
148
    PRUint64 gpregs[GPR_COUNT];
 
149
    double fpregs[FPR_COUNT];
 
150
    invoke_copy_to_stack(stack, paramCount, params, gpregs, fpregs);
 
151
 
 
152
    // Load FPR registers from fpregs[]
 
153
    register double d0 asm("xmm0");
 
154
    register double d1 asm("xmm1");
 
155
    register double d2 asm("xmm2");
 
156
    register double d3 asm("xmm3");
 
157
    register double d4 asm("xmm4");
 
158
    register double d5 asm("xmm5");
 
159
    register double d6 asm("xmm6");
 
160
    register double d7 asm("xmm7");
 
161
 
 
162
    switch (nr_fpr) {
 
163
#define ARG_FPR(N) \
 
164
    case N+1: d##N = fpregs[N];
 
165
        ARG_FPR(7);
 
166
        ARG_FPR(6);
 
167
        ARG_FPR(5);
 
168
        ARG_FPR(4);
 
169
        ARG_FPR(3);
 
170
        ARG_FPR(2);
 
171
        ARG_FPR(1);
 
172
        ARG_FPR(0);
 
173
    case 0:;
 
174
#undef ARG_FPR
 
175
    }
 
176
    
 
177
    // Load GPR registers from gpregs[]
 
178
    register PRUint64 a0 asm("rdi");
 
179
    register PRUint64 a1 asm("rsi");
 
180
    register PRUint64 a2 asm("rdx");
 
181
    register PRUint64 a3 asm("rcx");
 
182
    register PRUint64 a4 asm("r8");
 
183
    register PRUint64 a5 asm("r9");
 
184
    
 
185
    switch (nr_gpr) {
 
186
#define ARG_GPR(N) \
 
187
    case N+1: a##N = gpregs[N];
 
188
        ARG_GPR(5);
 
189
        ARG_GPR(4);
 
190
        ARG_GPR(3);
 
191
        ARG_GPR(2);
 
192
        ARG_GPR(1);
 
193
    case 1: a0 = (PRUint64) that;
 
194
    case 0:;
 
195
#undef ARG_GPR
 
196
    }
 
197
 
 
198
    // Ensure that assignments to SSE registers won't be optimized away
 
199
    asm("" ::
 
200
        "x" (d0), "x" (d1), "x" (d2), "x" (d3),
 
201
        "x" (d4), "x" (d5), "x" (d6), "x" (d7));
 
202
    
 
203
    // Get pointer to method
 
204
    PRUint64 methodAddress = *((PRUint64 *)that);
 
205
    methodAddress += 8 * methodIndex;
 
206
    methodAddress = *((PRUint64 *)methodAddress);
 
207
    
 
208
    typedef PRUint32 (*Method)(PRUint64, PRUint64, PRUint64, PRUint64, PRUint64, PRUint64);
 
209
    PRUint32 result = ((Method)methodAddress)(a0, a1, a2, a3, a4, a5);
 
210
    return result;
 
211
}