source: branches/working-0711/ccl/lisp-kernel/unix-calls.c @ 11456

Last change on this file since 11456 was 11456, checked in by gb, 11 years ago

Use syscall() for read/write/open/close on Linux, so that we can
see if this affects performance. (If the C library's handling
of async cancel points affects performance, there may be other
things - like #_poll - that're also negatively affected, but
if that is the culprit, changing read and write should help.)

File size: 2.6 KB
Line 
1/*
2   Copyright (C) 2008, Clozure Associates and contributors
3   This file is part of Clozure CL. 
4
5   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
6   License , known as the LLGPL and distributed with Clozure CL as the
7   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
8   which is distributed with Clozure CL as the file "LGPL".  Where these
9   conflict, the preamble takes precedence. 
10
11   Clozure CL is referenced in the preamble as the "LIBRARY."
12
13   The LLGPL is also available online at
14   http://opensource.franz.com/preamble.html
15*/
16
17/* Provide wrappers around some standard C library functions that
18   can't easily be called from CCL's FFI for some reason (or where
19   we want to override/extend the function's default behavior.)
20 
21   Functions in this file should be referenced via the kernel
22   imports table.
23
24   Callers should generally expect standard C library error-handling
25   conventions (e.g., return -1 or NULL and set errno on error.)
26*/
27
28#define _LARGEFILE64_SOURCE
29#include <errno.h>
30#include <unistd.h>
31#include <sys/stat.h>
32#include <dirent.h>
33#include <sys/syscall.h>
34#include <sys/time.h>
35#include <stdint.h>
36
37ssize_t
38lisp_read(int fd, void *buf, size_t count)
39{
40#ifdef LINUX
41  return syscall(SYS_read,fd,buf,count);
42#else
43  return read(fd,buf,count);
44#endif
45}
46
47ssize_t
48lisp_write(int fd, void *buf, size_t count)
49{
50#ifdef LINUX
51  return syscall(SYS_write,fd,buf,count);
52#else
53  return write(fd,buf,count);
54#endif
55}
56
57int
58lisp_open(char *path, int flags, mode_t mode)
59{
60#ifdef LINUX
61  return syscall(SYS_open,path,flags,mode);
62#else
63  return open(path,flags,mode);
64#endif
65}
66
67int
68lisp_fchmod(int fd, mode_t mode)
69{
70  return fchmod(fd,mode);
71}
72
73int64_t
74lisp_lseek(int fd, int64_t offset, int whence)
75{
76#ifdef LINUX
77  return lseek64(fd,offset,whence);
78#else
79  return lseek(fd,offset,whence);
80#endif
81}
82
83int
84lisp_close(int fd)
85{
86  return close(fd);
87}
88
89int
90lisp_ftruncate(int fd, off_t length)
91{
92  return ftruncate(fd,length);
93}
94
95int
96lisp_stat(char *path, void *buf)
97{
98  return stat(path,buf);
99}
100
101int
102lisp_fstat(int fd, void *buf)
103{
104  return fstat(fd,buf);
105}
106
107
108int
109lisp_futex(int *uaddr, int op, int val, void *timeout, int *uaddr2, int val3)
110{
111#ifdef LINUX
112  return syscall(SYS_futex,uaddr,op,val,timeout,uaddr2,val3);
113#else
114  errno = ENOSYS;
115  return -1;
116#endif
117}
118
119DIR *
120lisp_opendir(char *path)
121{
122  return opendir(path);
123}
124
125struct dirent *
126lisp_readdir(DIR *dir)
127{
128  return readdir(dir);
129}
130
131int
132lisp_closedir(DIR *dir)
133{
134  return closedir(dir);
135}
136
137int
138lisp_pipe(int pipefd[2])
139{
140  return pipe(pipefd);
141}
142
143int
144lisp_gettimeofday(struct timeval *tp, void *tzp)
145{
146  return gettimeofday(tp, tzp);
147}
Note: See TracBrowser for help on using the repository browser.