4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
35 * open() system call -- executed by subject process.
38 pr_open(struct ps_prochandle
*Pr
, const char *filename
, int flags
, mode_t mode
)
40 sysret_t rval
; /* return value from openat() */
41 argdes_t argd
[4]; /* arg descriptors for openat() */
45 if (Pr
== NULL
) /* no subject process */
46 return (open(filename
, flags
, mode
));
48 adp
= &argd
[0]; /* AT_FDCWD argument */
49 adp
->arg_value
= AT_FDCWD
;
50 adp
->arg_object
= NULL
;
51 adp
->arg_type
= AT_BYVAL
;
52 adp
->arg_inout
= AI_INPUT
;
55 adp
++; /* filename argument */
57 adp
->arg_object
= (void *)filename
;
58 adp
->arg_type
= AT_BYREF
;
59 adp
->arg_inout
= AI_INPUT
;
60 adp
->arg_size
= strlen(filename
)+1;
62 adp
++; /* flags argument */
63 adp
->arg_value
= (long)flags
;
64 adp
->arg_object
= NULL
;
65 adp
->arg_type
= AT_BYVAL
;
66 adp
->arg_inout
= AI_INPUT
;
69 adp
++; /* mode argument */
70 adp
->arg_value
= (long)mode
;
71 adp
->arg_object
= NULL
;
72 adp
->arg_type
= AT_BYVAL
;
73 adp
->arg_inout
= AI_INPUT
;
76 error
= Psyscall(Pr
, &rval
, SYS_openat
, 4, &argd
[0]);
79 errno
= (error
> 0)? error
: ENOSYS
;
82 return (rval
.sys_rval1
);
86 * creat() system call -- executed by subject process.
89 pr_creat(struct ps_prochandle
*Pr
, const char *filename
, mode_t mode
)
91 sysret_t rval
; /* return value from openat() */
92 argdes_t argd
[4]; /* arg descriptors for openat() */
96 if (Pr
== NULL
) /* no subject process */
97 return (creat(filename
, mode
));
99 adp
= &argd
[0]; /* AT_FDCWD argument */
100 adp
->arg_value
= AT_FDCWD
;
101 adp
->arg_object
= NULL
;
102 adp
->arg_type
= AT_BYVAL
;
103 adp
->arg_inout
= AI_INPUT
;
106 adp
++; /* filename argument */
108 adp
->arg_object
= (void *)filename
;
109 adp
->arg_type
= AT_BYREF
;
110 adp
->arg_inout
= AI_INPUT
;
111 adp
->arg_size
= strlen(filename
)+1;
113 adp
++; /* flags argument */
114 adp
->arg_value
= (O_WRONLY
| O_CREAT
| O_TRUNC
);
115 adp
->arg_object
= NULL
;
116 adp
->arg_type
= AT_BYVAL
;
117 adp
->arg_inout
= AI_INPUT
;
120 adp
++; /* mode argument */
121 adp
->arg_value
= (long)mode
;
122 adp
->arg_object
= NULL
;
123 adp
->arg_type
= AT_BYVAL
;
124 adp
->arg_inout
= AI_INPUT
;
127 error
= Psyscall(Pr
, &rval
, SYS_openat
, 4, &argd
[0]);
130 errno
= (error
> 0)? error
: ENOSYS
;
133 return (rval
.sys_rval1
);
137 * close() system call -- executed by subject process.
140 pr_close(struct ps_prochandle
*Pr
, int fd
)
142 sysret_t rval
; /* return value from close() */
143 argdes_t argd
[1]; /* arg descriptors for close() */
147 if (Pr
== NULL
) /* no subject process */
150 adp
= &argd
[0]; /* fd argument */
151 adp
->arg_value
= (int)fd
;
152 adp
->arg_object
= NULL
;
153 adp
->arg_type
= AT_BYVAL
;
154 adp
->arg_inout
= AI_INPUT
;
157 error
= Psyscall(Pr
, &rval
, SYS_close
, 1, &argd
[0]);
160 errno
= (error
> 0)? error
: ENOSYS
;
163 return (rval
.sys_rval1
);
167 * access() system call -- executed by subject process.
170 pr_access(struct ps_prochandle
*Pr
, const char *path
, int amode
)
172 sysret_t rval
; /* return from access() */
173 argdes_t argd
[4]; /* arg descriptors for access() */
177 if (Pr
== NULL
) /* no subject process */
178 return (access(path
, amode
));
180 adp
= &argd
[0]; /* directory fd argument */
181 adp
->arg_value
= AT_FDCWD
;
182 adp
->arg_object
= NULL
;
183 adp
->arg_type
= AT_BYVAL
;
184 adp
->arg_inout
= AI_INPUT
;
187 adp
++; /* path argument */
189 adp
->arg_object
= (void *)path
;
190 adp
->arg_type
= AT_BYREF
;
191 adp
->arg_inout
= AI_INPUT
;
192 adp
->arg_size
= strlen(path
) + 1;
194 adp
++; /* amode argument */
195 adp
->arg_value
= (long)amode
;
196 adp
->arg_object
= NULL
;
197 adp
->arg_type
= AT_BYVAL
;
198 adp
->arg_inout
= AI_INPUT
;
201 adp
++; /* flag argument */
203 adp
->arg_object
= NULL
;
204 adp
->arg_type
= AT_BYVAL
;
205 adp
->arg_inout
= AI_INPUT
;
208 err
= Psyscall(Pr
, &rval
, SYS_faccessat
, 4, &argd
[0]);
211 errno
= (err
> 0) ? err
: ENOSYS
;
215 return (rval
.sys_rval1
);