From 4381ac90950cff7aea3dea689b32546be38cfe37 Mon Sep 17 00:00:00 2001 From: sperber Date: Tue, 13 Aug 2002 15:46:17 +0000 Subject: [PATCH] Add a whole bunch of S48_GC_PROTECT annotations in functions which call s48_extract_integer. s48_extract_integer can cause a callback for bignums, and, hence, heap allocation. This fixes a bug report by Seth Alves noting spurious failures in SET-FILE-TIMES. --- scsh/syscalls1.c | 217 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 174 insertions(+), 43 deletions(-) diff --git a/scsh/syscalls1.c b/scsh/syscalls1.c index 19c0cb1..6f04e8e 100644 --- a/scsh/syscalls1.c +++ b/scsh/syscalls1.c @@ -59,17 +59,21 @@ extern char **environ; s48_value wait_pid(s48_value s48_pid, s48_value s48_flags) { int status=0; - pid_t pid = (pid_t) s48_extract_integer (s48_pid); - int flags = s48_extract_integer (s48_flags); + pid_t pid; + int flags; pid_t result_pid; s48_value sch_retval = S48_UNSPECIFIC; s48_value sch_result_pid = S48_UNSPECIFIC; s48_value sch_status = S48_UNSPECIFIC; s48_value sch_status_list = S48_UNSPECIFIC; - S48_DECLARE_GC_PROTECT(3); + S48_DECLARE_GC_PROTECT(5); - S48_GC_PROTECT_3(sch_result_pid, sch_status, sch_status_list); + S48_GC_PROTECT_5(s48_pid, s48_flags, + sch_result_pid, sch_status, sch_status_list); + + pid = (pid_t) s48_extract_integer (s48_pid); + flags = s48_extract_integer (s48_flags); result_pid = waitpid(pid, &status, flags); if (result_pid == -1) @@ -259,12 +263,19 @@ s48_value scsh_rmdir(s48_value sch_path) s48_value scm_utime(s48_value sch_path, s48_value sch_ac, s48_value sch_mod) { - struct utimbuf t; - int retval; - t.actime = s48_extract_integer (sch_ac); - t.modtime = s48_extract_integer (sch_mod); - retval = utime(s48_extract_string (sch_path), &t); - if (retval == -1) + struct utimbuf t; + int retval; + S48_DECLARE_GC_PROTECT(3); + + S48_GC_PROTECT_3(sch_path, sch_ac, sch_mod); + + t.actime = s48_extract_integer (sch_ac); + t.modtime = s48_extract_integer (sch_mod); + retval = utime(s48_extract_string (sch_path), &t); + + S48_GC_UNPROTECT(); + + if (retval == -1) s48_raise_os_error_3(errno, sch_path, sch_ac, sch_mod); return S48_UNSPECIFIC; } @@ -409,8 +420,16 @@ s48_value cpu_clock_ticks_per_sec() s48_value scsh_chmod(s48_value sch_path, s48_value sch_mode) { - int retval = chmod (s48_extract_string(sch_path), - s48_extract_integer(sch_mode)); + int retval; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sch_path, sch_mode); + + retval = chmod (s48_extract_string(sch_path), + s48_extract_integer(sch_mode)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_2(errno, sch_path, sch_mode); return S48_UNSPECIFIC; @@ -418,8 +437,16 @@ s48_value scsh_chmod(s48_value sch_path, s48_value sch_mode) s48_value scsh_fchmod(s48_value sch_fd, s48_value sch_mode) { - int retval = fchmod (s48_extract_fixnum(sch_fd), - s48_extract_integer(sch_mode)); + int retval; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sch_fd, sch_mode); + + retval = fchmod (s48_extract_fixnum(sch_fd), + s48_extract_integer(sch_mode)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_2(errno, sch_fd, sch_mode); return S48_UNSPECIFIC; @@ -427,10 +454,17 @@ s48_value scsh_fchmod(s48_value sch_fd, s48_value sch_mode) s48_value scsh_chown(s48_value sch_path, s48_value sch_uid, s48_value sch_gid) { - int retval = chown(s48_extract_string(sch_path), - s48_extract_integer(sch_uid), - s48_extract_integer(sch_gid)); - + int retval; + S48_DECLARE_GC_PROTECT(3); + + S48_GC_PROTECT_3(sch_path, sch_uid, sch_gid); + + retval = chown(s48_extract_string(sch_path), + s48_extract_integer(sch_uid), + s48_extract_integer(sch_gid)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_3(errno, sch_path, sch_uid, sch_gid); return S48_UNSPECIFIC; @@ -438,9 +472,16 @@ s48_value scsh_chown(s48_value sch_path, s48_value sch_uid, s48_value sch_gid) s48_value scsh_fchown(s48_value sch_fd, s48_value sch_uid, s48_value sch_gid) { - int retval = fchown(s48_extract_fixnum(sch_fd), - s48_extract_integer(sch_uid), - s48_extract_integer(sch_gid)); + int retval; + S48_DECLARE_GC_PROTECT(3); + + S48_GC_PROTECT_3(sch_fd, sch_uid, sch_gid); + + retval = fchown(s48_extract_fixnum(sch_fd), + s48_extract_integer(sch_uid), + s48_extract_integer(sch_gid)); + + S48_GC_UNPROTECT(); if (retval == -1) s48_raise_os_error_3(errno, sch_fd, sch_uid, sch_gid); @@ -449,8 +490,16 @@ s48_value scsh_fchown(s48_value sch_fd, s48_value sch_uid, s48_value sch_gid) s48_value scsh_access(s48_value sch_path, s48_value sch_mode) { - int retval = access (s48_extract_string(sch_path), - s48_extract_integer(sch_mode)); + int retval; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sch_path, sch_mode); + + retval = access (s48_extract_string(sch_path), + s48_extract_integer(sch_mode)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_2(errno, sch_path, sch_mode); return S48_UNSPECIFIC; @@ -565,8 +614,16 @@ s48_value scsh_symlink(s48_value sch_name1, s48_value sch_name2) s48_value scsh_truncate(s48_value sch_path, s48_value sch_length) { - int retval = truncate (s48_extract_string (sch_path), - s48_extract_integer (sch_length)); + int retval; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sch_path, sch_length); + + retval = truncate (s48_extract_string (sch_path), + s48_extract_integer (sch_length)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_2(errno, sch_path, sch_length); return S48_UNSPECIFIC; @@ -574,8 +631,17 @@ s48_value scsh_truncate(s48_value sch_path, s48_value sch_length) s48_value scsh_ftruncate(s48_value sch_fdes, s48_value sch_length) { - int retval = ftruncate (s48_extract_fixnum (sch_fdes), - s48_extract_integer (sch_length)); + int retval; + + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sch_fdes, sch_length); + + retval = ftruncate (s48_extract_fixnum (sch_fdes), + s48_extract_integer (sch_length)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_2(errno, sch_fdes, sch_length); return S48_UNSPECIFIC; @@ -633,9 +699,17 @@ s48_value scsh_dup2(s48_value sch_oldd, s48_value sch_newd) s48_value scsh_lseek(s48_value sch_fdes, s48_value sch_offset, s48_value sch_whence) { - int retval = lseek (s48_extract_fixnum (sch_fdes), - s48_extract_integer (sch_offset), - s48_extract_fixnum (sch_whence)); + int retval; + S48_DECLARE_GC_PROTECT(3); + + S48_GC_PROTECT_3(sch_fdes, sch_offset, sch_whence); + + retval = lseek (s48_extract_fixnum (sch_fdes), + s48_extract_integer (sch_offset), + s48_extract_fixnum (sch_whence)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_3 (errno, sch_fdes, sch_offset, sch_whence); return s48_enter_integer (retval); @@ -690,7 +764,15 @@ s48_value scsh_getegid() s48_value scsh_setgid(s48_value gid) { - int retval = setgid (s48_extract_integer (gid)); + int retval; + S48_DECLARE_GC_PROTECT(1); + + S48_GC_PROTECT_1(gid); + + retval = setgid (s48_extract_integer (gid)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_1(errno, gid); return S48_UNSPECIFIC; @@ -698,11 +780,19 @@ s48_value scsh_setgid(s48_value gid) s48_value scsh_setegid(s48_value gid) { + int retval; + S48_DECLARE_GC_PROTECT(1); + + S48_GC_PROTECT_1(gid); + #ifdef HAVE_SETEGID - int retval = setegid (s48_extract_integer (gid)); + retval = setegid (s48_extract_integer (gid)); #else - int retval = setregid (-1, s48_extract_integer (gid)); + retval = setregid (-1, s48_extract_integer (gid)); #endif + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_1(errno, gid); return S48_UNSPECIFIC; @@ -757,7 +847,15 @@ s48_value scsh_geteuid() s48_value scsh_setuid(s48_value uid) { - int retval = setuid (s48_extract_integer (uid)); + int retval; + S48_DECLARE_GC_PROTECT(1); + + S48_GC_PROTECT_1(uid); + + retval = setuid (s48_extract_integer (uid)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_1(errno, uid); return S48_UNSPECIFIC; @@ -765,11 +863,19 @@ s48_value scsh_setuid(s48_value uid) s48_value scsh_seteuid(s48_value uid) { + int retval; + S48_DECLARE_GC_PROTECT(1); + + S48_GC_PROTECT_1(uid); + #ifdef HAVE_SETEUID - int retval = seteuid (s48_extract_integer (uid)); + retval = seteuid (s48_extract_integer (uid)); #else - int retval = setreuid (-1, s48_extract_integer (uid)); + retval = setreuid (-1, s48_extract_integer (uid)); #endif + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_1(errno, uid); return S48_UNSPECIFIC; @@ -792,8 +898,16 @@ s48_value scsh_getpgrp() s48_value scsh_setpgid(s48_value sch_pid, s48_value sch_pgrp) { - int retval = setpgid(s48_extract_integer(sch_pid), - s48_extract_integer(sch_pgrp)); + int retval; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sch_pid, sch_pgrp); + + retval = setpgid(s48_extract_integer(sch_pid), + s48_extract_integer(sch_pgrp)); + + S48_GC_UNPROTECT(); + if (retval == -1) s48_raise_os_error_2(errno, sch_pid, sch_pgrp); return S48_UNSPECIFIC; @@ -962,8 +1076,16 @@ s48_value errno_msg(s48_value sch_i) s48_value fcntl_read(s48_value fd, s48_value command) { - int ret = fcntl(s48_extract_fixnum (fd), - s48_extract_integer (command)); + int ret; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(fd, command); + + ret = fcntl(s48_extract_fixnum (fd), + s48_extract_integer (command)); + + S48_GC_UNPROTECT(); + if (ret == -1) s48_raise_os_error_2(errno, fd, command); else return s48_enter_fixnum (ret); @@ -972,9 +1094,18 @@ s48_value fcntl_read(s48_value fd, s48_value command) s48_value fcntl_write(s48_value fd, s48_value command, s48_value value) { - int ret = fcntl(s48_extract_fixnum (fd), - s48_extract_integer (command), - s48_extract_integer (value)); + int ret; + + S48_DECLARE_GC_PROTECT(3); + + S48_GC_PROTECT_3(fd, command, value); + + ret = fcntl(s48_extract_fixnum (fd), + s48_extract_integer (command), + s48_extract_integer (value)); + + S48_GC_UNPROTECT(); + if (ret == -1) s48_raise_os_error_3(errno, fd, command, value); else return s48_enter_fixnum (ret);