Deleted Added
full compact
thr_syscalls.c (276681) thr_syscalls.c (277032)
1/*
2 * Copyright (c) 2014 The FreeBSD Foundation.
3 * Copyright (C) 2005 David Xu <davidxu@freebsd.org>.
4 * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>.
5 * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
6 * All rights reserved.
7 *
8 * Portions of this software were developed by Konstantin Belousov

--- 50 unchanged lines hidden (view full) ---

59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 */
65
66#include <sys/cdefs.h>
1/*
2 * Copyright (c) 2014 The FreeBSD Foundation.
3 * Copyright (C) 2005 David Xu <davidxu@freebsd.org>.
4 * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>.
5 * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
6 * All rights reserved.
7 *
8 * Portions of this software were developed by Konstantin Belousov

--- 50 unchanged lines hidden (view full) ---

59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 */
65
66#include <sys/cdefs.h>
67__FBSDID("$FreeBSD: head/lib/libthr/thread/thr_syscalls.c 276681 2015-01-05 01:06:54Z kib $");
67__FBSDID("$FreeBSD: head/lib/libthr/thread/thr_syscalls.c 277032 2015-01-11 22:16:31Z kib $");
68
69#include "namespace.h"
70#include <sys/types.h>
71#include <sys/mman.h>
72#include <sys/param.h>
73#include <sys/select.h>
74#include <sys/signalvar.h>
75#include <sys/socket.h>

--- 18 unchanged lines hidden (view full) ---

94
95#include "libc_private.h"
96#include "thr_private.h"
97
98#ifdef SYSCALL_COMPAT
99extern int __fcntl_compat(int, int, ...);
100#endif
101
68
69#include "namespace.h"
70#include <sys/types.h>
71#include <sys/mman.h>
72#include <sys/param.h>
73#include <sys/select.h>
74#include <sys/signalvar.h>
75#include <sys/socket.h>

--- 18 unchanged lines hidden (view full) ---

94
95#include "libc_private.h"
96#include "thr_private.h"
97
98#ifdef SYSCALL_COMPAT
99extern int __fcntl_compat(int, int, ...);
100#endif
101
102/*
103 * Cancellation behavior:
104 * If thread is canceled, no socket is created.
105 */
106static int
107__thr_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
108{
109 struct pthread *curthread;
110 int ret;
111
112 curthread = _get_curthread();
113 _thr_cancel_enter(curthread);

--- 70 unchanged lines hidden (view full) ---

184 curthread = _get_curthread();
185 _thr_cancel_enter(curthread);
186 ret = __sys_connect(fd, name, namelen);
187 _thr_cancel_leave(curthread, ret == -1);
188
189 return (ret);
190}
191
102static int
103__thr_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
104{
105 struct pthread *curthread;
106 int ret;
107
108 curthread = _get_curthread();
109 _thr_cancel_enter(curthread);

--- 70 unchanged lines hidden (view full) ---

180 curthread = _get_curthread();
181 _thr_cancel_enter(curthread);
182 ret = __sys_connect(fd, name, namelen);
183 _thr_cancel_leave(curthread, ret == -1);
184
185 return (ret);
186}
187
192
193/*
194 * Cancellation behavior:
188/*
189 * Cancellation behavior:
195 * If thread is canceled, file is not created.
196 */
197static int
198__thr_creat(const char *path, mode_t mode)
199{
200 struct pthread *curthread;
201 int ret;
202
203 curthread = _get_curthread();
204 _thr_cancel_enter(curthread);
205 ret = __libc_creat(path, mode);
206 _thr_cancel_leave(curthread, ret == -1);
207
208 return (ret);
209}
210
211/*
212 * Cancellation behavior:
213 * According to specification, only F_SETLKW is a cancellation point.
214 * Thread is only canceled at start, or canceled if the system call
215 * is failure, this means the function does not generate side effect
216 * if it is canceled.
217 */
218static int
219__thr_fcntl(int fd, int cmd, ...)
220{

--- 74 unchanged lines hidden (view full) ---

295 return (ret);
296}
297
298/*
299 * Cancellation behavior:
300 * If the thread is canceled, file is not opened.
301 */
302static int
190 * According to specification, only F_SETLKW is a cancellation point.
191 * Thread is only canceled at start, or canceled if the system call
192 * is failure, this means the function does not generate side effect
193 * if it is canceled.
194 */
195static int
196__thr_fcntl(int fd, int cmd, ...)
197{

--- 74 unchanged lines hidden (view full) ---

272 return (ret);
273}
274
275/*
276 * Cancellation behavior:
277 * If the thread is canceled, file is not opened.
278 */
279static int
303__thr_open(const char *path, int flags,...)
304{
305 struct pthread *curthread;
306 int mode, ret;
307 va_list ap;
308
309 /* Check if the file is being created: */
310 if ((flags & O_CREAT) != 0) {
311 /* Get the creation mode: */
312 va_start(ap, flags);
313 mode = va_arg(ap, int);
314 va_end(ap);
315 } else {
316 mode = 0;
317 }
318
319 curthread = _get_curthread();
320 _thr_cancel_enter(curthread);
321 ret = __sys_open(path, flags, mode);
322 _thr_cancel_leave(curthread, ret == -1);
323
324 return (ret);
325}
326
327/*
328 * Cancellation behavior:
329 * If the thread is canceled, file is not opened.
330 */
331static int
332__thr_openat(int fd, const char *path, int flags, ...)
333{
334 struct pthread *curthread;
335 int mode, ret;
336 va_list ap;
337
338
339 /* Check if the file is being created: */

--- 178 unchanged lines hidden (view full) ---

518
519 curthread = _get_curthread();
520 _thr_cancel_enter(curthread);
521 ret = __sys_sendto(s, m, l, f, t, tl);
522 _thr_cancel_leave(curthread, ret <= 0);
523 return (ret);
524}
525
280__thr_openat(int fd, const char *path, int flags, ...)
281{
282 struct pthread *curthread;
283 int mode, ret;
284 va_list ap;
285
286
287 /* Check if the file is being created: */

--- 178 unchanged lines hidden (view full) ---

466
467 curthread = _get_curthread();
468 _thr_cancel_enter(curthread);
469 ret = __sys_sendto(s, m, l, f, t, tl);
470 _thr_cancel_leave(curthread, ret <= 0);
471 return (ret);
472}
473
526static unsigned int
527__thr_sleep(unsigned int seconds)
528{
529 struct pthread *curthread;
530 unsigned int ret;
531
532 curthread = _get_curthread();
533 _thr_cancel_enter(curthread);
534 ret = __libc_sleep(seconds);
535 _thr_cancel_leave(curthread, 1);
536 return (ret);
537}
538
539static int
540__thr_system(const char *string)
541{
542 struct pthread *curthread;
543 int ret;
544
545 curthread = _get_curthread();
546 _thr_cancel_enter(curthread);

--- 15 unchanged lines hidden (view full) ---

562
563 curthread = _get_curthread();
564 _thr_cancel_enter(curthread);
565 ret = __libc_tcdrain(fd);
566 _thr_cancel_leave(curthread, ret == -1);
567 return (ret);
568}
569
474static int
475__thr_system(const char *string)
476{
477 struct pthread *curthread;
478 int ret;
479
480 curthread = _get_curthread();
481 _thr_cancel_enter(curthread);

--- 15 unchanged lines hidden (view full) ---

497
498 curthread = _get_curthread();
499 _thr_cancel_enter(curthread);
500 ret = __libc_tcdrain(fd);
501 _thr_cancel_leave(curthread, ret == -1);
502 return (ret);
503}
504
570static int
571__thr_usleep(useconds_t useconds)
572{
573 struct pthread *curthread;
574 int ret;
575
576 curthread = _get_curthread();
577 _thr_cancel_enter(curthread);
578 ret = __libc_usleep(useconds);
579 _thr_cancel_leave(curthread, 1);
580 return (ret);
581}
582
583/*
584 * Cancellation behavior:
585 * Thread may be canceled at start, but if the system call returns
586 * a child pid, the thread is not canceled.
587 */
588static pid_t
505/*
506 * Cancellation behavior:
507 * Thread may be canceled at start, but if the system call returns
508 * a child pid, the thread is not canceled.
509 */
510static pid_t
589__thr_wait(int *istat)
590{
591 struct pthread *curthread;
592 pid_t ret;
593
594 curthread = _get_curthread();
595 _thr_cancel_enter(curthread);
596 ret = __libc_wait(istat);
597 _thr_cancel_leave(curthread, ret <= 0);
598 return (ret);
599}
600
601/*
602 * Cancellation behavior:
603 * Thread may be canceled at start, but if the system call returns
604 * a child pid, the thread is not canceled.
605 */
606static pid_t
607__thr_wait3(int *status, int options, struct rusage *rusage)
608{
609 struct pthread *curthread;
610 pid_t ret;
611
612 curthread = _get_curthread();
613 _thr_cancel_enter(curthread);
614 ret = __libc_wait3(status, options, rusage);
615 _thr_cancel_leave(curthread, ret <= 0);
616 return (ret);
617}
618
619/*
620 * Cancellation behavior:
621 * Thread may be canceled at start, but if the system call returns
622 * a child pid, the thread is not canceled.
623 */
624static pid_t
625__thr_wait4(pid_t pid, int *status, int options, struct rusage *rusage)
626{
627 struct pthread *curthread;
628 pid_t ret;
629
630 curthread = _get_curthread();
631 _thr_cancel_enter(curthread);
632 ret = __sys_wait4(pid, status, options, rusage);
633 _thr_cancel_leave(curthread, ret <= 0);
634 return (ret);
635}
636
637/*
638 * Cancellation behavior:
511__thr_wait4(pid_t pid, int *status, int options, struct rusage *rusage)
512{
513 struct pthread *curthread;
514 pid_t ret;
515
516 curthread = _get_curthread();
517 _thr_cancel_enter(curthread);
518 ret = __sys_wait4(pid, status, options, rusage);
519 _thr_cancel_leave(curthread, ret <= 0);
520 return (ret);
521}
522
523/*
524 * Cancellation behavior:
639 * Thread may be canceled at start, but if the system call returns
640 * a child pid, the thread is not canceled.
641 */
642static pid_t
643__thr_waitpid(pid_t wpid, int *status, int options)
644{
645 struct pthread *curthread;
646 pid_t ret;
647
648 curthread = _get_curthread();
649 _thr_cancel_enter(curthread);
650 ret = __libc_waitpid(wpid, status, options);
651 _thr_cancel_leave(curthread, ret <= 0);
652 return (ret);
653}
654
655/*
656 * Cancellation behavior:
657 * Thread may be canceled at start, but if the thread wrote some data,
658 * it is not canceled.
659 */
660static ssize_t
661__thr_write(int fd, const void *buf, size_t nbytes)
662{
663 struct pthread *curthread;
664 ssize_t ret;

--- 31 unchanged lines hidden (view full) ---

696#define SLOT(name) \
697 *(__libc_interposing_slot(INTERPOS_##name)) = \
698 (interpos_func_t)__thr_##name;
699 SLOT(accept);
700 SLOT(accept4);
701 SLOT(aio_suspend);
702 SLOT(close);
703 SLOT(connect);
525 * Thread may be canceled at start, but if the thread wrote some data,
526 * it is not canceled.
527 */
528static ssize_t
529__thr_write(int fd, const void *buf, size_t nbytes)
530{
531 struct pthread *curthread;
532 ssize_t ret;

--- 31 unchanged lines hidden (view full) ---

564#define SLOT(name) \
565 *(__libc_interposing_slot(INTERPOS_##name)) = \
566 (interpos_func_t)__thr_##name;
567 SLOT(accept);
568 SLOT(accept4);
569 SLOT(aio_suspend);
570 SLOT(close);
571 SLOT(connect);
704 SLOT(creat);
705 SLOT(fcntl);
706 SLOT(fsync);
707 SLOT(fork);
708 SLOT(msync);
709 SLOT(nanosleep);
572 SLOT(fcntl);
573 SLOT(fsync);
574 SLOT(fork);
575 SLOT(msync);
576 SLOT(nanosleep);
710 SLOT(open);
711 SLOT(openat);
712 SLOT(poll);
713 SLOT(pselect);
577 SLOT(openat);
578 SLOT(poll);
579 SLOT(pselect);
714 SLOT(raise);
715 SLOT(read);
716 SLOT(readv);
717 SLOT(recvfrom);
718 SLOT(recvmsg);
719 SLOT(select);
720 SLOT(sendmsg);
721 SLOT(sendto);
722 SLOT(setcontext);
723 SLOT(sigaction);
724 SLOT(sigprocmask);
725 SLOT(sigsuspend);
726 SLOT(sigwait);
727 SLOT(sigtimedwait);
728 SLOT(sigwaitinfo);
729 SLOT(swapcontext);
730 SLOT(system);
580 SLOT(read);
581 SLOT(readv);
582 SLOT(recvfrom);
583 SLOT(recvmsg);
584 SLOT(select);
585 SLOT(sendmsg);
586 SLOT(sendto);
587 SLOT(setcontext);
588 SLOT(sigaction);
589 SLOT(sigprocmask);
590 SLOT(sigsuspend);
591 SLOT(sigwait);
592 SLOT(sigtimedwait);
593 SLOT(sigwaitinfo);
594 SLOT(swapcontext);
595 SLOT(system);
731 SLOT(sleep);
732 SLOT(tcdrain);
596 SLOT(tcdrain);
733 SLOT(usleep);
734 SLOT(pause);
735 SLOT(wait);
736 SLOT(wait3);
737 SLOT(wait4);
597 SLOT(wait4);
738 SLOT(waitpid);
739 SLOT(write);
740 SLOT(writev);
741#undef SLOT
742 *(__libc_interposing_slot(
743 INTERPOS__pthread_mutex_init_calloc_cb)) =
744 (interpos_func_t)_pthread_mutex_init_calloc_cb;
745}
598 SLOT(write);
599 SLOT(writev);
600#undef SLOT
601 *(__libc_interposing_slot(
602 INTERPOS__pthread_mutex_init_calloc_cb)) =
603 (interpos_func_t)_pthread_mutex_init_calloc_cb;
604}