unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: guile-devel@gnu.org
Subject: [PATCH] Verify Size of Objcode Headers
Date: Sun, 20 Jun 2010 15:44:58 -0400	[thread overview]
Message-ID: <AANLkTin3t5ss9MnTEKwx2Am18kQ_IsUZpeNtZK5CQTzB@mail.gmail.com> (raw)

Add static checks to make sure that the statically-generated object code
headers in continuations.c, control.c, foreign.c, gsubr.c and smob.c are the
same length as the struct scm_objcode data type in objcodes.h.
---
 libguile/continuations.c |    4 ++++
 libguile/control.c       |    3 +++
 libguile/foreign.c       |    3 +++
 libguile/gsubr.c         |    3 +++
 libguile/objcodes.h      |    5 +++++
 libguile/smob.c          |    3 +++
 6 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/libguile/continuations.c b/libguile/continuations.c
index dc504f0..e99043f 100644
--- a/libguile/continuations.c
+++ b/libguile/continuations.c
@@ -37,6 +37,7 @@
 #include "libguile/eval.h"
 #include "libguile/vm.h"
 #include "libguile/instructions.h"
+#include "libguile/objcodes.h"

 #include "libguile/validate.h"
 #include "libguile/continuations.h"
@@ -537,6 +538,9 @@ SCM_DEFINE (scm_with_continuation_barrier,
"with-continuation-barrier", 1,0,0,
 void
 scm_init_continuations ()
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER(5,5) };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
   tc16_continuation = scm_make_smob_type ("continuation", 0);
   scm_set_smob_print (tc16_continuation, continuation_print);
 #include "libguile/continuations.x"
diff --git a/libguile/control.c b/libguile/control.c
index 6c20675..91fedf1 100644
--- a/libguile/control.c
+++ b/libguile/control.c
@@ -271,6 +271,9 @@ scm_i_prompt_print (SCM exp, SCM port,
scm_print_state *pstate SCM_UNUSED)
 void
 scm_init_control (void)
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER(5,5) };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
 #include "libguile/control.x"
 }

diff --git a/libguile/foreign.c b/libguile/foreign.c
index aae4c67..60a01a1 100644
--- a/libguile/foreign.c
+++ b/libguile/foreign.c
@@ -1028,6 +1028,9 @@ scm_i_foreign_call (SCM foreign, const SCM *argv)
 static void
 scm_init_foreign (void)
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
 #ifndef SCM_MAGIC_SNARFER
 #include "libguile/foreign.x"
 #endif
diff --git a/libguile/gsubr.c b/libguile/gsubr.c
index de4bff6..c01471c 100644
--- a/libguile/gsubr.c
+++ b/libguile/gsubr.c
@@ -878,6 +878,9 @@ gsubr_21l(SCM req1, SCM req2, SCM opt, SCM rst)
 void
 scm_init_gsubr()
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
 #ifdef GSUBR_TEST
   scm_c_define_gsubr ("gsubr-2-1-l", 2, 1, 1, gsubr_21l); /* example */
 #endif
diff --git a/libguile/objcodes.h b/libguile/objcodes.h
index 2bff9aa..cb86e63 100644
--- a/libguile/objcodes.h
+++ b/libguile/objcodes.h
@@ -21,6 +21,8 @@

 #include <libguile.h>

+#include <verify.h> /* from Gnulib, in guile/lib */
+
 /* Objcode data should be directly mappable to this C structure.  */
 struct scm_objcode
 {
@@ -54,6 +56,9 @@ struct scm_objcode
 #define SCM_OBJCODE_IS_BYTEVECTOR(x) (SCM_OBJCODE_FLAGS (x) &
SCM_F_OBJCODE_IS_BYTEVECTOR)
 #define SCM_OBJCODE_IS_SLICE(x) (SCM_OBJCODE_FLAGS (x) &
SCM_F_OBJCODE_IS_SLICE)

+#define VERIFY_OBJCODE_HEADER_SIZE(header) verify(sizeof(header)        \
+                                                  == sizeof(struct
scm_objcode))
+
 SCM scm_c_make_objcode_slice (SCM parent, const scm_t_uint8 *ptr);
 SCM_API SCM scm_load_objcode (SCM file);
 SCM_API SCM scm_objcode_p (SCM obj);
diff --git a/libguile/smob.c b/libguile/smob.c
index 171db8d..3aba9de 100644
--- a/libguile/smob.c
+++ b/libguile/smob.c
@@ -598,6 +598,9 @@ void
 scm_smob_prehistory ()
 {
   long i;
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER };
+
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);

   smob_gc_kind = GC_new_kind (GC_new_free_list (),
 			      GC_MAKE_PROC (GC_new_proc (smob_mark), 0),
-- 
1.7.1



             reply	other threads:[~2010-06-20 19:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-20 19:44 Noah Lavine [this message]
2010-06-20 20:30 ` [PATCH] Verify Size of Objcode Headers Andy Wingo
2010-06-20 21:22 ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2010-06-20 23:59 Noah Lavine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTin3t5ss9MnTEKwx2Am18kQ_IsUZpeNtZK5CQTzB@mail.gmail.com \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).