Skip to content

Commit

Permalink
0.6.10.2:
Browse files Browse the repository at this point in the history
	merged MNA LOAD-FOREIGN patch (sbcl-devel 2001-01-10)
	tweaked LOAD-FOREIGN and RUN-PROGRAM to use :ENVIRONMENT
		instead of lossy :ENV by preference
	renamed GET-UNIX-ENVIRONMENT to SB-EXT:POSIX-ENVIRON, by
		analogy with SB-EXT:POSIX-GETENV
	removed (MERGE-PATHNAMES PROGRAM "path:") in RUN-PROGRAM,
		since it refers to a search list which isn't
		defined in SBCL (and since I'd like to remove all
		support for search lists anyway).
	SB-EXT is a public interface package not really intended as a
		home for implementations; switched IN-PACKAGEs
		to use SB-IMPL instead
	To support this, SB-IMPL should USE SB-C-CALL and SB-ALIEN
		as SB-EXT does.
	made RUN-PROGRAM default to copying Unix environment
	added LOAD-FOREIGN and RUN-PROGRAM test cases
  • Loading branch information
William Harold Newman committed Jan 19, 2001
1 parent e7c0037 commit e5f24eb
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 157 deletions.
11 changes: 11 additions & 0 deletions BUGS
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,17 @@ Error in function C::GET-LAMBDA-TO-COMPILE:
e-mail on cmucl-help@cons.org on 2001-01-16 and 2001-01-17 from WHN
and Pierre Mai.)

79:
as pointed out by Dan Barlow on sbcl-devel 2000-07-02:
The PICK-TEMPORARY-FILE-NAME utility used by LOAD-FOREIGN uses
an easily guessable temporary filename in a way which might open
applications using LOAD-FOREIGN to hijacking by malicious users
on the same machine. Incantations for doing this safely are
floating around the net in various "how to write secure programs
despite Unix" documents, and it would be good to (1) fix this in
LOAD-FOREIGN, and (2) hunt for any other code which uses temporary
files and make it share the same new safe logic.


KNOWN BUGS RELATED TO THE IR1 INTERPRETER

Expand Down
12 changes: 8 additions & 4 deletions package-data-list.lisp-expr
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@
#s(sb-cold:package-data
:name "SB!IMPL"
:doc "private: a grab bag of implementation details"
:use ("CL" "SB!EXT" "SB!INT" "SB!SYS" "SB!DEBUG" "SB!KERNEL" "SB!BIGNUM"
"SB!GRAY"))
:use ("CL" "SB!ALIEN" "SB!BIGNUM" "SB!C-CALL" "SB!DEBUG" "SB!EXT"
"SB!GRAY" "SB!INT" "SB!KERNEL" "SB!SYS"))

;; FIXME: It seems to me that this could go away, with its contents moved
;; into SB!KERNEL, like the implementation of the rest of the class system.
Expand Down Expand Up @@ -484,7 +484,7 @@ like *STACK-TOP-HINT*"
:reexport ("LOAD-FOREIGN" "LOAD-1-FOREIGN" "WEAK-POINTER-P")
:export (;; Information about how the program was invoked is
;; nonstandard but very useful.
"*POSIX-ARGV*" "POSIX-GETENV"
"*POSIX-ARGV*" "POSIX-GETENV" "POSIX-ENVIRON"

;; People have various good reasons to mess with the GC.
"*AFTER-GC-HOOKS*" "*BEFORE-GC-HOOKS*"
Expand Down Expand Up @@ -795,6 +795,10 @@ retained, possibly temporariliy, because it might be used internally."
"DEFINE-HASH-TABLE-TEST"
"*GC-INHIBIT-HOOK*"

;; compatibility hacks for old-style CMU CL data formats
"UNIX-ENVIRONMENT-CMUCL-FROM-SBCL"
"UNIX-ENVIRONMENT-SBCL-FROM-CMUCL"

;; not used any more, I think -- WHN 19991206
#+nil
("SERVE-BUTTON-PRESS"
Expand Down Expand Up @@ -1429,7 +1433,7 @@ stable Unix interface suitable for the end user.
This package only tries to implement what happens to be
needed by the current implementation of SBCL, and makes
no guarantees of interface stability."
:use ("CL" "SB!ALIEN" "SB!C-CALL" "SB!SYS" "SB!EXT" "SB!INT")
:use ("CL" "SB!ALIEN" "SB!C-CALL" "SB!EXT" "SB!INT" "SB!SYS")
:export ("CADDR-T" "D-INO" "D-NAME" "D-NAMLEN" "D-OFF" "D-RECLEN"
"DADDR-T" "DEV-T" "DIRECT" "EXECGRP" "EXECOTH" "EXECOWN" "F-DUPFD"
"F-GETFD" "F-GETFL" "F-GETOWN" "F-SETFD" "F-SETFL" "F-SETOWN"
Expand Down
2 changes: 1 addition & 1 deletion src/code/boot-extensions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.

(in-package "SB!EXT")
(in-package "SB!IMPL")

;;; Lots of code wants to get to the KEYWORD package or the
;;; COMMON-LISP package without a lot of fuss, so we cache them in
Expand Down
2 changes: 1 addition & 1 deletion src/code/early-extensions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.

(in-package "SB!EXT")
(in-package "SB!IMPL")

;;; something not EQ to anything we might legitimately READ
(defparameter *eof-object* (make-symbol "EOF-OBJECT"))
Expand Down
2 changes: 1 addition & 1 deletion src/code/final.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.

(in-package "SB!EXT")
(in-package "SB!IMPL")

(defvar *objects-pending-finalization* nil)

Expand Down
65 changes: 37 additions & 28 deletions src/code/foreign.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

(in-package "SB-SYS")

;;; not needed until we implement full-blown LOAD-FOREIGN
#|
(defun pick-temporary-file-name (&optional
;; KLUDGE: There are various security
;; nastyisms associated with easily
Expand Down Expand Up @@ -45,7 +43,7 @@
(return nil))
(t
(incf code))))))))
|#


