about summary refs log tree commit diff
path: root/src/libstd/libc.rs
AgeCommit message (Collapse)AuthorLines
2014-02-16Implement named pipes for windows, touch up unixAlex Crichton-4/+53
* Implementation of pipe_win32 filled out for libnative * Reorganize pipes to be clone-able * Fix a few file descriptor leaks on error * Factor out some common code into shared functions * Make use of the if_ok!() macro for less indentation Closes #11201
2014-02-16Implement Unix domain sockets in libnativeGeoffroy Couprie-0/+24
2014-02-16Allow configuration of uid/gid/detach on processesAlex Crichton-1/+5
This just copies the libuv implementation for libnative which seems reasonable enough (uid/gid fail on windows). Closes #12082
2014-02-09Fix the signature of CreateSymbolicLinkWAlex Crichton-8/+10
Closes #12123
2014-02-05Implement clone() for TCP/UDP/Unix socketsAlex Crichton-0/+49
This is part of the overall strategy I would like to take when approaching issue #11165. The only two I/O objects that reasonably want to be "split" are the network stream objects. Everything else can be "split" by just creating another version. The initial idea I had was the literally split the object into a reader and a writer half, but that would just introduce lots of clutter with extra interfaces that were a little unnnecssary, or it would return a ~Reader and a ~Writer which means you couldn't access things like the remote peer name or local socket name. The solution I found to be nicer was to just clone the stream itself. The clone is just a clone of the handle, nothing fancy going on at the kernel level. Conceptually I found this very easy to wrap my head around (everything else supports clone()), and it solved the "split" problem at the same time. The cloning support is pretty specific per platform/lib combination: * native/win32 - uses some specific WSA apis to clone the SOCKET handle * native/unix - uses dup() to get another file descriptor * green/all - This is where things get interesting. When we support full clones of a handle, this implies that we're allowing simultaneous writes and reads to happen. It turns out that libuv doesn't support two simultaneous reads or writes of the same object. It does support *one* read and *one* write at the same time, however. Some extra infrastructure was added to just block concurrent writers/readers until the previous read/write operation was completed. I've added tests to the tcp/unix modules to make sure that this functionality is supported everywhere.
2014-01-31Add libc::consts::os::posix01::PTHREAD_STACK_MINBen Noordhuis-3/+23
Represents the minimum size of a thread's stack. As such, it's both platform and architecture-specific. I put it under posix01 even though it predates POSIX.1-2001 by some years. I believe it was first formalized in SUSv2. I doubt anyone cares, though.
2014-01-27Set SO_REUSEADDR by default in libnative.xales-0/+4
Fixes std::net test error when re-running too quickly.
2014-01-24Use `mmap` to map in task stacks and guard pageCorey Richardson-0/+1
Also implement caching of stacks.
2014-01-24auto merge of #11732 : luqmana/rust/native-getaddrinfo, r=alexcrichtonbors-4/+44
The last bit I needed to be able to use libnative :P
2014-01-22auto merge of #11682 : thestinger/rust/vector, r=brsonbors-1/+1
This is just an initial implementation and does not yet fully replace `~[T]`. A generic initialization syntax for containers is missing, and the slice functionality needs to be reworked to make auto-slicing unnecessary. Traits for supporting indexing properly are also required. This also needs to be fixed to make ring buffers as easy to use as vectors. The tests and documentation for `~[T]` can be ported over to this type when it is removed. I don't really expect DST to happen for vectors as having both `~[T]` and `Vec<T>` is overcomplicated and changing the slice representation to 3 words is not at all appealing. Unlike with traits, it's possible (and easy) to implement `RcSlice<T>` and `GcSlice<T>` without compiler help.
2014-01-22libc: switch `free` to the proper signatureDaniel Micay-1/+1
This does not attempt to fully propagate the mutability everywhere, but gives new code a hint to avoid the same issues.
2014-01-22Implement native timersAlex Crichton-0/+1
Native timers are a much hairier thing to deal with than green timers due to the interface that we would like to expose (both a blocking sleep() and a channel-based interface). I ended up implementing timers in three different ways for the various platforms that we supports. In all three of the implementations, there is a worker thread which does send()s on channels for timers. This worker thread is initialized once and then communicated to in a platform-specific manner, but there's always a shared channel available for sending messages to the worker thread. * Windows - I decided to use windows kernel timer objects via CreateWaitableTimer and SetWaitableTimer in order to provide sleeping capabilities. The worker thread blocks via WaitForMultipleObjects where one of the objects is an event that is used to wake up the helper thread (which then drains the incoming message channel for requests). * Linux/(Android?) - These have the ideal interface for implementing timers, timerfd_create. Each timer corresponds to a timerfd, and the helper thread uses epoll to wait for all active timers and then send() for the next one that wakes up. The tricky part in this implementation is updating a timerfd, but see the implementation for the fun details * OSX/FreeBSD - These obviously don't have the windows APIs, and sadly don't have the timerfd api available to them, so I have thrown together a solution which uses select() plus a timeout in order to ad-hoc-ly implement a timer solution for threads. The implementation is backed by a sorted array of timers which need to fire. As I said, this is an ad-hoc solution which is certainly not accurate timing-wise. I have done this implementation due to the lack of other primitives to provide an implementation, and I've done it the best that I could, but I'm sure that there's room for improvement. I'm pretty happy with how these implementations turned out. In theory we could drop the timerfd implementation and have linux use the select() + timeout implementation, but it's so inaccurate that I would much rather continue to use timerfd rather than my ad-hoc select() implementation. The only change that I would make to the API in general is to have a generic sleep() method on an IoFactory which doesn't require allocating a Timer object. For everything but windows it's super-cheap to request a blocking sleep for a set amount of time, and it's probably worth it to provide a sleep() which doesn't do something like allocate a file descriptor on linux.
2014-01-22libnative: Implement get_host_addresses.Luqman Aden-4/+44
2014-01-17handle zero-size allocations correctlyDaniel Micay-1/+1
The `malloc` family of functions may return a null pointer for a zero-size allocation, which should not be interpreted as an out-of-memory error. If the implementation does not return a null pointer, then handling this will result in memory savings for zero-size types. This also switches some code to `malloc_raw` in order to maintain a centralized point for handling out-of-memory in `rt::global_heap`. Closes #11634
2014-01-15libstd: Added more #[inline] annotations and replaced uses of `libc::abort` ↵Eduard Burtescu-2/+1
with the intrinsic.
2014-01-14Fix the representation of C void pointers in LLVM IRBjörn Steinbrink-1/+12
Currently, we have c_void defined to be represented as an empty struct, but LLVM expects C's void* to be represented as i8*. That means we currently generate code in which LLVM doesn't recognize malloc() and free() and can't apply certain optimization that would remove calls to those functions.
2014-01-11define arch for iOS/ARMkud1ing-0/+1
2013-12-31auto merge of #11186 : alexcrichton/rust/native-udp, r=brsonbors-1/+90
I personally do not have huge amounts of experience in this area, so there's likely a thing or two wrong around the edges. I tried to just copy what libuv is doing as closely as possible with a few tweaks in a few places, but all of the `std::io::net::udp` tests are now run in both native and green settings so the published functionality is all being tested.
2013-12-31Implement native UDP I/OAlex Crichton-1/+90
2013-12-30Convert some C functions to rust functionsAlex Crichton-8/+102
Right now on linux, an empty executable with LTO still depends on librt becaues of the clock_gettime function in rust_builtin.o, but this commit moves this dependency into a rust function which is subject to elimination via LTO. At the same time, this also drops libstd's dependency on librt on unices that are not OSX because the library is only used by extra::time (and now the dependency is listed in that module instead).
2013-12-27Implement native TCP I/OAlex Crichton-0/+308
2013-11-24std::libc: Simplify win32/win64 type definitionsklutzy-164/+30
2013-11-24std::libc: Remove TCHAR typesklutzy-20/+17
2013-11-19Implement more native file I/OAlex Crichton-7/+188
This implements a fair amount of the unimpl() functionality in io::native relating to filesystem operations. I've also modified all io::fs tests to run in both a native and uv environment (so everything is actually tested). There are a two bits of remaining functionality which I was unable to get working: * change_file_times on windows * lstat on windows I think that change_file_times may just need a better interface, but lstat has a large implementation in libuv which I didn't want to tackle trying to copy.
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-6/+0
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-11-10Register new snapshotsAlex Crichton-110/+1
2013-11-05fix alignment of pthread_attr_tDaniel Micay-8/+8
Closes #10300
2013-11-05Move implementation for threads to RustDirkjan Bussink-7/+56
This binds to the appropriate pthreads_* and Windows specific functions and calls them from Rust. This allows for removal of the C++ support code for threads. Fixes #10162
2013-11-03Fill out the remaining functionality in io::fileAlex Crichton-1/+6
This adds bindings to the remaining functions provided by libuv, all of which are useful operations on files which need to get exposed somehow. Some highlights: * Dropped `FileReader` and `FileWriter` and `FileStream` for one `File` type * Moved all file-related methods to be static methods under `File` * All directory related methods are still top-level functions * Created `io::FilePermission` types (backed by u32) that are what you'd expect * Created `io::FileType` and refactored `FileStat` to use FileType and FilePermission * Removed the expanding matrix of `FileMode` operations. The mode of reading a file will not have the O_CREAT flag, but a write mode will always have the O_CREAT flag. Closes #10130 Closes #10131 Closes #10121
2013-10-20Fix unicode errors on Windows in path_is_dir, path_exists, getcwd and ↵LEE Wondong-4/+10
rust_localtime. This make these functions use wchar_t version of APIs, instead of char version.
2013-10-14Removing ccdeclSteve Klabnik-25/+25
as per https://github.com/mozilla/rust/pull/9606#discussion_r6930872
2013-10-14Remove unused abi attributes.Steve Klabnik-51/+25
They've been replaced by putting the name on the extern block. #[abi = "foo"] goes to extern "foo" { } Closes #9483.
2013-10-14std::libc: rustdoc indicates reexports nowScott Lawrence-3/+2
2013-10-08rm useless fast_ffi attributesDaniel Micay-14/+0
this is no longer used by the compiler
2013-09-25errfunc ptr is nullable, so use Option as part of interface to glob (#7752).Felix S. Klock II-1/+2
2013-09-25#7752: use fcnptr for glob errfunc.Felix S. Klock II-2/+1
2013-09-18fix compilation errors of mips targetJyun-Yan You-26/+139
2013-08-26std: Add Win64 supportklutzy-0/+106
Some extern blobs are duplicated without "stdcall" abi, since Win64 does not use any calling convention. (Giving any abi to them causes llvm producing wrong bytecode.)
2013-08-26std: Add Win64 typesklutzy-0/+166
2013-08-21auto merge of #8602 : sanxiyn/rust/sysconf, r=graydonbors-224/+214
Linux and Android share the kernel, but not the C library, so sysconf constants are different. For example, _SC_PAGESIZE is 30 on Linux, but 39 on Android. This patch * splits sysconf constants to sysconf module * merges non-MIPS and MIPS sysconf constants (they are same) * adds Android sysconf constants This patch also lets mmap tests to pass on Android.
2013-08-19Add externfn macro and correctly label fixed_stack_segmentsNiko Matsakis-0/+2
2013-08-14Add sysconf names for AndroidSeo Sanghyeon-224/+214
2013-08-04std and rustc: explicitly pass c strings to c functionsErick Tryzelaar-2/+2
When strings lose their trailing null, this pattern will become dangerous: let foo = "bar"; let foo_ptr: *u8 = &foo[0]; Instead we should use c_strs to handle this correctly.
2013-08-02librustc: Disallow "unsafe" for external functionsPatrick Walton-452/+371
2013-08-01Add a boatload of Linux x86/x86-64/arm errnosCorey Richardson-0/+107
2013-07-20librustc: Remove `pub extern` and `priv extern` from the language.Patrick Walton-372/+446
Place `pub` or `priv` on individual items instead.
2013-07-10Document std::libc::c_void.Kevin Mehall-0/+7
2013-07-09os: introduce cross-platform MemoryMap bindingsFedor Indutny-4/+5
Basically, one may just do: MemoryMap::new(16, ~[ MapExecutable, MapReadable, MapWritable ]) And executable+readable+writable chunk of at least 16 bytes size will be allocated and freed with the result of `MemoryMap::new`.
2013-07-08libc: add errno valuesFedor Indutny-0/+281
2013-07-08libc: VirtualAlloc and FileMapping bindingsFedor Indutny-4/+132