projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Standardize `!ptr` i/o `ptr == NULL`, `ptr` i/o `ptr != NULL`
[babeltrace.git]
/
src
/
compat
/
mman.c
diff --git
a/src/compat/mman.c
b/src/compat/mman.c
index aa31998004b2418d4015afbcf92c43055ffcb0ee..1a7638c98381e0d6511a3a78f597e43015d90df7 100644
(file)
--- a/
src/compat/mman.c
+++ b/
src/compat/mman.c
@@
-26,8
+26,9
@@
* SOFTWARE.
*/
* SOFTWARE.
*/
-#define BT_LOG_TAG "COMPAT-MMAN"
-#include "logging.h"
+#define BT_LOG_OUTPUT_LEVEL (mapping->log_level)
+#define BT_LOG_TAG "COMPAT/MMAN"
+#include "logging/log.h"
#include "common/macros.h"
#include "common/macros.h"
@@
-43,13
+44,17
@@
int bt_mman_dummy_symbol;
#ifdef __MINGW32__
#include <errno.h>
#ifdef __MINGW32__
#include <errno.h>
+#include <glib.h>
#include <io.h>
#include <pthread.h>
#include <stdlib.h>
#include <windows.h>
#include <io.h>
#include <pthread.h>
#include <stdlib.h>
#include <windows.h>
+
#include "compat/mman.h"
struct mmap_mapping {
#include "compat/mman.h"
struct mmap_mapping {
+ int log_level;
+
/* The duplicated handle. */
HANDLE file_handle;
/* Handle returned by CreateFileMapping. */
/* The duplicated handle. */
HANDLE file_handle;
/* Handle returned by CreateFileMapping. */
@@
-65,14
+70,15
@@
GHashTable *mmap_mappings = NULL;
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
static
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
static
-struct mmap_mapping *mapping_create(
void
)
+struct mmap_mapping *mapping_create(
int log_level
)
{
struct mmap_mapping *mapping;
mapping = malloc(sizeof(struct mmap_mapping));
{
struct mmap_mapping *mapping;
mapping = malloc(sizeof(struct mmap_mapping));
- if (mapping
!= NULL
) {
+ if (mapping) {
mapping->file_handle = NULL;
mapping->map_handle = NULL;
mapping->file_handle = NULL;
mapping->map_handle = NULL;
+ mapping->log_level = log_level;
}
return mapping;
}
return mapping;
@@
-100,25
+106,30
@@
void addr_clean(void *addr)
{
/* Cleanup of handles should never fail. */
if (!UnmapViewOfFile(addr)) {
{
/* Cleanup of handles should never fail. */
if (!UnmapViewOfFile(addr)) {
- BT_LOGF_STR("Failed to unmap mmap mapping.");
+ /*
+ * FIXME: We don't have access to the mapping's log
+ * level here, so force a FATAL level.
+ */
+ BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, BT_LOG_FATAL, BT_LOG_TAG,
+ "Failed to unmap mmap mapping.");
abort();
}
}
static
abort();
}
}
static
-void mmap_lock(
void
)
+void mmap_lock(
int log_level
)
{
if (pthread_mutex_lock(&mmap_mutex)) {
{
if (pthread_mutex_lock(&mmap_mutex)) {
- BT_LOG
F_STR(
"Failed to acquire mmap_mutex.");
+ BT_LOG
_WRITE_CUR_LVL(BT_LOG_FATAL, log_level, BT_LOG_TAG,
"Failed to acquire mmap_mutex.");
abort();
}
}
static
abort();
}
}
static
-void mmap_unlock(
void
)
+void mmap_unlock(
int log_level
)
{
if (pthread_mutex_unlock(&mmap_mutex)) {
{
if (pthread_mutex_unlock(&mmap_mutex)) {
- BT_LOG
F_STR(
"Failed to release mmap_mutex.");
+ BT_LOG
_WRITE_CUR_LVL(BT_LOG_FATAL, log_level, BT_LOG_TAG,
"Failed to release mmap_mutex.");
abort();
}
}
abort();
}
}
@@
-161,7
+172,7
@@
DWORD map_prot_flags(int prot, DWORD *dwDesiredAccess)
BT_HIDDEN
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
BT_HIDDEN
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
- off_t offset)
+ off_t offset
, int log_level
)
{
struct mmap_mapping *mapping = NULL;
void *mapping_addr;
{
struct mmap_mapping *mapping = NULL;
void *mapping_addr;
@@
-189,9
+200,10
@@
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
}
/* Allocate the mapping struct. */
}
/* Allocate the mapping struct. */
- mapping = mapping_create();
+ mapping = mapping_create(
log_level
);
if (!mapping) {
if (!mapping) {
- BT_LOGE_STR("Failed to allocate mmap mapping.");
+ BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG,
+ "Failed to allocate mmap mapping.");
_set_errno(ENOMEM);
goto error;
}
_set_errno(ENOMEM);
goto error;
}
@@
-231,7
+243,7
@@
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
goto error;
}
goto error;
}
- mmap_lock();
+ mmap_lock(
log_level
);
/* If we have never done any mappings, allocate the hashtable. */
if (!mmap_mappings) {
/* If we have never done any mappings, allocate the hashtable. */
if (!mmap_mappings) {
@@
-248,12
+260,12
@@
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
/* Add the new mapping to the hashtable. */
g_hash_table_insert(mmap_mappings, mapping_addr, mapping);
/* Add the new mapping to the hashtable. */
g_hash_table_insert(mmap_mappings, mapping_addr, mapping);
- mmap_unlock();
+ mmap_unlock(
log_level
);
return mapping_addr;
error_mutex_unlock:
return mapping_addr;
error_mutex_unlock:
- mmap_unlock();
+ mmap_unlock(
log_level
);
error:
mapping_clean(mapping);
return MAP_FAILED;
error:
mapping_clean(mapping);
return MAP_FAILED;
@@
-263,11
+275,15
@@
BT_HIDDEN
int bt_munmap(void *addr, size_t length)
{
int ret = 0;
int bt_munmap(void *addr, size_t length)
{
int ret = 0;
+ struct mmap_mapping *mapping = addr;
+ int log_level;
- mmap_lock();
+ BT_ASSERT(mapping);
+ log_level = mapping->log_level;
+ mmap_lock(log_level);
/* Check if the mapping exists in the hashtable. */
/* Check if the mapping exists in the hashtable. */
- if (
g_hash_table_lookup(mmap_mappings, addr) == NULL
) {
+ if (
!g_hash_table_lookup(mmap_mappings, addr)
) {
_set_errno(EINVAL);
ret = -1;
goto end;
_set_errno(EINVAL);
ret = -1;
goto end;
@@
-280,7
+296,7
@@
int bt_munmap(void *addr, size_t length)
}
end:
}
end:
- mmap_unlock();
+ mmap_unlock(
log_level
);
return ret;
}
return ret;
}
This page took
0.02551 seconds
and
4
git commands to generate.