Use Get/SetLastError on Win32

Using errno on win32 doesn't quite work, because the value set in a shared
library can't be read from e.g. an executable calling the function setting
errno.

At the same time, since buferror always uses errno/GetLastError, don't pass
it.
This commit is contained in:
Mike Hommey
2012-04-30 12:38:26 +02:00
committed by Jason Evans
parent af04b744bd
commit a14bce85e8
7 changed files with 71 additions and 33 deletions

View File

@@ -1,8 +1,17 @@
#ifndef JEMALLOC_INTERNAL_H
#define JEMALLOC_INTERNAL_H
#include <sys/param.h>
#include <math.h>
#ifdef _WIN32
# include <windows.h>
# define ENOENT ERROR_PATH_NOT_FOUND
# define EINVAL ERROR_BAD_ARGUMENTS
# define EAGAIN ERROR_OUTOFMEMORY
# define EPERM ERROR_WRITE_FAULT
# define EFAULT ERROR_INVALID_ADDRESS
# define ENOMEM ERROR_NOT_ENOUGH_MEMORY
# undef ERANGE
# define ERANGE ERROR_INVALID_DATA
#else
# include <sys/mman.h>
# include <sys/syscall.h>
@@ -11,10 +20,10 @@
# endif
# include <sys/uio.h>
# include <pthread.h>
# include <errno.h>
#endif
#include <sys/types.h>
#include <errno.h>
#include <limits.h>
#ifndef SIZE_T_MAX
# define SIZE_T_MAX SIZE_MAX
@@ -34,7 +43,6 @@
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#define JEMALLOC_NO_DEMANGLE
#include "../jemalloc@install_suffix@.h"

View File

@@ -84,7 +84,7 @@
extern void (*je_malloc_message)(void *wcbopaque, const char *s);
int buferror(int errnum, char *buf, size_t buflen);
int buferror(char *buf, size_t buflen);
uintmax_t malloc_strtoumax(const char *nptr, char **endptr, int base);
/*
@@ -109,6 +109,8 @@ void malloc_printf(const char *format, ...)
#ifndef JEMALLOC_ENABLE_INLINE
size_t pow2_ceil(size_t x);
void malloc_write(const char *s);
void set_errno(int errnum);
int get_errno(void);
#endif
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_UTIL_C_))
@@ -140,6 +142,30 @@ malloc_write(const char *s)
je_malloc_message(NULL, s);
}
/* Sets error code */
JEMALLOC_INLINE void
set_errno(int errnum)
{
#ifdef _WIN32
SetLastError(errnum);
#else
errno = errnum;
#endif
}
/* Get last error code */
JEMALLOC_INLINE int
get_errno(void)
{
#ifdef _WIN32
return GetLastError();
#else
return errno;
#endif
}
#endif
#endif /* JEMALLOC_H_INLINES */