mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Add sodium_mlock() and sodium_munlock()
This commit is contained in:
@@ -35,6 +35,12 @@ int sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen,
|
||||
const char * const ignore, size_t * const bin_len,
|
||||
const char ** const hex_end);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_mlock(const void *addr, const size_t len);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_munlock(const void *addr, const size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
# include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "randombytes.h"
|
||||
#ifdef _WIN32
|
||||
@@ -152,3 +156,29 @@ sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
sodium_mlock(const void *addr, const size_t len)
|
||||
{
|
||||
#ifdef HAVE_MLOCK
|
||||
return mlock(addr, len);
|
||||
#elif defined(HAVE_VIRTUALLOCK)
|
||||
return -(VirtualLock(addr, len) != 0);
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
sodium_munlock(const void *addr, const size_t len)
|
||||
{
|
||||
#ifdef HAVE_MLOCK
|
||||
return munlock(addr, len);
|
||||
#elif defined(HAVE_VIRTUALLOCK)
|
||||
return -(VirtualUnlock(addr, len) != 0);
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user