-.\" $OpenBSD: copy.9,v 1.17 2015/11/23 17:53:57 jmc Exp $
+.\" $OpenBSD: copy.9,v 1.18 2023/01/06 19:10:18 miod Exp $
.\" $NetBSD: copy.9,v 1.2 1996/01/09 03:23:04 thorpej Exp $
.\"
.\" Copyright (c) 1996 Jason R. Thorpe.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: November 23 2015 $
+.Dd $Mdocdate: January 6 2023 $
.Dt COPYIN 9
.Os
.Sh NAME
.Nm copyin ,
.Nm copyout ,
-.Nm copystr ,
.Nm copyinstr ,
.Nm copyoutstr ,
.Nm kcopy
.Ft int
.Fn copyout "const void *kaddr" "void *uaddr" "size_t len"
.Ft int
-.Fn copystr "const void *kfaddr" "void *kdaddr" "size_t len" "size_t *done"
-.Ft int
.Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done"
.Ft int
.Fn copyoutstr "const void *kaddr" "void *uaddr" "size_t len" "size_t *done"
.Nm
functions are designed to copy contiguous data from one address to another.
All but
-.Fn copystr
-and
.Fn kcopy
copy data from user-space to kernel-space or vice-versa.
.Pp
.Fa kaddr
to the user-space address
.Fa uaddr .
-.It Fn copystr
-Copies a null-terminated string, at most
-.Fa len
-bytes long, from kernel-space address
-.Fa kfaddr
-to kernel-space address
-.Fa kdaddr .
-The number of bytes actually copied, including the terminating null,
-is returned in
-.Fa *done ,
-if
-.Fa done
-is not
-.Dv NULL .
-.Pp
-Unlike the other
-.Nm
-functions,
-.Fn copystr
-does
-.Em not
-support returning
-.Er EFAULT
-when a bad address is encountered.
.It Fn copyinstr
Copies a null-terminated string, at most
.Fa len
.Er EFAULT
if a bad address is encountered.
In addition, the
-.Fn copystr ,
-.Fn copyinstr ,
+.Fn copyinstr
and
.Fn copyoutstr
functions return
-/* $OpenBSD: locore.s,v 1.49 2022/10/25 15:15:38 guenther Exp $ */
+/* $OpenBSD: locore.s,v 1.50 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: locore.s,v 1.94 2001/04/26 03:10:44 ross Exp $ */
/*-
*
* int copystr(char *from, char *to, size_t len, size_t *lenp);
*/
-LEAF(copystr, 4)
+STATIC_LEAF(copystr, 4)
LDGP(pv)
mov a2, t0 /* t0 = i = len */
-/* $OpenBSD: copy.S,v 1.16 2022/12/01 00:26:15 guenther Exp $ */
+/* $OpenBSD: copy.S,v 1.17 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: copy.S,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
/*
ret
lfence
-ENTRY(copystr)
- RETGUARD_SETUP(copystr, r10)
- xchgq %rdi,%rsi
- movq %rdx,%r8
-
- incq %rdx
-
-1: decq %rdx
- jz 4f
- lodsb
- stosb
- testb %al,%al
- jnz 1b
-
- /* Success -- 0 byte reached. */
- decq %rdx
- xorl %eax,%eax
- jmp 6f
-
-4: /* edx is zero -- return ENAMETOOLONG. */
- movl $ENAMETOOLONG,%eax
-
-6: /* Set *lencopied and return %eax. */
- testq %rcx,%rcx
- jz 7f
- subq %rdx,%r8
- movq %r8,(%rcx)
-7:
- RETGUARD_CHECK(copystr, r10)
- ret
- lfence
-
.section .rodata
.globl _stac
_stac:
-/* $OpenBSD: copystr.S,v 1.10 2022/12/08 01:25:44 guenther Exp $ */
+/* $OpenBSD: copystr.S,v 1.11 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: copystr.S,v 1.8 2002/10/13 14:54:48 bjh21 Exp $ */
/*
.word cpu_info_primary
#endif
-/*
- * r0 - from
- * r1 - to
- * r2 - maxlens
- * r3 - lencopied
- *
- * Copy string from r0 to r1
- */
-ENTRY(copystr)
- stmfd sp!, {r4-r5} /* stack is 8 byte aligned */
- teq r2, #0x00000000
- mov r5, #0x00000000
- moveq r0, #ENAMETOOLONG
- beq 2f
-
-1: ldrb r4, [r0], #0x0001
- add r5, r5, #0x00000001
- teq r4, #0x00000000
- strb r4, [r1], #0x0001
- teqne r5, r2
- bne 1b
-
- teq r4, #0x00000000
- moveq r0, #0x00000000
- movne r0, #ENAMETOOLONG
-
-2: teq r3, #0x00000000
- strne r5, [r3]
-
- ldmfd sp!, {r4-r5} /* stack is 8 byte aligned */
- mov pc, lr
-
#define SAVE_REGS stmfd sp!, {r4-r6}
#define RESTORE_REGS ldmfd sp!, {r4-r6}
-/* $OpenBSD: copystr.S,v 1.7 2020/10/20 23:21:41 patrick Exp $ */
+/* $OpenBSD: copystr.S,v 1.8 2023/01/06 19:10:18 miod Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
.align 2
/*
- * x0 - from
- * x1 - to
+ * x0 - user space address
+ * x1 - kernel space address
* x2 - maxlens
* x3 - lencopied
- * x4 - scratch
- * x5 - hold old onfault
*
- * Copy string from x0 to x1
+ * Copy string from user space to kernel space
*/
-ENTRY(copystr)
+ENTRY(copyinstr)
RETGUARD_SETUP(copystr, x15)
mrs x6, tpidr_el1 // load curcpu
ldr x6, [x6, #(CI_CURPCB)]
mov x8, xzr
cbz x2, 2f
-1: ldrb w4, [x0], 1
+1: tst x0, #(1ULL << 63)
+ b.ne .Lcopystrfault
+ ldtrb w4, [x0]
strb w4, [x1], #1
+ add x0, x0, #1
sub x2, x2, #1
add x8, x8, #1
cbz w4, .Lcopystrsuccess
RETGUARD_CHECK(copystr, x15)
ret
-/*
- * x0 - user space address
- * x1 - kernel space address
- * x2 - maxlens
- * x3 - lencopied
- *
- * Copy string from user space to kernel space
- */
-ENTRY(copyinstr)
- RETGUARD_SETUP(copystr, x15)
- mrs x6, tpidr_el1 // load curcpu
- ldr x6, [x6, #(CI_CURPCB)]
- ldr x5, [x6, #(PCB_ONFAULT)]
- adr x7, .Lcopystrfault
- str x7, [x6, #(PCB_ONFAULT)] // set handler
-
- mov x8, xzr
- cbz x2, 2f
-
-1: tst x0, #(1ULL << 63)
- b.ne .Lcopystrfault
- ldtrb w4, [x0]
- strb w4, [x1], #1
- add x0, x0, #1
- sub x2, x2, #1
- add x8, x8, #1
- cbz w4, .Lcopystrsuccess
- cbnz x2, 1b
-
-2:
- mov x0, #ENAMETOOLONG
- b .Lcopystrcleanup
-
/*
* x0 - kernel space address
* x1 - user space address
-/* $OpenBSD: machdep.c,v 1.267 2022/10/30 17:43:39 guenther Exp $ */
+/* $OpenBSD: machdep.c,v 1.268 2023/01/06 19:10:18 miod Exp $ */
/*
* Copyright (c) 1999-2003 Michael Shalayeff
return spcopy(HPPA_SID_KERNEL, from, HPPA_SID_KERNEL, to, size);
}
-int
-copystr(const void *src, void *dst, size_t size, size_t *lenp)
-{
- if (size == 0)
- return ENAMETOOLONG;
- return spstrcpy(HPPA_SID_KERNEL, src, HPPA_SID_KERNEL, dst, size, lenp);
-}
-
int
copyinstr(const void *src, void *dst, size_t size, size_t *lenp)
{
-/* $OpenBSD: locore.s,v 1.198 2022/12/08 01:25:44 guenther Exp $ */
+/* $OpenBSD: locore.s,v 1.199 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: locore.s,v 1.145 1996/05/03 19:41:19 christos Exp $ */
/*-
#endif
ret
-/*
- * copystr(caddr_t from, caddr_t to, size_t maxlen, size_t *lencopied);
- * Copy a NUL-terminated string, at most maxlen characters long. Return the
- * number of characters copied (including the NUL) in *lencopied. If the
- * string is too long, return ENAMETOOLONG; else return 0.
- */
-ENTRY(copystr)
-#ifdef DDB
- pushl %ebp
- movl %esp,%ebp
-#endif
- pushl %esi
- pushl %edi
-
- movl 12+FPADD(%esp),%esi # esi = from
- movl 16+FPADD(%esp),%edi # edi = to
- movl 20+FPADD(%esp),%edx # edx = maxlen
- incl %edx
-
-1: decl %edx
- jz 4f
- lodsb
- stosb
- testb %al,%al
- jnz 1b
-
- /* Success -- 0 byte reached. */
- decl %edx
- xorl %eax,%eax
- jmp 6f
-
-4: /* edx is zero -- return ENAMETOOLONG. */
- movl $ENAMETOOLONG,%eax
-
-6: /* Set *lencopied and return %eax. */
- movl 20+FPADD(%esp),%ecx
- subl %edx,%ecx
- movl 24+FPADD(%esp),%edx
- testl %edx,%edx
- jz 7f
- movl %ecx,(%edx)
-
-7: popl %edi
- popl %esi
-#ifdef DDB
- leave
-#endif
- ret
-
/*****************************************************************************/
/*
-/* $OpenBSD: m88k_machdep.c,v 1.71 2022/10/30 17:43:39 guenther Exp $ */
+/* $OpenBSD: m88k_machdep.c,v 1.72 2023/01/06 19:10:18 miod Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
* Copyright (c) 1996 Nivas Madhur
tf->tf_r[31] = stack;
}
-int
-copystr(fromaddr, toaddr, maxlength, lencopied)
- const void *fromaddr;
- void *toaddr;
- size_t maxlength;
- size_t *lencopied;
-{
- u_int tally;
-
- tally = 0;
-
- while (maxlength--) {
- *(u_char *)toaddr = *(u_char *)fromaddr++;
- tally++;
- if (*(u_char *)toaddr++ == 0) {
- if (lencopied) *lencopied = tally;
- return (0);
- }
- }
-
- if (lencopied)
- *lencopied = tally;
-
- return (ENAMETOOLONG);
-}
-
#ifdef DDB
int longformat = 1;
void
-# $OpenBSD: files.powerpc,v 1.56 2022/10/22 00:58:56 gkoehler Exp $
+# $OpenBSD: files.powerpc,v 1.57 2023/01/06 19:10:18 miod Exp $
#
file arch/powerpc/powerpc/setjmp.S ddb
-file arch/powerpc/powerpc/copystr.c
file arch/powerpc/powerpc/cpu_subr.c
file arch/powerpc/powerpc/fpu.c
file arch/powerpc/powerpc/in_cksum.c
-/* $OpenBSD: copystr.c,v 1.8 2003/10/15 02:43:09 drahn Exp $ */
-
-/*-
- * Copyright (C) 1995 Wolfgang Solfrank.
- * Copyright (C) 1995 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/systm.h>
-
-/*
- * Emulate copystr.
- */
-int
-copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
-{
- u_char *kfp = (u_char *)kfaddr;
- u_char *kdp = kdaddr;
- size_t l;
-
- for (l = 0; len-- > 0; l++) {
- if (!(*kdp++ = *kfp++)) {
- if (done)
- *done = l + 1;
- return (0);
- }
- }
- if (done)
- *done = l;
- return (ENAMETOOLONG);
-}
-/* $OpenBSD: copystr.S,v 1.4 2021/06/28 18:53:10 deraadt Exp $ */
+/* $OpenBSD: copystr.S,v 1.5 2023/01/06 19:10:18 miod Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
.text
/*
- * a0 - from
- * a1 - to
+ * a0 - user space address
+ * a1 - kernel space address
* a2 - maxlens
* a3 - lencopied
*
- * Copy string from a0 to a1
+ * Copy string from user space to kernel space
*/
-ENTRY(copystr)
+ENTRY(copyinstr)
RETGUARD_SETUP(copyiostr, a6)
beqz a2, .Lcopyiostrtoolong_early
- la a4, .Lcopyiostrfault
+ la a4, .Lcopyiostrfault_user
SWAP_FAULT_HANDLER(a4, t0, t1)
+ ENTER_USER_ACCESS(t0)
mv a5, x0
-1: lb t0, 0(a0)
+ li t1, VM_MAXUSER_ADDRESS
+1: bgtu a0, t1, .Lcopyiostrfault_user
+ lb t0, 0(a0)
addi a0, a0, 1
sb t0, 0(a1)
addi a1, a1, 1
addi a2, a2, -1
addi a5, a5, 1
- beqz t0, .Lcopyiostrsuccess
+ beqz t0, .Lcopyiostrsuccess_user
bnez a2, 1b
.Lcopyiostrtoolong_user:
RETGUARD_CHECK(copyiostr, a6)
ret
-/*
- * a0 - user space address
- * a1 - kernel space address
- * a2 - maxlens
- * a3 - lencopied
- *
- * Copy string from user space to kernel space
- */
-ENTRY(copyinstr)
- RETGUARD_SETUP(copyiostr, a6)
- beqz a2, .Lcopyiostrtoolong_early
- la a4, .Lcopyiostrfault_user
- SWAP_FAULT_HANDLER(a4, t0, t1)
- ENTER_USER_ACCESS(t0)
-
- mv a5, x0
-
- li t1, VM_MAXUSER_ADDRESS
-1: bgtu a0, t1, .Lcopyiostrfault_user
- lb t0, 0(a0)
- addi a0, a0, 1
- sb t0, 0(a1)
- addi a1, a1, 1
- addi a2, a2, -1
- addi a5, a5, 1
- beqz t0, .Lcopyiostrsuccess_user
- bnez a2, 1b
-
- j .Lcopyiostrtoolong_user
END(copyinstr)
/*
-/* $OpenBSD: locore_c.c,v 1.13 2020/09/25 14:42:25 deraadt Exp $ */
+/* $OpenBSD: locore_c.c,v 1.14 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: locore_c.c,v 1.13 2006/03/04 01:13:35 uwe Exp $ */
/*-
}
#endif /* SH4 */
#endif /* !P1_STACK */
-
-/*
- * copystr(caddr_t from, caddr_t to, size_t maxlen, size_t *lencopied);
- * Copy a NUL-terminated string, at most maxlen characters long. Return the
- * number of characters copied (including the NUL) in *lencopied. If the
- * string is too long, return ENAMETOOLONG; else return 0.
- */
-int
-copystr(const void *kfaddr, void *kdaddr, size_t maxlen, size_t *lencopied)
-{
- const char *from = kfaddr;
- char *to = kdaddr;
- int i;
-
- for (i = 0; maxlen-- > 0; i++) {
- if ((*to++ = *from++) == '\0') {
- if (lencopied)
- *lencopied = i + 1;
- return (0);
- }
- }
-
- if (lencopied)
- *lencopied = i;
-
- return (ENAMETOOLONG);
-}
-/* $OpenBSD: locore.s,v 1.196 2022/12/29 22:44:23 cheloha Exp $ */
+/* $OpenBSD: locore.s,v 1.197 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: locore.s,v 1.137 2001/08/13 06:10:10 jdolecek Exp $ */
/*
b Lcsdone ! error = EFAULT;
mov EFAULT, %o0 ! goto ret;
-/*
- * copystr(fromaddr, toaddr, maxlength, &lencopied)
- *
- * Copy a null terminated string from one point to another in
- * the kernel address space. (This is a leaf procedure, but
- * it does not seem that way to the C compiler.)
- */
-ENTRY(copystr)
- brgz,pt %o2, 0f ! Make sure len is valid
- mov %o1, %o5 ! to0 = to;
- retl
- mov ENAMETOOLONG, %o0
-0: ! loop:
- ldsb [%o0], %o4 ! c = *from;
- tst %o4
- stb %o4, [%o1] ! *to++ = c;
- be 1f ! if (c == 0)
- inc %o1 ! goto ok;
- deccc %o2 ! if (--len > 0) {
- bg,a 0b ! from++;
- inc %o0 ! goto loop;
- b 2f ! }
- mov ENAMETOOLONG, %o0 ! ret = ENAMETOOLONG; goto done;
-1: ! ok:
- clr %o0 ! ret = 0;
-2:
- sub %o1, %o5, %o1 ! len = to - to0;
- tst %o3 ! if (lencopied)
- bnz,a 3f
- stx %o1, [%o3] ! *lencopied = len;
-3:
- retl
- nop
-#ifdef DIAGNOSTIC
-4:
- sethi %hi(5f), %o0
- call panic
- or %lo(5f), %o0, %o0
- .data
-5:
- .asciz "copystr"
- _ALIGN
- .text
-#endif /* DIAGNOSTIC */
-
/*
* copyin(src, dst, len)
*
-/* $OpenBSD: systm.h,v 1.159 2022/09/03 15:29:44 kettenis Exp $ */
+/* $OpenBSD: systm.h,v 1.160 2023/01/06 19:10:18 miod Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
void *memset(void *, int, size_t)
__attribute__ ((__bounded__(__buffer__,1,3)));
-int copystr(const void *, void *, size_t, size_t *)
- __attribute__ ((__bounded__(__string__,2,3)));
int copyinstr(const void *, void *, size_t, size_t *)
__attribute__ ((__bounded__(__string__,2,3)));
int copyoutstr(const void *, void *, size_t, size_t *);