mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Fix a bunch of Windows bugs reported on Discord
This change addresses everything from stack smashing to %SYSTEMROOT% breaking socket(). Issues relating to compile.com not reporting text printed to stderr has been resolved for Windows builds.
This commit is contained in:
parent
b0e3258709
commit
5018171fa5
10 changed files with 104 additions and 46 deletions
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/elf/def.h"
|
||||
|
@ -139,16 +140,27 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
|
|||
size_t pathlen;
|
||||
struct stat st;
|
||||
const char *name;
|
||||
CHECK_NE(-1, (fd = open(path, O_RDONLY)));
|
||||
CHECK_NE(-1, fstat(fd, &st));
|
||||
if (stat(path, &st)) {
|
||||
perror(path);
|
||||
exit(1);
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if ((fd = open(path, O_RDONLY | O_DIRECTORY)) == -1) {
|
||||
perror(path);
|
||||
exit(1);
|
||||
}
|
||||
map = "";
|
||||
st.st_size = 0;
|
||||
} else if (st.st_size) {
|
||||
CHECK_NE(MAP_FAILED,
|
||||
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
|
||||
if ((fd = open(path, O_RDONLY)) == -1 ||
|
||||
(map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) ==
|
||||
MAP_FAILED) {
|
||||
perror(path);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
map = NULL;
|
||||
fd = -1;
|
||||
map = 0;
|
||||
}
|
||||
if (name_) {
|
||||
name = name_;
|
||||
|
@ -166,7 +178,9 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
|
|||
}
|
||||
elfwriter_zip(elf, name, name, strlen(name), map, st.st_size, st.st_mode,
|
||||
timestamp, timestamp, timestamp, nocompress_);
|
||||
if (st.st_size) CHECK_NE(-1, munmap(map, st.st_size));
|
||||
if (st.st_size) {
|
||||
unassert(!munmap(map, st.st_size));
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue