This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgloss/arm syscalls [PATCH]


Happy winter times, Jeff and all!

This patch implements a number of unistd calls with the best suited
syscall that the ARM kernel provides.

link(2) is mapped to the Rename syscall. The most common use of
link(2) is probably in renaming a file by calling link(oldpath,
newpath); unlink(oldpath). Mapping link(2) to the Rename syscall
allows this idiom to have the desired effect.

mknod(2) and other mkxxx(2) calls are mapped to open(2), with the mode
argument set appropriately.

See the ChangeLog for further mappings.

Cheers,
Shaun

2005-12-02  Shaun Jackman  <sjackman@gmail.com>

	* libcfunc.c (chdir, chmod, chown, dup, dup2, ioctl, readlink,
	symlink, utime): New fuction. Call the syscall.
	(ftruncate): New function. Call lseek.
	(lstat): New function. Call stat.
	(mknod): New function. Call creat.
	(mkdir): New function. Call mknod.
	(mkfifo): New function. Call mknod.
	(rmdir): New function. Call _unlink.
	(stime): New function. Set _stime_offset;
	(truncate): New function: Call open, ftruncate, close.
	(umask): New fuction. Stub.
	* syscalls.c (_link): Call _rename.
	(_stime_offset): New variable.
	(_gettimeofday): Add _stime_offset to the current time.
	(_execve): Call the System syscall.
	(_system): Call _execve.
	(getdents): Call _read.

Index: libcfunc.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/libcfunc.c,v
retrieving revision 1.6
diff -u -r1.6 libcfunc.c
--- libcfunc.c	30 Nov 2005 23:37:14 -0000	1.6
+++ libcfunc.c	2 Dec 2005 17:58:21 -0000
@@ -8,6 +8,10 @@

 #include "swi.h"
 #include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <time.h>
 #include <unistd.h>

 #ifdef ARM_RDI_MONITOR
@@ -43,11 +47,53 @@
 	return 0;
 }

+int __attribute__((weak))
+chdir(const char *path)
+{
+	return _chdir(path);
+}
+
+int __attribute__((weak))
+chmod(const char *path, mode_t mode)
+{
+	return _chmod(path, mode);
+}
+
+int __attribute__((weak))
+chown(const char *path, uid_t owner, gid_t group)
+{
+	return _chown(path, owner, group);
+}
+
 clock_t _clock(void);
 clock_t __attribute__((weak))
 clock(void)
 {
-      return _clock();
+	return _clock();
+}
+
+int __attribute__((weak))
+dup(int fildes)
+{
+	return _dup(fildes);
+}
+
+int __attribute__((weak))
+dup2(int fildes, int fildes2)
+{
+	return _dup2(fildes, fildes2);
+}
+
+int __attribute__((weak))
+ftruncate(int fildes, off_t length)
+{
+	return lseek(fildes, SEEK_SET, length) == (off_t)-1 ? -1 : 0;
+}
+
+int __attribute__((weak))
+ioctl(int fildes, int request, void *arg)
+{
+	return _ioctl(fildes, request, arg);
 }

 int _isatty(int fildes);
@@ -58,14 +104,54 @@
 }

 int __attribute__((weak))
+lstat(const char *path, struct stat *buf)
+{
+	return stat(path, buf);
+}
+
+int __attribute__((weak))
+mknod(const char *path, mode_t mode, dev_t dev)
+{
+	int fd = creat(path, mode | dev << 16);
+	if (fd == -1) return -1;
+	close(fd);
+	return 0;
+}
+
+#ifdef S_IFDIR
+int __attribute__((weak))
+mkdir(const char *path, mode_t mode)
+{
+	return mknod(path, S_IFDIR | mode, 0);
+}
+#endif
+
+#ifdef S_IFIFO
+int __attribute__((weak))
+mkfifo(const char *path, mode_t mode)
+{
+	return mknod(path, S_IFIFO | mode, 0);
+}
+#endif
+
+int __attribute__((weak))
 pause(void)
 {
 	errno = ENOSYS;
 	return -1;
 }

