From 802a6bc1bb93b4c6397a7c4100a1c86dd893b485 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 14 Oct 2013 14:47:07 +0200 Subject: [PATCH] crypt32: Pass context as BASE_CONTEXT to Context_AddRef and added structs describing memory layout behind context structs. --- dlls/crypt32/cert.c | 5 ++-- dlls/crypt32/context.c | 17 +++--------- dlls/crypt32/crl.c | 2 +- dlls/crypt32/crypt32_private.h | 47 +++++++++++++++++++++++++++++++--- dlls/crypt32/ctl.c | 2 +- dlls/crypt32/store.c | 2 +- 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c index 561fd598473..9e47847043c 100644 --- a/dlls/crypt32/cert.c +++ b/dlls/crypt32/cert.c @@ -176,15 +176,14 @@ end: return cert; } -PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext( - PCCERT_CONTEXT pCertContext) +PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext) { TRACE("(%p)\n", pCertContext); if (!pCertContext) return NULL; - Context_AddRef((void *)pCertContext); + Context_AddRef(&cert_from_ptr(pCertContext)->base); return pCertContext; } diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c index cdc8c016e86..a91b63b6c67 100644 --- a/dlls/crypt32/context.c +++ b/dlls/crypt32/context.c @@ -26,13 +26,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(context); -typedef struct _BASE_CONTEXT -{ - LONG ref; - struct _BASE_CONTEXT *linked; - CONTEXT_PROPERTY_LIST *properties; -} BASE_CONTEXT; - #define CONTEXT_FROM_BASE_CONTEXT(p) (void*)(p+1) #define BASE_CONTEXT_FROM_CONTEXT(p) ((BASE_CONTEXT*)(p)-1) @@ -72,18 +65,16 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned context->ref = 1; context->linked = BASE_CONTEXT_FROM_CONTEXT(linked); if (addRef) - Context_AddRef(linked); + Context_AddRef(BASE_CONTEXT_FROM_CONTEXT(linked)); TRACE("returning %p\n", context); return CONTEXT_FROM_BASE_CONTEXT(context); } -void Context_AddRef(void *context) +void Context_AddRef(context_t *context) { - BASE_CONTEXT *baseContext = BASE_CONTEXT_FROM_CONTEXT(context); - - InterlockedIncrement(&baseContext->ref); - TRACE("%p's ref count is %d\n", context, baseContext->ref); + InterlockedIncrement(&context->ref); + TRACE("(%p) ref=%d\n", context, context->ref); } void *Context_GetExtra(const void *context, size_t contextSize) diff --git a/dlls/crypt32/crl.c b/dlls/crypt32/crl.c index 6ed27f75f18..5f127cbfa23 100644 --- a/dlls/crypt32/crl.c +++ b/dlls/crypt32/crl.c @@ -327,7 +327,7 @@ PCCRL_CONTEXT WINAPI CertDuplicateCRLContext(PCCRL_CONTEXT pCrlContext) { TRACE("(%p)\n", pCrlContext); if (pCrlContext) - Context_AddRef((void *)pCrlContext); + Context_AddRef(&crl_from_ptr(pCrlContext)->base); return pCrlContext; } diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index cc1477c914d..18a3523712a 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -157,6 +157,49 @@ void crypt_sip_free(void) DECLSPEC_HIDDEN; void root_store_free(void) DECLSPEC_HIDDEN; void default_chain_engine_free(void) DECLSPEC_HIDDEN; +typedef struct _CONTEXT_PROPERTY_LIST CONTEXT_PROPERTY_LIST; + +typedef struct _context_t { + LONG ref; + struct _context_t *linked; + CONTEXT_PROPERTY_LIST *properties; +} BASE_CONTEXT, context_t; + +static inline context_t *context_from_ptr(const void *ptr) +{ + return (context_t*)ptr-1; +} + +typedef struct { + context_t base; + CERT_CONTEXT ctx; +} cert_t; + +static inline cert_t *cert_from_ptr(const CERT_CONTEXT *ptr) +{ + return CONTAINING_RECORD(ptr, cert_t, ctx); +} + +typedef struct { + context_t base; + CRL_CONTEXT ctx; +} crl_t; + +static inline crl_t *crl_from_ptr(const CRL_CONTEXT *ptr) +{ + return CONTAINING_RECORD(ptr, crl_t, ctx); +} + +typedef struct { + context_t base; + CTL_CONTEXT ctx; +} ctl_t; + +static inline ctl_t *ctl_from_ptr(const CTL_CONTEXT *ptr) +{ + return CONTAINING_RECORD(ptr, ctl_t, ctx); +} + /* Some typedefs that make it easier to abstract which type of context we're * working with. */ @@ -234,8 +277,6 @@ typedef enum _CertStoreType { StoreTypeEmpty } CertStoreType; -typedef struct _CONTEXT_PROPERTY_LIST CONTEXT_PROPERTY_LIST; - #define WINE_CRYPTCERTSTORE_MAGIC 0x74726563 /* A cert store is polymorphic through the use of function pointers. A type @@ -365,7 +406,7 @@ void Context_CopyProperties(const void *to, const void *from) DECLSPEC_HIDDEN; */ CONTEXT_PROPERTY_LIST *Context_GetProperties(const void *context) DECLSPEC_HIDDEN; -void Context_AddRef(void *context) DECLSPEC_HIDDEN; +void Context_AddRef(context_t*) DECLSPEC_HIDDEN; typedef void (*ContextFreeFunc)(void *context); diff --git a/dlls/crypt32/ctl.c b/dlls/crypt32/ctl.c index a484f856057..2ee94abeedc 100644 --- a/dlls/crypt32/ctl.c +++ b/dlls/crypt32/ctl.c @@ -457,7 +457,7 @@ PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext) { TRACE("(%p)\n", pCtlContext); if (pCtlContext) - Context_AddRef((void *)pCtlContext); + Context_AddRef(&ctl_from_ptr(pCtlContext)->base); return pCtlContext; } diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c index 521fd4f705f..506a33ce35b 100644 --- a/dlls/crypt32/store.c +++ b/dlls/crypt32/store.c @@ -1507,7 +1507,7 @@ static BOOL EmptyStore_add(WINECRYPT_CERTSTORE *store, void *context, /* FIXME: We should clone the context */ if(ret_context) { - Context_AddRef(context); + Context_AddRef(context_from_ptr(context)); *ret_context = context; }