@@ -213,99 +213,103 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
213213 @ Cached SysModuleBuiltins .AuditNode auditNode ) {
214214 auditNode .audit (inliningTarget , "fcnt.ioctl" , fd , request , arg );
215215
216- int intArg = 0 ;
217- if (arg != PNone .NO_VALUE ) {
218- Object buffer = null ;
219- // Buffer argument
220- if (acquireLib .hasBuffer (arg )) {
221- boolean writable = false ;
222- try {
223- buffer = acquireLib .acquireWritable (arg , frame , indirectCallData );
224- writable = true ;
225- } catch (PException e ) {
226- try {
227- buffer = acquireLib .acquireReadonly (arg , frame , indirectCallData );
228- } catch (PException e1 ) {
229- // ignore
230- }
231- }
232- if (buffer != null ) {
216+ try {
217+ int intArg = 0 ;
218+ if (arg != PNone .NO_VALUE ) {
219+ Object buffer = null ;
220+ // Buffer argument
221+ if (acquireLib .hasBuffer (arg )) {
222+ boolean writable = false ;
233223 try {
234- int len = bufferLib .getBufferLength (buffer );
235- boolean writeBack = false ;
236- boolean releaseGil = true ;
237- byte [] ioctlArg = null ;
238- if (writable && mutateArg ) {
239- writeBack = true ;
240- if (bufferLib .hasInternalByteArray (buffer )) {
241- byte [] internalArray = bufferLib .getInternalByteArray (buffer );
242- if (internalArray .length > len && internalArray [len ] == 0 ) {
243- writeBack = false ;
244- releaseGil = false ; // Could resize concurrently
245- ioctlArg = internalArray ;
246- }
247- }
248- } else {
249- if (len > IOCTL_BUFSZ ) {
250- throw raiseNode .get (inliningTarget ).raise (ValueError , ErrorMessages .IOCTL_STRING_ARG_TOO_LONG );
251- }
252- }
253- if (ioctlArg == null ) {
254- ioctlArg = new byte [len + 1 ];
255- bufferLib .readIntoByteArray (buffer , 0 , ioctlArg , 0 , len );
224+ buffer = acquireLib .acquireWritable (arg , frame , indirectCallData );
225+ writable = true ;
226+ } catch (PException e ) {
227+ try {
228+ buffer = acquireLib .acquireReadonly (arg , frame , indirectCallData );
229+ } catch (PException e1 ) {
230+ // ignore
256231 }
232+ }
233+ if (buffer != null ) {
257234 try {
258- int ret = callIoctlBytes (frame , inliningTarget , fd , request , ioctlArg , releaseGil , posixLib , gilNode , constructAndRaiseNode );
235+ int len = bufferLib .getBufferLength (buffer );
236+ boolean writeBack = false ;
237+ boolean releaseGil = true ;
238+ byte [] ioctlArg = null ;
259239 if (writable && mutateArg ) {
260- return ret ;
240+ writeBack = true ;
241+ if (bufferLib .hasInternalByteArray (buffer )) {
242+ byte [] internalArray = bufferLib .getInternalByteArray (buffer );
243+ if (internalArray .length > len && internalArray [len ] == 0 ) {
244+ writeBack = false ;
245+ releaseGil = false ; // Could resize concurrently
246+ ioctlArg = internalArray ;
247+ }
248+ }
261249 } else {
262- return factory .createBytes (ioctlArg , len );
250+ if (len > IOCTL_BUFSZ ) {
251+ throw raiseNode .get (inliningTarget ).raise (ValueError , ErrorMessages .IOCTL_STRING_ARG_TOO_LONG );
252+ }
263253 }
264- } finally {
265- if ( writeBack ) {
266- bufferLib .writeFromByteArray (buffer , 0 , ioctlArg , 0 , len );
254+ if ( ioctlArg == null ) {
255+ ioctlArg = new byte [ len + 1 ];
256+ bufferLib .readIntoByteArray (buffer , 0 , ioctlArg , 0 , len );
267257 }
258+ try {
259+ int ret = callIoctlBytes (frame , inliningTarget , fd , request , ioctlArg , releaseGil , posixLib , gilNode , constructAndRaiseNode );
260+ if (writable && mutateArg ) {
261+ return ret ;
262+ } else {
263+ return factory .createBytes (ioctlArg , len );
264+ }
265+ } finally {
266+ if (writeBack ) {
267+ bufferLib .writeFromByteArray (buffer , 0 , ioctlArg , 0 , len );
268+ }
269+ }
270+ } finally {
271+ bufferLib .release (buffer , frame , indirectCallData );
268272 }
269- } finally {
270- bufferLib .release (buffer , frame , indirectCallData );
271273 }
272274 }
273- }
274- // string arg
275- TruffleString stringArg = null ;
276- try {
277- stringArg = castToString .execute (inliningTarget , arg );
278- } catch (CannotCastException e ) {
279- // ignore
280- }
281- if (stringArg != null ) {
282- TruffleString .Encoding utf8 = TruffleString .Encoding .UTF_8 ;
283- stringArg = switchEncodingNode .execute (stringArg , utf8 );
284- int len = stringArg .byteLength (utf8 );
285- if (len > IOCTL_BUFSZ ) {
286- throw raiseNode .get (inliningTarget ).raise (ValueError , ErrorMessages .IOCTL_STRING_ARG_TOO_LONG );
275+ // string arg
276+ TruffleString stringArg = null ;
277+ try {
278+ stringArg = castToString .execute (inliningTarget , arg );
279+ } catch (CannotCastException e ) {
280+ // ignore
281+ }
282+ if (stringArg != null ) {
283+ TruffleString .Encoding utf8 = TruffleString .Encoding .UTF_8 ;
284+ stringArg = switchEncodingNode .execute (stringArg , utf8 );
285+ int len = stringArg .byteLength (utf8 );
286+ if (len > IOCTL_BUFSZ ) {
287+ throw raiseNode .get (inliningTarget ).raise (ValueError , ErrorMessages .IOCTL_STRING_ARG_TOO_LONG );
288+ }
289+ byte [] ioctlArg = new byte [len + 1 ];
290+ copyToByteArrayNode .execute (stringArg , 0 , ioctlArg , 0 , len , utf8 );
291+ callIoctlBytes (frame , inliningTarget , fd , request , ioctlArg , true , posixLib , gilNode , constructAndRaiseNode );
292+ return factory .createBytes (ioctlArg , len );
287293 }
288- byte [] ioctlArg = new byte [len + 1 ];
289- copyToByteArrayNode .execute (stringArg , 0 , ioctlArg , 0 , len , utf8 );
290- callIoctlBytes (frame , inliningTarget , fd , request , ioctlArg , true , posixLib , gilNode , constructAndRaiseNode );
291- return factory .createBytes (ioctlArg , len );
292- }
293294
294- // int arg
295- intArg = asIntNode .execute (frame , inliningTarget , arg );
296- // fall through
297- }
295+ // int arg
296+ intArg = asIntNode .execute (frame , inliningTarget , arg );
297+ // fall through
298+ }
298299
299- // default arg or int arg
300- try {
301- gilNode .release (true );
300+ // default arg or int arg
302301 try {
303- return posixLib .ioctlInt (getPosixSupport (), fd , request , intArg );
304- } finally {
305- gilNode .acquire ();
302+ gilNode .release (true );
303+ try {
304+ return posixLib .ioctlInt (getPosixSupport (), fd , request , intArg );
305+ } finally {
306+ gilNode .acquire ();
307+ }
308+ } catch (PosixException e ) {
309+ throw constructAndRaiseNode .get (inliningTarget ).raiseOSErrorFromPosixException (frame , e );
306310 }
307- } catch (PosixException e ) {
308- throw constructAndRaiseNode .get (inliningTarget ).raiseOSErrorFromPosixException (frame , e );
311+ } catch (PosixSupportLibrary . UnsupportedPosixFeatureException e ) {
312+ throw constructAndRaiseNode .get (inliningTarget ).raiseOSErrorUnsupported (frame , e );
309313 }
310314 }
311315
0 commit comments