;;; On any OS where we don't support foreign object file loading, any
;;; query of a foreign symbol value is answered with "no definition
Expand Down Expand Up @@ -96,11 +94,9 @@
(push (lambda () (setq *tables-from-dlopen* nil))
sb-int:*after-save-initializations*)

;;; not needed until we implement full-blown LOAD-FOREIGN
#|
(defvar *dso-linker* "/usr/bin/ld")
(defvar *dso-linker-options* '("-G" "-o"))
|#


(sb-alien:def-alien-routine dlopen system-area-pointer
(file sb-c-call:c-string) (mode sb-c-call:int))
Expand All @@ -126,8 +122,8 @@
(error "can't open global symbol table: ~S" (dlerror)))))

(defun load-1-foreign (file)
"a primitive way to load a foreign object file. (LOAD-FOREIGN is
probably preferred, but as of SBCL 0.6.7 is not implemented..)
"the primitive upon which the more general LOAD-FOREIGN is built: load
a single foreign object file
To use LOAD-1-FOREIGN, at the Unix command line do this:
echo 'int summish(int x, int y) { return 1 + x + y; }' > /tmp/ffi-test.c
Expand Down Expand Up @@ -165,30 +161,44 @@
(unless (zerop possible-result)
(return possible-result)))))

;;; code partially ported from CMU CL to SBCL, but needs RUN-PROGRAM
#|
(defun load-foreign (files &key
(libraries '("-lc"))
(base-file nil)
;; Note: Since SBCL has no *ENVIRONMENT-LIST*
;; variable, if this code is ever restored,
;; the default should be taken from the alien
;; "environ" variable.
,, ; do it!
(env sb-ext:*environment-list*))
(defun load-foreign (files
&key
(libraries '("-lc"))
;; FIXME: The old documentation said
;; The BASE-FILE argument is used to specify a
;; file to use as the starting place for
;; defined symbols. The default is the C start
;; up code for Lisp.
;; But the code ignored the BASE-FILE argument.
;; The comment above
;; (DECLARE (IGNORE BASE-FILE))
;; said
;; dlopen() remembers the name of an object,
;; when dlopen()ing the same name twice, the
;; old object is reused.
;; So I deleted all reference to BASE-FILE,
;; including the now-bogus reference to the
;; BASE-FILE argument in the documentation. But
;; are there any other subtleties of the new code
;; which need to be documented in its place?
(env nil env-p)
(environment (if env-p
(unix-environment-sbcl-from-cmu env)
(posix-environ))
environment-p))
#+sb-doc
"LOAD-FOREIGN loads a list of C object files into a running Lisp. The FILES
argument should be a single file or a list of files. The files may be
specified as namestrings or as pathnames. The libraries argument should be a
list of library files as would be specified to ld. They will be searched in
the order given. The default is just \"-lc\", i.e., the C library. The
base-file argument is used to specify a file to use as the starting place for
defined symbols. The default is the C start up code for Lisp. The ENV
argument is the Unix environment variable definitions for the invocation of
the linker. The default is the environment passed to Lisp."
;; Note: dlopen() remembers the name of an object, when dlopen()ing
;; the same name twice, the old object is reused.
(declare (ignore base-file))
ENVIRONMENT argument is a list of SIMPLE-STRINGs corresponding to the Unix
environment (\"man environ\") definitions for the invocation of the linker.
The default is the environment that Lisp is itself running in. Instead of
using the ENVIRONMENT argument, it is also possible to use the ENV argument,
using the alternate, lossy representation used by CMU CL."
(when (and env-p environment-p)
(error "can't specify :ENV and :ENVIRONMENT simultaneously"))
(let ((output-file (pick-temporary-file-name
(concatenate 'string "/tmp/~D~C" (string (gensym)))))
(error-output (make-string-output-stream)))
Expand All @@ -206,7 +216,7 @@
(list files)
files))
libraries))
:env env
:environment environment
:input nil
:output error-output
:error :output)))
Expand All @@ -219,6 +229,5 @@
(load-1-foreign output-file))
#-sb-show (sb-unix:unix-unlink output-file)
#+sb-show (/show "not unlinking" output-file)))) ; so we can look at it
|#

) ; PROGN
2 changes: 1 addition & 1 deletion src/code/format-time.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.

(in-package "SB!EXT")
(in-package "SB!IMPL")

(defparameter *abbrev-weekday-table*
#("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"))
Expand Down
2 changes: 1 addition & 1 deletion src/code/late-extensions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.

(in-package "SB!EXT")
(in-package "SB!IMPL")

(defun featurep (x)
#!+sb-doc
Expand Down
Loading

0 comments on commit e5f24eb

Please sign in to comment.