set up errno passing from syscalls
This commit is contained in:
Родитель
4b1bb98dde
Коммит
9388ce0ff7
4
emcc
4
emcc
|
@ -1000,6 +1000,10 @@ try:
|
|||
if js_opts:
|
||||
shared.Settings.RUNNING_JS_OPTS = 1
|
||||
|
||||
shared.Settings.EXPORTED_FUNCTIONS += ['___errno_location'] # so FS can report errno back to C
|
||||
if not shared.Settings.NO_EXIT_RUNTIME:
|
||||
shared.Settings.EXPORTED_FUNCTIONS += ['_fflush'] # to flush the streams on FS quit
|
||||
|
||||
shared.Settings.EMSCRIPTEN_VERSION = shared.EMSCRIPTEN_VERSION
|
||||
shared.Settings.OPT_LEVEL = opt_level
|
||||
shared.Settings.DEBUG_LEVEL = debug_level
|
||||
|
|
|
@ -5780,19 +5780,20 @@ LibraryManager.library = {
|
|||
{{{ cDefine('EOWNERDEAD') }}}: 'Previous owner died',
|
||||
{{{ cDefine('ESTRPIPE') }}}: 'Streams pipe error',
|
||||
},
|
||||
__errno_state: 0,
|
||||
__setErrNo__deps: ['__errno_state'],
|
||||
__setErrNo__postset: '___errno_state = Runtime.staticAlloc(4); {{{ makeSetValue("___errno_state", 0, 0, "i32") }}};',
|
||||
__setErrNo__deps: ['__errno_location'],
|
||||
__setErrNo: function(value) {
|
||||
// For convenient setting and returning of errno.
|
||||
{{{ makeSetValue('___errno_state', '0', 'value', 'i32') }}};
|
||||
if (___setErrNo.loc === undefined) {
|
||||
if (Module["___errno_location"]) {
|
||||
___setErrNo.loc = Module["___errno_location"]();
|
||||
} else {
|
||||
___setErrNo.loc = 0; // no __errno_location, so errno is inaccessible from C code; no need to set it
|
||||
}
|
||||
}
|
||||
if (___setErrNo.loc) {
|
||||
{{{ makeSetValue('___setErrNo.loc', '0', 'value', 'i32') }}};
|
||||
}
|
||||
return value;
|
||||
},
|
||||
__errno_location__deps: ['__setErrNo'],
|
||||
__errno_location: function() {
|
||||
return ___errno_state;
|
||||
},
|
||||
__errno: '__errno_location',
|
||||
|
||||
// ==========================================================================
|
||||
// sys/resource.h
|
||||
|
|
|
@ -379,6 +379,10 @@ mergeInto(LibraryManager.library, {
|
|||
#if SYSCALL_DEBUG
|
||||
Module.printErr('syscall! ' + [which, SYSCALLS.getFromCode(which)]);
|
||||
#endif
|
||||
function handleSyscallFSError(e) { // syscalls return a negative number which is errno; libc calls then return just -1
|
||||
if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
|
||||
return -e.errno;
|
||||
}
|
||||
switch (which) {
|
||||
case 4: { // write
|
||||
var fd = get(), buf = get(), count = get();
|
||||
|
@ -390,8 +394,7 @@ mergeInto(LibraryManager.library, {
|
|||
try {
|
||||
return FS.write(stream, {{{ makeGetSlabs('ptr', 'i8', true) }}}, buf, count);
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
}
|
||||
case 5: { // open
|
||||
|
@ -401,8 +404,7 @@ mergeInto(LibraryManager.library, {
|
|||
var stream = FS.open(pathname, flags, mode);
|
||||
return stream.fd;
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
}
|
||||
case 6: { // close
|
||||
|
@ -416,8 +418,7 @@ mergeInto(LibraryManager.library, {
|
|||
FS.close(stream);
|
||||
return 0;
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
}
|
||||
case 38: { // rename
|
||||
|
@ -428,8 +429,7 @@ mergeInto(LibraryManager.library, {
|
|||
FS.rename(old_path, new_path);
|
||||
return 0;
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
}
|
||||
case 39: { // mkdir
|
||||
|
@ -443,8 +443,7 @@ mergeInto(LibraryManager.library, {
|
|||
FS.mkdir(path, mode, 0);
|
||||
return 0;
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
}
|
||||
case 54: { // ioctl
|
||||
|
@ -476,8 +475,7 @@ mergeInto(LibraryManager.library, {
|
|||
try {
|
||||
var curr = FS.read(stream, {{{ makeGetSlabs('ptr', 'i8', true) }}}, ptr, len);
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
if (curr < 0) return -1;
|
||||
ret += curr;
|
||||
|
@ -499,8 +497,7 @@ mergeInto(LibraryManager.library, {
|
|||
try {
|
||||
var curr = FS.write(stream, {{{ makeGetSlabs('ptr', 'i8', true) }}}, ptr, len);
|
||||
} catch (e) {
|
||||
FS.handleFSError(e);
|
||||
return -1;
|
||||
return handleSyscallFSError(e);
|
||||
}
|
||||
if (curr < 0) return -1;
|
||||
ret += curr;
|
||||
|
|
|
@ -284,7 +284,7 @@ var NO_BROWSER = 0; // If set, disables building in browser support using the Br
|
|||
var NODE_STDOUT_FLUSH_WORKAROUND = 1; // Whether or not to work around node issues with not flushing stdout. This
|
||||
// can cause unnecessary whitespace to be printed.
|
||||
|
||||
var EXPORTED_FUNCTIONS = ['_main', '_malloc', '_fflush'];
|
||||
var EXPORTED_FUNCTIONS = ['_main', '_malloc'];
|
||||
// Functions that are explicitly exported. These functions are kept alive
|
||||
// through LLVM dead code elimination, and also made accessible outside of
|
||||
// the generated code even after running closure compiler (on "Module").
|
||||
|
@ -295,8 +295,6 @@ var EXPORTED_FUNCTIONS = ['_main', '_malloc', '_fflush'];
|
|||
// without keeping it there, you are in effect removing it).
|
||||
//
|
||||
// malloc should always be here, as it is used for internal allocations.
|
||||
// fflush is optional; it is needed to be able to flush stdout/stderr
|
||||
// during shutdown
|
||||
|
||||
var EXPORT_ALL = 0; // If true, we export all the symbols. Note that this does *not* affect LLVM, so it can
|
||||
// still eliminate functions as dead. This just exports them on the Module object.
|
||||
|
|
Загрузка…
Ссылка в новой задаче