[kaffe] CVS kaffe (robilad): Implemented thread safe wrappers for
some target system calls
Kaffe CVS
cvs-commits at kaffe.org
Tue Aug 2 02:56:56 PDT 2005
PatchSet 6776
Date: 2005/08/02 09:52:11
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Implemented thread safe wrappers for some target system calls
2005-08-02 Dalibor Topic <robilad at kaffe.org>
* include/jsyscall.h:
(KOPEN, KLSEEK, KCLOSE, KFSTAT) Documented.
* libraries/clib/target/Linux/target_native_file.h
(TARGET_NATIVE_FILE_OPEN, TARGET_NATIVE_FILE_CLOSE,
TARGET_NATIVE_FILE_AVAILABLE, TARGET_NATIVE_FILE_SIZE,
TARGET_NATIVE_FILE_TELL): New macros used to delegate
system calls to thread-safe wrappers for system calls.
Reported by: Guilhem Lavaux <guilhem at kaffe.org>
Members:
ChangeLog:1.4301->1.4302
include/jsyscall.h:1.21->1.22
libraries/clib/target/Linux/target_native_file.h:1.1->1.2
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4301 kaffe/ChangeLog:1.4302
--- kaffe/ChangeLog:1.4301 Mon Aug 1 20:53:36 2005
+++ kaffe/ChangeLog Tue Aug 2 09:52:11 2005
@@ -1,3 +1,16 @@
+2005-08-02 Dalibor Topic <robilad at kaffe.org>
+
+ * include/jsyscall.h:
+ (KOPEN, KLSEEK, KCLOSE, KFSTAT) Documented.
+
+ * libraries/clib/target/Linux/target_native_file.h
+ (TARGET_NATIVE_FILE_OPEN, TARGET_NATIVE_FILE_CLOSE,
+ TARGET_NATIVE_FILE_AVAILABLE, TARGET_NATIVE_FILE_SIZE,
+ TARGET_NATIVE_FILE_TELL): New macros used to delegate
+ system calls to thread-safe wrappers for system calls.
+
+ Reported by: Guilhem Lavaux <guilhem at kaffe.org>
+
2005-08-01 Guilhem Lavaux <guilhem at kaffe.org>
* test/jni/Makefile.am: Fixed typo.
@@ -32,7 +45,7 @@
* test/regression/Makefile.in: regenerated.
-2005-07-26 Dalibor Topic <robilad at kaffe.org>
+2005-07-30 Dalibor Topic <robilad at kaffe.org>
Resynced with GNU Classpath.
Index: kaffe/include/jsyscall.h
diff -u kaffe/include/jsyscall.h:1.21 kaffe/include/jsyscall.h:1.22
--- kaffe/include/jsyscall.h:1.21 Tue May 31 17:55:49 2005
+++ kaffe/include/jsyscall.h Tue Aug 2 09:52:14 2005
@@ -108,12 +108,56 @@
* Define some convenience macros
*/
-#define KOPEN(A,B,C,D) (*Kaffe_SystemCallInterface._open)(A,B,C,D)
+/**
+ * Open a file in a platform-independant, thread-safe way, and
+ * set the filedescriptor to the opened file's descriptor.
+ *
+ * @param filename name of file to open.
+ * @param flags flags to pass to open
+ * @param permissions permissions with which the file is to be opened
+ * @param filedescriptor pointer to the filedescriptor to store the result in
+ *
+ * @return 0 on success, or errno on failure.
+ */
+#define KOPEN(filename, flags, permissions, filedescriptor) \
+ (*Kaffe_SystemCallInterface._open)(filename, flags, permissions, filedescriptor)
+
#define KREAD(A,B,C,D) (*Kaffe_SystemCallInterface._read)(A,B,C,D)
#define KWRITE(A,B,C,D) (*Kaffe_SystemCallInterface._write)(A,B,C,D)
-#define KLSEEK(A,B,C,D) (*Kaffe_SystemCallInterface._lseek)(A,B,C,D)
-#define KCLOSE(A) (*Kaffe_SystemCallInterface._close)(A)
-#define KFSTAT(A,B) (*Kaffe_SystemCallInterface._fstat)(A,B)
+
+/**
+ * Reposition read/write offset in a file in a
+ * platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to stat
+ * @param offset offset to set
+ * @param whence how to set the offset
+ * @param new_offset new value of read/write offset
+ *
+ * @return 0 on success, or errno on failure.
+ */
+#define KLSEEK(filedescriptor, offset, whence, new_offset) \
+ (*Kaffe_SystemCallInterface._lseek)(filedescriptor, offset, whence, new_offset)
+
+/**
+ * Close a file in a platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to close
+ *
+ * @return 0 on success, or errno on failure.
+ */
+#define KCLOSE(filedescriptor) \
+ (*Kaffe_SystemCallInterface._close)(filedescriptor)
+
+/**
+ * FStat a file in a platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to stat
+ * @param stats return buffer
+ *
+ * @return 0 on success, or errno on failure.
+ */
+#define KFSTAT(filedescriptor, stats) (*Kaffe_SystemCallInterface._fstat)(filedescriptor, stats)
#define KSTAT(A,B) (*Kaffe_SystemCallInterface._stat)(A,B)
#define KFTRUNCATE(A,B) (*Kaffe_SystemCallInterface._ftruncate)(A,B)
#define KFSYNC(A) (*Kaffe_SystemCallInterface._fsync)(A)
Index: kaffe/libraries/clib/target/Linux/target_native_file.h
diff -u kaffe/libraries/clib/target/Linux/target_native_file.h:1.1 kaffe/libraries/clib/target/Linux/target_native_file.h:1.2
--- kaffe/libraries/clib/target/Linux/target_native_file.h:1.1 Tue Jul 19 01:16:37 2005
+++ kaffe/libraries/clib/target/Linux/target_native_file.h Tue Aug 2 09:52:14 2005
@@ -49,6 +49,8 @@
#include <stdlib.h>
+#include "jsyscall.h"
+
/****************** Conditional compilation switches *******************/
/***************************** Constants *******************************/
@@ -67,6 +69,175 @@
#ifdef __cplusplus
}
+#endif
+
+/***********************************************************************\
+* Name : TARGET_NATIVE_FILE_OPEN
+* Purpose : open a file
+* Input : -
+* Output : -
+* Return : -
+* Side-effect: unknown
+* Notes : file is created if it does not exist
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_OPEN
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #define TARGET_NATIVE_FILE_OPEN(filename,filedescriptor,flags,permissions,result) \
+ do { \
+ int kopen_result; \
+ kopen_result=KOPEN(filename, \
+ flags, \
+ permissions, \
+ &filedescriptor); \
+ if (kopen_result == 0) \
+ fcntl (filedescriptor,F_SETFD,FD_CLOEXEC); \
+ result=(kopen_result == 0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+ } while (0)
+#endif
+
+/***********************************************************************\
+* Name : TARGET_NATIVE_FILE_CLOSE
+* Purpose : close a file
+* Input : -
+* Output : -
+* Return : -
+* Side-effect: unknown
+* Notes : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_CLOSE
+ #include <unistd.h>
+ #define TARGET_NATIVE_FILE_CLOSE(filedescriptor,result) \
+ do { \
+ result=(KCLOSE(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+ } while (0)
+#endif
+
+/***********************************************************************\
+* Name : TARGET_NATIVE_FILE_AVAILABLE
+* Purpose : get available bytes for read
+* Input : -
+* Output : -
+* Return : -
+* Side-effect: unknown
+* Notes : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_AVAILABLE
+ #if defined(HAVE_FSTAT)
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
+ do { \
+ struct stat __statBuffer; \
+ off_t __n; \
+ \
+ length=0; \
+ \
+ if ((KFSTAT(filedescriptor,&__statBuffer)==0) && S_ISREG(__statBuffer.st_mode)) \
+ { \
+ int klseek_result; \
+ klseek_result=(KLSEEK(filedescriptor,0,SEEK_CUR, &__n)); \
+ if (klseek_result == 0) \
+ { \
+ length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size-__n); \
+ result=TARGET_NATIVE_OK; \
+ } \
+ else \
+ { \
+ result=TARGET_NATIVE_ERROR; \
+ } \
+ } \
+ else \
+ { \
+ result=TARGET_NATIVE_ERROR; \
+ } \
+ } while (0)
+ #elif defined(HAVE_SELECT)
+ #include <string.h>
+ #include <sys/select.h>
+ #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
+ do { \
+ fd_set __filedescriptset; \
+ struct timeval __timeval; \
+ int kselect_result; \
+ int num_available; \
+ \
+ length=0; \
+ \
+ FD_ZERO(&__filedescriptset); \
+ FD_SET(filedescriptor,&__filedescriptset); \
+ memset(&__timeval,0,sizeof(__timeval)); \
+ kselect_result = KSELECT(filedescriptor+1,&__filedescriptset,NULL,NULL,&__timeval, &num_available); \
+ if (kselect_result == 0) \
+ { \
+ switch (num_available) \
+ { \
+ case 0: length=TARGET_NATIVE_MATH_INT_INT64_CONST_0; result=TARGET_NATIVE_OK; break; \
+ default: length=TARGET_NATIVE_MATH_INT_INT64_CONST_1; result=TARGET_NATIVE_OK; break; \
+ } \
+ } \
+ else \
+ { \
+ result=TARGET_NATIVE_ERROR; break; \
+ } \
+ } while (0)
+ #else
+ #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
+ do { \
+ errno=TARGET_NATIVE_ERROR_OPERATION_NOT_PERMITTED; \
+ length=0; \
+ result=TARGET_NATIVE_ERROR; \
+ } while (0)
+ #endif
+#endif
+
+/***********************************************************************\
+* Name : TARGET_NATIVE_FILE_SIZE
+* Purpose : get size of file (in bytes)
+* Input : -
+* Output : -
+* Return : -
+* Side-effect: unknown
+* Notes : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_SIZE
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #define TARGET_NATIVE_FILE_SIZE(filedescriptor,length,result) \
+ do { \
+ struct stat __statBuffer; \
+ \
+ result=(KFSTAT(filedescriptor,&__statBuffer)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+ length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size); \
+ } while (0)
+#endif
+
+/***********************************************************************\
+* Name : TARGET_NATIVE_FILE_TELL
+* Purpose : get current file position
+* Input : -
+* Output : -
+* Return : -
+* Side-effect: unknown
+* Notes : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_TELL
+ #include <sys/types.h>
+ #include <unistd.h>
+ #define TARGET_NATIVE_FILE_TELL(filedescriptor,offset,result) \
+ do { \
+ int klseek_result; \
+ klseek_result=KLSEEK(filedescriptor,TARGET_NATIVE_MATH_INT_INT64_CONST_0,SEEK_CUR, &offset); \
+ result=(klseek_result==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+ } while (0)
#endif
/* include rest of definitions from generic file (do not move it to
More information about the kaffe
mailing list