⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syscalls.c

📁 kaffe是一个java虚拟机的源代码。里面包含了一些java例程和标准的java包。
💻 C
字号:
/* * syscalls.c * * Copyright (c) 1996, 1997 *      Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */#include "config.h"#include "config-std.h"#include "config-mem.h"#include "config-io.h"#include "config-signal.h"#include "config-net.h"#include "jthread.h"#include "jsyscall.h"#include "nets.h"/* * This file contains thread-safe version of various POSIXy functions. * Other functions that use or interact with asynchronous I/O, are in jthread.c. */static intjthreadedClose(int fd){	int rc = 0;	jthread_spinon(0);	if (close(fd) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedListen(int fd, int l){	int rc = 0;	jthread_spinon(0);	if (listen(fd, l) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedKill(int pid, int sig){	int rc = 0;	jthread_spinon(0);	if (kill(pid, sig) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedBind(int fd, struct sockaddr *addr, int namelen){	int rc = 0;	jthread_spinon(0);	if (bind(fd, addr, namelen) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedLSeek(int fd, off_t offset, int whence, off_t *out){	int rc = 0;	jthread_spinon(0);	*out = lseek(fd, offset, whence);	if (*out == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedFStat(int fd, struct stat *sb){	int rc = 0;	jthread_spinon(0);	if (fstat(fd, sb) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedStat(const char* path, struct stat *sb){	int rc = 0;	jthread_spinon(0);	if (stat(path, sb) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedMkdir(const char *path, int mode){	int rc = 0;	jthread_spinon(0);	if (mkdir(path, mode) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedRmdir(const char *path){	int rc = 0;	jthread_spinon(0);	if (rmdir(path) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedRename(const char *path1, const char *path2){	int rc = 0;	jthread_spinon(0);	if (rename(path1, path2) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedRemove(const char *entry){	int rc = 0;	jthread_spinon(0);	if (remove(entry) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static int     jthreadedSendto(int a, const void* b, size_t c, int d, const struct sockaddr* e,		int f, ssize_t *out){	int rc = 0;	jthread_spinon(0);	*out = e ? sendto(a, b, c, d, e, f) : send(a, b, c, d);	if (*out == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedSetSockOpt(int a, int b, int c, const void* d, int e){	int rc = 0;	jthread_spinon(0);	if (setsockopt(a, b, c, d, e) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedGetSockOpt(int a, int b, int c, void* d, int* e){	int rc = 0;	jthread_spinon(0);	if (getsockopt(a, b, c, d, e) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedGetSockName(int a, struct sockaddr* b, int* c){	int rc = 0;	jthread_spinon(0);	if (getsockname(a, b, c) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedGetPeerName(int a, struct sockaddr* b, int* c){	int rc = 0;	jthread_spinon(0);	if (getpeername(a, b, c) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}static intjthreadedGetHostByName(const char *host, struct hostent** out){	int rc = 0;	jthread_spinon(0);	/* NB: this will block the whole process while we're looking up	 * a name.  However, gethostbyname is extremely async-signal-unsafe,	 * and hence we have no other choice.  Now I understand why old 	 * Netscapes blocked when looking up a name.  	 *	 * In a UNIXy system, a possible solution is to spawn a process	 * for lookups, which I think is what NS eventually did.	 */	*out = gethostbyname(host);	if (*out == 0) {		rc = h_errno;		if (rc == 0) {			*out = (void*)-1;			rc = errno;		}	}	jthread_spinoff(0);	return (rc);}static intjthreadedGetHostByAddr(const char *host, int l, int t, struct hostent** out){	int rc = 0;	jthread_spinon(0);	/* NB: same comment as for jthreadedGetHostByName applies here */	*out = gethostbyaddr(host, l, t);	if (*out == 0) {		rc = h_errno;		if (rc == 0) {			*out = (void*)-1;			rc = errno;		}	}	jthread_spinoff(0);	return (rc);}static intjthreadedSelect(int a, fd_set* b, fd_set* c, fd_set* d, 		struct timeval* e, int* out){	int rc = 0;	jthread_spinon(0);	if ((*out = select(a, b, c, d, e)) == -1) {		rc = errno;	}	jthread_spinoff(0);	return (rc);}/* * The syscall interface as provided by the internal jthread system. */SystemCallInterface Kaffe_SystemCallInterface = {        jthreadedOpen,        jthreadedRead,	        jthreadedWrite,         jthreadedLSeek,        jthreadedClose,        jthreadedFStat,        jthreadedStat,        jthreadedMkdir,        jthreadedRmdir,        jthreadedRename,        jthreadedRemove,        jthreadedSocket,        jthreadedConnect,        jthreadedBind,        jthreadedListen,        jthreadedAccept,         jthreadedTimedRead,	        jthreadedRecvfrom,        jthreadedWrite,         jthreadedSendto,	        jthreadedSetSockOpt,	        jthreadedGetSockOpt,        jthreadedGetSockName,         jthreadedGetPeerName,         jthreadedClose,        jthreadedGetHostByName,        jthreadedGetHostByAddr,        jthreadedSelect,	        jthreadedForkExec,        jthreadedWaitpid,        jthreadedKill};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -