summaryrefslogtreecommitdiff
path: root/hurd
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-03-04 22:45:04 +0000
committerRoland McGrath <roland@gnu.org>1996-03-04 22:45:04 +0000
commitc3d3967cd2a9ebf8bd312ca5be09b6a844f3edf5 (patch)
tree36ca152b786abb7f1ce91792207b431d8108bd78 /hurd
parent661fa1767388fa7bd859d5fe5497df6794ea1dad (diff)
Mon Mar 4 17:35:09 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* hurd/catch-signal.c (hurd_safe_memmove): New function. (hurd_safe_copyin, hurd_safe_copyout): New functions. * hurd/hurd/sigpreempt.h: Declare them.
Diffstat (limited to 'hurd')
-rw-r--r--hurd/catch-signal.c79
-rw-r--r--hurd/hurd/sigpreempt.h14
2 files changed, 92 insertions, 1 deletions
diff --git a/hurd/catch-signal.c b/hurd/catch-signal.c
index 3e8ee6c7e2..c148193f71 100644
--- a/hurd/catch-signal.c
+++ b/hurd/catch-signal.c
@@ -85,3 +85,82 @@ hurd_safe_memset (void *dest, int byte, size_t nbytes)
(vm_address_t) dest, (vm_address_t) dest + nbytes,
&operate, SIG_ERR);
}
+
+
+error_t
+hurd_safe_copyout (void *dest, const void *src, size_t nbytes)
+{
+ error_t operate (struct hurd_signal_preempter *preempter)
+ {
+ memcpy (dest, src, nbytes);
+ return 0;
+ }
+ return hurd_catch_signal (sigmask (SIGBUS) | sigmask (SIGSEGV),
+ (vm_address_t) dest, (vm_address_t) dest + nbytes,
+ &operate, SIG_ERR);
+}
+
+error_t
+hurd_safe_copyin (void *dest, const void *src, size_t nbytes)
+{
+ error_t operate (struct hurd_signal_preempter *preempter)
+ {
+ memcpy (dest, src, nbytes);
+ return 0;
+ }
+ return hurd_catch_signal (sigmask (SIGBUS) | sigmask (SIGSEGV),
+ (vm_address_t) src, (vm_address_t) src + nbytes,
+ &operate, SIG_ERR);
+}
+
+error_t
+hurd_safe_memmove (void *dest, const void *src, size_t nbytes)
+{
+ jmp_buf buf;
+ void throw (int signo, long int sigcode, struct sigcontext *scp)
+ { longjmp (buf, scp->sc_error ?: EGRATUITOUS); }
+
+ struct hurd_signal_preempter src_preempter =
+ {
+ sigmask (SIGBUS) | sigmask (SIGSEGV),
+ (vm_address_t) src, (vm_address_t) src + nbytes,
+ NULL, (sighandler_t) &throw,
+ };
+ struct hurd_signal_preempter dest_preempter =
+ {
+ sigmask (SIGBUS) | sigmask (SIGSEGV),
+ (vm_address_t) dest, (vm_address_t) dest + nbytes,
+ NULL, (sighandler_t) &throw,
+ &src_preempter
+ };
+
+ struct hurd_sigstate *const ss = _hurd_self_sigstate ();
+ error_t error;
+
+ /* This returns again with nonzero value when we preempt a signal. */
+ error = setjmp (buf);
+
+ if (error == 0)
+ {
+ /* Install a signal preempter for the thread. */
+ __spin_lock (&ss->lock);
+ src_preempter.next = ss->preempters;
+ ss->preempters = &dest_preempter;
+ __spin_unlock (&ss->lock);
+
+ /* Do the copy; it might fault. */
+ memmove (dest, src, nbytes);
+ }
+
+ /* Either memmove completed happily and ERROR is still zero, or it hit
+ an expected signal and `throw' made setjmp return the signal error
+ code in ERROR. Now we can remove the preempter and return. */
+
+ __spin_lock (&ss->lock);
+ assert (ss->preempters == &dest_preempter);
+ ss->preempters = src_preempter.next;
+ __spin_unlock (&ss->lock);
+
+ return error;
+}
+
diff --git a/hurd/hurd/sigpreempt.h b/hurd/hurd/sigpreempt.h
index eed67b2e94..4042ea2448 100644
--- a/hurd/hurd/sigpreempt.h
+++ b/hurd/hurd/sigpreempt.h
@@ -83,8 +83,20 @@ error_t hurd_catch_signal (sigset_t sigset,
/* Convenience functions using `hurd_catch_signal'. */
-error_t hurd_safe_memmove (void *dest, const void *src, size_t nbytes);
+
+/* Like `memset', but catch faults in DEST. */
error_t hurd_safe_memset (void *dest, int byte, size_t nbytes);
+/* Like `memcpy', but catch faults in SRC. */
+error_t hurd_safe_copyin (void *dest, const void *src, size_t nbytes);
+
+/* Like `memcpy', but catch faults in DEST. */
+error_t hurd_safe_copyout (void *dest, const void *src, size_t nbytes);
+
+/* Like `memmove', but catch faults in SRC or DEST.
+ If only one region is expected to fault, it is more efficient
+ to use `hurd_safe_copyin' or `hurd_safe_copyout' as appropriate. */
+error_t hurd_safe_memmove (void *dest, const void *src, size_t nbytes);
+
#endif /* hurd/sigpreempt.h */