avoid using pthread cleanup push/pop in stdio when not needed
unfortunately in dynamic-linked programs, these macros cause pthread_self to be initialized, which costs a couple syscalls, and (much worse) would necessarily fail, crash, and burn on ancient (2.4 and earlier) kernels where setting up a thread pointer does not work. i'd like to do this in a more generic way that avoids all use of cleanup push/pop before pthread_self has been successfully called and avoids ugly if/else constructs like the one in this commit, but for now, this will suffice.
This commit is contained in:
parent
8cce15af83
commit
3f25354e62
2 changed files with 14 additions and 6 deletions
|
|
@ -15,9 +15,13 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
|
||||||
};
|
};
|
||||||
ssize_t cnt;
|
ssize_t cnt;
|
||||||
|
|
||||||
pthread_cleanup_push(cleanup, f);
|
if (libc.main_thread) {
|
||||||
cnt = syscall_cp(SYS_readv, f->fd, iov, 2);
|
pthread_cleanup_push(cleanup, f);
|
||||||
pthread_cleanup_pop(0);
|
cnt = syscall_cp(SYS_readv, f->fd, iov, 2);
|
||||||
|
pthread_cleanup_pop(0);
|
||||||
|
} else {
|
||||||
|
cnt = syscall(SYS_readv, f->fd, iov, 2);
|
||||||
|
}
|
||||||
if (cnt <= 0) {
|
if (cnt <= 0) {
|
||||||
f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt);
|
f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt);
|
||||||
f->rpos = f->rend = 0;
|
f->rpos = f->rend = 0;
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,13 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
|
||||||
int iovcnt = 2;
|
int iovcnt = 2;
|
||||||
ssize_t cnt;
|
ssize_t cnt;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
pthread_cleanup_push(cleanup, f);
|
if (libc.main_thread) {
|
||||||
cnt = syscall_cp(SYS_writev, f->fd, iov, iovcnt);
|
pthread_cleanup_push(cleanup, f);
|
||||||
pthread_cleanup_pop(0);
|
cnt = syscall_cp(SYS_writev, f->fd, iov, iovcnt);
|
||||||
|
pthread_cleanup_pop(0);
|
||||||
|
} else {
|
||||||
|
cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
|
||||||
|
}
|
||||||
if (cnt == rem) {
|
if (cnt == rem) {
|
||||||
f->wend = f->buf + f->buf_size;
|
f->wend = f->buf + f->buf_size;
|
||||||
f->wpos = f->wbase = f->buf;
|
f->wpos = f->wbase = f->buf;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue