_Exit
is implemented by jumping to the return capability, which is
assumed to be set before program execution begins.
TODO
Dandelion only exposes the abstraction of "inputs" and "outputs", which are binary blobs of data. To ease interoperability with existing code, we also aim to support file I/O, both as specified in the C standard library, as well as posix files. We achieve this in the following manner:
Each input and output is represented as a simple growable vector of the following form:
struct buf {
void* data;
size_t length;
size_t min_size;
}
This buffer can be written to, and the data pointer can be set explicitly, for example to a user-allocated buffer.
To enable support for files, we additionally need to keep track of things such as seek position, I/O mode (standard vs wide), mode, etc. We achieve this by storing files in the following manner:
struct _IO_file {
struct buf* buf;
size_t offset;
int mode;
}
This is also necessary to be able to open the same output multiple times, and read ad different offset simultaneously.
Furthermore, to enable us to associate files with inputs and outputs, we receive a metadata input, which contains a mapping from file paths (relative to a virtual root directory in which the program is executing) to input/output numbers, e.g.:
"/hello.txt" => input 0 "/x/y.txt" => output 1 "/foo.c" => input 1
Executing fopen
then proceeds as follows:
- Find input or output that requested file maps to.
- Check that mode flags make sense (e.g. we're not trying to write to an input file.
- Allocate a
struct _IO_file
, say,file
- Point the
buf
member offile
to the input/output we found in step 1.
All POSIX functions interacting with files are implemented on top of
struct _IO_file
. When open
is called, a new file descriptor is
allocated in a global table, with a corresponding instance of
struct _IO_file
. Any operations on the file descriptor are simply
delegated to the stdio implementation through the global table.
If open
is called with O_CREAT
, and there is no metadata entry
corresponding to the filename specified, the file is created as
a temporary file. We keep a separate mapping from newly created files
to file buffers. These are implicitly destroyed when the process exits.
dlibc's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.