@@ -67,6 +67,7 @@ export type OSUserSpaceContext = {
6767 wasmImports : {
6868 builtin_fcntl64 : ( fd : number , cmd : number , varargs ?: any ) => number ;
6969 builtin_fd_close : ( fd : number ) => number ;
70+ js_wasm_trace : ( ...args : any [ ] ) => void ;
7071 } ;
7172 wasmExports : {
7273 wasm_get_end_offset : ( fd : number ) => bigint ;
@@ -83,8 +84,6 @@ export type OSUserSpaceContext = {
8384 // TODO: Add this method to our main Emscripten FS types
8485 realPath ( node : FSNode ) : string ;
8586 } ;
86- // TODO: Likely rename this. There's no reason it should be different from the rest of the names.
87- _js_wasm_trace : ( ...args : any [ ] ) => void ;
8887} ;
8988
9089export function bindUserSpace (
@@ -115,13 +114,12 @@ export function bindUserSpace(
115114 LOCK_UN ,
116115 } ,
117116 errnoCodes : { EBADF , EINVAL , EAGAIN , EDEADLK , EWOULDBLOCK } ,
118- wasmImports : { builtin_fcntl64, builtin_fd_close } ,
117+ wasmImports : { builtin_fcntl64, builtin_fd_close, js_wasm_trace } ,
119118 wasmExports : { wasm_get_end_offset } ,
120119 syscalls : { getStreamFromFD } ,
121120 FS ,
122121 PROXYFS ,
123122 NODEFS ,
124- _js_wasm_trace,
125123 } : OSUserSpaceContext
126124) {
127125 class VarArgsAccessor {
@@ -164,7 +162,7 @@ export function bindUserSpace(
164162 [ F_UNLCK as FcntlLockState ] : 'unlocked' ,
165163 } as const satisfies Record < FcntlLockState , WholeFileLock [ 'type' ] > ,
166164 is_path_to_shared_fs ( path : string ) {
167- _js_wasm_trace ( 'is_path_to_shared_fs(%s)' , path ) ;
165+ js_wasm_trace ( 'is_path_to_shared_fs(%s)' , path ) ;
168166 const { node } = FS . lookupPath ( path , { noent_okay : true } ) ;
169167 if ( node . mount . type !== PROXYFS ) {
170168 return ! ! node . isSharedFS ;
@@ -208,7 +206,7 @@ export function bindUserSpace(
208206 // TODO: Tolerate ENOENT here?
209207 const { node : backingNode , path : backingPath } =
210208 node . mount . opts . fs . lookupPath ( vfsPath ) ;
211- _js_wasm_trace (
209+ js_wasm_trace (
212210 'backingNode for %s: %s' ,
213211 vfsPath ,
214212 backingPath ,
@@ -371,7 +369,7 @@ export function bindUserSpace(
371369 const stream = getStreamFromFD ( fd ) ;
372370 baseAddress = FS . llseek ( stream , 0 , whence ) ;
373371 } catch ( e ) {
374- _js_wasm_trace (
372+ js_wasm_trace (
375373 'get_base_address(%d, %d, %d) getStreamFromFD error %s' ,
376374 fd ,
377375 whence ,
@@ -407,11 +405,11 @@ export function bindUserSpace(
407405 async function fcntl64 ( fd : number , cmd : number , varargs ?: number ) {
408406 switch ( cmd ) {
409407 case F_GETLK : {
410- _js_wasm_trace ( 'fcntl(%d, F_GETLK)' , fd ) ;
408+ js_wasm_trace ( 'fcntl(%d, F_GETLK)' , fd ) ;
411409 const [ vfsPath , vfsPathErrno ] =
412410 locking . get_vfs_path_from_fd ( fd ) ;
413411 if ( vfsPathErrno !== 0 ) {
414- _js_wasm_trace (
412+ js_wasm_trace (
415413 'fcntl(%d, F_GETLK) %s get_vfs_path_from_fd errno %d' ,
416414 fd ,
417415 vfsPath ,
@@ -424,7 +422,7 @@ export function bindUserSpace(
424422 const flockStructAddr = varArgsAccessor . getNextAsPointer ( ) ;
425423
426424 if ( ! locking . is_path_to_shared_fs ( vfsPath ) ) {
427- _js_wasm_trace (
425+ js_wasm_trace (
428426 "fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'" ,
429427 fd ,
430428 vfsPath
@@ -449,7 +447,7 @@ export function bindUserSpace(
449447 flockStruct . l_type
450448 ) ;
451449 if ( paramsCheckErrno !== 0 ) {
452- _js_wasm_trace (
450+ js_wasm_trace (
453451 'fcntl(%d, F_GETLK) %s check_lock_params errno %d' ,
454452 fd ,
455453 vfsPath ,
@@ -467,7 +465,7 @@ export function bindUserSpace(
467465 flockStruct . l_start
468466 ) ;
469467 if ( baseAddressErrno !== 0 ) {
470- _js_wasm_trace (
468+ js_wasm_trace (
471469 'fcntl(%d, F_GETLK) %s get_base_address errno %d' ,
472470 fd ,
473471 vfsPath ,
@@ -490,7 +488,7 @@ export function bindUserSpace(
490488 }
491489 ) ;
492490 if ( conflictingLock === undefined ) {
493- _js_wasm_trace (
491+ js_wasm_trace (
494492 'fcntl(%d, F_GETLK) %s findFirstConflictingByteRangeLock type=unlocked start=0x%x end=0x%x' ,
495493 fd ,
496494 vfsPath ,
@@ -504,7 +502,7 @@ export function bindUserSpace(
504502 return 0 ;
505503 }
506504
507- _js_wasm_trace (
505+ js_wasm_trace (
508506 'fcntl(%d, F_GETLK) %s findFirstConflictingByteRangeLock type=%s start=0x%x end=0x%x conflictingLock %d' ,
509507 fd ,
510508 vfsPath ,
@@ -527,7 +525,7 @@ export function bindUserSpace(
527525 } ) ;
528526 return 0 ;
529527 } catch ( e ) {
530- _js_wasm_trace (
528+ js_wasm_trace (
531529 'fcntl(%d, F_GETLK) %s findFirstConflictingByteRangeLock error %s' ,
532530 fd ,
533531 vfsPath ,
@@ -537,11 +535,11 @@ export function bindUserSpace(
537535 }
538536 }
539537 case F_SETLK : {
540- _js_wasm_trace ( 'fcntl(%d, F_SETLK)' , fd ) ;
538+ js_wasm_trace ( 'fcntl(%d, F_SETLK)' , fd ) ;
541539 const [ vfsPath , vfsPathErrno ] =
542540 locking . get_vfs_path_from_fd ( fd ) ;
543541 if ( vfsPathErrno !== 0 ) {
544- _js_wasm_trace (
542+ js_wasm_trace (
545543 'fcntl(%d, F_SETLK) %s get_vfs_path_from_fd errno %d' ,
546544 fd ,
547545 vfsPath ,
@@ -551,7 +549,7 @@ export function bindUserSpace(
551549 }
552550
553551 if ( ! locking . is_path_to_shared_fs ( vfsPath ) ) {
554- _js_wasm_trace (
552+ js_wasm_trace (
555553 'fcntl(%d, F_SETLK) locking is not implemented for non-NodeFS path %s' ,
556554 fd ,
557555 vfsPath
@@ -573,7 +571,7 @@ export function bindUserSpace(
573571 flockStruct . l_start
574572 ) ;
575573 if ( baseAddressErrno !== 0 ) {
576- _js_wasm_trace (
574+ js_wasm_trace (
577575 'fcntl(%d, F_SETLK) %s get_base_address errno %d' ,
578576 fd ,
579577 vfsPath ,
@@ -583,7 +581,7 @@ export function bindUserSpace(
583581 }
584582
585583 if ( ! ( flockStruct . l_type in locking . fcntlToLockState ) ) {
586- _js_wasm_trace (
584+ js_wasm_trace (
587585 'fcntl(%d, F_SETLK) %s invalid lock type %d' ,
588586 fd ,
589587 vfsPath ,
@@ -597,7 +595,7 @@ export function bindUserSpace(
597595 flockStruct . l_type
598596 ) ;
599597 if ( paramsCheckErrno !== 0 ) {
600- _js_wasm_trace (
598+ js_wasm_trace (
601599 'fcntl(%d, F_SETLK) %s check_lock_params errno %d' ,
602600 fd ,
603601 vfsPath ,
@@ -620,7 +618,7 @@ export function bindUserSpace(
620618 try {
621619 const nativeFilePath =
622620 locking . get_native_path_from_vfs_path ( vfsPath ) ;
623- _js_wasm_trace (
621+ js_wasm_trace (
624622 'fcntl(%d, F_SETLK) %s calling lockFileByteRange for range lock %s' ,
625623 fd ,
626624 vfsPath ,
@@ -632,7 +630,7 @@ export function bindUserSpace(
632630 rangeLock
633631 ) ;
634632
635- _js_wasm_trace (
633+ js_wasm_trace (
636634 'fcntl(%d, F_SETLK) %s lockFileByteRange returned %d for range lock %s' ,
637635 fd ,
638636 vfsPath ,
@@ -641,7 +639,7 @@ export function bindUserSpace(
641639 ) ;
642640 return succeeded ? 0 : - EAGAIN ;
643641 } catch ( e ) {
644- _js_wasm_trace (
642+ js_wasm_trace (
645643 'fcntl(%d, F_SETLK) %s lockFileByteRange error %s for range lock %s' ,
646644 fd ,
647645 vfsPath ,
@@ -689,7 +687,7 @@ export function bindUserSpace(
689687 }
690688
691689 async function flock ( fd : number , op : number ) {
692- _js_wasm_trace ( 'js_flock(%d, %d)' , fd , op ) ;
690+ js_wasm_trace ( 'js_flock(%d, %d)' , fd , op ) ;
693691
694692 type FlockOp = typeof LOCK_SH | typeof LOCK_EX | typeof LOCK_UN ;
695693 const flockToLockOpType = {
@@ -700,7 +698,7 @@ export function bindUserSpace(
700698
701699 const [ vfsPath , vfsPathErrno ] = locking . get_vfs_path_from_fd ( fd ) ;
702700 if ( vfsPathErrno !== 0 ) {
703- _js_wasm_trace (
701+ js_wasm_trace (
704702 'js_flock(%d, %d) get_vfs_path_from_fd errno %d' ,
705703 fd ,
706704 op ,
@@ -711,7 +709,7 @@ export function bindUserSpace(
711709 }
712710
713711 if ( ! locking . is_path_to_shared_fs ( vfsPath ) ) {
714- _js_wasm_trace (
712+ js_wasm_trace (
715713 'flock(%d, %d) locking is not implemented for non-NodeFS path %s' ,
716714 fd ,
717715 op ,
@@ -724,7 +722,7 @@ export function bindUserSpace(
724722
725723 const paramsCheckErrno = locking . check_lock_params ( fd , op ) ;
726724 if ( paramsCheckErrno !== 0 ) {
727- _js_wasm_trace (
725+ js_wasm_trace (
728726 'js_flock(%d, %d) check_lock_params errno %d' ,
729727 fd ,
730728 op ,
@@ -735,7 +733,7 @@ export function bindUserSpace(
735733
736734 // @TODO : Consider supporting blocking mode of flock()
737735 if ( ( op & LOCK_NB ) === 0 ) {
738- _js_wasm_trace (
736+ js_wasm_trace (
739737 'js_flock(%d, %d) blocking mode of flock() is not implemented' ,
740738 fd ,
741739 op
@@ -749,21 +747,13 @@ export function bindUserSpace(
749747 const maskedOp = op & ( ( LOCK_SH | LOCK_EX | LOCK_UN ) as FlockOp | 0 ) ;
750748
751749 if ( maskedOp === 0 ) {
752- _js_wasm_trace (
753- 'js_flock(%d, %d) invalid flock() operation' ,
754- fd ,
755- op
756- ) ;
750+ js_wasm_trace ( 'js_flock(%d, %d) invalid flock() operation' , fd , op ) ;
757751 return - EINVAL ;
758752 }
759753
760754 const lockOpType = flockToLockOpType [ maskedOp as FlockOp ] ;
761755 if ( lockOpType === undefined ) {
762- _js_wasm_trace (
763- 'js_flock(%d, %d) invalid flock() operation' ,
764- fd ,
765- op
766- ) ;
756+ js_wasm_trace ( 'js_flock(%d, %d) invalid flock() operation' , fd , op ) ;
767757 return - EINVAL ;
768758 }
769759
@@ -778,7 +768,7 @@ export function bindUserSpace(
778768 fd,
779769 }
780770 ) ;
781- _js_wasm_trace (
771+ js_wasm_trace (
782772 'js_flock(%d, %d) lockWholeFile %s returned %d' ,
783773 fd ,
784774 op ,
@@ -787,12 +777,7 @@ export function bindUserSpace(
787777 ) ;
788778 return obtainedLock ? 0 : - EWOULDBLOCK ;
789779 } catch ( e ) {
790- _js_wasm_trace (
791- 'js_flock(%d, %d) lockWholeFile error %s' ,
792- fd ,
793- op ,
794- e
795- ) ;
780+ js_wasm_trace ( 'js_flock(%d, %d) lockWholeFile error %s' , fd , op , e ) ;
796781 return - EINVAL ;
797782 }
798783 }
@@ -805,12 +790,12 @@ export function bindUserSpace(
805790
806791 const fdCloseResult = builtin_fd_close ( fd ) ;
807792 if ( fdCloseResult !== 0 || ! locking . maybeLockedFds . has ( fd ) ) {
808- _js_wasm_trace ( 'fd_close(%d) result %d' , fd , fdCloseResult ) ;
793+ js_wasm_trace ( 'fd_close(%d) result %d' , fd , fdCloseResult ) ;
809794 return fdCloseResult ;
810795 }
811796
812797 if ( vfsPathResolutionErrno !== 0 ) {
813- _js_wasm_trace (
798+ js_wasm_trace (
814799 'fd_close(%d) get_vfs_path_from_fd error %d' ,
815800 fd ,
816801 vfsPathResolutionErrno
@@ -836,9 +821,9 @@ export function bindUserSpace(
836821 fd ,
837822 nativeFilePath
838823 ) ;
839- _js_wasm_trace ( 'fd_close(%d) release locks success' , fd ) ;
824+ js_wasm_trace ( 'fd_close(%d) release locks success' , fd ) ;
840825 } catch ( e ) {
841- _js_wasm_trace ( "fd_close(%d) error '%s'" , fd , e ) ;
826+ js_wasm_trace ( "fd_close(%d) error '%s'" , fd , e ) ;
842827 } finally {
843828 locking . maybeLockedFds . delete ( fd ) ;
844829 }
@@ -848,17 +833,17 @@ export function bindUserSpace(
848833 // TODO: Implement based on current process
849834 // TODO: Replace with process exit handler
850835 async function js_release_file_locks ( ) {
851- _js_wasm_trace ( 'js_release_file_locks()' ) ;
836+ js_wasm_trace ( 'js_release_file_locks()' ) ;
852837 if ( ! pid || ! fileLockManager ) {
853- _js_wasm_trace ( 'js_release_file_locks no pid or file lock manager' ) ;
838+ js_wasm_trace ( 'js_release_file_locks no pid or file lock manager' ) ;
854839 return ;
855840 }
856841
857842 try {
858843 await fileLockManager . releaseLocksForProcess ( pid ) ;
859- _js_wasm_trace ( 'js_release_file_locks succeeded' ) ;
844+ js_wasm_trace ( 'js_release_file_locks succeeded' ) ;
860845 } catch ( e ) {
861- _js_wasm_trace ( 'js_release_file_locks error %s' , e ) ;
846+ js_wasm_trace ( 'js_release_file_locks error %s' , e ) ;
862847 }
863848 }
864849
0 commit comments