1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1996-2021. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20-module(erlang).
21
22-export([apply/2,apply/3,spawn/4,spawn_link/4,
23	 spawn_monitor/1,spawn_monitor/2,
24	 spawn_monitor/3,spawn_monitor/4,
25	 spawn_opt/2,spawn_opt/3,spawn_opt/4,spawn_opt/5,
26         spawn_request/1, spawn_request/2,
27         spawn_request/3, spawn_request/4, spawn_request/5,
28         spawn_request_abandon/1, disconnect_node/1]).
29-export([spawn/1, spawn_link/1, spawn/2, spawn_link/2]).
30-export([yield/0]).
31-export([fun_info/1]).
32-export([send_nosuspend/2, send_nosuspend/3]).
33-export([localtime_to_universaltime/1]).
34-export([suspend_process/1]).
35-export([min/2, max/2]).
36-export([dmonitor_node/3]).
37-export([delay_trap/2]).
38-export([set_cookie/1, set_cookie/2, get_cookie/0, get_cookie/1]).
39-export([nodes/0]).
40
41-export([integer_to_list/2]).
42-export([integer_to_binary/2]).
43-export([set_cpu_topology/1, format_cpu_topology/1]).
44-export([memory/0, memory/1]).
45-export([alloc_info/1, alloc_sizes/1]).
46
47-export([gather_gc_info_result/1]).
48
49-export([dist_ctrl_input_handler/2,
50         dist_ctrl_put_data/2,
51         dist_ctrl_get_data/1,
52         dist_ctrl_get_data_notification/1,
53         dist_ctrl_get_opt/2,
54         dist_ctrl_set_opt/3,
55         dist_get_stat/1]).
56
57-deprecated([{now,0,
58              "see the \"Time and Time Correction in Erlang\" "
59              "chapter of the ERTS User's Guide for more information"}]).
60-deprecated([{phash,2, "use erlang:phash2/2 instead"}]).
61-removed([{hash,2,"use erlang:phash2/2 instead"}]).
62-removed([{get_stacktrace,0,
63           "use the new try/catch syntax for retrieving the "
64           "stack backtrace"}]).
65
66%% Get rid of autoimports of spawn to avoid clashes with ourselves.
67-compile({no_auto_import,[spawn_link/1]}).
68-compile({no_auto_import,[spawn_link/4]}).
69-compile({no_auto_import,[spawn_opt/2]}).
70-compile({no_auto_import,[spawn_opt/4]}).
71-compile({no_auto_import,[spawn_opt/5]}).
72
73%% We must inline these functions so that the stacktrace points to
74%% the correct function.
75-compile({inline, [badarg_with_info/1,error_with_info/2,
76                   error_with_inherited_info/3,badarg_with_cause/2]}).
77
78-export_type([timestamp/0]).
79-export_type([time_unit/0]).
80-export_type([deprecated_time_unit/0]).
81-export_type([spawn_opt_option/0]).
82-export_type([priority_level/0]).
83-export_type([max_heap_size/0]).
84-export_type([message_queue_data/0]).
85-export_type([monitor_option/0]).
86-export_type([stacktrace/0]).
87
88-type stacktrace_extrainfo() ::
89        {line, pos_integer()} |
90        {file, unicode:chardata()} |
91        {error_info, #{ module => module(), function => atom(), cause => term() }} |
92        {atom(), term()}.
93-type stacktrace() :: [{module(), atom(), arity() | [term()],
94                        [stacktrace_extrainfo()]} |
95                       {function(), arity() | [term()], [stacktrace_extrainfo()]}].
96
97-type ext_binary() :: binary().
98-type ext_iovec() :: iovec().
99-type timestamp() :: {MegaSecs :: non_neg_integer(),
100                      Secs :: non_neg_integer(),
101                      MicroSecs :: non_neg_integer()}.
102
103-type time_unit() ::
104	pos_integer()
105      | 'second'
106      | 'millisecond'
107      | 'microsecond'
108      | 'nanosecond'
109      | 'native'
110      | 'perf_counter'
111      | deprecated_time_unit().
112
113%% Deprecated symbolic units...
114-type deprecated_time_unit() ::
115      'seconds'
116      | 'milli_seconds'
117      | 'micro_seconds'
118      | 'nano_seconds'.
119
120-opaque prepared_code() :: reference().
121-export_type([prepared_code/0]).
122
123-opaque nif_resource() :: reference().
124-export_type([nif_resource/0]).
125
126-opaque dist_handle() :: atom().
127-export_type([dist_handle/0]).
128
129-type iovec() :: [binary()].
130-export_type([iovec/0]).
131
132%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133%% Native code BIF stubs and their types
134%% (BIF's actually implemented in this module goes last in the file)
135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138%% Exports for all native code stubs
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140
141-export([adler32/1, adler32/2, adler32_combine/3, append_element/2]).
142-export([atom_to_binary/1, atom_to_binary/2]).
143-export([atom_to_list/1, binary_part/2, binary_part/3]).
144-export([binary_to_atom/1, binary_to_atom/2]).
145-export([binary_to_existing_atom/1, binary_to_existing_atom/2]).
146-export([binary_to_float/1]).
147-export([binary_to_integer/1,binary_to_integer/2]).
148-export([binary_to_list/1]).
149-export([binary_to_list/3, binary_to_term/1, binary_to_term/2]).
150-export([bit_size/1, bitstring_to_list/1]).
151-export([bump_reductions/1, byte_size/1, call_on_load_function/1]).
152-export([cancel_timer/1, cancel_timer/2, ceil/1,
153	 check_old_code/1, check_process_code/2,
154	 check_process_code/3, crc32/1]).
155-export([crc32/2, crc32_combine/3, date/0, decode_packet/3]).
156-export([delete_element/2]).
157-export([delete_module/1, demonitor/1, demonitor/2, display/1]).
158-export([display_nl/0, display_string/1, erase/0, erase/1]).
159-export([error/1, error/2, error/3, exit/1, exit/2, exit_signal/2, external_size/1]).
160-export([external_size/2, finish_after_on_load/2, finish_loading/1, float/1]).
161-export([float_to_binary/1, float_to_binary/2,
162	 float_to_list/1, float_to_list/2, floor/1]).
163-export([fun_info/2, fun_info_mfa/1, fun_to_list/1, function_exported/3]).
164-export([garbage_collect/0, garbage_collect/1, garbage_collect/2]).
165-export([garbage_collect_message_area/0, get/0, get/1, get_keys/0, get_keys/1]).
166-export([get_module_info/1, group_leader/0]).
167-export([group_leader/2]).
168-export([halt/0, halt/1, halt/2,
169	 has_prepared_code_on_load/1, hibernate/3]).
170-export([insert_element/3]).
171-export([integer_to_binary/1, integer_to_list/1]).
172-export([iolist_size/1, iolist_to_binary/1, iolist_to_iovec/1]).
173-export([is_alive/0, is_builtin/3, is_map_key/2, is_process_alive/1, length/1, link/1]).
174-export([list_to_atom/1, list_to_binary/1]).
175-export([list_to_bitstring/1, list_to_existing_atom/1, list_to_float/1]).
176-export([list_to_integer/1, list_to_integer/2]).
177-export([list_to_pid/1, list_to_port/1, list_to_ref/1, list_to_tuple/1, loaded/0]).
178-export([localtime/0, make_ref/0]).
179-export([map_size/1, map_get/2, match_spec_test/3, md5/1, md5_final/1]).
180-export([md5_init/0, md5_update/2, module_loaded/1, monitor/2, monitor/3]).
181-export([monitor_node/2, monitor_node/3, nif_error/1, nif_error/2]).
182-export([node/0, node/1, now/0, phash/2, phash2/1, phash2/2]).
183-export([pid_to_list/1, port_close/1, port_command/2, port_command/3]).
184-export([port_connect/2, port_control/3, port_get_data/1]).
185-export([port_set_data/2, port_to_list/1, ports/0]).
186-export([posixtime_to_universaltime/1, pre_loaded/0, prepare_loading/2]).
187-export([monotonic_time/0, monotonic_time/1]).
188-export([system_time/0, system_time/1]).
189-export([convert_time_unit/3]).
190-export([unique_integer/0, unique_integer/1]).
191-export([time_offset/0, time_offset/1, timestamp/0]).
192-export([process_display/2]).
193-export([process_flag/3, process_info/1, processes/0, purge_module/1]).
194-export([put/2, raise/3, read_timer/1, read_timer/2, ref_to_list/1, register/2]).
195-export([send_after/3, send_after/4, start_timer/3, start_timer/4]).
196-export([registered/0, resume_process/1, round/1, self/0]).
197-export([seq_trace/2, seq_trace_print/1, seq_trace_print/2, setnode/2]).
198-export([setnode/3, size/1, spawn/3, spawn_link/3, split_binary/2]).
199-export([suspend_process/2, system_monitor/0]).
200-export([system_monitor/1, system_monitor/2, system_profile/0]).
201-export([system_profile/2, throw/1, time/0, trace/3, trace_delivered/1]).
202-export([trace_info/2, trunc/1, tuple_size/1, universaltime/0]).
203-export([universaltime_to_posixtime/1, unlink/1, unregister/1, whereis/1]).
204
205-export([abs/1, append/2, element/2, get_module_info/2, hd/1,
206         is_atom/1, is_binary/1, is_bitstring/1, is_boolean/1,
207         is_float/1, is_function/1, is_function/2, is_integer/1,
208         is_list/1, is_map/1, is_number/1, is_pid/1, is_port/1, is_record/2,
209         is_record/3, is_reference/1, is_tuple/1, load_module/2,
210         load_nif/2, localtime_to_universaltime/2, make_fun/3,
211         make_tuple/2, make_tuple/3, nodes/1, open_port/2,
212         port_call/2, port_call/3, port_info/1, port_info/2, process_flag/2,
213         process_info/2, send/2, send/3, seq_trace_info/1,
214         setelement/3,
215	 statistics/1, subtract/2, system_flag/2,
216         term_to_binary/1, term_to_binary/2,
217         term_to_iovec/1, term_to_iovec/2,
218         tl/1, trace_pattern/2,
219         trace_pattern/3, tuple_to_list/1, system_info/1,
220         universaltime_to_localtime/1]).
221-export([alias/0, alias/1, unalias/1]).
222-export([dt_get_tag/0, dt_get_tag_data/0, dt_prepend_vm_tag_data/1, dt_append_vm_tag_data/1,
223	 dt_put_tag/1, dt_restore_tag/1, dt_spread_tag/1]).
224
225%% Operators
226
227-export(['=='/2, '=:='/2,
228         '/='/2, '=/='/2,
229         '=<'/2, '>='/2,
230         '<'/2, '>'/2]).
231
232-export(['-'/1, '+'/1,
233         '-'/2, '+'/2,
234         '/'/2, '*'/2,
235         'div'/2, 'rem'/2,
236         'bsl'/2, 'bsr'/2,
237         'bor'/2, 'band'/2,
238         'bxor'/2, 'bnot'/1]).
239
240-export(['and'/2, 'or'/2,
241         'xor'/2, 'not'/1]).
242
243-export(['--'/2, '++'/2]).
244
245-export(['!'/2]).
246
247%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248%%% Simple native code BIFs
249%%% These are here for the types/specs, the real implementation is in the C code.
250%%% The first chunk is originally auto-generated from
251%%% $ERL_TOP/lib/hipe/cerl/erl_bif_types.erl as released in R15B.
252%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253
254
255%% types
256
257-type fun_info_item() ::
258      arity |
259      env |
260      index |
261      name |
262      module |
263      new_index |
264      new_uniq |
265      pid |
266      type |
267      uniq.
268
269-type seq_trace_info_returns() ::
270      { 'send' | 'receive' | 'print' | 'timestamp' | 'monotonic_timestamp' | 'strict_monotonic_timestamp', boolean() } |
271      { 'label', term() } |
272      { 'serial', { non_neg_integer(), non_neg_integer() } } |
273      [].
274
275-type system_profile_option() ::
276      'exclusive' |
277      'runnable_ports' |
278      'runnable_procs' |
279      'scheduler' |
280      'timestamp' |
281      'monotonic_timestamp' |
282      'strict_monotonic_timestamp'.
283
284-type system_monitor_option() ::
285      'busy_port' |
286      'busy_dist_port' |
287      {'long_gc', non_neg_integer()} |
288      {'long_schedule', non_neg_integer()} |
289      {'large_heap', non_neg_integer()}.
290
291-type raise_stacktrace() ::
292      [{module(), atom(), arity() | [term()]} |
293       {function(), arity() | [term()]}].
294
295-type bitstring_list() ::
296      maybe_improper_list(byte() | bitstring() | bitstring_list(), bitstring() | []).
297
298-type trace_flag() ::
299      all |
300      send |
301      'receive' |
302      procs |
303      ports |
304      call |
305      arity |
306      return_to |
307      silent |
308      running |
309      exiting |
310      running_procs |
311      running_ports |
312      garbage_collection |
313      timestamp |
314      cpu_timestamp |
315      monotonic_timestamp |
316      strict_monotonic_timestamp |
317      set_on_spawn |
318      set_on_first_spawn |
319      set_on_link |
320      set_on_first_link |
321      {tracer, pid() | port()} |
322      {tracer, module(), term()}.
323
324-type trace_info_item_result() ::
325       {traced, global | local | false | undefined} |
326       {match_spec, trace_match_spec() | false | undefined} |
327       {meta, pid() | port() | false | undefined | []} |
328       {meta, module(), term() } |
329       {meta_match_spec, trace_match_spec() | false | undefined} |
330       {call_count, non_neg_integer() | boolean() | undefined} |
331       {call_time, [{pid(), non_neg_integer(),
332		     non_neg_integer(), non_neg_integer()}] | boolean() | undefined}.
333
334-type trace_info_flag() ::
335      send |
336      'receive' |
337      set_on_spawn |
338      call |
339      return_to |
340      procs |
341      set_on_first_spawn |
342      set_on_link |
343      running |
344      garbage_collection |
345      timestamp |
346      monotonic_timestamp |
347      strict_monotonic_timestamp |
348      arity.
349
350-type trace_info_return() ::
351      undefined |
352      {flags, [trace_info_flag()]} |
353      {tracer, pid() | port() | []} |
354      {tracer, module(), term()} |
355      trace_info_item_result() |
356      {all, [ trace_info_item_result() ] | false | undefined}.
357
358%% Specs and stubs
359%% adler32/1
360-spec erlang:adler32(Data) -> non_neg_integer() when
361      Data :: iodata().
362adler32(_Data) ->
363    erlang:nif_error(undefined).
364
365%% adler32/2
366-spec erlang:adler32(OldAdler, Data) -> non_neg_integer() when
367      OldAdler :: non_neg_integer(),
368      Data :: iodata().
369adler32(_OldAdler, _Data) ->
370    erlang:nif_error(undefined).
371
372%% adler32_combine/3
373-spec erlang:adler32_combine(FirstAdler, SecondAdler, SecondSize) -> non_neg_integer() when
374      FirstAdler :: non_neg_integer(),
375      SecondAdler :: non_neg_integer(),
376      SecondSize :: non_neg_integer().
377adler32_combine(_FirstAdler, _SecondAdler, _SecondSize) ->
378    erlang:nif_error(undefined).
379
380%% append_element/2
381-spec erlang:append_element(Tuple1, Term) -> Tuple2 when
382      Tuple1 :: tuple(),
383      Tuple2 :: tuple(),
384      Term :: term().
385append_element(_Tuple1, _Term) ->
386    erlang:nif_error(undefined).
387
388%% atom_to_binary/1
389-spec atom_to_binary(Atom) -> binary() when
390      Atom :: atom().
391atom_to_binary(Atom) ->
392    try
393        erlang:atom_to_binary(Atom, utf8)
394    catch
395        error:Error ->
396            error_with_info(Error, [Atom])
397    end.
398
399%% atom_to_binary/2
400-spec atom_to_binary(Atom, Encoding) -> binary() when
401      Atom :: atom(),
402      Encoding :: latin1 | unicode | utf8.
403atom_to_binary(_Atom, _Encoding) ->
404    erlang:nif_error(undefined).
405
406%% atom_to_list/1
407-spec atom_to_list(Atom) -> string() when
408      Atom :: atom().
409atom_to_list(_Atom) ->
410    erlang:nif_error(undefined).
411
412%% binary_part/2
413%% Shadowed by erl_bif_types: erlang:binary_part/2
414-spec binary_part(Subject, PosLen) -> binary() when
415      Subject :: binary(),
416      PosLen :: {Start :: non_neg_integer(), Length :: integer()}.
417binary_part(_Subject, _PosLen) ->
418    erlang:nif_error(undefined).
419
420%% binary_part/3
421%% Shadowed by erl_bif_types: erlang:binary_part/3
422-spec binary_part(Subject, Start, Length) -> binary() when
423      Subject :: binary(),
424      Start :: non_neg_integer(),
425      Length :: integer().
426binary_part(_Subject, _Start, _Length) ->
427    erlang:nif_error(undefined).
428
429%% binary_to_atom/1
430-spec binary_to_atom(Binary) -> atom() when
431      Binary :: binary().
432binary_to_atom(Binary) ->
433    try
434        erlang:binary_to_atom(Binary, utf8)
435    catch
436	error:Error -> error_with_info(Error, [Binary])
437    end.
438
439%% binary_to_atom/2
440-spec binary_to_atom(Binary, Encoding) -> atom() when
441      Binary :: binary(),
442      Encoding :: latin1 | unicode | utf8.
443binary_to_atom(_Binary, _Encoding) ->
444    erlang:nif_error(undefined).
445
446%% binary_to_existing_atom/1
447-spec binary_to_existing_atom(Binary) -> atom() when
448      Binary :: binary().
449binary_to_existing_atom(Binary) ->
450    try
451        erlang:binary_to_existing_atom(Binary, utf8)
452    catch
453	error:Error -> error_with_info(Error, [Binary])
454    end.
455
456%% binary_to_existing_atom/2
457-spec binary_to_existing_atom(Binary, Encoding) -> atom() when
458      Binary :: binary(),
459      Encoding :: latin1 | unicode | utf8.
460binary_to_existing_atom(_Binary, _Encoding) ->
461    erlang:nif_error(undefined).
462
463%% binary_to_float/1
464-spec binary_to_float(Binary) -> float() when
465      Binary :: binary().
466binary_to_float(_Binary) ->
467    erlang:nif_error(undefined).
468
469%% binary_to_integer/1
470-spec binary_to_integer(Binary) -> integer() when
471      Binary :: binary().
472binary_to_integer(_Binary) ->
473    erlang:nif_error(undefined).
474
475%% binary_to_integer/2
476-spec binary_to_integer(Binary,Base) -> integer() when
477      Binary :: binary(),
478      Base :: 2..36.
479binary_to_integer(_Binary,_Base) ->
480    erlang:nif_error(undefined).
481
482%% binary_to_list/1
483-spec binary_to_list(Binary) -> [byte()] when
484      Binary :: binary().
485binary_to_list(_Binary) ->
486    erlang:nif_error(undefined).
487
488%% binary_to_list/3
489-spec binary_to_list(Binary, Start, Stop) -> [byte()] when
490      Binary :: binary(),
491      Start :: pos_integer(),
492      Stop :: pos_integer().
493binary_to_list(_Binary, _Start, _Stop) ->
494    erlang:nif_error(undefined).
495
496%% binary_to_term/1
497-spec binary_to_term(Binary) -> term() when
498      Binary :: ext_binary().
499binary_to_term(_Binary) ->
500    erlang:nif_error(undefined).
501
502%% binary_to_term/2
503-spec binary_to_term(Binary, Opts) -> term() | {term(), Used} when
504      Binary :: ext_binary(),
505      Opt :: safe | used,
506      Opts :: [Opt],
507      Used :: pos_integer().
508binary_to_term(_Binary, _Opts) ->
509    erlang:nif_error(undefined).
510
511%% bit_size/1
512%% Shadowed by erl_bif_types: erlang:bit_size/1
513-spec bit_size(Bitstring) -> non_neg_integer() when
514      Bitstring :: bitstring().
515bit_size(_Bitstring) ->
516    erlang:nif_error(undefined).
517
518%% bitstring_to_list/1
519-spec bitstring_to_list(Bitstring) -> [byte() | bitstring()] when
520      Bitstring :: bitstring().
521bitstring_to_list(_Bitstring) ->
522    erlang:nif_error(undefined).
523
524%% bump_reductions/1
525-spec erlang:bump_reductions(Reductions) -> true when
526      Reductions :: pos_integer().
527bump_reductions(_Reductions) ->
528    erlang:nif_error(undefined).
529
530%% byte_size/1
531%% Shadowed by erl_bif_types: erlang:byte_size/1
532-spec byte_size(Bitstring) -> non_neg_integer() when
533      Bitstring :: bitstring().
534byte_size(_Bitstring) ->
535    erlang:nif_error(undefined).
536
537%% call_on_load_function/1
538-spec erlang:call_on_load_function(P1) -> term() when
539      P1 :: atom().
540call_on_load_function(_P1) ->
541    erlang:nif_error(undefined).
542
543%% cancel_timer/1
544-spec erlang:cancel_timer(TimerRef) -> Result when
545      TimerRef :: reference(),
546      Time :: non_neg_integer(),
547      Result :: Time | false.
548
549cancel_timer(_TimerRef) ->
550    erlang:nif_error(undefined).
551
552%% cancel_timer/2
553-spec erlang:cancel_timer(TimerRef, Options) -> Result | ok when
554      TimerRef :: reference(),
555      Async :: boolean(),
556      Info :: boolean(),
557      Option :: {async, Async} | {info, Info},
558      Options :: [Option],
559      Time :: non_neg_integer(),
560      Result :: Time | false.
561
562cancel_timer(_TimerRef, _Options) ->
563    erlang:nif_error(undefined).
564
565%% ceil/1
566%% Shadowed by erl_bif_types: erlang:ceil/1
567-spec ceil(Number) -> integer() when
568      Number :: number().
569ceil(_) ->
570    erlang:nif_error(undef).
571
572%% check_old_code/1
573-spec check_old_code(Module) -> boolean() when
574      Module :: module().
575check_old_code(_Module) ->
576    erlang:nif_error(undefined).
577
578%% check_process_code/2
579-spec check_process_code(Pid, Module) -> CheckResult when
580      Pid :: pid(),
581      Module :: module(),
582      CheckResult :: boolean().
583check_process_code(Pid, Module) ->
584    try
585	erts_internal:check_process_code(Pid, Module, [{allow_gc, true}])
586    catch
587	error:Error -> error_with_info(Error, [Pid, Module])
588    end.
589
590%% check_process_code/3
591-spec check_process_code(Pid, Module, OptionList) -> CheckResult | async when
592      Pid :: pid(),
593      Module :: module(),
594      RequestId :: term(),
595      Option :: {async, RequestId} | {allow_gc, boolean()},
596      OptionList :: [Option],
597      CheckResult :: boolean() | aborted.
598check_process_code(Pid, Module, OptionList)  ->
599    try
600	erts_internal:check_process_code(Pid, Module, OptionList)
601    catch
602        error:bad_option ->
603            badarg_with_cause([Pid, Module, OptionList], bad_option);
604        error:_ ->
605            badarg_with_info([Pid, Module, OptionList])
606    end.
607
608%% crc32/1
609-spec erlang:crc32(Data) -> non_neg_integer() when
610      Data :: iodata().
611crc32(_Data) ->
612    erlang:nif_error(undefined).
613
614%% crc32/2
615-spec erlang:crc32(OldCrc, Data) -> non_neg_integer() when
616      OldCrc :: non_neg_integer(),
617      Data :: iodata().
618crc32(_OldCrc, _Data) ->
619    erlang:nif_error(undefined).
620
621%% crc32_combine/3
622-spec erlang:crc32_combine(FirstCrc, SecondCrc, SecondSize) -> non_neg_integer() when
623      FirstCrc :: non_neg_integer(),
624      SecondCrc :: non_neg_integer(),
625      SecondSize :: non_neg_integer().
626crc32_combine(_FirstCrc, _SecondCrc, _SecondSize) ->
627    erlang:nif_error(undefined).
628
629%% date/0
630-spec date() -> Date when
631      Date :: calendar:date().
632date() ->
633    erlang:nif_error(undefined).
634
635%% decode_packet/3
636-spec erlang:decode_packet(Type, Bin, Options) ->
637                                  {ok, Packet, Rest} |
638                                  {more, Length} |
639                                  {error, Reason} when
640      Type :: 'raw' | 0 | 1 | 2 | 4 | 'asn1' | 'cdr' | 'sunrm' | 'fcgi'
641            | 'tpkt' | 'line' | 'http' | 'http_bin' | 'httph' | 'httph_bin',
642      Bin :: binary(),
643      Options :: [Opt],
644      Opt :: {packet_size, non_neg_integer()}
645           | {line_length, non_neg_integer()},
646      Packet :: binary() | HttpPacket,
647      Rest :: binary(),
648      Length :: non_neg_integer() | undefined,
649      Reason :: term(),
650      HttpPacket :: HttpRequest
651                  | HttpResponse
652                  | HttpHeader
653                  | 'http_eoh'
654                  | HttpError,
655      HttpRequest :: {'http_request', HttpMethod, HttpUri, HttpVersion},
656      HttpResponse :: {'http_response', HttpVersion, integer(), HttpString},
657      HttpHeader :: {'http_header',
658                     integer(),
659                     HttpField,
660                     UnmodifiedField :: HttpString,
661                     Value :: HttpString},
662      HttpError :: {'http_error', HttpString},
663      HttpMethod :: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE'
664                  | 'TRACE' | HttpString,
665      HttpUri :: '*'
666               | { 'absoluteURI',
667                   'http' | 'https',
668                   Host :: HttpString,
669                   Port :: inet:port_number() | 'undefined',
670                   Path :: HttpString}
671               | {'scheme', Scheme :: HttpString, HttpString}
672               | {'abs_path', HttpString}
673               | HttpString,
674      HttpVersion :: {Major :: non_neg_integer(), Minor :: non_neg_integer()},
675      HttpField :: 'Cache-Control'
676                 | 'Connection'
677                 | 'Date'
678                 | 'Pragma'
679                 | 'Transfer-Encoding'
680                 | 'Upgrade'
681                 | 'Via'
682                 | 'Accept'
683                 | 'Accept-Charset'
684                 | 'Accept-Encoding'
685                 | 'Accept-Language'
686                 | 'Authorization'
687                 | 'From'
688                 | 'Host'
689                 | 'If-Modified-Since'
690                 | 'If-Match'
691                 | 'If-None-Match'
692                 | 'If-Range'
693                 | 'If-Unmodified-Since'
694                 | 'Max-Forwards'
695                 | 'Proxy-Authorization'
696                 | 'Range'
697                 | 'Referer'
698                 | 'User-Agent'
699                 | 'Age'
700                 | 'Location'
701                 | 'Proxy-Authenticate'
702                 | 'Public'
703                 | 'Retry-After'
704                 | 'Server'
705                 | 'Vary'
706                 | 'Warning'
707                 |'Www-Authenticate'
708                 | 'Allow'
709                 | 'Content-Base'
710                 | 'Content-Encoding'
711                 | 'Content-Language'
712                 | 'Content-Length'
713                 | 'Content-Location'
714                 | 'Content-Md5'
715                 | 'Content-Range'
716                 | 'Content-Type'
717                 | 'Etag'
718                 | 'Expires'
719                 | 'Last-Modified'
720                 | 'Accept-Ranges'
721                 | 'Set-Cookie'
722                 | 'Set-Cookie2'
723                 | 'X-Forwarded-For'
724                 | 'Cookie'
725                 | 'Keep-Alive'
726                 | 'Proxy-Connection'
727                 | HttpString,
728      HttpString :: string() | binary().
729decode_packet(_Type, _Bin, _Options) ->
730    erlang:nif_error(undefined).
731
732%% delete_element/2
733-spec erlang:delete_element(Index, Tuple1) -> Tuple2 when
734      Index  :: pos_integer(),
735      Tuple1 :: tuple(),
736      Tuple2 :: tuple().
737delete_element(_Index, _Tuple1) ->
738    erlang:nif_error(undefined).
739
740%% delete_module/1
741-spec delete_module(Module) -> true | undefined when
742      Module :: module().
743delete_module(_Module) ->
744    erlang:nif_error(undefined).
745
746%% demonitor/1
747-spec demonitor(MonitorRef) -> true when
748      MonitorRef :: reference().
749demonitor(_MonitorRef) ->
750    erlang:nif_error(undefined).
751
752%% demonitor/2
753-spec demonitor(MonitorRef, OptionList) -> boolean() when
754      MonitorRef :: reference(),
755      OptionList :: [Option],
756      Option :: flush | info.
757demonitor(_MonitorRef, _OptionList) ->
758    erlang:nif_error(undefined).
759
760-spec alias() -> Alias when
761      Alias :: reference().
762
763alias() ->
764    erlang:alias([]).
765
766-spec alias(Opts) -> Alias when
767      Alias :: reference(),
768      Opts :: ['explicit_unalias' | 'reply'].
769
770alias(_Opts) ->
771    erlang:nif_error(undefined).
772
773-spec unalias(Alias) -> boolean() when
774      Alias :: reference().
775
776unalias(_Alias) ->
777    erlang:nif_error(undefined).
778
779%% display/1
780-spec erlang:display(Term) -> true when
781      Term :: term().
782display(_Term) ->
783    erlang:nif_error(undefined).
784
785%% display_nl/0
786-spec erlang:display_nl() -> true.
787display_nl() ->
788    erlang:nif_error(undefined).
789
790%% display_string/1
791-spec erlang:display_string(P1) -> true when
792      P1 :: string().
793display_string(_P1) ->
794    erlang:nif_error(undefined).
795
796%% dt_append_vm_tag_data/1
797-spec erlang:dt_append_vm_tag_data(IoData) -> IoDataRet when
798      IoData :: iodata(),
799      IoDataRet :: iodata().
800dt_append_vm_tag_data(_IoData) ->
801    erlang:nif_error(undefined).
802
803%% dt_get_tag/0
804-spec erlang:dt_get_tag() -> binary() | undefined.
805dt_get_tag() ->
806    erlang:nif_error(undefined).
807
808%%  dt_get_tag_data/0
809-spec erlang:dt_get_tag_data() -> binary() | undefined.
810dt_get_tag_data() ->
811    erlang:nif_error(undefined).
812
813%% dt_prepend_vm_tag_data/1
814-spec erlang:dt_prepend_vm_tag_data(IoData) -> IoDataRet when
815      IoData :: iodata(),
816      IoDataRet :: iodata().
817dt_prepend_vm_tag_data(_IoData) ->
818    erlang:nif_error(undefined).
819
820%% dt_put_tag/1
821-spec erlang:dt_put_tag(IoData) -> binary() | undefined when
822      IoData :: iodata().
823dt_put_tag(_IoData) ->
824    erlang:nif_error(undefined).
825
826%% dt_restore_tag/1
827-spec erlang:dt_restore_tag(TagData) -> true when
828      TagData :: term().
829dt_restore_tag(_TagData) ->
830    erlang:nif_error(undefined).
831
832%% dt_spread_tag/1
833-spec erlang:dt_spread_tag(boolean()) -> TagData when
834      TagData :: term().
835dt_spread_tag(_Bool) ->
836    erlang:nif_error(undefined).
837
838%% erase/0
839-spec erase() -> [{Key, Val}] when
840      Key :: term(),
841      Val :: term().
842erase() ->
843    erlang:nif_error(undefined).
844
845%% erase/1
846-spec erase(Key) -> Val | undefined when
847      Key :: term(),
848      Val :: term().
849erase(_Key) ->
850    erlang:nif_error(undefined).
851
852%% error/1
853%% Shadowed by erl_bif_types: erlang:error/1
854-spec error(Reason) -> no_return() when
855      Reason :: term().
856error(_Reason) ->
857    erlang:nif_error(undefined).
858
859%% error/2
860%% Shadowed by erl_bif_types: erlang:error/2
861-spec error(Reason, Args) -> no_return() when
862      Reason :: term(),
863      Args :: [term()] | none.
864error(_Reason, _Args) ->
865    erlang:nif_error(undefined).
866
867%% error/3
868%% Shadowed by erl_bif_types: erlang:error/3
869-spec error(Reason, Args, Options) -> no_return() when
870      Reason :: term(),
871      Args :: [term()] | none,
872      Options :: [Option],
873      Option :: {'error_info', ErrorInfoMap},
874      ErrorInfoMap :: #{'cause' => term(),
875                        'module' => module(),
876                        'function' => atom()}.
877error(_Reason, _Args, _Options) ->
878    erlang:nif_error(undefined).
879
880%% exit/1
881%% Shadowed by erl_bif_types: erlang:exit/1
882-spec exit(Reason) -> no_return() when
883      Reason :: term().
884exit(_Reason) ->
885    erlang:nif_error(undefined).
886
887%% exit/2
888-spec exit(Pid, Reason) -> true when
889      Pid :: pid() | port(),
890      Reason :: term().
891exit(_Pid, _Reason) ->
892    erlang:nif_error(undefined).
893
894%% exit_signal/2
895-spec erlang:exit_signal(Pid, Reason) -> true when
896      Pid :: pid() | port(),
897      Reason :: term().
898exit_signal(_Pid, _Reason) ->
899    erlang:nif_error(undefined).
900
901%% external_size/1
902-spec erlang:external_size(Term) -> non_neg_integer() when
903      Term :: term().
904external_size(_Term) ->
905    erlang:nif_error(undefined).
906
907%% external_size/2
908-spec erlang:external_size(Term, Options) -> non_neg_integer() when
909      Term :: term(),
910      Options :: [{minor_version, Version :: non_neg_integer()}].
911external_size(_Term, _Options) ->
912    erlang:nif_error(undefined).
913
914%% finish_loading/2
915-spec erlang:finish_loading(PreparedCodeList) -> ok | Error when
916      PreparedCodeList :: [PreparedCode],
917      PreparedCode :: prepared_code(),
918      ModuleList :: [module()],
919      Error :: {not_purged,ModuleList} | {on_load,ModuleList}.
920finish_loading(_List) ->
921    erlang:nif_error(undefined).
922
923%% finish_after_on_load/2
924-spec erlang:finish_after_on_load(P1, P2) -> true when
925      P1 :: atom(),
926      P2 :: boolean().
927finish_after_on_load(_P1, _P2) ->
928    erlang:nif_error(undefined).
929
930%% float/1
931%% Shadowed by erl_bif_types: erlang:float/1
932-spec float(Number) -> float() when
933      Number :: number().
934float(_Number) ->
935    erlang:nif_error(undefined).
936
937%% float_to_binary/1
938-spec float_to_binary(Float) -> binary() when
939      Float :: float().
940float_to_binary(_Float) ->
941    erlang:nif_error(undefined).
942
943%% float_to_binary/2
944-spec float_to_binary(Float, Options) -> binary() when
945      Float :: float(),
946      Options :: [Option],
947      Option  :: {decimals, Decimals :: 0..253} |
948                 {scientific, Decimals :: 0..249} |
949                 compact.
950float_to_binary(_Float, _Options) ->
951    erlang:nif_error(undefined).
952
953%% float_to_list/1
954-spec float_to_list(Float) -> string() when
955      Float :: float().
956float_to_list(_Float) ->
957    erlang:nif_error(undefined).
958
959%% float_to_list/2
960-spec float_to_list(Float, Options) -> string() when
961      Float :: float(),
962      Options :: [Option],
963      Option  :: {decimals, Decimals :: 0..253} |
964                 {scientific, Decimals :: 0..249} |
965                 compact.
966float_to_list(_Float, _Options) ->
967    erlang:nif_error(undefined).
968
969%% floor/1
970%% Shadowed by erl_bif_types: erlang:floor/1
971-spec floor(Number) -> integer() when
972      Number :: number().
973floor(_) ->
974    erlang:nif_error(undef).
975
976%% fun_info/2
977-spec erlang:fun_info(Fun, Item) -> {Item, Info} when
978      Fun :: function(),
979      Item :: fun_info_item(),
980      Info :: term().
981fun_info(_Fun, _Item) ->
982    erlang:nif_error(undefined).
983
984%% fun_info_mfa/1
985-spec erlang:fun_info_mfa(Fun) -> {Mod, Name, Arity} when
986      Fun :: function(),
987      Mod :: atom(),
988      Name :: atom(),
989      Arity :: non_neg_integer().
990fun_info_mfa(_Fun) ->
991    erlang:nif_error(undefined).
992
993%% fun_to_list/1
994-spec erlang:fun_to_list(Fun) -> String :: string() when
995      Fun :: function().
996fun_to_list(_Fun) ->
997    erlang:nif_error(undefined).
998
999%% function_exported/3
1000-spec erlang:function_exported(Module, Function, Arity) -> boolean() when
1001      Module :: module(),
1002      Function :: atom(),
1003      Arity :: arity().
1004function_exported(_Module, _Function, _Arity) ->
1005    erlang:nif_error(undefined).
1006
1007%% garbage_collect/0
1008-spec garbage_collect() -> true.
1009garbage_collect() ->
1010    erts_internal:garbage_collect(major).
1011
1012%% garbage_collect/1
1013-spec garbage_collect(Pid) -> GCResult when
1014      Pid :: pid(),
1015      GCResult :: boolean().
1016garbage_collect(Pid) ->
1017    try
1018	erlang:garbage_collect(Pid, [])
1019    catch
1020	error:Error -> error_with_info(Error, [Pid])
1021    end.
1022
1023-record(gcopt, {
1024    async = sync :: sync | {async, _},
1025    type = major % default major, can also be minor
1026    }).
1027
1028%% garbage_collect/2
1029-spec garbage_collect(Pid, OptionList) -> GCResult | async when
1030      Pid :: pid(),
1031      RequestId :: term(),
1032      Option :: {async, RequestId} | {type, 'major' | 'minor'},
1033      OptionList :: [Option],
1034      GCResult :: boolean().
1035garbage_collect(Pid, OptionList)  ->
1036    try
1037	GcOpts = get_gc_opts(OptionList, #gcopt{}),
1038	case GcOpts#gcopt.async of
1039	    {async, ReqId} ->
1040		erts_internal:request_system_task(
1041                    Pid, inherit, {garbage_collect, ReqId, GcOpts#gcopt.type}),
1042		async;
1043	    sync ->
1044		case Pid == erlang:self() of
1045		    true ->
1046			erts_internal:garbage_collect(GcOpts#gcopt.type);
1047		    false ->
1048			ReqId = erlang:make_ref(),
1049			erts_internal:request_system_task(
1050                            Pid, inherit,
1051                            {garbage_collect, ReqId, GcOpts#gcopt.type}),
1052			receive
1053			    {garbage_collect, ReqId, GCResult} ->
1054				GCResult
1055			end
1056		end
1057	end
1058    catch
1059        throw:bad_option -> badarg_with_cause([Pid, OptionList], bad_option);
1060	error:_ -> badarg_with_info([Pid, OptionList])
1061    end.
1062
1063%% gets async opt and verify valid option list
1064get_gc_opts([{async, _ReqId} = AsyncTuple | Options], GcOpt = #gcopt{}) ->
1065    get_gc_opts(Options, GcOpt#gcopt{ async = AsyncTuple });
1066get_gc_opts([{type, T} | Options], GcOpt = #gcopt{}) ->
1067    get_gc_opts(Options, GcOpt#gcopt{ type = T });
1068get_gc_opts([], GcOpt) ->
1069    GcOpt;
1070get_gc_opts(_, _) ->
1071    erlang:throw(bad_option).
1072
1073%% garbage_collect_message_area/0
1074-spec erlang:garbage_collect_message_area() -> boolean().
1075garbage_collect_message_area() ->
1076    erlang:nif_error(undefined).
1077
1078%% get/0
1079-spec get() -> [{Key, Val}] when
1080      Key :: term(),
1081      Val :: term().
1082get() ->
1083    erlang:nif_error(undefined).
1084
1085%% get/1
1086-spec get(Key) -> Val | undefined when
1087      Key :: term(),
1088      Val :: term().
1089get(_Key) ->
1090    erlang:nif_error(undefined).
1091
1092%% get_keys/0
1093-spec get_keys() -> [Key] when
1094      Key :: term().
1095get_keys() ->
1096    erlang:nif_error(undefined).
1097
1098%% get_keys/1
1099-spec get_keys(Val) -> [Key] when
1100      Val :: term(),
1101      Key :: term().
1102get_keys(_Val) ->
1103    erlang:nif_error(undefined).
1104
1105%% get_module_info/1
1106-spec erlang:get_module_info(Module) -> [{Item, term()}] when
1107      Item :: module | exports | attributes | compile | native | md5,
1108      Module :: atom().
1109get_module_info(_Module) ->
1110    erlang:nif_error(undefined).
1111
1112%% group_leader/0
1113-spec group_leader() -> pid().
1114group_leader() ->
1115    erlang:nif_error(undefined).
1116
1117%% group_leader/2
1118-spec group_leader(GroupLeader, Pid) -> true when
1119      GroupLeader :: pid(),
1120      Pid :: pid().
1121group_leader(GroupLeader, Pid) ->
1122    case case erts_internal:group_leader(GroupLeader, Pid) of
1123             false ->
1124                 Ref = erlang:make_ref(),
1125                 erts_internal:group_leader(GroupLeader,
1126                                            Pid,
1127                                            Ref),
1128                 receive {Ref, MsgRes} -> MsgRes end;
1129             Res ->
1130                 Res
1131         end of
1132        true -> true;
1133        Error -> error_with_info(Error, [GroupLeader, Pid])
1134    end.
1135
1136%% halt/0
1137%% Shadowed by erl_bif_types: erlang:halt/0
1138-spec halt() -> no_return().
1139halt() ->
1140    erlang:halt(0, []).
1141
1142%% halt/1
1143%% Shadowed by erl_bif_types: erlang:halt/1
1144-spec halt(Status) -> no_return() when
1145      Status :: non_neg_integer() | 'abort' | string().
1146-dialyzer({no_return, halt/1}).
1147halt(Status) ->
1148    try
1149        erlang:halt(Status, [])
1150    catch
1151	error:Error -> error_with_info(Error, [Status])
1152    end.
1153
1154%% halt/2
1155%% Shadowed by erl_bif_types: erlang:halt/2
1156-spec halt(Status, Options) -> no_return() when
1157      Status :: non_neg_integer() | 'abort' | string(),
1158      Options :: [Option],
1159      Option :: {flush, boolean()}.
1160halt(_Status, _Options) ->
1161    erlang:nif_error(undefined).
1162
1163%% has_prepared_code_on_load/1
1164-spec erlang:has_prepared_code_on_load(PreparedCode) -> boolean() when
1165      PreparedCode :: prepared_code().
1166has_prepared_code_on_load(_PreparedCode) ->
1167    erlang:nif_error(undefined).
1168
1169%% hibernate/3
1170-spec erlang:hibernate(Module, Function, Args) -> no_return() when
1171      Module :: module(),
1172      Function :: atom(),
1173      Args :: [term()].
1174hibernate(_Module, _Function, _Args) ->
1175    erlang:nif_error(undefined).
1176
1177%% insert_element/3
1178-spec erlang:insert_element(Index, Tuple1, Term) -> Tuple2 when
1179      Index  :: pos_integer(),
1180      Tuple1 :: tuple(),
1181      Tuple2 :: tuple(),
1182      Term   :: term().
1183insert_element(_Index, _Tuple1, _Term) ->
1184    erlang:nif_error(undefined).
1185
1186%% integer_to_binary/1
1187-spec integer_to_binary(Integer) -> binary() when
1188      Integer :: integer().
1189integer_to_binary(_Integer) ->
1190    erlang:nif_error(undefined).
1191
1192%% integer_to_list/1
1193-spec integer_to_list(Integer) -> string() when
1194      Integer :: integer().
1195integer_to_list(_Integer) ->
1196    erlang:nif_error(undefined).
1197
1198%% iolist_size/1
1199-spec iolist_size(Item) -> non_neg_integer() when
1200      Item :: iolist() | binary().
1201iolist_size(_Item) ->
1202    erlang:nif_error(undefined).
1203
1204%% iolist_to_binary/1
1205-spec iolist_to_binary(IoListOrBinary) -> binary() when
1206      IoListOrBinary :: iolist() | binary().
1207iolist_to_binary(_IoListOrBinary) ->
1208    erlang:nif_error(undefined).
1209
1210%% iolist_to_iovec/1
1211-spec erlang:iolist_to_iovec(IoListOrBinary) -> iovec() when
1212      IoListOrBinary :: iolist() | binary().
1213iolist_to_iovec(_IoListOrBinary) ->
1214    erlang:nif_error(undefined).
1215
1216%% is_alive/0
1217-spec is_alive() -> boolean().
1218is_alive() ->
1219    erlang:nif_error(undefined).
1220
1221%% is_builtin/3
1222-spec erlang:is_builtin(Module, Function, Arity) -> boolean() when
1223      Module :: module(),
1224      Function :: atom(),
1225      Arity :: arity().
1226is_builtin(_Module, _Function, _Arity) ->
1227    erlang:nif_error(undefined).
1228
1229%% Shadowed by erl_bif_types: erlang:is_map_key/2
1230-spec is_map_key(Key, Map) -> boolean() when
1231    Key :: term(),
1232    Map :: map().
1233is_map_key(_,_) ->
1234    erlang:nif_error(undef).
1235
1236%% is_process_alive/1
1237-spec is_process_alive(Pid) -> boolean() when
1238      Pid :: pid().
1239is_process_alive(_Pid) ->
1240    erlang:nif_error(undefined).
1241
1242%% length/1
1243%% Shadowed by erl_bif_types: erlang:length/1
1244-spec length(List) -> non_neg_integer() when
1245      List :: [term()].
1246length(_List) ->
1247    erlang:nif_error(undefined).
1248
1249%% link/1
1250-spec link(PidOrPort) -> true when
1251      PidOrPort :: pid() | port().
1252link(_PidOrPort) ->
1253    erlang:nif_error(undefined).
1254
1255%% list_to_atom/1
1256-spec list_to_atom(String) -> atom() when
1257      String :: string().
1258list_to_atom(_String) ->
1259    erlang:nif_error(undefined).
1260
1261%% list_to_binary/1
1262-spec list_to_binary(IoList) -> binary() when
1263      IoList :: iolist().
1264list_to_binary(_IoList) ->
1265    erlang:nif_error(undefined).
1266
1267%% list_to_bitstring/1
1268-spec list_to_bitstring(BitstringList) -> bitstring() when
1269      BitstringList :: bitstring_list().
1270list_to_bitstring(_BitstringList) ->
1271    erlang:nif_error(undefined).
1272
1273%% list_to_existing_atom/1
1274-spec list_to_existing_atom(String) -> atom() when
1275      String :: string().
1276list_to_existing_atom(_String) ->
1277    erlang:nif_error(undefined).
1278
1279%% list_to_float/1
1280-spec list_to_float(String) -> float() when
1281      String :: string().
1282list_to_float(_String) ->
1283    erlang:nif_error(undefined).
1284
1285%% list_to_integer/1
1286-spec list_to_integer(String) -> integer() when
1287      String :: string().
1288list_to_integer(_String) ->
1289    erlang:nif_error(undefined).
1290
1291%% list_to_integer/2
1292-spec list_to_integer(String, Base) -> integer() when
1293      String :: string(),
1294      Base :: 2..36.
1295list_to_integer(_String,_Base) ->
1296    erlang:nif_error(undefined).
1297
1298%% list_to_pid/1
1299-spec list_to_pid(String) -> pid() when
1300      String :: string().
1301list_to_pid(_String) ->
1302    erlang:nif_error(undefined).
1303
1304%% list_to_port/1
1305-spec list_to_port(String) -> port() when
1306      String :: string().
1307list_to_port(_String) ->
1308    erlang:nif_error(undefined).
1309
1310%% list_to_ref/1
1311-spec list_to_ref(String) -> reference() when
1312      String :: string().
1313list_to_ref(_String) ->
1314    erlang:nif_error(undefined).
1315
1316%% list_to_tuple/1
1317-spec list_to_tuple(List) -> tuple() when
1318      List :: [term()].
1319list_to_tuple(_List) ->
1320    erlang:nif_error(undefined).
1321
1322%% loaded/0
1323-spec erlang:loaded() -> [Module] when
1324      Module :: module().
1325loaded() ->
1326    erlang:nif_error(undefined).
1327
1328%% localtime/0
1329-spec erlang:localtime() -> DateTime when
1330      DateTime :: calendar:datetime().
1331localtime() ->
1332    erlang:nif_error(undefined).
1333
1334%% make_ref/0
1335-spec make_ref() -> reference().
1336make_ref() ->
1337    erlang:nif_error(undefined).
1338
1339%% Shadowed by erl_bif_types: erlang:map_size/1
1340-spec map_size(Map) -> non_neg_integer() when
1341      Map :: map().
1342map_size(_Map) ->
1343    erlang:nif_error(undefined).
1344
1345%% Shadowed by erl_bif_types: erlang:map_get/2
1346-spec map_get(Key, Map) -> Value when
1347      Map :: map(),
1348      Key :: any(),
1349      Value :: any().
1350map_get(_Key, _Map) ->
1351    erlang:nif_error(undefined).
1352
1353%% match_spec_test/3
1354-spec erlang:match_spec_test(MatchAgainst, MatchSpec, Type) -> TestResult when
1355      MatchAgainst :: [term()] | tuple(),
1356      MatchSpec :: term(),
1357      Type :: table | trace,
1358      TestResult :: {ok, term(), [return_trace], [ {error | warning, string()} ]} | {error, [ {error | warning, string()} ]}.
1359match_spec_test(_P1, _P2, _P3) ->
1360    erlang:nif_error(undefined).
1361
1362%% md5/1
1363-spec erlang:md5(Data) -> Digest when
1364      Data :: iodata(),
1365      Digest :: binary().
1366md5(_Data) ->
1367    erlang:nif_error(undefined).
1368
1369%% md5_final/1
1370-spec erlang:md5_final(Context) -> Digest when
1371      Context :: binary(),
1372      Digest :: binary().
1373md5_final(_Context) ->
1374    erlang:nif_error(undefined).
1375
1376%% md5_init/0
1377-spec erlang:md5_init() -> Context when
1378      Context :: binary().
1379md5_init() ->
1380    erlang:nif_error(undefined).
1381
1382%% md5_update/2
1383-spec erlang:md5_update(Context, Data) -> NewContext when
1384      Context :: binary(),
1385      Data :: iodata(),
1386      NewContext :: binary().
1387md5_update(_Context, _Data) ->
1388    erlang:nif_error(undefined).
1389
1390%% module_loaded/1
1391-spec module_loaded(Module) -> boolean() when
1392      Module :: module().
1393module_loaded(_Module) ->
1394    erlang:nif_error(undefined).
1395
1396-type registered_name() :: atom().
1397-type registered_process_identifier() :: registered_name() | {registered_name(), node()}.
1398-type monitor_process_identifier() :: pid() | registered_process_identifier().
1399-type monitor_port_identifier() :: port() | registered_name().
1400-type monitor_option() :: {'alias', 'explicit_unalias' | 'demonitor' | 'reply_demonitor'}
1401                        | {'tag', term()}.
1402
1403%% monitor/2
1404-spec monitor
1405      (process, monitor_process_identifier()) -> MonitorRef
1406	  when MonitorRef :: reference();
1407      (port, monitor_port_identifier()) -> MonitorRef
1408	  when MonitorRef :: reference();
1409      (time_offset, clock_service) -> MonitorRef
1410	  when MonitorRef :: reference().
1411
1412monitor(_Type, _Item) ->
1413    erlang:nif_error(undefined).
1414
1415%% monitor/3
1416-spec monitor
1417      (process, monitor_process_identifier(), [monitor_option()]) -> MonitorRef
1418	  when MonitorRef :: reference();
1419      (port, monitor_port_identifier(), [monitor_option()]) -> MonitorRef
1420	  when MonitorRef :: reference();
1421      (time_offset, clock_service, [monitor_option()]) -> MonitorRef
1422	  when MonitorRef :: reference().
1423
1424monitor(_Type, _Item, _Opts) ->
1425    erlang:nif_error(undefined).
1426
1427%% monitor_node/2
1428-spec monitor_node(Node, Flag) -> true when
1429      Node :: node(),
1430      Flag :: boolean().
1431monitor_node(_Node, _Flag) ->
1432    erlang:nif_error(undefined).
1433
1434%% monitor_node/3
1435-spec erlang:monitor_node(Node, Flag, Options) -> true when
1436      Node :: node(),
1437      Flag :: boolean(),
1438      Options :: [Option],
1439      Option :: allow_passive_connect.
1440monitor_node(_Node, _Flag, _Options) ->
1441    erlang:nif_error(undefined).
1442
1443%% nif_error/1
1444%% Shadowed by erl_bif_types: erlang:nif_error/1
1445-spec erlang:nif_error(Reason) -> no_return() when
1446      Reason :: term().
1447nif_error(_Reason) ->
1448    erlang:nif_error(undefined).
1449
1450%% nif_error/2
1451%% Shadowed by erl_bif_types: erlang:nif_error/2
1452-spec erlang:nif_error(Reason, Args) -> no_return() when
1453      Reason :: term(),
1454      Args :: [term()].
1455nif_error(_Reason, _Args) ->
1456    erlang:nif_error(undefined).
1457
1458%% node/0
1459%% Shadowed by erl_bif_types: erlang:node/0
1460-spec node() -> Node when
1461      Node :: node().
1462node() ->
1463    erlang:nif_error(undefined).
1464
1465%% node/1
1466%% Shadowed by erl_bif_types: erlang:node/1
1467-spec node(Arg) -> Node when
1468      Arg :: pid() | port() | reference(),
1469      Node :: node().
1470node(_Arg) ->
1471    erlang:nif_error(undefined).
1472
1473%% now/0
1474-spec now() -> Timestamp when
1475      Timestamp :: timestamp().
1476now() ->
1477    erlang:nif_error(undefined).
1478
1479%% phash/2
1480-spec erlang:phash(Term, Range) -> Hash when
1481      Term :: term(),
1482      Range :: pos_integer(),
1483      Hash :: pos_integer().
1484phash(_Term, _Range) ->
1485    erlang:nif_error(undefined).
1486
1487%% phash2/1
1488-spec erlang:phash2(Term) -> Hash when
1489      Term :: term(),
1490      Hash :: non_neg_integer().
1491phash2(_Term) ->
1492    erlang:nif_error(undefined).
1493
1494%% phash2/2
1495-spec erlang:phash2(Term, Range) -> Hash when
1496      Term :: term(),
1497      Range :: pos_integer(),
1498      Hash :: non_neg_integer().
1499phash2(_Term, _Range) ->
1500    erlang:nif_error(undefined).
1501
1502%% pid_to_list/1
1503-spec pid_to_list(Pid) -> string() when
1504      Pid :: pid().
1505pid_to_list(_Pid) ->
1506    erlang:nif_error(undefined).
1507
1508%% port_to_list/1
1509-spec port_to_list(Port) -> string() when
1510      Port :: port().
1511port_to_list(_Port) ->
1512    erlang:nif_error(undefined).
1513
1514%% ports/0
1515-spec erlang:ports() -> [port()].
1516ports() ->
1517    erlang:nif_error(undefined).
1518
1519%% posixtime_to_universaltime/1
1520-spec erlang:posixtime_to_universaltime(P1) -> {calendar:date(), calendar:time()} when
1521      P1 :: integer().
1522posixtime_to_universaltime(_P1) ->
1523    erlang:nif_error(undefined).
1524
1525-spec erlang:unique_integer(ModifierList) -> integer() when
1526      ModifierList :: [Modifier],
1527      Modifier :: positive | monotonic.
1528
1529unique_integer(_ModifierList) ->
1530    erlang:nif_error(undefined).
1531
1532-spec erlang:unique_integer() -> integer().
1533
1534unique_integer() ->
1535    erlang:nif_error(undefined).
1536
1537-spec erlang:monotonic_time() -> integer().
1538
1539monotonic_time() ->
1540    erlang:nif_error(undefined).
1541
1542-spec erlang:monotonic_time(Unit) -> integer() when
1543      Unit :: time_unit().
1544
1545monotonic_time(_Unit) ->
1546    erlang:nif_error(undefined).
1547
1548-spec erlang:system_time() -> integer().
1549
1550system_time() ->
1551    erlang:nif_error(undefined).
1552
1553-spec erlang:system_time(Unit) -> integer() when
1554      Unit :: time_unit().
1555
1556system_time(_Unit) ->
1557    erlang:nif_error(undefined).
1558
1559-spec erlang:convert_time_unit(Time, FromUnit, ToUnit) -> ConvertedTime when
1560      Time :: integer(),
1561      ConvertedTime :: integer(),
1562      FromUnit :: time_unit(),
1563      ToUnit :: time_unit().
1564
1565convert_time_unit(Time, FromUnit, ToUnit) ->
1566    try
1567	FU = case FromUnit of
1568		 native -> erts_internal:time_unit();
1569                 perf_counter -> erts_internal:perf_counter_unit();
1570		 nanosecond -> 1000*1000*1000;
1571		 microsecond -> 1000*1000;
1572		 millisecond -> 1000;
1573		 second -> 1;
1574
1575		 %% Deprecated symbolic units...
1576		 nano_seconds -> 1000*1000*1000;
1577		 micro_seconds -> 1000*1000;
1578		 milli_seconds -> 1000;
1579		 seconds -> 1;
1580
1581		 _ when FromUnit > 0 -> FromUnit
1582	     end,
1583	TU = case ToUnit of
1584		 native -> erts_internal:time_unit();
1585                 perf_counter -> erts_internal:perf_counter_unit();
1586		 nanosecond -> 1000*1000*1000;
1587		 microsecond -> 1000*1000;
1588		 millisecond -> 1000;
1589		 second -> 1;
1590
1591		 %% Deprecated symbolic units...
1592		 nano_seconds -> 1000*1000*1000;
1593		 micro_seconds -> 1000*1000;
1594		 milli_seconds -> 1000;
1595		 seconds -> 1;
1596
1597		 _ when ToUnit > 0 -> ToUnit
1598	     end,
1599	case Time < 0 of
1600	    true -> TU*Time - (FU - 1);
1601	    false -> TU*Time
1602	end div FU
1603    catch
1604	_ : _ ->
1605	    error_with_info(badarg, [Time, FromUnit, ToUnit])
1606    end.
1607
1608-spec erlang:time_offset() -> integer().
1609
1610time_offset() ->
1611    erlang:nif_error(undefined).
1612
1613-spec erlang:time_offset(Unit) -> integer() when
1614      Unit :: time_unit().
1615
1616time_offset(_Unit) ->
1617    erlang:nif_error(undefined).
1618
1619-spec erlang:timestamp() -> Timestamp when
1620      Timestamp :: timestamp().
1621
1622timestamp() ->
1623    erlang:nif_error(undefined).
1624
1625%% prepare_loading/2
1626-spec erlang:prepare_loading(Module, Code) -> PreparedCode | {error, Reason} when
1627      Module :: module(),
1628      Code :: binary(),
1629      PreparedCode :: prepared_code(),
1630      Reason :: badfile.
1631prepare_loading(Module, <<"FOR1",_/bits>>=Code) ->
1632    prepare_loading_1(Module, Code);
1633prepare_loading(Module, Code0) ->
1634    %% Corrupt header or compressed module, attempt to decompress it before
1635    %% passing it to the loader and leave error signalling to the BIF.
1636    Code = try zlib:gunzip(Code0) of
1637               Decompressed -> Decompressed
1638           catch
1639               _:_ -> Code0
1640           end,
1641
1642    prepare_loading_1(Module, Code).
1643
1644prepare_loading_1(Module, Code) ->
1645    try erts_internal:prepare_loading(Module, Code) of
1646        Res -> Res
1647    catch
1648        error:Reason ->
1649            try
1650                erlang:error(new_stacktrace, [Module,Code])
1651            catch
1652                error:new_stacktrace:Stk0 ->
1653                    [{Mod,_,L,Loc0}|T] = Stk0,
1654                    Loc = [{error_info,#{module => erl_erts_errors}}|Loc0],
1655                    Stk = [{Mod,prepare_loading,L,Loc}|T],
1656                    erlang:raise(error, Reason, Stk)
1657            end
1658    end.
1659
1660%% pre_loaded/0
1661-spec pre_loaded() -> [module()].
1662pre_loaded() ->
1663    erlang:nif_error(undefined).
1664
1665%% process_display/2
1666-spec erlang:process_display(Pid, Type) -> true when
1667      Pid :: pid(),
1668      Type :: backtrace.
1669process_display(Pid, Type) ->
1670    case case erts_internal:process_display(Pid, Type) of
1671             Ref when erlang:is_reference(Ref) ->
1672                 receive
1673                     {Ref, Res} ->
1674                         Res
1675                 end;
1676             Res ->
1677                 Res
1678         end of
1679        badopt ->
1680            badarg_with_cause([Pid, Type], badopt);
1681        badarg ->
1682            badarg_with_info([Pid, Type]);
1683        Result ->
1684            Result
1685    end.
1686
1687%% process_flag/3
1688-spec process_flag(Pid, Flag, Value) -> OldValue when
1689      Pid :: pid(),
1690      Flag :: save_calls,
1691      Value :: non_neg_integer(),
1692      OldValue :: non_neg_integer().
1693process_flag(Pid, Flag, Value) ->
1694    case case erts_internal:process_flag(Pid, Flag, Value) of
1695             Ref when erlang:is_reference(Ref) ->
1696                 receive {Ref, Res} -> Res end;
1697             Res -> Res
1698         end of
1699        badtype -> badarg_with_cause([Pid, Flag, Value], badtype);
1700        badarg -> badarg_with_info([Pid, Flag, Value]);
1701        Result -> Result
1702    end.
1703
1704%% process_info/1
1705-spec process_info(Pid) -> Info when
1706      Pid :: pid(),
1707      Info :: [InfoTuple] | undefined,
1708      InfoTuple :: process_info_result_item().
1709process_info(_Pid) ->
1710    erlang:nif_error(undefined).
1711
1712%% processes/0
1713-spec processes() -> [pid()].
1714processes() ->
1715    erlang:nif_error(undefined).
1716
1717%% purge_module/1
1718-spec purge_module(Module) -> true when
1719      Module :: atom().
1720purge_module(Module) when erlang:is_atom(Module) ->
1721    case erts_code_purger:purge(Module) of
1722	{false, _} ->
1723	    badarg_with_info([Module]);
1724	{true, _} ->
1725	    true
1726    end;
1727purge_module(Arg) ->
1728    badarg_with_info([Arg]).
1729
1730
1731%% put/2
1732-spec put(Key, Val) -> term() when
1733      Key :: term(),
1734      Val :: term().
1735put(_Key, _Val) ->
1736    erlang:nif_error(undefined).
1737
1738%% raise/3
1739-spec erlang:raise(Class, Reason, Stacktrace) -> 'badarg' when
1740      Class :: 'error' | 'exit' | 'throw',
1741      Reason :: term(),
1742      Stacktrace :: raise_stacktrace() | stacktrace().
1743raise(_Class, _Reason, _Stacktrace) ->
1744    erlang:nif_error(undefined).
1745
1746%% read_timer/1
1747-spec erlang:read_timer(TimerRef) -> Result when
1748      TimerRef :: reference(),
1749      Time :: non_neg_integer(),
1750      Result :: Time | false.
1751
1752read_timer(_TimerRef) ->
1753    erlang:nif_error(undefined).
1754
1755%% read_timer/2
1756-spec erlang:read_timer(TimerRef, Options) -> Result | ok when
1757      TimerRef :: reference(),
1758      Async :: boolean(),
1759      Option :: {async, Async},
1760      Options :: [Option],
1761      Time :: non_neg_integer(),
1762      Result :: Time | false.
1763
1764read_timer(_TimerRef, _Options) ->
1765    erlang:nif_error(undefined).
1766
1767%% ref_to_list/1
1768-spec ref_to_list(Ref) -> string() when
1769      Ref :: reference().
1770ref_to_list(_Ref) ->
1771    erlang:nif_error(undefined).
1772
1773%% register/2
1774-spec register(RegName, PidOrPort) -> true when
1775      RegName :: atom(),
1776      PidOrPort :: port() | pid().
1777register(_RegName, _PidOrPort) ->
1778    erlang:nif_error(undefined).
1779
1780%% registered/0
1781-spec registered() -> [RegName] when
1782      RegName :: atom().
1783registered() ->
1784    erlang:nif_error(undefined).
1785
1786%% resume_process/1
1787-spec erlang:resume_process(Suspendee) -> true when
1788      Suspendee :: pid().
1789resume_process(_Suspendee) ->
1790    erlang:nif_error(undefined).
1791
1792%% round/1
1793%% Shadowed by erl_bif_types: erlang:round/1
1794-spec round(Number) -> integer() when
1795      Number :: number().
1796round(_Number) ->
1797    erlang:nif_error(undefined).
1798
1799%% self/0
1800%% Shadowed by erl_bif_types: erlang:self/0
1801-spec self() -> pid().
1802self() ->
1803    erlang:nif_error(undefined).
1804
1805%% send_after/3
1806-spec erlang:send_after(Time, Dest, Msg) -> TimerRef when
1807      Time :: non_neg_integer(),
1808      Dest :: pid() | atom(),
1809      Msg :: term(),
1810      TimerRef :: reference().
1811
1812send_after(_Time, _Dest, _Msg) ->
1813    erlang:nif_error(undefined).
1814
1815%% send_after/4
1816-spec erlang:send_after(Time, Dest, Msg, Options) -> TimerRef when
1817      Time :: integer(),
1818      Dest :: pid() | atom(),
1819      Msg :: term(),
1820      Options :: [Option],
1821      Abs :: boolean(),
1822      Option :: {abs, Abs},
1823      TimerRef :: reference().
1824
1825send_after(_Time, _Dest, _Msg, _Options) ->
1826    erlang:nif_error(undefined).
1827
1828%% seq_trace/2
1829-spec erlang:seq_trace(P1, P2) -> seq_trace_info_returns() | {term(), term(), term(), term(), term()} when
1830      P1 :: atom(),
1831      P2 :: boolean() | {integer(), integer()} | integer() | [].
1832seq_trace(_P1, _P2) ->
1833    erlang:nif_error(undefined).
1834
1835%% seq_trace_print/1
1836-spec erlang:seq_trace_print(P1) -> boolean() when
1837      P1 :: term().
1838seq_trace_print(_P1) ->
1839    erlang:nif_error(undefined).
1840
1841%% seq_trace_print/2
1842-spec erlang:seq_trace_print(P1, P2) -> boolean() when
1843      P1 :: atom() | integer(),
1844      P2 :: term().
1845seq_trace_print(_P1, _P2) ->
1846    erlang:nif_error(undefined).
1847
1848%% setnode/2
1849-spec erlang:setnode(P1, P2) -> true when
1850      P1 :: atom(),
1851      P2 :: integer().
1852setnode(_P1, _P2) ->
1853    erlang:nif_error(undefined).
1854
1855%% setnode/3
1856-spec erlang:setnode(Node, DistCtrlr, Opts) -> dist_handle() when
1857      Node :: atom(),
1858      DistCtrlr :: port() | pid(),
1859      Opts :: {integer(), integer(), pos_integer()}.
1860setnode(Node, DistCtrlr, {_Flags, _Ver, _Creation} = Opts) ->
1861    case case erts_internal:create_dist_channel(Node, DistCtrlr, Opts) of
1862             {ok, DH} -> DH;
1863             {message, Ref} -> receive {Ref, Res} -> Res end;
1864             Err -> Err
1865         end of
1866        Error when erlang:is_atom(Error) ->
1867            erlang:error(Error, [Node, DistCtrlr, Opts]);
1868        DHandle ->
1869            DHandle
1870    end;
1871setnode(Node, DistCtrlr, Opts) ->
1872    badarg_with_info([Node, DistCtrlr, Opts]).
1873
1874
1875%% size/1
1876%% Shadowed by erl_bif_types: erlang:size/1
1877-spec size(Item) -> non_neg_integer() when
1878      Item :: tuple() | binary().
1879size(_Item) ->
1880    erlang:nif_error(undefined).
1881
1882%% spawn/3
1883-spec spawn(Module, Function, Args) -> pid() when
1884      Module :: module(),
1885      Function :: atom(),
1886      Args :: [term()].
1887spawn(_Module, _Function, _Args) ->
1888    erlang:nif_error(undefined).
1889
1890%% spawn_link/3
1891-spec spawn_link(Module, Function, Args) -> pid() when
1892      Module :: module(),
1893      Function :: atom(),
1894      Args :: [term()].
1895spawn_link(_Module, _Function, _Args) ->
1896    erlang:nif_error(undefined).
1897
1898%% split_binary/2
1899-spec split_binary(Bin, Pos) -> {binary(), binary()} when
1900      Bin :: binary(),
1901      Pos :: non_neg_integer().
1902split_binary(_Bin, _Pos) ->
1903    erlang:nif_error(undefined).
1904
1905%% start_timer/3
1906-spec erlang:start_timer(Time, Dest, Msg) -> TimerRef when
1907      Time :: non_neg_integer(),
1908      Dest :: pid() | atom(),
1909      Msg :: term(),
1910      TimerRef :: reference().
1911
1912start_timer(_Time, _Dest, _Msg) ->
1913    erlang:nif_error(undefined).
1914
1915%% start_timer/4
1916-spec erlang:start_timer(Time, Dest, Msg, Options) -> TimerRef when
1917      Time :: integer(),
1918      Dest :: pid() | atom(),
1919      Msg :: term(),
1920      Options :: [Option],
1921      Abs :: boolean(),
1922      Option :: {abs, Abs},
1923      TimerRef :: reference().
1924
1925start_timer(_Time, _Dest, _Msg, _Options) ->
1926    erlang:nif_error(undefined).
1927
1928%% suspend_process/2
1929-spec erlang:suspend_process(Suspendee, OptList) -> boolean() when
1930      Suspendee :: pid(),
1931      OptList :: [Opt],
1932      Opt :: unless_suspending | asynchronous | {asynchronous, term()}.
1933suspend_process(Suspendee, OptList) ->
1934    case case erts_internal:suspend_process(Suspendee, OptList) of
1935	     Ref when erlang:is_reference(Ref) ->
1936                 receive {Ref, Res} -> Res end;
1937             Res ->
1938                 Res
1939         end of
1940        badopt -> badarg_with_cause([Suspendee, OptList], badopt);
1941        Bool when erlang:is_boolean(Bool) -> Bool;
1942	Error -> error_with_info(Error, [Suspendee, OptList])
1943    end.
1944
1945-spec erlang:suspend_process(Suspendee) -> 'true' when
1946      Suspendee :: pid().
1947suspend_process(Suspendee) ->
1948    case case erts_internal:suspend_process(Suspendee, []) of
1949	     Ref when erlang:is_reference(Ref) ->
1950                 receive {Ref, Res} -> Res end;
1951             Res ->
1952                 Res
1953	 end of
1954	true -> true;
1955        false -> erlang:error(internal_error, [Suspendee]);
1956	Error -> error_with_info(Error, [Suspendee])
1957    end.
1958
1959%% system_monitor/0
1960-spec erlang:system_monitor() -> MonSettings when
1961      MonSettings :: undefined | { MonitorPid, Options },
1962      MonitorPid :: pid(),
1963      Options :: [ system_monitor_option() ].
1964system_monitor() ->
1965    erlang:nif_error(undefined).
1966
1967%% system_monitor/1
1968-spec erlang:system_monitor(Arg) -> MonSettings when
1969      Arg :: undefined | { MonitorPid, Options },
1970      MonSettings :: undefined | { MonitorPid, Options },
1971      MonitorPid :: pid(),
1972      Options :: [ system_monitor_option() ].
1973system_monitor(_Arg) ->
1974    erlang:nif_error(undefined).
1975
1976%% system_monitor/2
1977-spec erlang:system_monitor(MonitorPid, Options) -> MonSettings when
1978      MonitorPid :: pid(),
1979      Options :: [ system_monitor_option() ],
1980      MonSettings :: undefined | { OldMonitorPid, OldOptions },
1981      OldMonitorPid :: pid(),
1982      OldOptions :: [ system_monitor_option() ].
1983system_monitor(_MonitorPid, _Options) ->
1984    erlang:nif_error(undefined).
1985
1986%% system_profile/0
1987-spec erlang:system_profile() -> ProfilerSettings when
1988      ProfilerSettings :: undefined | { ProfilerPid, Options},
1989      ProfilerPid :: pid() | port(),
1990      Options :: [ system_profile_option() ].
1991system_profile() ->
1992    erlang:nif_error(undefined).
1993
1994%% system_profile/2
1995-spec erlang:system_profile(ProfilerPid, Options) -> ProfilerSettings when
1996      ProfilerPid :: pid() | port() | undefined,
1997      Options :: [ system_profile_option() ],
1998      ProfilerSettings :: undefined | { pid() | port(), [ system_profile_option() ]}.
1999system_profile(_ProfilerPid, _Options) ->
2000    erlang:nif_error(undefined).
2001
2002%% throw/1
2003%% Shadowed by erl_bif_types: erlang:throw/1
2004-spec throw(Any) -> no_return() when
2005      Any :: term().
2006throw(_Any) ->
2007    erlang:nif_error(undefined).
2008
2009%% time/0
2010-spec time() -> Time when
2011      Time :: calendar:time().
2012time() ->
2013    erlang:nif_error(undefined).
2014
2015%% trace/3
2016-spec erlang:trace(PidPortSpec, How, FlagList) -> integer() when
2017      PidPortSpec :: pid() | port()
2018                   | all | processes | ports
2019                   | existing | existing_processes | existing_ports
2020                   | new | new_processes | new_ports,
2021      How :: boolean(),
2022      FlagList :: [trace_flag()].
2023trace(PidPortSpec, How, FlagList) ->
2024    ensure_tracer_module_loaded(tracer, FlagList),
2025    try erts_internal:trace(PidPortSpec, How, FlagList) of
2026        Res -> Res
2027    catch error:R:Stk ->
2028            error_with_inherited_info(R, [PidPortSpec, How, FlagList], Stk)
2029    end.
2030%% trace_delivered/1
2031-spec erlang:trace_delivered(Tracee) -> Ref when
2032      Tracee :: pid() | all,
2033      Ref :: reference().
2034trace_delivered(_Tracee) ->
2035    erlang:nif_error(undefined).
2036
2037%% trace_info/2
2038-spec erlang:trace_info(PidPortFuncEvent, Item) -> Res when
2039      PidPortFuncEvent :: pid() | port() | new | new_processes | new_ports
2040                     | {Module, Function, Arity} | on_load | send | 'receive',
2041      Module :: module(),
2042      Function :: atom(),
2043      Arity :: arity(),
2044      Item :: flags | tracer | traced | match_spec
2045            | meta | meta_match_spec | call_count | call_time | all,
2046      Res :: trace_info_return().
2047trace_info(_PidPortFuncEvent, _Item) ->
2048    erlang:nif_error(undefined).
2049
2050%% trunc/1
2051%% Shadowed by erl_bif_types: erlang:trunc/1
2052-spec trunc(Number) -> integer() when
2053      Number :: number().
2054trunc(_Number) ->
2055    erlang:nif_error(undefined).
2056
2057%% tuple_size/1
2058%% Shadowed by erl_bif_types: erlang:tuple_size/1
2059-spec tuple_size(Tuple) -> non_neg_integer() when
2060      Tuple :: tuple().
2061tuple_size(_Tuple) ->
2062    erlang:nif_error(undefined).
2063
2064%% universaltime/0
2065-spec erlang:universaltime() -> DateTime when
2066      DateTime :: calendar:datetime().
2067universaltime() ->
2068    erlang:nif_error(undefined).
2069
2070%% universaltime_to_posixtime/1
2071-spec erlang:universaltime_to_posixtime(P1) -> integer() when
2072      P1 :: {calendar:date(), calendar:time()}.
2073universaltime_to_posixtime(_P1) ->
2074    erlang:nif_error(undefined).
2075
2076%% unlink/1
2077-spec unlink(Id) -> true when
2078      Id :: pid() | port().
2079unlink(_Id) ->
2080    erlang:nif_error(undefined).
2081
2082%% unregister/1
2083-spec unregister(RegName) -> true when
2084      RegName :: atom().
2085unregister(_RegName) ->
2086    erlang:nif_error(undefined).
2087
2088%% whereis/1
2089-spec whereis(RegName) -> pid() | port() | undefined when
2090      RegName :: atom().
2091whereis(_RegName) ->
2092    erlang:nif_error(undefined).
2093
2094%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2095%%% More complicated native code BIFs
2096%%% These are here for the types/specs, the real implementation is in the C code.
2097%%% This chunk is handwritten, i.e. contains more complicated specs.
2098%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2099
2100%% types and specs
2101
2102%% Shadowed by erl_bif_types: erlang:abs/1
2103-spec abs(Float) -> float() when
2104      Float :: float();
2105         (Int) -> non_neg_integer() when
2106      Int :: integer().
2107abs(_Number) ->
2108    erlang:nif_error(undefined).
2109
2110%% Not documented
2111%% Shadowed by erl_bif_types: erlang:append/2
2112-spec erlang:append(List,Tail) -> maybe_improper_list() when
2113      List :: [term()],
2114      Tail :: term().
2115append(_List,_Tail) ->
2116    erlang:nif_error(undefined).
2117
2118%% Shadowed by erl_bif_types: erlang:element/2
2119-spec element(N, Tuple) -> term() when
2120    N :: pos_integer(),
2121    Tuple :: tuple().
2122element(_N, _Tuple) ->
2123    erlang:nif_error(undefined).
2124
2125%% Not documented
2126-type module_info_key() :: attributes | compile | exports | functions | md5
2127                         | module | native | native_addresses | nifs.
2128-spec erlang:get_module_info(Module, Item) -> ModuleInfo when
2129      Module :: atom(),
2130      Item :: module_info_key(),
2131      ModuleInfo :: term().
2132get_module_info(_Module, _Item) ->
2133    erlang:nif_error(undefined).
2134
2135%% Shadowed by erl_bif_types: erlang:hd/1
2136-spec hd(List) -> term() when
2137      List :: [term(), ...].
2138hd(_List) ->
2139    erlang:nif_error(undefined).
2140
2141%% erlang:info/1 no longer exists!
2142
2143%% Shadowed by erl_bif_types: erlang:is_atom/1
2144-spec is_atom(Term) -> boolean() when
2145      Term :: term().
2146is_atom(_Term) ->
2147    erlang:nif_error(undefined).
2148
2149%% Shadowed by erl_bif_types: erlang:is_binary/1
2150-spec is_binary(Term) -> boolean() when
2151      Term :: term().
2152is_binary(_Term) ->
2153    erlang:nif_error(undefined).
2154
2155%% Shadowed by erl_bif_types: erlang:is_bitstring/1
2156-spec is_bitstring(Term) -> boolean() when
2157      Term :: term().
2158is_bitstring(_Term) ->
2159    erlang:nif_error(undefined).
2160
2161%% Shadowed by erl_bif_types: erlang:is_boolean/1
2162-spec is_boolean(Term) -> boolean() when
2163      Term :: term().
2164is_boolean(_Term) ->
2165    erlang:nif_error(undefined).
2166
2167%% Shadowed by erl_bif_types: erlang:is_float/1
2168-spec is_float(Term) -> boolean() when
2169      Term :: term().
2170is_float(_Term) ->
2171    erlang:nif_error(undefined).
2172
2173%% Shadowed by erl_bif_types: erlang:is_function/1
2174-spec is_function(Term) -> boolean() when
2175      Term :: term().
2176is_function(_Term) ->
2177    erlang:nif_error(undefined).
2178
2179%% Shadowed by erl_bif_types: erlang:is_function/2
2180-spec is_function(Term, Arity) -> boolean() when
2181      Term :: term(),
2182      Arity :: arity().
2183is_function(_Term, _Arity) ->
2184    erlang:nif_error(undefined).
2185
2186%% Shadowed by erl_bif_types: erlang:is_integer/1
2187-spec is_integer(Term) -> boolean() when
2188      Term :: term().
2189is_integer(_Term) ->
2190    erlang:nif_error(undefined).
2191
2192%% Shadowed by erl_bif_types: erlang:is_list/1
2193-spec is_list(Term) -> boolean() when
2194      Term :: term().
2195is_list(_Term) ->
2196    erlang:nif_error(undefined).
2197
2198%% Shadowed by erl_bif_types: erlang:is_number/1
2199-spec is_number(Term) -> boolean() when
2200      Term :: term().
2201is_number(_Term) ->
2202    erlang:nif_error(undefined).
2203
2204%% Shadowed by erl_bif_types: erlang:is_pid/1
2205-spec is_pid(Term) -> boolean() when
2206      Term :: term().
2207is_pid(_Term) ->
2208    erlang:nif_error(undefined).
2209
2210%% Shadowed by erl_bif_types: erlang:is_map/1
2211-spec is_map(Term) -> boolean() when
2212      Term :: term().
2213is_map(_Term) ->
2214    erlang:nif_error(undefined).
2215
2216%% Shadowed by erl_bif_types: erlang:is_port/1
2217-spec is_port(Term) -> boolean() when
2218      Term :: term().
2219is_port(_Term) ->
2220    erlang:nif_error(undefined).
2221
2222%% Shadowed by erl_bif_types: erlang:is_record/2
2223-spec is_record(Term,RecordTag) -> boolean() when
2224      Term :: term(),
2225      RecordTag :: atom().
2226is_record(_Term,_RecordTag) ->
2227    erlang:nif_error(undefined).
2228
2229%% Shadowed by erl_bif_types: erlang:is_record/3
2230-spec is_record(Term,RecordTag,Size) -> boolean() when
2231      Term :: term(),
2232      RecordTag :: atom(),
2233      Size :: non_neg_integer().
2234is_record(_Term,_RecordTag,_Size) ->
2235    erlang:nif_error(undefined).
2236
2237%% Shadowed by erl_bif_types: erlang:is_reference/1
2238-spec is_reference(Term) -> boolean() when
2239      Term :: term().
2240is_reference(_Term) ->
2241    erlang:nif_error(undefined).
2242
2243%% Shadowed by erl_bif_types: erlang:is_tuple/1
2244-spec is_tuple(Term) -> boolean() when
2245      Term :: term().
2246is_tuple(_Term) ->
2247    erlang:nif_error(undefined).
2248
2249-spec load_module(Module, Binary) -> {module, Module} | {error, Reason} when
2250      Module :: module(),
2251      Binary :: binary(),
2252      Reason :: badfile | not_purged | on_load.
2253load_module(Mod, Code) ->
2254    try
2255        case erlang:prepare_loading(Mod, Code) of
2256            {error,_}=Error ->
2257                Error;
2258            Prep when erlang:is_reference(Prep) ->
2259                case erlang:finish_loading([Prep]) of
2260                    ok ->
2261                        {module,Mod};
2262                    {Error,[Mod]} ->
2263                        {error,Error}
2264                end
2265        end
2266    catch
2267        error:Reason -> error_with_info(Reason, [Mod, Code])
2268    end.
2269
2270-spec erlang:load_nif(Path, LoadInfo) ->  ok | Error when
2271      Path :: string(),
2272      LoadInfo :: term(),
2273      Error :: {error, {Reason, Text :: string()}},
2274      Reason :: load_failed | bad_lib | load | reload | upgrade | old_code.
2275load_nif(_Path, _LoadInfo) ->
2276    erlang:nif_error(undefined).
2277
2278-spec erlang:localtime_to_universaltime(Localtime, IsDst) -> Universaltime when
2279      Localtime :: calendar:datetime(),
2280      Universaltime :: calendar:datetime(),
2281      IsDst :: true | false | undefined.
2282localtime_to_universaltime(_Localtime, _IsDst) ->
2283    erlang:nif_error(undefined).
2284
2285%% CHECK! Why the strange very thorough specification of the error
2286%% condition with disallowed arity in erl_bif_types?
2287%% Not documented
2288%% Shadowed by erl_bif_types: erlang:make_fun/3
2289-spec erlang:make_fun(Module, Function, Arity) -> function() when
2290      Module :: atom(),
2291      Function :: atom(),
2292      Arity :: arity().
2293make_fun(_Module,_Function, _Arity) ->
2294    erlang:nif_error(undefined).
2295
2296%% Shadowed by erl_bif_types: erlang:make_tuple/2
2297-spec erlang:make_tuple(Arity, InitialValue) -> tuple() when
2298      Arity :: arity(),
2299      InitialValue :: term().
2300make_tuple(_Arity,_InitialValue) ->
2301    erlang:nif_error(undefined).
2302
2303%% Shadowed by erl_bif_types: erlang:make_tuple/3
2304-spec erlang:make_tuple(Arity, DefaultValue, InitList) -> tuple() when
2305      Arity :: arity(),
2306      DefaultValue :: term(),
2307      InitList :: [{Position :: pos_integer(), term()}].
2308make_tuple(_Arity,_DefaultValue,_InitList) ->
2309    erlang:nif_error(undefined).
2310
2311-spec nodes(Arg) -> Nodes when
2312      Arg :: NodeType | [NodeType],
2313      NodeType :: visible | hidden | connected | this | known,
2314      Nodes :: [node()].
2315nodes(_Arg) ->
2316    erlang:nif_error(undefined).
2317
2318-spec open_port(PortName, PortSettings) -> port() when
2319      PortName :: {spawn, Command :: string() | binary()} |
2320                  {spawn_driver, Command :: string() | binary()} |
2321                  {spawn_executable, FileName :: file:name_all() } |
2322                  {fd, In :: non_neg_integer(), Out :: non_neg_integer()},
2323      PortSettings :: [Opt],
2324      Opt :: {packet, N :: 1 | 2 | 4}
2325           | stream
2326           | {line, L :: non_neg_integer()}
2327           | {cd, Dir :: string() | binary()}
2328           | {env, Env :: [{Name :: os:env_var_name(), Val :: os:env_var_value() | false}]}
2329           | {args, [string() | binary()]}
2330           | {arg0, string() | binary()}
2331           | exit_status
2332           | use_stdio
2333           | nouse_stdio
2334           | stderr_to_stdout
2335           | in
2336           | out
2337           | binary
2338           | eof
2339	   | {parallelism, Boolean :: boolean()}
2340	   | hide
2341           | {busy_limits_port, {non_neg_integer(), non_neg_integer()} | disabled}
2342           | {busy_limits_msgq, {non_neg_integer(), non_neg_integer()} | disabled}.
2343open_port(PortName, PortSettings) ->
2344    case case erts_internal:open_port(PortName, PortSettings) of
2345	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
2346	     Res -> Res
2347	 end of
2348	Port when erlang:is_port(Port) -> Port;
2349        badopt -> badarg_with_cause([PortName, PortSettings], badopt);
2350	Error -> error_with_info(Error, [PortName, PortSettings])
2351    end.
2352
2353-type priority_level() ::
2354      low | normal | high | max.
2355
2356-type message_queue_data() ::
2357	off_heap | on_heap.
2358
2359-spec process_flag(trap_exit, Boolean) -> OldBoolean when
2360      Boolean :: boolean(),
2361      OldBoolean :: boolean();
2362                  (error_handler, Module) -> OldModule when
2363      Module :: atom(),
2364      OldModule :: atom();
2365                  (fullsweep_after, FullsweepAfter) -> OldFullsweepAfter when
2366      FullsweepAfter :: non_neg_integer(),
2367      OldFullsweepAfter :: non_neg_integer();
2368                  (min_heap_size, MinHeapSize) -> OldMinHeapSize when
2369      MinHeapSize :: non_neg_integer(),
2370      OldMinHeapSize :: non_neg_integer();
2371                  (min_bin_vheap_size, MinBinVHeapSize) -> OldMinBinVHeapSize when
2372      MinBinVHeapSize :: non_neg_integer(),
2373      OldMinBinVHeapSize :: non_neg_integer();
2374                  (max_heap_size, MaxHeapSize) -> OldMaxHeapSize when
2375      MaxHeapSize :: max_heap_size(),
2376      OldMaxHeapSize :: max_heap_size();
2377                  (message_queue_data, MQD) -> OldMQD when
2378      MQD :: message_queue_data(),
2379      OldMQD :: message_queue_data();
2380                  (priority, Level) -> OldLevel when
2381      Level :: priority_level(),
2382      OldLevel :: priority_level();
2383                  (save_calls, N) -> OldN when
2384      N :: 0..10000,
2385      OldN :: 0..10000;
2386                  (sensitive, Boolean) -> OldBoolean when
2387      Boolean :: boolean(),
2388      OldBoolean :: boolean();
2389                  %% Deliberately not documented.
2390                  ({monitor_nodes, term()}, term()) -> term();
2391                  (monitor_nodes, term()) -> term().
2392
2393process_flag(_Flag, _Value) ->
2394    erlang:nif_error(undefined).
2395
2396-type process_info_item() ::
2397      backtrace |
2398      binary |
2399      catchlevel |
2400      current_function |
2401      current_location |
2402      current_stacktrace |
2403      dictionary |
2404      error_handler |
2405      garbage_collection |
2406      garbage_collection_info |
2407      group_leader |
2408      heap_size |
2409      initial_call |
2410      links |
2411      last_calls |
2412      memory |
2413      message_queue_len |
2414      messages |
2415      min_heap_size |
2416      min_bin_vheap_size |
2417      monitored_by |
2418      monitors |
2419      message_queue_data |
2420      priority |
2421      reductions |
2422      registered_name |
2423      sequential_trace_token |
2424      stack_size |
2425      status |
2426      suspending |
2427      total_heap_size |
2428      trace |
2429      trap_exit.
2430
2431-type process_info_result_item() ::
2432      {backtrace, Bin :: binary()} |
2433      {binary, BinInfo :: [{non_neg_integer(),
2434                            non_neg_integer(),
2435                            non_neg_integer()}]} |
2436      {catchlevel, CatchLevel :: non_neg_integer()} |
2437      {current_function,
2438       {Module :: module(), Function :: atom(), Arity :: arity()} | undefined} |
2439      {current_location,
2440       {Module :: module(), Function :: atom(), Arity :: arity(),
2441        Location :: [{file, Filename :: string()} | % not a stack_item()!
2442                     {line, Line :: pos_integer()}]}} |
2443      {current_stacktrace, Stack :: [stack_item()]} |
2444      {dictionary, Dictionary :: [{Key :: term(), Value :: term()}]} |
2445      {error_handler, Module :: module()} |
2446      {garbage_collection, GCInfo :: [{atom(),non_neg_integer()}]} |
2447      {garbage_collection_info, GCInfo :: [{atom(),non_neg_integer()}]} |
2448      {group_leader, GroupLeader :: pid()} |
2449      {heap_size, Size :: non_neg_integer()} |
2450      {initial_call, mfa()} |
2451      {links, PidsAndPorts :: [pid() | port()]} |
2452      {last_calls, false | (Calls :: [mfa()])} |
2453      {memory, Size :: non_neg_integer()} |
2454      {message_queue_len, MessageQueueLen :: non_neg_integer()} |
2455      {messages, MessageQueue :: [term()]} |
2456      {min_heap_size, MinHeapSize :: non_neg_integer()} |
2457      {min_bin_vheap_size, MinBinVHeapSize :: non_neg_integer()} |
2458      {max_heap_size, MaxHeapSize :: max_heap_size()} |
2459      {monitored_by, MonitoredBy :: [pid() | port() | nif_resource()]} |
2460      {monitors,
2461       Monitors :: [{process | port, Pid :: pid() | port() |
2462                                     {RegName :: atom(), Node :: node()}}]} |
2463      {message_queue_data, MQD :: message_queue_data()} |
2464      {priority, Level :: priority_level()} |
2465      {reductions, Number :: non_neg_integer()} |
2466      {registered_name, [] | (Atom :: atom())} |
2467      {sequential_trace_token, [] | (SequentialTraceToken :: term())} |
2468      {stack_size, Size :: non_neg_integer()} |
2469      {status, Status :: exiting | garbage_collecting | waiting | running | runnable | suspended} |
2470      {suspending,
2471       SuspendeeList :: [{Suspendee :: pid(),
2472                          ActiveSuspendCount :: non_neg_integer(),
2473                          OutstandingSuspendCount ::non_neg_integer()}]} |
2474      {total_heap_size, Size :: non_neg_integer()} |
2475      {trace, InternalTraceFlags :: non_neg_integer()} |
2476      {trap_exit, Boolean :: boolean()}.
2477
2478-type stack_item() ::
2479        {Module :: module(),
2480         Function :: atom(),
2481         Arity :: arity() | (Args :: [term()]),
2482         Location :: [{file, Filename :: string()} |
2483                      {line, Line :: pos_integer()}]}.
2484
2485-spec process_info(Pid, Item) ->
2486                          InfoTuple | [] | undefined when
2487      Pid :: pid(),
2488      Item :: process_info_item(),
2489      InfoTuple :: process_info_result_item();
2490                  (Pid, ItemList) -> InfoTupleList | [] | undefined when
2491      Pid :: pid(),
2492      ItemList :: [Item],
2493      Item :: process_info_item(),
2494      InfoTupleList :: [InfoTuple],
2495      InfoTuple :: process_info_result_item().
2496process_info(_Pid,_ItemSpec) ->
2497    erlang:nif_error(undefined).
2498
2499-spec erlang:send(Dest, Msg) -> Msg when
2500      Dest :: dst(),
2501      Msg :: term().
2502send(_Dest,_Msg) ->
2503    erlang:nif_error(undefined).
2504
2505-spec erlang:send(Dest, Msg, Options) -> Res when
2506      Dest :: dst(),
2507      Msg :: term(),
2508      Options :: [nosuspend | noconnect],
2509      Res :: ok | nosuspend | noconnect.
2510send(_Dest,_Msg,_Options) ->
2511    erlang:nif_error(undefined).
2512
2513%% Not documented
2514-spec erlang:seq_trace_info(send) -> {send, boolean()};
2515                    ('receive') -> {'receive', boolean()};
2516                    (print) -> {print, boolean()};
2517                    (timestamp) -> {timestamp, boolean()};
2518                    (monotonic_timestamp) -> {timestamp, boolean()};
2519                    (strict_monotonic_timestamp) -> {strict_monotonic_timestamp, boolean()};
2520                    (label) -> [] | {label, term()};
2521                    (serial) -> [] | {serial, {non_neg_integer(), non_neg_integer()}}.
2522seq_trace_info(_What) ->
2523    erlang:nif_error(undefined).
2524
2525%% Shadowed by erl_bif_types: erlang:setelement/3
2526-spec setelement(Index, Tuple1, Value) -> Tuple2 when
2527      Index :: pos_integer(),
2528      Tuple1 :: tuple(),
2529      Tuple2 :: tuple(),
2530      Value :: term().
2531setelement(_Index, _Tuple1, _Value) ->
2532   erlang:nif_error(undefined).
2533
2534-spec statistics(active_tasks) -> [ActiveTasks] when
2535      ActiveTasks :: non_neg_integer();
2536		(active_tasks_all) -> [ActiveTasks] when
2537      ActiveTasks :: non_neg_integer();
2538		(context_switches) -> {ContextSwitches,0} when
2539      ContextSwitches :: non_neg_integer();
2540                (exact_reductions) -> {Total_Exact_Reductions,
2541                                       Exact_Reductions_Since_Last_Call} when
2542      Total_Exact_Reductions :: non_neg_integer(),
2543      Exact_Reductions_Since_Last_Call :: non_neg_integer();
2544                (garbage_collection) -> {Number_of_GCs, Words_Reclaimed, 0} when
2545      Number_of_GCs :: non_neg_integer(),
2546      Words_Reclaimed :: non_neg_integer();
2547                (io) -> {{input, Input}, {output, Output}} when
2548      Input :: non_neg_integer(),
2549      Output :: non_neg_integer();
2550                (microstate_accounting) -> [MSAcc_Thread] | undefined when
2551      MSAcc_Thread :: #{ type := MSAcc_Thread_Type,
2552                        id := MSAcc_Thread_Id,
2553                        counters := MSAcc_Counters},
2554      MSAcc_Thread_Type :: async | aux | dirty_io_scheduler
2555                         | dirty_cpu_scheduler | poll | scheduler,
2556      MSAcc_Thread_Id :: non_neg_integer(),
2557      MSAcc_Counters :: #{ MSAcc_Thread_State => non_neg_integer() },
2558      MSAcc_Thread_State :: alloc | aux | bif | busy_wait | check_io |
2559                            emulator | ets | gc | gc_fullsweep | nif |
2560                            other | port | send | sleep | timers;
2561                (reductions) -> {Total_Reductions,
2562                                 Reductions_Since_Last_Call} when
2563      Total_Reductions :: non_neg_integer(),
2564      Reductions_Since_Last_Call :: non_neg_integer();
2565                (run_queue) -> non_neg_integer();
2566                (run_queue_lengths) -> [RunQueueLength] when
2567      RunQueueLength :: non_neg_integer();
2568                (run_queue_lengths_all) -> [RunQueueLength] when
2569      RunQueueLength :: non_neg_integer();
2570                (runtime) -> {Total_Run_Time, Time_Since_Last_Call} when
2571      Total_Run_Time :: non_neg_integer(),
2572      Time_Since_Last_Call :: non_neg_integer();
2573                (scheduler_wall_time) -> [{SchedulerId, ActiveTime, TotalTime}] | undefined when
2574      SchedulerId :: pos_integer(),
2575      ActiveTime  :: non_neg_integer(),
2576      TotalTime   :: non_neg_integer();
2577                (scheduler_wall_time_all) -> [{SchedulerId, ActiveTime, TotalTime}] | undefined when
2578      SchedulerId :: pos_integer(),
2579      ActiveTime  :: non_neg_integer(),
2580      TotalTime   :: non_neg_integer();
2581		(total_active_tasks) -> ActiveTasks when
2582      ActiveTasks :: non_neg_integer();
2583		(total_active_tasks_all) -> ActiveTasks when
2584      ActiveTasks :: non_neg_integer();
2585                (total_run_queue_lengths) -> TotalRunQueueLengths when
2586      TotalRunQueueLengths :: non_neg_integer();
2587                (total_run_queue_lengths_all) -> TotalRunQueueLengths when
2588      TotalRunQueueLengths :: non_neg_integer();
2589                (wall_clock) -> {Total_Wallclock_Time,
2590                                 Wallclock_Time_Since_Last_Call} when
2591      Total_Wallclock_Time :: non_neg_integer(),
2592      Wallclock_Time_Since_Last_Call :: non_neg_integer().
2593statistics(_Item) ->
2594    erlang:nif_error(undefined).
2595
2596%% Not documented
2597%% Shadowed by erl_bif_types: erlang:subtract/2
2598-spec erlang:subtract([term()], [term()]) -> [term()].
2599subtract(_,_) ->
2600    erlang:nif_error(undefined).
2601
2602-type scheduler_bind_type() ::
2603      'no_node_processor_spread' |
2604      'no_node_thread_spread' |
2605      'no_spread' |
2606      'processor_spread' |
2607      'spread' |
2608      'thread_spread' |
2609      'thread_no_node_processor_spread' |
2610      'unbound'.
2611
2612-spec erlang:system_flag(backtrace_depth, Depth) -> OldDepth when
2613      Depth :: non_neg_integer(),
2614      OldDepth :: non_neg_integer();
2615                        (cpu_topology, CpuTopology) -> OldCpuTopology when
2616      CpuTopology :: cpu_topology(),
2617      OldCpuTopology :: cpu_topology();
2618                        (dirty_cpu_schedulers_online, DirtyCPUSchedulersOnline) ->
2619                                OldDirtyCPUSchedulersOnline when
2620      DirtyCPUSchedulersOnline :: pos_integer(),
2621      OldDirtyCPUSchedulersOnline :: pos_integer();
2622                        (erts_alloc, {Alloc, F, V}) -> ok | notsup when
2623      Alloc :: atom(),
2624      F :: atom(),
2625      V :: integer();
2626                        (fullsweep_after, Number) -> OldNumber when
2627      Number :: non_neg_integer(),
2628      OldNumber :: non_neg_integer();
2629                        (microstate_accounting, Action) -> OldState when
2630      Action :: true | false | reset,
2631      OldState :: true | false;
2632                        (min_heap_size, MinHeapSize) -> OldMinHeapSize when
2633      MinHeapSize :: non_neg_integer(),
2634      OldMinHeapSize :: non_neg_integer();
2635                        (min_bin_vheap_size, MinBinVHeapSize) ->
2636                                OldMinBinVHeapSize when
2637      MinBinVHeapSize :: non_neg_integer(),
2638      OldMinBinVHeapSize :: non_neg_integer();
2639                        (max_heap_size, MaxHeapSize) -> OldMaxHeapSize when
2640      MaxHeapSize :: max_heap_size(),
2641      OldMaxHeapSize :: max_heap_size();
2642                        (multi_scheduling, BlockState) -> OldBlockState when
2643      BlockState :: block | unblock | block_normal | unblock_normal,
2644      OldBlockState :: blocked | disabled | enabled;
2645                        (scheduler_bind_type, How) -> OldBindType when
2646      How :: scheduler_bind_type() | default_bind,
2647      OldBindType :: scheduler_bind_type();
2648                        (scheduler_wall_time, Boolean) ->  OldBoolean when
2649      Boolean :: boolean(),
2650      OldBoolean :: boolean();
2651                        (schedulers_online, SchedulersOnline) ->
2652                                OldSchedulersOnline when
2653      SchedulersOnline :: pos_integer(),
2654      OldSchedulersOnline :: pos_integer();
2655                        (system_logger, Logger) -> PrevLogger when
2656      Logger :: logger | undefined | pid(),
2657      PrevLogger :: logger | undefined | pid();
2658                        (trace_control_word, TCW) -> OldTCW when
2659      TCW :: non_neg_integer(),
2660      OldTCW :: non_neg_integer();
2661			(time_offset, finalize) -> OldState when
2662      OldState :: preliminary | final | volatile;
2663                        %% These are deliberately not documented
2664			(internal_cpu_topology, term()) -> term();
2665                        (sequential_tracer, Tracer) -> PrevTracer | false when
2666      Tracer :: pid() | port() | {module(), term()} | false,
2667      PrevTracer :: pid() | port() | {module(), term()} | false;
2668                        (reset_seq_trace,true) -> true.
2669
2670system_flag(_Flag, _Value) ->
2671    erlang:nif_error(undefined).
2672
2673-spec term_to_binary(Term) -> ext_binary() when
2674      Term :: term().
2675term_to_binary(_Term) ->
2676    erlang:nif_error(undefined).
2677
2678-spec term_to_binary(Term, Options) -> ext_binary() when
2679      Term :: term(),
2680      Options :: [compressed |
2681         {compressed, Level :: 0..9} |
2682         deterministic |
2683         {minor_version, Version :: 0..2} ].
2684term_to_binary(_Term, _Options) ->
2685    erlang:nif_error(undefined).
2686
2687-spec term_to_iovec(Term) -> ext_iovec() when
2688      Term :: term().
2689term_to_iovec(_Term) ->
2690    erlang:nif_error(undefined).
2691
2692-spec term_to_iovec(Term, Options) -> ext_iovec() when
2693      Term :: term(),
2694      Options :: [compressed |
2695         {compressed, Level :: 0..9} |
2696         deterministic |
2697         {minor_version, Version :: 0..2} ].
2698term_to_iovec(_Term, _Options) ->
2699    erlang:nif_error(undefined).
2700
2701%% Shadowed by erl_bif_types: erlang:tl/1
2702-spec tl(List) -> term() when
2703      List :: nonempty_maybe_improper_list().
2704tl(_List) ->
2705    erlang:nif_error(undefined).
2706
2707-type match_variable() :: atom(). % Approximation of '$1' | '$2' | ...
2708-type trace_pattern_mfa() ::
2709      {atom(),atom(),arity() | '_'} | on_load.
2710-type trace_match_spec() ::
2711      [{[term()] | '_' | match_variable() ,[term()],[term()]}].
2712
2713-spec erlang:trace_pattern(MFA, MatchSpec) -> non_neg_integer() when
2714      MFA :: trace_pattern_mfa() | send | 'receive',
2715      MatchSpec :: (MatchSpecList :: trace_match_spec())
2716                 | boolean()
2717                 | restart
2718                 | pause.
2719trace_pattern(MFA, MatchSpec) ->
2720    try erts_internal:trace_pattern(MFA, MatchSpec, []) of
2721        Res -> Res
2722    catch error:R:Stk ->
2723            error_with_inherited_info(R, [MFA, MatchSpec], Stk)
2724    end.
2725
2726-type trace_pattern_flag() ::
2727      global | local |
2728      meta | {meta, Pid :: pid()} |
2729      {meta, TracerModule :: module(), TracerState :: term()} |
2730      call_count |
2731      call_time.
2732
2733-spec erlang:trace_pattern(send, MatchSpec, []) -> non_neg_integer() when
2734      MatchSpec :: (MatchSpecList :: trace_match_spec())
2735                 | boolean();
2736			  ('receive', MatchSpec, []) -> non_neg_integer() when
2737      MatchSpec :: (MatchSpecList :: trace_match_spec())
2738                 | boolean();
2739			  (MFA, MatchSpec, FlagList) -> non_neg_integer() when
2740      MFA :: trace_pattern_mfa(),
2741      MatchSpec :: (MatchSpecList :: trace_match_spec())
2742                 | boolean()
2743                 | restart
2744                 | pause,
2745      FlagList :: [ trace_pattern_flag() ].
2746trace_pattern(MFA, MatchSpec, FlagList) ->
2747    ensure_tracer_module_loaded(meta, FlagList),
2748    try erts_internal:trace_pattern(MFA, MatchSpec, FlagList) of
2749        Res -> Res
2750    catch error:R:Stk ->
2751            error_with_inherited_info(R, [MFA, MatchSpec, FlagList], Stk)
2752    end.
2753
2754%% Shadowed by erl_bif_types: erlang:tuple_to_list/1
2755-spec tuple_to_list(Tuple) -> [term()] when
2756      Tuple :: tuple().
2757tuple_to_list(_Tuple) ->
2758    erlang:nif_error(undefined).
2759
2760-type cpu_topology() ::
2761        [LevelEntry :: level_entry()] | undefined.
2762-type level_entry() ::
2763        {LevelTag :: level_tag(), SubLevel :: sub_level()}
2764      | {LevelTag :: level_tag(),
2765         InfoList :: info_list(),
2766         SubLevel :: sub_level()}.
2767-type level_tag() :: core | node | processor | thread.
2768-type sub_level() :: [LevelEntry :: level_entry()]
2769                   | (LogicalCpuId :: {logical, non_neg_integer()}).
2770-type info_list() :: [].
2771
2772%% Note: changing the ordering number of a clause will change the docs!
2773%% Shadowed by erl_bif_types: erlang:system_info/1
2774-spec erlang:system_info
2775         (allocated_areas) -> [ tuple() ];
2776         (allocator) ->
2777                 {Allocator, Version, Features, Settings} when
2778      Allocator :: undefined | glibc,
2779      Version :: [non_neg_integer()],
2780      Features :: [atom()],
2781      Settings :: [{Subsystem :: atom(),
2782                    [{Parameter :: atom(),
2783                      Value :: term()}]}];
2784         ({allocator, Alloc}) -> [_] when %% More or less anything
2785      Alloc :: atom();
2786         (alloc_util_allocators) -> [Alloc] when
2787      Alloc :: atom();
2788         ({allocator_sizes, Alloc}) -> [_] when %% More or less anything
2789      Alloc :: atom();
2790         (atom_count) -> pos_integer();
2791         (atom_limit) -> pos_integer();
2792         (build_type) -> opt | debug |
2793                         gcov | valgrind | gprof | lcnt | frmptr;
2794         (c_compiler_used) -> {atom(), term()};
2795         (check_io) -> [_];
2796         (compat_rel) -> integer();
2797         (cpu_topology) ->  CpuTopology when
2798      CpuTopology :: cpu_topology();
2799         ({cpu_topology, defined | detected | used}) -> CpuTopology when
2800      CpuTopology :: cpu_topology();
2801         (creation) -> integer();
2802         (debug_compiled) -> boolean();
2803         (delayed_node_table_gc) -> infinity | non_neg_integer();
2804         (dirty_cpu_schedulers) -> non_neg_integer();
2805         (dirty_cpu_schedulers_online) -> non_neg_integer();
2806         (dirty_io_schedulers) -> non_neg_integer();
2807         (dist) -> binary();
2808         (dist_buf_busy_limit) -> non_neg_integer();
2809         (dist_ctrl) -> {Node :: node(),
2810                         ControllingEntity :: port() | pid()};
2811         (driver_version) -> string();
2812         (dynamic_trace) -> none | dtrace | systemtap;
2813         (dynamic_trace_probes) -> boolean();
2814         (eager_check_io) -> boolean();
2815         (emu_flavor) -> emu | jit;
2816         (emu_type) -> opt | debug | gcov | valgrind | gprof | lcnt | frmptr;
2817         (end_time) -> non_neg_integer();
2818         (ets_count) -> pos_integer();
2819         (ets_limit) -> pos_integer();
2820         (fullsweep_after) -> {fullsweep_after, non_neg_integer()};
2821         (garbage_collection) -> [{atom(), integer()}];
2822         (heap_sizes) -> [non_neg_integer()];
2823         (heap_type) -> private;
2824         (info) -> binary();
2825         (kernel_poll) -> boolean();
2826         (loaded) -> binary();
2827         (logical_processors |
2828          logical_processors_available |
2829          logical_processors_online) -> unknown | pos_integer();
2830         (machine) -> string();
2831         (max_heap_size) -> {max_heap_size, MaxHeapSize :: max_heap_size()};
2832         (message_queue_data) -> message_queue_data();
2833         (min_heap_size) -> {min_heap_size, MinHeapSize :: pos_integer()};
2834         (min_bin_vheap_size) -> {min_bin_vheap_size,
2835                                  MinBinVHeapSize :: pos_integer()};
2836         (modified_timing_level) -> integer() | undefined;
2837         (multi_scheduling) -> disabled | blocked | blocked_normal | enabled;
2838         (multi_scheduling_blockers) -> [Pid :: pid()];
2839         (nif_version) -> string();
2840         (normal_multi_scheduling_blockers) -> [Pid :: pid()];
2841         (otp_release) -> string();
2842         (os_monotonic_time_source) -> [{atom(),term()}];
2843         (os_system_time_source) -> [{atom(),term()}];
2844         (port_parallelism) -> boolean();
2845         (port_count) -> non_neg_integer();
2846         (port_limit) -> pos_integer();
2847         (process_count) -> pos_integer();
2848         (process_limit) -> pos_integer();
2849         (procs) -> binary();
2850         (scheduler_bind_type) -> spread |
2851                                  processor_spread |
2852                                  thread_spread |
2853                                  thread_no_node_processor_spread |
2854                                  no_node_processor_spread |
2855                                  no_node_thread_spread |
2856                                  no_spread |
2857                                  unbound;
2858         (scheduler_bindings) ->  tuple();
2859         (scheduler_id) -> SchedulerId :: pos_integer();
2860         (schedulers | schedulers_online) -> pos_integer();
2861         (smp_support) -> boolean();
2862         (start_time) -> integer();
2863         (system_architecture) -> string();
2864         (system_logger) -> logger | undefined | pid();
2865         (system_version) -> string();
2866         (threads) -> boolean();
2867         (thread_pool_size) -> non_neg_integer();
2868         (time_correction) -> true | false;
2869         (time_offset) -> preliminary | final | volatile;
2870         (time_warp_mode) -> no_time_warp | single_time_warp | multi_time_warp;
2871         (tolerant_timeofday) -> enabled | disabled;
2872         (trace_control_word) -> non_neg_integer();
2873         (update_cpu_info) -> changed | unchanged;
2874         (version) -> string();
2875         (wordsize | {wordsize, internal} | {wordsize, external}) -> 4 | 8;
2876         (overview) -> boolean();
2877         %% Deliberately left undocumented
2878         (sequential_tracer) -> {sequential_tracer, pid() | port() | {module(),term()} | false}.
2879system_info(_Item) ->
2880    erlang:nif_error(undefined).
2881
2882-spec erlang:universaltime_to_localtime(Universaltime) ->  Localtime when
2883      Localtime :: calendar:datetime(),
2884      Universaltime :: calendar:datetime().
2885universaltime_to_localtime(_Universaltime) ->
2886    erlang:nif_error(undefined).
2887
2888%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2889%%% End of  native code BIFs
2890%%% Actual Erlang implementation of some BIF's follow
2891%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2892
2893%%--------------------------------------------------------------------------
2894
2895%% Shadowed by erl_bif_types: erlang:apply/2
2896-spec apply(Fun, Args) -> term() when
2897      Fun :: function(),
2898      Args :: [term()].
2899apply(Fun, Args) ->
2900    erlang:apply(Fun, Args).
2901
2902%% Shadowed by erl_bif_types: erlang:apply/3
2903-spec apply(Module, Function, Args) -> term() when
2904      Module :: module(),
2905      Function :: atom(),
2906      Args :: [term()].
2907apply(Mod, Name, Args) ->
2908    erlang:apply(Mod, Name, Args).
2909
2910%% Spawns with a fun
2911
2912-spec spawn(Fun) -> pid() when
2913      Fun :: function().
2914spawn(F) when erlang:is_function(F) ->
2915    erlang:spawn(erlang, apply, [F, []]);
2916spawn({M,F}=MF) when erlang:is_atom(M), erlang:is_atom(F) ->
2917    erlang:spawn(erlang, apply, [MF, []]);
2918spawn(F) ->
2919    badarg_with_info([F]).
2920
2921-spec spawn(Node, Fun) -> pid() when
2922      Node :: node(),
2923      Fun :: function().
2924spawn(N, F) when N =:= erlang:node() ->
2925    erlang:spawn(F);
2926spawn(N, F) when erlang:is_function(F) ->
2927    erlang:spawn(N, erlang, apply, [F, []]);
2928spawn(N, {M,F}=MF) when erlang:is_atom(M), erlang:is_atom(F) ->
2929    erlang:spawn(N, erlang, apply, [MF, []]);
2930spawn(N, F) ->
2931    badarg_with_info([N, F]).
2932
2933-spec spawn_link(Fun) -> pid() when
2934      Fun :: function().
2935spawn_link(F) when erlang:is_function(F) ->
2936    erlang:spawn_link(erlang, apply, [F, []]);
2937spawn_link({M,F}=MF) when erlang:is_atom(M), erlang:is_atom(F) ->
2938    erlang:spawn_link(erlang, apply, [MF, []]);
2939spawn_link(F) ->
2940    badarg_with_info([F]).
2941
2942-spec spawn_link(Node, Fun) -> pid() when
2943      Node :: node(),
2944      Fun :: function().
2945spawn_link(N, F) when N =:= erlang:node() ->
2946    spawn_link(F);
2947spawn_link(N, F) when erlang:is_function(F) ->
2948    spawn_link(N, erlang, apply, [F, []]);
2949spawn_link(N, {M,F}=MF) when erlang:is_atom(M), erlang:is_atom(F) ->
2950    spawn_link(N, erlang, apply, [MF, []]);
2951spawn_link(N, F) ->
2952    badarg_with_info([N, F]).
2953
2954%% Spawn and atomically set up a monitor.
2955
2956-spec spawn_monitor(Fun) -> {pid(), reference()} when
2957      Fun :: function().
2958spawn_monitor(F) when erlang:is_function(F, 0) ->
2959    erlang:spawn_opt(erlang,apply,[F,[]],[monitor]);
2960spawn_monitor(F) ->
2961    badarg_with_info([F]).
2962
2963-spec spawn_monitor(Node, Fun) -> {pid(), reference()} when
2964      Node :: node(),
2965      Fun :: function().
2966
2967spawn_monitor(Node, F) when erlang:is_atom(Node), erlang:is_function(F, 0) ->
2968    try
2969        erlang:spawn_monitor(Node,erlang,apply,[F,[]])
2970    catch
2971        error:Err ->
2972            error_with_info(Err, [Node, F])
2973    end;
2974spawn_monitor(Node, F) ->
2975    badarg_with_info([Node, F]).
2976
2977-spec spawn_monitor(Module, Function, Args) -> {pid(), reference()} when
2978      Module :: module(),
2979      Function :: atom(),
2980      Args :: [term()].
2981spawn_monitor(M, F, A) when erlang:is_atom(M),
2982                            erlang:is_atom(F),
2983                            erlang:is_list(A) ->
2984    erlang:spawn_opt(M,F,A,[monitor]);
2985spawn_monitor(M, F, A) ->
2986    badarg_with_info([M,F,A]).
2987
2988
2989-type max_heap_size() ::
2990        Size :: non_neg_integer()
2991        %% TODO change size => to := when -type maps support is finalized
2992      | #{ size => non_neg_integer(),
2993           kill => boolean(),
2994           error_logger => boolean() }.
2995
2996-type spawn_opt_option() ::
2997	link
2998      | monitor
2999      | {monitor, MonitorOpts :: [monitor_option()]}
3000      | {priority, Level :: priority_level()}
3001      | {fullsweep_after, Number :: non_neg_integer()}
3002      | {min_heap_size, Size :: non_neg_integer()}
3003      | {min_bin_vheap_size, VSize :: non_neg_integer()}
3004      | {max_heap_size, Size :: max_heap_size()}
3005      | {message_queue_data, MQD :: message_queue_data()}.
3006
3007-spec spawn_opt(Fun, Options) -> pid() | {pid(), reference()} when
3008      Fun :: function(),
3009      Options :: [spawn_opt_option()].
3010spawn_opt(F, O) when erlang:is_function(F) ->
3011    try
3012        erlang:spawn_opt(erlang, apply, [F, []], O)
3013    catch
3014        error:Error:Stk ->
3015            error_with_inherited_info(Error, [F,O], Stk)
3016    end;
3017spawn_opt({M,F}=MF, O) when erlang:is_atom(M), erlang:is_atom(F) ->
3018    erlang:spawn_opt(erlang, apply, [MF, []], O);
3019spawn_opt(F, O) ->
3020    badarg_with_info([F, O]).
3021
3022-spec spawn_opt(Node, Fun, Options) -> pid() | {pid(), reference()} when
3023      Node :: node(),
3024      Fun :: function(),
3025      Options :: [monitor |
3026                  {monitor, [monitor_option()]} |
3027                  link |
3028                  OtherOption],
3029      OtherOption :: term().
3030spawn_opt(N, F, O) when N =:= erlang:node() ->
3031    try
3032        erlang:spawn_opt(F, O)
3033    catch
3034        error:Error:Stk ->
3035            error_with_inherited_info(Error, [N, F, O], Stk)
3036    end;
3037spawn_opt(N, F, O) when erlang:is_function(F, 0) ->
3038    try
3039        erlang:spawn_opt(N, erlang, apply, [F, []], O)
3040    catch
3041        error:Error:Stk -> error_with_inherited_info(Error, [N, F,O], Stk)
3042    end;
3043spawn_opt(N, {M,F}=MF, O) when erlang:is_atom(M), erlang:is_atom(F) ->
3044    erlang:spawn_opt(N, erlang, apply, [MF, []], O);
3045spawn_opt(N, F, O) ->
3046    badarg_with_info([N, F, O]).
3047
3048%% Spawns with MFA
3049
3050-spec spawn(Node, Module, Function, Args) -> pid() when
3051      Node :: node(),
3052      Module :: module(),
3053      Function :: atom(),
3054      Args :: [term()].
3055spawn(N,M,F,A) when N =:= erlang:node(),
3056                    erlang:is_atom(M),
3057                    erlang:is_atom(F),
3058                    erlang:is_list(A) ->
3059    erlang:spawn(M,F,A);
3060spawn(N,M,F,A) when erlang:is_atom(N),
3061                    erlang:is_atom(M),
3062                    erlang:is_atom(F) ->
3063    try
3064        erlang:spawn_opt(N, M, F, A, [])
3065    catch
3066        _:Reason ->
3067            error_with_info(Reason, [N, M, F, A])
3068    end;
3069spawn(N,M,F,A) ->
3070    badarg_with_info([N, M, F, A]).
3071
3072-spec spawn_link(Node, Module, Function, Args) -> pid() when
3073      Node :: node(),
3074      Module :: module(),
3075      Function :: atom(),
3076      Args :: [term()].
3077spawn_link(N,M,F,A) when N =:= erlang:node(),
3078                         erlang:is_atom(M),
3079                         erlang:is_atom(F),
3080                         erlang:is_list(A) ->
3081    erlang:spawn_link(M,F,A);
3082spawn_link(N,M,F,A) when erlang:is_atom(N),
3083                         erlang:is_atom(M),
3084                         erlang:is_atom(F) ->
3085    try
3086        erlang:spawn_opt(N, M, F, A, [link])
3087    catch
3088        _:Reason ->
3089            error_with_info(Reason, [N, M, F, A])
3090    end;
3091spawn_link(N,M,F,A) ->
3092    badarg_with_info([N, M, F, A]).
3093
3094-spec spawn_monitor(Node, Module, Function, Args) -> {pid(), reference()} when
3095      Node :: node(),
3096      Module :: module(),
3097      Function :: atom(),
3098      Args :: [term()].
3099spawn_monitor(N,M,F,A) when N =:= erlang:node(),
3100                            erlang:is_atom(M),
3101                            erlang:is_atom(F),
3102                            erlang:is_list(A) ->
3103    try
3104        erlang:spawn_monitor(M,F,A)
3105    catch
3106        error:Err ->
3107            error_with_info(Err, [N, M, F, A])
3108    end;
3109spawn_monitor(N,M,F,A) when erlang:is_atom(N),
3110                            erlang:is_atom(M),
3111                            erlang:is_atom(F) ->
3112    Ref = try
3113              erlang:spawn_request(N, M, F, A, [monitor])
3114          catch
3115              error:Err0 ->
3116                  error_with_info(Err0, [N, M, F, A])
3117          end,
3118    receive
3119        {spawn_reply, Ref, ok, Pid} when erlang:is_pid(Pid) ->
3120            {Pid, Ref};
3121        {spawn_reply, Ref, error, badopt} ->
3122            badarg_with_info([N, M, F, A]);
3123        {spawn_reply, Ref, error, noconnection} ->
3124            try
3125                erlang:spawn_opt(erts_internal,crasher,
3126                                 [N,M,F,A,[monitor],
3127                                  noconnection],
3128                                 [monitor])
3129            catch
3130                _:Err1 ->
3131                    error_with_info(Err1, [N, M, F, A])
3132            end;
3133        {spawn_reply, Ref, error, Err2} ->
3134            error_with_info(Err2, [N, M, F, A])
3135    end;
3136spawn_monitor(N,M,F,A) ->
3137    badarg_with_info([N, M, F, A]).
3138
3139-spec spawn_opt(Module, Function, Args, Options) ->
3140          Pid | {Pid, MonitorRef} when
3141      Module :: module(),
3142      Function :: atom(),
3143      Args :: [term()],
3144      Options :: [spawn_opt_option()],
3145      Pid :: pid(),
3146      MonitorRef :: reference().
3147spawn_opt(_Module, _Function, _Args, _Options) ->
3148   erlang:nif_error(undefined).
3149
3150
3151-spec spawn_opt(Node, Module, Function, Args, Options) ->
3152                       pid() | {pid(), reference()} when
3153      Node :: node(),
3154      Module :: module(),
3155      Function :: atom(),
3156      Args :: [term()],
3157      Options :: [monitor |
3158                  {monitor, [monitor_option()]} |
3159                  link |
3160                  OtherOption],
3161      OtherOption :: term().
3162
3163spawn_opt(N, M, F, A, O) when N =:= erlang:node(),
3164			      erlang:is_atom(M), erlang:is_atom(F),
3165                              erlang:is_list(A), erlang:is_list(O) ->
3166    try
3167        erlang:spawn_opt(M, F, A, O)
3168    catch
3169        error:Error:Stk ->
3170            error_with_inherited_info(Error, [N, M, F, A, O], Stk)
3171    end;
3172spawn_opt(N, M, F, A, O) when erlang:is_atom(N),
3173                              erlang:is_atom(M),
3174                              erlang:is_atom(F) ->
3175    {Ref, MonOpt} = case erts_internal:dist_spawn_request(N, {M, F, A}, O, spawn_opt) of
3176                        {R, MO} when erlang:is_reference(R) -> {R, MO};
3177                        badarg -> badarg_with_info([N, M, F, A, O])
3178                    end,
3179    receive
3180        {spawn_reply, Ref, ok, Pid} when erlang:is_pid(Pid) ->
3181            case MonOpt of
3182                true -> {Pid, Ref};
3183                false -> Pid
3184            end;
3185        {spawn_reply, Ref, error, badopt} ->
3186            badarg_with_cause([N, M, F, A, O], badopt);
3187        {spawn_reply, Ref, error, noconnection} ->
3188            try
3189                erlang:spawn_opt(erts_internal,crasher,
3190                                 [N,M,F,A,O,noconnection], O)
3191            catch
3192                _:Err1 ->
3193                    error_with_info(Err1, [N, M, F, A, O])
3194            end;
3195        {spawn_reply, Ref, error, notsup} ->
3196            case old_remote_spawn_opt(N, M, F, A, O) of
3197                Pid when erlang:is_pid(Pid) ->
3198                    Pid;
3199                Err2 ->
3200                    error_with_info(Err2, [N, M, F, A, O])
3201            end;
3202        {spawn_reply, Ref, error, Err3} ->
3203            error_with_info(Err3, [N, M, F, A, O])
3204    end;
3205spawn_opt(N,M,F,A,O) ->
3206    badarg_with_info([N,M,F,A,O]).
3207
3208old_remote_spawn_opt(N, M, F, A, O) ->
3209    case lists:member(monitor, O) of
3210	true ->
3211            badarg;
3212	_ ->
3213            {L,NO} = lists:foldl(fun (link, {_, NewOpts}) ->
3214                                         {link, NewOpts};
3215                                     (Opt, {LO, NewOpts}) ->
3216                                         {LO, [Opt|NewOpts]}
3217                                 end,
3218                                 {no_link,[]},
3219                                 O),
3220            case catch gen_server:call({net_kernel,N},
3221                                       {spawn_opt,M,F,A,NO,L,erlang:group_leader()},
3222                                       infinity) of
3223                Pid when erlang:is_pid(Pid) ->
3224                    Pid;
3225                Error ->
3226                    case remote_spawn_error(Error, {L, N, M, F, A, NO}) of
3227                        {fault, Fault} ->
3228                            Fault;
3229                        Pid ->
3230                            Pid
3231                    end
3232            end
3233    end.
3234
3235remote_spawn_error({'EXIT', {{nodedown,N}, _}}, {L, N, M, F, A, O}) ->
3236    {Opts, LL} = case L =:= link of
3237		     true ->
3238			 {[link|O], [link]};
3239		     false ->
3240			 {O, []}
3241		 end,
3242    erlang:spawn_opt(erts_internal,crasher,[N,M,F,A,Opts,noconnection], LL);
3243remote_spawn_error({'EXIT', {Reason, _}}, _) ->
3244    {fault, Reason};
3245remote_spawn_error({'EXIT', Reason}, _) ->
3246    {fault, Reason};
3247remote_spawn_error(Other, _) ->
3248    {fault, Other}.
3249
3250%%
3251%% spawn_request/1
3252%%
3253
3254-spec spawn_request(Fun) -> ReqId when
3255      Fun :: function(),
3256      ReqId :: reference().
3257
3258spawn_request(F) when erlang:is_function(F, 0) ->
3259    try
3260        erlang:spawn_request(erlang, apply, [F, []], [])
3261    catch
3262        error:Err ->
3263            error_with_info(Err, [F])
3264    end;
3265spawn_request(F) ->
3266    badarg_with_info([F]).
3267
3268%%
3269%% spawn_request/2
3270%%
3271
3272-spec spawn_request(Fun, Options) -> ReqId when
3273      Fun :: function(),
3274      Option :: {reply_tag, ReplyTag}
3275              | {reply, Reply}
3276              | spawn_opt_option(),
3277      ReplyTag :: term(),
3278      Reply :: yes | no | error_only | success_only,
3279      Options :: [Option],
3280      ReqId :: reference();
3281                   (Node, Fun) -> ReqId when
3282      Node :: node(),
3283      Fun :: function(),
3284      ReqId :: reference().
3285
3286spawn_request(F, O) when erlang:is_function(F, 0) ->
3287    try
3288        erlang:spawn_request(erlang, apply, [F, []], O)
3289    catch
3290        error:Err:Stk ->
3291            error_with_inherited_info(Err, [F, O], Stk)
3292    end;
3293spawn_request(N, F) when erlang:is_function(F, 0) ->
3294    try
3295        erlang:spawn_request(N, erlang, apply, [F, []], [])
3296    catch
3297        error:Err:Stk ->
3298            error_with_inherited_info(Err, [N, F], Stk)
3299    end;
3300spawn_request(A1, A2) ->
3301    badarg_with_info([A1, A2]).
3302
3303%%
3304%% spawn_request/3
3305%%
3306
3307-spec spawn_request(Node, Fun, Options) -> ReqId when
3308      Node :: node(),
3309      Fun :: function(),
3310      Options :: [Option],
3311      Option :: monitor
3312              | {monitor, [monitor_option()]}
3313              | link
3314              | {reply_tag, ReplyTag}
3315              | {reply, Reply}
3316              | OtherOption,
3317      ReplyTag :: term(),
3318      Reply :: yes | no | error_only | success_only,
3319      OtherOption :: term(),
3320      ReqId :: reference();
3321                   (Module, Function, Args) ->
3322                           ReqId when
3323      Module :: module(),
3324      Function :: atom(),
3325      Args :: [term()],
3326      ReqId :: reference().
3327
3328spawn_request(N, F, O) when erlang:is_function(F, 0) ->
3329    try
3330        erlang:spawn_request(N, erlang, apply, [F, []], O)
3331    catch
3332        error:Err ->
3333            error_with_info(Err, [N, F, O])
3334    end;
3335spawn_request(M, F, A) ->
3336    try
3337        erlang:spawn_request(M, F, A, [])
3338    catch
3339        error:Err ->
3340            error_with_info(Err, [M, F, A])
3341    end.
3342
3343%%
3344%% spawn_request/4
3345%%
3346
3347-spec spawn_request(Node, Module, Function, Args) ->
3348                           ReqId when
3349      Node :: node(),
3350      Module :: module(),
3351      Function :: atom(),
3352      Args :: [term()],
3353      ReqId :: reference();
3354                   (Module, Function, Args, Options) ->
3355                           ReqId when
3356      Module :: module(),
3357      Function :: atom(),
3358      Args :: [term()],
3359      Option :: {reply_tag, ReplyTag}
3360              | {reply, Reply}
3361              | spawn_opt_option(),
3362      ReplyTag :: term(),
3363      Reply :: yes | no | error_only | success_only,
3364      Options :: [Option],
3365      ReqId :: reference().
3366
3367spawn_request(N, M, F, A) when erlang:is_atom(F) ->
3368    try
3369        erlang:spawn_request(N, M, F, A, [])
3370    catch
3371        error:Err ->
3372            error_with_info(Err, [N, M, F, A])
3373    end;
3374spawn_request(M, F, A, O) ->
3375    case erts_internal:spawn_request(M, F, A, O) of
3376        Ref when erlang:is_reference(Ref) ->
3377            Ref;
3378        badopt ->
3379            badarg_with_cause([M, F, A, O], badopt);
3380        badarg ->
3381            badarg_with_info([M, F, A, O])
3382    end.
3383
3384%%
3385%% spawn_request/5
3386%%
3387
3388-spec spawn_request(Node, Module, Function, Args, Options) ->
3389                           ReqId when
3390      Node :: node(),
3391      Module :: module(),
3392      Function :: atom(),
3393      Args :: [term()],
3394      Options :: [Option],
3395      Option :: monitor
3396              | {monitor, [monitor_option()]}
3397              | link
3398              | {reply_tag, ReplyTag}
3399              | {reply, Reply}
3400              | OtherOption,
3401      ReplyTag :: term(),
3402      Reply :: yes | no | error_only | success_only,
3403      OtherOption :: term(),
3404      ReqId :: reference().
3405
3406spawn_request(N, M, F, A, O) when N =:= erlang:node() ->
3407    try
3408        erlang:spawn_request(M, F, A, O)
3409    catch
3410        error:Err:Stk ->
3411            error_with_inherited_info(Err, [N, M, F, A, O], Stk)
3412    end;
3413spawn_request(N, M, F, A, O) ->
3414    case erts_internal:dist_spawn_request(N, {M, F, A}, O, spawn_request) of
3415        Ref when erlang:is_reference(Ref) ->
3416            Ref;
3417        badarg ->
3418            badarg_with_info([N, M, F, A, O])
3419    end.
3420
3421-spec spawn_request_abandon(ReqId :: reference()) -> boolean().
3422
3423spawn_request_abandon(_ReqId) ->
3424    erlang:nif_error(undefined).
3425
3426-spec erlang:yield() -> 'true'.
3427yield() ->
3428    % This is not an infinite loop because erlang:yield() is
3429    % translated to an instruction by the loader
3430    erlang:yield().
3431
3432-spec nodes() -> Nodes when
3433      Nodes :: [node()].
3434nodes() ->
3435    erlang:nodes(visible).
3436
3437-spec disconnect_node(Node) -> boolean() | ignored when
3438      Node :: node().
3439disconnect_node(Node) ->
3440    net_kernel:disconnect(Node).
3441
3442-spec erlang:fun_info(Fun) -> [{Item, Info}] when
3443      Fun :: function(),
3444      Item :: arity | env | index | name
3445            | module | new_index | new_uniq | pid | type | uniq,
3446      Info :: term().
3447fun_info(Fun) when erlang:is_function(Fun) ->
3448    Keys = [type,env,arity,name,uniq,index,new_uniq,new_index,module,pid],
3449    fun_info_1(Keys, Fun, []);
3450fun_info(Fun) ->
3451    badarg_with_info([Fun]).
3452
3453fun_info_1([K|Ks], Fun, A) ->
3454    case erlang:fun_info(Fun, K) of
3455	{K,undefined} -> fun_info_1(Ks, Fun, A);
3456	{K,_}=P -> fun_info_1(Ks, Fun, [P|A])
3457    end;
3458fun_info_1([], _, A) -> A.
3459
3460-type dst() :: pid()
3461             | reference()
3462             | port()
3463             | (RegName :: atom())
3464             | {RegName :: atom(), Node :: node()}.
3465
3466-spec erlang:send_nosuspend(Dest, Msg) -> boolean() when
3467      Dest :: dst(),
3468      Msg :: term().
3469send_nosuspend(Pid, Msg) ->
3470    try
3471        send_nosuspend(Pid, Msg, [])
3472    catch
3473        error:Error -> error_with_info(Error, [Pid, Msg])
3474    end.
3475
3476-spec erlang:send_nosuspend(Dest, Msg, Options) -> boolean() when
3477      Dest :: dst(),
3478      Msg :: term(),
3479      Options :: [noconnect].
3480send_nosuspend(Pid, Msg, Opts) ->
3481    try erlang:send(Pid, Msg, [nosuspend|Opts]) of
3482	ok -> true;
3483	_  -> false
3484    catch
3485        error:Error:Stk ->
3486            error_with_inherited_info(Error, [Pid, Msg, Opts], Stk)
3487    end.
3488
3489-spec erlang:localtime_to_universaltime(Localtime) -> Universaltime when
3490      Localtime :: calendar:datetime(),
3491      Universaltime :: calendar:datetime().
3492localtime_to_universaltime(Localtime) ->
3493    try
3494        erlang:localtime_to_universaltime(Localtime, undefined)
3495    catch
3496        error:Error ->
3497            error_with_info(Error, [Localtime])
3498    end.
3499
3500%%
3501%% Port BIFs
3502%%
3503%%       Currently all port BIFs calls the corresponding
3504%%       erts_internal:port_*() native function which perform
3505%%       most of the actual work. These native functions should
3506%%       *never* be called directly by other functionality. The
3507%%       native functions may be changed, or removed without any
3508%%       notice whatsoever!
3509%%
3510%% IMPORTANT NOTE:
3511%%       When the erts_internal:port_*() native functions return
3512%%       a reference, they have also internally prepared the
3513%%       message queue of the caller for a receive that will
3514%%       unconditionally wait for a message containing this
3515%%       reference. If the erlang code calling these native
3516%%       functions do not do this, subsequent receives will not
3517%%       work as expected! That is, it is of *vital importance*
3518%%       that the receive is performed as described above!
3519%%
3520
3521-spec port_command(Port, Data) -> 'true' when
3522      Port :: port() | atom(),
3523      Data :: iodata().
3524
3525port_command(Port, Data) ->
3526    case case erts_internal:port_command(Port, Data, []) of
3527	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3528	     Res -> Res
3529	 end of
3530	true -> true;
3531	Error -> error_with_info(Error, [Port, Data])
3532    end.
3533
3534-spec port_command(Port, Data, OptionList) -> boolean() when
3535      Port :: port() | atom(),
3536      Data :: iodata(),
3537      Option :: force | nosuspend,
3538      OptionList :: [Option].
3539
3540port_command(Port, Data, Flags) ->
3541    case case erts_internal:port_command(Port, Data, Flags) of
3542	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3543	     Res -> Res
3544	 end of
3545        badopt -> badarg_with_cause([Port, Data, Flags], badopt);
3546	Bool when erlang:is_boolean(Bool) -> Bool;
3547	Error -> error_with_info(Error, [Port, Data, Flags])
3548    end.
3549
3550-spec port_connect(Port, Pid) -> 'true' when
3551      Port :: port() | atom(),
3552      Pid :: pid().
3553
3554port_connect(Port, Pid) ->
3555    case case erts_internal:port_connect(Port, Pid) of
3556	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3557	     Res -> Res
3558	 end of
3559	true -> true;
3560	Error -> error_with_info(Error, [Port, Pid])
3561    end.
3562
3563-spec port_close(Port) -> 'true' when
3564      Port :: port() | atom().
3565
3566port_close(Port) ->
3567    case case erts_internal:port_close(Port) of
3568	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3569	     Res -> Res
3570	 end of
3571	true -> true;
3572	Error -> error_with_info(Error, [Port])
3573    end.
3574
3575-spec port_control(Port, Operation, Data) -> iodata() | binary() when
3576      Port :: port() | atom(),
3577      Operation :: integer(),
3578      Data :: iodata().
3579
3580port_control(Port, Operation, Data) ->
3581    case case erts_internal:port_control(Port, Operation, Data) of
3582	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3583	     Res -> Res
3584	 end of
3585	badarg -> badarg_with_info([Port, Operation, Data]);
3586	Result -> Result
3587    end.
3588
3589-spec erlang:port_call(Port, Data) -> term() when
3590      Port :: port() | atom(),
3591      Data :: term().
3592
3593port_call(Port, Data) ->
3594    case case erts_internal:port_call(Port, 0, Data) of
3595	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3596	     Res -> Res
3597	 end of
3598	{ok, Result} -> Result;
3599	Error -> error_with_info(Error, [Port, Data])
3600    end.
3601
3602-spec erlang:port_call(Port, Operation, Data) -> term() when
3603      Port :: port() | atom(),
3604      Operation :: integer(),
3605      Data :: term().
3606
3607port_call(Port, Operation, Data) ->
3608    case case erts_internal:port_call(Port, Operation, Data) of
3609	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3610	     Res -> Res
3611	 end of
3612	{ok, Result} -> Result;
3613	Error -> error_with_info(Error, [Port, Operation, Data])
3614    end.
3615
3616-spec erlang:port_info(Port) -> Result when
3617      Port :: port() | atom(),
3618      ResultItem :: {registered_name, RegisteredName :: atom()}
3619		  | {id, Index :: non_neg_integer()}
3620		  | {connected, Pid :: pid()}
3621		  | {links, Pids :: [pid()]}
3622		  | {name, String :: string()}
3623		  | {input, Bytes :: non_neg_integer()}
3624		  | {output, Bytes :: non_neg_integer()}
3625		  | {os_pid, OsPid :: non_neg_integer() | 'undefined'},
3626      Result :: [ResultItem] | 'undefined'.
3627
3628port_info(Port) ->
3629    case case erts_internal:port_info(Port) of
3630	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3631	     Res -> Res
3632	 end of
3633	badarg -> badarg_with_info([Port]);
3634	Result -> Result
3635    end.
3636
3637-spec erlang:port_info(Port, connected) -> {connected, Pid} | 'undefined' when
3638      Port :: port() | atom(),
3639      Pid :: pid();
3640		      (Port, id) -> {id, Index} | 'undefined' when
3641      Port :: port() | atom(),
3642      Index :: non_neg_integer();
3643		      (Port, input) -> {input, Bytes} | 'undefined' when
3644      Port :: port() | atom(),
3645      Bytes :: non_neg_integer();
3646		      (Port, links) -> {links, Pids} | 'undefined' when
3647      Port :: port() | atom(),
3648      Pids :: [pid()];
3649		      (Port, locking) -> {locking, Locking} | 'undefined' when
3650      Port :: port() | atom(),
3651      Locking :: 'false' | 'port_level' | 'driver_level';
3652		      (Port, memory) -> {memory, Bytes} | 'undefined' when
3653      Port :: port() | atom(),
3654      Bytes :: non_neg_integer();
3655		      (Port, monitors) -> {monitors, Monitors} | 'undefined' when
3656      Port :: port() | atom(),
3657      Monitors :: [{process, pid()}];
3658		      (Port, monitored_by) -> {monitored_by, MonitoredBy} | 'undefined' when
3659      Port :: port() | atom(),
3660      MonitoredBy :: [pid()];
3661		      (Port, name) -> {name, Name} | 'undefined' when
3662      Port :: port() | atom(),
3663      Name :: string();
3664		      (Port, os_pid) -> {os_pid, OsPid} | 'undefined' when
3665      Port :: port() | atom(),
3666      OsPid :: non_neg_integer() | 'undefined';
3667		      (Port, output) -> {output, Bytes} | 'undefined' when
3668      Port :: port() | atom(),
3669      Bytes :: non_neg_integer();
3670		      (Port, parallelism) -> {parallelism, Boolean} | 'undefined' when
3671      Port :: port() | atom(),
3672      Boolean :: boolean();
3673		      (Port, queue_size) -> {queue_size, Bytes} | 'undefined' when
3674      Port :: port() | atom(),
3675      Bytes :: non_neg_integer();
3676		      (Port, registered_name) -> {registered_name, RegisteredName} | [] | 'undefined' when
3677      Port :: port() | atom(),
3678      RegisteredName :: atom().
3679
3680port_info(Port, Item) ->
3681    case case erts_internal:port_info(Port, Item) of
3682	     Ref when erlang:is_reference(Ref) -> receive {Ref, Res} -> Res end;
3683	     Res -> Res
3684	 end of
3685        badtype -> badarg_with_cause([Port, Item], badtype);
3686	badarg -> badarg_with_info([Port, Item]);
3687	Result -> Result
3688    end.
3689
3690-spec erlang:port_set_data(Port, Data) -> 'true' when
3691      Port :: port() | atom(),
3692      Data :: term().
3693
3694port_set_data(_Port, _Data) ->
3695    erlang:nif_error(undefined).
3696
3697-spec erlang:port_get_data(Port) -> term() when
3698      Port :: port() | atom().
3699
3700port_get_data(_Port) ->
3701    erlang:nif_error(undefined).
3702
3703%%
3704%% Distribution channel management
3705%%
3706
3707-spec erlang:dist_ctrl_input_handler(DHandle, InputHandler) -> 'ok' when
3708      DHandle :: dist_handle(),
3709      InputHandler :: pid().
3710
3711dist_ctrl_input_handler(_DHandle, _InputHandler) ->
3712    erlang:nif_error(undefined).
3713
3714-spec erlang:dist_ctrl_put_data(DHandle, Data) -> 'ok' when
3715      DHandle :: dist_handle(),
3716      Data :: iodata().
3717
3718dist_ctrl_put_data(_DHandle, _Data) ->
3719    erlang:nif_error(undefined).
3720
3721-spec erlang:dist_ctrl_get_data(DHandle) -> {Size, Data} | Data | 'none' when
3722      Size :: non_neg_integer(),
3723      DHandle :: dist_handle(),
3724      Data :: iovec().
3725
3726dist_ctrl_get_data(_DHandle) ->
3727    erlang:nif_error(undefined).
3728
3729-spec erlang:dist_ctrl_get_data_notification(DHandle) -> 'ok' when
3730      DHandle :: dist_handle().
3731
3732dist_ctrl_get_data_notification(_DHandle) ->
3733    erlang:nif_error(undefined).
3734
3735-spec erlang:dist_ctrl_set_opt(DHandle, 'get_size', Value) -> OldValue when
3736      DHandle :: dist_handle(),
3737      Value :: boolean(),
3738      OldValue :: boolean().
3739
3740dist_ctrl_set_opt(_DHandle, _Opt, _Val) ->
3741    erlang:nif_error(undefined).
3742
3743-spec erlang:dist_ctrl_get_opt(DHandle, 'get_size') -> Value when
3744      DHandle :: dist_handle(),
3745      Value :: boolean().
3746
3747dist_ctrl_get_opt(_DHandle, _Opt) ->
3748    erlang:nif_error(undefined).
3749
3750-spec erlang:dist_get_stat(DHandle) -> Res when
3751      DHandle :: dist_handle(),
3752      InputPackets :: non_neg_integer(),
3753      OutputPackets :: non_neg_integer(),
3754      PendingOutputPackets :: non_neg_integer(),
3755      Res :: {'ok', InputPackets, OutputPackets, PendingOutputPackets}.
3756
3757dist_get_stat(_DHandle) ->
3758    erlang:nif_error(undefined).
3759
3760
3761dmonitor_node(Node, _Flag, []) ->
3762    %% Only called when auto-connect attempt failed early in VM
3763    erlang:self() ! {nodedown, Node},
3764    true;
3765dmonitor_node(Node, Flag, Opts) ->
3766    case lists:member(allow_passive_connect, Opts) of
3767	true ->
3768	    case net_kernel:passive_cnct(Node) of
3769		true -> erlang:monitor_node(Node, Flag, Opts);
3770		false -> erlang:self() ! {nodedown, Node}, true
3771	    end;
3772	_ ->
3773	    dmonitor_node(Node,Flag,[])
3774    end.
3775
3776%%
3777%% Trap function used when modified timing has been enabled.
3778%%
3779
3780-spec erlang:delay_trap(Result, timeout()) -> Result.
3781delay_trap(Result, 0) -> erlang:yield(), Result;
3782delay_trap(Result, Timeout) -> receive after Timeout -> Result end.
3783
3784
3785-spec erlang:set_cookie(Cookie) -> true when
3786      Cookie :: atom().
3787set_cookie(C) when erlang:is_atom(C) ->
3788    auth:set_cookie(C);
3789set_cookie(C) ->
3790    badarg_with_info([C]).
3791
3792-spec erlang:set_cookie(Node, Cookie) -> true when
3793      Node :: node(),
3794      Cookie :: atom().
3795set_cookie(Node, C)
3796  when Node =/= nonode@nohost, erlang:is_atom(Node), erlang:is_atom(C) ->
3797    auth:set_cookie(Node, C);
3798set_cookie(Node, C) ->
3799    badarg_with_info([Node, C]).
3800
3801
3802-spec erlang:get_cookie() -> Cookie | nocookie when
3803      Cookie :: atom().
3804get_cookie() ->
3805    auth:get_cookie().
3806
3807-spec erlang:get_cookie(Node) -> Cookie | nocookie when
3808      Node :: node(),
3809      Cookie :: atom().
3810get_cookie(Node) when erlang:is_atom(Node) ->
3811    auth:get_cookie(Node);
3812get_cookie(Node) ->
3813    badarg_with_info([Node]).
3814
3815
3816-spec integer_to_list(Integer, Base) -> string() when
3817      Integer :: integer(),
3818      Base :: 2..36.
3819integer_to_list(_I, _Base) ->
3820    erlang:nif_error(undefined).
3821
3822-spec integer_to_binary(Integer, Base) -> binary() when
3823      Integer :: integer(),
3824      Base :: 2..36.
3825integer_to_binary(_I, _Base) ->
3826    erlang:nif_error(undefined).
3827
3828
3829-record(cpu, {node = -1,
3830	      processor = -1,
3831	      processor_node = -1,
3832	      core = -1,
3833	      thread = -1,
3834	      logical = -1}).
3835
3836%% erlang:set_cpu_topology/1 is for internal use only!
3837%%
3838%% erlang:system_flag(cpu_topology, CpuTopology) traps to
3839%% erlang:set_cpu_topology(CpuTopology).
3840set_cpu_topology(CpuTopology) ->
3841    try format_cpu_topology(erlang:system_flag(internal_cpu_topology,
3842					       cput_e2i(CpuTopology)))
3843    catch
3844	Class:Exception when Class =/= error; Exception =/= internal_error ->
3845	    badarg_with_info([CpuTopology])
3846    end.
3847
3848cput_e2i_clvl({logical, _}, _PLvl) ->
3849    #cpu.logical;
3850cput_e2i_clvl([E | _], PLvl) ->
3851    case erlang:element(1, E) of
3852	node -> case PLvl of
3853		    0 -> #cpu.node;
3854		    #cpu.processor -> #cpu.processor_node
3855		end;
3856	processor -> case PLvl of
3857			 0 -> #cpu.node;
3858			 #cpu.node -> #cpu.processor
3859		     end;
3860	core -> #cpu.core;
3861	thread -> #cpu.thread
3862    end.
3863
3864cput_e2i(undefined) ->
3865    undefined;
3866cput_e2i(E) ->
3867    rvrs(cput_e2i(E, -1, -1, #cpu{}, 0, cput_e2i_clvl(E, 0), [])).
3868
3869cput_e2i([], _NId, _PId, _IS, _PLvl, _Lvl, Res) ->
3870    Res;
3871cput_e2i([E|Es], NId0, PId, IS, PLvl, Lvl, Res0) ->
3872    case cput_e2i(E, NId0, PId, IS, PLvl, Lvl, Res0) of
3873	[] ->
3874	    cput_e2i(Es, NId0, PId, IS, PLvl, Lvl, Res0);
3875	[#cpu{node = N,
3876	      processor = P,
3877	      processor_node = PN} = CPU|_] = Res1 ->
3878	    NId1 = case N > PN of
3879			 true -> N;
3880			 false -> PN
3881		     end,
3882	    cput_e2i(Es, NId1, P, CPU, PLvl, Lvl, Res1)
3883    end;
3884cput_e2i({Tag, [], TagList}, Nid, PId, CPU, PLvl, Lvl, Res) ->
3885    %% Currently [] is the only valid InfoList
3886    cput_e2i({Tag, TagList}, Nid, PId, CPU, PLvl, Lvl, Res);
3887cput_e2i({node, NL}, Nid0, PId, _CPU, 0, #cpu.node, Res) ->
3888    Nid1 = Nid0+1,
3889    Lvl = cput_e2i_clvl(NL, #cpu.node),
3890    cput_e2i(NL, Nid1, PId, #cpu{node = Nid1}, #cpu.node, Lvl, Res);
3891cput_e2i({processor, PL}, Nid, PId0, _CPU, 0, #cpu.node, Res) ->
3892    PId1 = PId0+1,
3893    Lvl = cput_e2i_clvl(PL, #cpu.processor),
3894    cput_e2i(PL, Nid, PId1, #cpu{processor = PId1}, #cpu.processor, Lvl, Res);
3895cput_e2i({processor, PL}, Nid, PId0, CPU, PLvl, CLvl, Res)
3896  when PLvl < #cpu.processor, CLvl =< #cpu.processor ->
3897    PId1 = PId0+1,
3898    Lvl = cput_e2i_clvl(PL, #cpu.processor),
3899    cput_e2i(PL, Nid, PId1, CPU#cpu{processor = PId1,
3900				    processor_node = -1,
3901				    core = -1,
3902				    thread = -1}, #cpu.processor, Lvl, Res);
3903cput_e2i({node, NL}, Nid0, PId, CPU, #cpu.processor, #cpu.processor_node,
3904	 Res) ->
3905    Nid1 = Nid0+1,
3906    Lvl = cput_e2i_clvl(NL, #cpu.processor_node),
3907    cput_e2i(NL, Nid1, PId, CPU#cpu{processor_node = Nid1},
3908	     #cpu.processor_node, Lvl, Res);
3909cput_e2i({core, CL}, Nid, PId, #cpu{core = C0} = CPU, PLvl, #cpu.core, Res)
3910  when PLvl < #cpu.core ->
3911    Lvl = cput_e2i_clvl(CL, #cpu.core),
3912    cput_e2i(CL, Nid, PId, CPU#cpu{core = C0+1, thread = -1}, #cpu.core, Lvl,
3913	     Res);
3914cput_e2i({thread, TL}, Nid, PId, #cpu{thread = T0} = CPU, PLvl, #cpu.thread,
3915	 Res) when PLvl < #cpu.thread ->
3916    Lvl = cput_e2i_clvl(TL, #cpu.thread),
3917    cput_e2i(TL, Nid, PId, CPU#cpu{thread = T0+1}, #cpu.thread, Lvl, Res);
3918cput_e2i({logical, ID}, _Nid, PId, #cpu{processor=P, core=C, thread=T} = CPU,
3919	 PLvl, #cpu.logical, Res)
3920  when PLvl < #cpu.logical, erlang:is_integer(ID), 0 =< ID, ID < 65536 ->
3921    [CPU#cpu{processor = case P of -1 -> PId+1; _ -> P end,
3922	     core = case C of -1 -> 0; _ -> C end,
3923	     thread = case T of -1 -> 0; _ -> T end,
3924	     logical = ID} | Res].
3925
3926%% erlang:format_cpu_topology/1 is for internal use only!
3927%%
3928%% erlang:system_info(cpu_topology),
3929%% and erlang:system_info({cpu_topology, Which}) traps to
3930%% erlang:format_cpu_topology(InternalCpuTopology).
3931format_cpu_topology(InternalCpuTopology) ->
3932    try cput_i2e(InternalCpuTopology)
3933    catch _ : _ -> erlang:error(internal_error, [InternalCpuTopology])
3934    end.
3935
3936
3937cput_i2e(undefined) -> undefined;
3938cput_i2e(Is) -> cput_i2e(Is, true, #cpu.node, cput_i2e_tag_map()).
3939
3940cput_i2e([], _Frst, _Lvl, _TM) ->
3941    [];
3942cput_i2e([#cpu{logical = LID}| _], _Frst, Lvl, _TM) when Lvl == #cpu.logical ->
3943    {logical, LID};
3944cput_i2e([#cpu{} = I | Is], Frst, Lvl, TM) ->
3945    cput_i2e(erlang:element(Lvl, I), Frst, Is, [I], Lvl, TM).
3946
3947cput_i2e(V, Frst, [I | Is], SameV, Lvl, TM) when V =:= erlang:element(Lvl, I) ->
3948    cput_i2e(V, Frst, Is, [I | SameV], Lvl, TM);
3949cput_i2e(-1, true, [], SameV, Lvl, TM) ->
3950    cput_i2e(rvrs(SameV), true, Lvl+1, TM);
3951cput_i2e(_V, true, [], SameV, Lvl, TM) when Lvl =/= #cpu.processor,
3952                                            Lvl =/= #cpu.processor_node ->
3953    cput_i2e(rvrs(SameV), true, Lvl+1, TM);
3954cput_i2e(-1, _Frst, Is, SameV, #cpu.node, TM) ->
3955    cput_i2e(rvrs(SameV), true, #cpu.processor, TM)
3956	++ cput_i2e(Is, false, #cpu.node, TM);
3957cput_i2e(_V, _Frst, Is, SameV, Lvl, TM) ->
3958    [{cput_i2e_tag(Lvl, TM), cput_i2e(rvrs(SameV), true, Lvl+1, TM)}
3959     | cput_i2e(Is, false, Lvl, TM)].
3960
3961cput_i2e_tag_map() -> erlang:list_to_tuple([cpu | record_info(fields, cpu)]).
3962
3963cput_i2e_tag(Lvl, TM) ->
3964    case erlang:element(Lvl, TM) of processor_node -> node; Other -> Other end.
3965
3966rvrs([_] = L) -> L;
3967rvrs(Xs) -> rvrs(Xs, []).
3968
3969rvrs([],Ys) -> Ys;
3970rvrs([X|Xs],Ys) -> rvrs(Xs, [X|Ys]).
3971
3972-spec min(Term1, Term2) -> Minimum when
3973      Term1 :: term(),
3974      Term2 :: term(),
3975      Minimum :: term().
3976min(A, B) when A > B -> B;
3977min(A, _) -> A.
3978
3979-spec max(Term1, Term2) -> Maximum when
3980      Term1 :: term(),
3981      Term2 :: term(),
3982      Maximum :: term().
3983max(A, B) when A < B -> B;
3984max(A, _) -> A.
3985
3986
3987%%
3988%% erlang:memory/[0,1]
3989%%
3990%% NOTE! When updating these functions, make sure to also update
3991%%       erts_memory() in $ERL_TOP/erts/emulator/beam/erl_alloc.c
3992%%
3993
3994-type memory_type() :: 'total' | 'processes' | 'processes_used' | 'system'
3995                     | 'atom' | 'atom_used' | 'binary' | 'code' | 'ets'.
3996
3997-define(CARRIER_ALLOCS, [mseg_alloc]).
3998-define(ALL_NEEDED_ALLOCS, (erlang:system_info(alloc_util_allocators)
3999			    -- ?CARRIER_ALLOCS)).
4000
4001-record(memory, {total = 0,
4002		 processes = 0,
4003		 processes_used = 0,
4004		 system = 0,
4005		 atom = 0,
4006		 atom_used = 0,
4007		 binary = 0,
4008		 code = 0,
4009		 ets = 0}).
4010
4011-spec erlang:memory() -> [{Type, Size}] when
4012      Type :: memory_type(),
4013      Size :: non_neg_integer().
4014memory() ->
4015    case aa_mem_data(au_mem_data(?ALL_NEEDED_ALLOCS)) of
4016	notsup ->
4017	    erlang:error(notsup);
4018	Mem ->
4019	    [{total, Mem#memory.total},
4020	     {processes, Mem#memory.processes},
4021	     {processes_used, Mem#memory.processes_used},
4022	     {system, Mem#memory.system},
4023	     {atom, Mem#memory.atom},
4024	     {atom_used, Mem#memory.atom_used},
4025	     {binary, Mem#memory.binary},
4026	     {code, Mem#memory.code},
4027	     {ets, Mem#memory.ets}]
4028    end.
4029
4030-spec erlang:memory(Type :: memory_type()) -> non_neg_integer();
4031                   (TypeList :: [memory_type()]) -> [{memory_type(), non_neg_integer()}].
4032memory(Type) when erlang:is_atom(Type) ->
4033    try
4034        case aa_mem_data(au_mem_data(?ALL_NEEDED_ALLOCS)) of
4035            notsup -> error_with_info(notsup, [Type]);
4036            Mem -> get_memval(Type, Mem)
4037        end
4038    catch
4039        error:badarg -> badarg_with_info([Type])
4040    end;
4041memory(Types) when erlang:is_list(Types) ->
4042    try
4043        case aa_mem_data(au_mem_data(?ALL_NEEDED_ALLOCS)) of
4044            notsup -> error_with_info(notsup, [Types]);
4045            Mem -> memory_1(Types, Mem)
4046        end
4047    catch
4048        error:badarg -> badarg_with_info([Types])
4049    end;
4050memory(Arg) ->
4051    badarg_with_info([Arg]).
4052
4053memory_1([Type | Types], Mem) ->
4054    [{Type, get_memval(Type, Mem)} | memory_1(Types, Mem)];
4055memory_1([], _Mem) ->
4056    [].
4057
4058get_memval(total, #memory{total = V}) -> V;
4059get_memval(processes, #memory{processes = V}) -> V;
4060get_memval(processes_used, #memory{processes_used = V}) -> V;
4061get_memval(system, #memory{system = V}) -> V;
4062get_memval(atom, #memory{atom = V}) -> V;
4063get_memval(atom_used, #memory{atom_used = V}) -> V;
4064get_memval(binary, #memory{binary = V}) -> V;
4065get_memval(code, #memory{code = V}) -> V;
4066get_memval(ets, #memory{ets = V}) -> V;
4067get_memval(_, #memory{}) -> erlang:error(badarg).
4068
4069get_fix_proc([{ProcType, A1, U1}| Rest], {A0, U0}) when ProcType == proc;
4070							ProcType == monitor;
4071							ProcType == link;
4072							ProcType == msg_ref;
4073							ProcType == ll_ptimer;
4074							ProcType == hl_ptimer;
4075							ProcType == bif_timer;
4076							ProcType == accessor_bif_timer ->
4077    get_fix_proc(Rest, {A0+A1, U0+U1});
4078get_fix_proc([_|Rest], Acc) ->
4079    get_fix_proc(Rest, Acc);
4080get_fix_proc([], Acc) ->
4081    Acc.
4082
4083fix_proc([{fix_types, SizeList} | _Rest], Acc) ->
4084    get_fix_proc(SizeList, Acc);
4085fix_proc([{fix_types, Mask, SizeList} | _Rest], Acc) ->
4086    {A, U} = get_fix_proc(SizeList, Acc),
4087    {Mask, A, U};
4088fix_proc([_ | Rest], Acc) ->
4089    fix_proc(Rest, Acc);
4090fix_proc([], Acc) ->
4091    Acc.
4092
4093au_mem_fix(#memory{ processes = Proc,
4094                    processes_used = ProcU } = Mem, Data) ->
4095    case fix_proc(Data, {0, 0}) of
4096        {A, U} ->
4097            Mem#memory{ processes = Proc+A,
4098                        processes_used = ProcU+U };
4099        {Mask, A, U} ->
4100            Mem#memory{ processes = Mask band (Proc+A),
4101                        processes_used = Mask band (ProcU+U) }
4102    end.
4103
4104au_mem_acc(#memory{ total = Tot,
4105                    processes = Proc,
4106                    processes_used = ProcU } = Mem,
4107           eheap_alloc, Data) ->
4108    Sz = acc_blocks_size(Data, 0),
4109    Mem#memory{ total = Tot+Sz,
4110                processes = Proc+Sz,
4111                processes_used = ProcU+Sz};
4112au_mem_acc(#memory{ total = Tot,
4113                    ets = Ets } = Mem,
4114           ets_alloc, Data) ->
4115    Sz = acc_blocks_size(Data, 0),
4116    Mem#memory{ total = Tot+Sz,
4117                ets = Ets+Sz };
4118au_mem_acc(#memory{total = Tot,
4119		    binary = Bin } = Mem,
4120	    binary_alloc, Data) ->
4121    Sz = acc_blocks_size(Data, 0),
4122    Mem#memory{ total = Tot+Sz,
4123                binary = Bin+Sz};
4124au_mem_acc(#memory{ total = Tot } = Mem,
4125           _Type, Data) ->
4126    Sz = acc_blocks_size(Data, 0),
4127    Mem#memory{ total = Tot+Sz }.
4128
4129acc_blocks_size([{size, Sz, _, _} | Rest], Acc) ->
4130    acc_blocks_size(Rest, Acc+Sz);
4131acc_blocks_size([{size, Sz} | Rest], Acc) ->
4132    acc_blocks_size(Rest, Acc+Sz);
4133acc_blocks_size([_ | Rest], Acc) ->
4134    acc_blocks_size(Rest, Acc);
4135acc_blocks_size([], Acc) ->
4136    Acc.
4137
4138au_mem_blocks([{blocks, L} | Rest], Mem0) ->
4139    Mem = au_mem_blocks_1(L, Mem0),
4140    au_mem_blocks(Rest, Mem);
4141au_mem_blocks([_ | Rest], Mem) ->
4142    au_mem_blocks(Rest, Mem);
4143au_mem_blocks([], Mem) ->
4144    Mem.
4145
4146au_mem_blocks_1([{Type, SizeList} | Rest], Mem) ->
4147    au_mem_blocks_1(Rest, au_mem_acc(Mem, Type, SizeList));
4148au_mem_blocks_1([], Mem) ->
4149    Mem.
4150
4151au_mem_current(Mem, Type, [{mbcs_pool, Stats} | Rest]) ->
4152    au_mem_current(au_mem_blocks(Stats, Mem), Type, Rest);
4153au_mem_current(Mem, Type, [{mbcs, Stats} | Rest]) ->
4154    au_mem_current(au_mem_blocks(Stats, Mem), Type, Rest);
4155au_mem_current(Mem, Type, [{sbcs, Stats} | Rest]) ->
4156    au_mem_current(au_mem_blocks(Stats, Mem), Type, Rest);
4157au_mem_current(Mem, Type, [_ | Rest]) ->
4158    au_mem_current(Mem, Type, Rest);
4159au_mem_current(Mem, _Type, []) ->
4160    Mem.
4161
4162au_mem_data(notsup, _) ->
4163    notsup;
4164au_mem_data(_, [{_, false} | _]) ->
4165    notsup;
4166au_mem_data(#memory{} = Mem0, [{fix_alloc, _, Data} | Rest]) ->
4167    Mem = au_mem_fix(Mem0, Data),
4168    au_mem_data(au_mem_current(Mem, fix_alloc, Data), Rest);
4169au_mem_data(#memory{} = Mem, [{Type, _, Data} | Rest]) ->
4170    au_mem_data(au_mem_current(Mem, Type, Data), Rest);
4171au_mem_data(EMD, []) ->
4172    EMD.
4173
4174au_mem_data(Allocs) ->
4175    Ref = erlang:make_ref(),
4176    erlang:system_info({memory_internal, Ref, Allocs}),
4177    receive_emd(Ref).
4178
4179receive_emd(_Ref, EMD, 0) ->
4180    EMD;
4181receive_emd(Ref, EMD, N) ->
4182    receive
4183	{Ref, _, Data} ->
4184	    receive_emd(Ref, au_mem_data(EMD, Data), N-1)
4185    end.
4186
4187receive_emd(Ref) ->
4188    receive_emd(Ref, #memory{}, erlang:system_info(schedulers)).
4189
4190aa_mem_data(#memory{total = Tot} = Mem,
4191	    [{external_alloc, Sz} | Rest]) ->
4192    %% Externally allocated data, this is not a part of alloc_util so we must
4193    %% bump the total memory size.
4194    aa_mem_data(Mem#memory{total = Tot + Sz},
4195		Rest);
4196aa_mem_data(#memory{atom = Atom,
4197		    atom_used = AtomU} = Mem,
4198	    [{atom_space, Alloced, Used} | Rest]) ->
4199    aa_mem_data(Mem#memory{atom = Atom+Alloced,
4200			   atom_used = AtomU+Used},
4201		Rest);
4202aa_mem_data(#memory{atom = Atom,
4203		    atom_used = AtomU} = Mem,
4204	    [{atom_table, Sz} | Rest]) ->
4205    aa_mem_data(Mem#memory{atom = Atom+Sz,
4206			   atom_used = AtomU+Sz},
4207		Rest);
4208aa_mem_data(#memory{ets = Ets} = Mem,
4209	    [{ets_misc, Sz} | Rest]) ->
4210    aa_mem_data(Mem#memory{ets = Ets+Sz},
4211		Rest);
4212aa_mem_data(#memory{processes = Proc,
4213		    processes_used = ProcU } = Mem,
4214	    [{ProcData, Sz} | Rest]) when ProcData == bif_timer;
4215					  ProcData == process_table ->
4216    aa_mem_data(Mem#memory{processes = Proc+Sz,
4217			   processes_used = ProcU+Sz },
4218		Rest);
4219aa_mem_data(#memory{code = Code} = Mem,
4220	    [{CodeData, Sz} | Rest]) when CodeData == module_table;
4221					  CodeData == export_table;
4222					  CodeData == export_list;
4223					  CodeData == fun_table;
4224					  CodeData == module_refs;
4225					  CodeData == loaded_code ->
4226    aa_mem_data(Mem#memory{code = Code+Sz},
4227		Rest);
4228aa_mem_data(EMD, [{_, _} | Rest]) ->
4229    aa_mem_data(EMD, Rest);
4230aa_mem_data(#memory{ total = Tot,
4231                     processes = Proc } = Mem,
4232            []) ->
4233    Mem#memory{system = Tot - Proc}.
4234
4235aa_mem_data(notsup) ->
4236    notsup;
4237aa_mem_data(EMD) ->
4238    aa_mem_data(EMD, erlang:system_info(allocated_areas)).
4239
4240%%
4241%% alloc_info/1 and alloc_sizes/1 are for internal use only (used by
4242%% erlang:system_info({allocator|allocator_sizes, _})).
4243%%
4244
4245alloc_info(Allocs) ->
4246    get_alloc_info(allocator, Allocs).
4247
4248alloc_sizes(Allocs) ->
4249    get_alloc_info(allocator_sizes, Allocs).
4250
4251get_alloc_info(Type, AAtom) when erlang:is_atom(AAtom) ->
4252    [{AAtom, Result}] = get_alloc_info(Type, [AAtom]),
4253    Result;
4254get_alloc_info(Type, AList) when erlang:is_list(AList) ->
4255    Ref = erlang:make_ref(),
4256    erlang:system_info({Type, Ref, AList}),
4257    receive_allocator(Ref,
4258		      erlang:system_info(schedulers),
4259		      mk_res_list(AList)).
4260
4261mk_res_list([]) ->
4262    [];
4263mk_res_list([Alloc | Rest]) ->
4264    [{Alloc, []} | mk_res_list(Rest)].
4265
4266insert_instance(I, N, Rest) when erlang:is_atom(N) ->
4267    [{N, I} | Rest];
4268insert_instance(I, N, []) ->
4269    [{instance, N, I}];
4270insert_instance(I, N, [{instance, M, _}|_] = Rest) when N < M ->
4271    [{instance, N, I} | Rest];
4272insert_instance(I, N, [Prev|Rest]) ->
4273    [Prev | insert_instance(I, N, Rest)].
4274
4275insert_info([], Ys) ->
4276    Ys;
4277insert_info([{A, false}|Xs], [{A, _IList}|Ys]) ->
4278    insert_info(Xs, [{A, false}|Ys]);
4279insert_info([{A, N, I}|Xs], [{A, IList}|Ys]) ->
4280    insert_info(Xs, [{A, insert_instance(I, N, IList)}|Ys]);
4281insert_info([{A1, _}|_] = Xs, [{A2, _} = Y | Ys]) when A1 /= A2 ->
4282    [Y | insert_info(Xs, Ys)];
4283insert_info([{A1, _, _}|_] = Xs, [{A2, _} = Y | Ys]) when A1 /= A2 ->
4284    [Y | insert_info(Xs, Ys)].
4285
4286receive_allocator(_Ref, 0, Acc) ->
4287    Acc;
4288receive_allocator(Ref, N, Acc) ->
4289    receive
4290	{Ref, _, InfoList} ->
4291	    receive_allocator(Ref, N-1, insert_info(InfoList, Acc))
4292    end.
4293
4294-spec erlang:gather_gc_info_result(Ref) ->
4295   {number(),number(),0} when Ref :: reference().
4296
4297gather_gc_info_result(Ref) when erlang:is_reference(Ref) ->
4298    gc_info(Ref, erlang:system_info(schedulers), {0,0}).
4299
4300gc_info(_Ref, 0, {Colls,Recl}) ->
4301    {Colls,Recl,0};
4302gc_info(Ref, N, {OrigColls,OrigRecl}) ->
4303    receive
4304	{Ref, {_,Colls, Recl}} ->
4305	    gc_info(Ref, N-1, {Colls+OrigColls,Recl+OrigRecl})
4306    end.
4307
4308%% Operators
4309
4310-spec erlang:'=='(term(), term()) -> boolean().
4311'=='(_A, _B) ->
4312    erlang:nif_error(undefined).
4313-spec erlang:'=:='(term(), term()) -> boolean().
4314'=:='(_A, _B) ->
4315    erlang:nif_error(undefined).
4316-spec erlang:'/='(term(), term()) -> boolean().
4317'/='(_A, _B) ->
4318    erlang:nif_error(undefined).
4319-spec erlang:'=/='(term(), term()) -> boolean().
4320'=/='(_A, _B) ->
4321    erlang:nif_error(undefined).
4322-spec erlang:'=<'(term(), term()) -> boolean().
4323'=<'(_A, _B) ->
4324    erlang:nif_error(undefined).
4325-spec erlang:'>='(term(), term()) -> boolean().
4326'>='(_A, _B) ->
4327    erlang:nif_error(undefined).
4328-spec erlang:'<'(term(), term()) -> boolean().
4329'<'(_A, _B) ->
4330    erlang:nif_error(undefined).
4331-spec erlang:'>'(term(), term()) -> boolean().
4332'>'(_A, _B) ->
4333    erlang:nif_error(undefined).
4334
4335-spec erlang:'-'(number()) -> number().
4336'-'(_A) ->
4337    erlang:nif_error(undefined).
4338-spec erlang:'+'(number()) -> number().
4339'+'(_A) ->
4340    erlang:nif_error(undefined).
4341-spec erlang:'-'(number(), number()) -> number().
4342'-'(_A, _B) ->
4343    erlang:nif_error(undefined).
4344-spec erlang:'+'(number(), number()) -> number().
4345'+'(_A, _B) ->
4346    erlang:nif_error(undefined).
4347-spec erlang:'/'(number(), number()) -> float().
4348'/'(_A, _B) ->
4349    erlang:nif_error(undefined).
4350-spec erlang:'*'(number(), number()) -> number().
4351'*'(_A, _B) ->
4352    erlang:nif_error(undefined).
4353-spec erlang:'div'(integer(), integer()) -> integer().
4354'div'(_A, _B) ->
4355    erlang:nif_error(undefined).
4356-spec erlang:'rem'(integer(), integer()) -> integer().
4357'rem'(_A, _B) ->
4358    erlang:nif_error(undefined).
4359-spec erlang:'bsl'(integer(), integer()) -> integer().
4360'bsl'(_A, _B) ->
4361    erlang:nif_error(undefined).
4362-spec erlang:'bsr'(integer(), integer()) -> integer().
4363'bsr'(_A, _B) ->
4364    erlang:nif_error(undefined).
4365-spec erlang:'bor'(integer(), integer()) -> integer().
4366'bor'(_A, _B) ->
4367    erlang:nif_error(undefined).
4368-spec erlang:'band'(integer(), integer()) -> integer().
4369'band'(_A, _B) ->
4370    erlang:nif_error(undefined).
4371-spec erlang:'bxor'(integer(), integer()) -> integer().
4372'bxor'(_A, _B) ->
4373    erlang:nif_error(undefined).
4374-spec erlang:'bnot'(integer()) -> integer().
4375'bnot'(_A) ->
4376    erlang:nif_error(undefined).
4377
4378-spec erlang:'--'(list(), list()) -> list().
4379'--'(_A, _B) ->
4380    erlang:nif_error(undefined).
4381-spec erlang:'++'(list(), term()) -> term().
4382'++'(_A, _B) ->
4383    erlang:nif_error(undefined).
4384
4385-spec erlang:'and'(boolean(), boolean()) -> boolean().
4386'and'(_A, _B) ->
4387    erlang:nif_error(undefined).
4388-spec erlang:'or'(boolean(), boolean()) -> boolean().
4389'or'(_A, _B) ->
4390    erlang:nif_error(undefined).
4391
4392-spec erlang:'xor'(boolean(), boolean()) -> boolean().
4393'xor'(_A, _B) ->
4394    erlang:nif_error(undefined).
4395-spec erlang:'not'(boolean()) -> boolean().
4396'not'(_A) ->
4397    erlang:nif_error(undefined).
4398
4399-spec erlang:'!'(dst(), term()) -> term().
4400'!'(_Dst, _Msg) ->
4401    erlang:nif_error(undefined).
4402
4403%% Make sure that we have loaded the tracer module.
4404ensure_tracer_module_loaded(Flag, FlagList) ->
4405    try lists:keyfind(Flag, 1, FlagList) of
4406        {Flag, Module, State} when erlang:is_atom(Module) ->
4407            case erlang:module_loaded(Module) of
4408                false ->
4409                    Module:enabled(trace_status, erlang:self(), State);
4410                true ->
4411                    ok
4412            end;
4413        _ ->
4414            ok
4415    catch
4416        _:_ ->
4417            ok
4418    end.
4419
4420error_with_inherited_info(Reason, Args, [{_,_,_,ExtraInfo}|_]) ->
4421    %% We KNOW that lists:keyfind/3 is a BIF and is therefore safe to call.
4422    case lists:keyfind(error_info, 1, ExtraInfo) of
4423        {error_info,_}=ErrorInfoTuple ->
4424            erlang:error(Reason, Args, [ErrorInfoTuple]);
4425        false ->
4426            erlang:error(Reason, Args, [{error_info, #{module => erl_erts_errors}}])
4427    end.
4428
4429error_with_info(Reason, Args) ->
4430    erlang:error(Reason, Args, [{error_info, #{module => erl_erts_errors}}]).
4431
4432badarg_with_info(Args) ->
4433    erlang:error(badarg, Args, [{error_info, #{module => erl_erts_errors}}]).
4434
4435badarg_with_cause(Args, Cause) ->
4436    erlang:error(badarg, Args, [{error_info, #{module => erl_erts_errors,
4437                                              cause => Cause}}]).
4438