-#include <sys/types.h>
-#include <time.h>
+ssize_t __attribute__((weak))
+readlink(const char *path, char *buf, size_t bufsize)
+{
+	return _readlink(path, buf, bufsize);
+}
+
+int __attribute__((weak))
+rmdir(const char *path)
+{
+	return _unlink(path);
+}

 unsigned __attribute__((weak))
 sleep(unsigned seconds)
@@ -78,6 +164,39 @@
 }

 int __attribute__((weak))
+stime(time_t *t)
+{
+	extern time_t _stime_offset;
+	_stime_offset = *t - time(NULL);
+	return 0;
+}
+
+int __attribute__((weak))
+symlink(const char *path1, const char *path2)
+{
+	return _symlink(path1, path2);
+}
+
+int __attribute__((weak))
+truncate(const char *path, off_t length)
+{
+	int status, fd = open(path, O_WRONLY);
+	if (fd == -1) return -1;
+	status = ftruncate(fd, length);
+	close(fd);
+	return status;
+}
+
+mode_t __attribute__((weak))
+umask(mode_t cmask)
+{
+	static mode_t mask = 0022;
+	mode_t previous = mask;
+	mask = cmask & 0777;
+	return previous;
+}
+
+int __attribute__((weak))
 usleep(useconds_t useconds)
 {
 	clock_t t0 = _clock();
@@ -86,3 +205,11 @@
 	while (_clock() - t0  < dt);
 	return 0;
 }
+
+struct utimbuf;
+
+int __attribute__((weak))
+utime(const char *path, const struct utimbuf *times)
+{
+	return _utime(path, times);
+}
Index: syscalls.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
retrieving revision 1.8
diff -u -r1.8 syscalls.c
--- syscalls.c	30 Nov 2005 23:37:14 -0000	1.8
+++ syscalls.c	2 Dec 2005 17:58:21 -0000
@@ -23,7 +23,7 @@
 clock_t _times		_PARAMS ((struct tms *));
 int     _gettimeofday	_PARAMS ((struct timeval *, struct timezone *));
 int     _unlink		_PARAMS ((const char *));
-int     _link 		_PARAMS ((void));
+int     _link		_PARAMS ((const char *, const char *));
 int     _stat 		_PARAMS ((const char *, struct stat *));
 int     _fstat 		_PARAMS ((int, struct stat *));
 caddr_t _sbrk		_PARAMS ((int));
@@ -550,10 +550,9 @@
 }

 int __attribute__((weak))
-_link (void)
+_link(const char *path1, const char *path2)
 {
-  errno = ENOSYS;
-  return -1;
+  return _rename(path1, path2);
 }

 int
@@ -567,6 +566,8 @@
 #endif
 }

+time_t _stime_offset;
+
 int
 _gettimeofday (struct timeval * tp, struct timezone * tzp)
 {
@@ -583,6 +584,7 @@
         tp->tv_sec = value;
       }
 #endif
+      tp->tv_sec += _stime_offset;
       tp->tv_usec = 0;
     }

@@ -639,18 +641,25 @@
 #endif
 }

-int
-_system (const char *s)
+int __attribute__((weak))
+_execve(const char *path, char *const argv[], char *const envp[])
 {
 #ifdef ARM_RDI_MONITOR
-  return do_AngelSWI (AngelSWI_Reason_System, &s);
+  (void)argv; (void)envp;
+  return do_AngelSWI (AngelSWI_Reason_System, &path);
 #else
-  (void)s;
+  (void)path; (void)argv; (void)envp;
   asm ("swi %a0" :: "i" (SWI_CLI));
 #endif
 }

 int
+_system (const char *s)
+{
+  return _execve(s, NULL, NULL);
+}
+
+int
 _rename (const char * oldpath, const char * newpath)
 {
 #ifdef ARM_RDI_MONITOR
@@ -661,3 +670,11 @@
   asm ("swi %a0" :: "i" (SWI_Rename));
 #endif
 }
+
+struct dirent;
+
+ssize_t
+getdents(int fd, struct dirent *dirp, size_t count)
+{
+	return _read(fd, (void*)dirp, count);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]