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

NAME

6       copyin - copy data from a user program to a driver buffer
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/ddi.h>
11
12
13
14       int copyin(const void *userbuf, void *driverbuf, size_t cn);
15
16

INTERFACE LEVEL

18       This interface is obsolete. ddi_copyin(9F) should be used instead.
19

PARAMETERS

21       userbuf       User  program  source  address  from which data is trans‐
22                     ferred.
23
24
25       driverbuf     Driver destination address to which data is transferred.
26
27
28       cn            Number of bytes transferred.
29
30

DESCRIPTION

32       copyin() copies data from a user program source  address  to  a  driver
33       buffer.   The driver developer must ensure that adequate space is allo‐
34       cated for the destination address.
35
36
37       Addresses that are word-aligned are moved most  efficiently.   However,
38       the  driver developer is not obligated to ensure alignment.  This func‐
39       tion automatically finds the most efficient move according  to  address
40       alignment.
41

RETURN VALUES

43       Under  normal conditions, a 0 is returned indicating a successful copy.
44       Otherwise, a −1 is returned if one of the following occurs:
45
46           o      Paging fault; the driver tried to access a  page  of  memory
47                  for which it did not have read or write access.
48
49           o      Invalid user address, such as a user area or stack area.
50
51           o      Invalid  address  that  would  have  resulted  in data being
52                  copied into the user block.
53
54           o      Hardware fault; a hardware error  prevented  access  to  the
55                  specified  user memory. For example, an uncorrectable parity
56                  or ECC error occurred.
57
58
59       If a −1 is returned to the caller, driver entry point  routines  should
60       return EFAULT.
61

CONTEXT

63       copyin() can be called from user context only.
64

EXAMPLES

66       Example 1 An ioctl() Routine
67
68
69       A  driver  ioctl(9E) routine (line 10) can be used to get or set device
70       attributes or registers. In the XX_GETREGS  condition  (line  17),  the
71       driver  copies  the  current device register values to a user data area
72       (line 18).  If the specified argument contains an invalid  address,  an
73       error code is returned.
74
75
76
77          1  struct device  {         /* layout of physical device registers  */
78          2       int      control;   /* physical device control word  */
79          3       int      status;    /* physical device status word   */
80          4       short    recv_char; /* receive character from device */
81          5       short    xmit_char; /* transmit character to device  */
82          6  };
83          7
84          8  extern struct device xx_addr[];   /* phys. device regs. location */
85          9    . . .
86         10  xx_ioctl(dev_t dev, int cmd, int arg, int mode,
87         11      cred_t *cred_p, int *rval_p)
88         12               ...
89         13  {
90         14      register struct device *rp = &xx_addr[getminor(dev) >> 4];
91         15      switch (cmd) {
92         16
93         17      case XX_GETREGS: /* copy device regs. to user program */
94         18            if (copyin(arg, rp, sizeof(struct device)))
95         19                return(EFAULT);
96         20            break;
97         21               ...
98         22      }
99         23               ...
100         24  }
101
102

ATTRIBUTES

104       See attributes(5) for a description of the following attributes:
105
106
107
108
109       ┌─────────────────────────────┬─────────────────────────────┐
110ATTRIBUTE TYPE         ATTRIBUTE VALUE        
111       ├─────────────────────────────┼─────────────────────────────┤
112       │Stability Level              │Obsolete                     │
113       └─────────────────────────────┴─────────────────────────────┘
114

SEE ALSO

116       attributes(5),   ioctl(9E),   bcopy(9F),  copyout(9F),  ddi_copyin(9F),
117       ddi_copyout(9F), uiomove(9F).
118
119
120       Writing Device Drivers
121

NOTES

123       Driver writers who intend to support layered ioctls in their  ioctl(9E)
124       routines should use ddi_copyin(9F) instead.
125
126
127       Driver defined locks should not be held across calls to this function.
128
129
130       copyin()  should  not  be  used from a streams driver. See M_COPYIN and
131       M_COPYOUT in STREAMS Programming Guide.
132
133
134
135SunOS 5.11                        27 Sep 2002                       copyin(9F)
Impressum