Skip to content
Snippets Groups Projects
linux-os.lisp 2.6 KiB
Newer Older
ram's avatar
ram committed
;;; -*- Package: SYSTEM -*-
;;;
;;; **********************************************************************
;;; This code was written as part of the CMU Common Lisp project at
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
cshapiro's avatar
cshapiro committed
  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/linux-os.lisp,v 1.6 2007/07/18 09:50:24 cshapiro Exp $")
ram's avatar
ram committed
;;;
;;; **********************************************************************
;;;
toy's avatar
toy committed
;;; OS interface functions for CMUCL under Linux.
ram's avatar
ram committed
;;;
;;; Written and maintained mostly by Skef Wholey and Rob MacLachlan.
;;; Scott Fahlman, Dan Aronson, and Steve Handerson did stuff here, too.
;;;
toy's avatar
toy committed
;;; Derived from mach-os.lisp by Paul Werkowski
ram's avatar
ram committed

(in-package "SYSTEM")
(use-package "EXTENSIONS")
(export '(get-system-info get-page-size os-init))

(register-lisp-feature :linux)
(register-lisp-feature :elf)
cshapiro's avatar
cshapiro committed
(register-lisp-runtime-feature :executable)
ram's avatar
ram committed

(setq *software-type* "Linux")

emarsden's avatar
 
emarsden committed
;;; We use READ-SEQUENCE instead of READ-LINE to work around a bug in
;;; the proc file system on Linux kernel 2.6.x. The select() system
;;; call does not work correctly on certain files; it never reports
;;; that data is available for reading. Since CMUCL's fd-streams use
;;; select(), as a part of the SERVE-EVENT mechanism, normal I/O (for
;;; instance with READ-CHAR or READ-LINE) will fail on these files.
;;; Luckily READ-SEQUENCE does not suffer from this problem.
;;;
;;; We could also call "uname -r" here, but using the filesystem-based
;;; interface seems cleaner.
ram's avatar
ram committed
(defun software-version ()
  "Returns a string describing version of the supporting software."
toy's avatar
toy committed
  (when (probe-file "/proc/version")
    (with-open-file (f "/proc/version")
emarsden's avatar
 
emarsden committed
      (let* ((buf (make-string 1024))
             (count (read-sequence buf f :end 1024)))
        (subseq buf 0 (1- count))))))
toy's avatar
toy committed
;;; OS-Init initializes our operating-system interface.
;;;
(defun os-init () nil)
ram's avatar
ram committed


;;; GET-SYSTEM-INFO  --  Interface
;;;
;;;    Return system time, user time and number of page faults.
;;;
(defun get-system-info ()
  (multiple-value-bind (err? utime stime maxrss ixrss idrss
			     isrss minflt majflt)
		       (unix:unix-getrusage unix:rusage_self)
    (declare (ignore maxrss ixrss idrss isrss minflt))
    (unless err?
      (error "Unix system call getrusage failed: ~A."
	     (unix:get-unix-error-msg utime)))
    
    (values utime stime majflt)))


;;; GET-PAGE-SIZE  --  Interface
;;;
;;;    Return the system page size.
;;;
(defun get-page-size ()
toy's avatar
toy committed
  (multiple-value-bind (val err)
      (unix:unix-getpagesize)
    (unless val
      (error "Getpagesize failed: ~A" (unix:get-unix-error-msg err)))
    val))
ram's avatar
ram committed