From 429fc2d45a2ab183d1b61a2c23c2225a63afbdce Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Thu, 9 Aug 2007 22:10:55 +0000 Subject: [PATCH] pull up r19624 from trunk r19624@cathode-dark-space: jaltman | 2007-06-22 14:54:49 -0400 ticket: 5584 . Fix formatting in kherr.c 2. The FormatMessage() call needs special handling for 64 bit platforms. Add a compile time check for now until we figure out what to do. 3. Remove unused code from kherr.c. 4. Correct bad references to typedefs. kherr_severity and kherr_suggestion were sometimes referenced as 'enum kherr_severity' and 'enum kherr_suggestion' even though they are typedefs. ticket: 5584 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@19782 dc483132-0cff-0310-8789-dd5450dbe970 --- src/windows/identity/kherr/kherr.c | 268 ++++++++++++++++++++--------- src/windows/identity/kherr/kherr.h | 8 +- 2 files changed, 186 insertions(+), 90 deletions(-) diff --git a/src/windows/identity/kherr/kherr.c b/src/windows/identity/kherr/kherr.c index ec83f3895..e4435e5fc 100644 --- a/src/windows/identity/kherr/kherr.c +++ b/src/windows/identity/kherr/kherr.c @@ -44,7 +44,9 @@ kherr_serial ctx_serial = 0; #ifdef DEBUG #define DEBUG_CONTEXT -KHMEXP void kherr_debug_printf(wchar_t * fmt, ...) { +KHMEXP void +kherr_debug_printf(wchar_t * fmt, ...) +{ va_list vl; wchar_t buf[1024]; @@ -55,10 +57,11 @@ KHMEXP void kherr_debug_printf(wchar_t * fmt, ...) { } #endif -KHMEXP void KHMAPI kherr_add_ctx_handler(kherr_ctx_handler h, - khm_int32 filter, - kherr_serial serial) { - +KHMEXP void KHMAPI +kherr_add_ctx_handler(kherr_ctx_handler h, + khm_int32 filter, + kherr_serial serial) +{ khm_size idx; assert(h); @@ -111,8 +114,10 @@ KHMEXP void KHMAPI kherr_add_ctx_handler(kherr_ctx_handler h, LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_remove_ctx_handler(kherr_ctx_handler h, - kherr_serial serial) { +KHMEXP void KHMAPI +kherr_remove_ctx_handler(kherr_ctx_handler h, + kherr_serial serial) +{ khm_size i; EnterCriticalSection(&cs_error); @@ -134,7 +139,9 @@ KHMEXP void KHMAPI kherr_remove_ctx_handler(kherr_ctx_handler h, } /* Called with cs_error held */ -void notify_ctx_event(enum kherr_ctx_event e, kherr_context * c) { +static void +notify_ctx_event(enum kherr_ctx_event e, kherr_context * c) +{ khm_size i; kherr_ctx_handler h; @@ -166,7 +173,9 @@ void notify_ctx_event(enum kherr_ctx_event e, kherr_context * c) { } } -void attach_this_thread(void) { +void +attach_this_thread(void) +{ kherr_thread * t; t = (kherr_thread *) TlsGetValue(tls_error); @@ -182,7 +191,9 @@ void attach_this_thread(void) { TlsSetValue(tls_error, t); } -void detach_this_thread(void) { +void +detach_this_thread(void) +{ kherr_thread * t; khm_size i; @@ -196,7 +207,9 @@ void detach_this_thread(void) { } } -kherr_context * peek_context(void) { +static kherr_context * +peek_context(void) +{ kherr_thread * t; t = (kherr_thread *) TlsGetValue(tls_error); @@ -216,7 +229,9 @@ kherr_context * peek_context(void) { return NULL; } -void push_context(kherr_context * c) { +static void +push_context(kherr_context * c) +{ kherr_thread * t; t = (kherr_thread *) TlsGetValue(tls_error); @@ -253,7 +268,9 @@ void push_context(kherr_context * c) { } /* returned pointer is still held */ -kherr_context * pop_context(void) { +static kherr_context * +pop_context(void) +{ kherr_thread * t; kherr_context * c; @@ -270,7 +287,9 @@ kherr_context * pop_context(void) { } } -kherr_event * get_empty_event(void) { +static kherr_event * +get_empty_event(void) +{ kherr_event * e; EnterCriticalSection(&cs_error); @@ -287,8 +306,11 @@ kherr_event * get_empty_event(void) { return e; } -void free_event_params(kherr_event * e) { +static void +free_event_params(kherr_event * e) +{ assert(IS_KHERR_EVENT(e)); + if(parm_type(e->p1) == KEPT_STRINGT) { assert((void *) parm_data(e->p1)); PFREE((void*) parm_data(e->p1)); @@ -311,8 +333,9 @@ void free_event_params(kherr_event * e) { } } -void free_event(kherr_event * e) { - +static void +free_event(kherr_event * e) +{ EnterCriticalSection(&cs_error); assert(IS_KHERR_EVENT(e)); @@ -352,7 +375,9 @@ void free_event(kherr_event * e) { LeaveCriticalSection(&cs_error); } -kherr_context * get_empty_context(void) { +static kherr_context * +get_empty_context(void) +{ kherr_context * c; EnterCriticalSection(&cs_error); @@ -378,7 +403,9 @@ kherr_context * get_empty_context(void) { /* Assumes that the context has been deleted from all relevant lists */ -void free_context(kherr_context * c) { +static void +free_context(kherr_context * c) +{ kherr_context * ch; kherr_event * e; @@ -415,7 +442,8 @@ void free_context(kherr_context * c) { #endif } -void add_event(kherr_context * c, kherr_event * e) +static void +add_event(kherr_context * c, kherr_event * e) { kherr_event * te; @@ -441,7 +469,8 @@ void add_event(kherr_context * c, kherr_event * e) LeaveCriticalSection(&cs_error); } -void pick_err_event(kherr_context * c) +static void +pick_err_event(kherr_context * c) { kherr_event * e; kherr_event * ce = NULL; @@ -472,7 +501,9 @@ void pick_err_event(kherr_context * c) LeaveCriticalSection(&cs_error); } -static void arg_from_param(DWORD_PTR ** parm, kherr_param p) { +static void +arg_from_param(DWORD_PTR ** parm, kherr_param p) +{ int t; if (p.type != KEPT_NONE) { @@ -486,7 +517,7 @@ static void arg_from_param(DWORD_PTR ** parm, kherr_param p) { *(*parm)++ = (DWORD_PTR) parm_data(p); } else if (t == KEPT_INT64 || - t == KEPT_UINT64) { + t == KEPT_UINT64) { *(*parm)++ = (DWORD_PTR) parm_data(p) & 0xffffffff; *(*parm)++ = (DWORD_PTR) (parm_data(p) >> 32) & 0xffffffff; } else @@ -495,17 +526,25 @@ static void arg_from_param(DWORD_PTR ** parm, kherr_param p) { } /* The 'buf' parameter MUST point to a DWORD_PTR[8] array */ -static void args_from_event(DWORD_PTR * buf, kherr_event * e) { +static void +args_from_event(DWORD_PTR * buf, kherr_event * e) +{ arg_from_param(&buf, e->p1); arg_from_param(&buf, e->p2); arg_from_param(&buf, e->p3); arg_from_param(&buf, e->p4); } -static void resolve_string_resource(kherr_event * e, - const wchar_t ** str, - khm_int32 if_flag, - khm_int32 or_flag) { +#ifdef _WIN64 +# error resolve_string_resource() does not work on 64 bit architectures +#endif + +static void +resolve_string_resource(kherr_event * e, + const wchar_t ** str, + khm_int32 if_flag, + khm_int32 or_flag) +{ wchar_t tfmt[KHERR_MAXCCH_STRING]; wchar_t tbuf[KHERR_MAXCCH_STRING]; size_t chars = 0; @@ -547,10 +586,16 @@ static void resolve_string_resource(kherr_event * e, } } -static void resolve_msg_resource(kherr_event * e, - const wchar_t ** str, - khm_int32 if_flag, - khm_int32 or_flag) { +#ifdef _WIN64 +# error resolve_msg_resource() does not work on 64 bit architectures +#endif + +static void +resolve_msg_resource(kherr_event * e, + const wchar_t ** str, + khm_int32 if_flag, + khm_int32 or_flag) +{ wchar_t tbuf[KHERR_MAXCCH_STRING]; size_t chars = 0; size_t bytes = 0; @@ -595,12 +640,17 @@ static void resolve_msg_resource(kherr_event * e, } } -static void resolve_string(kherr_event * e, - const wchar_t ** str, - khm_int32 mask, - khm_int32 free_if, - khm_int32 or_flag) { +#ifdef _WIN64 +# error resolve_string() does not work on 64 bit architectures +#endif +static void +resolve_string(kherr_event * e, + const wchar_t ** str, + khm_int32 mask, + khm_int32 free_if, + khm_int32 or_flag) +{ wchar_t tbuf[KHERR_MAXCCH_STRING]; size_t chars; size_t bytes; @@ -642,7 +692,8 @@ static void resolve_string(kherr_event * e, } -void resolve_event_strings(kherr_event * e) +void +resolve_event_strings(kherr_event * e) { resolve_string(e, &e->short_desc, KHERR_RFMASK_SHORT_DESC, @@ -692,7 +743,9 @@ void resolve_event_strings(kherr_event * e) } -KHMEXP void KHMAPI kherr_evaluate_event(kherr_event * e) { +KHMEXP void KHMAPI +kherr_evaluate_event(kherr_event * e) +{ if (!IS_KHERR_EVENT(e)) return; @@ -701,7 +754,9 @@ KHMEXP void KHMAPI kherr_evaluate_event(kherr_event * e) { LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_evaluate_last_event(void) { +KHMEXP void KHMAPI +kherr_evaluate_last_event(void) +{ kherr_context * c; kherr_event * e; DWORD tid; @@ -726,7 +781,8 @@ KHMEXP void KHMAPI kherr_evaluate_last_event(void) { } KHMEXP kherr_event * __cdecl -kherr_reportf(const wchar_t * long_desc_fmt, ...) { +kherr_reportf(const wchar_t * long_desc_fmt, ...) +{ va_list vl; wchar_t buf[1024]; kherr_event * e; @@ -760,7 +816,8 @@ kherr_reportf_ex(enum kherr_severity severity, #ifdef _WIN32 HMODULE hModule, #endif - const wchar_t * long_desc_fmt, ...) { + const wchar_t * long_desc_fmt, ...) +{ va_list vl; wchar_t buf[1024]; kherr_event * e; @@ -806,11 +863,17 @@ kherr_report(enum kherr_severity severity, #ifdef _WIN32 ,HMODULE h_module #endif - ) { + ) +{ kherr_context * c; kherr_event * e; + khm_boolean invalid = FALSE; - /*TODO: sanity check flags (ISPOW2) */ + /* sanity check */ + if (!IS_POW2(flags & KHERR_RFMASK_SHORT_DESC) || + !IS_POW2(flags & KHERR_RFMASK_LONG_DESC) || + !IS_POW2(flags & KHERR_RFMASK_SUGGEST)) + invalid = TRUE; e = get_empty_event(); @@ -838,7 +901,7 @@ kherr_report(enum kherr_severity severity, EnterCriticalSection(&cs_error); c = peek_context(); - if(!c) { + if(!c || invalid) { /* the reason why we are doing it this way is because p1..p4, the descriptions and the suggestion may contain allocations that has to be freed. */ @@ -853,9 +916,11 @@ kherr_report(enum kherr_severity severity, return e; } -KHMEXP void KHMAPI kherr_suggest(wchar_t * suggestion, - enum kherr_suggestion suggestion_id, - khm_int32 flags) { +KHMEXP void KHMAPI +kherr_suggest(wchar_t * suggestion, + enum kherr_suggestion suggestion_id, + khm_int32 flags) +{ kherr_context * c; kherr_event * e; DWORD tid; @@ -894,7 +959,9 @@ _exit: LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_location(wchar_t * location) { +KHMEXP void KHMAPI +kherr_location(wchar_t * location) +{ kherr_context * c; kherr_event * e; DWORD tid; @@ -916,8 +983,10 @@ _exit: LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_facility(wchar_t * facility, - khm_int32 facility_id) { +KHMEXP void KHMAPI +kherr_facility(wchar_t * facility, + khm_int32 facility_id) +{ kherr_context * c; kherr_event * e; DWORD tid; @@ -939,7 +1008,9 @@ _exit: LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_set_desc_event(void) { +KHMEXP void KHMAPI +kherr_set_desc_event(void) +{ kherr_context * c; kherr_event * e; DWORD tid; @@ -968,7 +1039,9 @@ _exit: LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_del_last_event(void) { +KHMEXP void KHMAPI +kherr_del_last_event(void) +{ kherr_context * c; kherr_event * e; DWORD tid; @@ -995,7 +1068,8 @@ KHMEXP void KHMAPI kherr_del_last_event(void) { LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_push_context(kherr_context * c) +KHMEXP void KHMAPI +kherr_push_context(kherr_context * c) { kherr_context * p = NULL; int new_context = FALSE; @@ -1022,7 +1096,8 @@ KHMEXP void KHMAPI kherr_push_context(kherr_context * c) LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_push_new_context(khm_int32 flags) +KHMEXP void KHMAPI +kherr_push_new_context(khm_int32 flags) { kherr_context * p = NULL; kherr_context * c; @@ -1049,7 +1124,9 @@ KHMEXP void KHMAPI kherr_push_new_context(khm_int32 flags) LeaveCriticalSection(&cs_error); } -kherr_param dup_parm(kherr_param p) { +static kherr_param +dup_parm(kherr_param p) +{ if(parm_type(p) == KEPT_STRINGT) { wchar_t * d = PWCSDUP((wchar_t *)parm_data(p)); return kherr_val(KEPT_STRINGT, (khm_ui_8) d); @@ -1057,7 +1134,9 @@ kherr_param dup_parm(kherr_param p) { return p; } -kherr_event * fold_context(kherr_context * c) { +static kherr_event * +fold_context(kherr_context * c) +{ kherr_event * e; kherr_event * g; @@ -1097,16 +1176,20 @@ kherr_event * fold_context(kherr_context * c) { return e; } -KHMEXP void KHMAPI kherr_hold_context(kherr_context * c) { - +KHMEXP void KHMAPI +kherr_hold_context(kherr_context * c) +{ if(!IS_KHERR_CTX(c)) return; + EnterCriticalSection(&cs_error); c->refcount++; LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_release_context(kherr_context * c) { +KHMEXP void KHMAPI +kherr_release_context(kherr_context * c) +{ if (!IS_KHERR_CTX(c)) return; @@ -1143,7 +1226,9 @@ KHMEXP void KHMAPI kherr_release_context(kherr_context * c) { LeaveCriticalSection(&cs_error); } -KHMEXP void KHMAPI kherr_pop_context(void) { +KHMEXP void KHMAPI +kherr_pop_context(void) +{ kherr_context * c; EnterCriticalSection(&cs_error); @@ -1154,7 +1239,9 @@ KHMEXP void KHMAPI kherr_pop_context(void) { LeaveCriticalSection(&cs_error); } -KHMEXP kherr_context * KHMAPI kherr_peek_context(void) { +KHMEXP kherr_context * KHMAPI +kherr_peek_context(void) +{ kherr_context * c; c = peek_context(); @@ -1164,25 +1251,33 @@ KHMEXP kherr_context * KHMAPI kherr_peek_context(void) { return c; } -KHMEXP khm_boolean KHMAPI kherr_is_error(void) { +KHMEXP khm_boolean KHMAPI +kherr_is_error(void) +{ kherr_context * c = peek_context(); return kherr_is_error_i(c); } -KHMEXP khm_boolean KHMAPI kherr_is_error_i(kherr_context * c) { +KHMEXP khm_boolean KHMAPI +kherr_is_error_i(kherr_context * c) +{ if(IS_KHERR_CTX(c) && c->severity <= KHERR_ERROR) return TRUE; else return FALSE; } -KHMEXP void KHMAPI kherr_clear_error(void) { +KHMEXP void KHMAPI +kherr_clear_error(void) +{ kherr_context * c = peek_context(); if (IS_KHERR_CTX(c)) kherr_clear_error_i(c); } -KHMEXP void KHMAPI kherr_clear_error_i(kherr_context * c) { +KHMEXP void KHMAPI +kherr_clear_error_i(kherr_context * c) +{ kherr_event * e; if (IS_KHERR_CTX(c)) { EnterCriticalSection(&cs_error); @@ -1237,7 +1332,9 @@ kherr_set_progress(khm_ui_4 num, khm_ui_4 denom) } } -KHMEXP void KHMAPI kherr_get_progress(khm_ui_4 * num, khm_ui_4 * denom) { +KHMEXP void KHMAPI +kherr_get_progress(khm_ui_4 * num, khm_ui_4 * denom) +{ kherr_context * c = peek_context(); kherr_get_progress_i(c,num,denom); } @@ -1304,7 +1401,8 @@ kherr_get_progress_i(kherr_context * c, } } -KHMEXP kherr_event * KHMAPI kherr_get_first_event(kherr_context * c) +KHMEXP kherr_event * KHMAPI +kherr_get_first_event(kherr_context * c) { kherr_event * e; @@ -1318,7 +1416,8 @@ KHMEXP kherr_event * KHMAPI kherr_get_first_event(kherr_context * c) return e; } -KHMEXP kherr_event * KHMAPI kherr_get_next_event(kherr_event * e) +KHMEXP kherr_event * KHMAPI +kherr_get_next_event(kherr_event * e) { kherr_event * ee; @@ -1332,7 +1431,8 @@ KHMEXP kherr_event * KHMAPI kherr_get_next_event(kherr_event * e) return ee; } -KHMEXP kherr_event * KHMAPI kherr_get_prev_event(kherr_event * e) +KHMEXP kherr_event * KHMAPI +kherr_get_prev_event(kherr_event * e) { kherr_event * ee; @@ -1346,7 +1446,8 @@ KHMEXP kherr_event * KHMAPI kherr_get_prev_event(kherr_event * e) return ee; } -KHMEXP kherr_event * KHMAPI kherr_get_last_event(kherr_context * c) +KHMEXP kherr_event * KHMAPI +kherr_get_last_event(kherr_context * c) { kherr_event * e; @@ -1360,7 +1461,8 @@ KHMEXP kherr_event * KHMAPI kherr_get_last_event(kherr_context * c) return e; } -KHMEXP kherr_context * KHMAPI kherr_get_first_context(kherr_context * c) +KHMEXP kherr_context * KHMAPI +kherr_get_first_context(kherr_context * c) { kherr_context * cc; @@ -1382,7 +1484,8 @@ KHMEXP kherr_context * KHMAPI kherr_get_first_context(kherr_context * c) return cc; } -KHMEXP kherr_context * KHMAPI kherr_get_next_context(kherr_context * c) +KHMEXP kherr_context * KHMAPI +kherr_get_next_context(kherr_context * c) { kherr_context * cc; @@ -1398,7 +1501,8 @@ KHMEXP kherr_context * KHMAPI kherr_get_next_context(kherr_context * c) return cc; } -KHMEXP kherr_event * KHMAPI kherr_get_err_event(kherr_context * c) +KHMEXP kherr_event * KHMAPI +kherr_get_err_event(kherr_context * c) { kherr_event * e; @@ -1415,7 +1519,8 @@ KHMEXP kherr_event * KHMAPI kherr_get_err_event(kherr_context * c) return e; } -KHMEXP kherr_event * KHMAPI kherr_get_desc_event(kherr_context * c) +KHMEXP kherr_event * KHMAPI +kherr_get_desc_event(kherr_context * c) { kherr_event * e; @@ -1429,7 +1534,8 @@ KHMEXP kherr_event * KHMAPI kherr_get_desc_event(kherr_context * c) return e; } -KHMEXP kherr_param kherr_dup_string(const wchar_t * s) +KHMEXP kherr_param +kherr_dup_string(const wchar_t * s) { wchar_t * dest; size_t cb_s; @@ -1451,13 +1557,3 @@ KHMEXP kherr_param kherr_dup_string(const wchar_t * s) return _tstr(dest); } - -#if 0 -KHMEXP kherr_param kherr_val(khm_octet ptype, khm_ui_8 pvalue) { - kherr_param p; - p.type = ptype; - p.data = pvalue; - - return p; -} -#endif diff --git a/src/windows/identity/kherr/kherr.h b/src/windows/identity/kherr/kherr.h index d792c6068..a74664d98 100644 --- a/src/windows/identity/kherr/kherr.h +++ b/src/windows/identity/kherr/kherr.h @@ -362,7 +362,7 @@ enum kherr_context_flags { threads whose current error context is this one. */ - KHERR_CFMASK_INITIAL = 0x0000000a, + KHERR_CFMASK_INITIAL = 0x0000000a, /*!< Allowed initial flags */ }; @@ -580,14 +580,14 @@ KHMEXP void KHMAPI kherr_remove_ctx_handler(kherr_ctx_handler h, when the event is freed other than that implied by \a flags. */ KHMEXP kherr_event * KHMAPI kherr_report( - enum kherr_severity severity, + kherr_severity severity, const wchar_t * short_desc, const wchar_t * facility, const wchar_t * location, const wchar_t * long_desC, const wchar_t * suggestion, khm_int32 facility_id, - enum kherr_suggestion suggestion_id, + kherr_suggestion suggestion_id, kherr_param p1, kherr_param p2, kherr_param p3, @@ -606,7 +606,7 @@ KHMEXP kherr_event * KHMAPI kherr_report( string against the arguments. */ KHMEXP kherr_event * __cdecl -kherr_reportf_ex(enum kherr_severity severity, +kherr_reportf_ex(kherr_severity severity, const wchar_t * facility, khm_int32 facility_id, #ifdef _WIN32 -- 2.26.2