Changeset 10660


Ignore:
Timestamp:
Sep 8, 2008, 3:30:12 PM (11 years ago)
Author:
gb
Message:

Don't use syscalls for I/O; use INT-ERRNO-FFCALL and new kernel imports.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-0/l0-io.lisp

    r10575 r10660  
    1717(in-package "CCL")
    1818
    19 (eval-when (:compile-toplevel)
    20   #+linuxppc-target
    21   (require "PPC-LINUX-SYSCALLS")
    22   #+linuxx8664-target
    23   (require "X8664-LINUX-SYSCALLS")
    24   #+darwinppc-target
    25   (require "DARWINPPC-SYSCALLS")
    26   #+darwinx8632-target
    27   (require "DARWINX8632-SYSCALLS")
    28   #+darwinx8664-target
    29   (require "DARWINX8664-SYSCALLS")
    30   #+freebsd-target
    31   (require "X8664-FREEBSD-SYSCALLS")
    32   #+solarisx8664-target
    33   (require "X8664-SOLARIS-SYSCALLS")
    34   #+win64-target
    35   (require "X86-WIN64-SYSCALLS")
    36   )
     19
    3720
    3821
     
    200183;;; write nbytes bytes from buffer buf to file-descriptor fd.
    201184(defun fd-write (fd buf nbytes)
    202   (ignoring-eintr
    203    (syscall syscalls::write fd buf nbytes)))
     185  (ignoring-eintr
     186   (int-errno-ffcall
     187    (%kernel-import target::kernel-import-lisp-write)
     188             :int fd :address buf :ssize_t nbytes :ssize_t)))
    204189
    205190(defun fd-read (fd buf nbytes)
    206   (ignoring-eintr (syscall syscalls::read fd buf nbytes)))
     191  (ignoring-eintr
     192   (int-errno-ffcall
     193    (%kernel-import target::kernel-import-lisp-read)
     194             :int fd :address buf :ssize_t nbytes :ssize_t)))
    207195
    208196
     
    212200   #-(or darwin-target windows-target) with-cstrs
    213201   ((p path))
    214     (let* ((fd (syscall syscalls::open p flags create-mode)))
     202    (let* ((fd (int-errno-ffcall
     203                (%kernel-import target::kernel-import-lisp-open)
     204                :address p :int flags :mode_t create-mode :int)))
    215205      (declare (fixnum fd))
    216206      (when (or (= fd (- #$EMFILE))
     
    218208        (gc)
    219209        (drain-termination-queue)
    220         (setq fd (syscall syscalls::open p flags create-mode)))
     210        (setq fd (int-errno-ffcall
     211                  (%kernel-import target::kernel-import-lisp-open)
     212                           :address p :int flags :mode_t create-mode :int)))
    221213      fd)))
    222214
    223215(defun fd-chmod (fd mode)
    224   (syscall syscalls::fchmod fd mode))
    225 
    226 ;;; This should really be conditionalized on whether the seek system
    227 ;;; call supports 64-bit offsets or on whether one has to use some
    228 ;;; variant.
    229 #+(and ppc32-target linux-target)
     216  (int-errno-ffcall (%kernel-import target::kernel-import-lisp-fchmod)
     217                    :int fd
     218                    :mode_t mode
     219                    :int))
     220
    230221(defun fd-lseek (fd offset whence)
    231   (let* ((high (ldb (byte 32 32) offset))
    232          (low (ldb (byte 32 0) offset)))
    233     (declare (type (unsigned-byte 32) high low))
    234     (%stack-block ((pos 8))
    235       (let* ((res (syscall syscalls::_llseek fd high low pos whence)))
    236         (declare (fixnum res))
    237         (if (< res 0)
    238           res
    239           (let* ((pos-high (%get-unsigned-long pos 0))
    240                  (pos-low (%get-unsigned-long pos 4)))
    241             (declare (type (unsigned-byte 32) pos-high pos-low))
    242             (if (zerop pos-high)
    243               pos-low
    244               (dpb pos-high (byte 32 32) pos-low))))))))
    245 
    246 #-(and ppc32-target linux-target)
    247 (defun fd-lseek (fd offset whence)
    248   #+freebsd-target
    249   (syscall syscalls::lseek fd 0 offset whence)
    250   #-freebsd-target
    251   (syscall syscalls::lseek fd offset whence))
     222  (int-errno-ffcall
     223   (%kernel-import target::kernel-import-lisp-lseek)
     224   :int fd
     225   :ssize_t offset
     226   :int whence
     227   :ssize_t))
    252228
    253229(defun fd-close (fd)
    254   (syscall syscalls::close fd))
     230  (int-errno-ffcall (%kernel-import target::kernel-import-lisp-close)
     231                    :int fd
     232                    :int))
    255233
    256234(defun fd-tell (fd)
     
    267245
    268246(defun fd-ftruncate (fd new)
    269   #-solaris-target
    270   (syscall syscalls::ftruncate fd new)
    271   #+solaris-target
    272   (rlet ((lck #>flock))
    273     (setf (pref lck :flock.l_whence) 0
    274           (pref lck :flock.l_start) new
    275           (pref lck :flock.l_type) #$F_WRLCK
    276           (pref lck :flock.l_len) 0)
    277     (syscall syscalls::fcntl fd #$F_FREESP lck)))
     247  (int-errno-ffcall (%kernel-import target::kernel-import-lisp-ftruncate)
     248                    :int fd :off_t new :int))
    278249
    279250(defun %string-to-stderr (str)
Note: See TracChangeset for help on using the changeset viewer.