Make INFO's compiler-macro more forgiving.
[sbcl.git] / src / code / android-os.lisp
blobb033bc1c7c88070f3939ccbad2a77e7a0c40b0e0
1 ;;;; OS interface functions for SBCL under Linux
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.
12 (in-package "SB!SYS")
14 ;;; Check that target machine features are set up consistently with
15 ;;; this file.
16 #!-android (error "missing :ANDROID feature")
18 (defun software-type ()
19 #!+sb-doc
20 "Return a string describing the supporting software."
21 "Android")
23 ;;; FIXME: More duplicated logic here vrt. other oses. Abstract into
24 ;;; uname-software-version?
25 (defun software-version ()
26 #!+sb-doc
27 "Return a string describing version of the supporting software, or NIL
28 if not available."
29 (or *software-version*
30 (setf *software-version*
31 (sb!alien:with-alien
32 ((ptr (* char)
33 (sb!alien:alien-funcall
34 (sb!alien:extern-alien "software_version"
35 (function (* sb!alien:char))))))
36 (and (not (sb!alien:null-alien ptr))
37 (unwind-protect
38 (sb!alien:with-alien ((c-string sb!alien:c-string ptr))
39 c-string)
40 (sb!alien:free-alien ptr)))))))
42 ;;; Return user time, system time, and number of page faults.
43 (defun get-system-info ()
44 (multiple-value-bind
45 (err? utime stime maxrss ixrss idrss isrss minflt majflt)
46 (sb!unix:unix-getrusage sb!unix:rusage_self)
47 (declare (ignore maxrss ixrss idrss isrss minflt))
48 (unless err? ; FIXME: nonmnemonic (reversed) name for ERR?
49 (error "Unix system call getrusage failed: ~A." (strerror utime)))
50 (values utime stime majflt)))
52 ;;; Return the system page size.
53 (defun get-page-size ()
54 sb!c:*backend-page-bytes*)
56 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
57 (defun get-machine-version ()
58 (or
59 #!+(and mips little-endian)
60 "little-endian"
61 #!+(and mips big-endian)
62 "big-endian"
63 (let ((marker
64 ;; hoping "cpu" exists and gives something useful in
65 ;; all relevant Linuxen...
67 ;; from Lars Brinkhoff sbcl-devel 26 Jun 2003:
68 ;; I examined different versions of Linux/PPC at
69 ;; http://lxr.linux.no/ (the file that outputs
70 ;; /proc/cpuinfo is arch/ppc/kernel/setup.c, if
71 ;; you want to check), and all except 2.0.x
72 ;; seemed to do the same thing as far as the
73 ;; "cpu" field is concerned, i.e. it always
74 ;; starts with the (C-syntax) string "cpu\t\t: ".
75 #!+ppc "cpu"
76 ;; The field "model name" exists on kernel 2.4.21-rc6-ac1
77 ;; anyway, with values e.g.
78 ;; "AMD Athlon(TM) XP 2000+"
79 ;; "Intel(R) Pentium(R) M processor 1300MHz"
80 ;; which seem comparable to the information in the example
81 ;; in the MACHINE-VERSION page of the ANSI spec.
82 #!+(or x86 x86-64) "model name"
83 #!+arm "Processor"))
84 (when marker
85 (with-open-file (stream "/proc/cpuinfo"
86 ;; Even on Linux it's an option to build
87 ;; kernels without /proc filesystems, so
88 ;; degrade gracefully.
89 :if-does-not-exist nil)
90 (loop with line while (setf line (read-line stream nil))
91 when (eql (search marker line) 0)
92 return (string-trim " " (subseq line (1+ (position #\: line))))))))))