1bcopy(9F)                Kernel Functions for Drivers                bcopy(9F)
2
3
4

NAME

6       bcopy - copy data between address locations in the kernel
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/sunddi.h>
11
12
13
14
15       void bcopy(const void *from, void *to, size_t bcount);
16
17

INTERFACE LEVEL

19       Architecture independent level 1 (DDI/DKI).
20

PARAMETERS

22       from      Source address from which the copy is made.
23
24
25       to        Destination address to which copy is made.
26
27
28       bcount    The number of bytes moved.
29
30

DESCRIPTION

32       The  bcopy()  function  copies  bcount bytes from one kernel address to
33       another. If the input and output addresses overlap,  the  command  exe‐
34       cutes, but the results may not be as expected.
35
36
37       Note that bcopy() should never be used to move data in or out of a user
38       buffer, because it has no provision for handling page faults. The  user
39       address  space  can  be  swapped  out  at  any time, and bcopy() always
40       assumes that there will be no paging faults.  If  bcopy()  attempts  to
41       access  the  user buffer when it is swapped out, the system will panic.
42       It is safe to use bcopy() to move data within kernel space, since  ker‐
43       nel space is never swapped out.
44

CONTEXT

46       The bcopy() function can be called from user, interrupt, or kernel con‐
47       text.
48

EXAMPLES

50       Example 1 Copying data between address locations in the kernel:
51
52
53       An I/O request is made for data stored in a RAM disk. If the I/O opera‐
54       tion  is a read request, the data is copied from the RAM disk to a buf‐
55       fer (line 8).  If it is a write request, the data is copied from a buf‐
56       fer  to the RAM disk (line 15). bcopy() is used since both the RAM disk
57       and the buffer are part of the kernel address space.
58
59
60          1 #define RAMDNBLK 1000                /* blocks in the RAM disk */
61          2 #define RAMDBSIZ 512                 /* bytes per block */
62          3 char ramdblks[RAMDNBLK][RAMDBSIZ];   /* blocks forming RAM
63                                                 /* disk
64                 ...
65          4
66          5 if   (bp->b_flags & B_READ)      /* if read request, copy data */
67          6                                  /* from RAM disk data block */
68          7                                  /* to system buffer */
69          8           bcopy(&ramdblks[bp->b_blkno][0], bp->b_un.b_addr,
70          9               bp->b_bcount);
71         10
72         11 else                             /* else write request, */
73         12                                  /* copy data from a */
74         13                                  /* system buffer to RAM disk */
75         14                                  /* data block */
76         15           bcopy(bp->b_un.b_addr, &ramdblks[bp->b_blkno][0],
77         16               bp->b_bcount);
78
79

SEE ALSO

81       copyin(9F), copyout(9F)
82
83
84       Writing Device Drivers
85

WARNINGS

87       The from and to addresses must be within the  kernel  space.  No  range
88       checking  is  done.  If  an  address  outside  of  the  kernel space is
89       selected, the driver may corrupt the system in an unpredictable way.
90
91
92
93SunOS 5.11                        16 Jan 2006                        bcopy(9F)
Impressum