0.9.7.31:
[sbcl.git] / src / code / linux-os.lisp
1 ;;;; OS interface functions for CMU CL under Linux
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!SYS")
13
14 ;;; Check that target machine features are set up consistently with
15 ;;; this file.
16 #!-linux (error "missing :LINUX feature")
17
18 (defun software-type ()
19   #!+sb-doc
20   "Return a string describing the supporting software."
21   (values "Linux"))
22
23 (defvar *software-version* nil)
24
25 ;;; FIXME: More duplicated logic here vrt. other oses. Abstract into
26 ;;; uname-software-version?
27 (defun software-version ()
28   #!+sb-doc
29   "Return a string describing version of the supporting software, or NIL
30   if not available."
31   (or *software-version*
32       (setf *software-version*
33             (string-trim '(#\newline)
34                          (with-output-to-string (stream)
35                            (sb!ext:run-program "/bin/uname" `("-r")
36                                                :output stream))))))
37
38 ;;; FIXME: This logic is duplicated in other backends:
39 ;;; abstract, abstract. OS-COMMON-COLD-INIT-OR-REINIT, mayhaps?
40 (defun os-cold-init-or-reinit () ; KLUDGE: don't know what to do here
41   (/show0 "entering linux-os.lisp OS-COLD-INIT-OR-REINIT")
42   (setf *software-version* nil)
43   (/show0 "setting *DEFAULT-PATHNAME-DEFAULTS*")
44   (setf *default-pathname-defaults*
45         ;; (temporary value, so that #'NATIVE-PATHNAME won't blow up
46         ;; when we call it below:)
47         (make-trivial-default-pathname)
48         *default-pathname-defaults*
49         ;; (final value, constructed using #'NATIVE-PATHNAME:)
50         (native-pathname (sb!unix:posix-getcwd/)))
51   (/show0 "leaving linux-os.lisp OS-COLD-INIT-OR-REINIT"))
52
53 ;;; Return system time, user time and number of page faults.
54 (defun get-system-info ()
55   (multiple-value-bind
56       (err? utime stime maxrss ixrss idrss isrss minflt majflt)
57       (sb!unix:unix-getrusage sb!unix:rusage_self)
58     (declare (ignore maxrss ixrss idrss isrss minflt))
59     (unless err? ; FIXME: nonmnemonic (reversed) name for ERR?
60       (error "Unix system call getrusage failed: ~A." (strerror utime)))
61     (values utime stime majflt)))
62
63 ;;; Return the system page size.
64 (defun get-page-size ()
65   ;; probably should call getpagesize()
66   ;; FIXME: Or we could just get rid of this, since the uses of it look
67   ;; disposable.
68   4096)