@@ -768,6 +768,16 @@ func Munmap(b []byte) (err error) {
768768 return mapper .Munmap (b )
769769}
770770
771+ func MmapPtr (fd int , offset int64 , addr unsafe.Pointer , length uintptr , prot int , flags int ) (ret unsafe.Pointer , err error ) {
772+ xaddr , err := mapper .mmap (uintptr (addr ), length , prot , flags , fd , offset )
773+ return unsafe .Pointer (xaddr ), err
774+ }
775+
776+ func MunmapPtr (addr unsafe.Pointer , length uintptr ) (err error ) {
777+ return mapper .munmap (uintptr (addr ), length )
778+ }
779+
780+
771781//sys Gethostname(buf []byte) (err error) = SYS___GETHOSTNAME_A
772782//sysnb Getgid() (gid int)
773783//sysnb Getpid() (pid int)
@@ -3115,3 +3125,90 @@ func legacy_Mkfifoat(dirfd int, path string, mode uint32) (err error) {
31153125//sys Posix_openpt(oflag int) (fd int, err error) = SYS_POSIX_OPENPT
31163126//sys Grantpt(fildes int) (rc int, err error) = SYS_GRANTPT
31173127//sys Unlockpt(fildes int) (rc int, err error) = SYS_UNLOCKPT
3128+
3129+ func fcntlAsIs (fd uintptr , cmd int , arg uintptr ) (val int , err error ) {
3130+ runtime .EnterSyscall ()
3131+ r0 , e2 , e1 := CallLeFuncWithErr (GetZosLibVec ()+ SYS_FCNTL << 4 , uintptr (fd ), uintptr (cmd ), arg )
3132+ runtime .ExitSyscall ()
3133+ val = int (r0 )
3134+ if int64 (r0 ) == - 1 {
3135+ err = errnoErr2 (e1 , e2 )
3136+ }
3137+ return
3138+ }
3139+
3140+ func Fcntl (fd uintptr , cmd int , op interface {}) (ret int , err error ) {
3141+ switch op .(type ) {
3142+ case * Flock_t :
3143+ err = FcntlFlock (fd , cmd , op .(* Flock_t ))
3144+ if err != nil {
3145+ ret = - 1
3146+ }
3147+ return
3148+ case int :
3149+ return FcntlInt (fd , cmd , op .(int ))
3150+ case * F_cnvrt :
3151+ return fcntlAsIs (fd , cmd , uintptr (unsafe .Pointer (op .(* F_cnvrt ))))
3152+ case unsafe.Pointer :
3153+ return fcntlAsIs (fd , cmd , uintptr (op .(unsafe.Pointer )))
3154+ default :
3155+ return - 1 , EINVAL
3156+ }
3157+ return
3158+ }
3159+
3160+ func Sendfile (outfd int , infd int , offset * int64 , count int ) (written int , err error ) {
3161+ if raceenabled {
3162+ raceReleaseMerge (unsafe .Pointer (& ioSync ))
3163+ }
3164+ return sendfile (outfd , infd , offset , count )
3165+ }
3166+
3167+ func sendfile (outfd int , infd int , offset * int64 , count int ) (written int , err error ) {
3168+ // TODO: use LE call instead if the call is implemented
3169+ originalOffset , err := Seek (infd , 0 , SEEK_CUR )
3170+ if err != nil {
3171+ return - 1 , err
3172+ }
3173+ //start reading data from in_fd
3174+ if offset != nil {
3175+ _ , err := Seek (infd , * offset , SEEK_SET )
3176+ if err != nil {
3177+ return - 1 , err
3178+ }
3179+ }
3180+
3181+ buf := make ([]byte , count )
3182+ readBuf := make ([]byte , 0 )
3183+ var n int = 0
3184+ for i := 0 ; i < count ; i += n {
3185+ n , err := Read (infd , buf )
3186+ if n == 0 {
3187+ if err != nil {
3188+ return - 1 , err
3189+ } else { // EOF
3190+ break
3191+ }
3192+ }
3193+ readBuf = append (readBuf , buf ... )
3194+ buf = buf [0 :0 ]
3195+ }
3196+
3197+ n2 , err := Write (outfd , readBuf )
3198+ if err != nil {
3199+ return - 1 , err
3200+ }
3201+
3202+ //When sendfile() returns, this variable will be set to the
3203+ // offset of the byte following the last byte that was read.
3204+ if offset != nil {
3205+ * offset = * offset + int64 (n )
3206+ // If offset is not NULL, then sendfile() does not modify the file
3207+ // offset of in_fd
3208+ _ , err := Seek (infd , originalOffset , SEEK_SET )
3209+ if err != nil {
3210+ return - 1 , err
3211+ }
3212+ }
3213+ return n2 , nil
3214+ }
0 commit comments