crypt32: Pass context as BASE_CONTEXT to Context_AddRef and added structs describing memory layout behind context structs.

This commit is contained in:
Jacek Caban 2013-10-14 14:47:07 +02:00 committed by Alexandre Julliard
parent b2b71c2085
commit 802a6bc1bb
6 changed files with 53 additions and 22 deletions

View File

@ -176,15 +176,14 @@ end:
return cert; return cert;
} }
PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext( PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext)
PCCERT_CONTEXT pCertContext)
{ {
TRACE("(%p)\n", pCertContext); TRACE("(%p)\n", pCertContext);
if (!pCertContext) if (!pCertContext)
return NULL; return NULL;
Context_AddRef((void *)pCertContext); Context_AddRef(&cert_from_ptr(pCertContext)->base);
return pCertContext; return pCertContext;
} }

View File

@ -26,13 +26,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(context); 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 CONTEXT_FROM_BASE_CONTEXT(p) (void*)(p+1)
#define BASE_CONTEXT_FROM_CONTEXT(p) ((BASE_CONTEXT*)(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->ref = 1;
context->linked = BASE_CONTEXT_FROM_CONTEXT(linked); context->linked = BASE_CONTEXT_FROM_CONTEXT(linked);
if (addRef) if (addRef)
Context_AddRef(linked); Context_AddRef(BASE_CONTEXT_FROM_CONTEXT(linked));
TRACE("returning %p\n", context); TRACE("returning %p\n", context);
return CONTEXT_FROM_BASE_CONTEXT(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(&context->ref);
TRACE("(%p) ref=%d\n", context, context->ref);
InterlockedIncrement(&baseContext->ref);
TRACE("%p's ref count is %d\n", context, baseContext->ref);
} }
void *Context_GetExtra(const void *context, size_t contextSize) void *Context_GetExtra(const void *context, size_t contextSize)

View File

@ -327,7 +327,7 @@ PCCRL_CONTEXT WINAPI CertDuplicateCRLContext(PCCRL_CONTEXT pCrlContext)
{ {
TRACE("(%p)\n", pCrlContext); TRACE("(%p)\n", pCrlContext);
if (pCrlContext) if (pCrlContext)
Context_AddRef((void *)pCrlContext); Context_AddRef(&crl_from_ptr(pCrlContext)->base);
return pCrlContext; return pCrlContext;
} }

View File

@ -157,6 +157,49 @@ void crypt_sip_free(void) DECLSPEC_HIDDEN;
void root_store_free(void) DECLSPEC_HIDDEN; void root_store_free(void) DECLSPEC_HIDDEN;
void default_chain_engine_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 /* Some typedefs that make it easier to abstract which type of context we're
* working with. * working with.
*/ */
@ -234,8 +277,6 @@ typedef enum _CertStoreType {
StoreTypeEmpty StoreTypeEmpty
} CertStoreType; } CertStoreType;
typedef struct _CONTEXT_PROPERTY_LIST CONTEXT_PROPERTY_LIST;
#define WINE_CRYPTCERTSTORE_MAGIC 0x74726563 #define WINE_CRYPTCERTSTORE_MAGIC 0x74726563
/* A cert store is polymorphic through the use of function pointers. A type /* 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; 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); typedef void (*ContextFreeFunc)(void *context);

View File

@ -457,7 +457,7 @@ PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext)
{ {
TRACE("(%p)\n", pCtlContext); TRACE("(%p)\n", pCtlContext);
if (pCtlContext) if (pCtlContext)
Context_AddRef((void *)pCtlContext); Context_AddRef(&ctl_from_ptr(pCtlContext)->base);
return pCtlContext; return pCtlContext;
} }

View File

@ -1507,7 +1507,7 @@ static BOOL EmptyStore_add(WINECRYPT_CERTSTORE *store, void *context,
/* FIXME: We should clone the context */ /* FIXME: We should clone the context */
if(ret_context) { if(ret_context) {
Context_AddRef(context); Context_AddRef(context_from_ptr(context));
*ret_context = context; *ret_context = context;
} }