Non-pageable Memory

## Non-pageable Memory Non-pageable Memory — Secure Non-pageable Memory |

## Synopsis

    #define             mate_keyring_memory_new            (type,
                                                             n_objects)
    gpointer            mate_keyring_memory_alloc          (gulong sz);
    gpointer            mate_keyring_memory_try_alloc      (gulong sz);
    gpointer            mate_keyring_memory_realloc        (gpointer p,
                                                             gulong sz);
    gpointer            mate_keyring_memory_try_realloc    (gpointer p,
                                                             gulong sz);
    void                mate_keyring_memory_free           (gpointer p);
    gboolean            mate_keyring_memory_is_secure      (gpointer p);
    gchar*              mate_keyring_memory_strdup         (const gchar *str);

## Description

Normal allocated memory can be paged to disk at the whim of the operating system. This can be a serious problem for sensitive information like passwords, keys and secrets.

MATE Keyring holds passwords in non-pageable, or locked memory. This happens both in the daemon and in the library. This is only possible if the OS contains support for it.

These functions allow applications to use to hold passwords and other sensitive information.

## Details

### mate_keyring_memory_new()

    #define             mate_keyring_memory_new(type, n_objects)

Allocate objects in non-pageable mate-keyring memory.

`type` : | The C type of the objects to allocate
`n_objects` : | The number of objects to allocate.
Returns : | The new block of memory.

### mate_keyring_memory_alloc ()

    gpointer            mate_keyring_memory_alloc          (gulong sz);

Allocate a block of mate-keyring non-pageable memory.

If non-pageable memory cannot be allocated then normal memory will be returned.

`sz` : | The new desired size of the memory block.
Returns : | The new memory block which should be freed with `mate_keyring_memory_free()`

### mate_keyring_memory_try_alloc ()

    gpointer            mate_keyring_memory_try_alloc      (gulong sz);

Allocate a block of mate-keyring non-pageable memory.

If non-pageable memory cannot be allocated, then NULL is returned.

`sz` : | The new desired size of the memory block.
Returns : | The new block, or NULL if memory cannot be allocated. The memory block should be freed with `mate_keyring_memory_free()`

### mate_keyring_memory_realloc ()

    gpointer            mate_keyring_memory_realloc        (gpointer p,
                                                             gulong sz);

Reallocate a block of mate-keyring non-pageable memory.

Glib memory is also reallocated correctly. If called with a null pointer, then a new block of memory is allocated. If called with a zero size, then the block of memory is freed.

If non-pageable memory cannot be allocated then normal memory will be returned.

`p` : | The pointer to reallocate or NULL to allocate a new block.
`sz` : | The new desired size of the memory block, or 0 to free the memory.
Returns : | The new block, or NULL if the block was freed. The memory block should be freed with `mate_keyring_memory_free()`

### mate_keyring_memory_try_realloc ()

    gpointer            mate_keyring_memory_try_realloc    (gpointer p,
                                                             gulong sz);

Reallocate a block of mate-keyring non-pageable memory.

Glib memory is also reallocated correctly when passed to this function. If called with a null pointer, then a new block of memory is allocated. If called with a zero size, then the block of memory is freed.

If memory cannot be allocated, NULL is returned and the original block of memory remains intact.

`p` : | The pointer to reallocate or NULL to allocate a new block.
`sz` : | The new desired size of the memory block.
Returns : | The new block, or NULL if memory cannot be allocated. The memory block should be freed with `mate_keyring_memory_free()`

### mate_keyring_memory_free ()

    void                mate_keyring_memory_free           (gpointer p);

Free a block of mate-keyring non-pageable memory.

Glib memory is also freed correctly when passed to this function. If called with a null pointer then no action is taken.

`p` : | The pointer to the beginning of the block of memory to free.

### mate_keyring_memory_is_secure ()

    gboolean            mate_keyring_memory_is_secure      (gpointer p);

Check if a pointer is in non-pageable memory allocated by mate-keyring.

`p` : | The pointer to check
Returns : | Whether the memory is non-pageable or not

### mate_keyring_memory_strdup ()

    gchar*              mate_keyring_memory_strdup         (const gchar *str);

Copy a string into non-pageable memory. If the input string is `NULL`, then `NULL` will be returned.

`str` : | The null terminated string to copy
Returns : | The copied string, should be freed with `mate_keyring_memory_free()`