mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 19:58:30 +00:00
Use re-entrant locks on stdio
This commit is contained in:
parent
4e9662cbc7
commit
1f229e4efc
78 changed files with 427 additions and 179 deletions
|
@ -27,6 +27,7 @@
|
|||
* @return memory address, or NULL w/ errno
|
||||
* @throw EINVAL if !IS2POW(a)
|
||||
* @see pvalloc()
|
||||
* @threadsafe
|
||||
*/
|
||||
void *aligned_alloc(size_t a, size_t n) {
|
||||
if (IS2POW(a)) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
* portability, since that's guaranteed to work with all libraries
|
||||
* @return bytes written (excluding NUL) or -1 w/ errno
|
||||
* @see xasprintf() for a better API
|
||||
* @threadsafe
|
||||
*/
|
||||
int(asprintf)(char **strp, const char *fmt, ...) {
|
||||
int res;
|
||||
|
|
|
@ -26,5 +26,6 @@
|
|||
// @return rax is memory address, or NULL w/ errno
|
||||
// @note overreliance on memalign is a sure way to fragment space
|
||||
// @see dlcalloc()
|
||||
// @threadsafe
|
||||
calloc: jmp *hook_calloc(%rip)
|
||||
.endfn calloc,globl
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
//
|
||||
// @param rdi is allocation address, which may be NULL
|
||||
// @see dlfree()
|
||||
// @threadsafe
|
||||
free: jmp *hook_free(%rip)
|
||||
.endfn free,globl
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
* that'll be returned.
|
||||
*
|
||||
* @return pointer that must be free()'d, or NULL w/ errno
|
||||
* @threadsafe
|
||||
*/
|
||||
dontdiscard char *get_current_dir_name(void) {
|
||||
const char *p;
|
||||
|
|
|
@ -33,5 +33,6 @@
|
|||
//
|
||||
// @param rdi is number of bytes needed, coerced to 1+
|
||||
// @return new memory, or NULL w/ errno
|
||||
// @threadsafe
|
||||
malloc: jmp *hook_malloc(%rip)
|
||||
.endfn malloc,globl
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
// @param rdi is address of allocation
|
||||
// @return rax is total number of bytes
|
||||
// @see dlmalloc_usable_size()
|
||||
// @threadsafe
|
||||
malloc_usable_size:
|
||||
jmp *hook_malloc_usable_size(%rip)
|
||||
.endfn malloc_usable_size,globl
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
// @param rsi is number of bytes needed, coerced to 1+
|
||||
// @return rax is memory address, or NULL w/ errno
|
||||
// @see valloc(), pvalloc()
|
||||
// @threadsafe
|
||||
memalign:
|
||||
jmp *hook_memalign(%rip)
|
||||
.endfn memalign,globl
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
* @param bytes is number of bytes to allocate
|
||||
* @return return 0 or EINVAL or ENOMEM w/o setting errno
|
||||
* @see memalign()
|
||||
* @threadsafe
|
||||
*/
|
||||
int posix_memalign(void **pp, size_t alignment, size_t bytes) {
|
||||
int e;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
* @param n number of bytes needed
|
||||
* @return memory address, or NULL w/ errno
|
||||
* @see valloc()
|
||||
* @threadsafe
|
||||
*/
|
||||
void *pvalloc(size_t n) {
|
||||
return memalign(PAGESIZE, ROUNDUP(n, PAGESIZE));
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
// @note realloc(p=0, n=0) → malloc(32)
|
||||
// @note realloc(p≠0, n=0) → free(p)
|
||||
// @see dlrealloc()
|
||||
// @threadsafe
|
||||
realloc:
|
||||
jmp *hook_realloc(%rip)
|
||||
.endfn realloc,globl
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
// @param rsi (newsize) is number of bytes needed
|
||||
// @return rax is result, or NULL w/ errno
|
||||
// @see dlrealloc_in_place()
|
||||
// @threadsafe
|
||||
realloc_in_place:
|
||||
jmp *hook_realloc_in_place(%rip)
|
||||
.endfn realloc_in_place,globl
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
* @param ptr may be NULL for malloc() behavior
|
||||
* @param nmemb may be 0 for free() behavior; shrinking is promised too
|
||||
* @return new address or NULL w/ errno and ptr is NOT free()'d
|
||||
* @threadsafe
|
||||
*/
|
||||
void *reallocarray(void *ptr, size_t nmemb, size_t itemsize) {
|
||||
size_t n;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
* @param s is a NUL-terminated byte string
|
||||
* @return new string or NULL w/ errno
|
||||
* @error ENOMEM
|
||||
* @threadsafe
|
||||
*/
|
||||
char *strdup(const char *s) {
|
||||
size_t len = strlen(s);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
* @param n if less than strlen(s) will truncate the string
|
||||
* @return new string or NULL w/ errno
|
||||
* @error ENOMEM
|
||||
* @threadsafe
|
||||
*/
|
||||
char *strndup(const char *s, size_t n) {
|
||||
char *s2;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* @param n number of bytes needed
|
||||
* @return memory address, or NULL w/ errno
|
||||
* @see pvalloc()
|
||||
* @threadsafe
|
||||
*/
|
||||
void *valloc(size_t n) {
|
||||
return memalign(PAGESIZE, n);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
/**
|
||||
* Formats string w/ dynamic memory allocation.
|
||||
* @see xasprintf() for a better API
|
||||
* @threadsafe
|
||||
*/
|
||||
int(vasprintf)(char **strp, const char *fmt, va_list va) {
|
||||
va_list vb;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
/**
|
||||
* Allocates copy of wide string.
|
||||
* @threadsafe
|
||||
*/
|
||||
wchar_t *wcsdup(const wchar_t *s) {
|
||||
size_t len = wcslen(s);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue