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