1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1.  Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 * 2.  Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
16 *     contributors may be used to endorse or promote products derived from
17 *     this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Portions of this software have been released under the following terms:
31 *
32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
35 *
36 * To anyone who acknowledges that this file is provided "AS IS"
37 * without any express or implied warranty:
38 * permission to use, copy, modify, and distribute this file for any
39 * purpose is hereby granted without fee, provided that the above
40 * copyright notices and this notice appears in all source code copies,
41 * and that none of the names of Open Software Foundation, Inc., Hewlett-
42 * Packard Company or Digital Equipment Corporation be used
43 * in advertising or publicity pertaining to distribution of the software
44 * without specific, written prior permission.  Neither Open Software
45 * Foundation, Inc., Hewlett-Packard Company nor Digital
46 * Equipment Corporation makes any representations about the suitability
47 * of this software for any purpose.
48 *
49 * Copyright (c) 2007, Novell, Inc. All rights reserved.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 *
54 * 1.  Redistributions of source code must retain the above copyright
55 *     notice, this list of conditions and the following disclaimer.
56 * 2.  Redistributions in binary form must reproduce the above copyright
57 *     notice, this list of conditions and the following disclaimer in the
58 *     documentation and/or other materials provided with the distribution.
59 * 3.  Neither the name of Novell Inc. nor the names of its contributors
60 *     may be used to endorse or promote products derived from this
61 *     this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 *
74 * @APPLE_LICENSE_HEADER_END@
75 */
76
77/*
78**
79**  NAME:
80**
81**      sscmaset.c
82**
83**  FACILITY:
84**
85**      IDL Stub Runtime Support
86**
87**  ABSTRACT:
88**
89**      CMA machinery used by IDL stubs, conversion between
90**       exceptions and status codes, maps between statuses,
91**       ASCII/EBCDIC support, optimization support
92**
93**  VERSION: DCE 1.0
94**
95*/
96#if HAVE_CONFIG_H
97#include <config.h>
98#endif
99
100/* The ordering of the following 3 includes should NOT be changed! */
101#include <dce/rpc.h>
102#include <dce/stubbase.h>
103#include <lsysdep.h>
104
105#ifdef MIA
106#include <dce/idlddefs.h>
107#endif
108
109#   include <stdio.h>
110#   ifdef __STDC__
111#       include <stdlib.h>
112#   endif
113
114void rpc_ss_trans_table_init(void);
115
116/*
117 * declare the default character translation tables.  Not in stubbase, since
118 * the stubs never reference them directly.
119 */
120globalref rpc_trans_tab_t ndr_g_def_ascii_to_ebcdic;
121globalref rpc_trans_tab_t ndr_g_def_ebcdic_to_ascii;
122
123/*
124 * Forward referenced routines.
125 */
126static error_status_t rpc_ss_map_fault_code
127(
128    ndr_ulong_int fault_code
129);
130
131/* rpc_ss_call_free is needed because we can't use 'free' as a procedure argument
132    or in an assignment, because CMA has redefined free to be
133    a macro with an argument */
134void rpc_ss_call_free
135(
136    rpc_void_p_t address
137)
138{
139    free( address );
140}
141
142#if defined(CMA_INCLUDE)  /* Need CMA_INCLUDE which provides cma_global_lock */
143
144/******************************************************************************/
145/*                                                                            */
146/*    Set up jacket for getenv() to make it thread safe.                      */
147/*    If the base implementation provides a safe getenv, this can be discarded*/
148/*                                                                            */
149/******************************************************************************/
150char * safe_getenv
151(
152    char *variable
153)
154{
155    char *result;
156    cma_lock_global ();
157    result = (char*)getenv (variable);
158    cma_unlock_global ();
159    return result;
160}
161#define getenv safe_getenv
162#endif
163
164/***************************************************************************
165 * Initialize the character translation tables.
166 * This routine is designed to be called from rpc_ss_init_client.
167 * That guarantees that it will only be invoked once per address space.
168 **************************************************************************/
169void rpc_ss_trans_table_init(
170    void
171)
172{
173char *filename;
174FILE *fid;
175
176    /*
177     * Attempt to translate the environment variable which points us
178     * to a file containing replacement translation tables.
179     */
180    if (!(filename = (char*)getenv("DCERPCCHARTRANS"))) {
181        ndr_g_ascii_to_ebcdic = (rpc_trans_tab_p_t) &ndr_g_def_ascii_to_ebcdic[0];
182        ndr_g_ebcdic_to_ascii = (rpc_trans_tab_p_t) &ndr_g_def_ebcdic_to_ascii[0];
183        return;
184    }
185
186    /*
187     * We have a translation, therefore we attempt to open the file.
188     * A failure to open the file must be reported.  We can't use
189     * the defalt translation table if the user told us to use some
190     * alternate ones. Raise a file open failure exception.
191     */
192    ndr_g_ascii_to_ebcdic = (rpc_trans_tab_p_t) malloc (512);
193
194    if (ndr_g_ascii_to_ebcdic==NULL)
195        DCETHREAD_RAISE(rpc_x_no_memory);
196
197    if (!(fid = fopen (filename, "r")))
198        DCETHREAD_RAISE(rpc_x_ss_char_trans_open_fail);
199
200    /*
201     * Successfully opened the file.  There must be at least 512 bytes
202     * in the file.  The first 256 are the ASCII->EBCDIC table--the second
203     * 256 are the EBCDIC->ASCII table.  Bytes after 512 are ignored.
204     */
205    ndr_g_ebcdic_to_ascii = (rpc_trans_tab_p_t)(
206                     (char*) ndr_g_ascii_to_ebcdic + 256);
207
208    /*
209     * If fewer than 512 bytes are read, raise a shortfile exception.
210     */
211    if (fread ((char *)ndr_g_ascii_to_ebcdic, 1, 512, fid) < (size_t)512)
212    {
213        fclose (fid);
214        DCETHREAD_RAISE(rpc_x_ss_char_trans_short_file);
215    }
216
217    /*
218     * We are done, with the table pointers initialized to either the default
219     * tables, or to the custom tables read from the file.
220     */
221    fclose (fid);
222}
223
224/******************************************************************************/
225/*                                                                            */
226/*    Set up CMA machinery required by client                                 */
227/*                                                                            */
228/******************************************************************************/
229
230ndr_boolean rpc_ss_client_is_set_up = ndr_false;
231static RPC_SS_THREADS_ONCE_T client_once = RPC_SS_THREADS_ONCE_INIT;
232
233globaldef dcethread_exc rpc_x_assoc_grp_not_found;
234globaldef dcethread_exc rpc_x_call_timeout;
235globaldef dcethread_exc rpc_x_cancel_timeout;
236globaldef dcethread_exc rpc_x_coding_error;
237globaldef dcethread_exc rpc_x_context_id_not_found;
238globaldef dcethread_exc rpc_x_comm_failure;
239globaldef dcethread_exc rpc_x_endpoint_not_found;
240globaldef dcethread_exc rpc_x_in_args_too_big;
241globaldef dcethread_exc rpc_x_invalid_binding;
242globaldef dcethread_exc rpc_x_invalid_bound;
243globaldef dcethread_exc rpc_x_invalid_call_opt;
244globaldef dcethread_exc rpc_x_invalid_naf_id;
245globaldef dcethread_exc rpc_x_invalid_rpc_protseq;
246globaldef dcethread_exc rpc_x_invalid_tag;
247globaldef dcethread_exc rpc_x_invalid_timeout;
248globaldef dcethread_exc rpc_x_manager_not_entered;
249globaldef dcethread_exc rpc_x_max_descs_exceeded;
250globaldef dcethread_exc rpc_x_no_fault;
251globaldef dcethread_exc rpc_x_no_memory;
252globaldef dcethread_exc rpc_x_not_rpc_tower;
253globaldef dcethread_exc rpc_x_op_rng_error;
254globaldef dcethread_exc rpc_x_object_not_found;
255globaldef dcethread_exc rpc_x_protocol_error;
256globaldef dcethread_exc rpc_x_protseq_not_supported;
257globaldef dcethread_exc rpc_x_rpcd_comm_failure;
258globaldef dcethread_exc rpc_x_server_too_busy;
259globaldef dcethread_exc rpc_x_unknown_error;
260globaldef dcethread_exc rpc_x_unknown_if;
261globaldef dcethread_exc rpc_x_unknown_mgr_type;
262globaldef dcethread_exc rpc_x_unknown_reject;
263globaldef dcethread_exc rpc_x_unknown_remote_fault;
264globaldef dcethread_exc rpc_x_unsupported_type;
265globaldef dcethread_exc rpc_x_who_are_you_failed;
266globaldef dcethread_exc rpc_x_wrong_boot_time;
267globaldef dcethread_exc rpc_x_wrong_kind_of_binding;
268globaldef dcethread_exc uuid_x_getconf_failure;
269globaldef dcethread_exc uuid_x_no_address;
270globaldef dcethread_exc uuid_x_internal_error;
271globaldef dcethread_exc uuid_x_socket_failure;
272
273globaldef dcethread_exc rpc_x_access_control_info_inv;
274globaldef dcethread_exc rpc_x_assoc_grp_max_exceeded;
275globaldef dcethread_exc rpc_x_assoc_shutdown;
276globaldef dcethread_exc rpc_x_cannot_accept;
277globaldef dcethread_exc rpc_x_cannot_connect;
278globaldef dcethread_exc rpc_x_cannot_set_nodelay;
279globaldef dcethread_exc rpc_x_cant_inq_socket;
280globaldef dcethread_exc rpc_x_connect_closed_by_rem;
281globaldef dcethread_exc rpc_x_connect_no_resources;
282globaldef dcethread_exc rpc_x_connect_rejected;
283globaldef dcethread_exc rpc_x_connect_timed_out;
284globaldef dcethread_exc rpc_x_connection_aborted;
285globaldef dcethread_exc rpc_x_connection_closed;
286globaldef dcethread_exc rpc_x_host_unreachable;
287globaldef dcethread_exc rpc_x_invalid_endpoint_format;
288globaldef dcethread_exc rpc_x_loc_connect_aborted;
289globaldef dcethread_exc rpc_x_network_unreachable;
290globaldef dcethread_exc rpc_x_no_rem_endpoint;
291globaldef dcethread_exc rpc_x_rem_host_crashed;
292globaldef dcethread_exc rpc_x_rem_host_down;
293globaldef dcethread_exc rpc_x_rem_network_shutdown;
294globaldef dcethread_exc rpc_x_rpc_prot_version_mismatch;
295globaldef dcethread_exc rpc_x_string_too_long;
296globaldef dcethread_exc rpc_x_too_many_rem_connects;
297globaldef dcethread_exc rpc_x_tsyntaxes_unsupported;
298
299globaldef dcethread_exc rpc_x_binding_vector_full;
300globaldef dcethread_exc rpc_x_entry_not_found;
301globaldef dcethread_exc rpc_x_group_not_found;
302globaldef dcethread_exc rpc_x_incomplete_name;
303globaldef dcethread_exc rpc_x_invalid_arg;
304globaldef dcethread_exc rpc_x_invalid_import_context;
305globaldef dcethread_exc rpc_x_invalid_inquiry_context;
306globaldef dcethread_exc rpc_x_invalid_inquiry_type;
307globaldef dcethread_exc rpc_x_invalid_lookup_context;
308globaldef dcethread_exc rpc_x_invalid_name_syntax;
309globaldef dcethread_exc rpc_x_invalid_object;
310globaldef dcethread_exc rpc_x_invalid_vers_option;
311globaldef dcethread_exc rpc_x_name_service_unavailable;
312globaldef dcethread_exc rpc_x_no_env_setup;
313globaldef dcethread_exc rpc_x_no_more_bindings;
314globaldef dcethread_exc rpc_x_no_more_elements;
315globaldef dcethread_exc rpc_x_no_ns_permission;
316globaldef dcethread_exc rpc_x_not_found;
317globaldef dcethread_exc rpc_x_not_rpc_entry;
318globaldef dcethread_exc rpc_x_obj_uuid_not_found;
319globaldef dcethread_exc rpc_x_profile_not_found;
320globaldef dcethread_exc rpc_x_unsupported_name_syntax;
321
322globaldef dcethread_exc rpc_x_auth_bad_integrity;
323globaldef dcethread_exc rpc_x_auth_badaddr;
324globaldef dcethread_exc rpc_x_auth_baddirection;
325globaldef dcethread_exc rpc_x_auth_badkeyver;
326globaldef dcethread_exc rpc_x_auth_badmatch;
327globaldef dcethread_exc rpc_x_auth_badorder;
328globaldef dcethread_exc rpc_x_auth_badseq;
329globaldef dcethread_exc rpc_x_auth_badversion;
330globaldef dcethread_exc rpc_x_auth_field_toolong;
331globaldef dcethread_exc rpc_x_auth_inapp_cksum;
332globaldef dcethread_exc rpc_x_auth_method;
333globaldef dcethread_exc rpc_x_auth_msg_type;
334globaldef dcethread_exc rpc_x_auth_modified;
335globaldef dcethread_exc rpc_x_auth_mut_fail;
336globaldef dcethread_exc rpc_x_auth_nokey;
337globaldef dcethread_exc rpc_x_auth_not_us;
338globaldef dcethread_exc rpc_x_auth_repeat;
339globaldef dcethread_exc rpc_x_auth_skew;
340globaldef dcethread_exc rpc_x_auth_tkt_expired;
341globaldef dcethread_exc rpc_x_auth_tkt_nyv;
342globaldef dcethread_exc rpc_x_call_id_not_found;
343globaldef dcethread_exc rpc_x_credentials_too_large;
344globaldef dcethread_exc rpc_x_invalid_checksum;
345globaldef dcethread_exc rpc_x_invalid_crc;
346globaldef dcethread_exc rpc_x_invalid_credentials;
347globaldef dcethread_exc rpc_x_key_id_not_found;
348
349globaldef dcethread_exc rpc_x_ss_pipe_empty;
350globaldef dcethread_exc rpc_x_ss_pipe_closed;
351globaldef dcethread_exc rpc_x_ss_pipe_order;
352globaldef dcethread_exc rpc_x_ss_pipe_discipline_error;
353globaldef dcethread_exc rpc_x_ss_pipe_comm_error;
354globaldef dcethread_exc rpc_x_ss_pipe_memory;
355globaldef dcethread_exc rpc_x_ss_context_mismatch;
356globaldef dcethread_exc rpc_x_ss_context_damaged;
357globaldef dcethread_exc rpc_x_ss_in_null_context;
358globaldef dcethread_exc rpc_x_ss_char_trans_short_file;
359globaldef dcethread_exc rpc_x_ss_char_trans_open_fail;
360globaldef dcethread_exc rpc_x_ss_remote_comm_failure;
361globaldef dcethread_exc rpc_x_ss_remote_no_memory;
362globaldef dcethread_exc rpc_x_ss_bad_buffer;
363globaldef dcethread_exc rpc_x_ss_bad_es_action;
364globaldef dcethread_exc rpc_x_ss_wrong_es_version;
365globaldef dcethread_exc rpc_x_ss_incompatible_codesets;
366globaldef dcethread_exc rpc_x_stub_protocol_error;
367globaldef dcethread_exc rpc_x_unknown_stub_rtl_if_vers;
368globaldef dcethread_exc rpc_x_ss_codeset_conv_error;
369
370static void rpc_ss_init_client(
371    void
372)
373{
374    /* Initialize exceptions */
375    DCETHREAD_EXC_INIT(rpc_x_assoc_grp_not_found);
376    dcethread_exc_setstatus(&rpc_x_assoc_grp_not_found,rpc_s_assoc_grp_not_found);
377    DCETHREAD_EXC_INIT(rpc_x_call_timeout);
378    dcethread_exc_setstatus(&rpc_x_call_timeout,rpc_s_call_timeout);
379    DCETHREAD_EXC_INIT(rpc_x_cancel_timeout);
380    dcethread_exc_setstatus(&rpc_x_cancel_timeout,rpc_s_cancel_timeout);
381    DCETHREAD_EXC_INIT(rpc_x_coding_error);
382    dcethread_exc_setstatus(&rpc_x_coding_error,rpc_s_coding_error);
383    DCETHREAD_EXC_INIT(rpc_x_comm_failure);
384    dcethread_exc_setstatus(&rpc_x_comm_failure,rpc_s_comm_failure);
385    DCETHREAD_EXC_INIT(rpc_x_context_id_not_found);
386    dcethread_exc_setstatus(&rpc_x_context_id_not_found,rpc_s_context_id_not_found);
387    DCETHREAD_EXC_INIT(rpc_x_endpoint_not_found);
388    dcethread_exc_setstatus(&rpc_x_endpoint_not_found,rpc_s_endpoint_not_found);
389    DCETHREAD_EXC_INIT(rpc_x_in_args_too_big);
390    dcethread_exc_setstatus(&rpc_x_in_args_too_big,rpc_s_in_args_too_big);
391    DCETHREAD_EXC_INIT(rpc_x_invalid_binding);
392    dcethread_exc_setstatus(&rpc_x_invalid_binding,rpc_s_invalid_binding);
393    DCETHREAD_EXC_INIT(rpc_x_invalid_bound);
394    dcethread_exc_setstatus(&rpc_x_invalid_bound,rpc_s_fault_invalid_bound);
395    DCETHREAD_EXC_INIT(rpc_x_invalid_call_opt);
396    dcethread_exc_setstatus(&rpc_x_invalid_call_opt,rpc_s_invalid_call_opt);
397    DCETHREAD_EXC_INIT(rpc_x_invalid_naf_id);
398    dcethread_exc_setstatus(&rpc_x_invalid_naf_id,rpc_s_invalid_naf_id);
399    DCETHREAD_EXC_INIT(rpc_x_invalid_rpc_protseq);
400    dcethread_exc_setstatus(&rpc_x_invalid_rpc_protseq,rpc_s_invalid_rpc_protseq);
401    DCETHREAD_EXC_INIT(rpc_x_invalid_tag);
402    dcethread_exc_setstatus(&rpc_x_invalid_tag,rpc_s_fault_invalid_tag);
403    DCETHREAD_EXC_INIT(rpc_x_invalid_timeout);
404    dcethread_exc_setstatus(&rpc_x_invalid_timeout,rpc_s_invalid_timeout);
405    DCETHREAD_EXC_INIT(rpc_x_manager_not_entered);
406    dcethread_exc_setstatus(&rpc_x_manager_not_entered,rpc_s_manager_not_entered);
407    DCETHREAD_EXC_INIT(rpc_x_max_descs_exceeded);
408    dcethread_exc_setstatus(&rpc_x_max_descs_exceeded,rpc_s_max_descs_exceeded);
409    DCETHREAD_EXC_INIT(rpc_x_no_fault);
410    dcethread_exc_setstatus(&rpc_x_no_fault,rpc_s_no_fault);
411    DCETHREAD_EXC_INIT(rpc_x_no_memory);
412    dcethread_exc_setstatus(&rpc_x_no_memory,rpc_s_no_memory);
413    DCETHREAD_EXC_INIT(rpc_x_not_rpc_tower);
414    dcethread_exc_setstatus(&rpc_x_not_rpc_tower,rpc_s_not_rpc_tower);
415    DCETHREAD_EXC_INIT(rpc_x_object_not_found);
416    dcethread_exc_setstatus(&rpc_x_object_not_found,rpc_s_object_not_found);
417    DCETHREAD_EXC_INIT(rpc_x_op_rng_error);
418    dcethread_exc_setstatus(&rpc_x_op_rng_error,rpc_s_op_rng_error);
419    DCETHREAD_EXC_INIT(rpc_x_protocol_error);
420    dcethread_exc_setstatus(&rpc_x_protocol_error,rpc_s_protocol_error);
421    DCETHREAD_EXC_INIT(rpc_x_protseq_not_supported);
422    dcethread_exc_setstatus(&rpc_x_protseq_not_supported,rpc_s_protseq_not_supported);
423    DCETHREAD_EXC_INIT(rpc_x_rpcd_comm_failure);
424    dcethread_exc_setstatus(&rpc_x_rpcd_comm_failure,rpc_s_rpcd_comm_failure);
425    DCETHREAD_EXC_INIT(rpc_x_server_too_busy);
426    dcethread_exc_setstatus(&rpc_x_server_too_busy,rpc_s_server_too_busy);
427    DCETHREAD_EXC_INIT(rpc_x_unknown_error);
428    dcethread_exc_setstatus(&rpc_x_unknown_error,rpc_s_unknown_error);
429    DCETHREAD_EXC_INIT(rpc_x_unknown_if);
430    dcethread_exc_setstatus(&rpc_x_unknown_if,rpc_s_unknown_if);
431    DCETHREAD_EXC_INIT(rpc_x_unknown_mgr_type);
432    dcethread_exc_setstatus(&rpc_x_unknown_mgr_type,rpc_s_unknown_mgr_type);
433    DCETHREAD_EXC_INIT(rpc_x_unknown_reject);
434    dcethread_exc_setstatus(&rpc_x_unknown_reject,rpc_s_unknown_reject);
435    DCETHREAD_EXC_INIT(rpc_x_unknown_remote_fault);
436    dcethread_exc_setstatus(&rpc_x_unknown_remote_fault,rpc_s_fault_unspec);
437    DCETHREAD_EXC_INIT(rpc_x_unsupported_type);
438    dcethread_exc_setstatus(&rpc_x_unsupported_type,rpc_s_unsupported_type);
439    DCETHREAD_EXC_INIT(rpc_x_who_are_you_failed);
440    dcethread_exc_setstatus(&rpc_x_who_are_you_failed,rpc_s_who_are_you_failed);
441    DCETHREAD_EXC_INIT(rpc_x_wrong_boot_time);
442    dcethread_exc_setstatus(&rpc_x_wrong_boot_time,rpc_s_wrong_boot_time);
443    DCETHREAD_EXC_INIT(rpc_x_wrong_kind_of_binding);
444    dcethread_exc_setstatus(&rpc_x_wrong_kind_of_binding,rpc_s_wrong_kind_of_binding);
445    DCETHREAD_EXC_INIT(uuid_x_getconf_failure);
446    dcethread_exc_setstatus(&uuid_x_getconf_failure,uuid_s_getconf_failure);
447    DCETHREAD_EXC_INIT(uuid_x_internal_error);
448    dcethread_exc_setstatus(&uuid_x_internal_error,uuid_s_internal_error);
449    DCETHREAD_EXC_INIT(uuid_x_no_address);
450    dcethread_exc_setstatus(&uuid_x_no_address,uuid_s_no_address);
451    DCETHREAD_EXC_INIT(uuid_x_socket_failure);
452    dcethread_exc_setstatus(&uuid_x_socket_failure,uuid_s_socket_failure);
453
454    DCETHREAD_EXC_INIT(rpc_x_access_control_info_inv);
455    dcethread_exc_setstatus(&rpc_x_access_control_info_inv,rpc_s_access_control_info_inv);
456    DCETHREAD_EXC_INIT(rpc_x_assoc_grp_max_exceeded);
457    dcethread_exc_setstatus(&rpc_x_assoc_grp_max_exceeded,rpc_s_assoc_grp_max_exceeded);
458    DCETHREAD_EXC_INIT(rpc_x_assoc_shutdown);
459    dcethread_exc_setstatus(&rpc_x_assoc_shutdown,rpc_s_assoc_shutdown);
460    DCETHREAD_EXC_INIT(rpc_x_cannot_accept);
461    dcethread_exc_setstatus(&rpc_x_cannot_accept,rpc_s_cannot_accept);
462    DCETHREAD_EXC_INIT(rpc_x_cannot_connect);
463    dcethread_exc_setstatus(&rpc_x_cannot_connect,rpc_s_cannot_connect);
464    DCETHREAD_EXC_INIT(rpc_x_cannot_set_nodelay);
465    dcethread_exc_setstatus(&rpc_x_cannot_set_nodelay,rpc_s_cannot_set_nodelay);
466    DCETHREAD_EXC_INIT(rpc_x_cant_inq_socket);
467    dcethread_exc_setstatus(&rpc_x_cant_inq_socket,rpc_s_cant_inq_socket);
468    DCETHREAD_EXC_INIT(rpc_x_connect_closed_by_rem);
469    dcethread_exc_setstatus(&rpc_x_connect_closed_by_rem,rpc_s_connect_closed_by_rem);
470    DCETHREAD_EXC_INIT(rpc_x_connect_no_resources);
471    dcethread_exc_setstatus(&rpc_x_connect_no_resources,rpc_s_connect_no_resources);
472    DCETHREAD_EXC_INIT(rpc_x_connect_rejected);
473    dcethread_exc_setstatus(&rpc_x_connect_rejected,rpc_s_connect_rejected);
474    DCETHREAD_EXC_INIT(rpc_x_connect_timed_out);
475    dcethread_exc_setstatus(&rpc_x_connect_timed_out,rpc_s_connect_timed_out);
476    DCETHREAD_EXC_INIT(rpc_x_connection_aborted);
477    dcethread_exc_setstatus(&rpc_x_connection_aborted,rpc_s_connection_aborted);
478    DCETHREAD_EXC_INIT(rpc_x_connection_closed);
479    dcethread_exc_setstatus(&rpc_x_connection_closed,rpc_s_connection_closed);
480    DCETHREAD_EXC_INIT(rpc_x_host_unreachable);
481    dcethread_exc_setstatus(&rpc_x_host_unreachable,rpc_s_host_unreachable);
482    DCETHREAD_EXC_INIT(rpc_x_invalid_endpoint_format);
483    dcethread_exc_setstatus(&rpc_x_invalid_endpoint_format,rpc_s_invalid_endpoint_format);
484    DCETHREAD_EXC_INIT(rpc_x_loc_connect_aborted);
485    dcethread_exc_setstatus(&rpc_x_loc_connect_aborted,rpc_s_loc_connect_aborted);
486    DCETHREAD_EXC_INIT(rpc_x_network_unreachable);
487    dcethread_exc_setstatus(&rpc_x_network_unreachable,rpc_s_network_unreachable);
488    DCETHREAD_EXC_INIT(rpc_x_no_rem_endpoint);
489    dcethread_exc_setstatus(&rpc_x_no_rem_endpoint,rpc_s_no_rem_endpoint);
490    DCETHREAD_EXC_INIT(rpc_x_rem_host_crashed);
491    dcethread_exc_setstatus(&rpc_x_rem_host_crashed,rpc_s_rem_host_crashed);
492    DCETHREAD_EXC_INIT(rpc_x_rem_host_down);
493    dcethread_exc_setstatus(&rpc_x_rem_host_down,rpc_s_rem_host_down);
494    DCETHREAD_EXC_INIT(rpc_x_rem_network_shutdown);
495    dcethread_exc_setstatus(&rpc_x_rem_network_shutdown,rpc_s_rem_network_shutdown);
496    DCETHREAD_EXC_INIT(rpc_x_rpc_prot_version_mismatch);
497    dcethread_exc_setstatus(&rpc_x_rpc_prot_version_mismatch,rpc_s_rpc_prot_version_mismatch);
498    DCETHREAD_EXC_INIT(rpc_x_string_too_long);
499    dcethread_exc_setstatus(&rpc_x_string_too_long,rpc_s_string_too_long);
500    DCETHREAD_EXC_INIT(rpc_x_too_many_rem_connects);
501    dcethread_exc_setstatus(&rpc_x_too_many_rem_connects,rpc_s_too_many_rem_connects);
502    DCETHREAD_EXC_INIT(rpc_x_tsyntaxes_unsupported);
503    dcethread_exc_setstatus(&rpc_x_tsyntaxes_unsupported,rpc_s_tsyntaxes_unsupported);
504
505    DCETHREAD_EXC_INIT(rpc_x_binding_vector_full);
506    dcethread_exc_setstatus(&rpc_x_binding_vector_full,rpc_s_binding_vector_full);
507    DCETHREAD_EXC_INIT(rpc_x_entry_not_found);
508    dcethread_exc_setstatus(&rpc_x_entry_not_found,rpc_s_entry_not_found);
509    DCETHREAD_EXC_INIT(rpc_x_group_not_found);
510    dcethread_exc_setstatus(&rpc_x_group_not_found,rpc_s_group_not_found);
511    DCETHREAD_EXC_INIT(rpc_x_incomplete_name);
512    dcethread_exc_setstatus(&rpc_x_incomplete_name,rpc_s_incomplete_name);
513    DCETHREAD_EXC_INIT(rpc_x_invalid_arg);
514    dcethread_exc_setstatus(&rpc_x_invalid_arg,rpc_s_invalid_arg);
515    DCETHREAD_EXC_INIT(rpc_x_invalid_import_context);
516    dcethread_exc_setstatus(&rpc_x_invalid_import_context,rpc_s_invalid_import_context);
517    DCETHREAD_EXC_INIT(rpc_x_invalid_inquiry_context);
518    dcethread_exc_setstatus(&rpc_x_invalid_inquiry_context,rpc_s_invalid_inquiry_context);
519    DCETHREAD_EXC_INIT(rpc_x_invalid_inquiry_type);
520    dcethread_exc_setstatus(&rpc_x_invalid_inquiry_type,rpc_s_invalid_inquiry_type);
521    DCETHREAD_EXC_INIT(rpc_x_invalid_lookup_context);
522    dcethread_exc_setstatus(&rpc_x_invalid_lookup_context,rpc_s_invalid_lookup_context);
523    DCETHREAD_EXC_INIT(rpc_x_invalid_name_syntax);
524    dcethread_exc_setstatus(&rpc_x_invalid_name_syntax,rpc_s_invalid_name_syntax);
525    DCETHREAD_EXC_INIT(rpc_x_invalid_object);
526    dcethread_exc_setstatus(&rpc_x_invalid_object,rpc_s_invalid_object);
527    DCETHREAD_EXC_INIT(rpc_x_invalid_vers_option);
528    dcethread_exc_setstatus(&rpc_x_invalid_vers_option,rpc_s_invalid_vers_option);
529    DCETHREAD_EXC_INIT(rpc_x_name_service_unavailable);
530    dcethread_exc_setstatus(&rpc_x_name_service_unavailable,rpc_s_name_service_unavailable);
531    DCETHREAD_EXC_INIT(rpc_x_no_env_setup);
532    dcethread_exc_setstatus(&rpc_x_no_env_setup,rpc_s_no_env_setup);
533    DCETHREAD_EXC_INIT(rpc_x_no_more_bindings);
534    dcethread_exc_setstatus(&rpc_x_no_more_bindings,rpc_s_no_more_bindings);
535    DCETHREAD_EXC_INIT(rpc_x_no_more_elements);
536    dcethread_exc_setstatus(&rpc_x_no_more_elements,rpc_s_no_more_elements);
537    DCETHREAD_EXC_INIT(rpc_x_no_ns_permission);
538    dcethread_exc_setstatus(&rpc_x_no_ns_permission,rpc_s_no_ns_permission);
539    DCETHREAD_EXC_INIT(rpc_x_not_found);
540    dcethread_exc_setstatus(&rpc_x_not_found,rpc_s_not_found);
541    DCETHREAD_EXC_INIT(rpc_x_not_rpc_entry);
542    dcethread_exc_setstatus(&rpc_x_not_rpc_entry,rpc_s_not_rpc_entry);
543    DCETHREAD_EXC_INIT(rpc_x_obj_uuid_not_found);
544    dcethread_exc_setstatus(&rpc_x_obj_uuid_not_found,rpc_s_obj_uuid_not_found);
545    DCETHREAD_EXC_INIT(rpc_x_profile_not_found);
546    dcethread_exc_setstatus(&rpc_x_profile_not_found,rpc_s_profile_not_found);
547    DCETHREAD_EXC_INIT(rpc_x_unsupported_name_syntax);
548    dcethread_exc_setstatus(&rpc_x_unsupported_name_syntax,rpc_s_unsupported_name_syntax);
549
550    DCETHREAD_EXC_INIT(rpc_x_auth_bad_integrity);
551    dcethread_exc_setstatus(&rpc_x_auth_bad_integrity,rpc_s_auth_bad_integrity);
552    DCETHREAD_EXC_INIT(rpc_x_auth_badaddr);
553    dcethread_exc_setstatus(&rpc_x_auth_badaddr,rpc_s_auth_badaddr);
554    DCETHREAD_EXC_INIT(rpc_x_auth_baddirection);
555    dcethread_exc_setstatus(&rpc_x_auth_baddirection,rpc_s_auth_baddirection);
556    DCETHREAD_EXC_INIT(rpc_x_auth_badkeyver);
557    dcethread_exc_setstatus(&rpc_x_auth_badkeyver,rpc_s_auth_badkeyver);
558    DCETHREAD_EXC_INIT(rpc_x_auth_badmatch);
559    dcethread_exc_setstatus(&rpc_x_auth_badmatch,rpc_s_auth_badmatch);
560    DCETHREAD_EXC_INIT(rpc_x_auth_badorder);
561    dcethread_exc_setstatus(&rpc_x_auth_badorder,rpc_s_auth_badorder);
562    DCETHREAD_EXC_INIT(rpc_x_auth_badseq);
563    dcethread_exc_setstatus(&rpc_x_auth_badseq,rpc_s_auth_badseq);
564    DCETHREAD_EXC_INIT(rpc_x_auth_badversion);
565    dcethread_exc_setstatus(&rpc_x_auth_badversion,rpc_s_auth_badversion);
566    DCETHREAD_EXC_INIT(rpc_x_auth_field_toolong);
567    dcethread_exc_setstatus(&rpc_x_auth_field_toolong,rpc_s_auth_field_toolong);
568    DCETHREAD_EXC_INIT(rpc_x_auth_inapp_cksum);
569    dcethread_exc_setstatus(&rpc_x_auth_inapp_cksum,rpc_s_auth_inapp_cksum);
570    DCETHREAD_EXC_INIT(rpc_x_auth_method);
571    dcethread_exc_setstatus(&rpc_x_auth_method,rpc_s_auth_method);
572    DCETHREAD_EXC_INIT(rpc_x_auth_msg_type);
573    dcethread_exc_setstatus(&rpc_x_auth_msg_type,rpc_s_auth_msg_type);
574    DCETHREAD_EXC_INIT(rpc_x_auth_modified);
575    dcethread_exc_setstatus(&rpc_x_auth_modified,rpc_s_auth_modified);
576    DCETHREAD_EXC_INIT(rpc_x_auth_mut_fail);
577    dcethread_exc_setstatus(&rpc_x_auth_mut_fail,rpc_s_auth_mut_fail);
578    DCETHREAD_EXC_INIT(rpc_x_auth_nokey);
579    dcethread_exc_setstatus(&rpc_x_auth_nokey,rpc_s_auth_nokey);
580    DCETHREAD_EXC_INIT(rpc_x_auth_not_us);
581    dcethread_exc_setstatus(&rpc_x_auth_not_us,rpc_s_auth_not_us);
582    DCETHREAD_EXC_INIT(rpc_x_auth_repeat);
583    dcethread_exc_setstatus(&rpc_x_auth_repeat,rpc_s_auth_repeat);
584    DCETHREAD_EXC_INIT(rpc_x_auth_skew);
585    dcethread_exc_setstatus(&rpc_x_auth_skew,rpc_s_auth_skew);
586    DCETHREAD_EXC_INIT(rpc_x_auth_tkt_expired);
587    dcethread_exc_setstatus(&rpc_x_auth_tkt_expired,rpc_s_auth_tkt_expired);
588    DCETHREAD_EXC_INIT(rpc_x_auth_tkt_nyv);
589    dcethread_exc_setstatus(&rpc_x_auth_tkt_nyv,rpc_s_auth_tkt_nyv);
590    DCETHREAD_EXC_INIT(rpc_x_call_id_not_found);
591    dcethread_exc_setstatus(&rpc_x_call_id_not_found,rpc_s_call_id_not_found);
592    DCETHREAD_EXC_INIT(rpc_x_credentials_too_large);
593    dcethread_exc_setstatus(&rpc_x_credentials_too_large,rpc_s_credentials_too_large);
594    DCETHREAD_EXC_INIT(rpc_x_invalid_checksum);
595    dcethread_exc_setstatus(&rpc_x_invalid_checksum,rpc_s_invalid_checksum);
596    DCETHREAD_EXC_INIT(rpc_x_invalid_crc);
597    dcethread_exc_setstatus(&rpc_x_invalid_crc,rpc_s_invalid_crc);
598    DCETHREAD_EXC_INIT(rpc_x_invalid_credentials);
599    dcethread_exc_setstatus(&rpc_x_invalid_credentials,rpc_s_invalid_credentials);
600    DCETHREAD_EXC_INIT(rpc_x_key_id_not_found);
601    dcethread_exc_setstatus(&rpc_x_key_id_not_found,rpc_s_key_id_not_found);
602
603    DCETHREAD_EXC_INIT(rpc_x_ss_char_trans_open_fail);
604    dcethread_exc_setstatus(&rpc_x_ss_char_trans_open_fail,rpc_s_ss_char_trans_open_fail);
605    DCETHREAD_EXC_INIT(rpc_x_ss_char_trans_short_file);
606    dcethread_exc_setstatus(&rpc_x_ss_char_trans_short_file,rpc_s_ss_char_trans_short_file);
607    DCETHREAD_EXC_INIT(rpc_x_ss_pipe_empty);
608    dcethread_exc_setstatus(&rpc_x_ss_pipe_empty,rpc_s_fault_pipe_empty);
609    DCETHREAD_EXC_INIT(rpc_x_ss_pipe_closed);
610    dcethread_exc_setstatus(&rpc_x_ss_pipe_closed,rpc_s_fault_pipe_closed);
611    DCETHREAD_EXC_INIT(rpc_x_ss_pipe_order);
612    dcethread_exc_setstatus(&rpc_x_ss_pipe_order,rpc_s_fault_pipe_order);
613    DCETHREAD_EXC_INIT(rpc_x_ss_pipe_discipline_error);
614    dcethread_exc_setstatus(&rpc_x_ss_pipe_discipline_error,rpc_s_fault_pipe_discipline);
615    DCETHREAD_EXC_INIT(rpc_x_ss_pipe_comm_error);
616    dcethread_exc_setstatus(&rpc_x_ss_pipe_comm_error,rpc_s_fault_pipe_comm_error);
617    DCETHREAD_EXC_INIT(rpc_x_ss_pipe_memory);
618    dcethread_exc_setstatus(&rpc_x_ss_pipe_memory,rpc_s_fault_pipe_memory);
619    DCETHREAD_EXC_INIT(rpc_x_ss_context_mismatch);
620    dcethread_exc_setstatus(&rpc_x_ss_context_mismatch,rpc_s_fault_context_mismatch);
621    DCETHREAD_EXC_INIT(rpc_x_ss_context_damaged);
622    dcethread_exc_setstatus(&rpc_x_ss_context_damaged,rpc_s_ss_context_damaged);
623    DCETHREAD_EXC_INIT(rpc_x_ss_in_null_context);
624    dcethread_exc_setstatus(&rpc_x_ss_in_null_context,rpc_s_ss_in_null_context);
625    DCETHREAD_EXC_INIT(rpc_x_ss_remote_comm_failure);
626    dcethread_exc_setstatus(&rpc_x_ss_remote_comm_failure,rpc_s_fault_remote_comm_failure);
627    DCETHREAD_EXC_INIT(rpc_x_ss_remote_no_memory);
628    dcethread_exc_setstatus(&rpc_x_ss_remote_no_memory,rpc_s_fault_remote_no_memory);
629    DCETHREAD_EXC_INIT(rpc_x_ss_bad_buffer);
630    dcethread_exc_setstatus(&rpc_x_ss_bad_buffer,rpc_s_ss_bad_buffer);
631    DCETHREAD_EXC_INIT(rpc_x_ss_bad_es_action);
632    dcethread_exc_setstatus(&rpc_x_ss_bad_es_action,rpc_s_ss_bad_es_action);
633    DCETHREAD_EXC_INIT(rpc_x_ss_wrong_es_version);
634    dcethread_exc_setstatus(&rpc_x_ss_wrong_es_version,rpc_s_ss_wrong_es_version);
635    DCETHREAD_EXC_INIT(rpc_x_ss_incompatible_codesets);
636    dcethread_exc_setstatus(&rpc_x_ss_incompatible_codesets,rpc_s_ss_incompatible_codesets);
637    DCETHREAD_EXC_INIT(rpc_x_stub_protocol_error);
638    dcethread_exc_setstatus(&rpc_x_stub_protocol_error,rpc_s_stub_protocol_error);
639    DCETHREAD_EXC_INIT(rpc_x_unknown_stub_rtl_if_vers);
640    dcethread_exc_setstatus(&rpc_x_unknown_stub_rtl_if_vers,rpc_s_unknown_stub_rtl_if_vers);
641
642    rpc_ss_trans_table_init ();
643}
644
645void rpc_ss_init_client_once(
646    void
647)
648{
649    RPC_SS_THREADS_INIT;
650    RPC_SS_THREADS_ONCE( &client_once, rpc_ss_init_client );
651    rpc_ss_client_is_set_up = ndr_true;
652}
653
654#ifdef IDL_ENABLE_STATUS_MAPPING
655/******************************************************************************/
656/*                                                                            */
657/*    Routines to map a DCE status code to/from the local status code format  */
658/*                                                                            */
659/******************************************************************************/
660
661/* DCE status format definitions */
662#define FACILITY_CODE_MASK          0xF0000000
663#define FACILITY_CODE_SHIFT         28
664#define COMPONENT_CODE_MASK         0x0FFFF000
665#define COMPONENT_CODE_SHIFT        12
666#define STATUS_CODE_MASK            0x00000FFF
667#define STATUS_CODE_SHIFT           0
668
669/* DCE status definitions */
670#define dce_rpc_s_mod 0x16c9a000
671#define dce_thd_s_mod 0x177db000
672#define dce_sec_s_mod 0x17122000
673
674/******************************************************************************/
675/*                                                                            */
676/*    Map a DCE status code to the local status code format                   */
677/*                                                                            */
678/******************************************************************************/
679void rpc_ss_map_dce_to_local_status
680(
681    error_status_t *status_code_p   /* [in,out] pointer to DCE status -> local status */
682)
683{
684    unsigned long facility_and_comp_code;
685    unsigned short  status_code;
686
687    /*
688     * extract the DCE component, facility and status codes
689     */
690    facility_and_comp_code = (*status_code_p &
691        (FACILITY_CODE_MASK|COMPONENT_CODE_MASK));
692
693    status_code = (*status_code_p & STATUS_CODE_MASK)
694        >> STATUS_CODE_SHIFT;
695}
696
697/******************************************************************************/
698/*                                                                            */
699/*    Map to a DCE status code from the local status code format              */
700/*                                                                            */
701/******************************************************************************/
702void rpc_ss_map_local_to_dce_status
703(
704    error_status_t *status_code_p   /* [in,out] pointer to local status -> DCE status */
705)
706{
707	/* XXX todo? */
708}
709#endif /* IDL_ENABLE_STATUS_MAPPING */
710
711/******************************************************************************/
712/*                                                                            */
713/*    Convert contents of fault packet to exception                           */
714/*                                                                            */
715/******************************************************************************/
716static void rpc_ss_raise_arch_exception
717(
718    ndr_ulong_int fault_code,
719    RPC_SS_THREADS_CANCEL_STATE_T async_cancel_state
720)
721{
722    dcethread_exc *p_exception;
723
724    switch (fault_code) {
725        case nca_s_fault_context_mismatch:
726            p_exception = &rpc_x_ss_context_mismatch;
727            break;
728        case nca_s_fault_cancel:
729            p_exception = &RPC_SS_THREADS_X_CANCELLED;
730            break;
731        case nca_s_fault_addr_error:
732            p_exception = &dcethread_illaddr_e;
733            break;
734        case nca_s_fault_fp_div_zero:
735            p_exception = &dcethread_fltdiv_e;
736            break;
737        case nca_s_fault_fp_error:
738            p_exception = &dcethread_aritherr_e;
739            break;
740        case nca_s_fault_fp_overflow:
741            p_exception = &dcethread_fltovf_e;
742            break;
743        case nca_s_fault_fp_underflow:
744            p_exception = &dcethread_fltund_e;
745            break;
746        case nca_s_fault_ill_inst:
747            p_exception = &dcethread_illinstr_e;
748            break;
749        case nca_s_fault_int_div_by_zero:
750            p_exception = &dcethread_intdiv_e;
751            break;
752        case nca_s_fault_int_overflow:
753            p_exception = &dcethread_intovf_e;
754            break;
755        case nca_s_fault_invalid_bound:
756            p_exception = &rpc_x_invalid_bound;
757            break;
758        case nca_s_fault_invalid_tag:
759            p_exception = &rpc_x_invalid_tag;
760            break;
761        case nca_s_fault_pipe_closed:
762            p_exception = &rpc_x_ss_pipe_closed;
763            break;
764        case nca_s_fault_pipe_comm_error:
765            p_exception = &rpc_x_ss_pipe_comm_error;
766            break;
767        case nca_s_fault_pipe_discipline:
768            p_exception = &rpc_x_ss_pipe_discipline_error;
769            break;
770        case nca_s_fault_pipe_empty:
771            p_exception = &rpc_x_ss_pipe_empty;
772            break;
773        case nca_s_fault_pipe_memory:
774            p_exception = &rpc_x_ss_pipe_memory;
775            break;
776        case nca_s_fault_pipe_order:
777            p_exception = &rpc_x_ss_pipe_order;
778            break;
779        case nca_s_fault_remote_comm_failure:
780            p_exception = &rpc_x_ss_remote_comm_failure;
781            break;
782        case nca_s_fault_remote_no_memory:
783            p_exception = &rpc_x_ss_remote_no_memory;
784            break;
785        default:
786            p_exception = &rpc_x_unknown_remote_fault;
787            break;
788    }
789    RPC_SS_THREADS_RESTORE_ASYNC( async_cancel_state );
790    DCETHREAD_RAISE( *p_exception );
791}
792
793/******************************************************************************/
794/*                                                                            */
795/*    Convert contents of fault packet to local error code                    */
796/*                                                                            */
797/******************************************************************************/
798static error_status_t rpc_ss_map_fault_code
799(
800    ndr_ulong_int fault_code
801)
802{
803    switch (fault_code) {
804        case nca_s_fault_addr_error:
805            return( rpc_s_fault_addr_error );
806        case nca_s_fault_context_mismatch:
807            return( rpc_s_fault_context_mismatch );
808        case nca_s_fault_cancel:
809            return( rpc_s_call_cancelled );
810        case nca_s_fault_fp_div_zero:
811            return( rpc_s_fault_fp_div_by_zero );
812        case nca_s_fault_fp_error:
813            return( rpc_s_fault_fp_error );
814        case nca_s_fault_fp_overflow:
815            return( rpc_s_fault_fp_overflow );
816        case nca_s_fault_fp_underflow:
817            return( rpc_s_fault_fp_underflow );
818        case nca_s_fault_ill_inst:
819            return( rpc_s_fault_ill_inst );
820        case nca_s_fault_int_div_by_zero:
821            return( rpc_s_fault_int_div_by_zero );
822        case nca_s_fault_int_overflow:
823            return( rpc_s_fault_int_overflow );
824        case nca_s_fault_invalid_bound:
825            return( rpc_s_fault_invalid_bound );
826        case nca_s_fault_invalid_tag:
827            return( rpc_s_fault_invalid_tag );
828        case nca_s_fault_pipe_closed:
829            return( rpc_s_fault_pipe_closed );
830        case nca_s_fault_pipe_comm_error:
831            return( rpc_s_fault_pipe_comm_error );
832        case nca_s_fault_pipe_discipline:
833            return( rpc_s_fault_pipe_discipline );
834        case nca_s_fault_pipe_empty:
835            return( rpc_s_fault_pipe_empty );
836        case nca_s_fault_pipe_memory:
837            return( rpc_s_fault_pipe_memory );
838        case nca_s_fault_pipe_order:
839            return( rpc_s_fault_pipe_order );
840        case nca_s_fault_remote_comm_failure:
841            return( rpc_s_fault_remote_comm_failure );
842        case nca_s_fault_remote_no_memory:
843            return( rpc_s_fault_remote_no_memory );
844        case nca_s_fault_user_defined:
845            return(rpc_s_fault_user_defined);
846        default:
847            return( rpc_s_fault_unspec );
848    }
849}
850
851/******************************************************************************/
852/*                                                                            */
853/*    Convert error code to exception                                         */
854/*                                                                            */
855/******************************************************************************/
856static void rpc_ss_raise_impl_exception
857(
858    ndr_ulong_int result_code,
859    RPC_SS_THREADS_CANCEL_STATE_T async_cancel_state
860)
861{
862    dcethread_exc *p_exception;
863
864    switch (result_code) {
865        case rpc_s_assoc_grp_not_found:
866            p_exception = &rpc_x_assoc_grp_not_found;
867            break;
868        case rpc_s_call_timeout:
869            p_exception = &rpc_x_call_timeout;
870            break;
871        case rpc_s_cancel_timeout:
872            p_exception = &rpc_x_cancel_timeout;
873            break;
874        case rpc_s_coding_error:
875            p_exception = &rpc_x_coding_error;
876            break;
877        case rpc_s_comm_failure:
878            p_exception = &rpc_x_comm_failure;
879            break;
880        case rpc_s_context_id_not_found:
881            p_exception = &rpc_x_context_id_not_found;
882            break;
883        case rpc_s_endpoint_not_found:
884            p_exception = &rpc_x_endpoint_not_found;
885            break;
886        case rpc_s_in_args_too_big:
887            p_exception = &rpc_x_in_args_too_big;
888            break;
889        case rpc_s_invalid_binding:
890            p_exception = &rpc_x_invalid_binding;
891            break;
892        case rpc_s_invalid_call_opt:
893            p_exception = &rpc_x_invalid_call_opt;
894            break;
895        case rpc_s_invalid_naf_id:
896            p_exception = &rpc_x_invalid_naf_id;
897            break;
898        case rpc_s_invalid_rpc_protseq:
899            p_exception = &rpc_x_invalid_rpc_protseq;
900            break;
901        case rpc_s_invalid_timeout:
902            p_exception = &rpc_x_invalid_timeout;
903            break;
904        case rpc_s_manager_not_entered:
905            p_exception = &rpc_x_manager_not_entered;
906            break;
907        case rpc_s_max_descs_exceeded:
908            p_exception = &rpc_x_max_descs_exceeded;
909            break;
910        case rpc_s_no_fault:
911            p_exception = &rpc_x_no_fault;
912            break;
913        case rpc_s_no_memory:
914            p_exception = &rpc_x_no_memory;
915            break;
916        case rpc_s_not_rpc_tower:
917            p_exception = &rpc_x_not_rpc_tower;
918            break;
919        case rpc_s_object_not_found:
920            p_exception = &rpc_x_object_not_found;
921            break;
922        case rpc_s_op_rng_error:
923            p_exception = &rpc_x_op_rng_error;
924            break;
925        case rpc_s_protocol_error:
926            p_exception = &rpc_x_protocol_error;
927            break;
928        case rpc_s_protseq_not_supported:
929            p_exception = &rpc_x_protseq_not_supported;
930            break;
931        case rpc_s_rpcd_comm_failure:
932            p_exception = &rpc_x_rpcd_comm_failure;
933            break;
934        case rpc_s_unknown_if:
935            p_exception = &rpc_x_unknown_if;
936            break;
937        case rpc_s_unknown_mgr_type:
938            p_exception = &rpc_x_unknown_mgr_type;
939            break;
940        case rpc_s_unknown_reject:
941            p_exception = &rpc_x_unknown_reject;
942            break;
943        case rpc_s_unsupported_type:
944            p_exception = &rpc_x_unsupported_type;
945            break;
946        case rpc_s_who_are_you_failed:
947            p_exception = &rpc_x_who_are_you_failed;
948            break;
949        case rpc_s_wrong_boot_time:
950            p_exception = &rpc_x_wrong_boot_time;
951            break;
952        case rpc_s_wrong_kind_of_binding:
953            p_exception = &rpc_x_wrong_kind_of_binding;
954            break;
955        case uuid_s_getconf_failure:
956            p_exception = &uuid_x_getconf_failure;
957            break;
958        case uuid_s_internal_error:
959            p_exception = &uuid_x_internal_error;
960            break;
961         case uuid_s_no_address:
962            p_exception = &uuid_x_no_address;
963            break;
964        case uuid_s_socket_failure:
965            p_exception = &uuid_x_socket_failure;
966            break;
967       /* CN errors */
968        case rpc_s_access_control_info_inv:
969            p_exception = &rpc_x_access_control_info_inv;
970            break;
971        case rpc_s_assoc_grp_max_exceeded:
972            p_exception = &rpc_x_assoc_grp_max_exceeded;
973            break;
974        case rpc_s_assoc_shutdown:
975            p_exception = &rpc_x_assoc_shutdown;
976            break;
977        case rpc_s_cannot_accept:
978            p_exception = &rpc_x_cannot_accept;
979            break;
980        case rpc_s_cannot_connect:
981            p_exception = &rpc_x_cannot_connect;
982            break;
983        case rpc_s_cannot_set_nodelay:
984            p_exception = &rpc_x_cannot_set_nodelay;
985            break;
986        case rpc_s_cant_inq_socket:
987            p_exception = &rpc_x_cant_inq_socket;
988            break;
989        case rpc_s_connect_closed_by_rem:
990            p_exception = &rpc_x_connect_closed_by_rem;
991            break;
992        case rpc_s_connect_no_resources:
993            p_exception = &rpc_x_connect_no_resources;
994            break;
995        case rpc_s_connect_rejected:
996            p_exception = &rpc_x_connect_rejected;
997            break;
998        case rpc_s_connect_timed_out:
999            p_exception = &rpc_x_connect_timed_out;
1000            break;
1001        case rpc_s_connection_aborted:
1002            p_exception = &rpc_x_connection_aborted;
1003            break;
1004        case rpc_s_connection_closed:
1005            p_exception = &rpc_x_connection_closed;
1006            break;
1007        case rpc_s_host_unreachable:
1008            p_exception = &rpc_x_host_unreachable;
1009            break;
1010        case rpc_s_invalid_endpoint_format:
1011            p_exception = &rpc_x_invalid_endpoint_format;
1012            break;
1013        case rpc_s_loc_connect_aborted:
1014            p_exception = &rpc_x_loc_connect_aborted;
1015            break;
1016        case rpc_s_network_unreachable:
1017            p_exception = &rpc_x_network_unreachable;
1018            break;
1019        case rpc_s_no_rem_endpoint:
1020            p_exception = &rpc_x_no_rem_endpoint;
1021            break;
1022        case rpc_s_rem_host_crashed:
1023            p_exception = &rpc_x_rem_host_crashed;
1024            break;
1025        case rpc_s_rem_host_down:
1026            p_exception = &rpc_x_rem_host_down;
1027            break;
1028        case rpc_s_rem_network_shutdown:
1029            p_exception = &rpc_x_rem_network_shutdown;
1030            break;
1031        case rpc_s_rpc_prot_version_mismatch:
1032            p_exception = &rpc_x_rpc_prot_version_mismatch;
1033            break;
1034        case rpc_s_string_too_long:
1035            p_exception = &rpc_x_string_too_long;
1036            break;
1037        case rpc_s_too_many_rem_connects:
1038            p_exception = &rpc_x_too_many_rem_connects;
1039            break;
1040        case rpc_s_tsyntaxes_unsupported:
1041            p_exception = &rpc_x_tsyntaxes_unsupported;
1042            break;
1043        /* NS import routine errors */
1044        case rpc_s_binding_vector_full:
1045            p_exception = &rpc_x_binding_vector_full;
1046            break;
1047        case rpc_s_entry_not_found:
1048            p_exception = &rpc_x_entry_not_found;
1049            break;
1050        case rpc_s_group_not_found:
1051            p_exception = &rpc_x_group_not_found;
1052            break;
1053        case rpc_s_incomplete_name:
1054            p_exception = &rpc_x_incomplete_name;
1055            break;
1056        case rpc_s_invalid_arg:
1057            p_exception = &rpc_x_invalid_arg;
1058            break;
1059        case rpc_s_invalid_import_context:
1060            p_exception = &rpc_x_invalid_import_context;
1061            break;
1062        case rpc_s_invalid_inquiry_context:
1063            p_exception = &rpc_x_invalid_inquiry_context;
1064            break;
1065        case rpc_s_invalid_inquiry_type:
1066            p_exception = &rpc_x_invalid_inquiry_type;
1067            break;
1068        case rpc_s_invalid_lookup_context:
1069            p_exception = &rpc_x_invalid_lookup_context;
1070            break;
1071        case rpc_s_invalid_name_syntax:
1072            p_exception = &rpc_x_invalid_name_syntax;
1073            break;
1074        case rpc_s_invalid_object:
1075            p_exception = &rpc_x_invalid_object;
1076            break;
1077        case rpc_s_invalid_vers_option:
1078            p_exception = &rpc_x_invalid_vers_option;
1079            break;
1080        case rpc_s_name_service_unavailable:
1081            p_exception = &rpc_x_name_service_unavailable;
1082            break;
1083        case rpc_s_no_env_setup:
1084            p_exception = &rpc_x_no_env_setup;
1085            break;
1086        case rpc_s_no_more_bindings:
1087            p_exception = &rpc_x_no_more_bindings;
1088            break;
1089        case rpc_s_no_more_elements:
1090            p_exception = &rpc_x_no_more_elements;
1091            break;
1092        case rpc_s_no_ns_permission:
1093            p_exception = &rpc_x_no_ns_permission;
1094            break;
1095        case rpc_s_not_found:
1096            p_exception = &rpc_x_not_found;
1097            break;
1098        case rpc_s_not_rpc_entry:
1099            p_exception = &rpc_x_not_rpc_entry;
1100            break;
1101        case rpc_s_obj_uuid_not_found:
1102            p_exception = &rpc_x_obj_uuid_not_found;
1103            break;
1104        case rpc_s_profile_not_found:
1105            p_exception = &rpc_x_profile_not_found;
1106            break;
1107        case rpc_s_unsupported_name_syntax:
1108            p_exception = &rpc_x_unsupported_name_syntax;
1109            break;
1110        /* Authentication errors */
1111        case rpc_s_auth_bad_integrity:
1112            p_exception = &rpc_x_auth_bad_integrity;
1113            break;
1114        case rpc_s_auth_badaddr:
1115            p_exception = &rpc_x_auth_badaddr;
1116            break;
1117        case rpc_s_auth_baddirection:
1118            p_exception = &rpc_x_auth_baddirection;
1119            break;
1120        case rpc_s_auth_badkeyver:
1121            p_exception = &rpc_x_auth_badkeyver;
1122            break;
1123        case rpc_s_auth_badmatch:
1124            p_exception = &rpc_x_auth_badmatch;
1125            break;
1126        case rpc_s_auth_badorder:
1127            p_exception = &rpc_x_auth_badorder;
1128            break;
1129        case rpc_s_auth_badseq:
1130            p_exception = &rpc_x_auth_badseq;
1131            break;
1132        case rpc_s_auth_badversion:
1133            p_exception = &rpc_x_auth_badversion;
1134            break;
1135        case rpc_s_auth_field_toolong:
1136            p_exception = &rpc_x_auth_field_toolong;
1137            break;
1138        case rpc_s_auth_inapp_cksum:
1139            p_exception = &rpc_x_auth_inapp_cksum;
1140            break;
1141        case rpc_s_auth_method:
1142            p_exception = &rpc_x_auth_method;
1143            break;
1144        case rpc_s_auth_msg_type:
1145            p_exception = &rpc_x_auth_msg_type;
1146            break;
1147        case rpc_s_auth_modified:
1148            p_exception = &rpc_x_auth_modified;
1149            break;
1150        case rpc_s_auth_mut_fail:
1151            p_exception = &rpc_x_auth_mut_fail;
1152            break;
1153        case rpc_s_auth_nokey:
1154            p_exception = &rpc_x_auth_nokey;
1155            break;
1156        case rpc_s_auth_not_us:
1157            p_exception = &rpc_x_auth_not_us;
1158            break;
1159        case rpc_s_auth_repeat:
1160            p_exception = &rpc_x_auth_repeat;
1161            break;
1162        case rpc_s_auth_skew:
1163            p_exception = &rpc_x_auth_skew;
1164            break;
1165        case rpc_s_auth_tkt_expired:
1166            p_exception = &rpc_x_auth_tkt_expired;
1167            break;
1168        case rpc_s_auth_tkt_nyv:
1169            p_exception = &rpc_x_auth_tkt_nyv;
1170            break;
1171        case rpc_s_call_id_not_found:
1172            p_exception = &rpc_x_call_id_not_found;
1173            break;
1174        case rpc_s_credentials_too_large:
1175            p_exception = &rpc_x_credentials_too_large;
1176            break;
1177        case rpc_s_invalid_checksum:
1178            p_exception = &rpc_x_invalid_checksum;
1179            break;
1180        case rpc_s_invalid_crc:
1181            p_exception = &rpc_x_invalid_crc;
1182            break;
1183        case rpc_s_invalid_credentials:
1184            p_exception = &rpc_x_invalid_credentials;
1185            break;
1186        case rpc_s_key_id_not_found:
1187            p_exception = &rpc_x_key_id_not_found;
1188            break;
1189        /* Other pickling errors */
1190        case rpc_s_ss_bad_buffer:
1191            p_exception = &rpc_x_ss_bad_buffer;
1192            break;
1193        case rpc_s_ss_bad_es_action:
1194            p_exception = &rpc_x_ss_bad_es_action;
1195            break;
1196        case rpc_s_ss_wrong_es_version:
1197            p_exception = &rpc_x_ss_wrong_es_version;
1198            break;
1199        case rpc_s_ss_incompatible_codesets:
1200            p_exception = &rpc_x_ss_incompatible_codesets;
1201            break;
1202        case rpc_s_stub_protocol_error:
1203            p_exception = &rpc_x_stub_protocol_error;
1204            break;
1205        case rpc_s_unknown_stub_rtl_if_vers:
1206            p_exception = &rpc_x_unknown_stub_rtl_if_vers;
1207            break;
1208        default:
1209            {
1210            dcethread_exc unknown_status_exception;
1211            DCETHREAD_EXC_INIT(unknown_status_exception);
1212            dcethread_exc_setstatus(&unknown_status_exception, result_code);
1213            RPC_SS_THREADS_RESTORE_ASYNC( async_cancel_state );
1214            DCETHREAD_RAISE( unknown_status_exception );
1215            break;
1216            }
1217    }
1218    RPC_SS_THREADS_RESTORE_ASYNC( async_cancel_state );
1219    DCETHREAD_RAISE( *p_exception );
1220}
1221
1222#ifdef MIA
1223/******************************************************************************/
1224/*                                                                            */
1225/*    Report error status to the caller                                       */
1226/*    New version - user exceptions                                           */
1227/*                                                                            */
1228/******************************************************************************/
1229void rpc_ss_report_error_2
1230(
1231    ndr_ulong_int fault_code,
1232    ndr_ulong_int user_fault_id,
1233    ndr_ulong_int result_code,
1234    RPC_SS_THREADS_CANCEL_STATE_T *p_async_cancel_state,
1235    error_status_t *p_comm_status,
1236    error_status_t *p_fault_status,
1237    dcethread_exc *user_exception_pointers[],
1238    IDL_msp_t IDL_msp ATTRIBUTE_UNUSED
1239)
1240{
1241    if (p_comm_status != NULL) *p_comm_status = error_status_ok;
1242    if (p_fault_status != NULL) *p_fault_status = error_status_ok;
1243
1244    if (fault_code != error_status_ok)
1245    {
1246        if ( p_fault_status == NULL )
1247        {
1248            if (fault_code == nca_s_fault_user_defined)
1249            {
1250                RPC_SS_THREADS_RESTORE_ASYNC( *p_async_cancel_state );
1251                DCETHREAD_RAISE( *(user_exception_pointers[user_fault_id]) );
1252            }
1253            rpc_ss_raise_arch_exception( fault_code, *p_async_cancel_state );
1254        }
1255        else
1256        {
1257            *p_fault_status = rpc_ss_map_fault_code( fault_code );
1258            return;
1259        }
1260    }
1261    else if (result_code != error_status_ok)
1262    {
1263        if ( p_comm_status == NULL )
1264            rpc_ss_raise_impl_exception( result_code, *p_async_cancel_state );
1265        else
1266        {
1267            *p_comm_status = result_code;
1268            return;
1269        }
1270    }
1271}
1272#endif
1273
1274/******************************************************************************/
1275/*                                                                            */
1276/*    Report error status to the caller                                       */
1277/*    Old version - no user exceptions                                        */
1278/*                                                                            */
1279/******************************************************************************/
1280void rpc_ss_report_error
1281(
1282    ndr_ulong_int fault_code,
1283    ndr_ulong_int result_code,
1284    RPC_SS_THREADS_CANCEL_STATE_T async_cancel_state,
1285    error_status_t *p_comm_status,
1286    error_status_t *p_fault_status
1287)
1288{
1289    rpc_ss_report_error_2(fault_code, 0, result_code, &async_cancel_state,
1290                            p_comm_status, p_fault_status, NULL, NULL);
1291}
1292
1293/******************************************************************************/
1294/*                                                                            */
1295/*  If there is a fault, get the fault packet. Then end the call              */
1296/*  New interface - user exceptions                                           */
1297/*                                                                            */
1298/******************************************************************************/
1299void rpc_ss_call_end_2
1300(
1301    volatile rpc_call_handle_t *p_call_h,
1302    volatile ndr_ulong_int *p_fault_code,
1303    volatile ndr_ulong_int *p_user_fault_id,
1304    volatile error_status_t *p_st
1305)
1306{
1307    rpc_iovector_elt_t iovec_elt;
1308    ndr_format_t drep;
1309    error_status_t status;
1310    rpc_mp_t mp;
1311
1312/*    *p_fault_code = error_status_ok; Initialization done by stub */
1313    if ( *p_st == rpc_s_call_faulted )
1314    {
1315        rpc_call_receive_fault((rpc_call_handle_t)*p_call_h, &iovec_elt, &drep,
1316                                 &status );
1317        if (status == error_status_ok)
1318        {
1319            rpc_init_mp(mp, iovec_elt.data_addr);
1320            rpc_convert_ulong_int(drep, ndr_g_local_drep, mp, (*p_fault_code));
1321            if (*p_fault_code == nca_s_fault_user_defined)
1322            {
1323                rpc_advance_mp(mp, 4);  /* Next longword represents user
1324                                                                    exception */
1325                rpc_convert_ulong_int(drep, ndr_g_local_drep, mp,
1326                                                    (*p_user_fault_id));
1327            }
1328            if (iovec_elt.buff_dealloc != NULL)
1329            {
1330                (*iovec_elt.buff_dealloc)(iovec_elt.buff_addr);
1331                iovec_elt.buff_dealloc = NULL;
1332            }
1333
1334            /*
1335             * Remote comm failures are reported by a fault packet.  However,
1336             * we want to treat them in the same way as a local comm failure,
1337             * not as a fault.  We do the translation here.
1338             */
1339            if (*p_fault_code == nca_s_fault_remote_comm_failure)
1340            {
1341                *p_st = rpc_s_fault_remote_comm_failure;
1342                *p_fault_code = error_status_ok;
1343            }
1344        }
1345        else *p_st = status;
1346    }
1347    if ( *p_call_h != NULL )
1348    {
1349        rpc_call_end( (rpc_call_handle_t*) p_call_h, &status);
1350        /* Don't destroy any existing error code with the value from call end */
1351        if ( *p_st == error_status_ok ) *p_st = status;
1352    }
1353}
1354
1355/******************************************************************************/
1356/*                                                                            */
1357/*  If there is a fault, get the fault packet. Then end the call              */
1358/*  Old interface - no user exceptions                                        */
1359/*                                                                            */
1360/******************************************************************************/
1361void rpc_ss_call_end
1362(
1363    volatile rpc_call_handle_t *p_call_h,
1364    volatile ndr_ulong_int *p_fault_code,
1365    volatile error_status_t *p_st
1366)
1367{
1368    ndr_ulong_int user_fault_id;    /* Discarded argument */
1369
1370    rpc_ss_call_end_2(p_call_h, p_fault_code, &user_fault_id, p_st);
1371}
1372
1373/******************************************************************************/
1374/*                                                                            */
1375/*  Optimization support routine - change receive buffer                      */
1376/*                                                                            */
1377/******************************************************************************/
1378void rpc_ss_new_recv_buff
1379(
1380    rpc_iovector_elt_t *elt,
1381    rpc_call_handle_t call_h,
1382    rpc_mp_t *p_mp,
1383    volatile error_status_t *st
1384)
1385{
1386    if (elt->buff_dealloc && (elt->data_len != 0))
1387    {
1388        (*elt->buff_dealloc)(elt->buff_addr);
1389        elt->buff_dealloc = NULL;
1390    }
1391
1392    rpc_call_receive(call_h, elt, (unsigned32*)st);
1393    if (*st == error_status_ok)
1394    {
1395        if (elt->data_addr != NULL)
1396        {
1397            rpc_init_mp((*p_mp), elt->data_addr);
1398            return;
1399        }
1400        else
1401            *st = rpc_s_stub_protocol_error;
1402    }
1403    {
1404        /* If cancelled, raise the cancelled exception */
1405        if (*st==rpc_s_call_cancelled) DCETHREAD_RAISE(RPC_SS_THREADS_X_CANCELLED);
1406
1407        /*
1408         *  Otherwise, raise the pipe comm error which causes the stub to
1409         *  report the value of the status variable.
1410         */
1411        DCETHREAD_RAISE(rpc_x_ss_pipe_comm_error);
1412    }
1413}
1414