SupportMisc.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT_SUPPORTMISC_H_
00014 #define _SUPPORT_SUPPORTMISC_H_
00015 
00016 #include <support/SupportDefs.h>
00017 #include <support/IBinder.h>
00018 #include <support/IMemory.h>
00019 #include <support/KeyedVector.h>
00020 #include <support/Locker.h>
00021 
00022 #include <support/StaticValue.h>
00023 
00024 // value_small_data and value_large_data are defined here.
00025 #include <support_p/ValueMapFormat.h>
00026 
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #if TARGET_HOST == TARGET_HOST_PALMOS
00031 #include <Kernel.h>
00032 #endif
00033 
00034 #include <SysThreadConcealed.h>
00035 
00036 #if _SUPPORTS_NAMESPACE
00037 namespace palmos {
00038 namespace support {
00039 #endif
00040 
00041 enum {
00042     kPackedSmallAtomType = B_PACK_SMALL_TYPE(B_ATOM_TYPE, sizeof(void*)),
00043     kPackedSmallAtomWeakType = B_PACK_SMALL_TYPE(B_ATOM_WEAK_TYPE, sizeof(void*)),
00044     kPackedSmallBinderType = B_PACK_SMALL_TYPE(B_BINDER_TYPE, sizeof(void*)),
00045     kPackedSmallBinderWeakType = B_PACK_SMALL_TYPE(B_BINDER_WEAK_TYPE, sizeof(void*)),
00046     kPackedSmallBinderHandleType = B_PACK_SMALL_TYPE(B_BINDER_HANDLE_TYPE, sizeof(void*)),
00047     kPackedSmallBinderWeakHandleType = B_PACK_SMALL_TYPE(B_BINDER_WEAK_HANDLE_TYPE, sizeof(void*)),
00048 };
00049 
00050 // optimization for gcc
00051 #if (defined(__GNUC__) && (__GNUC__ < 3) && !defined(__CC_ARM))
00052 #define DECLARE_RETURN(x) return x
00053 #else
00054 #define DECLARE_RETURN(x)
00055 #endif
00056 
00057 // SLooper/BProcess startup and shutdown.
00058 #if !LIBBE_BOOTSTRAP
00059 void __initialize_looper(void);
00060 void __stop_looper(void);
00061 void __terminate_looper(void);
00062 #endif
00063 
00064 // Low-level locking primitive.
00065 void dbg_init_gehnaphore(volatile int32_t* value);
00066 void dbg_lock_gehnaphore(volatile int32_t* value);
00067 void dbg_unlock_gehnaphore(volatile int32_t* value);
00068 
00069 // Cleanup helpers.
00070 typedef void (*binder_cleanup_func)();
00071 void add_binder_cleanup_func(binder_cleanup_func func);
00072 void rem_binder_cleanup_func(binder_cleanup_func func);
00073 void call_binder_cleanup_funcs();
00074 
00075 // Syslog madness.
00076 void enable_thread_syslog();
00077 void disable_thread_syslog();
00078 extern int32_t g_syslogTLS;
00079 
00080 // -------------------------------------------------------------------
00081 // These are for objects stored in SValues, where we want
00082 // to use less space (8 bytes instead of 16), so we can store the
00083 // data inline in the SValue.
00084 
00085 // Generic acquire and release of objects.
00086 void acquire_object(const small_flat_data& obj, const void* who);
00087 void release_object(const small_flat_data& obj, const void* who);
00088 
00089 #if defined(SUPPORTS_ATOM_DEBUG) && SUPPORTS_ATOM_DEBUG
00090 void rename_object(const small_flat_data& obj, const void* newWho, const void* oldWho);
00091 #else
00092 inline void rename_object(const small_flat_data&, const void*, const void*) { }
00093 #endif
00094 
00095 void flatten_binder(const sptr<IBinder>& binder, small_flat_data* out);
00096 void flatten_binder(const wptr<IBinder>& binder, small_flat_data* out);
00097 status_t unflatten_binder(const small_flat_data& flat, sptr<IBinder>* out);
00098 status_t unflatten_binder(const small_flat_data& flat, wptr<IBinder>* out);
00099 
00100 // -------------------------------------------------------------------
00101 // These are for objects stored in an SParcel, where we need
00102 // to have 8 bytes of data to store both the IBinder address and
00103 // SAtom address (cookie) for correct interaction with the driver.
00104 
00105 struct flat_binder_object;  // defined in support_p/binder_module.h
00106 
00107 // Generic acquire and release of objects.
00108 void acquire_object(const flat_binder_object& obj, const void* who);
00109 void release_object(const flat_binder_object& obj, const void* who);
00110 
00111 void flatten_binder(const sptr<IBinder>& binder, flat_binder_object* out);
00112 void flatten_binder(const wptr<IBinder>& binder, flat_binder_object* out);
00113 status_t unflatten_binder(const flat_binder_object& flat, sptr<IBinder>* out);
00114 status_t unflatten_binder(const flat_binder_object& flat, wptr<IBinder>* out);
00115 
00116 // -------------------------------------------------------------------
00117 // Stuff for Memory.cpp, which must be located in Static.cpp to
00118 // get correct ordering of static constructors/destructors.
00119 
00120 struct area_translation_info
00121 {
00122     sptr<IMemoryHeap>   heap;
00123     int32_t             count;
00124 };
00125 
00126 #if _SUPPORTS_NAMESPACE
00127 } } // namespace palmos::support
00128 #endif
00129 
00130 #if _SUPPORTS_NAMESPACE
00131 namespace palmos {
00132 namespace osp {
00133 using namespace palmos::support;
00134 #endif
00135 
00136 extern SKeyedVector<sptr<IBinder>, area_translation_info> gAreaTranslationCache;
00137 extern SLocker gAreaTranslationLock;
00138 
00139 #if _SUPPORTS_NAMESPACE
00140 } } // namespace palmos::osp
00141 #endif
00142 
00143 
00144 #if _SUPPORTS_NAMESPACE
00145 namespace palmos {
00146 namespace support {
00147 #endif
00148 
00149 void __terminate_shared_buffer(void);
00150 
00151 // Static objects for Parcel.cpp.
00152 extern SLocker  g_parcel_pool_lock;
00153 
00154 struct parcel_pool_cleanup {
00155     parcel_pool_cleanup();
00156     ~parcel_pool_cleanup();
00157 };
00158 extern parcel_pool_cleanup g_parcel_pool_cleanup;
00159 
00160 extern sysThreadDirectFuncs g_threadDirectFuncs;
00161 
00162 #if _SUPPORTS_NAMESPACE
00163 } } // namespace palmos::support
00164 #endif
00165 
00166 #endif  /* _SUPPORT_SUPPORTMISC_H_ */