mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-06 08:56:22 +00:00
Add some more necessary locks
This commit is contained in:
parent
8b72490431
commit
91953dd308
9 changed files with 29 additions and 15 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
/**
|
||||
* Frees addresses returned by getaddrinfo().
|
||||
* @threadsafe
|
||||
*/
|
||||
int freeaddrinfo(struct addrinfo *ai) {
|
||||
struct addrinfo *next;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
* @param res receives a pointer that must be freed with freeaddrinfo(),
|
||||
* and won't be modified if -1 is returned
|
||||
* @return 0 on success or EAI_xxx value
|
||||
* @threadsafe
|
||||
*/
|
||||
int getaddrinfo(const char *name, const char *service,
|
||||
const struct addrinfo *hints, struct addrinfo **res) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/dns/hoststxt.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/pthread.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -32,6 +33,7 @@
|
|||
static struct HostsTxt *g_hoststxt;
|
||||
static struct HostsTxtInitialStaticMemory {
|
||||
struct HostsTxt ht;
|
||||
pthread_mutex_t lock;
|
||||
struct HostsTxtEntry entries[8];
|
||||
char strings[64];
|
||||
} g_hoststxt_init;
|
||||
|
@ -53,6 +55,7 @@ static textwindows dontinline char *GetNtHostsTxtPath(char *pathbuf,
|
|||
* Returns hosts.txt map.
|
||||
*
|
||||
* @note yoinking realloc() ensures there's no size limits
|
||||
* @threadsafe
|
||||
*/
|
||||
const struct HostsTxt *GetHostsTxt(void) {
|
||||
FILE *f;
|
||||
|
@ -60,6 +63,7 @@ const struct HostsTxt *GetHostsTxt(void) {
|
|||
char pathbuf[PATH_MAX];
|
||||
struct HostsTxtInitialStaticMemory *init;
|
||||
init = &g_hoststxt_init;
|
||||
pthread_mutex_lock(&init->lock);
|
||||
if (!g_hoststxt) {
|
||||
g_hoststxt = &init->ht;
|
||||
init->ht.entries.n = pushpop(ARRAYLEN(init->entries));
|
||||
|
@ -78,5 +82,6 @@ const struct HostsTxt *GetHostsTxt(void) {
|
|||
fclose(f);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&init->lock);
|
||||
return g_hoststxt;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/dns/resolvconf.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/pthread.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
@ -28,17 +29,20 @@
|
|||
static struct ResolvConf *g_resolvconf;
|
||||
static struct ResolvConfInitialStaticMemory {
|
||||
struct ResolvConf rv;
|
||||
pthread_mutex_t lock;
|
||||
struct sockaddr_in nameservers[3];
|
||||
} g_resolvconf_init;
|
||||
|
||||
/**
|
||||
* Returns singleton with DNS server address.
|
||||
* @threadsafe
|
||||
*/
|
||||
const struct ResolvConf *GetResolvConf(void) {
|
||||
int rc;
|
||||
FILE *f;
|
||||
struct ResolvConfInitialStaticMemory *init;
|
||||
init = &g_resolvconf_init;
|
||||
pthread_mutex_lock(&init->lock);
|
||||
if (!g_resolvconf) {
|
||||
g_resolvconf = &init->rv;
|
||||
pushmov(&init->rv.nameservers.n, ARRAYLEN(init->nameservers));
|
||||
|
@ -58,5 +62,6 @@ const struct ResolvConf *GetResolvConf(void) {
|
|||
/* TODO(jart): Elevate robustness. */
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&init->lock);
|
||||
return g_resolvconf;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
* @return -1 on error, or positive port number
|
||||
* @note aliases are read from file for comparison, but not returned.
|
||||
* @see LookupServicesByPort
|
||||
* @threadsafe
|
||||
*/
|
||||
int LookupServicesByName(const char *servname, char *servproto,
|
||||
size_t servprotolen, char *buf, size_t bufsize,
|
||||
|
|
|
@ -37,6 +37,7 @@ void __cxa_printexits(FILE *f, void *pred) {
|
|||
fprintf(f, " GLOBAL DESTRUCTORS \n");
|
||||
fprintf(f, " callback arg pred \n");
|
||||
fprintf(f, "---------------------- ------------------ ------------------\n");
|
||||
__cxa_lock();
|
||||
if ((b = __cxa_blocks.p)) {
|
||||
do {
|
||||
mask = b->mask;
|
||||
|
@ -56,5 +57,6 @@ void __cxa_printexits(FILE *f, void *pred) {
|
|||
}
|
||||
} while ((b = b->next));
|
||||
}
|
||||
__cxa_unlock();
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
|
|
@ -127,10 +127,6 @@
|
|||
// Loads address of errno into %rcx
|
||||
.macro .errno
|
||||
call __errno_location
|
||||
// cs
|
||||
// cs
|
||||
// cs
|
||||
// mov $__errno,%eax
|
||||
.endm
|
||||
|
||||
// Post-Initialization Read-Only (PIRO) BSS section.
|
||||
|
|
|
@ -124,6 +124,16 @@ cosmo: push %rbp
|
|||
.weak ape_stack_align
|
||||
#endif
|
||||
|
||||
#if IsAsan()
|
||||
.init.start 305,_init_symbols
|
||||
push %rdi
|
||||
push %rsi
|
||||
call __init_symbols
|
||||
pop %rsi
|
||||
pop %rdi
|
||||
.init.end 305,_init_symbols
|
||||
#endif
|
||||
|
||||
#ifdef __PG__
|
||||
.init.start 306,_init_ftrace
|
||||
push %rdi
|
||||
|
@ -135,16 +145,6 @@ cosmo: push %rbp
|
|||
.init.end 306,_init_ftrace
|
||||
#endif
|
||||
|
||||
#if IsAsan()
|
||||
.init.start 306,_init_symbols
|
||||
push %rdi
|
||||
push %rsi
|
||||
call __init_symbols
|
||||
pop %rsi
|
||||
pop %rdi
|
||||
.init.end 306,_init_symbols
|
||||
#endif
|
||||
|
||||
#if IsModeDbg()
|
||||
#ifdef SYSDEBUG
|
||||
.init.start 307,_init_printargs
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
|
@ -42,6 +44,7 @@ void _firewall(const void *addr, uint32_t addrsize) {
|
|||
*p++ = '\n';
|
||||
write(2, b, p - b);
|
||||
if (weaken(__die)) weaken(__die)();
|
||||
abort();
|
||||
__restorewintty();
|
||||
_Exit(66);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue