Commit ae91dacb authored by johnx's avatar johnx Committed by Commit Bot

Introduce libc wrappers like v8::base::Malloc

The Cobalt project has its own Starboard equivalent of libc APIs like
`malloc` and `free`. This CL introduces the wrappers for some libc
functions. In followup CLs, for example occurences of malloc will all
be replaced by base::Malloc in V8.

See b/156155426 for more information.

Bug: v8:10927
Change-Id: Ida3d161a1da56755b681e18b4827e277e6cb4c4d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2416150
Commit-Queue: John Xu <johnx@google.com>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Auto-Submit: John Xu <johnx@google.com>
Cr-Commit-Position: refs/heads/master@{#70702}
parent 0d0a3416
......@@ -4071,6 +4071,8 @@ v8_component("v8_libbase") {
"src/base/platform/semaphore.h",
"src/base/platform/time.cc",
"src/base/platform/time.h",
"src/base/platform/wrappers.h",
"src/base/platform/wrappers_std.cc",
"src/base/region-allocator.cc",
"src/base/region-allocator.h",
"src/base/ring-buffer.h",
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_BASE_PLATFORM_WRAPPERS_H_
#define V8_BASE_PLATFORM_WRAPPERS_H_
#include <stddef.h>
#include <stdio.h>
namespace v8 {
namespace base {
void* Malloc(size_t size);
void* Realloc(void* memory, size_t size);
void Free(void* memory);
void* Calloc(size_t count, size_t size);
void* Memcpy(void* dest, const void* source, size_t count);
FILE* Fopen(const char* filename, const char* mode);
int Fclose(FILE* stream);
} // namespace base
} // namespace v8
#endif // V8_BASE_PLATFORM_WRAPPERS_H_
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "starboard/memory.h"
#include "src/base/platform/wrappers.h"
namespace v8 {
namespace base {
void* Malloc(size_t size) { return SbMemoryAlloc(size); }
void* Realloc(void* memory, size_t size) {
return SbMemoryReallocate(memory, size);
}
void Free(void* memory) { return SbMemoryDeallocate(memory); }
void* Calloc(size_t count, size_t size) { return SbMemoryCalloc(count, size); }
void* Memcpy(void* dest, const void* source, size_t count) {
return SbMemoryCopy(dest, source, count);
}
FILE* Fopen(const char* filename, const char* mode) { return NULL; }
int Fclose(FILE* stream) { return -1; }
} // namespace base
} // namespace v8
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "src/base/platform/wrappers.h"
namespace v8 {
namespace base {
void* Malloc(size_t size) { return malloc(size); }
void* Realloc(void* memory, size_t size) { return realloc(memory, size); }
void Free(void* memory) { return free(memory); }
void* Calloc(size_t count, size_t size) { return calloc(count, size); }
void* Memcpy(void* dest, const void* source, size_t count) {
return memcpy(dest, source, count);
}
FILE* Fopen(const char* filename, const char* mode) {
return fopen(filename, mode);
}
int Fclose(FILE* stream) { return fclose(stream); }
} // namespace base
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment