Skip to content

Commit

Permalink
[PAL,LibOS] Replace malloc_copy() with alloc_and_copy()
Browse files Browse the repository at this point in the history
Previously, Gramine had two generic functions doing the same thing.
Remove one of them.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
  • Loading branch information
dimakuv committed Oct 18, 2023
1 parent c92355d commit c114403
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 21 deletions.
1 change: 0 additions & 1 deletion libos/include/libos_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ int init_slab(void);

void* malloc(size_t size);
void free(void* mem);
void* malloc_copy(const void* mem, size_t size);

/* ELF binary loading */
struct link_map;
Expand Down
8 changes: 0 additions & 8 deletions libos/src/libos_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ void* realloc(void* ptr, size_t new_size) {
}
#endif

// Copies data from `mem` to a newly allocated buffer of a specified size.
void* malloc_copy(const void* mem, size_t size) {
void* buff = malloc(size);
if (buff)
memcpy(buff, mem, size);
return buff;
}

void free(void* mem) {
if (memory_migrated(mem)) {
return;
Expand Down
1 change: 0 additions & 1 deletion pal/include/pal_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ void pal_disable_early_memory_bookkeeping(void);

void init_slab_mgr(void);
void* malloc(size_t size);
void* malloc_copy(const void* mem, size_t size);
void* calloc(size_t num, size_t size);
void free(void* mem);

Expand Down
2 changes: 1 addition & 1 deletion pal/src/pal_streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int parse_stream_uri(const char** uri, char** prefix, struct handle_ops**
*uri = p;

if (prefix) {
*prefix = malloc_copy(u, p - u);
*prefix = alloc_and_copy(u, p - u);
if (!*prefix)
return -PAL_ERROR_NOMEM;
/* We don't want ':' in prefix, replacing that with nullbyte which also ends the string. */
Expand Down
10 changes: 0 additions & 10 deletions pal/src/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ void* malloc(size_t size) {
return ptr;
}

// Copies data from `mem` to a newly allocated buffer of a specified size.
void* malloc_copy(const void* mem, size_t size) {
void* nmem = malloc(size);

if (nmem)
memcpy(nmem, mem, size);

return nmem;
}

void* calloc(size_t num, size_t size) {
size_t total;
if (__builtin_mul_overflow(num, size, &total))
Expand Down

0 comments on commit c114403

Please sign in to comment.