-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
|
||
/** | ||
* @brief Log a set of flags | ||
* | ||
* @param flags the flags to log | ||
* @param flag_strs the flags strings | ||
* @param flag_strs_size the size of the flag strings array | ||
* @return int the number of bytes written | ||
*/ | ||
int flags_log(uint64_t flags, const flag_str_t *flag_strs, size_t flag_strs_size) | ||
{ | ||
int size_written = 0; | ||
bool_t first = true; | ||
for (size_t i = 0; i < flag_strs_size; i++) | ||
{ | ||
if (flags & flag_strs[i].flag) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%s", flag_strs[i].str); | ||
first = false; | ||
flags &= ~flag_strs[i].flag; | ||
} | ||
} | ||
if (flags != 0) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%#llx", flags); | ||
} | ||
return size_written; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <sys/mman.h> | ||
#include <macros.h> | ||
|
||
static const flag_str_t mmap_flags[] = { | ||
FLAG_STR(MAP_SHARED), | ||
FLAG_STR(MAP_PRIVATE), | ||
FLAG_STR(MAP_FIXED), | ||
FLAG_STR(MAP_ANONYMOUS), | ||
FLAG_STR(MAP_GROWSDOWN), | ||
FLAG_STR(MAP_DENYWRITE), | ||
FLAG_STR(MAP_EXECUTABLE), | ||
FLAG_STR(MAP_LOCKED), | ||
FLAG_STR(MAP_NORESERVE), | ||
FLAG_STR(MAP_POPULATE), | ||
FLAG_STR(MAP_NONBLOCK), | ||
FLAG_STR(MAP_STACK), | ||
FLAG_STR(MAP_HUGETLB), | ||
FLAG_STR(MAP_SYNC), | ||
FLAG_STR(MAP_FIXED_NOREPLACE), | ||
}; | ||
|
||
/** | ||
* @brief Log mmap flags | ||
* | ||
* @param value the value to log | ||
* @return int the number of bytes written | ||
*/ | ||
int log_MMAP_FLAGS(uint64_t value) | ||
{ | ||
if (value == 0) | ||
return ft_dprintf(STDERR_FILENO, "MAP_FILE"); | ||
return flags_log(value, mmap_flags, ELEM_COUNT(mmap_flags)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <sys/mman.h> | ||
#include <macros.h> | ||
|
||
static const flag_str_t mmap_prot_flags[] = { | ||
FLAG_STR(PROT_READ), | ||
FLAG_STR(PROT_WRITE), | ||
FLAG_STR(PROT_EXEC), | ||
}; | ||
|
||
/** | ||
* @brief Log mmap protection flags | ||
* | ||
* @param value the value to log | ||
* @return int the number of bytes written | ||
*/ | ||
int log_MMAP_PROT(uint64_t value) | ||
{ | ||
if (value == 0) | ||
return ft_dprintf(STDERR_FILENO, "PROT_NONE"); | ||
return flags_log(value, mmap_prot_flags, ELEM_COUNT(mmap_prot_flags)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters