Skip to content

Commit

Permalink
rename CANDO_*_PAGE macros to CANDO_PAGE_*
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Davis Jr <[email protected]>
  • Loading branch information
EasyIP2023 committed Dec 16, 2024
1 parent 38de413 commit 3bb4abc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
23 changes: 12 additions & 11 deletions include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
#define CANDO_API
#endif

/*
* Define typical page size without including
* limits.h header.
*/
#define CANDO_PAGE_SIZE (1<<12)

/*
* Informs the compiler that you expect a variable
* to be unused and instructs compiler to not issue
Expand All @@ -34,10 +28,17 @@
#define CANDO_INLINE inline __attribute__((always_inline))
#define CANDO_STATIC_INLINE static inline __attribute__((always_inline))

/*
* Define typical page size without including
* limits.h header.
*/
#define CANDO_PAGE_SIZE (1<<12)


/*
* Retrieves the starting address of the page @ptr resides in.
*/
#define CANDO_GET_PAGE(ptr) \
#define CANDO_PAGE_GET(ptr) \
((void*)((uintptr_t)ptr & ~(CANDO_PAGE_SIZE-1)))


Expand All @@ -47,11 +48,11 @@
* @param ptr - Pointer to data caller wants write-only
* @param size - Size of data that needs to be set write-only
*/
#define CANDO_SET_PAGE_WRITE(ptr, size) \
#define CANDO_PAGE_SET_WRITE(ptr, size) \
__extension__ \
({ \
int err = -1; \
void *page = CANDO_GET_PAGE(ptr); \
void *page = CANDO_PAGE_GET(ptr); \
err = mprotect(page, size, PROT_WRITE); \
err; \
})
Expand All @@ -63,11 +64,11 @@
* @param ptr - Pointer to data caller wants write-only
* @param size - Size of data that needs to be set write-only
*/
#define CANDO_SET_PAGE_READ(ptr, size) \
#define CANDO_PAGE_SET_READ(ptr, size) \
__extension__ \
({ \
int err = -1; \
void *page = CANDO_GET_PAGE(ptr); \
void *page = CANDO_PAGE_GET(ptr); \
err = mprotect(page, size, PROT_READ); \
err; \
})
Expand Down
10 changes: 5 additions & 5 deletions src/file-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ cando_file_ops_create (const void *_fileCreateInfo)
}
}

ret = mprotect(flops, sizeof(struct cando_file_ops), PROT_READ);
ret = CANDO_PAGE_SET_READ(flops, sizeof(struct cando_file_ops));
if (ret == -1) {
cando_log_err("mprotect: %s\n", strerror(errno));
cando_file_ops_destroy(flops);
Expand Down Expand Up @@ -294,7 +294,7 @@ cando_file_ops_get_line (struct cando_file_ops *flops,
}
}

ret = CANDO_SET_PAGE_WRITE(flops->retData, offset);
ret = CANDO_PAGE_SET_WRITE(flops->retData, offset);
if (ret == -1) {
cando_log_set_err(flops, errno, "mprotect: %s", strerror(errno));
return NULL;
Expand All @@ -305,7 +305,7 @@ cando_file_ops_get_line (struct cando_file_ops *flops,
memcpy(flops->retData, ((char*)flops->data)+(offset-c), c);
*((char*)(flops->retData+c)) = '\0';

ret = CANDO_SET_PAGE_READ(flops->retData, offset);
ret = CANDO_PAGE_SET_READ(flops->retData, offset);
if (ret == -1) {
cando_log_set_err(flops, errno, "mprotect: %s", strerror(errno));
return NULL;
Expand Down Expand Up @@ -399,15 +399,15 @@ cando_file_ops_set_data (struct cando_file_ops *flops,

data = (void*)(((char*)flops->data)+fileInfo->offset);

ret = CANDO_SET_PAGE_WRITE(data, fileInfo->dataSize);
ret = CANDO_PAGE_SET_WRITE(data, fileInfo->dataSize);
if (ret == -1) {
cando_log_set_err(flops, errno, "mprotect: %s", strerror(errno));
return -1;
}

memcpy(data, fileInfo->data, fileInfo->dataSize);

ret = CANDO_SET_PAGE_READ(data, fileInfo->dataSize);
ret = CANDO_PAGE_SET_READ(data, fileInfo->dataSize);
if (ret == -1) {
cando_log_set_err(flops, errno, "mprotect: %s", strerror(errno));
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cando_log_set_error_struct (const void *context,
if (!error)
return;

CANDO_SET_PAGE_WRITE(error, sizeof(struct cando_log_error_struct));
CANDO_PAGE_SET_WRITE(error, sizeof(struct cando_log_error_struct));

error->code = code;

Expand All @@ -117,7 +117,7 @@ cando_log_set_error_struct (const void *context,
strncpy(error->buffer+offset, string, sizeof(error->buffer)-offset);
}

CANDO_SET_PAGE_READ(error, sizeof(struct cando_log_error_struct));
CANDO_PAGE_SET_READ(error, sizeof(struct cando_log_error_struct));
}


Expand Down

0 comments on commit 3bb4abc

Please sign in to comment.